[NEW] Mark message as unread (#1785)

Co-authored-by: Djorkaeff Alexandre <djorkaeff.unb@gmail.com>
This commit is contained in:
Youssef Muhamad 2020-02-28 16:31:19 -03:00 committed by GitHub
parent 98e65d69d4
commit 9d615d5ffb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 3 deletions

View File

@ -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;

View File

@ -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'
};

View File

@ -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'
};

View File

@ -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

View File

@ -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;