|
17 | 17 | import activity, { ActivityMessage, DocUpdateMessage } from '@hcengineering/activity' |
18 | 18 | import chunter, { ChatMessage } from '@hcengineering/chunter' |
19 | 19 | import contact, { |
| 20 | + Employee, |
20 | 21 | getAvatarProviderId, |
21 | 22 | getGravatarUrl, |
22 | 23 | Person, |
@@ -1908,6 +1909,31 @@ async function OnActivityMessageRemove (message: ActivityMessage, control: Trigg |
1908 | 1909 | return res |
1909 | 1910 | } |
1910 | 1911 |
|
| 1912 | +async function OnEmployeeDeactivate (tx: TxCUD<Doc>, control: TriggerControl): Promise<Tx[]> { |
| 1913 | + const actualTx = TxProcessor.extractTx(tx) |
| 1914 | + if (core.class.TxMixin !== actualTx._class) { |
| 1915 | + return [] |
| 1916 | + } |
| 1917 | + const ctx = actualTx as TxMixin<Person, Employee> |
| 1918 | + if (ctx.mixin !== contact.mixin.Employee || ctx.attributes.active !== false) { |
| 1919 | + return [] |
| 1920 | + } |
| 1921 | + |
| 1922 | + const targetAccount = control.modelDb.getAccountByPersonId(ctx.objectId) as PersonAccount[] |
| 1923 | + if (targetAccount.length === 0) return [] |
| 1924 | + |
| 1925 | + const res: Tx[] = [] |
| 1926 | + for (const acc of targetAccount) { |
| 1927 | + const subscriptions = await control.findAll(control.ctx, notification.class.PushSubscription, { |
| 1928 | + user: acc._id |
| 1929 | + }) |
| 1930 | + for (const sub of subscriptions) { |
| 1931 | + res.push(control.txFactory.createTxRemoveDoc(sub._class, sub.space, sub._id)) |
| 1932 | + } |
| 1933 | + } |
| 1934 | + return res |
| 1935 | +} |
| 1936 | + |
1911 | 1937 | async function OnDocRemove (originTx: TxCUD<Doc>, control: TriggerControl): Promise<Tx[]> { |
1912 | 1938 | const tx = TxProcessor.extractTx(originTx) as TxRemoveDoc<Doc> |
1913 | 1939 |
|
@@ -1949,7 +1975,8 @@ export default async () => ({ |
1949 | 1975 | trigger: { |
1950 | 1976 | OnAttributeCreate, |
1951 | 1977 | OnAttributeUpdate, |
1952 | | - OnDocRemove |
| 1978 | + OnDocRemove, |
| 1979 | + OnEmployeeDeactivate |
1953 | 1980 | }, |
1954 | 1981 | function: { |
1955 | 1982 | IsUserInFieldValueTypeMatch: isUserInFieldValueTypeMatch, |
|
0 commit comments