Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions server-plugins/notification-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ export async function pushInboxNotifications (
modifiedOn: Timestamp,
shouldUpdateTimestamp = true
): Promise<TxCreateDoc<InboxNotification> | undefined> {
const context = contexts.find((context) => context.user === receiver._id && context.objectId === objectId)

const context = getDocNotifyContext(control, contexts, objectId, receiver._id)
let docNotifyContextId: Ref<DocNotifyContext>

if (context === undefined) {
Expand Down Expand Up @@ -732,9 +731,7 @@ export async function getNotificationTxes (
)
}
} else {
const context = docNotifyContexts.find(
(context) => context.objectId === message.attachedTo && context.user === receiver.account._id
)
const context = getDocNotifyContext(control, docNotifyContexts, message.attachedTo, receiver.account._id)

if (context === undefined) {
await createNotifyContext(
Expand Down Expand Up @@ -1584,7 +1581,7 @@ async function updateCollaborators (ctx: MeasureContext, control: TriggerControl
for (const addedUser of addedInfo) {
const info = toReceiverInfo(hierarchy, addedUser)
if (info === undefined) continue
const context = contexts.find(({ user }) => user === info._id)
const context = getDocNotifyContext(control, contexts, objectId, info._id)
if (context !== undefined) continue
await createNotifyContext(control, objectId, objectClass, objectSpace, info)
}
Expand Down Expand Up @@ -1701,6 +1698,31 @@ export async function getCollaborators (
}
}

function getDocNotifyContext (
control: TriggerControl,
contexts: DocNotifyContext[],
objectId: Ref<Doc>,
user: Ref<Account>
): DocNotifyContext | undefined {
const context = contexts.find((it) => it.objectId === objectId && it.user === user)

if (context !== undefined) {
return context
}

const txes = [...control.txes.apply, ...control.txes.result, ...control.operationContext.derived.txes] as TxCUD<Doc>[]

for (const tx of txes) {
if (tx._class === core.class.TxCreateDoc && tx.objectClass === notification.class.DocNotifyContext) {
const doc = TxProcessor.createDoc2Doc(tx as TxCreateDoc<DocNotifyContext>)
if (doc.objectId === objectId && doc.user === user) {
return doc
}
}
}
return undefined
}

async function OnActivityMessageRemove (message: ActivityMessage, control: TriggerControl): Promise<Tx[]> {
if (control.removedMap.has(message.attachedTo)) {
return []
Expand Down