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 Message-Star Package to js #6781

Merged
merged 5 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
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.

69 changes: 69 additions & 0 deletions packages/rocketchat-message-star/client/views/starredMessages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*globals StarredMessage */
Copy link
Member

Choose a reason for hiding this comment

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

I can't find the coffee version of this file

Copy link
Contributor Author

@MartinSchoeler MartinSchoeler Apr 27, 2017

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Can you delete the file in your commit? Or do you want to keep the old .coffee file?

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);
return this.autorun(() => {
return () => {
Copy link
Member

Choose a reason for hiding this comment

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

Why this function? It'll never be called

const sub = this.subscribe('starredMessages', this.data.rid, this.limit.get());
if (sub.ready()) {
if (StarredMessage.find({
Copy link
Member

Choose a reason for hiding this comment

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

Do not break the if, move the find to a variable

rid: this.data.rid
}).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