mirror of
https://github.com/sergeyyarkov/educt-server.git
synced 2026-10-11 10:19:20 +03:00
feat: delete notifications
This commit is contained in:
parent
cd811195f1
commit
c6472013a3
@ -31,7 +31,13 @@ export interface ServerToClientEvents {
|
|||||||
/**
|
/**
|
||||||
* Chat
|
* Chat
|
||||||
*/
|
*/
|
||||||
'chat:message': (data: { content: string; time: string; from: string; to: string; notificationId: string }) => void;
|
'chat:message': (data: {
|
||||||
|
content: string;
|
||||||
|
time: string;
|
||||||
|
from: string;
|
||||||
|
to: string;
|
||||||
|
notificationId?: string | undefined;
|
||||||
|
}) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClientToServerEvents {
|
export interface ClientToServerEvents {
|
||||||
@ -45,6 +51,11 @@ export interface ClientToServerEvents {
|
|||||||
* Chat
|
* Chat
|
||||||
*/
|
*/
|
||||||
'chat:message': (data: { content: string; to: string }) => void;
|
'chat:message': (data: { content: string; to: string }) => void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notification
|
||||||
|
*/
|
||||||
|
'notification:read': (data: { userId: string; ids: string[] }) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InterServerEvents {}
|
export interface InterServerEvents {}
|
||||||
@ -130,11 +141,17 @@ class WsService {
|
|||||||
|
|
||||||
await this.messageStore.add(userId, to, message);
|
await this.messageStore.add(userId, to, message);
|
||||||
|
|
||||||
|
if (userId !== to) {
|
||||||
const notification = await this.notificationStore.add(to, `You received a new private message`, 'MESSAGE');
|
const notification = await this.notificationStore.add(to, `You received a new private message`, 'MESSAGE');
|
||||||
this.io.to(to).emit('chat:message', { ...message, notificationId: notification.id });
|
this.io.to(to).emit('chat:message', { ...message, notificationId: notification.id });
|
||||||
|
} else {
|
||||||
|
this.io.to(to).emit('chat:message', { ...message });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('notification:read', data => this.notificationStore.del(data.userId, data.ids));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy session on user logout request
|
* Destroy session on user logout request
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -50,6 +50,14 @@ class RedisNotificationStore {
|
|||||||
const notification = (await this.redisClient.hgetall(key)) as NotificationType;
|
const notification = (await this.redisClient.hgetall(key)) as NotificationType;
|
||||||
return notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async del(userId: string, keys: string[]): Promise<number> {
|
||||||
|
const k = keys.map(v => `notification:${v}`);
|
||||||
|
const count = await this.redisClient.zrem(`user:${userId}`, k);
|
||||||
|
await this.redisClient.del(k);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default RedisNotificationStore;
|
export default RedisNotificationStore;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user