Move notifications to person spaces (#6263)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina
2024-08-06 16:44:23 +07:00
committed by GitHub
parent b997b0c753
commit 1c1d0bc538
52 changed files with 729 additions and 500 deletions
@@ -1,19 +1,21 @@
import { Account, Doc, Ref, TxOperations } from '@hcengineering/core'
import notification, { DocNotifyContext } from '@hcengineering/notification'
import { IntlString } from '@hcengineering/platform'
import { PersonSpace } from '@hcengineering/contact'
import github from '@hcengineering/github'
export async function createNotification (
client: TxOperations,
forDoc: Doc,
data: { user: Ref<Account>, message: IntlString, props: Record<string, any> }
data: { user: Ref<Account>, space: Ref<PersonSpace>, message: IntlString, props: Record<string, any> }
): Promise<void> {
let docNotifyContext = await client.findOne(notification.class.DocNotifyContext, { attachedTo: forDoc._id })
let docNotifyContext = await client.findOne(notification.class.DocNotifyContext, { objectId: forDoc._id })
if (docNotifyContext?._id === undefined) {
const docNotifyContextId = await client.createDoc(notification.class.DocNotifyContext, forDoc.space, {
attachedTo: forDoc._id,
attachedToClass: forDoc._class,
const docNotifyContextId = await client.createDoc(notification.class.DocNotifyContext, data.space, {
objectId: forDoc._id,
objectClass: forDoc._class,
objectSpace: forDoc.space,
user: data.user,
isPinned: false
})
@@ -21,7 +23,6 @@ export async function createNotification (
}
// Check if we had already same notification send, and just unmark it viewed.
const existing = await client.findOne(notification.class.CommonInboxNotification, {
user: data.user,
message: data.message,
@@ -32,7 +33,7 @@ export async function createNotification (
isViewed: false
})
} else {
await client.createDoc(notification.class.CommonInboxNotification, forDoc.space, {
await client.createDoc(notification.class.CommonInboxNotification, data.space, {
user: data.user,
icon: github.icon.Github,
message: data.message,
+33 -21
View File
@@ -409,13 +409,17 @@ export class PlatformWorker {
const person = (await client.findOne(contact.class.Person, { _id: account.person })) as Person
if (person !== undefined) {
if (!revoke) {
await createNotification(client, person, {
user: account._id,
message: github.string.AuthenticatedWithGithub,
props: {
login: update.login
}
})
const personSpace = await client.findOne(contact.class.PersonSpace, { person: person._id })
if (personSpace !== undefined) {
await createNotification(client, person, {
user: account._id,
space: personSpace._id,
message: github.string.AuthenticatedWithGithub,
props: {
login: update.login
}
})
}
const githubAccount = (await client.findOne(core.class.Account, {
email: 'github:' + update.login
@@ -427,23 +431,31 @@ export class PlatformWorker {
const dPerson = (await client.findOne(contact.class.Person, { _id: dummyPerson })) as Person
if (person !== undefined && dPerson !== undefined) {
await createNotification(client, dPerson, {
user: account._id,
message: github.string.AuthenticatedWithGithubEmployee,
props: {
login: update.login
}
})
const personSpace = await client.findOne(contact.class.PersonSpace, { person: person._id })
if (personSpace !== undefined) {
await createNotification(client, dPerson, {
user: githubAccount._id,
space: personSpace._id,
message: github.string.AuthenticatedWithGithubEmployee,
props: {
login: update.login
}
})
}
}
}
} else {
await createNotification(client, person, {
user: account._id,
message: github.string.AuthenticationRevokedGithub,
props: {
login: update.login
}
})
const personSpace = await client.findOne(contact.class.PersonSpace, { person: person._id })
if (personSpace !== undefined) {
await createNotification(client, person, {
user: account._id,
space: personSpace._id,
message: github.string.AuthenticationRevokedGithub,
props: {
login: update.login
}
})
}
}
}
+9 -5
View File
@@ -543,11 +543,15 @@ export class GithubWorker implements IntegrationManager {
if (accountRef !== undefined) {
const person = await this.client.findOne(contact.class.Person, { _id: accountRef.person })
if (person !== undefined) {
await createNotification(this._client, person, {
user: account,
message: github.string.AuthenticatedWithGithubRequired,
props: {}
})
const personSpace = await this.client.findOne(contact.class.PersonSpace, { person: person._id })
if (personSpace !== undefined) {
await createNotification(this._client, person, {
user: account,
space: personSpace._id,
message: github.string.AuthenticatedWithGithubRequired,
props: {}
})
}
}
}
this.ctx.info('get octokit: return bot', { account })