mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-04 03:21:18 +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) {
|
if (!ajaxify.data.template.chats || !app.user.userslug) {
|
||||||
return;
|
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}"]`);
|
const roomEl = chatNavWrapper.find(`[data-roomid="${roomId}"]`);
|
||||||
if (roomEl.length) {
|
if (roomEl.length) {
|
||||||
const html = await app.parseAndTranslate('partials/chats/room-teaser', {
|
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('[component="chat/room/teaser"]').html(html[0].outerHTML);
|
||||||
roomEl.find('.timeago').timeago();
|
roomEl.find('.timeago').timeago();
|
||||||
|
moveChatAndHrToTop(roomEl);
|
||||||
} else {
|
} else {
|
||||||
const { rooms } = await api.get(`/chats`, { start: 0, perPage: 2 });
|
const { rooms } = await api.get(`/chats`, { start: 0, perPage: 2 });
|
||||||
const room = rooms.find(r => parseInt(r.roomId, 10) === parseInt(roomId, 10));
|
const room = rooms.find(r => parseInt(r.roomId, 10) === parseInt(roomId, 10));
|
||||||
if (room) {
|
if (room) {
|
||||||
const recentEl = components.get('chat/recent');
|
|
||||||
const html = await app.parseAndTranslate('chats', 'rooms', {
|
const html = await app.parseAndTranslate('chats', 'rooms', {
|
||||||
rooms: [room],
|
rooms: [room],
|
||||||
showBottomHr: true,
|
showBottomHr: true,
|
||||||
});
|
});
|
||||||
recentEl.prepend(html);
|
moveChatAndHrToTop(html);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,22 +39,24 @@ define('forum/chats/events', [
|
|||||||
if (chatModule.isFromBlockedUser(data.fromUid)) {
|
if (chatModule.isFromBlockedUser(data.fromUid)) {
|
||||||
return;
|
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) {
|
if (!Chats.newMessage) {
|
||||||
Chats.newMessage = data.self === 0;
|
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, {
|
messages.appendChatMessage($('[component="chat/message/content"]'), data.message);
|
||||||
content: utils.stripHTMLTags(utils.decodeHTMLEntities(data.message.content)),
|
|
||||||
user: data.message.fromUser,
|
|
||||||
timestampISO: data.message.timestampISO,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
Chats.updateTeaser(data.roomId, {
|
||||||
|
content: utils.stripHTMLTags(utils.decodeHTMLEntities(data.message.content)),
|
||||||
|
user: data.message.fromUser,
|
||||||
|
timestampISO: data.message.timestampISO,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function publicChatUnread(data) {
|
function publicChatUnread(data) {
|
||||||
|
|||||||
Reference in New Issue
Block a user