Skip push notification for people got new message ws package

This commit is contained in:
2025-02-02 15:57:41 +08:00
parent bfd3a0a1dd
commit f368e047be
4 changed files with 14 additions and 5 deletions

View File

@ -92,10 +92,13 @@ func NewEvent(event models.Event) (models.Event, error) {
idxList := lo.Map(members, func(item models.ChannelMember, index int) uint64 {
return uint64(item.AccountID)
})
PushCommandBatch(idxList, nex.WebSocketPackage{
successList64 := PushCommandBatch(idxList, nex.WebSocketPackage{
Action: "events.new",
Payload: event,
})
successList := lo.Map(successList64, func(item uint64, index int) uint {
return uint(item)
})
if strings.HasPrefix(event.Type, "messages") {
event.Channel, _ = GetChannel(event.ChannelID)
@ -105,7 +108,9 @@ func NewEvent(event models.Event) (models.Event, error) {
event.Channel.Realm = &realm
}
}
go NotifyMessageEvent(members, event)
go NotifyMessageEvent(lo.Filter(members, func(item models.ChannelMember, _ int) bool {
return !lo.Contains(successList, item.AccountID)
}), event)
}
return event, nil

View File

@ -27,12 +27,12 @@ func PushCommand(userId uint, task nex.WebSocketPackage) {
}
}
func PushCommandBatch(userId []uint64, task nex.WebSocketPackage) {
func PushCommandBatch(userId []uint64, task nex.WebSocketPackage) []uint64 {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
pc := gap.Nx.GetNexusGrpcConn()
_, err := proto.NewStreamServiceClient(pc).PushStreamBatch(ctx, &proto.PushStreamBatchRequest{
resp, err := proto.NewStreamServiceClient(pc).PushStreamBatch(ctx, &proto.PushStreamBatchRequest{
UserId: userId,
Body: task.Marshal(),
})
@ -40,4 +40,6 @@ func PushCommandBatch(userId []uint64, task nex.WebSocketPackage) {
if err != nil {
log.Warn().Err(err).Msg("Failed to push websocket command to nexus in batches...")
}
return resp.GetSuccessList()
}