TSK-1046 Gmail/telegram messages collaborators TSK-1097 Inbox scroll (#2928)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2023-04-10 15:15:00 +06:00
committed by GitHub
parent d353c0e42d
commit 2c714e33fe
27 changed files with 369 additions and 63 deletions
@@ -33,6 +33,7 @@
"@hcengineering/view": "^0.6.3",
"@hcengineering/login": "^0.6.2",
"@hcengineering/workbench": "^0.6.3",
"@hcengineering/minio": "^0.6.0"
"@hcengineering/minio": "^0.6.0",
"@hcengineering/notification": "^0.6.9"
}
}
+52 -1
View File
@@ -15,6 +15,7 @@
//
import contact, {
Channel,
Contact,
contactId,
Employee,
@@ -38,6 +39,7 @@ import core, {
TxUpdateDoc,
updateAttribute
} from '@hcengineering/core'
import notification, { Collaborators } from '@hcengineering/notification'
import { getMetadata } from '@hcengineering/platform'
import serverCore, { AsyncTriggerControl, TriggerControl } from '@hcengineering/server-core'
import { workbenchId } from '@hcengineering/workbench'
@@ -275,6 +277,54 @@ export async function OnEmployeeUpdate (tx: Tx, control: AsyncTriggerControl): P
return result
}
/**
* @public
*/
export async function OnChannelUpdate (tx: Tx, control: TriggerControl): Promise<Tx[]> {
if (tx._class !== core.class.TxUpdateDoc) {
return []
}
const uTx = tx as TxUpdateDoc<Channel>
if (!control.hierarchy.isDerived(uTx.objectClass, contact.class.Channel)) {
return []
}
const result: Tx[] = []
if (uTx.operations.$inc?.items !== undefined) {
const doc = (await control.findAll(uTx.objectClass, { _id: uTx.objectId }, { limit: 1 }))[0]
if (doc !== undefined) {
if (control.hierarchy.hasMixin(doc, notification.mixin.Collaborators)) {
const collab = control.hierarchy.as(doc, notification.mixin.Collaborators) as Doc as Collaborators
if (collab.collaborators.includes(tx.modifiedBy)) {
result.push(
control.txFactory.createTxMixin(doc._id, doc._class, doc.space, notification.mixin.Collaborators, {
$push: {
collaborators: tx.modifiedBy
}
})
)
}
} else {
control.txFactory.createTxMixin<Doc, Collaborators>(
doc._id,
doc._class,
doc.space,
notification.mixin.Collaborators,
{
collaborators: [tx.modifiedBy]
}
)
result.push()
}
}
}
return result
}
/**
* @public
*/
@@ -317,7 +367,8 @@ export function organizationTextPresenter (doc: Doc): string {
export default async () => ({
trigger: {
OnContactDelete,
OnEmployeeUpdate
OnEmployeeUpdate,
OnChannelUpdate
},
function: {
PersonHTMLPresenter: personHTMLPresenter,
+1
View File
@@ -30,6 +30,7 @@ export const serverContactId = 'server-contact' as Plugin
export default plugin(serverContactId, {
trigger: {
OnContactDelete: '' as Resource<TriggerFunc>,
OnChannelUpdate: '' as Resource<TriggerFunc>,
OnEmployeeUpdate: '' as Resource<AsyncTriggerFunc>
},
function: {
@@ -29,6 +29,7 @@
"@hcengineering/core": "^0.6.22",
"@hcengineering/platform": "^0.6.8",
"@hcengineering/server-core": "^0.6.1",
"@hcengineering/notification": "^0.6.9",
"@hcengineering/contact": "^0.6.12",
"@hcengineering/gmail": "^0.6.5"
}
+47 -9
View File
@@ -23,11 +23,13 @@ import core, {
Hierarchy,
Ref,
Tx,
TxCUD,
TxCreateDoc,
TxProcessor
} from '@hcengineering/core'
import gmail, { Message } from '@hcengineering/gmail'
import { TriggerControl } from '@hcengineering/server-core'
import notification from '@hcengineering/notification'
/**
* @public
@@ -54,6 +56,7 @@ export async function FindMessages (
* @public
*/
export async function OnMessageCreate (tx: Tx, control: TriggerControl): Promise<Tx[]> {
const res: Tx[] = []
const actualTx = TxProcessor.extractTx(tx)
if (actualTx._class !== core.class.TxCreateDoc) {
return []
@@ -67,16 +70,51 @@ export async function OnMessageCreate (tx: Tx, control: TriggerControl): Promise
const message = TxProcessor.createDoc2Doc<Message>(createTx)
const channel = (await control.findAll(contact.class.Channel, { _id: message.attachedTo }, { limit: 1 }))[0]
if (channel === undefined) {
return []
if (channel !== undefined) {
if (channel.lastMessage === undefined || channel.lastMessage < message.sendOn) {
const tx = control.txFactory.createTxUpdateDoc(channel._class, channel.space, channel._id, {
lastMessage: message.sendOn
})
res.push(tx)
}
if (message.incoming) {
const docs = await control.findAll(notification.class.DocUpdates, {
attachedTo: channel._id,
user: message.modifiedBy
})
for (const doc of docs) {
res.push(
control.txFactory.createTxUpdateDoc(doc._class, doc.space, doc._id, {
$push: {
txes: [tx._id as Ref<TxCUD<Doc>>, tx.modifiedOn]
}
})
)
res.push(
control.txFactory.createTxUpdateDoc(doc._class, doc.space, doc._id, {
lastTx: tx._id as Ref<TxCUD<Doc>>,
lastTxTime: tx.modifiedOn,
hidden: false
})
)
}
if (docs.length === 0) {
res.push(
control.txFactory.createTxCreateDoc(notification.class.DocUpdates, notification.space.Notifications, {
user: tx.modifiedBy,
attachedTo: channel._id,
attachedToClass: channel._class,
hidden: false,
lastTx: tx._id as Ref<TxCUD<Doc>>,
lastTxTime: tx.modifiedOn,
txes: [[tx._id as Ref<TxCUD<Doc>>, tx.modifiedOn]]
})
)
}
}
}
if (channel.lastMessage === undefined || channel.lastMessage < message.sendOn) {
const tx = control.txFactory.createTxUpdateDoc(channel._class, channel.space, channel._id, {
lastMessage: message.sendOn
})
return [tx]
}
return []
return res
}
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
@@ -30,6 +30,7 @@
"@hcengineering/platform": "^0.6.8",
"@hcengineering/server-core": "^0.6.1",
"@hcengineering/contact": "^0.6.12",
"@hcengineering/notification": "^0.6.9",
"@hcengineering/telegram": "^0.6.5"
}
}
+48 -9
View File
@@ -23,11 +23,13 @@ import core, {
Hierarchy,
Ref,
Tx,
TxCUD,
TxCreateDoc,
TxProcessor
} from '@hcengineering/core'
import { TriggerControl } from '@hcengineering/server-core'
import telegram, { TelegramMessage } from '@hcengineering/telegram'
import notification from '@hcengineering/notification'
/**
* @public
@@ -54,6 +56,7 @@ export async function FindMessages (
* @public
*/
export async function OnMessageCreate (tx: Tx, control: TriggerControl): Promise<Tx[]> {
const res: Tx[] = []
const actualTx = TxProcessor.extractTx(tx)
if (actualTx._class !== core.class.TxCreateDoc) {
return []
@@ -67,16 +70,52 @@ export async function OnMessageCreate (tx: Tx, control: TriggerControl): Promise
const message = TxProcessor.createDoc2Doc<TelegramMessage>(createTx)
const channel = (await control.findAll(contact.class.Channel, { _id: message.attachedTo }, { limit: 1 }))[0]
if (channel === undefined) {
return []
if (channel !== undefined) {
if (channel.lastMessage === undefined || channel.lastMessage < message.sendOn) {
const tx = control.txFactory.createTxUpdateDoc(channel._class, channel.space, channel._id, {
lastMessage: message.sendOn
})
res.push(tx)
}
if (message.incoming) {
const docs = await control.findAll(notification.class.DocUpdates, {
attachedTo: channel._id,
user: message.modifiedBy
})
for (const doc of docs) {
res.push(
control.txFactory.createTxUpdateDoc(doc._class, doc.space, doc._id, {
$push: {
txes: [tx._id as Ref<TxCUD<Doc>>, tx.modifiedOn]
}
})
)
res.push(
control.txFactory.createTxUpdateDoc(doc._class, doc.space, doc._id, {
lastTx: tx._id as Ref<TxCUD<Doc>>,
lastTxTime: tx.modifiedOn,
hidden: false
})
)
}
if (docs.length === 0) {
res.push(
control.txFactory.createTxCreateDoc(notification.class.DocUpdates, notification.space.Notifications, {
user: tx.modifiedBy,
attachedTo: channel._id,
attachedToClass: channel._class,
hidden: false,
lastTx: tx._id as Ref<TxCUD<Doc>>,
lastTxTime: tx.modifiedOn,
txes: [[tx._id as Ref<TxCUD<Doc>>, tx.modifiedOn]]
})
)
}
}
}
if (channel.lastMessage === undefined || channel.lastMessage < message.sendOn) {
const tx = control.txFactory.createTxUpdateDoc(channel._class, channel.space, channel._id, {
lastMessage: message.sendOn
})
return [tx]
}
return []
return res
}
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type