mpp-server-dev2/src/Notification.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-05-28 23:15:00 +02:00
module.exports = class Notification {
constructor (data) {
this.id = data.id;
this.chat = data.chat;
this.refresh = data.refresh;
this.title = data.title;
this.text = data.text;
this.html = data.html;
this.target = data.target;
this.duration = data.duration;
this.class = data.class;
this.id = data.id;
}
send(_id, room) {
2022-07-09 06:28:52 +02:00
let msg = {};
Object.assign(msg, this);
msg.m = "notification";
2021-05-28 23:15:00 +02:00
switch (_id) {
2022-07-09 06:28:52 +02:00
case "all":
2021-05-28 23:15:00 +02:00
for (let con of Array.from(room.server.connections.values())) {
2022-07-09 06:28:52 +02:00
con.sendArray([msg]);
2021-05-28 23:15:00 +02:00
}
break;
2022-07-09 06:28:52 +02:00
case "room":
2022-07-09 11:06:51 +02:00
case "channel":
2021-05-28 23:15:00 +02:00
for (let con of room.connections) {
2022-07-09 06:28:52 +02:00
con.sendArray([msg]);
2021-05-28 23:15:00 +02:00
}
break;
2022-07-09 06:28:52 +02:00
default:
2021-05-28 23:15:00 +02:00
Array.from(room.server.connections.values()).filter((usr) => typeof(usr.user) !== 'undefined' ? usr.user._id == _id : null).forEach((p) => {
2022-07-09 06:28:52 +02:00
p.sendArray([msg]);
2021-05-28 23:15:00 +02:00
});
2022-07-09 06:28:52 +02:00
break;
2021-05-28 23:15:00 +02:00
}
}
}