Skip to content

Commit

Permalink
converted rocketchat-message-mark-as-unread coffee/js (#6445)
Browse files Browse the repository at this point in the history
* converted rocketchat-message-mark-as-unread coffee/js

* fix revision

* Update actionButton.js
  • Loading branch information
ggazzo authored and rodrigok committed Mar 23, 2017
1 parent 80aa620 commit 865eb9c
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 51 deletions.

This file was deleted.

29 changes: 29 additions & 0 deletions packages/rocketchat-message-mark-as-unread/client/actionButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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
});
});
7 changes: 2 additions & 5 deletions packages/rocketchat-message-mark-as-unread/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ Package.describe({

Package.onUse(function(api) {
api.use([
'coffeescript',
'ecmascript',
'underscore',
'less',
'rocketchat:lib',
'rocketchat:logger',
'rocketchat:ui'
Expand All @@ -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');
});
6 changes: 2 additions & 4 deletions packages/rocketchat-message-mark-as-unread/server/logger.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* globals logger:true */
/* exported logger */

logger = new Logger('MessageMarkAsUnread', {
const logger = new Logger('MessageMarkAsUnread', {
sections: {
connection: 'Connection',
events: 'Events'
}
});
export default logger;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 comments on commit 865eb9c

Please sign in to comment.