diff options
| author | Kyren223 <Kyren223@proton.me> | 2025-02-04 19:37:06 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2025-02-04 19:37:06 +0200 |
| commit | f0607f16633d266f55a4b08f7edbbc13d08121ae (patch) | |
| tree | 168d1e6c46ada637bba76c6a4bd5735af1a4e02a | |
| parent | 752403fd523f287020dfcc6cdd3bf6d304365672 (diff) | |
Server now also sends the last_read column to the client so the client
so the client can use it to persist notifications
| -rw-r--r-- | internal/client/ui/core/state/state.go | 3 | ||||
| -rw-r--r-- | internal/packet/types.go | 5 | ||||
| -rw-r--r-- | internal/server/api/helpers.go | 6 |
3 files changed, 10 insertions, 4 deletions
diff --git a/internal/client/ui/core/state/state.go b/internal/client/ui/core/state/state.go index c1dd4cd..6a865d2 100644 --- a/internal/client/ui/core/state/state.go +++ b/internal/client/ui/core/state/state.go @@ -260,6 +260,9 @@ func SendUserDatUpdate() { func UpdateNotifications(info *packet.NotificationsInfo) { for i := 0; i < len(info.Source); i++ { + lastRead := snowflake.ID(info.LastRead[i]) + State.LastReadMessages[info.Source[i]] = &lastRead + ping := info.Pings[i] if ping != nil { State.Notifications[info.Source[i]] = int(*ping) diff --git a/internal/packet/types.go b/internal/packet/types.go index bb2b013..67759e7 100644 --- a/internal/packet/types.go +++ b/internal/packet/types.go @@ -244,8 +244,9 @@ func (m *SetLastReadMessages) Type() PacketType { } type NotificationsInfo struct { - Source []snowflake.ID - Pings []*int64 + Source []snowflake.ID + LastRead []int64 + Pings []*int64 } func (m *NotificationsInfo) Type() PacketType { diff --git a/internal/server/api/helpers.go b/internal/server/api/helpers.go index 27c6f55..2daeb9f 100644 --- a/internal/server/api/helpers.go +++ b/internal/server/api/helpers.go @@ -148,7 +148,7 @@ permitted_frequencies AS ( WHERE m.is_member = true AND (f.perms != 0 OR m.is_admin = true) ) SELECT - e.source_id, + e.source_id, e.last_read, CASE WHEN COUNT(m.id) = 0 THEN NULL ELSE SUM(CASE WHEN (m.ping = 0 OR (m.ping = 1 AND pf.is_admin = true) OR m.ping = ?) THEN 1 ELSE 0 END) @@ -173,11 +173,13 @@ func getNotifications(ctx context.Context, userId snowflake.ID) (packet.Notifica var items packet.NotificationsInfo for rows.Next() { var source *snowflake.ID + var lastRead *int64 var pings *int64 - if err := rows.Scan(&source, &pings); err != nil { + if err := rows.Scan(&source, &lastRead, &pings); err != nil { return packet.NotificationsInfo{}, err } items.Source = append(items.Source, *source) + items.LastRead = append(items.LastRead, *lastRead) items.Pings = append(items.Pings, pings) } if err := rows.Close(); err != nil { |
