forked from EVOgeek/Vmeda.Online
MOBILE-2620 messages: Contact requests in user profile handler
parent
43cbd655d8
commit
1cefb4ae04
|
@ -95,14 +95,14 @@ export class AddonMessagesAddContactUserHandler implements CoreUserProfileHandle
|
||||||
|
|
||||||
this.messagesProvider.isContact(user.id).then((isContact) => {
|
this.messagesProvider.isContact(user.id).then((isContact) => {
|
||||||
if (isContact) {
|
if (isContact) {
|
||||||
const template = this.translate.instant('addon.messages.removecontactconfirm'),
|
const message = this.translate.instant('addon.messages.removecontactconfirm', {$a: user.fullname});
|
||||||
title = this.translate.instant('addon.messages.removecontact');
|
const okText = this.translate.instant('core.remove');
|
||||||
|
|
||||||
return this.domUtils.showConfirm(template, title, title).then(() => {
|
return this.domUtils.showConfirm(message, undefined, okText).then(() => {
|
||||||
return this.messagesProvider.removeContact(user.id);
|
return this.messagesProvider.removeContact(user.id);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return this.messagesProvider.addContact(user.id);
|
return this.addContact(user);
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
this.domUtils.showErrorModalDefault(error, 'core.error', true);
|
this.domUtils.showErrorModalDefault(error, 'core.error', true);
|
||||||
|
@ -125,10 +125,12 @@ export class AddonMessagesAddContactUserHandler implements CoreUserProfileHandle
|
||||||
protected checkButton(userId: number): Promise<void> {
|
protected checkButton(userId: number): Promise<void> {
|
||||||
this.updateButton(userId, {spinner: true});
|
this.updateButton(userId, {spinner: true});
|
||||||
|
|
||||||
|
const groupMessagingEnabled = this.messagesProvider.isGroupMessagingEnabled();
|
||||||
|
|
||||||
return this.messagesProvider.isContact(userId).then((isContact) => {
|
return this.messagesProvider.isContact(userId).then((isContact) => {
|
||||||
if (isContact) {
|
if (isContact) {
|
||||||
this.updateButton(userId, {
|
this.updateButton(userId, {
|
||||||
title: 'addon.messages.removecontact',
|
title: groupMessagingEnabled ? 'addon.messages.removefromyourcontacts' : 'addon.messages.removecontact',
|
||||||
class: 'addon-messages-removecontact-handler',
|
class: 'addon-messages-removecontact-handler',
|
||||||
icon: 'remove',
|
icon: 'remove',
|
||||||
hidden: false,
|
hidden: false,
|
||||||
|
@ -136,7 +138,7 @@ export class AddonMessagesAddContactUserHandler implements CoreUserProfileHandle
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.updateButton(userId, {
|
this.updateButton(userId, {
|
||||||
title: 'addon.messages.addcontact',
|
title: groupMessagingEnabled ? 'addon.messages.addtoyourcontacts' : 'addon.messages.addcontact',
|
||||||
class: 'addon-messages-addcontact-handler',
|
class: 'addon-messages-addcontact-handler',
|
||||||
icon: 'add',
|
icon: 'add',
|
||||||
hidden: false,
|
hidden: false,
|
||||||
|
@ -160,6 +162,42 @@ export class AddonMessagesAddContactUserHandler implements CoreUserProfileHandle
|
||||||
this.eventsProvider.trigger(CoreUserDelegate.UPDATE_HANDLER_EVENT, { handler: this.name, data: data, userId: userId });
|
this.eventsProvider.trigger(CoreUserDelegate.UPDATE_HANDLER_EVENT, { handler: this.name, data: data, userId: userId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a contact or send a contact request if group messaging is enabled.
|
||||||
|
*
|
||||||
|
* @param {any} user User to add as contact.
|
||||||
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
|
*/
|
||||||
|
protected addContact(user: any): Promise<any> {
|
||||||
|
if (!this.messagesProvider.isGroupMessagingEnabled()) {
|
||||||
|
return this.messagesProvider.addContact(user.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.messagesProvider.getMemberInfo(user.id).then((member) => {
|
||||||
|
const currentUserId = this.sitesProvider.getCurrentSiteUserId();
|
||||||
|
const requestSent = member.contactrequests.some((request) => {
|
||||||
|
return request.userid == currentUserId && request.requesteduserid == user.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (requestSent) {
|
||||||
|
const message = this.translate.instant('addon.messages.yourcontactrequestpending', {$a: user.fullname});
|
||||||
|
|
||||||
|
return this.domUtils.showAlert(null, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
const message = this.translate.instant('addon.messages.addcontactconfirm', {$a: user.fullname});
|
||||||
|
const okText = this.translate.instant('core.add');
|
||||||
|
|
||||||
|
return this.domUtils.showConfirm(message, undefined, okText).then(() => {
|
||||||
|
return this.messagesProvider.createContactRequest(user.id);
|
||||||
|
}).then(() => {
|
||||||
|
const message = this.translate.instant('addon.messages.contactrequestsent');
|
||||||
|
|
||||||
|
return this.domUtils.showAlert(null, message);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroyed method.
|
* Destroyed method.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue