mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-03 11:01:20 +01:00
fix: closes #13240, move the updatedTeaser to the top of the recent chat list
This commit is contained in:
@@ -667,6 +667,15 @@ define('forum/chats', [
|
||||
if (!ajaxify.data.template.chats || !app.user.userslug) {
|
||||
return;
|
||||
}
|
||||
|
||||
function moveChatAndHrToTop(roomEl) {
|
||||
const hr = roomEl.next('hr');
|
||||
components.get('chat/recent').prepend(roomEl);
|
||||
if (hr.length) {
|
||||
roomEl.after(hr);
|
||||
}
|
||||
}
|
||||
|
||||
const roomEl = chatNavWrapper.find(`[data-roomid="${roomId}"]`);
|
||||
if (roomEl.length) {
|
||||
const html = await app.parseAndTranslate('partials/chats/room-teaser', {
|
||||
@@ -674,16 +683,16 @@ define('forum/chats', [
|
||||
});
|
||||
roomEl.find('[component="chat/room/teaser"]').html(html[0].outerHTML);
|
||||
roomEl.find('.timeago').timeago();
|
||||
moveChatAndHrToTop(roomEl);
|
||||
} 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);
|
||||
moveChatAndHrToTop(html);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -39,22 +39,24 @@ define('forum/chats/events', [
|
||||
if (chatModule.isFromBlockedUser(data.fromUid)) {
|
||||
return;
|
||||
}
|
||||
if (parseInt(data.roomId, 10) === parseInt(ajaxify.data.roomId, 10)) {
|
||||
data.self = parseInt(app.user.uid, 10) === parseInt(data.fromUid, 10) ? 1 : 0;
|
||||
data.self = parseInt(app.user.uid, 10) === parseInt(data.fromUid, 10) ? 1 : 0;
|
||||
data.message.self = data.self;
|
||||
data.message.timestamp = Math.min(Date.now(), data.message.timestamp);
|
||||
data.message.timestampISO = utils.toISOString(data.message.timestamp);
|
||||
const isMessageForCurrentRoom = parseInt(data.roomId, 10) === parseInt(ajaxify.data.roomId, 10);
|
||||
|
||||
if (isMessageForCurrentRoom) {
|
||||
if (!Chats.newMessage) {
|
||||
Chats.newMessage = data.self === 0;
|
||||
}
|
||||
data.message.self = data.self;
|
||||
data.message.timestamp = Math.min(Date.now(), data.message.timestamp);
|
||||
data.message.timestampISO = utils.toISOString(data.message.timestamp);
|
||||
messages.appendChatMessage($('[component="chat/message/content"]'), data.message);
|
||||
|
||||
Chats.updateTeaser(data.roomId, {
|
||||
content: utils.stripHTMLTags(utils.decodeHTMLEntities(data.message.content)),
|
||||
user: data.message.fromUser,
|
||||
timestampISO: data.message.timestampISO,
|
||||
});
|
||||
messages.appendChatMessage($('[component="chat/message/content"]'), data.message);
|
||||
}
|
||||
Chats.updateTeaser(data.roomId, {
|
||||
content: utils.stripHTMLTags(utils.decodeHTMLEntities(data.message.content)),
|
||||
user: data.message.fromUser,
|
||||
timestampISO: data.message.timestampISO,
|
||||
});
|
||||
}
|
||||
|
||||
function publicChatUnread(data) {
|
||||
|
||||
Reference in New Issue
Block a user