diff --git a/server/router/api/v1/user_service.go b/server/router/api/v1/user_service.go index 8ca617734..053713307 100644 --- a/server/router/api/v1/user_service.go +++ b/server/router/api/v1/user_service.go @@ -1583,8 +1583,11 @@ func (s *APIV1Service) ListUserNotifications(ctx context.Context, request *v1pb. } // Fetch inbox items from storage + // Filter at database level to only include MEMO_COMMENT notifications (ignore legacy VERSION_UPDATE entries) + memoCommentType := storepb.InboxMessage_MEMO_COMMENT inboxes, err := s.Store.ListInboxes(ctx, &store.FindInbox{ - ReceiverID: &userID, + ReceiverID: &userID, + MessageType: &memoCommentType, }) if err != nil { return nil, status.Errorf(codes.Internal, "failed to list inboxes: %v", err) diff --git a/store/db/mysql/inbox.go b/store/db/mysql/inbox.go index a18fb51f1..ec20a8ebe 100644 --- a/store/db/mysql/inbox.go +++ b/store/db/mysql/inbox.go @@ -60,6 +60,11 @@ func (d *DB) ListInboxes(ctx context.Context, find *store.FindInbox) ([]*store.I if find.Status != nil { where, args = append(where, "`status` = ?"), append(args, *find.Status) } + if find.MessageType != nil { + // Filter by message type using JSON extraction + // Note: The type field in JSON is stored as string representation of the enum name + where, args = append(where, "JSON_EXTRACT(`message`, '$.type') = ?"), append(args, find.MessageType.String()) + } query := "SELECT `id`, UNIX_TIMESTAMP(`created_ts`), `sender_id`, `receiver_id`, `status`, `message` FROM `inbox` WHERE " + strings.Join(where, " AND ") + " ORDER BY `created_ts` DESC" if find.Limit != nil { diff --git a/store/db/postgres/inbox.go b/store/db/postgres/inbox.go index 1777d801d..7df32e287 100644 --- a/store/db/postgres/inbox.go +++ b/store/db/postgres/inbox.go @@ -50,6 +50,11 @@ func (d *DB) ListInboxes(ctx context.Context, find *store.FindInbox) ([]*store.I if find.Status != nil { where, args = append(where, "status = "+placeholder(len(args)+1)), append(args, *find.Status) } + if find.MessageType != nil { + // Filter by message type using PostgreSQL JSON extraction + // Note: The type field in JSON is stored as string representation of the enum name + where, args = append(where, "message->>'type' = "+placeholder(len(args)+1)), append(args, find.MessageType.String()) + } query := "SELECT id, created_ts, sender_id, receiver_id, status, message FROM inbox WHERE " + strings.Join(where, " AND ") + " ORDER BY created_ts DESC" if find.Limit != nil { diff --git a/store/db/sqlite/inbox.go b/store/db/sqlite/inbox.go index 776ed7d0b..2ab8e68d0 100644 --- a/store/db/sqlite/inbox.go +++ b/store/db/sqlite/inbox.go @@ -52,6 +52,11 @@ func (d *DB) ListInboxes(ctx context.Context, find *store.FindInbox) ([]*store.I if find.Status != nil { where, args = append(where, "`status` = ?"), append(args, *find.Status) } + if find.MessageType != nil { + // Filter by message type using JSON extraction + // Note: The type field in JSON is stored as string representation of the enum name + where, args = append(where, "JSON_EXTRACT(`message`, '$.type') = ?"), append(args, find.MessageType.String()) + } query := "SELECT `id`, `created_ts`, `sender_id`, `receiver_id`, `status`, `message` FROM `inbox` WHERE " + strings.Join(where, " AND ") + " ORDER BY `created_ts` DESC" if find.Limit != nil { diff --git a/store/inbox.go b/store/inbox.go index 2df3c19d1..417ea9f86 100644 --- a/store/inbox.go +++ b/store/inbox.go @@ -39,10 +39,11 @@ type UpdateInbox struct { // FindInbox specifies filter criteria for querying inbox items. type FindInbox struct { - ID *int32 - SenderID *int32 - ReceiverID *int32 - Status *InboxStatus + ID *int32 + SenderID *int32 + ReceiverID *int32 + Status *InboxStatus + MessageType *storepb.InboxMessage_Type // Pagination Limit *int