Skip to content

Commit

Permalink
Merge pull request #6781 from RocketChat/message-star-to-js
Browse files Browse the repository at this point in the history
Convert Message-Star Package to js
  • Loading branch information
rodrigok authored Apr 27, 2017
2 parents 1359fff + 08d059f commit b75c867
Show file tree
Hide file tree
Showing 18 changed files with 252 additions and 194 deletions.
83 changes: 0 additions & 83 deletions packages/rocketchat-message-star/client/actionButton.coffee

This file was deleted.

85 changes: 85 additions & 0 deletions packages/rocketchat-message-star/client/actionButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import toastr from 'toastr';
Meteor.startup(function() {
RocketChat.MessageAction.addButton({
id: 'star-message',
icon: 'icon-star-empty',
i18nLabel: 'Star_Message',
context: ['starred', 'message', 'message-mobile'],
action() {
const message = this._arguments[1];
message.starred = Meteor.userId();
return Meteor.call('starMessage', message, function(error) {
if (error) {
return handleError(error);
}
});
},
validation(message) {
if (RocketChat.models.Subscriptions.findOne({ rid: message.rid }) == null) {
return false;
}
return RocketChat.settings.get('Message_AllowStarring') && !message.starred;
},
order: 10
});
RocketChat.MessageAction.addButton({
id: 'unstar-message',
icon: 'icon-star',
i18nLabel: 'Unstar_Message',
context: ['starred', 'message', 'message-mobile'],
action() {
const message = this._arguments[1];
message.starred = false;
return Meteor.call('starMessage', message, function(error) {
if (error) {
return handleError(error);
}
});
},
validation(message) {
if (RocketChat.models.Subscriptions.findOne({ rid: message.rid }) == null) {
return false;
}
return RocketChat.settings.get('Message_AllowStarring') && message.starred;
},
order: 10
});
RocketChat.MessageAction.addButton({
id: 'jump-to-star-message',
icon: 'icon-right-hand',
i18nLabel: 'Jump_to_message',
context: ['starred'],
action() {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
return RoomHistoryManager.getSurroundingMessages(message, 50);
},
validation(message) {
if (RocketChat.models.Subscriptions.findOne({ rid: message.rid }) == null) {
return false;
}
return true;
},
order: 100
});
return RocketChat.MessageAction.addButton({
id: 'permalink-star',
icon: 'icon-link',
i18nLabel: 'Permalink',
classes: 'clipboard',
context: ['starred'],
action() {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
$(event.currentTarget).attr('data-clipboard-text', RocketChat.MessageAction.getPermaLink(message._id));
return toastr.success(TAPi18n.__('Copied'));
},
validation(message) {
if (RocketChat.models.Subscriptions.findOne({ rid: message.rid }) == null) {
return false;
}
return true;
},
order: 101
});
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this.StarredMessage = new Mongo.Collection('rocketchat_starred_message');
15 changes: 0 additions & 15 deletions packages/rocketchat-message-star/client/starMessage.coffee

This file was deleted.

20 changes: 20 additions & 0 deletions packages/rocketchat-message-star/client/starMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Meteor.methods({
starMessage(message) {
if (!Meteor.userId()) {
return false;
}
if (RocketChat.models.Subscriptions.findOne({ rid: message.rid }) == null) {
return false;
}
if (!RocketChat.settings.get('Message_AllowStarring')) {
return false;
}
return ChatMessage.update({
_id: message._id
}, {
$set: {
starred: !!message.starred
}
});
}
});
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', 'direct'],
id: 'starred-messages',
i18nTitle: 'Starred_Messages',
icon: 'icon-star',
template: 'starredMessages',
order: 3
})
});
});

This file was deleted.

66 changes: 66 additions & 0 deletions packages/rocketchat-message-star/client/views/starredMessages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*globals StarredMessage */
Template.starredMessages.helpers({
hasMessages() {
return StarredMessage.find({
rid: this.rid
}, {
sort: {
ts: -1
}
}).count() > 0;
},
messages() {
return StarredMessage.find({
rid: this.rid
}, {
sort: {
ts: -1
}
});
},
message() {
return _.extend(this, {
customClass: 'starred'
});
},
hasMore() {
return Template.instance().hasMore.get();
}
});

Template.starredMessages.onCreated(function() {
this.hasMore = new ReactiveVar(true);
this.limit = new ReactiveVar(50);
this.autorun(() => {
const sub = this.subscribe('starredMessages', this.data.rid, this.limit.get());
const findStarredMessage = StarredMessage.find({ rid: this.data.rid });
if (sub.ready()) {
if (findStarredMessage.count() < this.limit.get()) {
return this.hasMore.set(false);
}
}
});
});

Template.starredMessages.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 = StarredMessage.findOne(message_id);
const actions = RocketChat.MessageAction.getButtons(message, 'starred');
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) {
return instance.limit.set(instance.limit.get() + 50);
}
}, 200)
});
19 changes: 9 additions & 10 deletions packages/rocketchat-message-star/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Package.describe({
Package.onUse(function(api) {
api.use([
'mongo',
'coffeescript',
'ecmascript',
'underscore',
'less',
Expand All @@ -18,19 +17,19 @@ Package.onUse(function(api) {
api.use('templating', 'client');

api.addFiles([
'client/lib/StarredMessage.coffee',
'client/actionButton.coffee',
'client/starMessage.coffee',
'client/tabBar.coffee',
'client/lib/StarredMessage.js',
'client/actionButton.js',
'client/starMessage.js',
'client/tabBar.js',
'client/views/starredMessages.html',
'client/views/starredMessages.coffee',
'client/views/starredMessages.js',
'client/views/stylesheets/messagestar.less'
], 'client');

api.addFiles([
'server/settings.coffee',
'server/starMessage.coffee',
'server/publications/starredMessages.coffee',
'server/startup/indexes.coffee'
'server/settings.js',
'server/starMessage.js',
'server/publications/starredMessages.js',
'server/startup/indexes.js'
], 'server');
});

This file was deleted.

Loading

0 comments on commit b75c867

Please sign in to comment.