From 698b44614ef3b0e7375cb7a9bb128a7e615da8bb Mon Sep 17 00:00:00 2001 From: Kristina Date: Thu, 18 Sep 2025 07:16:03 +0400 Subject: [PATCH] Fix directs order (#9885) --- .../src/components/ChatNavigation.svelte | 3 -- server-plugins/card-resources/src/index.ts | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/plugins/chat-resources/src/components/ChatNavigation.svelte b/plugins/chat-resources/src/components/ChatNavigation.svelte index f0bdaa5251..34cd5b34d8 100644 --- a/plugins/chat-resources/src/components/ChatNavigation.svelte +++ b/plugins/chat-resources/src/components/ChatNavigation.svelte @@ -116,9 +116,6 @@ { type: communication.type.Direct, order: 2 } ], fixedTypes: [chat.masterTag.Thread, communication.type.Direct], - specialSorting: { - [communication.type.Direct]: 'alphabetical' - }, allowCreate: true, defaultSorting: 'recent', lookback: '2w', diff --git a/server-plugins/card-resources/src/index.ts b/server-plugins/card-resources/src/index.ts index ebee2ab0ad..36d5fb046d 100644 --- a/server-plugins/card-resources/src/index.ts +++ b/server-plugins/card-resources/src/index.ts @@ -380,6 +380,37 @@ async function OnCardUpdate (ctx: TxUpdateDoc[], control: TriggerControl): }) } + res.push(...(await updatePeers(control, doc, updateTx))) + return res +} + +async function updatePeers (control: TriggerControl, doc: Card, updateTx: TxUpdateDoc): Promise { + if (updateTx.space === core.space.DerivedTx) return [] + const isDirect = control.hierarchy.isDerived(doc._class, communication.type.Direct) + const isThreadFromDirect = (doc.parentInfo ?? []).some((it) => + control.hierarchy.isDerived(it._class, communication.type.Direct) + ) + + if (!isDirect && !isThreadFromDirect) return [] + + delete updateTx.operations.title + delete updateTx.operations.parentInfo + delete updateTx.operations.parent + delete updateTx.operations.$inc + + const peers = ( + ( + await control.domainRequest(control.ctx, 'communication' as OperationDomain, { + findPeers: { params: { kind: 'card', cardId: doc._id } } + }) + ).value as CardPeer[] + ).flatMap((it) => it.members) + + const res: Tx[] = [] + for (const peer of peers) { + res.push(control.txFactory.createTxUpdateDoc(doc._class, peer.extra.space, peer.cardId, updateTx.operations)) + } + return res }