mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-23 10:05:01 +02:00
Fix messages query (#46)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
@@ -14,3 +14,5 @@
|
||||
//
|
||||
|
||||
export * from './lq'
|
||||
|
||||
export type { MessageQueryParams } from './types'
|
||||
|
||||
@@ -34,7 +34,7 @@ import type {
|
||||
FindClient
|
||||
} from '@hcengineering/communication-sdk-types'
|
||||
|
||||
import type { FindParams, QueryId, AnyQuery } from './types'
|
||||
import type { FindParams, QueryId, AnyQuery, MessageQueryParams } from './types'
|
||||
import { MessagesQuery } from './messages/query'
|
||||
import { NotificationQuery } from './notifications/query'
|
||||
import { NotificationContextsQuery } from './notification-contexts/query'
|
||||
@@ -76,7 +76,7 @@ export class LiveQueries {
|
||||
}
|
||||
}
|
||||
|
||||
queryMessages(params: FindMessagesParams, callback: PagedQueryCallback<Message>): CreateQueryResult {
|
||||
queryMessages(params: MessageQueryParams, callback: PagedQueryCallback<Message>): CreateQueryResult {
|
||||
return this.createAndStoreQuery<Message, FindMessagesParams, MessagesQuery>(
|
||||
params,
|
||||
callback,
|
||||
|
||||
@@ -652,11 +652,29 @@ export class MessagesQuery implements PagedQuery<Message, MessageQueryParams> {
|
||||
if (tmp) this.result.delete(tmp)
|
||||
this.tmpMessages.delete(eventId)
|
||||
}
|
||||
const lastMessage = this.result.getLast()
|
||||
const firstMessage = this.result.getFirst()
|
||||
|
||||
function shouldResort(order: SortingOrder): boolean {
|
||||
if (firstMessage == null || lastMessage == null) return false
|
||||
if (order === SortingOrder.Ascending) {
|
||||
return lastMessage.created > message.created
|
||||
}
|
||||
return firstMessage.created > message.created
|
||||
}
|
||||
if (this.params.order === SortingOrder.Ascending) {
|
||||
this.result.push(message)
|
||||
} else {
|
||||
this.result.unshift(message)
|
||||
}
|
||||
|
||||
if (shouldResort(this.params.order ?? SortingOrder.Ascending)) {
|
||||
this.result.sort((a, b) =>
|
||||
this.params.order === SortingOrder.Ascending
|
||||
? a.created.getTime() - b.created.getTime()
|
||||
: b.created.getTime() - a.created.getTime()
|
||||
)
|
||||
}
|
||||
await this.notify()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user