MOBILE-4653 messages: Move AddonMessages constants
parent
dab0ea6c6e
commit
e69eed4f4c
|
@ -0,0 +1,52 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
export const ADDON_MESSAGES_NEW_MESSAGE_EVENT = 'addon_messages_new_message_event';
|
||||||
|
export const ADDON_MESSAGES_READ_CHANGED_EVENT = 'addon_messages_read_changed_event';
|
||||||
|
// Notify a conversation should be opened.
|
||||||
|
export const ADDON_MESSAGES_OPEN_CONVERSATION_EVENT = 'addon_messages_open_conversation_event';
|
||||||
|
export const ADDON_MESSAGES_UPDATE_CONVERSATION_LIST_EVENT = 'addon_messages_update_conversation_list_event';
|
||||||
|
export const ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT = 'addon_messages_member_changed_event';
|
||||||
|
export const ADDON_MESSAGES_UNREAD_CONVERSATION_COUNTS_EVENT = 'addon_messages_unread_conversation_counts_event';
|
||||||
|
export const ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT = 'addon_messages_contact_requests_count_event';
|
||||||
|
|
||||||
|
export const ADDON_MESSAGES_POLL_INTERVAL = 10000;
|
||||||
|
export const ADDON_MESSAGES_PUSH_SIMULATION_COMPONENT = 'AddonMessagesPushSimulation';
|
||||||
|
|
||||||
|
export const enum AddonMessagesMessagePrivacy {
|
||||||
|
COURSEMEMBER = 0, // Privacy setting for being messaged by anyone within courses user is member.
|
||||||
|
ONLYCONTACTS = 1, // Privacy setting for being messaged only by contacts.
|
||||||
|
SITE = 2, // Privacy setting for being messaged by anyone on the site.
|
||||||
|
}
|
||||||
|
|
||||||
|
export const enum AddonMessagesMessageConversationType {
|
||||||
|
INDIVIDUAL = 1, // An individual conversation.
|
||||||
|
GROUP = 2, // A group conversation.
|
||||||
|
SELF = 3, // A self conversation.
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ADDON_MESSAGES_LIMIT_CONTACTS = 50;
|
||||||
|
export const ADDON_MESSAGES_LIMIT_MESSAGES = 50;
|
||||||
|
export const ADDON_MESSAGES_LIMIT_INITIAL_USER_SEARCH = 3;
|
||||||
|
export const ADDON_MESSAGES_LIMIT_SEARCH = 50;
|
||||||
|
|
||||||
|
export const ADDON_MESSAGES_NOTIFICATION_PREFERENCES_KEY = 'message_provider_moodle_instantmessage';
|
||||||
|
|
||||||
|
export const ADDON_MESSAGES_AUTO_SYNCED = 'addon_messages_autom_synced';
|
||||||
|
|
||||||
|
export const enum AddonMessagesUpdateConversationAction {
|
||||||
|
MUTE = 'mute',
|
||||||
|
FAVOURITE = 'favourite',
|
||||||
|
DELETE = 'delete',
|
||||||
|
}
|
|
@ -15,7 +15,6 @@
|
||||||
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import {
|
import {
|
||||||
AddonMessagesProvider,
|
|
||||||
AddonMessagesGetContactsWSResponse,
|
AddonMessagesGetContactsWSResponse,
|
||||||
AddonMessagesSearchContactsContact,
|
AddonMessagesSearchContactsContact,
|
||||||
AddonMessagesGetContactsContact,
|
AddonMessagesGetContactsContact,
|
||||||
|
@ -29,6 +28,7 @@ import { CoreScreen } from '@services/screen';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
||||||
import { CoreKeyboard } from '@singletons/keyboard';
|
import { CoreKeyboard } from '@singletons/keyboard';
|
||||||
|
import { ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT } from '@addons/messages/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that displays the list of contacts.
|
* Page that displays the list of contacts.
|
||||||
|
@ -73,7 +73,7 @@ export class AddonMessagesContacts35Page implements OnInit, OnDestroy {
|
||||||
|
|
||||||
// Refresh the list when a contact request is confirmed.
|
// Refresh the list when a contact request is confirmed.
|
||||||
this.memberInfoObserver = CoreEvents.on(
|
this.memberInfoObserver = CoreEvents.on(
|
||||||
AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT,
|
ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT,
|
||||||
(data) => {
|
(data) => {
|
||||||
if (data.contactRequestConfirmed) {
|
if (data.contactRequestConfirmed) {
|
||||||
this.refreshData();
|
this.refreshData();
|
||||||
|
|
|
@ -18,12 +18,12 @@ import { CoreSites } from '@services/sites';
|
||||||
import {
|
import {
|
||||||
AddonMessages,
|
AddonMessages,
|
||||||
AddonMessagesConversationMember,
|
AddonMessagesConversationMember,
|
||||||
AddonMessagesProvider,
|
|
||||||
} from '../../services/messages';
|
} from '../../services/messages';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreScreen } from '@services/screen';
|
import { CoreScreen } from '@services/screen';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
||||||
|
import { ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT, ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT } from '@addons/messages/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that displays contacts and contact requests.
|
* Page that displays contacts and contact requests.
|
||||||
|
@ -63,7 +63,7 @@ export class AddonMessagesContactsPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
// Update the contact requests badge.
|
// Update the contact requests badge.
|
||||||
this.contactRequestsCountObserver = CoreEvents.on(
|
this.contactRequestsCountObserver = CoreEvents.on(
|
||||||
AddonMessagesProvider.CONTACT_REQUESTS_COUNT_EVENT,
|
ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT,
|
||||||
(data) => {
|
(data) => {
|
||||||
this.requestsBadge = data.count > 0 ? String(data.count) : '';
|
this.requestsBadge = data.count > 0 ? String(data.count) : '';
|
||||||
},
|
},
|
||||||
|
@ -72,7 +72,7 @@ export class AddonMessagesContactsPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
// Update block status of a user.
|
// Update block status of a user.
|
||||||
this.memberInfoObserver = CoreEvents.on(
|
this.memberInfoObserver = CoreEvents.on(
|
||||||
AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT,
|
ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT,
|
||||||
(data) => {
|
(data) => {
|
||||||
if (data.userBlocked || data.userUnblocked) {
|
if (data.userBlocked || data.userUnblocked) {
|
||||||
const user = this.confirmedContacts.find((user) => user.id == data.userId);
|
const user = this.confirmedContacts.find((user) => user.id == data.userId);
|
||||||
|
|
|
@ -18,17 +18,15 @@ import { AlertOptions } from '@ionic/core';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import {
|
import {
|
||||||
AddonMessagesProvider,
|
|
||||||
AddonMessagesConversationFormatted,
|
AddonMessagesConversationFormatted,
|
||||||
AddonMessagesConversationMember,
|
AddonMessagesConversationMember,
|
||||||
AddonMessagesGetMessagesMessage,
|
AddonMessagesGetMessagesMessage,
|
||||||
AddonMessages,
|
AddonMessages,
|
||||||
AddonMessagesConversationMessageFormatted,
|
AddonMessagesConversationMessageFormatted,
|
||||||
AddonMessagesSendMessageResults,
|
AddonMessagesSendMessageResults,
|
||||||
AddonMessagesUpdateConversationAction,
|
|
||||||
} from '../../services/messages';
|
} from '../../services/messages';
|
||||||
import { AddonMessagesOffline, AddonMessagesOfflineMessagesDBRecordFormatted } from '../../services/messages-offline';
|
import { AddonMessagesOffline, AddonMessagesOfflineMessagesDBRecordFormatted } from '../../services/messages-offline';
|
||||||
import { AddonMessagesSync, AddonMessagesSyncProvider } from '../../services/messages-sync';
|
import { AddonMessagesSync } from '../../services/messages-sync';
|
||||||
import { CoreUser } from '@features/user/services/user';
|
import { CoreUser } from '@features/user/services/user';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
|
@ -48,6 +46,18 @@ import { CoreText } from '@singletons/text';
|
||||||
import { CoreWait } from '@singletons/wait';
|
import { CoreWait } from '@singletons/wait';
|
||||||
import { CoreModals } from '@services/modals';
|
import { CoreModals } from '@services/modals';
|
||||||
import { CoreLoadings } from '@services/loadings';
|
import { CoreLoadings } from '@services/loadings';
|
||||||
|
import {
|
||||||
|
ADDON_MESSAGES_AUTO_SYNCED,
|
||||||
|
ADDON_MESSAGES_LIMIT_MESSAGES,
|
||||||
|
ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT,
|
||||||
|
ADDON_MESSAGES_NEW_MESSAGE_EVENT,
|
||||||
|
ADDON_MESSAGES_OPEN_CONVERSATION_EVENT,
|
||||||
|
ADDON_MESSAGES_POLL_INTERVAL,
|
||||||
|
ADDON_MESSAGES_READ_CHANGED_EVENT,
|
||||||
|
ADDON_MESSAGES_UPDATE_CONVERSATION_LIST_EVENT,
|
||||||
|
AddonMessagesMessageConversationType,
|
||||||
|
AddonMessagesUpdateConversationAction,
|
||||||
|
} from '@addons/messages/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that displays a message discussion page.
|
* Page that displays a message discussion page.
|
||||||
|
@ -125,7 +135,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
||||||
this.logger = CoreLogger.getInstance('AddonMessagesDiscussionPage');
|
this.logger = CoreLogger.getInstance('AddonMessagesDiscussionPage');
|
||||||
|
|
||||||
// Refresh data if this discussion is synchronized automatically.
|
// Refresh data if this discussion is synchronized automatically.
|
||||||
this.syncObserver = CoreEvents.on(AddonMessagesSyncProvider.AUTO_SYNCED, (data) => {
|
this.syncObserver = CoreEvents.on(ADDON_MESSAGES_AUTO_SYNCED, (data) => {
|
||||||
if ((data.userId && data.userId == this.userId) ||
|
if ((data.userId && data.userId == this.userId) ||
|
||||||
(data.conversationId && data.conversationId == this.conversationId)) {
|
(data.conversationId && data.conversationId == this.conversationId)) {
|
||||||
// Fetch messages.
|
// Fetch messages.
|
||||||
|
@ -140,7 +150,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
||||||
|
|
||||||
// Refresh data if info of a mamber of the conversation have changed.
|
// Refresh data if info of a mamber of the conversation have changed.
|
||||||
this.memberInfoObserver = CoreEvents.on(
|
this.memberInfoObserver = CoreEvents.on(
|
||||||
AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT,
|
ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT,
|
||||||
(data) => {
|
(data) => {
|
||||||
if (data.userId && (this.members[data.userId] || this.otherMember && data.userId == this.otherMember.id)) {
|
if (data.userId && (this.members[data.userId] || this.otherMember && data.userId == this.otherMember.id)) {
|
||||||
this.fetchData();
|
this.fetchData();
|
||||||
|
@ -595,13 +605,13 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
||||||
this.conversationId = this.conversation.id;
|
this.conversationId = this.conversation.id;
|
||||||
this.title = this.conversation.name;
|
this.title = this.conversation.name;
|
||||||
this.conversationImage = this.conversation.imageurl;
|
this.conversationImage = this.conversation.imageurl;
|
||||||
this.isGroup = this.conversation.type == AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_GROUP;
|
this.isGroup = this.conversation.type === AddonMessagesMessageConversationType.GROUP;
|
||||||
this.favouriteIcon = 'fas-star';
|
this.favouriteIcon = 'fas-star';
|
||||||
this.muteIcon = this.conversation.ismuted ? 'fas-bell' : 'fas-bell-slash';
|
this.muteIcon = this.conversation.ismuted ? 'fas-bell' : 'fas-bell-slash';
|
||||||
if (!this.isGroup) {
|
if (!this.isGroup) {
|
||||||
this.userId = this.conversation.userid;
|
this.userId = this.conversation.userid;
|
||||||
}
|
}
|
||||||
this.isSelf = this.conversation.type == AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_SELF;
|
this.isSelf = this.conversation.type === AddonMessagesMessageConversationType.SELF;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -645,7 +655,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
||||||
const messages: AddonMessagesConversationMessageFormatted[] = result.messages;
|
const messages: AddonMessagesConversationMessageFormatted[] = result.messages;
|
||||||
|
|
||||||
if (pagesToLoad > 0 && result.canLoadMore) {
|
if (pagesToLoad > 0 && result.canLoadMore) {
|
||||||
offset += AddonMessagesProvider.LIMIT_MESSAGES;
|
offset += ADDON_MESSAGES_LIMIT_MESSAGES;
|
||||||
|
|
||||||
// Get more messages.
|
// Get more messages.
|
||||||
const nextMessages = await this.getConversationMessages(pagesToLoad, offset);
|
const nextMessages = await this.getConversationMessages(pagesToLoad, offset);
|
||||||
|
@ -764,7 +774,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
||||||
}
|
}
|
||||||
|
|
||||||
if (readChanged) {
|
if (readChanged) {
|
||||||
CoreEvents.trigger(AddonMessagesProvider.READ_CHANGED_EVENT, {
|
CoreEvents.trigger(ADDON_MESSAGES_READ_CHANGED_EVENT, {
|
||||||
conversationId: this.conversationId,
|
conversationId: this.conversationId,
|
||||||
userId: this.userId,
|
userId: this.userId,
|
||||||
}, this.siteId);
|
}, this.siteId);
|
||||||
|
@ -789,7 +799,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
||||||
|
|
||||||
if (trigger) {
|
if (trigger) {
|
||||||
// Update discussions last message.
|
// Update discussions last message.
|
||||||
CoreEvents.trigger(AddonMessagesProvider.NEW_MESSAGE_EVENT, {
|
CoreEvents.trigger(ADDON_MESSAGES_NEW_MESSAGE_EVENT, {
|
||||||
conversationId: this.conversationId,
|
conversationId: this.conversationId,
|
||||||
userId: this.userId,
|
userId: this.userId,
|
||||||
message: this.lastMessage?.text,
|
message: this.lastMessage?.text,
|
||||||
|
@ -905,7 +915,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
||||||
this.fetchMessages().catch(() => {
|
this.fetchMessages().catch(() => {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
});
|
});
|
||||||
}, AddonMessagesProvider.POLL_INTERVAL);
|
}, ADDON_MESSAGES_POLL_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1265,7 +1275,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
||||||
if (splitViewLoaded) {
|
if (splitViewLoaded) {
|
||||||
// Notify the left pane to load it, this way the right conversation will be highlighted.
|
// Notify the left pane to load it, this way the right conversation will be highlighted.
|
||||||
CoreEvents.trigger(
|
CoreEvents.trigger(
|
||||||
AddonMessagesProvider.OPEN_CONVERSATION_EVENT,
|
ADDON_MESSAGES_OPEN_CONVERSATION_EVENT,
|
||||||
{ userId },
|
{ userId },
|
||||||
this.siteId,
|
this.siteId,
|
||||||
);
|
);
|
||||||
|
@ -1300,7 +1310,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
||||||
// Get the conversation data so it's cached. Don't block the user for this.
|
// Get the conversation data so it's cached. Don't block the user for this.
|
||||||
AddonMessages.getConversation(this.conversation.id, undefined, true);
|
AddonMessages.getConversation(this.conversation.id, undefined, true);
|
||||||
|
|
||||||
CoreEvents.trigger(AddonMessagesProvider.UPDATE_CONVERSATION_LIST_EVENT, {
|
CoreEvents.trigger(ADDON_MESSAGES_UPDATE_CONVERSATION_LIST_EVENT, {
|
||||||
conversationId: this.conversation.id,
|
conversationId: this.conversation.id,
|
||||||
action: AddonMessagesUpdateConversationAction.FAVOURITE,
|
action: AddonMessagesUpdateConversationAction.FAVOURITE,
|
||||||
value: this.conversation.isfavourite,
|
value: this.conversation.isfavourite,
|
||||||
|
@ -1332,7 +1342,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
||||||
// Get the conversation data so it's cached. Don't block the user for this.
|
// Get the conversation data so it's cached. Don't block the user for this.
|
||||||
AddonMessages.getConversation(this.conversation.id, undefined, true);
|
AddonMessages.getConversation(this.conversation.id, undefined, true);
|
||||||
|
|
||||||
CoreEvents.trigger(AddonMessagesProvider.UPDATE_CONVERSATION_LIST_EVENT, {
|
CoreEvents.trigger(ADDON_MESSAGES_UPDATE_CONVERSATION_LIST_EVENT, {
|
||||||
conversationId: this.conversation.id,
|
conversationId: this.conversation.id,
|
||||||
action: AddonMessagesUpdateConversationAction.MUTE,
|
action: AddonMessagesUpdateConversationAction.MUTE,
|
||||||
value: this.conversation.ismuted,
|
value: this.conversation.ismuted,
|
||||||
|
@ -1447,7 +1457,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
|
||||||
await AddonMessages.deleteConversation(this.conversation.id);
|
await AddonMessages.deleteConversation(this.conversation.id);
|
||||||
|
|
||||||
CoreEvents.trigger(
|
CoreEvents.trigger(
|
||||||
AddonMessagesProvider.UPDATE_CONVERSATION_LIST_EVENT,
|
ADDON_MESSAGES_UPDATE_CONVERSATION_LIST_EVENT,
|
||||||
{
|
{
|
||||||
conversationId: this.conversation.id,
|
conversationId: this.conversation.id,
|
||||||
action: AddonMessagesUpdateConversationAction.DELETE,
|
action: AddonMessagesUpdateConversationAction.DELETE,
|
||||||
|
|
|
@ -19,7 +19,6 @@ import {
|
||||||
AddonMessages,
|
AddonMessages,
|
||||||
AddonMessagesDiscussion,
|
AddonMessagesDiscussion,
|
||||||
AddonMessagesMessageAreaContact,
|
AddonMessagesMessageAreaContact,
|
||||||
AddonMessagesProvider,
|
|
||||||
} from '../../services/messages';
|
} from '../../services/messages';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
|
@ -33,6 +32,7 @@ import { CoreScreen } from '@services/screen';
|
||||||
import { CorePlatform } from '@services/platform';
|
import { CorePlatform } from '@services/platform';
|
||||||
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
||||||
import { CoreKeyboard } from '@singletons/keyboard';
|
import { CoreKeyboard } from '@singletons/keyboard';
|
||||||
|
import { ADDON_MESSAGES_NEW_MESSAGE_EVENT, ADDON_MESSAGES_READ_CHANGED_EVENT } from '@addons/messages/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that displays the list of discussions.
|
* Page that displays the list of discussions.
|
||||||
|
@ -75,7 +75,7 @@ export class AddonMessagesDiscussions35Page implements OnInit, OnDestroy {
|
||||||
|
|
||||||
// Update discussions when new message is received.
|
// Update discussions when new message is received.
|
||||||
this.newMessagesObserver = CoreEvents.on(
|
this.newMessagesObserver = CoreEvents.on(
|
||||||
AddonMessagesProvider.NEW_MESSAGE_EVENT,
|
ADDON_MESSAGES_NEW_MESSAGE_EVENT,
|
||||||
(data) => {
|
(data) => {
|
||||||
if (data.userId && this.discussions) {
|
if (data.userId && this.discussions) {
|
||||||
const discussion = this.discussions.find((disc) => disc.message?.user === data.userId);
|
const discussion = this.discussions.find((disc) => disc.message?.user === data.userId);
|
||||||
|
@ -97,7 +97,7 @@ export class AddonMessagesDiscussions35Page implements OnInit, OnDestroy {
|
||||||
|
|
||||||
// Update discussions when a message is read.
|
// Update discussions when a message is read.
|
||||||
this.readChangedObserver = CoreEvents.on(
|
this.readChangedObserver = CoreEvents.on(
|
||||||
AddonMessagesProvider.READ_CHANGED_EVENT,
|
ADDON_MESSAGES_READ_CHANGED_EVENT,
|
||||||
(data) => {
|
(data) => {
|
||||||
if (data.userId && this.discussions) {
|
if (data.userId && this.discussions) {
|
||||||
const discussion = this.discussions.find((disc) => disc.message?.user === data.userId);
|
const discussion = this.discussions.find((disc) => disc.message?.user === data.userId);
|
||||||
|
|
|
@ -17,12 +17,10 @@ import { AccordionGroupChangeEventDetail, IonAccordionGroup, IonContent } from '
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import {
|
import {
|
||||||
AddonMessagesProvider,
|
|
||||||
AddonMessagesConversationFormatted,
|
AddonMessagesConversationFormatted,
|
||||||
AddonMessages,
|
AddonMessages,
|
||||||
AddonMessagesNewMessagedEventData,
|
AddonMessagesNewMessagedEventData,
|
||||||
AddonMessagesUnreadConversationCountsEventData,
|
AddonMessagesUnreadConversationCountsEventData,
|
||||||
AddonMessagesUpdateConversationAction,
|
|
||||||
} from '../../services/messages';
|
} from '../../services/messages';
|
||||||
import {
|
import {
|
||||||
AddonMessagesOffline,
|
AddonMessagesOffline,
|
||||||
|
@ -40,6 +38,17 @@ import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreScreen } from '@services/screen';
|
import { CoreScreen } from '@services/screen';
|
||||||
import { CorePlatform } from '@services/platform';
|
import { CorePlatform } from '@services/platform';
|
||||||
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
||||||
|
import {
|
||||||
|
ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT,
|
||||||
|
ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT,
|
||||||
|
ADDON_MESSAGES_NEW_MESSAGE_EVENT,
|
||||||
|
ADDON_MESSAGES_OPEN_CONVERSATION_EVENT,
|
||||||
|
ADDON_MESSAGES_READ_CHANGED_EVENT,
|
||||||
|
ADDON_MESSAGES_UNREAD_CONVERSATION_COUNTS_EVENT,
|
||||||
|
ADDON_MESSAGES_UPDATE_CONVERSATION_LIST_EVENT,
|
||||||
|
AddonMessagesMessageConversationType,
|
||||||
|
AddonMessagesUpdateConversationAction,
|
||||||
|
} from '@addons/messages/constants';
|
||||||
|
|
||||||
const enum AddonMessagesGroupConversationOptionNames {
|
const enum AddonMessagesGroupConversationOptionNames {
|
||||||
FAVOURITES = 'favourites',
|
FAVOURITES = 'favourites',
|
||||||
|
@ -82,7 +91,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
optionName: AddonMessagesGroupConversationOptionNames.GROUP,
|
optionName: AddonMessagesGroupConversationOptionNames.GROUP,
|
||||||
titleString: 'addon.messages.groupconversations',
|
titleString: 'addon.messages.groupconversations',
|
||||||
emptyString: 'addon.messages.nogroupconversations',
|
emptyString: 'addon.messages.nogroupconversations',
|
||||||
type: AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_GROUP,
|
type: AddonMessagesMessageConversationType.GROUP,
|
||||||
favourites: false,
|
favourites: false,
|
||||||
count: 0,
|
count: 0,
|
||||||
unread: 0,
|
unread: 0,
|
||||||
|
@ -92,7 +101,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
optionName: AddonMessagesGroupConversationOptionNames.INDIVIDUAL,
|
optionName: AddonMessagesGroupConversationOptionNames.INDIVIDUAL,
|
||||||
titleString: 'addon.messages.individualconversations',
|
titleString: 'addon.messages.individualconversations',
|
||||||
emptyString: 'addon.messages.noindividualconversations',
|
emptyString: 'addon.messages.noindividualconversations',
|
||||||
type: AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
|
type: AddonMessagesMessageConversationType.INDIVIDUAL,
|
||||||
favourites: false,
|
favourites: false,
|
||||||
count: 0,
|
count: 0,
|
||||||
unread: 0,
|
unread: 0,
|
||||||
|
@ -100,7 +109,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
typeGroup = AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_GROUP;
|
typeGroup = AddonMessagesMessageConversationType.GROUP;
|
||||||
|
|
||||||
protected siteId: string;
|
protected siteId: string;
|
||||||
protected currentUserId: number;
|
protected currentUserId: number;
|
||||||
|
@ -124,7 +133,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
// Update conversations when new message is received.
|
// Update conversations when new message is received.
|
||||||
this.newMessagesObserver = CoreEvents.on(
|
this.newMessagesObserver = CoreEvents.on(
|
||||||
AddonMessagesProvider.NEW_MESSAGE_EVENT,
|
ADDON_MESSAGES_NEW_MESSAGE_EVENT,
|
||||||
(data) => {
|
(data) => {
|
||||||
// Check if the new message belongs to the option that is currently expanded.
|
// Check if the new message belongs to the option that is currently expanded.
|
||||||
const expandedOption = this.getExpandedOption();
|
const expandedOption = this.getExpandedOption();
|
||||||
|
@ -163,7 +172,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
conversation.lastmessagedate = data.timecreated / 1000;
|
conversation.lastmessagedate = data.timecreated / 1000;
|
||||||
if (data.userFrom) {
|
if (data.userFrom) {
|
||||||
conversation.sentfromcurrentuser = data.userFrom.id === this.currentUserId;
|
conversation.sentfromcurrentuser = data.userFrom.id === this.currentUserId;
|
||||||
if (conversation.type === AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_GROUP) {
|
if (conversation.type === AddonMessagesMessageConversationType.GROUP) {
|
||||||
conversation.members[0] = data.userFrom;
|
conversation.members[0] = data.userFrom;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,7 +192,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update conversations when a message is read.
|
// Update conversations when a message is read.
|
||||||
this.readChangedObserver = CoreEvents.on(AddonMessagesProvider.READ_CHANGED_EVENT, (data) => {
|
this.readChangedObserver = CoreEvents.on(ADDON_MESSAGES_READ_CHANGED_EVENT, (data) => {
|
||||||
if (data.conversationId) {
|
if (data.conversationId) {
|
||||||
const conversation = this.findConversation(data.conversationId);
|
const conversation = this.findConversation(data.conversationId);
|
||||||
|
|
||||||
|
@ -200,7 +209,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
// Load a discussion if we receive an event to do so.
|
// Load a discussion if we receive an event to do so.
|
||||||
this.openConversationObserver = CoreEvents.on(
|
this.openConversationObserver = CoreEvents.on(
|
||||||
AddonMessagesProvider.OPEN_CONVERSATION_EVENT,
|
ADDON_MESSAGES_OPEN_CONVERSATION_EVENT,
|
||||||
(data) => {
|
(data) => {
|
||||||
if (data.conversationId || data.userId) {
|
if (data.conversationId || data.userId) {
|
||||||
this.gotoConversation(data.conversationId, data.userId);
|
this.gotoConversation(data.conversationId, data.userId);
|
||||||
|
@ -222,7 +231,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
// Update conversations if we receive an event to do so.
|
// Update conversations if we receive an event to do so.
|
||||||
this.updateConversationListObserver = CoreEvents.on(
|
this.updateConversationListObserver = CoreEvents.on(
|
||||||
AddonMessagesProvider.UPDATE_CONVERSATION_LIST_EVENT,
|
ADDON_MESSAGES_UPDATE_CONVERSATION_LIST_EVENT,
|
||||||
(data) => {
|
(data) => {
|
||||||
if (data?.action === AddonMessagesUpdateConversationAction.MUTE) {
|
if (data?.action === AddonMessagesUpdateConversationAction.MUTE) {
|
||||||
// If the conversation is displayed, change its muted value.
|
// If the conversation is displayed, change its muted value.
|
||||||
|
@ -256,7 +265,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
// Update unread conversation counts.
|
// Update unread conversation counts.
|
||||||
this.cronObserver = CoreEvents.on(
|
this.cronObserver = CoreEvents.on(
|
||||||
AddonMessagesProvider.UNREAD_CONVERSATION_COUNTS_EVENT,
|
ADDON_MESSAGES_UNREAD_CONVERSATION_COUNTS_EVENT,
|
||||||
(data) => {
|
(data) => {
|
||||||
this.setCounts(data, 'unread');
|
this.setCounts(data, 'unread');
|
||||||
},
|
},
|
||||||
|
@ -265,7 +274,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
// Update the contact requests badge.
|
// Update the contact requests badge.
|
||||||
this.contactRequestsCountObserver = CoreEvents.on(
|
this.contactRequestsCountObserver = CoreEvents.on(
|
||||||
AddonMessagesProvider.CONTACT_REQUESTS_COUNT_EVENT,
|
ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT,
|
||||||
(data) => {
|
(data) => {
|
||||||
this.contactRequestsCount = data.count;
|
this.contactRequestsCount = data.count;
|
||||||
},
|
},
|
||||||
|
@ -274,7 +283,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
// Update block status of a user.
|
// Update block status of a user.
|
||||||
this.memberInfoObserver = CoreEvents.on(
|
this.memberInfoObserver = CoreEvents.on(
|
||||||
AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT,
|
ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT,
|
||||||
(data) => {
|
(data) => {
|
||||||
if (!data.userBlocked && !data.userUnblocked) {
|
if (!data.userBlocked && !data.userUnblocked) {
|
||||||
// The block status has not changed, ignore.
|
// The block status has not changed, ignore.
|
||||||
|
@ -638,7 +647,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
// Conversation not found, it could be an old one or the message could belong to another option.
|
// Conversation not found, it could be an old one or the message could belong to another option.
|
||||||
conversation = {
|
conversation = {
|
||||||
id: message.conversationid,
|
id: message.conversationid,
|
||||||
type: message.conversation?.type || AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
|
type: message.conversation?.type || AddonMessagesMessageConversationType.INDIVIDUAL,
|
||||||
membercount: message.conversation?.membercount || 0,
|
membercount: message.conversation?.membercount || 0,
|
||||||
ismuted: message.conversation?.ismuted || false,
|
ismuted: message.conversation?.ismuted || false,
|
||||||
isfavourite: message.conversation?.isfavourite || false,
|
isfavourite: message.conversation?.isfavourite || false,
|
||||||
|
@ -657,7 +666,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
this.addOfflineConversation(conversation, option);
|
this.addOfflineConversation(conversation, option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (option.type === AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) {
|
} else if (option.type === AddonMessagesMessageConversationType.INDIVIDUAL) {
|
||||||
// It's a new conversation. Check if we already created it (there is more than one message for the same user).
|
// It's a new conversation. Check if we already created it (there is more than one message for the same user).
|
||||||
const conversation = this.findConversation(undefined, message.touserid, option);
|
const conversation = this.findConversation(undefined, message.touserid, option);
|
||||||
|
|
||||||
|
@ -675,7 +684,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
}).then((user) => {
|
}).then((user) => {
|
||||||
const conversation: AddonMessagesConversationForList = {
|
const conversation: AddonMessagesConversationForList = {
|
||||||
id: 0,
|
id: 0,
|
||||||
type: AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
|
type: AddonMessagesMessageConversationType.INDIVIDUAL,
|
||||||
membercount: 0, // Faked data.
|
membercount: 0, // Faked data.
|
||||||
ismuted: false, // Faked data.
|
ismuted: false, // Faked data.
|
||||||
isfavourite: false, // Faked data.
|
isfavourite: false, // Faked data.
|
||||||
|
@ -742,7 +751,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
||||||
return AddonMessagesGroupConversationOptionNames.FAVOURITES;
|
return AddonMessagesGroupConversationOptionNames.FAVOURITES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conversation.type === AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_GROUP) {
|
if (conversation.type === AddonMessagesMessageConversationType.GROUP) {
|
||||||
return AddonMessagesGroupConversationOptionNames.GROUP;
|
return AddonMessagesGroupConversationOptionNames.GROUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ import { Component, OnDestroy, ViewChild } from '@angular/core';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import {
|
import {
|
||||||
AddonMessagesProvider,
|
|
||||||
AddonMessagesConversationMember,
|
AddonMessagesConversationMember,
|
||||||
AddonMessagesMessageAreaContact,
|
AddonMessagesMessageAreaContact,
|
||||||
AddonMessages,
|
AddonMessages,
|
||||||
|
@ -26,6 +25,11 @@ import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreScreen } from '@services/screen';
|
import { CoreScreen } from '@services/screen';
|
||||||
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
||||||
import { CoreKeyboard } from '@singletons/keyboard';
|
import { CoreKeyboard } from '@singletons/keyboard';
|
||||||
|
import {
|
||||||
|
ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT,
|
||||||
|
ADDON_MESSAGES_LIMIT_SEARCH,
|
||||||
|
ADDON_MESSAGES_LIMIT_INITIAL_USER_SEARCH,
|
||||||
|
} from '@addons/messages/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page for searching users.
|
* Page for searching users.
|
||||||
|
@ -74,7 +78,7 @@ export class AddonMessagesSearchPage implements OnDestroy {
|
||||||
constructor() {
|
constructor() {
|
||||||
// Update block status of a user.
|
// Update block status of a user.
|
||||||
this.memberInfoObserver = CoreEvents.on(
|
this.memberInfoObserver = CoreEvents.on(
|
||||||
AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT,
|
ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT,
|
||||||
(data) => {
|
(data) => {
|
||||||
if (!data.userBlocked && !data.userUnblocked) {
|
if (!data.userBlocked && !data.userUnblocked) {
|
||||||
// The block status has not changed, ignore.
|
// The block status has not changed, ignore.
|
||||||
|
@ -139,7 +143,7 @@ export class AddonMessagesSearchPage implements OnDestroy {
|
||||||
let canLoadMoreMessages = false;
|
let canLoadMoreMessages = false;
|
||||||
|
|
||||||
if (!loadMore || loadMore == 'contacts' || loadMore == 'noncontacts') {
|
if (!loadMore || loadMore == 'contacts' || loadMore == 'noncontacts') {
|
||||||
const limitNum = loadMore ? AddonMessagesProvider.LIMIT_SEARCH : AddonMessagesProvider.LIMIT_INITIAL_USER_SEARCH;
|
const limitNum = loadMore ? ADDON_MESSAGES_LIMIT_SEARCH : ADDON_MESSAGES_LIMIT_INITIAL_USER_SEARCH;
|
||||||
let limitFrom = 0;
|
let limitFrom = 0;
|
||||||
if (loadMore == 'contacts') {
|
if (loadMore == 'contacts') {
|
||||||
limitFrom = this.contacts.results.length;
|
limitFrom = this.contacts.results.length;
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
import { Component, OnDestroy, OnInit, signal } from '@angular/core';
|
import { Component, OnDestroy, OnInit, signal } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
AddonMessagesProvider, AddonMessagesMessagePreferences,
|
AddonMessagesMessagePreferences,
|
||||||
AddonMessagesMessagePreferencesNotification,
|
AddonMessagesMessagePreferencesNotification,
|
||||||
AddonMessagesMessagePreferencesNotificationProcessor,
|
AddonMessagesMessagePreferencesNotificationProcessor,
|
||||||
AddonMessages,
|
AddonMessages,
|
||||||
|
@ -29,6 +29,7 @@ import { AddonNotificationsPreferencesNotificationProcessorState } from '@addons
|
||||||
import { CorePlatform } from '@services/platform';
|
import { CorePlatform } from '@services/platform';
|
||||||
import { CoreErrorHelper } from '@services/error-helper';
|
import { CoreErrorHelper } from '@services/error-helper';
|
||||||
import { CoreLoadings } from '@services/loadings';
|
import { CoreLoadings } from '@services/loadings';
|
||||||
|
import { ADDON_MESSAGES_NOTIFICATION_PREFERENCES_KEY, AddonMessagesMessagePrivacy } from '@addons/messages/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that displays the messages settings page.
|
* Page that displays the messages settings page.
|
||||||
|
@ -46,9 +47,9 @@ export class AddonMessagesSettingsPage implements OnInit, OnDestroy {
|
||||||
contactablePrivacy?: number | boolean;
|
contactablePrivacy?: number | boolean;
|
||||||
advancedContactable = false; // Whether the site supports "advanced" contactable privacy.
|
advancedContactable = false; // Whether the site supports "advanced" contactable privacy.
|
||||||
allowSiteMessaging = false;
|
allowSiteMessaging = false;
|
||||||
onlyContactsValue = AddonMessagesProvider.MESSAGE_PRIVACY_ONLYCONTACTS;
|
onlyContactsValue = AddonMessagesMessagePrivacy.ONLYCONTACTS;
|
||||||
courseMemberValue = AddonMessagesProvider.MESSAGE_PRIVACY_COURSEMEMBER;
|
courseMemberValue = AddonMessagesMessagePrivacy.COURSEMEMBER;
|
||||||
siteValue = AddonMessagesProvider.MESSAGE_PRIVACY_SITE;
|
siteValue = AddonMessagesMessagePrivacy.SITE;
|
||||||
groupMessagingEnabled = false;
|
groupMessagingEnabled = false;
|
||||||
sendOnEnter = false;
|
sendOnEnter = false;
|
||||||
warningMessage = signal<string | undefined>(undefined);
|
warningMessage = signal<string | undefined>(undefined);
|
||||||
|
@ -91,7 +92,7 @@ export class AddonMessagesSettingsPage implements OnInit, OnDestroy {
|
||||||
for (const component of preferences.components) {
|
for (const component of preferences.components) {
|
||||||
// Only display get the notification preferences.
|
// Only display get the notification preferences.
|
||||||
component.notifications = component.notifications.filter((notification) =>
|
component.notifications = component.notifications.filter((notification) =>
|
||||||
notification.preferencekey == AddonMessagesProvider.NOTIFICATION_PREFERENCES_KEY);
|
notification.preferencekey === ADDON_MESSAGES_NOTIFICATION_PREFERENCES_KEY);
|
||||||
|
|
||||||
if (this.loggedInOffLegacyMode) {
|
if (this.loggedInOffLegacyMode) {
|
||||||
// Load enabled from loggedin / loggedoff values.
|
// Load enabled from loggedin / loggedoff values.
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
AddonMessagesProvider,
|
|
||||||
AddonMessages,
|
AddonMessages,
|
||||||
} from '../messages';
|
} from '../messages';
|
||||||
import { CoreMainMenuHandler, CoreMainMenuHandlerToDisplay } from '@features/mainmenu/services/mainmenu-delegate';
|
import { CoreMainMenuHandler, CoreMainMenuHandlerToDisplay } from '@features/mainmenu/services/mainmenu-delegate';
|
||||||
|
@ -28,6 +27,10 @@ import {
|
||||||
import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate';
|
import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { CoreMainMenuProvider } from '@features/mainmenu/services/mainmenu';
|
import { CoreMainMenuProvider } from '@features/mainmenu/services/mainmenu';
|
||||||
|
import {
|
||||||
|
ADDON_MESSAGES_UNREAD_CONVERSATION_COUNTS_EVENT,
|
||||||
|
ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT,
|
||||||
|
} from '@addons/messages/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to inject an option into main menu.
|
* Handler to inject an option into main menu.
|
||||||
|
@ -58,14 +61,14 @@ export class AddonMessagesMainMenuHandlerService implements CoreMainMenuHandler,
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
CoreEvents.on(AddonMessagesProvider.UNREAD_CONVERSATION_COUNTS_EVENT, (data) => {
|
CoreEvents.on(ADDON_MESSAGES_UNREAD_CONVERSATION_COUNTS_EVENT, (data) => {
|
||||||
this.unreadCount = data.favourites + data.individual + data.group + data.self;
|
this.unreadCount = data.favourites + data.individual + data.group + data.self;
|
||||||
this.orMore = !!data.orMore;
|
this.orMore = !!data.orMore;
|
||||||
|
|
||||||
data.siteId && this.updateBadge(data.siteId);
|
data.siteId && this.updateBadge(data.siteId);
|
||||||
});
|
});
|
||||||
|
|
||||||
CoreEvents.on(AddonMessagesProvider.CONTACT_REQUESTS_COUNT_EVENT, (data) => {
|
CoreEvents.on(ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT, (data) => {
|
||||||
this.contactRequestsCount = data.count;
|
this.contactRequestsCount = data.count;
|
||||||
|
|
||||||
data.siteId && this.updateBadge(data.siteId);
|
data.siteId && this.updateBadge(data.siteId);
|
||||||
|
|
|
@ -18,7 +18,6 @@ import {
|
||||||
AddonMessagesOffline, AddonMessagesOfflineAnyMessagesFormatted,
|
AddonMessagesOffline, AddonMessagesOfflineAnyMessagesFormatted,
|
||||||
} from './messages-offline';
|
} from './messages-offline';
|
||||||
import {
|
import {
|
||||||
AddonMessagesProvider,
|
|
||||||
AddonMessages,
|
AddonMessages,
|
||||||
AddonMessagesGetMessagesWSParams,
|
AddonMessagesGetMessagesWSParams,
|
||||||
} from './messages';
|
} from './messages';
|
||||||
|
@ -33,6 +32,20 @@ import { CoreError } from '@classes/errors/error';
|
||||||
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
||||||
import { CoreWait } from '@singletons/wait';
|
import { CoreWait } from '@singletons/wait';
|
||||||
import { CoreErrorHelper, CoreErrorObject } from '@services/error-helper';
|
import { CoreErrorHelper, CoreErrorObject } from '@services/error-helper';
|
||||||
|
import { ADDON_MESSAGES_AUTO_SYNCED, ADDON_MESSAGES_LIMIT_MESSAGES } from '../constants';
|
||||||
|
|
||||||
|
declare module '@singletons/events' {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Augment CoreEventsData interface with events specific to this service.
|
||||||
|
*
|
||||||
|
* @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
||||||
|
*/
|
||||||
|
export interface CoreEventsData {
|
||||||
|
[ADDON_MESSAGES_AUTO_SYNCED]: AddonMessagesSyncEvents;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to sync messages.
|
* Service to sync messages.
|
||||||
|
@ -40,8 +53,6 @@ import { CoreErrorHelper, CoreErrorObject } from '@services/error-helper';
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class AddonMessagesSyncProvider extends CoreSyncBaseProvider<AddonMessagesSyncEvents> {
|
export class AddonMessagesSyncProvider extends CoreSyncBaseProvider<AddonMessagesSyncEvents> {
|
||||||
|
|
||||||
static readonly AUTO_SYNCED = 'addon_messages_autom_synced';
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super('AddonMessagesSync');
|
super('AddonMessagesSync');
|
||||||
}
|
}
|
||||||
|
@ -113,7 +124,7 @@ export class AddonMessagesSyncProvider extends CoreSyncBaseProvider<AddonMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync successful, send event.
|
// Sync successful, send event.
|
||||||
CoreEvents.trigger(AddonMessagesSyncProvider.AUTO_SYNCED, result, siteId);
|
CoreEvents.trigger(ADDON_MESSAGES_AUTO_SYNCED, result, siteId);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}));
|
}));
|
||||||
|
@ -126,7 +137,7 @@ export class AddonMessagesSyncProvider extends CoreSyncBaseProvider<AddonMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync successful, send event.
|
// Sync successful, send event.
|
||||||
CoreEvents.trigger(AddonMessagesSyncProvider.AUTO_SYNCED, result, siteId);
|
CoreEvents.trigger(ADDON_MESSAGES_AUTO_SYNCED, result, siteId);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}));
|
}));
|
||||||
|
@ -305,7 +316,7 @@ export class AddonMessagesSyncProvider extends CoreSyncBaseProvider<AddonMessage
|
||||||
const params: AddonMessagesGetMessagesWSParams = {
|
const params: AddonMessagesGetMessagesWSParams = {
|
||||||
useridto: userId,
|
useridto: userId,
|
||||||
useridfrom: siteCurrentUserId,
|
useridfrom: siteCurrentUserId,
|
||||||
limitnum: AddonMessagesProvider.LIMIT_MESSAGES,
|
limitnum: ADDON_MESSAGES_LIMIT_MESSAGES,
|
||||||
};
|
};
|
||||||
const preSets: CoreSiteWSPreSets = {
|
const preSets: CoreSiteWSPreSets = {
|
||||||
cacheKey: AddonMessages.getCacheKeyForDiscussion(userId),
|
cacheKey: AddonMessages.getCacheKeyForDiscussion(userId),
|
||||||
|
|
|
@ -30,11 +30,28 @@ import { CoreSite } from '@classes/sites/site';
|
||||||
import { CoreWSExternalWarning } from '@services/ws';
|
import { CoreWSExternalWarning } from '@services/ws';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreError } from '@classes/errors/error';
|
||||||
import { AddonMessagesSyncEvents, AddonMessagesSyncProvider } from './messages-sync';
|
|
||||||
import { CoreWSError } from '@classes/errors/wserror';
|
import { CoreWSError } from '@classes/errors/wserror';
|
||||||
import { AddonNotificationsPreferencesNotificationProcessorState } from '@addons/notifications/services/notifications';
|
import { AddonNotificationsPreferencesNotificationProcessorState } from '@addons/notifications/services/notifications';
|
||||||
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
||||||
import { CoreCacheUpdateFrequency } from '@/core/constants';
|
import { CoreCacheUpdateFrequency } from '@/core/constants';
|
||||||
|
import {
|
||||||
|
ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT,
|
||||||
|
ADDON_MESSAGES_LIMIT_CONTACTS,
|
||||||
|
ADDON_MESSAGES_LIMIT_INITIAL_USER_SEARCH,
|
||||||
|
ADDON_MESSAGES_LIMIT_MESSAGES,
|
||||||
|
ADDON_MESSAGES_LIMIT_SEARCH,
|
||||||
|
ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT,
|
||||||
|
ADDON_MESSAGES_NEW_MESSAGE_EVENT,
|
||||||
|
ADDON_MESSAGES_OPEN_CONVERSATION_EVENT,
|
||||||
|
ADDON_MESSAGES_POLL_INTERVAL,
|
||||||
|
ADDON_MESSAGES_PUSH_SIMULATION_COMPONENT,
|
||||||
|
ADDON_MESSAGES_READ_CHANGED_EVENT,
|
||||||
|
ADDON_MESSAGES_UNREAD_CONVERSATION_COUNTS_EVENT,
|
||||||
|
ADDON_MESSAGES_UPDATE_CONVERSATION_LIST_EVENT,
|
||||||
|
AddonMessagesMessageConversationType,
|
||||||
|
AddonMessagesMessagePrivacy,
|
||||||
|
AddonMessagesUpdateConversationAction,
|
||||||
|
} from '../constants';
|
||||||
|
|
||||||
declare module '@singletons/events' {
|
declare module '@singletons/events' {
|
||||||
|
|
||||||
|
@ -44,24 +61,17 @@ declare module '@singletons/events' {
|
||||||
* @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
* @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
||||||
*/
|
*/
|
||||||
export interface CoreEventsData {
|
export interface CoreEventsData {
|
||||||
[AddonMessagesProvider.NEW_MESSAGE_EVENT]: AddonMessagesNewMessagedEventData;
|
[ADDON_MESSAGES_NEW_MESSAGE_EVENT]: AddonMessagesNewMessagedEventData;
|
||||||
[AddonMessagesProvider.READ_CHANGED_EVENT]: AddonMessagesReadChangedEventData;
|
[ADDON_MESSAGES_READ_CHANGED_EVENT]: AddonMessagesReadChangedEventData;
|
||||||
[AddonMessagesProvider.OPEN_CONVERSATION_EVENT]: AddonMessagesOpenConversationEventData;
|
[ADDON_MESSAGES_OPEN_CONVERSATION_EVENT]: AddonMessagesOpenConversationEventData;
|
||||||
[AddonMessagesProvider.UPDATE_CONVERSATION_LIST_EVENT]: AddonMessagesUpdateConversationListEventData;
|
[ADDON_MESSAGES_UPDATE_CONVERSATION_LIST_EVENT]: AddonMessagesUpdateConversationListEventData;
|
||||||
[AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT]: AddonMessagesMemberInfoChangedEventData;
|
[ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT]: AddonMessagesMemberInfoChangedEventData;
|
||||||
[AddonMessagesProvider.UNREAD_CONVERSATION_COUNTS_EVENT]: AddonMessagesUnreadConversationCountsEventData;
|
[ADDON_MESSAGES_UNREAD_CONVERSATION_COUNTS_EVENT]: AddonMessagesUnreadConversationCountsEventData;
|
||||||
[AddonMessagesProvider.CONTACT_REQUESTS_COUNT_EVENT]: AddonMessagesContactRequestCountEventData;
|
[ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT]: AddonMessagesContactRequestCountEventData;
|
||||||
[AddonMessagesSyncProvider.AUTO_SYNCED]: AddonMessagesSyncEvents;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum AddonMessagesUpdateConversationAction {
|
|
||||||
MUTE = 'mute',
|
|
||||||
FAVOURITE = 'favourite',
|
|
||||||
DELETE = 'delete',
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to handle messages.
|
* Service to handle messages.
|
||||||
*/
|
*/
|
||||||
|
@ -70,27 +80,87 @@ export class AddonMessagesProvider {
|
||||||
|
|
||||||
protected static readonly ROOT_CACHE_KEY = 'mmaMessages:';
|
protected static readonly ROOT_CACHE_KEY = 'mmaMessages:';
|
||||||
|
|
||||||
static readonly NEW_MESSAGE_EVENT = 'addon_messages_new_message_event';
|
/**
|
||||||
static readonly READ_CHANGED_EVENT = 'addon_messages_read_changed_event';
|
* @deprecated since 5.0. Use ADDON_MESSAGES_NEW_MESSAGE_EVENT instead.
|
||||||
static readonly OPEN_CONVERSATION_EVENT = 'addon_messages_open_conversation_event'; // Notify a conversation should be opened.
|
*/
|
||||||
static readonly UPDATE_CONVERSATION_LIST_EVENT = 'addon_messages_update_conversation_list_event';
|
static readonly NEW_MESSAGE_EVENT = ADDON_MESSAGES_NEW_MESSAGE_EVENT;
|
||||||
static readonly MEMBER_INFO_CHANGED_EVENT = 'addon_messages_member_changed_event';
|
/**
|
||||||
static readonly UNREAD_CONVERSATION_COUNTS_EVENT = 'addon_messages_unread_conversation_counts_event';
|
* @deprecated since 5.0. Use ADDON_MESSAGES_READ_CHANGED_EVENT instead.
|
||||||
static readonly CONTACT_REQUESTS_COUNT_EVENT = 'addon_messages_contact_requests_count_event';
|
*/
|
||||||
static readonly POLL_INTERVAL = 10000;
|
static readonly READ_CHANGED_EVENT = ADDON_MESSAGES_READ_CHANGED_EVENT;
|
||||||
static readonly PUSH_SIMULATION_COMPONENT = 'AddonMessagesPushSimulation';
|
/**
|
||||||
|
* @deprecated since 5.0. Use ADDON_MESSAGES_OPEN_CONVERSATION_EVENT instead.
|
||||||
|
*/
|
||||||
|
static readonly OPEN_CONVERSATION_EVENT = ADDON_MESSAGES_OPEN_CONVERSATION_EVENT;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use ADDON_MESSAGES_UPDATE_CONVERSATION_LIST_EVENT instead.
|
||||||
|
*/
|
||||||
|
static readonly UPDATE_CONVERSATION_LIST_EVENT = ADDON_MESSAGES_UPDATE_CONVERSATION_LIST_EVENT;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT instead.
|
||||||
|
*/
|
||||||
|
static readonly MEMBER_INFO_CHANGED_EVENT = ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use ADDON_MESSAGES_UNREAD_CONVERSATION_COUNTS_EVENT instead.
|
||||||
|
*/
|
||||||
|
static readonly UNREAD_CONVERSATION_COUNTS_EVENT = ADDON_MESSAGES_UNREAD_CONVERSATION_COUNTS_EVENT;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT instead.
|
||||||
|
*/
|
||||||
|
static readonly CONTACT_REQUESTS_COUNT_EVENT = ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use ADDON_MESSAGES_POLL_INTERVAL instead.
|
||||||
|
*/
|
||||||
|
static readonly POLL_INTERVAL = ADDON_MESSAGES_POLL_INTERVAL;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use ADDON_MESSAGES_PUSH_SIMULATION_COMPONENT instead.
|
||||||
|
*/
|
||||||
|
static readonly PUSH_SIMULATION_COMPONENT = ADDON_MESSAGES_PUSH_SIMULATION_COMPONENT;
|
||||||
|
|
||||||
static readonly MESSAGE_PRIVACY_COURSEMEMBER = 0; // Privacy setting for being messaged by anyone within courses user is member.
|
/**
|
||||||
static readonly MESSAGE_PRIVACY_ONLYCONTACTS = 1; // Privacy setting for being messaged only by contacts.
|
* @deprecated since 5.0. Use AddonMessagesMessagePrivacy.COURSEMEMBER instead.
|
||||||
static readonly MESSAGE_PRIVACY_SITE = 2; // Privacy setting for being messaged by anyone on the site.
|
*/
|
||||||
static readonly MESSAGE_CONVERSATION_TYPE_INDIVIDUAL = 1; // An individual conversation.
|
static readonly MESSAGE_PRIVACY_COURSEMEMBER = AddonMessagesMessagePrivacy.COURSEMEMBER;
|
||||||
static readonly MESSAGE_CONVERSATION_TYPE_GROUP = 2; // A group conversation.
|
/**
|
||||||
static readonly MESSAGE_CONVERSATION_TYPE_SELF = 3; // A self conversation.
|
* @deprecated since 5.0. Use AddonMessagesMessagePrivacy.ONLYCONTACTS instead.
|
||||||
static readonly LIMIT_CONTACTS = 50;
|
*/
|
||||||
static readonly LIMIT_MESSAGES = 50;
|
static readonly MESSAGE_PRIVACY_ONLYCONTACTS = AddonMessagesMessagePrivacy.ONLYCONTACTS;
|
||||||
static readonly LIMIT_INITIAL_USER_SEARCH = 3;
|
/**
|
||||||
static readonly LIMIT_SEARCH = 50;
|
* @deprecated since 5.0. Use AddonMessagesMessagePrivacy.SITE instead.
|
||||||
|
*/
|
||||||
|
static readonly MESSAGE_PRIVACY_SITE = AddonMessagesMessagePrivacy.SITE;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use AddonMessagesMessageConversationType.INDIVIDUAL instead.
|
||||||
|
*/
|
||||||
|
static readonly MESSAGE_CONVERSATION_TYPE_INDIVIDUAL = AddonMessagesMessageConversationType.INDIVIDUAL;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use AddonMessagesMessageConversationType.GROUP instead.
|
||||||
|
*/
|
||||||
|
static readonly MESSAGE_CONVERSATION_TYPE_GROUP = AddonMessagesMessageConversationType.GROUP;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use AddonMessagesMessageConversationType.SELF instead.
|
||||||
|
*/
|
||||||
|
static readonly MESSAGE_CONVERSATION_TYPE_SELF = AddonMessagesMessageConversationType.SELF;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use ADDON_MESSAGES_LIMIT_CONTACTS instead.
|
||||||
|
*/
|
||||||
|
static readonly LIMIT_CONTACTS = ADDON_MESSAGES_LIMIT_CONTACTS;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use ADDON_MESSAGES_LIMIT_MESSAGES instead.
|
||||||
|
*/
|
||||||
|
static readonly LIMIT_MESSAGES = ADDON_MESSAGES_LIMIT_MESSAGES;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use ADDON_MESSAGES_LIMIT_INITIAL_USER_SEARCH instead.
|
||||||
|
*/
|
||||||
|
static readonly LIMIT_INITIAL_USER_SEARCH = ADDON_MESSAGES_LIMIT_INITIAL_USER_SEARCH;
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use ADDON_MESSAGES_LIMIT_SEARCH instead.
|
||||||
|
*/
|
||||||
|
static readonly LIMIT_SEARCH = ADDON_MESSAGES_LIMIT_SEARCH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated since 5.0. Use ADDON_MESSAGES_NEW_MESSAGE_EVENT instead.
|
||||||
|
*/
|
||||||
static readonly NOTIFICATION_PREFERENCES_KEY = 'message_provider_moodle_instantmessage';
|
static readonly NOTIFICATION_PREFERENCES_KEY = 'message_provider_moodle_instantmessage';
|
||||||
|
|
||||||
protected logger: CoreLogger;
|
protected logger: CoreLogger;
|
||||||
|
@ -148,7 +218,7 @@ export class AddonMessagesProvider {
|
||||||
} finally {
|
} finally {
|
||||||
const data: AddonMessagesMemberInfoChangedEventData = { userId, userBlocked: true };
|
const data: AddonMessagesMemberInfoChangedEventData = { userId, userBlocked: true };
|
||||||
|
|
||||||
CoreEvents.trigger(AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT, data, site.id);
|
CoreEvents.trigger(ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT, data, site.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +247,7 @@ export class AddonMessagesProvider {
|
||||||
this.refreshContactRequestsCount(site.id),
|
this.refreshContactRequestsCount(site.id),
|
||||||
]).finally(() => {
|
]).finally(() => {
|
||||||
const data: AddonMessagesMemberInfoChangedEventData = { userId, contactRequestConfirmed: true };
|
const data: AddonMessagesMemberInfoChangedEventData = { userId, contactRequestConfirmed: true };
|
||||||
CoreEvents.trigger(AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT, data, site.id);
|
CoreEvents.trigger(ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT, data, site.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +283,7 @@ export class AddonMessagesProvider {
|
||||||
|
|
||||||
await this.invalidateAllMemberInfo(userId, site).finally(() => {
|
await this.invalidateAllMemberInfo(userId, site).finally(() => {
|
||||||
const data: AddonMessagesMemberInfoChangedEventData = { userId, contactRequestCreated: true };
|
const data: AddonMessagesMemberInfoChangedEventData = { userId, contactRequestCreated: true };
|
||||||
CoreEvents.trigger(AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT, data, site.id);
|
CoreEvents.trigger(ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT, data, site.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +310,7 @@ export class AddonMessagesProvider {
|
||||||
this.refreshContactRequestsCount(site.id),
|
this.refreshContactRequestsCount(site.id),
|
||||||
]).finally(() => {
|
]).finally(() => {
|
||||||
const data: AddonMessagesMemberInfoChangedEventData = { userId, contactRequestDeclined: true };
|
const data: AddonMessagesMemberInfoChangedEventData = { userId, contactRequestDeclined: true };
|
||||||
CoreEvents.trigger(AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT, data, site.id);
|
CoreEvents.trigger(ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT, data, site.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,8 +444,8 @@ export class AddonMessagesProvider {
|
||||||
conversation.lastmessagedate = lastMessage ? lastMessage.timecreated : undefined;
|
conversation.lastmessagedate = lastMessage ? lastMessage.timecreated : undefined;
|
||||||
conversation.sentfromcurrentuser = lastMessage ? lastMessage.useridfrom == userId : undefined;
|
conversation.sentfromcurrentuser = lastMessage ? lastMessage.useridfrom == userId : undefined;
|
||||||
|
|
||||||
if (conversation.type != AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_GROUP) {
|
if (conversation.type != AddonMessagesMessageConversationType.GROUP) {
|
||||||
const isIndividual = conversation.type == AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_INDIVIDUAL;
|
const isIndividual = conversation.type == AddonMessagesMessageConversationType.INDIVIDUAL;
|
||||||
|
|
||||||
const otherUser = conversation.members.find((member) =>
|
const otherUser = conversation.members.find((member) =>
|
||||||
(isIndividual && member.id != userId) || (!isIndividual && member.id == userId));
|
(isIndividual && member.id != userId) || (!isIndividual && member.id == userId));
|
||||||
|
@ -680,14 +750,14 @@ export class AddonMessagesProvider {
|
||||||
* Get the list of user contacts.
|
* Get the list of user contacts.
|
||||||
*
|
*
|
||||||
* @param limitFrom Position of the first contact to fetch.
|
* @param limitFrom Position of the first contact to fetch.
|
||||||
* @param limitNum Number of contacts to fetch. Default is AddonMessagesProvider.LIMIT_CONTACTS.
|
* @param limitNum Number of contacts to fetch. Default is ADDON_MESSAGES_LIMIT_CONTACTS.
|
||||||
* @param siteId Site ID. If not defined, use current site.
|
* @param siteId Site ID. If not defined, use current site.
|
||||||
* @returns Promise resolved with the list of user contacts.
|
* @returns Promise resolved with the list of user contacts.
|
||||||
* @since 3.6
|
* @since 3.6
|
||||||
*/
|
*/
|
||||||
async getUserContacts(
|
async getUserContacts(
|
||||||
limitFrom: number = 0,
|
limitFrom: number = 0,
|
||||||
limitNum: number = AddonMessagesProvider.LIMIT_CONTACTS,
|
limitNum: number = ADDON_MESSAGES_LIMIT_CONTACTS,
|
||||||
siteId?: string,
|
siteId?: string,
|
||||||
): Promise<{contacts: AddonMessagesConversationMember[]; canLoadMore: boolean}> {
|
): Promise<{contacts: AddonMessagesConversationMember[]; canLoadMore: boolean}> {
|
||||||
const site = await CoreSites.getSite(siteId);
|
const site = await CoreSites.getSite(siteId);
|
||||||
|
@ -724,14 +794,14 @@ export class AddonMessagesProvider {
|
||||||
* Get the contact request sent to the current user.
|
* Get the contact request sent to the current user.
|
||||||
*
|
*
|
||||||
* @param limitFrom Position of the first contact request to fetch.
|
* @param limitFrom Position of the first contact request to fetch.
|
||||||
* @param limitNum Number of contact requests to fetch. Default is AddonMessagesProvider.LIMIT_CONTACTS.
|
* @param limitNum Number of contact requests to fetch. Default is ADDON_MESSAGES_LIMIT_CONTACTS.
|
||||||
* @param siteId Site ID. If not defined, use current site.
|
* @param siteId Site ID. If not defined, use current site.
|
||||||
* @returns Promise resolved with the list of contact requests.
|
* @returns Promise resolved with the list of contact requests.
|
||||||
* @since 3.6
|
* @since 3.6
|
||||||
*/
|
*/
|
||||||
async getContactRequests(
|
async getContactRequests(
|
||||||
limitFrom: number = 0,
|
limitFrom: number = 0,
|
||||||
limitNum: number = AddonMessagesProvider.LIMIT_CONTACTS,
|
limitNum: number = ADDON_MESSAGES_LIMIT_CONTACTS,
|
||||||
siteId?: string,
|
siteId?: string,
|
||||||
): Promise<{requests: AddonMessagesConversationMember[]; canLoadMore: boolean}> {
|
): Promise<{requests: AddonMessagesConversationMember[]; canLoadMore: boolean}> {
|
||||||
const site = await CoreSites.getSite(siteId);
|
const site = await CoreSites.getSite(siteId);
|
||||||
|
@ -792,7 +862,7 @@ export class AddonMessagesProvider {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Notify the new count so all badges are updated.
|
// Notify the new count so all badges are updated.
|
||||||
CoreEvents.trigger(AddonMessagesProvider.CONTACT_REQUESTS_COUNT_EVENT, data , site.id);
|
CoreEvents.trigger(ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT, data , site.id);
|
||||||
|
|
||||||
return data.count;
|
return data.count;
|
||||||
|
|
||||||
|
@ -936,7 +1006,7 @@ export class AddonMessagesProvider {
|
||||||
): Promise<{members: AddonMessagesConversationMember[]; canLoadMore: boolean}> {
|
): Promise<{members: AddonMessagesConversationMember[]; canLoadMore: boolean}> {
|
||||||
const site = await CoreSites.getSite(siteId);
|
const site = await CoreSites.getSite(siteId);
|
||||||
userId = userId || site.getUserId();
|
userId = userId || site.getUserId();
|
||||||
limitTo = limitTo ?? AddonMessagesProvider.LIMIT_MESSAGES;
|
limitTo = limitTo ?? ADDON_MESSAGES_LIMIT_MESSAGES;
|
||||||
|
|
||||||
const preSets: CoreSiteWSPreSets = {
|
const preSets: CoreSiteWSPreSets = {
|
||||||
cacheKey: this.getCacheKeyForConversationMembers(userId, conversationId),
|
cacheKey: this.getCacheKeyForConversationMembers(userId, conversationId),
|
||||||
|
@ -984,7 +1054,7 @@ export class AddonMessagesProvider {
|
||||||
|
|
||||||
options.userId = options.userId || site.getUserId();
|
options.userId = options.userId || site.getUserId();
|
||||||
options.limitFrom = options.limitFrom || 0;
|
options.limitFrom = options.limitFrom || 0;
|
||||||
options.limitTo = options.limitTo ?? AddonMessagesProvider.LIMIT_MESSAGES;
|
options.limitTo = options.limitTo ?? ADDON_MESSAGES_LIMIT_MESSAGES;
|
||||||
options.timeFrom = options.timeFrom || 0;
|
options.timeFrom = options.timeFrom || 0;
|
||||||
options.newestFirst = options.newestFirst ?? true;
|
options.newestFirst = options.newestFirst ?? true;
|
||||||
|
|
||||||
|
@ -1077,7 +1147,7 @@ export class AddonMessagesProvider {
|
||||||
const params: AddonMessagesGetConversationsWSParams = {
|
const params: AddonMessagesGetConversationsWSParams = {
|
||||||
userid: userId,
|
userid: userId,
|
||||||
limitfrom: limitFrom,
|
limitfrom: limitFrom,
|
||||||
limitnum: AddonMessagesProvider.LIMIT_MESSAGES + 1,
|
limitnum: ADDON_MESSAGES_LIMIT_MESSAGES + 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (forceCache) {
|
if (forceCache) {
|
||||||
|
@ -1092,7 +1162,7 @@ export class AddonMessagesProvider {
|
||||||
if (favourites !== undefined && favourites != null) {
|
if (favourites !== undefined && favourites != null) {
|
||||||
params.favourites = !!favourites;
|
params.favourites = !!favourites;
|
||||||
}
|
}
|
||||||
if (site.isVersionGreaterEqualThan('3.7') && type != AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_GROUP) {
|
if (site.isVersionGreaterEqualThan('3.7') && type != AddonMessagesMessageConversationType.GROUP) {
|
||||||
// Add self conversation to the list.
|
// Add self conversation to the list.
|
||||||
params.mergeself = true;
|
params.mergeself = true;
|
||||||
}
|
}
|
||||||
|
@ -1113,12 +1183,12 @@ export class AddonMessagesProvider {
|
||||||
|
|
||||||
// Format the conversations, adding some calculated fields.
|
// Format the conversations, adding some calculated fields.
|
||||||
const conversations = response.conversations
|
const conversations = response.conversations
|
||||||
.slice(0, AddonMessagesProvider.LIMIT_MESSAGES)
|
.slice(0, ADDON_MESSAGES_LIMIT_MESSAGES)
|
||||||
.map((conversation) => this.formatConversation(conversation, userId!));
|
.map((conversation) => this.formatConversation(conversation, userId!));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
conversations,
|
conversations,
|
||||||
canLoadMore: response.conversations.length > AddonMessagesProvider.LIMIT_MESSAGES,
|
canLoadMore: response.conversations.length > ADDON_MESSAGES_LIMIT_MESSAGES,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1145,9 +1215,9 @@ export class AddonMessagesProvider {
|
||||||
|
|
||||||
const counts = {
|
const counts = {
|
||||||
favourites: result.favourites,
|
favourites: result.favourites,
|
||||||
individual: result.types[AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_INDIVIDUAL],
|
individual: result.types[AddonMessagesMessageConversationType.INDIVIDUAL],
|
||||||
group: result.types[AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_GROUP],
|
group: result.types[AddonMessagesMessageConversationType.GROUP],
|
||||||
self: result.types[AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_SELF] || 0,
|
self: result.types[AddonMessagesMessageConversationType.SELF] || 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
return counts;
|
return counts;
|
||||||
|
@ -1190,7 +1260,7 @@ export class AddonMessagesProvider {
|
||||||
const params: AddonMessagesGetMessagesWSParams = {
|
const params: AddonMessagesGetMessagesWSParams = {
|
||||||
useridto: site.getUserId(),
|
useridto: site.getUserId(),
|
||||||
useridfrom: userId,
|
useridfrom: userId,
|
||||||
limitnum: AddonMessagesProvider.LIMIT_MESSAGES,
|
limitnum: ADDON_MESSAGES_LIMIT_MESSAGES,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (lfReceivedUnread > 0 || lfReceivedRead > 0 || lfSentUnread > 0 || lfSentRead > 0) {
|
if (lfReceivedUnread > 0 || lfReceivedRead > 0 || lfSentUnread > 0 || lfSentRead > 0) {
|
||||||
|
@ -1213,13 +1283,13 @@ export class AddonMessagesProvider {
|
||||||
result.messages = result.messages.concat(sent);
|
result.messages = result.messages.concat(sent);
|
||||||
const hasSent = sent.length > 0;
|
const hasSent = sent.length > 0;
|
||||||
|
|
||||||
if (result.messages.length > AddonMessagesProvider.LIMIT_MESSAGES) {
|
if (result.messages.length > ADDON_MESSAGES_LIMIT_MESSAGES) {
|
||||||
// Sort messages and get the more recent ones.
|
// Sort messages and get the more recent ones.
|
||||||
result.canLoadMore = true;
|
result.canLoadMore = true;
|
||||||
result.messages = this.sortMessages(result['messages']);
|
result.messages = this.sortMessages(result['messages']);
|
||||||
result.messages = result.messages.slice(-AddonMessagesProvider.LIMIT_MESSAGES);
|
result.messages = result.messages.slice(-ADDON_MESSAGES_LIMIT_MESSAGES);
|
||||||
} else {
|
} else {
|
||||||
result.canLoadMore = result.messages.length == AddonMessagesProvider.LIMIT_MESSAGES && (!hasReceived || !hasSent);
|
result.canLoadMore = result.messages.length == ADDON_MESSAGES_LIMIT_MESSAGES && (!hasReceived || !hasSent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (excludePending) {
|
if (excludePending) {
|
||||||
|
@ -1290,7 +1360,7 @@ export class AddonMessagesProvider {
|
||||||
const params: AddonMessagesGetMessagesWSParams = {
|
const params: AddonMessagesGetMessagesWSParams = {
|
||||||
useridto: currentUserId,
|
useridto: currentUserId,
|
||||||
useridfrom: 0,
|
useridfrom: 0,
|
||||||
limitnum: AddonMessagesProvider.LIMIT_MESSAGES,
|
limitnum: ADDON_MESSAGES_LIMIT_MESSAGES,
|
||||||
};
|
};
|
||||||
|
|
||||||
const preSets: CoreSiteWSPreSets = {
|
const preSets: CoreSiteWSPreSets = {
|
||||||
|
@ -1573,9 +1643,9 @@ export class AddonMessagesProvider {
|
||||||
|
|
||||||
counts = {
|
counts = {
|
||||||
favourites: result.favourites,
|
favourites: result.favourites,
|
||||||
individual: result.types[AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_INDIVIDUAL],
|
individual: result.types[AddonMessagesMessageConversationType.INDIVIDUAL],
|
||||||
group: result.types[AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_GROUP],
|
group: result.types[AddonMessagesMessageConversationType.GROUP],
|
||||||
self: result.types[AddonMessagesProvider.MESSAGE_CONVERSATION_TYPE_SELF] || 0,
|
self: result.types[AddonMessagesMessageConversationType.SELF] || 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -1593,7 +1663,7 @@ export class AddonMessagesProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the new counts so all views are updated.
|
// Notify the new counts so all views are updated.
|
||||||
CoreEvents.trigger(AddonMessagesProvider.UNREAD_CONVERSATION_COUNTS_EVENT, counts, site.id);
|
CoreEvents.trigger(ADDON_MESSAGES_UNREAD_CONVERSATION_COUNTS_EVENT, counts, site.id);
|
||||||
|
|
||||||
return counts;
|
return counts;
|
||||||
}
|
}
|
||||||
|
@ -1618,7 +1688,7 @@ export class AddonMessagesProvider {
|
||||||
const params: AddonMessagesGetMessagesWSParams = {
|
const params: AddonMessagesGetMessagesWSParams = {
|
||||||
read: false,
|
read: false,
|
||||||
limitfrom: 0,
|
limitfrom: 0,
|
||||||
limitnum: AddonMessagesProvider.LIMIT_MESSAGES,
|
limitnum: ADDON_MESSAGES_LIMIT_MESSAGES,
|
||||||
useridto: site.getUserId(),
|
useridto: site.getUserId(),
|
||||||
useridfrom: 0,
|
useridfrom: 0,
|
||||||
};
|
};
|
||||||
|
@ -2250,7 +2320,7 @@ export class AddonMessagesProvider {
|
||||||
this.invalidateContactsCache(site.id),
|
this.invalidateContactsCache(site.id),
|
||||||
]).then(() => {
|
]).then(() => {
|
||||||
const data: AddonMessagesMemberInfoChangedEventData = { userId, contactRemoved: true };
|
const data: AddonMessagesMemberInfoChangedEventData = { userId, contactRemoved: true };
|
||||||
CoreEvents.trigger(AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT, data, site.id);
|
CoreEvents.trigger(ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT, data, site.id);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
@ -2297,7 +2367,7 @@ export class AddonMessagesProvider {
|
||||||
* @param query The query string.
|
* @param query The query string.
|
||||||
* @param userId The user ID. If not defined, current user.
|
* @param userId The user ID. If not defined, current user.
|
||||||
* @param limitFrom Position of the first result to get. Defaults to 0.
|
* @param limitFrom Position of the first result to get. Defaults to 0.
|
||||||
* @param limitNum Number of results to get. Defaults to AddonMessagesProvider.LIMIT_SEARCH.
|
* @param limitNum Number of results to get. Defaults to ADDON_MESSAGES_LIMIT_SEARCH.
|
||||||
* @param siteId Site ID. If not defined, current site.
|
* @param siteId Site ID. If not defined, current site.
|
||||||
* @returns Promise resolved with the results.
|
* @returns Promise resolved with the results.
|
||||||
*/
|
*/
|
||||||
|
@ -2305,7 +2375,7 @@ export class AddonMessagesProvider {
|
||||||
query: string,
|
query: string,
|
||||||
userId?: number,
|
userId?: number,
|
||||||
limitFrom: number = 0,
|
limitFrom: number = 0,
|
||||||
limitNum: number = AddonMessagesProvider.LIMIT_SEARCH,
|
limitNum: number = ADDON_MESSAGES_LIMIT_SEARCH,
|
||||||
siteId?: string,
|
siteId?: string,
|
||||||
): Promise<{messages: AddonMessagesMessageAreaContact[]; canLoadMore: boolean}> {
|
): Promise<{messages: AddonMessagesMessageAreaContact[]; canLoadMore: boolean}> {
|
||||||
const site = await CoreSites.getSite(siteId);
|
const site = await CoreSites.getSite(siteId);
|
||||||
|
@ -2350,7 +2420,7 @@ export class AddonMessagesProvider {
|
||||||
*
|
*
|
||||||
* @param query Text to search for.
|
* @param query Text to search for.
|
||||||
* @param limitFrom Position of the first found user to fetch.
|
* @param limitFrom Position of the first found user to fetch.
|
||||||
* @param limitNum Number of found users to fetch. Defaults to AddonMessagesProvider.LIMIT_SEARCH.
|
* @param limitNum Number of found users to fetch. Defaults to ADDON_MESSAGES_LIMIT_SEARCH.
|
||||||
* @param siteId Site ID. If not defined, use current site.
|
* @param siteId Site ID. If not defined, use current site.
|
||||||
* @returns Resolved with two lists of found users: contacts and non-contacts.
|
* @returns Resolved with two lists of found users: contacts and non-contacts.
|
||||||
* @since 3.6
|
* @since 3.6
|
||||||
|
@ -2358,7 +2428,7 @@ export class AddonMessagesProvider {
|
||||||
async searchUsers(
|
async searchUsers(
|
||||||
query: string,
|
query: string,
|
||||||
limitFrom: number = 0,
|
limitFrom: number = 0,
|
||||||
limitNum: number = AddonMessagesProvider.LIMIT_SEARCH,
|
limitNum: number = ADDON_MESSAGES_LIMIT_SEARCH,
|
||||||
siteId?: string,
|
siteId?: string,
|
||||||
): Promise<{
|
): Promise<{
|
||||||
contacts: AddonMessagesConversationMember[];
|
contacts: AddonMessagesConversationMember[];
|
||||||
|
@ -2828,7 +2898,7 @@ export class AddonMessagesProvider {
|
||||||
} finally {
|
} finally {
|
||||||
const data: AddonMessagesMemberInfoChangedEventData = { userId, userUnblocked: true };
|
const data: AddonMessagesMemberInfoChangedEventData = { userId, userUnblocked: true };
|
||||||
|
|
||||||
CoreEvents.trigger(AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT, data, site.id);
|
CoreEvents.trigger(ADDON_MESSAGES_MEMBER_INFO_CHANGED_EVENT, data, site.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue