Skip to content

Commit

Permalink
[FIX] Error 400 on send a reply to an old thread (#14402)
Browse files Browse the repository at this point in the history
* fix error 400 on send a reply to an old thread

* ignoring properly hidden messages
  • Loading branch information
ggazzo authored May 7, 2019
1 parent 123133e commit 7b463af
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
3 changes: 2 additions & 1 deletion app/threads/client/flextab/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ Template.thread.helpers({
},
messageBoxData() {
const instance = Template.instance();
const { mainMessage: { rid, _id: tmid } } = this;
const { mainMessage: { rid, _id: tmid }, subscription } = this;

return {
subscription,
rid,
tmid,
onSend: (...args) => instance.chatMessages && instance.chatMessages.send.apply(instance.chatMessages, args),
Expand Down
3 changes: 3 additions & 0 deletions app/threads/client/flextab/threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Template.threads.events({
});

Template.threads.helpers({
subscription() {
return Template.instance().data.subscription;
},
doDotLoadThreads() {
return Template.instance().state.get('close');
},
Expand Down
10 changes: 2 additions & 8 deletions app/ui-message/client/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,7 @@ const findParentMessage = (() => {
},
}, { multi: true });
if (!Messages.findOne({ _id })) {
/**
* Delete rid from message to not render it and to not be considred in last message
* find from load history method what was preveting the load of some messages in
* between the reals last loaded message and this one if this one is older than
* the real last loaded message.
*/
delete msg.rid;
msg._hidden = true;
Messages.upsert({ _id }, msg);
}
});
Expand Down Expand Up @@ -600,7 +594,7 @@ const processSequentials = ({ currentNode, settings, forceDate, showDateSeparato
} else {
nextNode.classList.remove('new-day');
}
} else {
} else if (shouldCollapseReplies) {
const [el] = $(`#chat-window-${ msg.rid }`);
const view = el && Blaze.getView(el);
const templateInstance = view && view.templateInstance();
Expand Down
1 change: 0 additions & 1 deletion app/ui-message/client/messageBox/messageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ Template.messageBox.helpers({
if (!rid) {
return false;
}

const isAnonymous = !Meteor.userId();
return isAnonymous || instance.state.get('mustJoinWithCode');
},
Expand Down
3 changes: 2 additions & 1 deletion app/ui-message/client/messageBox/messageBoxNotSubscribed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
import { Template } from 'meteor/templating';
import { settings } from '../../../settings';
import { call, roomTypes, RoomManager, RoomHistoryManager } from '../../../ui-utils';
import { call, RoomManager, RoomHistoryManager } from '../../../ui-utils';
import { roomTypes } from '../../../utils';
import { hasAllPermission } from '../../../authorization';
import './messageBoxNotSubscribed.html';

Expand Down
6 changes: 3 additions & 3 deletions app/ui-utils/client/lib/RoomHistoryManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const RoomHistoryManager = new class {
room.isLoading.set(true);

// ScrollListener.setLoader true
const lastMessage = ChatMessage.findOne({ rid }, { sort: { ts: 1 } });
const lastMessage = ChatMessage.findOne({ rid, _hidden: { $ne: true } }, { sort: { ts: 1 } });
// lastMessage ?= ChatMessage.findOne({rid: rid}, {sort: {ts: 1}})

if (lastMessage) {
Expand Down Expand Up @@ -180,7 +180,7 @@ export const RoomHistoryManager = new class {

room.isLoading.set(true);

const lastMessage = ChatMessage.findOne({ rid }, { sort: { ts: -1 } });
const lastMessage = ChatMessage.findOne({ rid, _hidden: { $ne: true } }, { sort: { ts: -1 } });

let typeName = undefined;

Expand Down Expand Up @@ -225,7 +225,7 @@ export const RoomHistoryManager = new class {

const instance = Blaze.getView($('.messages-box .wrapper')[0]).templateInstance();

if (ChatMessage.findOne(message._id)) {
if (ChatMessage.findOne({ _id: message._id, _hidden: { $ne: true } })) {
const wrapper = $('.messages-box .wrapper');
const msgElement = $(`#${ message._id }`, wrapper);
if (msgElement.length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion app/ui-utils/client/lib/RoomManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export const RoomManager = new function() {
};

const loadMissedMessages = function(rid) {
const lastMessage = ChatMessage.findOne({ rid, temp: { $exists: false } }, { sort: { ts: -1 }, limit: 1 });
const lastMessage = ChatMessage.findOne({ rid, _hidden: { $ne: true }, temp: { $exists: false } }, { sort: { ts: -1 }, limit: 1 });
if (lastMessage == null) {
return;
}
Expand Down
4 changes: 3 additions & 1 deletion app/ui/client/views/app/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ Template.room.helpers({
const viewMode = getUserPreference(Meteor.userId(), 'messageViewMode');
const query = {
rid,
_hidden: { $ne: true },
...((ignoreReplies || modes[viewMode] === 'compact') && { tmid: { $exists: 0 } }),
};

Expand Down Expand Up @@ -596,13 +597,14 @@ Template.room.events({
event.preventDefault();
event.stopPropagation();

const { tabBar } = Template.instance();
const { tabBar, subscription } = Template.instance();

const { msg, msg: { rid, _id, tmid } } = messageArgs(this);
const $flexTab = $('.flex-tab-container .flex-tab');
$flexTab.attr('template', 'thread');

tabBar.setData({
subscription: subscription.get(),
msg,
rid,
mid: tmid || _id,
Expand Down

0 comments on commit 7b463af

Please sign in to comment.