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

Convert Mentions-Flextab Package to Js #6689

Merged
merged 3 commits into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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,66 @@
/*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(() => {
return this.subscribe('mentionedMessages', this.data.rid, this.limit.get(), function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code uses => and had this inside, you should keep the arrow function.

if (MentionedMessage.find({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, do not break que if condition, extract the find to a variable if you prefer.

rid: this.data.rid
}).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)
});
10 changes: 5 additions & 5 deletions packages/rocketchat-mentions-flextab/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ Package.onUse(function(api) {
api.use('templating', 'client');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the package coffeescript


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,35 @@
Meteor.publish('mentionedMessages', function(rid, limit) {
if (limit == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the default values

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();
});
});