diff --git a/app/containers/MessageActions.js b/app/containers/MessageActions.js index ab3677fc..79f75c7c 100644 --- a/app/containers/MessageActions.js +++ b/app/containers/MessageActions.js @@ -63,6 +63,12 @@ class MessageActions extends React.Component { this.EDIT_INDEX = this.options.length - 1; } + // Mark as unread + if (message.u && message.u._id !== user.id) { + this.options.push(I18n.t('Mark_unread')); + this.UNREAD_INDEX = this.options.length - 1; + } + // Permalink this.options.push(I18n.t('Permalink')); this.PERMALINK_INDEX = this.options.length - 1; @@ -243,6 +249,30 @@ class MessageActions extends React.Component { editInit(message); } + handleUnread = async() => { + const { message, room } = this.props; + const { id: messageId, ts } = message; + const { rid } = room; + try { + const db = database.active; + const result = await RocketChat.markAsUnread({ messageId }); + if (result.success) { + const subCollection = db.collections.get('subscriptions'); + const subRecord = await subCollection.find(rid); + await db.action(async() => { + try { + await subRecord.update(sub => sub.lastOpen = ts); + } catch { + // do nothing + } + }); + Navigation.navigate('RoomsListView'); + } + } catch (e) { + log(e); + } + } + handleCopy = async() => { const { message } = this.props; await Clipboard.setString(message.msg); @@ -349,6 +379,9 @@ class MessageActions extends React.Component { case this.EDIT_INDEX: this.handleEdit(); break; + case this.UNREAD_INDEX: + this.handleUnread(); + break; case this.PERMALINK_INDEX: this.handlePermalink(); break; diff --git a/app/i18n/locales/en.js b/app/i18n/locales/en.js index 7f40b56b..7c9a01dc 100644 --- a/app/i18n/locales/en.js +++ b/app/i18n/locales/en.js @@ -501,5 +501,6 @@ export default { New_line: 'New line', You_will_be_logged_out_of_this_application: 'You will be logged out of this application.', Clear: 'Clear', - This_will_clear_all_your_offline_data: 'This will clear all your offline data.' + This_will_clear_all_your_offline_data: 'This will clear all your offline data.', + Mark_unread: 'Mark Unread' }; diff --git a/app/i18n/locales/pt-BR.js b/app/i18n/locales/pt-BR.js index 61711e32..4afde104 100644 --- a/app/i18n/locales/pt-BR.js +++ b/app/i18n/locales/pt-BR.js @@ -449,5 +449,6 @@ export default { New_line: 'Nova linha', You_will_be_logged_out_of_this_application: 'Você sairá deste aplicativo.', Clear: 'Limpar', - This_will_clear_all_your_offline_data: 'Isto limpará todos os seus dados offline.' + This_will_clear_all_your_offline_data: 'Isto limpará todos os seus dados offline.', + Mark_unread: 'Marcar como não Lida' }; diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 1858b451..81aacb89 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -649,6 +649,9 @@ const RocketChat = { // RC 0.49.0 return this.sdk.post('chat.update', { roomId: rid, msgId: id, text: msg }); }, + markAsUnread({ messageId }) { + return this.sdk.post('subscriptions.unread', { firstUnreadMessage: { _id: messageId } }); + }, toggleStarMessage(messageId, starred) { if (starred) { // RC 0.59.0 diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index c0df45fd..39053591 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -737,7 +737,7 @@ class RoomView extends React.Component { showUnreadSeparator = moment(item.ts).isAfter(lastOpen); } else { showUnreadSeparator = lastOpen - && moment(item.ts).isAfter(lastOpen) + && moment(item.ts).isSameOrAfter(lastOpen) && moment(previousItem.ts).isBefore(lastOpen); if (!moment(item.ts).isSame(previousItem.ts, 'day')) { dateSeparator = item.ts;