diff --git a/internal/payload/incoming/messages.go b/internal/payload/incoming/messages.go index 3cfa0aaef..ba56136c1 100644 --- a/internal/payload/incoming/messages.go +++ b/internal/payload/incoming/messages.go @@ -18,6 +18,8 @@ type ( Messages struct { ChannelID uint64 `json:"channelId,string"` + FromID uint64 `json:"fromID,string"` + ToID uint64 `json:"toID,string"` FirstID uint64 `json:"firstID,string"` LastID uint64 `json:"lastID,string"` RepliesTo uint64 `json:"repliesTo,string"` diff --git a/sam/repository/message.go b/sam/repository/message.go index 7294e3340..78a21d87f 100644 --- a/sam/repository/message.go +++ b/sam/repository/message.go @@ -115,17 +115,28 @@ func (r *message) FindMessages(filter *types.MessageFilter) (types.MessageSet, e sql += " AND reply_to = 0 " } - if filter.FirstID > 0 || filter.LastID > 0 { - // Fetching (exclusively) range of messages, without reply - if filter.FirstID > 0 { - sql += " AND id > ? " - params = append(params, filter.FirstID) - } + // first, exclusive + if filter.FirstID > 0 { + sql += " AND id > ? " + params = append(params, filter.FirstID) + } - if filter.LastID > 0 { - sql += " AND id < ? " - params = append(params, filter.LastID) - } + // from, inclusive + if filter.FromID > 0 { + sql += " AND id >= ? " + params = append(params, filter.FromID) + } + + // last, exclusive + if filter.LastID > 0 { + sql += " AND id < ? " + params = append(params, filter.LastID) + } + + // to, inclusive + if filter.ToID > 0 { + sql += " AND id <= ? " + params = append(params, filter.ToID) } sql += " AND rel_channel IN " + sqlChannelAccess diff --git a/sam/types/message.go b/sam/types/message.go index 374387fb0..08e039149 100644 --- a/sam/types/message.go +++ b/sam/types/message.go @@ -46,6 +46,12 @@ type ( FirstID uint64 LastID uint64 + // [FromID...ToID, for paging + // + // Include all messages which IDs range from "from" to "to" (inclusive!) + FromID uint64 + ToID uint64 + Limit uint } diff --git a/sam/websocket/session_incoming_message.go b/sam/websocket/session_incoming_message.go index 7414b7da9..d9f5ffe7d 100644 --- a/sam/websocket/session_incoming_message.go +++ b/sam/websocket/session_incoming_message.go @@ -35,6 +35,8 @@ func (s *Session) messageHistory(ctx context.Context, p *incoming.Messages) erro var ( filter = &types.MessageFilter{ ChannelID: p.ChannelID, + FromID: p.FromID, + ToID: p.ToID, FirstID: p.FirstID, LastID: p.LastID,