Skip to content
Snippets Groups Projects
Commit 865eb9c5 authored by Guilherme Gazzo's avatar Guilherme Gazzo Committed by Rodrigo Nascimento
Browse files

converted rocketchat-message-mark-as-unread coffee/js (#6445)

* converted rocketchat-message-mark-as-unread coffee/js

* fix revision

* Update actionButton.js
parent 80aa6204
No related branches found
No related tags found
No related merge requests found
Meteor.startup ->
RocketChat.MessageAction.addButton
id: 'mark-message-as-unread'
icon: 'icon-flag'
i18nLabel: 'Mark_as_unread'
context: [
'message'
'message-mobile'
]
action: (event, instance) ->
message = @_arguments[1]
RocketChat.MessageAction.hideDropDown()
Meteor.call 'unreadMessages', message, (error, result) ->
if error
return handleError(error)
subscription = ChatSubscription.findOne rid: message.rid
if not subscription?
return
RoomManager.close subscription.t + subscription.name
FlowRouter.go('home')
validation: (message) ->
return message.u._id isnt Meteor.user()._id
order: 22
Meteor.startup(() => {
return RocketChat.MessageAction.addButton({
id: 'mark-message-as-unread',
icon: 'icon-flag',
i18nLabel: 'Mark_as_unread',
context: ['message', 'message-mobile'],
action() {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
return Meteor.call('unreadMessages', message, function(error) {
if (error) {
return handleError(error);
}
const subscription = ChatSubscription.findOne({
rid: message.rid
});
if (subscription == null) {
return;
}
RoomManager.close(subscription.t + subscription.name);
return FlowRouter.go('home');
});
},
validation(message) {
return message.u._id !== Meteor.user()._id;
},
order: 22
});
});
......@@ -6,10 +6,7 @@ Package.describe({
Package.onUse(function(api) {
api.use([
'coffeescript',
'ecmascript',
'underscore',
'less',
'rocketchat:lib',
'rocketchat:logger',
'rocketchat:ui'
......@@ -18,11 +15,11 @@ Package.onUse(function(api) {
api.use('templating', 'client');
api.addFiles([
'client/actionButton.coffee'
'client/actionButton.js'
], 'client');
api.addFiles([
'server/logger.js',
'server/unreadMessages.coffee'
'server/unreadMessages.js'
], 'server');
});
/* globals logger:true */
/* exported logger */
logger = new Logger('MessageMarkAsUnread', {
const logger = new Logger('MessageMarkAsUnread', {
sections: {
connection: 'Connection',
events: 'Events'
}
});
export default logger;
Meteor.methods
unreadMessages: (firstUnreadMessage) ->
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'unreadMessages' }
originalMessage = RocketChat.models.Messages.findOneById firstUnreadMessage._id, {fields: {u: 1, rid: 1, file: 1, ts: 1}}
if not originalMessage?
throw new Meteor.Error 'error-action-not-allowed', 'Not allowed', { method: 'unreadMessages', action: 'Unread_messages' }
if Meteor.userId() is originalMessage.u._id
throw new Meteor.Error 'error-action-not-allowed', 'Not allowed', { method: 'unreadMessages', action: 'Unread_messages' }
lastSeen = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(originalMessage.rid, Meteor.userId()).ls
if firstUnreadMessage.ts >= lastSeen
logger.connection.debug('Provided message is already marked as unread')
return
logger.connection.debug('Updating unread message of ' + originalMessage.ts + ' as the first unread')
RocketChat.models.Subscriptions.setAsUnreadByRoomIdAndUserId(originalMessage.rid, Meteor.userId(), originalMessage.ts)
import logger from './logger';
Meteor.methods({
unreadMessages(firstUnreadMessage) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'unreadMessages'
});
}
const originalMessage = RocketChat.models.Messages.findOneById(firstUnreadMessage._id, {
fields: {
u: 1,
rid: 1,
file: 1,
ts: 1
}
});
if (originalMessage == null || Meteor.userId() === originalMessage.u._id) {
throw new Meteor.Error('error-action-not-allowed', 'Not allowed', {
method: 'unreadMessages',
action: 'Unread_messages'
});
}
const lastSeen = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(originalMessage.rid, Meteor.userId()).ls;
if (firstUnreadMessage.ts >= lastSeen) {
return logger.connection.debug('Provided message is already marked as unread');
}
logger.connection.debug('Updating unread message of ' + originalMessage.ts + ' as the first unread');
return RocketChat.models.Subscriptions.setAsUnreadByRoomIdAndUserId(originalMessage.rid, Meteor.userId(), originalMessage.ts);
}
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment