Skip to content

Commit

Permalink
MDL-55972 message: confirmation modal when deleting conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwyllie authored and mdjnelson committed Oct 7, 2016
1 parent 10ea827 commit 9d8f6f4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
1 change: 1 addition & 0 deletions lang/en/message.php
Expand Up @@ -46,6 +46,7 @@
$string['conversations'] = 'Conversations';
$string['defaultmessageoutputs'] = 'Default message outputs';
$string['defaults'] = 'Defaults';
$string['deleteallconfirm'] = "Are you sure you would like to delete this entire conversation?";
$string['deletemessage'] = 'Delete message';
$string['deletemessageconfirmation'] = 'Are you sure you want to delete this message? It will only be deleted from your messaging history and will still be viewable by the user who sent or received the message.';
$string['deleteselectedmessages'] = 'Delete selected messages';
Expand Down
61 changes: 42 additions & 19 deletions message/amd/src/message_area_messages.js
Expand Up @@ -22,8 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/custom_interaction_events',
'core/auto_rows', 'core_message/message_area_actions'],
function($, ajax, templates, notification, customEvents, AutoRows, Actions) {
'core/auto_rows', 'core_message/message_area_actions', 'core/modal_factory', 'core/modal_events', 'core/str'],
function($, ajax, templates, notification, customEvents, AutoRows, Actions, ModalFactory, ModalEvents, Str) {

var MESSAGES_AREA_DEFAULT_HEIGHT = 500;
var MESSAGES_RESPONSE_DEFAULT_HEIGHT = 50;
Expand All @@ -50,6 +50,9 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
/** @type {int} the number of messages to retrieve */
Messages.prototype._numMessagesToRetrieve = 20;

/** @type {Modal} the confirmation modal */
Messages.prototype._confirmationModal = null;

/** @type {Messagearea} The messaging area object. */
Messages.prototype.messageArea = null;

Expand Down Expand Up @@ -401,23 +404,43 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
* @private
*/
Messages.prototype._deleteAllMessages = function() {
var otherUserId = this._getUserId();
var request = {
methodname: 'core_message_delete_conversation',
args: {
userid: this.messageArea.getCurrentUserId(),
otheruserid: otherUserId
}
};

// Delete the conversation.
ajax.call([request])[0].then(function() {
// Clear the message area.
this.messageArea.find(this.messageArea.SELECTORS.MESSAGESAREA).empty();
// Let the app know a conversation was deleted.
this.messageArea.trigger(this.messageArea.EVENTS.CONVERSATIONDELETED, otherUserId);
this._hideDeleteAction();
}.bind(this), notification.exeption);
// Create the confirmation modal if we haven't already.
if (!this._confirmationModal) {
ModalFactory.create({
type: ModalFactory.types.CONFIRM,
body: Str.get_string('deleteallconfirm', 'message'),
}, this.messageArea.find(this.messageArea.SELECTORS.DELETEALLMESSAGES))
.done(function(modal) {
this._confirmationModal = modal;

// Only delete the conversation if the user agreed in the confirmation modal.
modal.getRoot().on(ModalEvents.yes, function() {
var otherUserId = this._getUserId();
var request = {
methodname: 'core_message_delete_conversation',
args: {
userid: this.messageArea.getCurrentUserId(),
otheruserid: otherUserId
}
};

// Delete the conversation.
ajax.call([request])[0].then(function() {
// Clear the message area.
this.messageArea.find(this.messageArea.SELECTORS.MESSAGESAREA).empty();
// Let the app know a conversation was deleted.
this.messageArea.trigger(this.messageArea.EVENTS.CONVERSATIONDELETED, otherUserId);
this._hideDeleteAction();
}.bind(this), notification.exeption);
}.bind(this));

// Display the confirmation.
modal.show();
}.bind(this));
} else {
// Otherwise just show the existing modal.
this._confirmationModal.show();
}
};

/**
Expand Down

0 comments on commit 9d8f6f4

Please sign in to comment.