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",
|
"name": "schedule-parser-next",
|
||||||
"version": "1.3.1",
|
"version": "1.3.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "schedule-parser-next",
|
"name": "schedule-parser-next",
|
||||||
"version": "1.3.1",
|
"version": "1.3.2",
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs/cache-manager": "^2.2.2",
|
"@nestjs/cache-manager": "^2.2.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "schedule-parser-next",
|
"name": "schedule-parser-next",
|
||||||
"version": "1.3.1",
|
"version": "1.3.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "N08I40K",
|
"author": "N08I40K",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ import { isSemVer } from "class-validator";
|
|||||||
@Controller("api/v1/fcm")
|
@Controller("api/v1/fcm")
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
export class FirebaseAdminController {
|
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) {}
|
constructor(private readonly firebaseAdminService: FirebaseAdminService) {}
|
||||||
|
|
||||||
@@ -37,10 +38,11 @@ export class FirebaseAdminController {
|
|||||||
await this.firebaseAdminService.updateToken(user, token)
|
await this.firebaseAdminService.updateToken(user, token)
|
||||||
).userDto;
|
).userDto;
|
||||||
|
|
||||||
await this.firebaseAdminService.subscribe(
|
await this.firebaseAdminService
|
||||||
updatedUser,
|
.subscribe(updatedUser, this.defaultTopics, true)
|
||||||
this.defaultTopics,
|
.then((userDto) =>
|
||||||
);
|
this.firebaseAdminService.unsubscribe(userDto, this.oldTopics),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("update-callback/:version")
|
@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 fcm = user.fcm;
|
||||||
const currentTopics = new Set(fcm.topics);
|
const currentTopics = new Set(fcm.topics);
|
||||||
|
|
||||||
for (const topic of 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);
|
await this.messaging.subscribeToTopic(fcm.token, topic);
|
||||||
currentTopics.add(topic);
|
currentTopics.add(topic);
|
||||||
@@ -106,7 +110,7 @@ export class FirebaseAdminService implements OnModuleInit {
|
|||||||
version: string,
|
version: string,
|
||||||
topics: Set<string>,
|
topics: Set<string>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.subscribe(userDto, topics).then(async (userDto) => {
|
await this.subscribe(userDto, topics, true).then(async (userDto) => {
|
||||||
await this.usersService.update({
|
await this.usersService.update({
|
||||||
where: { id: userDto.id },
|
where: { id: userDto.id },
|
||||||
data: { version: version },
|
data: { version: version },
|
||||||
|
|||||||
Reference in New Issue
Block a user