From 46f0ed379a23768853df9c917e1eaf16899ceda3 Mon Sep 17 00:00:00 2001 From: texuf Date: Wed, 14 Sep 2022 22:14:21 -0700 Subject: [PATCH] Hack out read receipt de-duping protection zion hack - always send the notification data on a read receipt the notifications are stored in two different databases, and somehow the notification database prunes data, so trying to mark old notifications as read will fail, but the notification will still exist in the other db todo, revist when this refactor lands: https://github.com/matrix-org/dendrite/pull/2688/files it looks like we cleanup the notification table after a day func (s *notificationsStatements) Clean(ctx context.Context, txn *sql.Tx) error { _, err := sqlutil.TxStmt(txn, s.cleanNotificationsStmt).ExecContext( ctx, time.Now().AddDate(0, 0, -1).UnixNano()/int64(time.Millisecond), // keep non-highlights for a day time.Now().AddDate(0, -1, 0).UnixNano()/int64(time.Millisecond), // keep highlights for a month ) return err } But we don't clean up the notifications in the syncAPI table. When we send a read receipt we first do a updated _, err := s.db.SetNotificationsRead(ctx, localpart, roomID, int64(read.Read), true) and only forward the message on if the table was updated. If a user waits more than a day to send a read receipt, they can't clear their notifications. --- userapi/consumers/syncapi_readupdate.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/userapi/consumers/syncapi_readupdate.go b/userapi/consumers/syncapi_readupdate.go index 54654f757..21b6efc91 100644 --- a/userapi/consumers/syncapi_readupdate.go +++ b/userapi/consumers/syncapi_readupdate.go @@ -95,22 +95,27 @@ func (s *OutputReadUpdateConsumer) onMessage(ctx context.Context, msgs []*nats.M log.Tracef("Received read update from sync API: %#v", read) if read.Read > 0 { - updated, err := s.db.SetNotificationsRead(ctx, localpart, roomID, int64(read.Read), true) + /*updated*/ _, err := s.db.SetNotificationsRead(ctx, localpart, roomID, int64(read.Read), true) if err != nil { log.WithError(err).Error("userapi EDU consumer") return false } - if updated { - if err = s.syncProducer.GetAndSendNotificationData(ctx, userID, roomID); err != nil { - log.WithError(err).Error("userapi EDU consumer: GetAndSendNotificationData failed") - return false - } - if err = util.NotifyUserCountsAsync(ctx, s.pgClient, localpart, s.db); err != nil { - log.WithError(err).Error("userapi EDU consumer: NotifyUserCounts failed") - return false - } + // zion hack - always send the notification data + // the notifications are stored in two different databases, and somehow the notification database + // prunes data, so trying to mark old notifications as read will fail, but the notification will still exist in the other db + // todo, revist when this refactor lands: https://github.com/matrix-org/dendrite/pull/2688/files + + //if updated { + if err = s.syncProducer.GetAndSendNotificationData(ctx, userID, roomID); err != nil { + log.WithError(err).Error("userapi EDU consumer: GetAndSendNotificationData failed") + return false } + if err = util.NotifyUserCountsAsync(ctx, s.pgClient, localpart, s.db); err != nil { + log.WithError(err).Error("userapi EDU consumer: NotifyUserCounts failed") + return false + } + //} } if read.FullyRead > 0 {