Channels sotring modifiedOn (#944)

Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov 2022-02-07 15:09:57 +06:00 committed by GitHub
parent dab0f365f5
commit 53713d8c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 7 deletions

View File

@ -63,7 +63,7 @@ export class TContact extends TDoc implements Contact {
}
@Model(contact.class.Channel, core.class.AttachedDoc, DOMAIN_CONTACT)
@UX('Channel' as IntlString, contact.icon.Person)
@UX('Channel' as IntlString, contact.icon.Person, undefined, 'modifiedOn')
export class TChannel extends TAttachedDoc implements Channel {
@Prop(TypeRef(contact.class.ChannelProvider), 'Channel provider' as IntlString)
provider!: Ref<ChannelProvider>

View File

@ -2,7 +2,7 @@ import { DocumentQuery } from '.'
import { Doc } from './classes'
import { getObjectValue } from './objvalue'
import { createPredicates, isPredicate } from './predicate'
import { SortingQuery } from './storage'
import { SortingOrder, SortingQuery } from './storage'
/**
* @public
@ -37,27 +37,33 @@ export function resultSort<T extends Doc> (result: T[], sortOptions: SortingQuer
for (const key in sortOptions) {
const aValue = getValue(key, a)
const bValue = getValue(key, b)
const result = getSortingResult(aValue, bValue)
if (result !== 0) return result * (sortOptions[key] as number)
const result = getSortingResult(aValue, bValue, (sortOptions[key] as SortingOrder))
if (result !== 0) return result
}
return 0
}
result.sort(sortFunc)
}
function getSortingResult (aValue: any, bValue: any): number {
function getSortingResult (aValue: any, bValue: any, order: SortingOrder): number {
let res = 0
if (typeof aValue === 'undefined') {
return typeof bValue === 'undefined' ? 0 : -1
}
if (typeof bValue === 'undefined') {
return 1
}
return typeof aValue === 'string' ? aValue.localeCompare(bValue) : (aValue - bValue)
if (Array.isArray(aValue) && Array.isArray(bValue)) {
res = (aValue.sort((a, b) => (a - b) * order)[0] ?? 0) - (bValue.sort((a, b) => (a - b) * order)[0] ?? 0)
} else {
res = typeof aValue === 'string' ? aValue.localeCompare(bValue) : (aValue - bValue)
}
return res * order
}
function getValue (key: string, obj: any): any {
let value = getObjectValue(key, obj)
if (typeof value === 'object') {
if (typeof value === 'object' && !Array.isArray(value)) {
value = JSON.stringify(value)
}
return value

View File

@ -253,6 +253,9 @@ export class LiveQuery extends TxProcessor implements Client {
needCallback = this.proccesLookupUpdateDoc(q.result, lookup, tx)
if (needCallback) {
if (q.options?.sort !== undefined) {
resultSort(q.result, q.options?.sort)
}
q.callback(this.clone(q.result))
}
}
@ -408,6 +411,9 @@ export class LiveQuery extends TxProcessor implements Client {
needCallback = this.proccesLookupAddDoc(q.result, lookup, doc)
if (needCallback) {
if (q.options?.sort !== undefined) {
resultSort(q.result, q.options?.sort)
}
q.callback(this.clone(q.result))
}
}
@ -501,6 +507,9 @@ export class LiveQuery extends TxProcessor implements Client {
}
}
if (needCallback) {
if (q.options?.sort !== undefined) {
resultSort(q.result, q.options?.sort)
}
q.callback(this.clone(q.result))
}
}