Server now also sends the last_read column to the client so the client

so the client can use it to persist notifications
This commit is contained in:
2025-02-04 19:37:06 +02:00
parent 752403fd52
commit f0607f1663
3 changed files with 10 additions and 4 deletions

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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 {