Skip to content

Commit

Permalink
[NEW] Threads (#13541)
Browse files Browse the repository at this point in the history
Co-authored-by: Oliver Jägle <github@beimir.net>
Co-authored-by: vickyokrm <vickyokrm@gmail.com>
  • Loading branch information
3 people authored and sampaiodiego committed Mar 8, 2019
1 parent 8849ece commit b93b31b
Show file tree
Hide file tree
Showing 103 changed files with 2,117 additions and 204 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ settings.json
build.sh
/public/livechat
packages/rocketchat-i18n/i18n/livechat.*
tests/end-to-end/temporary_staged_test
.screenshots
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ rocketchat:search
chatpal:search
rocketchat:lazy-load
tap:i18n
assistify:threading
underscore@1.0.10
rocketchat:bigbluebutton
rocketchat:mailmessages
Expand Down
1 change: 1 addition & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ accounts-password@1.5.1
accounts-twitter@1.4.2
aldeed:simple-schema@1.5.4
allow-deny@1.1.0
assistify:threading@0.1.0
autoupdate@1.5.0
babel-compiler@7.2.4
babel-runtime@1.3.0
Expand Down
6 changes: 6 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"version": "0.2.0",
"configurations": [

{
"name": "Attach to meteor debug",
"type": "node",
Expand All @@ -13,6 +14,7 @@
"meteor://💻app/*": "${workspaceFolder}/*",
"meteor://💻app/packages/rocketchat:*": "${workspaceFolder}/packages/rocketchat-*",
"meteor://💻app/packages/chatpal:*": "${workspaceFolder}/packages/chatpal-*",
"meteor://💻app/packages/assistify:*": "${workspaceFolder}/packages/assistify-*"
},
"protocol": "inspector"
},
Expand All @@ -26,6 +28,7 @@
"meteor://💻app/*": "${workspaceFolder}/*",
"meteor://💻app/packages/rocketchat:*": "${workspaceFolder}/packages/rocketchat-*",
"meteor://💻app/packages/chatpal:*": "${workspaceFolder}/packages/chatpal-*",
"meteor://💻app/packages/assistify:*": "${workspaceFolder}/packages/assistify-*"
}
},
{
Expand All @@ -43,6 +46,7 @@
"meteor://💻app/*": "${workspaceFolder}/*",
"meteor://💻app/packages/rocketchat:*": "${workspaceFolder}/packages/rocketchat-*",
"meteor://💻app/packages/chatpal:*": "${workspaceFolder}/packages/chatpal-*",
"meteor://💻app/packages/assistify:*": "${workspaceFolder}/packages/assistify-*"
},
"protocol": "inspector"
},
Expand All @@ -61,6 +65,7 @@
"meteor://💻app/*": "${workspaceFolder}/*",
"meteor://💻app/packages/rocketchat:*": "${workspaceFolder}/packages/rocketchat-*",
"meteor://💻app/packages/chatpal:*": "${workspaceFolder}/packages/chatpal-*",
"meteor://💻app/packages/assistify:*": "${workspaceFolder}/packages/assistify-*"
},
"protocol": "inspector"
},
Expand All @@ -79,6 +84,7 @@
"meteor://💻app/*": "${workspaceFolder}/*",
"meteor://💻app/packages/rocketchat:*": "${workspaceFolder}/packages/rocketchat-*",
"meteor://💻app/packages/chatpal:*": "${workspaceFolder}/packages/chatpal-*",
"meteor://💻app/packages/assistify:*": "${workspaceFolder}/packages/assistify-*"
},
"env": {
"TEST_MODE": "true"
Expand Down
6 changes: 5 additions & 1 deletion client/routes/roomRoute.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import mem from 'mem';

import { FlowRouter } from 'meteor/kadira:flow-router';
import { ChatSubscription } from 'meteor/rocketchat:models';
import { roomTypes } from 'meteor/rocketchat:utils';
import { call } from 'meteor/rocketchat:ui-utils';

const getRoomById = mem((rid) => call('getRoomById', rid));

FlowRouter.goToRoomById = async(rid) => {
if (!rid) {
return;
Expand All @@ -12,6 +16,6 @@ FlowRouter.goToRoomById = async(rid) => {
return roomTypes.openRouteLink(subscription.t, subscription, FlowRouter.current().queryParams);
}

const room = await call('getRoomById', rid);
const room = await getRoomById(rid);
return roomTypes.openRouteLink(room.t, room, FlowRouter.current().queryParams);
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
"jslint": "eslint .",
"stylelint": "stylelint \"packages/**/*.css\"",
"test": "node .scripts/start.js",
"deploy": "npm run build && pm2 startOrRestart pm2.json",
"chimp-path": "chimp tests/chimp-config.js --path=$CHIMP_PATH",
"chimp-watch": "chimp --ddp=http://localhost:3000 --watch --mocha --path=tests/end-to-end",
"chimp-test": "chimp tests/chimp-config.js",
"postinstall": "cd packages/rocketchat-katex && npm i",
Expand Down
49 changes: 49 additions & 0 deletions packages/assistify-threading/client/createThreadMessageAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { Subscriptions } from 'meteor/rocketchat:models';
import { settings } from 'meteor/rocketchat:settings';
import { hasPermission } from 'meteor/rocketchat:authorization';
import { MessageAction, modal } from 'meteor/rocketchat:ui-utils';


const condition = (rid, uid) => {
if (!Subscriptions.findOne({ rid })) {
return false;
}
return uid !== Meteor.userId() ? hasPermission('start-thread-other-user') : hasPermission('start-thread');
};

Meteor.startup(function() {
Tracker.autorun(() => {
if (settings.get('Thread_from_context_menu') !== 'button') {
return MessageAction.removeButton('start-thread');
}

MessageAction.addButton({
id: 'start-thread',
icon: 'thread',
label: 'Thread_start',
context: ['message', 'message-mobile'],
async action() {
const [, message] = this._arguments;

modal.open({
content: 'CreateThread',
data: { rid: message.rid, message, onCreate() {
modal.close();
} },
showConfirmButton: false,
showCancelButton: false,
});
},
condition({ rid, u: { _id: uid }, attachments }) {
if (attachments && attachments[0] && attachments[0].fields && attachments[0].fields[0].type === 'messageCounter') {
return false;
}
return condition(rid, uid);
},
order: 0,
group: 'menu',
});
});
});
20 changes: 20 additions & 0 deletions packages/assistify-threading/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Templates
import './views/creationDialog/CreateThread.html';
import './views/creationDialog/CreateThread';
import './views/ThreadList.html';
import './views/ThreadList';
import './views/ThreadsTabbar.html';
import './views/ThreadsTabbar';
import './views/fieldTypeThreadReplyCounter.html';
import './views/fieldTypeThreadReplyCounter';
import './views/fieldTypeThreadLastMessageAge.html';
import './views/fieldTypeThreadLastMessageAge';

// Other UI extensions
import './lib/messageTypes/threadMessage';
import './lib/threadsOfRoom';
import './createThreadMessageAction';
import './threadFromMessageBox';
import './tabBar';

import '../lib/threadRoomType';
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/tap:i18n';
import { MessageTypes } from 'meteor/rocketchat:ui-utils';

Meteor.startup(function() {
MessageTypes.registerType({
id: 'thread-created',
system: true,
message: 'thread-created',
data(message) {
return {
// channelLink: `<a class="mention-link" data-channel= ${ message.channels[0]._id } title="">${ TAPi18n.__('thread') }</a>`,
message: message.msg,
username: `<a class="mention-link" data-username=${ message.u.username } title="">@${ message.u.username }</a>`,
};
},
});

MessageTypes.registerType({
id: 'thread-welcome',
system: true,
message: 'thread-welcome',
data(message) {
const threadChannelName = TAPi18n.__('a_direct_message');

return {
parentChannel: `<a class="mention-link" data-channel= ${ threadChannelName } title="">${ threadChannelName }</a>`,
username: `<a class="mention-link" data-username= ${ message.mentions[0].name } title="">@${ message.mentions[0].name }</a>`,
};
},
});
});
3 changes: 3 additions & 0 deletions packages/assistify-threading/client/lib/threadsOfRoom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Mongo } from 'meteor/mongo';

export const ThreadsOfRoom = new Mongo.Collection('rocketchat_threads_of_room');
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.attachment-fields button {
min-height: auto;
padding: 3px;

font-weight: normal;
}

.attachment-fields button:hover {
text-decoration: none;
}

.attachment-fields button.no-replies {
opacity: 0.4;
}

.threads-list .empty {
margin-top: 60px;

text-align: center;

color: #7f7f7f;
}

.threads-list .load-more {
text-align: center;
text-transform: lowercase;

font-style: italic;
line-height: 40px;
}

.threads-list .load-more .load-more-loading {
color: #aaaaaa;
}
13 changes: 13 additions & 0 deletions packages/assistify-threading/client/tabBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Meteor } from 'meteor/meteor';
import { TabBar } from 'meteor/rocketchat:ui-utils';

Meteor.startup(function() {
return TabBar.addButton({
groups: ['channel', 'group', 'direct'],
id: 'threads',
i18nTitle: 'Threads',
icon: 'thread',
template: 'threadsTabbar',
order: 10,
});
});
33 changes: 33 additions & 0 deletions packages/assistify-threading/client/threadFromMessageBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { messageBox, modal } from 'meteor/rocketchat:ui-utils';
import { settings } from 'meteor/rocketchat:settings';

Meteor.startup(function() {
Tracker.autorun(() => {
if (settings.get('Thread_from_context_menu') !== 'button') {
return messageBox.actions.remove('Create_new', /start-thread/);
}
messageBox.actions.add('Create_new', 'Thread', {
id: 'start-thread',
icon: 'thread',
condition: () => true,
action(data) {
modal.open({
// title: t('Message_info'),
content: 'CreateThread',
data: {
...data,
onCreate() {
modal.close();
},
},
showConfirmButton: false,
showCancelButton: false,
// confirmButtonText: t('Close'),
});
},
});

});
});
10 changes: 10 additions & 0 deletions packages/assistify-threading/client/views/ThreadList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template name="ThreadList">
{{#if rooms}}
<h3 class="rooms-list__type">
{{_ "Threads"}}
</h3>
<ul class="rooms-list__list">
{{#each room in rooms}} {{> chatRoomItem room }} {{/each}}
</ul>
{{/if}}
</template>
25 changes: 25 additions & 0 deletions packages/assistify-threading/client/views/ThreadList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { ChatSubscription } from 'meteor/rocketchat:models';
import { getUserPreference } from 'meteor/rocketchat:utils';
import { settings } from 'meteor/rocketchat:settings';
Template.ThreadList.helpers({
rooms() {
const user = Meteor.userId();
const sortBy = getUserPreference(user, 'sidebarSortby') || 'alphabetical';
const query = {
open: true,
};

const sort = {};

if (sortBy === 'activity') {
sort.lm = -1;
} else { // alphabetical
sort[this.identifier === 'd' && settings.get('UI_Use_Real_Name') ? 'lowerCaseFName' : 'lowerCaseName'] = /descending/.test(sortBy) ? -1 : 1;
}

query.prid = { $exists: true };
return ChatSubscription.find(query, { sort });
},
});
22 changes: 22 additions & 0 deletions packages/assistify-threading/client/views/ThreadsTabbar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template name="threadsTabbar">
{{#if Template.subscriptionsReady}}
{{#unless hasMessages}}
<div class="list-view threads-list flex-tab__header">
<h2>{{_ "No_threads_yet"}}</h2>
</div>
{{/unless}}
{{/if}}
<div class="flex-tab__result threads-list js-list">
<ul class="list clearfix">
{{#each messages}}
{{#nrr nrrargs 'message' message}}{{/nrr}}
{{/each}}
</ul>

{{#if hasMore}}
<div class="load-more">
{{> loading}}
</div>
{{/if}}
</div>
</template>
Loading

0 comments on commit b93b31b

Please sign in to comment.