diff --git a/api/messaging/spec.json b/api/messaging/spec.json index 5d646b263..d79db23e5 100644 --- a/api/messaging/spec.json +++ b/api/messaging/spec.json @@ -410,10 +410,34 @@ "parameters": { "get": [ { - "name": "lastMessageID", + "name": "afterMessageID", "type": "uint64", "required": false, - "title": "" + "title": "ID of the first message in the list (exclusive)" + }, + { + "name": "beforeMessageID", + "type": "uint64", + "required": false, + "title": "ID of the last message in the list (exclusive)" + }, + { + "name": "fromMessageID", + "type": "uint64", + "required": false, + "title": "ID of the first message in the list (inclusive)" + }, + { + "name": "toMessageID", + "type": "uint64", + "required": false, + "title": "ID of the last message the list (inclusive)" + }, + { + "name": "limit", + "type": "uint", + "required": false, + "title": "Number of messages to get" } ] } diff --git a/api/messaging/spec/message.json b/api/messaging/spec/message.json index 8ca4bcd1c..db47d0fd0 100644 --- a/api/messaging/spec/message.json +++ b/api/messaging/spec/message.json @@ -73,10 +73,34 @@ "Parameters": { "get": [ { - "name": "lastMessageID", + "name": "afterMessageID", "required": false, - "title": "", + "title": "ID of the first message in the list (exclusive)", "type": "uint64" + }, + { + "name": "beforeMessageID", + "required": false, + "title": "ID of the last message in the list (exclusive)", + "type": "uint64" + }, + { + "name": "fromMessageID", + "required": false, + "title": "ID of the first message in the list (inclusive)", + "type": "uint64" + }, + { + "name": "toMessageID", + "required": false, + "title": "ID of the last message the list (inclusive)", + "type": "uint64" + }, + { + "name": "limit", + "required": false, + "title": "Number of messages to get", + "type": "uint" } ] } diff --git a/docs/messaging/README.md b/docs/messaging/README.md index bbfc196c4..efb2966a1 100644 --- a/docs/messaging/README.md +++ b/docs/messaging/README.md @@ -358,7 +358,11 @@ The following event types may be sent with a message event: | Parameter | Type | Method | Description | Default | Required? | | --------- | ---- | ------ | ----------- | ------- | --------- | -| lastMessageID | uint64 | GET | | N/A | NO | +| afterMessageID | uint64 | GET | ID of the first message in the list (exclusive) | N/A | NO | +| beforeMessageID | uint64 | GET | ID of the last message in the list (exclusive) | N/A | NO | +| fromMessageID | uint64 | GET | ID of the first message in the list (inclusive) | N/A | NO | +| toMessageID | uint64 | GET | ID of the last message the list (inclusive) | N/A | NO | +| limit | uint | GET | Number of messages to get | N/A | NO | | channelID | uint64 | PATH | Channel ID | N/A | YES | ## Manages read/unread messages in a channel or a thread diff --git a/messaging/internal/repository/message.go b/messaging/internal/repository/message.go index 072ee4045..5ca84ddb4 100644 --- a/messaging/internal/repository/message.go +++ b/messaging/internal/repository/message.go @@ -141,9 +141,9 @@ func (r *message) Find(filter *types.MessageFilter) (types.MessageSet, error) { } // first, exclusive - if filter.FirstID > 0 { + if filter.AfterID > 0 { sql += " AND id > ? " - params = append(params, filter.FirstID) + params = append(params, filter.AfterID) } // from, inclusive @@ -153,9 +153,9 @@ func (r *message) Find(filter *types.MessageFilter) (types.MessageSet, error) { } // last, exclusive - if filter.LastID > 0 { + if filter.BeforeID > 0 { sql += " AND id < ? " - params = append(params, filter.LastID) + params = append(params, filter.BeforeID) } // to, inclusive @@ -174,6 +174,15 @@ func (r *message) Find(filter *types.MessageFilter) (types.MessageSet, error) { } } + if filter.AttachmentsOnly { + sql += " AND type IN (?, ?) " + params = append( + params, + types.MessageTypeAttachment, + types.MessageTypeInlineImage, + ) + } + sql += " AND rel_channel IN " + sqlChannelAccess params = append(params, filter.CurrentUserID, types.ChannelTypePublic) diff --git a/messaging/rest/message.go b/messaging/rest/message.go index 49c42dae5..aec51e16c 100644 --- a/messaging/rest/message.go +++ b/messaging/rest/message.go @@ -53,7 +53,11 @@ func (ctrl *Message) ReplyGet(ctx context.Context, r *request.MessageReplyGet) ( func (ctrl *Message) History(ctx context.Context, r *request.MessageHistory) (interface{}, error) { return ctrl.wrapSet(ctx)(ctrl.svc.msg.With(ctx).Find(&types.MessageFilter{ ChannelID: r.ChannelID, - FirstID: r.LastMessageID, + AfterID: r.AfterMessageID, + BeforeID: r.BeforeMessageID, + FromID: r.FromMessageID, + ToID: r.ToMessageID, + Limit: r.Limit, })) } diff --git a/messaging/rest/request/message.go b/messaging/rest/request/message.go index 2736257ad..6e30d1c48 100644 --- a/messaging/rest/request/message.go +++ b/messaging/rest/request/message.go @@ -131,8 +131,12 @@ var _ RequestFiller = NewMessageExecuteCommand() // Message history request parameters type MessageHistory struct { - LastMessageID uint64 `json:",string"` - ChannelID uint64 `json:",string"` + AfterMessageID uint64 `json:",string"` + BeforeMessageID uint64 `json:",string"` + FromMessageID uint64 `json:",string"` + ToMessageID uint64 `json:",string"` + Limit uint + ChannelID uint64 `json:",string"` } func NewMessageHistory() *MessageHistory { @@ -166,9 +170,25 @@ func (mReq *MessageHistory) Fill(r *http.Request) (err error) { post[name] = string(param[0]) } - if val, ok := get["lastMessageID"]; ok { + if val, ok := get["afterMessageID"]; ok { - mReq.LastMessageID = parseUInt64(val) + mReq.AfterMessageID = parseUInt64(val) + } + if val, ok := get["beforeMessageID"]; ok { + + mReq.BeforeMessageID = parseUInt64(val) + } + if val, ok := get["fromMessageID"]; ok { + + mReq.FromMessageID = parseUInt64(val) + } + if val, ok := get["toMessageID"]; ok { + + mReq.ToMessageID = parseUInt64(val) + } + if val, ok := get["limit"]; ok { + + mReq.Limit = parseUint(val) } mReq.ChannelID = parseUInt64(chi.URLParam(r, "channelID")) diff --git a/messaging/rest/request/util.go b/messaging/rest/request/util.go index f8b7fda70..21521e4f2 100644 --- a/messaging/rest/request/util.go +++ b/messaging/rest/request/util.go @@ -44,6 +44,15 @@ func parseUInt64(s string) uint64 { return i } +// parseUInt64 parses a string to uint64 +func parseUint(s string) uint { + if s == "" { + return 0 + } + i, _ := strconv.ParseUint(s, 10, 32) + return uint(i) +} + func parseUInt64A(values []string) []uint64 { var result []uint64 if values != nil && len(values) > 0 { diff --git a/messaging/rest/search.go b/messaging/rest/search.go index ef8dcbe8d..c9a86f274 100644 --- a/messaging/rest/search.go +++ b/messaging/rest/search.go @@ -32,8 +32,8 @@ func (ctrl *Search) Messages(ctx context.Context, r *request.SearchMessages) (in Query: r.Query, ChannelID: r.InChannel, UserID: r.FromUser, - FirstID: r.FirstID, - LastID: r.LastID, + AfterID: r.FirstID, + BeforeID: r.LastID, })) } diff --git a/messaging/types/message.go b/messaging/types/message.go index 65cdc00c1..42d5e0c5b 100644 --- a/messaging/types/message.go +++ b/messaging/types/message.go @@ -56,11 +56,11 @@ type ( // Return all replies to a single message RepliesTo uint64 - // (FirstID...LastID), for paging + // (AfterID...BeforeID), for paging // // Include all messages which IDs range from "first" to "last" (exclusive!) - FirstID uint64 - LastID uint64 + AfterID uint64 + BeforeID uint64 // [FromID...ToID, for paging // diff --git a/messaging/websocket/session_incoming_message.go b/messaging/websocket/session_incoming_message.go index 23fbbb9d9..6949fd3b9 100644 --- a/messaging/websocket/session_incoming_message.go +++ b/messaging/websocket/session_incoming_message.go @@ -37,8 +37,8 @@ func (s *Session) messageHistory(ctx context.Context, p *incoming.Messages) erro ChannelID: p.ChannelID, FromID: p.FromID, ToID: p.ToID, - FirstID: p.FirstID, - LastID: p.LastID, + AfterID: p.FirstID, + BeforeID: p.LastID, RepliesTo: p.RepliesTo, @@ -64,8 +64,8 @@ func (s *Session) messageThreads(ctx context.Context, p *incoming.MessageThreads var ( filter = &types.MessageFilter{ ChannelID: p.ChannelID, - FirstID: p.FirstID, - LastID: p.LastID, + AfterID: p.FirstID, + BeforeID: p.LastID, // Max no. of messages we will return Limit: 50,