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

[NEW] Slack Like Threading #13394

Closed
wants to merge 1 commit into from
Closed
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ tramp
ecosystem.json
pm2.json
settings.json
build.sh

/public/livechat
packages/rocketchat-i18n/i18n/livechat.*
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ rocketchat:e2e
rocketchat:blockstack
rocketchat:version-check
rocketchat:search
rocketchat:replies
chatpal:search
rocketchat:lazy-load
tap:i18n
Expand Down
1 change: 1 addition & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ rocketchat:otr@0.0.1
rocketchat:push@3.3.1
rocketchat:push-notifications@0.0.1
rocketchat:reactions@0.0.1
rocketchat:replies@0.0.1
rocketchat:retention-policy@0.0.1
rocketchat:sandstorm@0.0.1
rocketchat:search@0.0.1
Expand Down
98 changes: 0 additions & 98 deletions .vscode/launch.json

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![alt text](threading.png)

![](https://user-images.githubusercontent.com/551004/43643393-884b00a4-9701-11e8-94d8-14c46d1f3660.png)

<h1 align="center">
Expand Down
20 changes: 20 additions & 0 deletions client/methods/addMessageReply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import _ from 'underscore';

Meteor.methods({
addMessageReply(message) {
if (!Meteor.userId()) {
return false;
}

Tracker.nonreactive(function() {
message = RocketChat.callbacks.run('beforeSaveMessage', message);
const messageObject = { customFields: { replyIds: message.customFields.replyIds} };
ChatMessage.update({
_id: message._id,
'u._id': Meteor.userId(),
}, { $set : messageObject });
});
},
});
12 changes: 12 additions & 0 deletions client/methods/deleteMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Meteor.methods({
return false;
}

let ref = message.ref;

// We're now only passed in the `_id` property to lower the amount of data sent to the server
message = ChatMessage.findOne({ _id: message._id });

Expand All @@ -33,6 +35,16 @@ Meteor.methods({


}
let parentMessage;
let replyIds;
if (ref) {
parentMessage = ChatMessage.findOne({ _id: ref });
replyIds = _.without(parentMessage.customFields.replyIds, message._id);
}


Meteor.call('addMessageReply', { _id: parentMessage._id, customFields: { replyIds } });


Tracker.nonreactive(function() {
ChatMessage.remove({
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ Meteor.methods({
attachment.video_type = file.type;
attachment.video_size = file.size;
}

const customFields = file.customFields;
delete file.customFields;
const user = Meteor.user();
let msg = Object.assign({
_id: Random.id(),
rid: roomId,
ts: new Date(),
customFields: customFields,
msg: '',
file: {
_id: file._id,
Expand Down
12 changes: 9 additions & 3 deletions packages/rocketchat-lib/client/MessageAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,15 @@ Meteor.startup(function() {
if (RocketChat.models.Subscriptions.findOne({ rid: message.rid }) == null) {
return false;
}
if (message.customFields.ref) {
return false;
}
if (message.customFields.replyIds && message.customFields.replyIds.length) {
return false;
}

return true;
// return true;
return false;
},
order: 1,
group: 'menu',
Expand Down Expand Up @@ -309,8 +316,7 @@ Meteor.startup(function() {
if (RocketChat.models.Subscriptions.findOne({ rid: message.rid }) == null) {
return false;
}

return true;
return false;
},
order: 6,
group: 'menu',
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Package.onUse(function(api) {
api.addFiles('server/functions/setEmail.js', 'server');
api.addFiles('server/functions/unarchiveRoom.js', 'server');
api.addFiles('server/functions/updateMessage.js', 'server');
api.addFiles('server/functions/addMessageReply.js', 'server');
api.addFiles('server/functions/validateCustomFields.js', 'server');
api.addFiles('server/functions/Notifications.js', 'server');

Expand Down Expand Up @@ -197,6 +198,7 @@ Package.onUse(function(api) {
api.addFiles('server/methods/unarchiveRoom.js', 'server');
api.addFiles('server/methods/unblockUser.js', 'server');
api.addFiles('server/methods/updateMessage.js', 'server');
api.addFiles('server/methods/addMessageReply.js', 'server');

// SERVER STARTUP
api.addFiles('server/startup/settingsOnLoadCdnPrefix.js', 'server');
Expand Down
42 changes: 42 additions & 0 deletions packages/rocketchat-lib/server/functions/addMessageReply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Meteor } from 'meteor/meteor';

RocketChat.addMessageReply = function(message, user, originalMessage) {
if (!originalMessage) {
originalMessage = RocketChat.models.Messages.findOneById(message._id);
}

// For the Rocket.Chat Apps :)
if (message && Apps && Apps.isLoaded()) {
const appMessage = Object.assign({}, originalMessage, message);

const prevent = Promise.await(Apps.getBridges().getListenerBridge().messageEvent('IPreMessageUpdatedPrevent', appMessage));
if (prevent) {
throw new Meteor.Error('error-app-prevented-updating', 'A Rocket.Chat App prevented the message updating.');
}

let result;
result = Promise.await(Apps.getBridges().getListenerBridge().messageEvent('IPreMessageUpdatedExtend', appMessage));
result = Promise.await(Apps.getBridges().getListenerBridge().messageEvent('IPreMessageUpdatedModify', result));

if (typeof result === 'object') {
message = Object.assign(appMessage, result);
}
}

const tempid = message._id;
delete message._id;

RocketChat.models.Messages.update({ _id: tempid }, { $set: message });

const room = RocketChat.models.Rooms.findOneById(message.rid);

if (Apps && Apps.isLoaded()) {
// This returns a promise, but it won't mutate anything about the message
// so, we don't really care if it is successful or fails
Apps.getBridges().getListenerBridge().messageEvent('IPostMessageUpdated', message);
}

Meteor.defer(function() {
RocketChat.callbacks.run('afterSaveMessage', RocketChat.models.Messages.findOneById(tempid), room, user._id);
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ RocketChat.settings.get(/Message_HideType_.+/, function(key, value) {
});
});

RocketChat.loadMessageHistory = function loadMessageHistory({ userId, rid, end, limit = 20, ls }) {
const options = {
RocketChat.loadMessageHistory = function loadMessageHistory({ userId, rid, end, limit = 20, ls, parentMessageId }) {
let options = {
sort: {
ts: -1,
},
Expand All @@ -32,7 +32,10 @@ RocketChat.loadMessageHistory = function loadMessageHistory({ userId, rid, end,
}

let records;
if (end != null) {
if (parentMessageId) {
options.sort = { ts: 1};
records = RocketChat.models.Messages.findReplies(rid, hideMessagesOfType, options, parentMessageId).fetch();
} else if (end != null) {
records = RocketChat.models.Messages.findVisibleByRoomIdBeforeTimestampNotContainingTypes(rid, end, hideMessagesOfType, options).fetch();
} else {
records = RocketChat.models.Messages.findVisibleByRoomIdNotContainingTypes(rid, hideMessagesOfType, options).fetch();
Expand Down
23 changes: 23 additions & 0 deletions packages/rocketchat-lib/server/methods/addMessageReply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import moment from 'moment';

Meteor.methods({
addMessageReply(message) {
check(message, Match.ObjectIncluding({ _id:String }));

if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'addMessageReply' });
}

const originalMessage = RocketChat.models.Messages.findOneById(message._id);

if (!originalMessage || !originalMessage._id) {
return;
}

message.u = originalMessage.u;

return RocketChat.addMessageReply(message, Meteor.user(), originalMessage);
},
});
21 changes: 21 additions & 0 deletions packages/rocketchat-lib/server/models/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base {
this.tryEnsureIndex({ rid: 1, ts: 1 });
this.tryEnsureIndex({ ts: 1 });
this.tryEnsureIndex({ 'u._id': 1 });
this.tryEnsureIndex({ 'customFields.replyIds': 1 });
this.tryEnsureIndex({ 'customFields.ref': 1 });
this.tryEnsureIndex({ editedAt: 1 }, { sparse: 1 });
this.tryEnsureIndex({ 'editedBy._id': 1 }, { sparse: 1 });
this.tryEnsureIndex({ rid: 1, t: 1, 'u._id': 1 });
Expand Down Expand Up @@ -98,6 +100,7 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base {
},

rid: roomId,
'customFields.ref': { $exists: false}
};

if (Match.test(types, [String]) && (types.length > 0)) {
Expand All @@ -108,6 +111,24 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base {
return this.find(query, options);
}

findReplies(roomId, types, options, parentMessageId) {
const query = {
_hidden: {
$ne: true,
},

rid: roomId,
'customFields.ref': parentMessageId
};

if (Match.test(types, [String]) && (types.length > 0)) {
query.t =
{ $nin: types };
}

return this.find(query, options);
}

findInvisibleByRoomId(roomId, options) {
const query = {
_hidden: true,
Expand Down
Loading