@@ -99,6 +99,13 @@ const (
99
99
WHERE topic = ? AND (id > ? OR published = 0)
100
100
ORDER BY time, id
101
101
`
102
+ selectMessagesLatestQuery = `
103
+ SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, content_type, encoding
104
+ FROM messages
105
+ WHERE topic = ? AND published = 1
106
+ ORDER BY time DESC, id DESC
107
+ LIMIT 1
108
+ `
102
109
selectMessagesDueQuery = `
103
110
SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, content_type, encoding
104
111
FROM messages
@@ -416,6 +423,8 @@ func (c *messageCache) addMessages(ms []*message) error {
416
423
func (c * messageCache ) Messages (topic string , since sinceMarker , scheduled bool ) ([]* message , error ) {
417
424
if since .IsNone () {
418
425
return make ([]* message , 0 ), nil
426
+ } else if since .IsLatest () {
427
+ return c .messagesLatest (topic )
419
428
} else if since .IsID () {
420
429
return c .messagesSinceID (topic , since , scheduled )
421
430
}
@@ -462,6 +471,14 @@ func (c *messageCache) messagesSinceID(topic string, since sinceMarker, schedule
462
471
return readMessages (rows )
463
472
}
464
473
474
+ func (c * messageCache ) messagesLatest (topic string ) ([]* message , error ) {
475
+ rows , err := c .db .Query (selectMessagesLatestQuery , topic )
476
+ if err != nil {
477
+ return nil , err
478
+ }
479
+ return readMessages (rows )
480
+ }
481
+
465
482
func (c * messageCache ) MessagesDue () ([]* message , error ) {
466
483
rows , err := c .db .Query (selectMessagesDueQuery , time .Now ().Unix ())
467
484
if err != nil {
0 commit comments