mirror of
https://github.com/n08i40k/schedule-parser-next.git
synced 2025-12-06 09:47:46 +03:00
1.3.2
Фикс подписки пользователя на уведомления.
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "schedule-parser-next",
|
||||
"version": "1.3.1",
|
||||
"version": "1.3.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "schedule-parser-next",
|
||||
"version": "1.3.1",
|
||||
"version": "1.3.2",
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@nestjs/cache-manager": "^2.2.2",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "schedule-parser-next",
|
||||
"version": "1.3.1",
|
||||
"version": "1.3.2",
|
||||
"description": "",
|
||||
"author": "N08I40K",
|
||||
"private": true,
|
||||
|
||||
@@ -20,7 +20,8 @@ import { isSemVer } from "class-validator";
|
||||
@Controller("api/v1/fcm")
|
||||
@UseGuards(AuthGuard)
|
||||
export class FirebaseAdminController {
|
||||
private readonly defaultTopics = new Set(["schedule-update", "app-update"]);
|
||||
private readonly oldTopics = new Set(["app-update", "schedule-update"]);
|
||||
private readonly defaultTopics = new Set(["common"]);
|
||||
|
||||
constructor(private readonly firebaseAdminService: FirebaseAdminService) {}
|
||||
|
||||
@@ -37,10 +38,11 @@ export class FirebaseAdminController {
|
||||
await this.firebaseAdminService.updateToken(user, token)
|
||||
).userDto;
|
||||
|
||||
await this.firebaseAdminService.subscribe(
|
||||
updatedUser,
|
||||
this.defaultTopics,
|
||||
);
|
||||
await this.firebaseAdminService
|
||||
.subscribe(updatedUser, this.defaultTopics, true)
|
||||
.then((userDto) =>
|
||||
this.firebaseAdminService.unsubscribe(userDto, this.oldTopics),
|
||||
);
|
||||
}
|
||||
|
||||
@Post("update-callback/:version")
|
||||
|
||||
@@ -81,12 +81,16 @@ export class FirebaseAdminService implements OnModuleInit {
|
||||
});
|
||||
}
|
||||
|
||||
async subscribe(user: UserDto, topics: Set<string>): Promise<UserDto> {
|
||||
async subscribe(
|
||||
user: UserDto,
|
||||
topics: Set<string>,
|
||||
force: boolean = false,
|
||||
): Promise<UserDto> {
|
||||
const fcm = user.fcm;
|
||||
const currentTopics = new Set(fcm.topics);
|
||||
|
||||
for (const topic of topics) {
|
||||
if (fcm.topics.includes(topic)) continue;
|
||||
if (fcm.topics.includes(topic) && !force) continue;
|
||||
|
||||
await this.messaging.subscribeToTopic(fcm.token, topic);
|
||||
currentTopics.add(topic);
|
||||
@@ -106,7 +110,7 @@ export class FirebaseAdminService implements OnModuleInit {
|
||||
version: string,
|
||||
topics: Set<string>,
|
||||
): Promise<void> {
|
||||
await this.subscribe(userDto, topics).then(async (userDto) => {
|
||||
await this.subscribe(userDto, topics, true).then(async (userDto) => {
|
||||
await this.usersService.update({
|
||||
where: { id: userDto.id },
|
||||
data: { version: version },
|
||||
|
||||
Reference in New Issue
Block a user