Adjust message sorting when doing after/before & from/to filtering
cortezaproject/corteza-webapp-messaging#35
This commit is contained in:
@@ -208,7 +208,14 @@ func (r *message) Find(filter *types.MessageFilter) (types.MessageSet, error) {
|
||||
sql += " AND rel_channel IN " + sqlChannelAccess
|
||||
params = append(params, filter.CurrentUserID, types.ChannelTypePublic)
|
||||
|
||||
sql += " ORDER BY id DESC"
|
||||
if filter.AfterID > 0 || filter.FromID > 0 || filter.BeforeID > 0 || filter.ToID > 0 {
|
||||
// When filtering by after/before & from/to we're relying order of messages
|
||||
// so let's make sure that they are sorted properly
|
||||
sql += " ORDER BY id ASC"
|
||||
} else {
|
||||
// By default, we just take last N messages.
|
||||
sql += " ORDER BY id DESC"
|
||||
}
|
||||
|
||||
sql += " LIMIT ? "
|
||||
params = append(params, filter.Limit)
|
||||
|
||||
Reference in New Issue
Block a user