(ctx context.Context, msg *nats.Msg)
| 65 | } |
| 66 | |
| 67 | func (s *OutputReadUpdateConsumer) onMessage(ctx context.Context, msg *nats.Msg) bool { |
| 68 | var read types.ReadUpdate |
| 69 | if err := json.Unmarshal(msg.Data, &read); err != nil { |
| 70 | log.WithError(err).Error("userapi clientapi consumer: message parse failure") |
| 71 | return true |
| 72 | } |
| 73 | if read.FullyRead == 0 && read.Read == 0 { |
| 74 | return true |
| 75 | } |
| 76 | |
| 77 | userID := string(msg.Header.Get(jetstream.UserID)) |
| 78 | roomID := string(msg.Header.Get(jetstream.RoomID)) |
| 79 | |
| 80 | localpart, domain, err := gomatrixserverlib.SplitID('@', userID) |
| 81 | if err != nil { |
| 82 | log.WithError(err).Error("userapi clientapi consumer: SplitID failure") |
| 83 | return true |
| 84 | } |
| 85 | if domain != s.ServerName { |
| 86 | log.Error("userapi clientapi consumer: not a local user") |
| 87 | return true |
| 88 | } |
| 89 | |
| 90 | log := log.WithFields(log.Fields{ |
| 91 | "room_id": roomID, |
| 92 | "user_id": userID, |
| 93 | }) |
| 94 | log.Tracef("Received read update from sync API: %#v", read) |
| 95 | |
| 96 | if read.Read > 0 { |
| 97 | updated, err := s.db.SetNotificationsRead(ctx, localpart, roomID, int64(read.Read), true) |
| 98 | if err != nil { |
| 99 | log.WithError(err).Error("userapi EDU consumer") |
| 100 | return false |
| 101 | } |
| 102 | |
| 103 | if updated { |
| 104 | if err = s.syncProducer.GetAndSendNotificationData(ctx, userID, roomID); err != nil { |
| 105 | log.WithError(err).Error("userapi EDU consumer: GetAndSendNotificationData failed") |
| 106 | return false |
| 107 | } |
| 108 | if err = util.NotifyUserCountsAsync(ctx, s.pgClient, localpart, s.db); err != nil { |
| 109 | log.WithError(err).Error("userapi EDU consumer: NotifyUserCounts failed") |
| 110 | return false |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | if read.FullyRead > 0 { |
| 116 | deleted, err := s.db.DeleteNotificationsUpTo(ctx, localpart, roomID, int64(read.FullyRead)) |
| 117 | if err != nil { |
| 118 | log.WithError(err).Errorf("userapi clientapi consumer: DeleteNotificationsUpTo failed") |
| 119 | return false |
| 120 | } |
| 121 | |
| 122 | if deleted { |
| 123 | if err := util.NotifyUserCountsAsync(ctx, s.pgClient, localpart, s.db); err != nil { |
| 124 | log.WithError(err).Error("userapi clientapi consumer: NotifyUserCounts failed") |
nothing calls this directly
no test coverage detected