Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVE] Rewrite clear all unread modal #22764

Merged
merged 3 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions app/ui-master/client/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { Template } from 'meteor/templating';

import { t } from '../../utils/client';
import { chatMessages } from '../../ui';
import { Layout, modal, popover, fireGlobalEvent, RoomManager } from '../../ui-utils';
import { Layout, popover, fireGlobalEvent, RoomManager } from '../../ui-utils';
import { settings } from '../../settings';
import { ChatSubscription } from '../../models';

import './body.html';
import { imperativeModal } from '../../../client/lib/imperativeModal';
import GenericModal from '../../../client/components/GenericModal';

Template.body.onRendered(function() {
new Clipboard('.clipboard');
Expand All @@ -21,14 +22,8 @@ Template.body.onRendered(function() {
if (e.keyCode === 27 && (e.shiftKey === true || e.ctrlKey === true) && (unread != null) && unread !== '') {
e.preventDefault();
e.stopPropagation();
modal.open({
title: t('Clear_all_unreads_question'),
type: 'warning',
confirmButtonText: t('Yes_clear_all'),
showCancelButton: true,
cancelButtonText: t('Cancel'),
confirmButtonColor: '#DD6B55',
}, function() {

const handleClearUnreadAllMessages = () => {
const subscriptions = ChatSubscription.find({
open: true,
}, {
Expand All @@ -47,6 +42,21 @@ Template.body.onRendered(function() {
Meteor.call('readMessages', subscription.rid);
}
});

imperativeModal.close();
};

imperativeModal.open({
component: GenericModal,
props: {
children: t('Are_you_sure_you_want_to_clear_all_unread_messages'),
variant: 'warning',
title: t('Clear_all_unreads_question'),
confirmText: t('Yes_clear_all'),
onClose: imperativeModal.close,
onCancel: imperativeModal.close,
onConfirm: handleClearUnreadAllMessages,
},
});
}
});
Expand Down
6 changes: 6 additions & 0 deletions app/ui-utils/client/lib/readMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export const readMessage = new class extends Emitter {
}

readNow(rid = Session.get('openedRoom')) {
const unread = Session.get('unread');

if (rid == null) {
this.log('readMessage -> readNow canceled, no rid informed');
return;
Expand All @@ -77,6 +79,10 @@ export const readMessage = new class extends Emitter {
return;
}

if ((unread != null) && unread !== '') {
return;
}

return Meteor.call('readMessages', rid, () => {
RoomHistoryManager.getRoom(rid).unreadNotLoaded.set(0);
return this.emit(rid);
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@
"are_also_typing": "are also typing",
"are_typing": "are typing",
"Are_you_sure": "Are you sure?",
"Are_you_sure_you_want_to_clear_all_unread_messages": "Are you sure you want to clear all unread messages?",
"Are_you_sure_you_want_to_close_this_chat": "Are you sure you want to close this chat?",
"Are_you_sure_you_want_to_delete_this_record": "Are you sure you want to delete this record?",
"Are_you_sure_you_want_to_delete_your_account": "Are you sure you want to delete your account?",
Expand Down