Node.js based forum software built for the modern web
feat: link pinned message timestamp to its place in the conversation (#14699)
palmoni58cb1be358039
diff --git a/public/src/client/chats.js b/public/src/client/chats.jsindex ac41bb8bf5..726d1d08f0 100644--- a/public/src/client/chats.js+++ b/public/src/client/chats.js@@ -106,6 +106,7 @@ define('forum/chats', [Chats.addScrollHandler(roomId, ajaxify.data.uid, chatMessageContent);Chats.addScrollBottomHandler(roomId, chatMessageContent);Chats.addParentHandler(chatMainWrapper);+ Chats.addPinnedTimestampHandler(chatMainWrapper);Chats.addCharactersLeftHandler(chatMainWrapper);Chats.addTextareaResizeHandler(chatMainWrapper);Chats.addTypingHandler(chatMainWrapper, roomId);@@ -197,10 +198,13 @@ define('forum/chats', [});};- function gotoMessage(event, timestampEl) {- const mid = timestampEl.parents('[data-parent-mid]').attr('data-parent-mid');- const containerEl = timestampEl.parents('[component="chat/message/content"]');- const messageEl = containerEl.find(`[component="chat/message"][data-mid="${mid}"]`);+ function gotoMessage(event, timestampEl, mid) {+ // :visible because the conversation is swapped out for the message search+ // results, and there is nothing to scroll while those are shown+ const contentEl = timestampEl+ .closest('[component="chat/message/window"]')+ .find('[component="chat/message/content"]:visible');+ const messageEl = contentEl.find(`[component="chat/message"][data-mid="${mid}"]`);if (messageEl.length) {event.preventDefault();messages.scrollToMessage(messageEl);@@ -224,7 +228,25 @@ define('forum/chats', [// deeper selector, so this runs before the collapse handler abovemainWrapper.off('click', '[component="chat/message/parent"] .chat-timestamp').on('click', '[component="chat/message/parent"] .chat-timestamp', function (ev) {- return gotoMessage(ev, $(this));+ const timestampEl = $(this);+ return gotoMessage(+ ev, timestampEl, timestampEl.parents('[data-parent-mid]').attr('data-parent-mid')+ );+ });+ };++ // a pinned message is shown out of context, so its own timestamp links back to+ // where it sits in the conversation+ Chats.addPinnedTimestampHandler = function (mainWrapper) {+ // scoped to .message-header, as the timestamp of a quoted parent rendered in+ // the panel is already handled by addParentHandler+ const selector = '[component="chat/messages/pinned"] .message-header .chat-timestamp';+ mainWrapper.off('click', selector)+ .on('click', selector, function (ev) {+ const timestampEl = $(this);+ return gotoMessage(+ ev, timestampEl, timestampEl.parents('[component="chat/message"]').attr('data-mid')+ );});};diff --git a/public/src/client/chats/pinned-messages.js b/public/src/client/chats/pinned-messages.jsindex 87d0dc6d0c..22193a6905 100644--- a/public/src/client/chats/pinned-messages.js+++ b/public/src/client/chats/pinned-messages.js@@ -30,6 +30,7 @@ define('forum/chats/pinned-messages', ['api', 'alerts'], function (api, alerts)if (data && data.length) {const html = await parseMessages(data);container.find('[component="chat/messages/pinned"]').append(html);+ html.find('.timeago').timeago();}}}, 200));diff --git a/src/views/partials/chats/pinned-messages-list.tpl b/src/views/partials/chats/pinned-messages-list.tplindex d3a82dcbc0..9944ec5f36 100644--- a/src/views/partials/chats/pinned-messages-list.tpl+++ b/src/views/partials/chats/pinned-messages-list.tpl@@ -9,7 +9,7 @@<a href="{config.relative_path}/user/{messages.fromUser.userslug}" class="text-decoration-none">{{buildAvatar(messages.fromUser, "18px", true, "not-responsive")}}</a><span class="chat-user fw-semibold"><a href="{config.relative_path}/user/{messages.fromUser.userslug}">{{txDisplayname(messages.fromUser)}}</a></span>- <span class="chat-timestamp text-muted timeago" title="{messages.timestampISO}"></span>+ <a href="{config.relative_path}/message/{messages.messageId}" class="chat-timestamp text-muted timeago" title="{messages.timestampISO}"></a><div component="chat/message/edited" class="text-muted ms-auto {{{ if !messages.edited }}}hidden{{{ end }}}" title="{{tx("global:edited-timestamp", isoTimeToLocaleString(messages.editedISO, config.userLang))}}"><i class="fa fa-edit"></i></span></div></div><div class="message-body-wrapper">