-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathservice.ts
More file actions
29 lines (24 loc) · 1020 Bytes
/
service.ts
File metadata and controls
29 lines (24 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { IPushService } from '@rocket.chat/core-services';
import { ServiceClassInternal } from '@rocket.chat/core-services';
import { PushToken } from '@rocket.chat/models';
export class PushService extends ServiceClassInternal implements IPushService {
protected name = 'push';
constructor() {
super();
this.onEvent('watch.users', async (data) => {
// for some reason data.diff can be set to undefined
if (!('diff' in data) || !data.diff || !('services.resume.loginTokens' in data.diff)) {
return;
}
const loginTokens = Array.isArray(data.diff['services.resume.loginTokens']) ? data.diff['services.resume.loginTokens'] : [];
if (data.diff['services.resume.loginTokens'] === undefined || loginTokens.length === 0) {
await PushToken.removeAllByUserId(data.id);
return;
}
const tokens = loginTokens.map(({ hashedToken }: { hashedToken: string }) => hashedToken);
if (tokens.length > 0) {
await PushToken.removeByUserIdExceptTokens(data.id, tokens);
}
});
}
}