feat(dashboard phase1): SSE stream with 15s heartbeat; history paging (50); channel sidebar and nav/footer; OG/Twitter link card endpoint; tail UI rework with infinite scroll and auto-follow pause
This commit is contained in:
parent
a6091b8758
commit
3f94aa7068
3 changed files with 318 additions and 56 deletions
|
|
@ -117,6 +117,39 @@ func (s *Store) ListMessagesSince(ctx context.Context, channel string, since tim
|
|||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// ListMessagesBefore returns up to limit messages for a channel strictly before the given time.
|
||||
// Results are returned in ascending chronological order.
|
||||
func (s *Store) ListMessagesBefore(ctx context.Context, channel string, before time.Time, limit int) ([]Message, error) {
|
||||
if limit <= 0 {
|
||||
limit = 50
|
||||
}
|
||||
rows, err := s.db.QueryContext(ctx,
|
||||
"SELECT id, channel, author, body, at, msgid FROM messages WHERE lower(channel) = lower(?) AND at < ? ORDER BY at DESC LIMIT ?",
|
||||
channel, before.UTC(), limit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var tmp []Message
|
||||
for rows.Next() {
|
||||
var m Message
|
||||
var at time.Time
|
||||
var msgid sql.NullString
|
||||
if err := rows.Scan(&m.ID, &m.Channel, &m.Author, &m.Body, &at, &msgid); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.Time = at
|
||||
if msgid.Valid { m.MsgID = msgid.String }
|
||||
tmp = append(tmp, m)
|
||||
}
|
||||
// Reverse to ascending order
|
||||
for i, j := 0, len(tmp)-1; i < j; i, j = i+1, j-1 {
|
||||
tmp[i], tmp[j] = tmp[j], tmp[i]
|
||||
}
|
||||
return tmp, rows.Err()
|
||||
}
|
||||
|
||||
// ListRecentMessages returns the most recent N messages for a channel.
|
||||
func (s *Store) ListRecentMessages(ctx context.Context, channel string, limit int) ([]Message, error) {
|
||||
if limit <= 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue