Skip to content

Commit

Permalink
Merge pull request #6689 from RocketChat/mentions-to-js
Browse files Browse the repository at this point in the history
Convert Mentions-Flextab Package to Js
  • Loading branch information
rodrigok authored Apr 24, 2017
2 parents 03b5294 + bb19692 commit 460244e
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 91 deletions.
17 changes: 0 additions & 17 deletions packages/rocketchat-mentions-flextab/client/actionButton.coffee

This file was deleted.

17 changes: 17 additions & 0 deletions packages/rocketchat-mentions-flextab/client/actionButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Meteor.startup(function() {
return RocketChat.MessageAction.addButton({
id: 'jump-to-message',
icon: 'icon-right-hand',
i18nLabel: 'Jump_to_message',
context: ['mentions'],
action() {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
return RoomHistoryManager.getSurroundingMessages(message, 50);
},
validation(message) {
return message.mentionedList === true;
},
order: 100
});
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this.MentionedMessage = new Mongo.Collection('rocketchat_mentioned_message');
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Meteor.startup ->
RocketChat.TabBar.addButton({
Meteor.startup(function() {
return RocketChat.TabBar.addButton({
groups: ['channel', 'group'],
id: 'mentions',
i18nTitle: 'Mentions',
icon: 'icon-at',
template: 'mentionsFlexTab',
order: 3
})
});
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*globals MentionedMessage */
Template.mentionsFlexTab.helpers({
hasMessages() {
return MentionedMessage.find({
rid: this.rid
}, {
sort: {
ts: -1
}
}).count() > 0;
},
messages() {
return MentionedMessage.find({
rid: this.rid
}, {
sort: {
ts: -1
}
});
},
message() {
return _.extend(this, {
customClass: 'mentions'
});
},
hasMore() {
return Template.instance().hasMore.get();
}
});

Template.mentionsFlexTab.onCreated(function() {
this.hasMore = new ReactiveVar(true);
this.limit = new ReactiveVar(50);
return this.autorun(() => {
const mentionedMessageFind = MentionedMessage.find({ rid: this.data.rid });
return this.subscribe('mentionedMessages', this.data.rid, this.limit.get(), () => {
if (mentionedMessageFind.count() < this.limit.get()) {
return this.hasMore.set(false);
}
});
});
});

Template.mentionsFlexTab.events({
'click .message-cog'(e, t) {
e.stopPropagation();
e.preventDefault();
const message_id = $(e.currentTarget).closest('.message').attr('id');
RocketChat.MessageAction.hideDropDown();
t.$(`\#${ message_id } .message-dropdown`).remove();
const message = MentionedMessage.findOne(message_id);
const actions = RocketChat.MessageAction.getButtons(message, 'mentions');
const el = Blaze.toHTMLWithData(Template.messageDropdown, {
actions
});
t.$(`\#${ message_id } .message-cog-container`).append(el);
const dropDown = t.$(`\#${ message_id } .message-dropdown`);
return dropDown.show();
},
'scroll .content': _.throttle(function(e, instance) {
if (e.target.scrollTop >= e.target.scrollHeight - e.target.clientHeight && instance.hasMore.get()) {
return instance.limit.set(instance.limit.get() + 50);
}
}, 200)
});
11 changes: 5 additions & 6 deletions packages/rocketchat-mentions-flextab/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Package.onUse(function(api) {
api.use([
'mongo',
'ecmascript',
'coffeescript',
'underscore',
'less',
'rocketchat:lib'
Expand All @@ -18,15 +17,15 @@ Package.onUse(function(api) {
api.use('templating', 'client');

api.addFiles([
'client/lib/MentionedMessage.coffee',
'client/lib/MentionedMessage.js',
'client/views/stylesheets/mentionsFlexTab.less',
'client/views/mentionsFlexTab.html',
'client/views/mentionsFlexTab.coffee',
'client/actionButton.coffee',
'client/tabBar.coffee'
'client/views/mentionsFlexTab.js',
'client/actionButton.js',
'client/tabBar.js'
], 'client');

api.addFiles([
'server/publications/mentionedMessages.coffee'
'server/publications/mentionedMessages.js'
], 'server');
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Meteor.publish('mentionedMessages', function(rid, limit = 50) {
if (!this.userId) {
return this.ready();
}
const publication = this;
const user = RocketChat.models.Users.findOneById(this.userId);
if (!user) {
return this.ready();
}
const cursorHandle = RocketChat.models.Messages.findVisibleByMentionAndRoomId(user.username, rid, {
sort: {
ts: -1
},
limit
}).observeChanges({
added(_id, record) {
record.mentionedList = true;
return publication.added('rocketchat_mentioned_message', _id, record);
},
changed(_id, record) {
record.mentionedList = true;
return publication.changed('rocketchat_mentioned_message', _id, record);
},
removed(_id) {
return publication.removed('rocketchat_mentioned_message', _id);
}
});
this.ready();
return this.onStop(function() {
return cursorHandle.stop();
});
});

0 comments on commit 460244e

Please sign in to comment.