mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
refactor: #12713, update chat teasers even if chat notifications are disabled
This commit is contained in:
@@ -684,31 +684,6 @@ define('forum/chats', [
|
||||
};
|
||||
|
||||
Chats.addSocketListeners = function () {
|
||||
socket.on('event:new_notification', async function (notif) {
|
||||
const { type, roomId } = notif;
|
||||
if (ajaxify.data.template.chats && app.user.userslug && (type === 'new-chat' || type === 'new-group-chat')) {
|
||||
const inRoom = parseInt(roomId, 10) === parseInt(ajaxify.data.roomId, 10);
|
||||
if (inRoom) {
|
||||
return;
|
||||
}
|
||||
const { rooms } = await api.get(`/chats`, { start: 0, perPage: 1 });
|
||||
const room = rooms.find(r => parseInt(r.roomId, 10) === parseInt(roomId, 10));
|
||||
if (room) {
|
||||
const roomEl = chatNavWrapper.find(`[data-roomid="${roomId}"]`);
|
||||
if (roomEl.length) {
|
||||
updateTeaser(roomId, room.teaser);
|
||||
} else {
|
||||
const recentEl = components.get('chat/recent');
|
||||
const html = await app.parseAndTranslate('chats', 'rooms', {
|
||||
rooms: [room],
|
||||
showBottomHr: true,
|
||||
});
|
||||
recentEl.prepend(html);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('event:chats.receive', function (data) {
|
||||
if (chatModule.isFromBlockedUser(data.fromUid)) {
|
||||
return;
|
||||
@@ -723,7 +698,7 @@ define('forum/chats', [
|
||||
data.message.timestampISO = utils.toISOString(data.message.timestamp);
|
||||
messages.appendChatMessage($('[component="chat/message/content"]'), data.message);
|
||||
|
||||
updateTeaser(data.roomId, {
|
||||
Chats.updateTeaser(data.roomId, {
|
||||
content: utils.stripHTMLTags(utils.decodeHTMLEntities(data.message.content)),
|
||||
user: data.message.fromUser,
|
||||
timestampISO: data.message.timestampISO,
|
||||
@@ -731,17 +706,6 @@ define('forum/chats', [
|
||||
}
|
||||
});
|
||||
|
||||
async function updateTeaser(roomId, teaser) {
|
||||
const roomEl = $(`[data-roomid="${roomId}"]`);
|
||||
if (roomEl.length) {
|
||||
const html = await app.parseAndTranslate('partials/chats/room-teaser', {
|
||||
teaser: teaser,
|
||||
});
|
||||
roomEl.find('[component="chat/room/teaser"]').html(html[0].outerHTML);
|
||||
roomEl.find('.timeago').timeago();
|
||||
}
|
||||
}
|
||||
|
||||
socket.on('event:chats.public.unread', function (data) {
|
||||
if (
|
||||
chatModule.isFromBlockedUser(data.fromUid) ||
|
||||
@@ -796,6 +760,31 @@ define('forum/chats', [
|
||||
});
|
||||
};
|
||||
|
||||
Chats.updateTeaser = async function (roomId, teaser) {
|
||||
if (!ajaxify.data.template.chats || !app.user.userslug) {
|
||||
return;
|
||||
}
|
||||
const roomEl = chatNavWrapper.find(`[data-roomid="${roomId}"]`);
|
||||
if (roomEl.length) {
|
||||
const html = await app.parseAndTranslate('partials/chats/room-teaser', {
|
||||
teaser: teaser,
|
||||
});
|
||||
roomEl.find('[component="chat/room/teaser"]').html(html[0].outerHTML);
|
||||
roomEl.find('.timeago').timeago();
|
||||
} else {
|
||||
const { rooms } = await api.get(`/chats`, { start: 0, perPage: 2 });
|
||||
const room = rooms.find(r => parseInt(r.roomId, 10) === parseInt(roomId, 10));
|
||||
if (room) {
|
||||
const recentEl = components.get('chat/recent');
|
||||
const html = await app.parseAndTranslate('chats', 'rooms', {
|
||||
rooms: [room],
|
||||
showBottomHr: true,
|
||||
});
|
||||
recentEl.prepend(html);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Chats.markChatPageElUnread = function (data) {
|
||||
if (!ajaxify.data.template.chats) {
|
||||
return;
|
||||
|
||||
@@ -42,6 +42,7 @@ define('forum/header/chat', [
|
||||
return;
|
||||
}
|
||||
chatPage.markChatPageElUnread(data);
|
||||
chatPage.updateTeaser(data.roomId, data.teaser);
|
||||
}
|
||||
|
||||
let { count } = await api.get('/chats/unread');
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const winston = require('winston');
|
||||
const validator = require('validator');
|
||||
|
||||
const batch = require('../batch');
|
||||
const db = require('../database');
|
||||
@@ -8,6 +9,7 @@ const notifications = require('../notifications');
|
||||
const user = require('../user');
|
||||
const io = require('../socket.io');
|
||||
const plugins = require('../plugins');
|
||||
const utils = require('../utils');
|
||||
|
||||
module.exports = function (Messaging) {
|
||||
Messaging.setUserNotificationSetting = async (uid, roomId, value) => {
|
||||
@@ -66,6 +68,13 @@ module.exports = function (Messaging) {
|
||||
// push unread count only for private rooms
|
||||
if (!isPublic) {
|
||||
const uids = await Messaging.getAllUidsInRoomFromSet(`chat:room:${roomId}:uids:online`);
|
||||
unreadData.teaser = {
|
||||
content: validator.escape(
|
||||
String(utils.stripHTMLTags(utils.decodeHTMLEntities(messageObj.content)))
|
||||
),
|
||||
user: messageObj.fromUser,
|
||||
timestampISO: messageObj.timestampISO,
|
||||
};
|
||||
Messaging.pushUnreadCount(uids, unreadData);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user