fix: history gossip not triggering for pre-feature messages
Two bugs: 1. RecentMessagesSince had msg_id IS NOT NULL filter — messages sent before EXT-007 deployment all have msg_id=NULL so nothing was returned. Removed the filter; mid-based INSERT OR IGNORE dedup is sufficient. 2. queryMessages didn't SELECT room, so gossipped messages had empty room field. Added room to SELECT and Scan in queryMessages. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -107,7 +107,7 @@ func (s *Store) PeerAlias(peerID proto.PeerID) string {
|
|||||||
// RecentMessages returns up to limit messages for a room, oldest first.
|
// RecentMessages returns up to limit messages for a room, oldest first.
|
||||||
func (s *Store) RecentMessages(room string, limit int) ([]proto.ChatMessage, error) {
|
func (s *Store) RecentMessages(room string, limit int) ([]proto.ChatMessage, error) {
|
||||||
return s.queryMessages(
|
return s.queryMessages(
|
||||||
`SELECT mid, from_peer, body, sent_at FROM messages
|
`SELECT mid, from_peer, room, body, sent_at FROM messages
|
||||||
WHERE room = ?
|
WHERE room = ?
|
||||||
ORDER BY sent_at DESC LIMIT ?`,
|
ORDER BY sent_at DESC LIMIT ?`,
|
||||||
room, limit,
|
room, limit,
|
||||||
@@ -115,15 +115,23 @@ func (s *Store) RecentMessages(room string, limit int) ([]proto.ChatMessage, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RecentMessagesSince returns up to limit messages for a room with ts > sinceMs, oldest first.
|
// RecentMessagesSince returns up to limit messages for a room with ts > sinceMs, oldest first.
|
||||||
// Only messages that have a msg_id (i.e. gossip-safe) are returned.
|
// sinceMs == 0 returns the most recent messages regardless of timestamp.
|
||||||
func (s *Store) RecentMessagesSince(room string, sinceMs int64, limit int) ([]proto.ChatMessage, error) {
|
func (s *Store) RecentMessagesSince(room string, sinceMs int64, limit int) ([]proto.ChatMessage, error) {
|
||||||
if limit <= 0 || limit > 500 {
|
if limit <= 0 || limit > 500 {
|
||||||
limit = 500
|
limit = 500
|
||||||
}
|
}
|
||||||
|
if sinceMs == 0 {
|
||||||
|
return s.queryMessages(
|
||||||
|
`SELECT mid, from_peer, room, body, sent_at FROM messages
|
||||||
|
WHERE room = ?
|
||||||
|
ORDER BY sent_at DESC LIMIT ?`,
|
||||||
|
room, limit,
|
||||||
|
)
|
||||||
|
}
|
||||||
since := time.UnixMilli(sinceMs).UTC()
|
since := time.UnixMilli(sinceMs).UTC()
|
||||||
return s.queryMessages(
|
return s.queryMessages(
|
||||||
`SELECT mid, from_peer, body, sent_at FROM messages
|
`SELECT mid, from_peer, room, body, sent_at FROM messages
|
||||||
WHERE room = ? AND sent_at > ? AND msg_id IS NOT NULL
|
WHERE room = ? AND sent_at > ?
|
||||||
ORDER BY sent_at DESC LIMIT ?`,
|
ORDER BY sent_at DESC LIMIT ?`,
|
||||||
room, since, limit,
|
room, since, limit,
|
||||||
)
|
)
|
||||||
@@ -141,7 +149,7 @@ func (s *Store) queryMessages(q string, args ...any) ([]proto.ChatMessage, error
|
|||||||
var m proto.ChatMessage
|
var m proto.ChatMessage
|
||||||
var from string
|
var from string
|
||||||
var sentAt time.Time
|
var sentAt time.Time
|
||||||
if err := rows.Scan(&m.Mid, &from, &m.Text, &sentAt); err != nil {
|
if err := rows.Scan(&m.Mid, &from, &m.Room, &m.Text, &sentAt); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m.From = proto.PeerID(from)
|
m.From = proto.PeerID(from)
|
||||||
|
|||||||
Reference in New Issue
Block a user