-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove push tokens when login tokens are removed
- Loading branch information
1 parent
d05834f
commit 30c6b16
Showing
12 changed files
with
78 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { registerModel } from '@rocket.chat/models'; | ||
|
||
import { db } from '../database/utils'; | ||
import { PushTokenRaw } from './raw/PushToken'; | ||
|
||
registerModel('IPushTokenModel', new PushTokenRaw(db)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { IPushToken } from '@rocket.chat/core-typings'; | ||
import type { IPushTokenModel } from '@rocket.chat/model-typings'; | ||
import type { Db, DeleteWriteOpResultObject, IndexSpecification } from 'mongodb'; | ||
|
||
import { BaseRaw } from './BaseRaw'; | ||
|
||
export class PushTokenRaw extends BaseRaw<IPushToken> implements IPushTokenModel { | ||
constructor(db: Db) { | ||
super(db, '_raix_push_app_tokens'); | ||
} | ||
|
||
modelIndexes(): IndexSpecification[] { | ||
return [{ key: { userId: 1, authToken: 1 } }, { key: { appName: 1, token: 1 } }]; | ||
} | ||
|
||
removeByUserIdExceptTokens(userId: string, tokens: string[]): Promise<DeleteWriteOpResultObject> { | ||
return this.deleteMany({ | ||
userId, | ||
authToken: { $nin: tokens }, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { IServiceClass } from './ServiceClass'; | ||
|
||
export type IPushService = IServiceClass; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { PushToken } from '@rocket.chat/models'; | ||
|
||
import { IPushService } from '../../sdk/types/IPushService'; | ||
import { ServiceClassInternal } from '../../sdk/types/ServiceClass'; | ||
|
||
export class PushService extends ServiceClassInternal implements IPushService { | ||
protected name = 'push'; | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.onEvent('watch.users', async ({ id, diff }) => { | ||
if (diff && 'services.resume.loginTokens' in diff) { | ||
const tokens = diff['services.resume.loginTokens'].map(({ hashedToken }: { hashedToken: string }) => hashedToken); | ||
this.cleanUpUserTokens(id, tokens); | ||
} | ||
}); | ||
} | ||
|
||
private async cleanUpUserTokens(userId: string, tokens: string[]): Promise<void> { | ||
await PushToken.removeByUserIdExceptTokens(userId, tokens); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { IPushToken } from '@rocket.chat/core-typings'; | ||
import type { DeleteWriteOpResultObject } from 'mongodb'; | ||
|
||
import type { IBaseModel } from './IBaseModel'; | ||
|
||
export interface IPushTokenModel extends IBaseModel<IPushToken> { | ||
removeByUserIdExceptTokens(userId: string, tokens: string[]): Promise<DeleteWriteOpResultObject>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters