Merge pull request #1894 from dpalou/MOBILE-2964

Mobile 2964
main
Juan Leyva 2019-05-07 20:34:07 +02:00 committed by GitHub
commit bb09944662
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 69 additions and 10 deletions

View File

@ -182,6 +182,7 @@
"addon.messages.deleteallconfirm": "message", "addon.messages.deleteallconfirm": "message",
"addon.messages.deleteallselfconfirm": "message", "addon.messages.deleteallselfconfirm": "message",
"addon.messages.deleteconversation": "message", "addon.messages.deleteconversation": "message",
"addon.messages.deleteforeveryone": "message",
"addon.messages.deletemessage": "local_moodlemobileapp", "addon.messages.deletemessage": "local_moodlemobileapp",
"addon.messages.deletemessageconfirmation": "local_moodlemobileapp", "addon.messages.deletemessageconfirmation": "local_moodlemobileapp",
"addon.messages.errordeletemessage": "local_moodlemobileapp", "addon.messages.errordeletemessage": "local_moodlemobileapp",

View File

@ -21,6 +21,7 @@
"deleteallconfirm": "Are you sure you would like to delete this entire conversation? This will not delete it for other conversation participants.", "deleteallconfirm": "Are you sure you would like to delete this entire conversation? This will not delete it for other conversation participants.",
"deleteallselfconfirm": "Are you sure you would like to delete this entire personal conversation?", "deleteallselfconfirm": "Are you sure you would like to delete this entire personal conversation?",
"deleteconversation": "Delete conversation", "deleteconversation": "Delete conversation",
"deleteforeveryone": "Delete for me and everyone",
"deletemessage": "Delete message", "deletemessage": "Delete message",
"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.", "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.",
"errordeletemessage": "Error while deleting the message.", "errordeletemessage": "Error while deleting the message.",

View File

