update: the push service
This commit is contained in:
@@ -18,7 +18,7 @@ export class NajvaPushService {
|
|||||||
|
|
||||||
//===============================================
|
//===============================================
|
||||||
|
|
||||||
async sendPushNotification(tokens: string[], message: INajvaNotificationMessage): Promise<INajvaPushResponse | null> {
|
async sendPushNotification(tokens: string[], message: INajvaNotificationMessage) {
|
||||||
if (!tokens || tokens.length === 0) {
|
if (!tokens || tokens.length === 0) {
|
||||||
this.logger.warn("No tokens provided for push notification");
|
this.logger.warn("No tokens provided for push notification");
|
||||||
return null;
|
return null;
|
||||||
@@ -100,7 +100,7 @@ export class NajvaPushService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//===============================================
|
//===============================================
|
||||||
async sendNotificationToUser(userToken: string, message: INajvaNotificationMessage): Promise<boolean> {
|
async sendNotificationToUser(userToken: string, message: INajvaNotificationMessage) {
|
||||||
try {
|
try {
|
||||||
const result = await this.sendPushNotification([userToken], message);
|
const result = await this.sendPushNotification([userToken], message);
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ export class NajvaPushService {
|
|||||||
}
|
}
|
||||||
//===============================================
|
//===============================================
|
||||||
|
|
||||||
async sendNotificationToMultipleUsers(userTokens: string[], message: INajvaNotificationMessage): Promise<{ success: number; failed: number }> {
|
async sendNotificationToMultipleUsers(userTokens: string[], message: INajvaNotificationMessage) {
|
||||||
try {
|
try {
|
||||||
const result = await this.sendPushNotification(userTokens, message);
|
const result = await this.sendPushNotification(userTokens, message);
|
||||||
|
|
||||||
|
|||||||
@@ -72,10 +72,9 @@ export class NotificationsService {
|
|||||||
...createNotificationDto,
|
...createNotificationDto,
|
||||||
recipient: user,
|
recipient: user,
|
||||||
});
|
});
|
||||||
//
|
|
||||||
await em.persistAndFlush(notification);
|
await em.persistAndFlush(notification);
|
||||||
|
|
||||||
// Send push notification if user has a push token
|
|
||||||
if (user.pushToken) {
|
if (user.pushToken) {
|
||||||
await this.sendPushNotificationToUser(user.pushToken, {
|
await this.sendPushNotificationToUser(user.pushToken, {
|
||||||
title: createNotificationDto.title,
|
title: createNotificationDto.title,
|
||||||
@@ -92,13 +91,13 @@ export class NotificationsService {
|
|||||||
|
|
||||||
//===============================================
|
//===============================================
|
||||||
|
|
||||||
async sendPushNotificationToUser(userToken: string, message: INajvaNotificationMessage): Promise<boolean> {
|
async sendPushNotificationToUser(userToken: string, message: INajvaNotificationMessage) {
|
||||||
return this.najvaPushService.sendNotificationToUser(userToken, message);
|
return this.najvaPushService.sendNotificationToUser(userToken, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===============================================
|
//===============================================
|
||||||
|
|
||||||
async sendPushNotificationToMultipleUsers(userTokens: string[], message: INajvaNotificationMessage): Promise<{ success: number; failed: number }> {
|
async sendPushNotificationToMultipleUsers(userTokens: string[], message: INajvaNotificationMessage) {
|
||||||
return this.najvaPushService.sendNotificationToMultipleUsers(userTokens, message);
|
return this.najvaPushService.sendNotificationToMultipleUsers(userTokens, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user