-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Changes from 4 commits
a3f4482
1cb867f
1ba54db
e91c9cd
08d059f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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'); |
This file was deleted.
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/*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); | ||
return this.autorun(() => { | ||
return () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
}); |
This file was deleted.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rodrigok https://github.com/RocketChat/Rocket.Chat/blob/develop/packages/rocketchat-message-star/client/views/starredMessages.coffee
There was a problem hiding this comment.
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?