@ -810,11 +810,25 @@ export class AddonMessagesDiscussionPage implements OnDestroy {
* @param {number} index Index where the message is to delete it from the view. * @param {number} index Index where the message is to delete it from the view.
*/ */
deleteMessage(message: any, index: number): void { deleteMessage(message: any, index: number): void {
const langKey = message.pending ? 'core.areyousure' : 'addon.messages.deletemessageconfirmation'; const canDeleteAll = this.conversation && this.conversation.candeletemessagesforallusers,
this.domUtils.showConfirm(this.translate.instant(langKey)).then(() => { langKey = message.pending || canDeleteAll ? 'core.areyousure' : 'addon.messages.deletemessageconfirmation',
options: any = {};
if (canDeleteAll && !message.pending) {
// Show delete for all checkbox.
options.inputs = [{
type: 'checkbox',
name: 'deleteforall',
checked: false,
value: true,
label: this.translate.instant('addon.messages.deleteforeveryone')
}];
}
this.domUtils.showConfirm(this.translate.instant(langKey), undefined, undefined, undefined, options).then((data) => {
const modal = this.domUtils.showModalLoading('core.deleting', true); const modal = this.domUtils.showModalLoading('core.deleting', true);
return this.messagesProvider.deleteMessage(message).then(() => { return this.messagesProvider.deleteMessage(message, data && data[0]).then(() => {
// Remove message from the list without having to wait for re-fetch. // Remove message from the list without having to wait for re-fetch.
this.messages.splice(index, 1); this.messages.splice(index, 1);
this.removeMessage(message.hash); this.removeMessage(message.hash);

View File

@ -244,12 +244,17 @@ export class AddonMessagesProvider {
* Delete a message (online or offline). * Delete a message (online or offline).
* *
* @param {any} message Message to delete. * @param {any} message Message to delete.
* @param {boolean} [deleteForAll] Whether the message should be deleted for all users.
* @return {Promise<any>} Promise resolved when the message has been deleted. * @return {Promise<any>} Promise resolved when the message has been deleted.
*/ */
deleteMessage(message: any): Promise<any> { deleteMessage(message: any, deleteForAll?: boolean): Promise<any> {
if (message.id) { if (message.id) {
// Message has ID, it means it has been sent to the server. // Message has ID, it means it has been sent to the server.
return this.deleteMessageOnline(message.id, message.read); if (deleteForAll) {
return this.deleteMessageForAllOnline(message.id);
} else {
return this.deleteMessageOnline(message.id, message.read);
}
} }
// It's an offline message. // It's an offline message.
@ -283,6 +288,24 @@ export class AddonMessagesProvider {
}); });
} }
/**
* Delete a message for all users.
*
* @param {number} id Message ID.
* @param {number} [userId] User we want to delete the message for. If not defined, use current user.
* @return {Promise<any>} Promise resolved when the message has been deleted.
*/
deleteMessageForAllOnline(id: number, userId?: number): Promise<any> {
const params: any = {
messageid: id,
userid: userId || this.sitesProvider.getCurrentSiteUserId()
};
return this.sitesProvider.getCurrentSite().write('core_message_delete_message_for_all_users', params).then(() => {
return this.invalidateDiscussionCache(userId);
});
}
/** /**
* Format a conversation. * Format a conversation.
* *

View File

@ -595,6 +595,25 @@ ion-app.app-root {
.alert-message { .alert-message {
overflow-y: auto; overflow-y: auto;
} }
ion-alert.core-nohead {
&.alert-md .alert-message {
padding-top: $alert-md-message-padding-bottom;
}
&.alert-ios .alert-message {
padding-top: $alert-ios-message-padding-bottom;
}
&.alert-wp .alert-message {
padding-top: $alert-wp-message-padding-bottom;
}
.alert-head {
display: none;
}
}
ion-alert .alert-checkbox-group {
border: 0;
}
ion-toast.core-toast-success .toast-wrapper{ ion-toast.core-toast-success .toast-wrapper{
background: $green-dark; background: $green-dark;

View File

@ -182,6 +182,7 @@
"addon.messages.deleteallconfirm": "Are you sure you would like to delete this entire conversation? This will not delete it for other conversation participants.", "addon.messages.deleteallconfirm": "Are you sure you would like to delete this entire conversation? This will not delete it for other conversation participants.",
"addon.messages.deleteallselfconfirm": "Are you sure you would like to delete this entire personal conversation?", "addon.messages.deleteallselfconfirm": "Are you sure you would like to delete this entire personal conversation?",
"addon.messages.deleteconversation": "Delete conversation", "addon.messages.deleteconversation": "Delete conversation",
"addon.messages.deleteforeveryone": "Delete for me and everyone",
"addon.messages.deletemessage": "Delete message", "addon.messages.deletemessage": "Delete message",
"addon.messages.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.", "addon.messages.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.",
"addon.messages.errordeletemessage": "Error while deleting the message.", "addon.messages.errordeletemessage": "Error while deleting the message.",

View File

@ -990,10 +990,10 @@ export class CoreDomUtilsProvider {
* @param {string} [title] Title of the modal. * @param {string} [title] Title of the modal.
* @param {string} [okText] Text of the OK button. * @param {string} [okText] Text of the OK button.
* @param {string} [cancelText] Text of the Cancel button. * @param {string} [cancelText] Text of the Cancel button.
* @param {any} [options] More options. See https://ionicframework.com/docs/api/components/alert/AlertController/ * @param {any} [options] More options. See https://ionicframework.com/docs/v3/api/components/alert/AlertController/
* @return {Promise<void>} Promise resolved if the user confirms and rejected with a canceled error if he cancels. * @return {Promise<any>} Promise resolved if the user confirms and rejected with a canceled error if he cancels.
*/ */
showConfirm(message: string, title?: string, okText?: string, cancelText?: string, options?: any): Promise<void> { showConfirm(message: string, title?: string, okText?: string, cancelText?: string, options?: any): Promise<any> {
return new Promise<void>((resolve, reject): void => { return new Promise<void>((resolve, reject): void => {
const hasHTMLTags = this.textUtils.hasHTMLTags(message); const hasHTMLTags = this.textUtils.hasHTMLTags(message);
let promise; let promise;
@ -1023,8 +1023,8 @@ export class CoreDomUtilsProvider {
}, },
{ {
text: okText || this.translate.instant('core.ok'), text: okText || this.translate.instant('core.ok'),
handler: (): void => { handler: (data: any): void => {
resolve(); resolve(data);
} }
} }
]; ];