-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
converted rocketchat-message-mark-as-unread coffee/js (#6445)
* converted rocketchat-message-mark-as-unread coffee/js * fix revision * Update actionButton.js
- Loading branch information
Showing
6 changed files
with
63 additions
and
51 deletions.
There are no files selected for viewing
23 changes: 0 additions & 23 deletions
23
packages/rocketchat-message-mark-as-unread/client/actionButton.coffee
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
packages/rocketchat-message-mark-as-unread/client/actionButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
19 changes: 0 additions & 19 deletions
19
packages/rocketchat-message-mark-as-unread/server/unreadMessages.coffee
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
packages/rocketchat-message-mark-as-unread/server/unreadMessages.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |