3
0

More options for msg search queries

This commit is contained in:
Denis Arh 2018-11-01 14:34:08 +01:00
parent 52cd5d33da
commit 71986df8d3
4 changed files with 31 additions and 10 deletions

View File

@ -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"`

View File

@ -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

View File

@ -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
}

View File

@ -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,