Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Thread reply disappearing and threads result on search #18349

Merged
merged 2 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/message-pin/client/views/pinnedMessages.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2>{{_ "No_pinned_messages"}}</h2>
<div class="flex-tab__result pinned-messages-list js-list">
<ul class="list clearfix">
{{# with messageContext}}
{{#each msg in messages}}{{> message msg=msg room=room groupable=true subscription=subscription settings=settings u=u }}{{/each}}
{{#each msg in messages}}{{> message context="pinned" msg=msg room=room groupable=true subscription=subscription settings=settings u=u }}{{/each}}
{{/with}}
</ul>

Expand Down
12 changes: 11 additions & 1 deletion app/search/client/provider/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,15 @@ Template.DefaultSearchResultTemplate.helpers({
msg.searchedText = text;
return { customClass: 'search', actionContext: 'search', ...msg, groupable: false };
},
messageContext,
messageContext() {
const result = messageContext.call(this, { rid: Session.get('openedRoom') });
return {
...result,
settings: {
...result.settings,
showReplyButton: false,
showreply: false,
},
};
},
});
2 changes: 1 addition & 1 deletion app/threads/client/flextab/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Template.thread.helpers({
const instance = Template.instance();
const { mainMessage: { rid, _id: tmid }, subscription } = Template.currentData();

const thread = Messages.findOne({ _id: tmid }, { fields: { replies: 1 } });
const thread = instance.Threads.findOne({ _id: tmid }, { fields: { replies: 1 } });

const following = thread?.replies?.includes(Meteor.userId());

Expand Down
51 changes: 4 additions & 47 deletions app/ui-message/client/message.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import _ from 'underscore';
import s from 'underscore.string';
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { Template } from 'meteor/templating';
import { Session } from 'meteor/session';
Expand All @@ -9,12 +8,11 @@ import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { timeAgo, formatDateAndTime } from '../../lib/client/lib/formatDate';
import { DateFormat } from '../../lib/client';
import { normalizeThreadTitle } from '../../threads/client/lib/normalizeThreadTitle';
import { renderMessageBody, MessageTypes, MessageAction, call } from '../../ui-utils/client';
import { RoomRoles, UserRoles, Roles, Messages } from '../../models/client';
import { renderMessageBody, MessageTypes, MessageAction } from '../../ui-utils/client';
import { RoomRoles, UserRoles, Roles } from '../../models/client';
import { callbacks } from '../../callbacks/client';
import { Markdown } from '../../markdown/client';
import { t, roomTypes } from '../../utils';
import { upsertMessage } from '../../ui-utils/client/lib/RoomHistoryManager';
import './message.html';
import './messageThread';
import { AutoTranslate } from '../../autotranslate/client';
Expand Down Expand Up @@ -51,39 +49,6 @@ const renderBody = (msg, settings) => {
return msg;
};

const findParentMessage = (() => {
const waiting = [];
const uid = Tracker.nonreactive(() => Meteor.userId());
const getMessages = _.debounce(async function() {
const _tmp = [...waiting];
waiting.length = 0;
(await call('getMessages', _tmp)).map((msg) => Messages.findOne({ _id: msg._id }) || upsertMessage({ msg: { ...msg, _hidden: true }, uid }));
}, 500);


return (tmid) => {
if (waiting.indexOf(tmid) > -1) {
return;
}
const message = Messages.findOne({ _id: tmid });
if (!message) {
waiting.push(tmid);
return getMessages();
}
return Messages.update(
{ tmid, repliesCount: { $exists: 0 } },
{
$set: {
following: message.replies && message.replies.indexOf(uid) > -1,
threadMsg: normalizeThreadTitle(message),
repliesCount: message.tcount,
},
},
{ multi: true },
);
};
})();

Template.message.helpers({
following() {
const { msg, u } = this;
Expand Down Expand Up @@ -438,8 +403,8 @@ Template.message.helpers({
return !(groupable === true || _groupable === true) && !!(tmid && showreply && (!t || t === 'e2e'));
},
shouldHideBody() {
const { msg: { tmid }, settings: { showreply } } = this;
return showreply && tmid;
const { msg: { tmid, actionContext }, settings: { showreply }, context } = this;
return showreply && tmid && !(actionContext || context);
},
collapsed() {
const { msg: { tmid, collapsed }, settings: { showreply }, shouldCollapseReplies } = this;
Expand All @@ -462,14 +427,6 @@ Template.message.helpers({
},
});


Template.message.onCreated(function() {
const { msg, shouldCollapseReplies } = Template.currentData();
if (shouldCollapseReplies && msg.tmid && !msg.threadMsg) {
findParentMessage(msg.tmid);
}
});

const hasTempClass = (node) => node.classList.contains('temp');

const getPreviousSentMessage = (currentNode) => {
Expand Down
5 changes: 1 addition & 4 deletions app/ui-message/client/messageThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ Template.messageThread.helpers({
Template.messageThread.onCreated(function() {
this.parentMessage = new ReactiveVar();
this.autorun(async () => {
const { parentMessage, tmid } = Template.currentData();
if (parentMessage) {
return this.parentMessage.set(parentMessage);
}
const { tmid } = Template.currentData();
this.parentMessage.set(await findParentMessage(tmid));
});
});
4 changes: 2 additions & 2 deletions app/ui-utils/client/lib/RoomHistoryManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function upsertMessageBulk({ msgs, subscription }, collection = ChatMessa

const defaultLimit = parseInt(getConfig('roomListLimit')) || 50;

const waitAfterFlush = (fn) => setTimeout(() => Tracker.afterFlush(fn), 70);
const waitAfterFlush = (fn) => setTimeout(() => Tracker.afterFlush(fn), 10);

export const RoomHistoryManager = new class {
constructor() {
Expand Down Expand Up @@ -167,7 +167,7 @@ export const RoomHistoryManager = new class {

if (wrapper) {
waitAfterFlush(() => {
if (wrapper.scrollHeight <= wrapper.offsetHeight) {
if (wrapper.children[0].scrollHeight <= wrapper.offsetHeight) {
return this.getMore(rid);
}
const heightDiff = wrapper.scrollHeight - previousHeight;
Expand Down