Unverified Commit 9d615d5f authored by Youssef Muhamad's avatar Youssef Muhamad Committed by GitHub
Browse files

[NEW] Mark message as unread (#1785)


Co-authored-by: default avatarDjorkaeff Alexandre <djorkaeff.unb@gmail.com>
parent 98e65d69
......@@ -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;
......
......@@ -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'
};
......@@ -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'
};
......@@ -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
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment