chan: remove cast in pushMessage

This commit is contained in:
Reto Brunner 2024-04-14 02:38:00 +02:00
parent bb7c3925c6
commit 540144c417

View file

@ -61,18 +61,13 @@ class Chan {
} }
pushMessage(client: Client, msg: Msg, increasesUnread = false) { pushMessage(client: Client, msg: Msg, increasesUnread = false) {
const chan = this.id; const chanId = this.id;
const obj = {chan, msg} as { const obj = {chan: chanId, msg, unread: undefined, highlight: undefined};
chan: number;
msg: Msg;
unread?: number;
highlight?: number;
};
msg.id = client.idMsg++; msg.id = client.idMsg++;
// If this channel is open in any of the clients, do not increase unread counter // If this channel is open in any of the clients, do not increase unread counter
const isOpen = _.find(client.attachedClients, {openChannel: chan}) !== undefined; const isOpen = _.find(client.attachedClients, {openChannel: chanId}) !== undefined;
if (msg.self) { if (msg.self) {
// reset counters/markers when receiving self-/echo-message // reset counters/markers when receiving self-/echo-message
@ -85,15 +80,15 @@ class Chan {
} }
if (increasesUnread || msg.highlight) { if (increasesUnread || msg.highlight) {
obj.unread = ++this.unread; this.unread++;
} }
if (msg.highlight) { if (msg.highlight) {
obj.highlight = ++this.highlight; this.highlight++;
} }
} }
client.emit("msg", obj); client.emit("msg", {chan: chanId, msg, unread: this.unread, highlight: this.highlight});
// Never store messages in public mode as the session // Never store messages in public mode as the session
// is completely destroyed when the page gets closed // is completely destroyed when the page gets closed