New & improved channel histroy rest endpoint params

This commit is contained in:
Denis Arh
2019-04-26 07:35:19 +02:00
parent ed078ce456
commit 1a8a7da000
10 changed files with 117 additions and 23 deletions
+26 -2
View File
@@ -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"
}
]
}
+26 -2
View File
@@ -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"
}
]
}
+5 -1
View File
@@ -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
+13 -4
View File
@@ -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)
+5 -1
View File
@@ -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,
}))
}
+24 -4
View File
@@ -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"))
+9
View File
@@ -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 {
+2 -2
View File
@@ -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,
}))
}
+3 -3
View File
@@ -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
//
@@ -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,