MOBILE-3631 messages: Small fixes found during Peer review

main
Pau Ferrer Ocaña 2021-02-04 10:55:07 +01:00
parent 344eedfde5
commit a03e29eba3
10 changed files with 100 additions and 118 deletions

View File

@ -17,7 +17,7 @@ import { IonRefresher } from '@ionic/angular';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { import {
AddonMessagesProvider, AddonMessagesProvider,
AddonMessagesGetContactsResult, AddonMessagesGetContactsWSResponse,
AddonMessagesSearchContactsContact, AddonMessagesSearchContactsContact,
AddonMessagesGetContactsContact, AddonMessagesGetContactsContact,
AddonMessages, AddonMessages,
@ -268,6 +268,6 @@ export class AddonMessagesContacts35Page implements OnInit, OnDestroy {
/** /**
* Contacts with some calculated data. * Contacts with some calculated data.
*/ */
export type AddonMessagesGetContactsFormatted = AddonMessagesGetContactsResult & { export type AddonMessagesGetContactsFormatted = AddonMessagesGetContactsWSResponse & {
search?: AddonMessagesSearchContactsContact[]; // Calculated in the app. Result of searching users. search?: AddonMessagesSearchContactsContact[]; // Calculated in the app. Result of searching users.
}; };

View File

@ -24,15 +24,14 @@ import {
AddonMessagesGetMessagesMessage, AddonMessagesGetMessagesMessage,
AddonMessages, AddonMessages,
AddonMessagesMemberInfoChangedEventData, AddonMessagesMemberInfoChangedEventData,
AddonMessagesSendInstantMessagesMessage,
AddonMessagesSendMessagesToConversationMessage,
AddonMessagesReadChangedEventData, AddonMessagesReadChangedEventData,
AddonMessagesNewMessagedEventData, AddonMessagesNewMessagedEventData,
AddonMessagesUpdateConversationListEventData, AddonMessagesUpdateConversationListEventData,
AddonMessagesConversationMessageFormatted, AddonMessagesConversationMessageFormatted,
AddonMessagesOpenConversationEventData, AddonMessagesOpenConversationEventData,
AddonMessagesSendMessageResults,
} from '../../services/messages'; } from '../../services/messages';
import { AddonMessagesOffline } from '../../services/messages-offline'; import { AddonMessagesOffline, AddonMessagesOfflineMessagesDBRecordFormatted } from '../../services/messages-offline';
import { AddonMessagesSync, AddonMessagesSyncEvents, AddonMessagesSyncProvider } from '../../services/messages-sync'; import { AddonMessagesSync, AddonMessagesSyncEvents, AddonMessagesSyncProvider } 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';
@ -49,9 +48,6 @@ import { ModalController, Translate } from '@singletons';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreIonLoadingElement } from '@classes/ion-loading'; import { CoreIonLoadingElement } from '@classes/ion-loading';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import {
AddonMessagesOfflineMessagesDBRecordFormatted,
} from '@addons/messages/services/database/messages';
import { AddonMessagesConversationInfoComponent } from '../../components/conversation-info/conversation-info'; import { AddonMessagesConversationInfoComponent } from '../../components/conversation-info/conversation-info';
/** /**
@ -1187,10 +1183,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView
} finally { } finally {
try { try {
let data: { let data: AddonMessagesSendMessageResults;
sent: boolean;
message: AddonMessagesSendMessagesToConversationMessage | AddonMessagesSendInstantMessagesMessage;
};
if (this.conversationId) { if (this.conversationId) {
data = await AddonMessages.instance.sendMessageToConversation(this.conversation!, text); data = await AddonMessages.instance.sendMessageToConversation(this.conversation!, text);
} else { } else {

View File

@ -57,16 +57,10 @@ export class AddonMessagesDiscussions35Page implements OnInit, OnDestroy {
discussions: AddonMessagesDiscussion[] = []; discussions: AddonMessagesDiscussion[] = [];
discussionUserId?: number; discussionUserId?: number;
search: { search = {
enabled: boolean;
showResults: boolean;
results: AddonMessagesMessageAreaContact[];
loading: string;
text: string;
} = {
enabled: false, enabled: false,
showResults: false, showResults: false,
results: [], results: <AddonMessagesMessageAreaContact[]> [],
loading: '', loading: '',
text: '', text: '',
}; };

View File

@ -28,7 +28,10 @@ import {
AddonMessagesNewMessagedEventData, AddonMessagesNewMessagedEventData,
AddonMessagesOpenConversationEventData, AddonMessagesOpenConversationEventData,
} from '../../services/messages'; } from '../../services/messages';
import { AddonMessagesOffline } from '../../services/messages-offline'; import {
AddonMessagesOffline,
AddonMessagesOfflineAnyMessagesFormatted,
} from '../../services/messages-offline';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate'; import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate';
@ -38,10 +41,6 @@ import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifi
import { ActivatedRoute, Params } from '@angular/router'; import { ActivatedRoute, Params } from '@angular/router';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import {
AddonMessagesOfflineConversationMessagesDBRecordFormatted,
AddonMessagesOfflineMessagesDBRecordFormatted,
} from '@addons/messages/services/database/messages';
import { AddonMessagesSettingsHandlerService } from '@addons/messages/services/handlers/settings'; import { AddonMessagesSettingsHandlerService } from '@addons/messages/services/handlers/settings';
import { CoreScreen } from '@services/screen'; import { CoreScreen } from '@services/screen';
@ -402,12 +401,12 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
const limitFrom = loadingMore ? option.conversations.length : 0; const limitFrom = loadingMore ? option.conversations.length : 0;
const promises: Promise<unknown>[] = []; const promises: Promise<unknown>[] = [];
let data: { conversations: AddonMessagesConversationForList[]; canLoadMore: boolean } = { let data = {
conversations: [], conversations: <AddonMessagesConversationForList[]> [],
canLoadMore: false, canLoadMore: false,
}; };
let offlineMessages: let offlineMessages:
(AddonMessagesOfflineConversationMessagesDBRecordFormatted | AddonMessagesOfflineMessagesDBRecordFormatted)[] = []; AddonMessagesOfflineAnyMessagesFormatted[] = [];
// Get the conversations and, if needed, the offline messages. Always try to get the latest data. // Get the conversations and, if needed, the offline messages. Always try to get the latest data.
promises.push(AddonMessages.instance.invalidateConversations(this.siteId).then(async () => { promises.push(AddonMessages.instance.invalidateConversations(this.siteId).then(async () => {
@ -574,7 +573,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
*/ */
protected async loadOfflineMessages( protected async loadOfflineMessages(
option: AddonMessagesGroupConversationOption, option: AddonMessagesGroupConversationOption,
messages: (AddonMessagesOfflineConversationMessagesDBRecordFormatted | AddonMessagesOfflineMessagesDBRecordFormatted)[], messages: AddonMessagesOfflineAnyMessagesFormatted[],
): Promise<void> { ): Promise<void> {
const promises: Promise<void>[] = []; const promises: Promise<void>[] = [];
@ -605,7 +604,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
userid: 0, // Faked data. userid: 0, // Faked data.
name: message.conversation?.name, name: message.conversation?.name,
imageurl: message.conversation?.imageurl || '', imageurl: message.conversation?.imageurl || '',
}; message.conversation || {}; };
if (this.getConversationOption(conversation) == option) { if (this.getConversationOption(conversation) == option) {
// Message belongs to current option, add the conversation. // Message belongs to current option, add the conversation.
@ -674,7 +673,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
*/ */
protected addLastOfflineMessage( protected addLastOfflineMessage(
conversation: AddonMessagesConversationForList, conversation: AddonMessagesConversationForList,
message: AddonMessagesOfflineConversationMessagesDBRecordFormatted | AddonMessagesOfflineMessagesDBRecordFormatted, message: AddonMessagesOfflineAnyMessagesFormatted,
): void { ): void {
conversation.lastmessage = message.text; conversation.lastmessage = message.text;
conversation.lastmessagedate = message.timecreated / 1000; conversation.lastmessagedate = message.timecreated / 1000;

View File

@ -1,4 +1,4 @@
ion-app.app-root page-addon-messages-settings { :host {
.list-header { .list-header {
margin-bottom: 0; margin-bottom: 0;
border-top: 0; border-top: 0;

View File

@ -13,7 +13,6 @@
// limitations under the License. // limitations under the License.
import { CoreSiteSchema } from '@services/sites'; import { CoreSiteSchema } from '@services/sites';
import { AddonMessagesConversation } from '../messages';
/** /**
* Database variables for AddonMessagesOffline service. * Database variables for AddonMessagesOffline service.
@ -87,11 +86,6 @@ export type AddonMessagesOfflineMessagesDBRecord = {
deviceoffline: number; // If message was stored because device was offline. deviceoffline: number; // If message was stored because device was offline.
}; };
export type AddonMessagesOfflineMessagesDBRecordFormatted = AddonMessagesOfflineMessagesDBRecord & {
pending?: boolean; // Will be likely true.
text?: string; // Copy of smallmessage.
};
export type AddonMessagesOfflineConversationMessagesDBRecord = { export type AddonMessagesOfflineConversationMessagesDBRecord = {
conversationid: number; conversationid: number;
text: string; text: string;
@ -99,13 +93,3 @@ export type AddonMessagesOfflineConversationMessagesDBRecord = {
deviceoffline: number; // If message was stored because device was offline. deviceoffline: number; // If message was stored because device was offline.
conversation: string; // Data about the conversation. conversation: string; // Data about the conversation.
}; };
export type AddonMessagesOfflineConversationMessagesDBRecordFormatted =
Omit<AddonMessagesOfflineConversationMessagesDBRecord, 'conversation'> &
{
conversation?: AddonMessagesConversation; // Data about the conversation.
pending: boolean; // Will be always true.
useridfrom?: number; // User Id who send the message, will be likely us.
};

View File

@ -18,9 +18,7 @@ import { CoreApp } from '@services/app';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { import {
AddonMessagesOfflineConversationMessagesDBRecord, AddonMessagesOfflineConversationMessagesDBRecord,
AddonMessagesOfflineConversationMessagesDBRecordFormatted,
AddonMessagesOfflineMessagesDBRecord, AddonMessagesOfflineMessagesDBRecord,
AddonMessagesOfflineMessagesDBRecordFormatted,
CONVERSATION_MESSAGES_TABLE, CONVERSATION_MESSAGES_TABLE,
MESSAGES_TABLE, MESSAGES_TABLE,
} from './database/messages'; } from './database/messages';
@ -94,28 +92,23 @@ export class AddonMessagesOfflineProvider {
*/ */
async getAllDeviceOfflineMessages( async getAllDeviceOfflineMessages(
siteId?: string, siteId?: string,
): Promise<(AddonMessagesOfflineConversationMessagesDBRecordFormatted | AddonMessagesOfflineMessagesDBRecordFormatted)[]> { ): Promise<AddonMessagesOfflineAnyMessagesFormatted[]> {
const site = await CoreSites.instance.getSite(siteId); const site = await CoreSites.instance.getSite(siteId);
const promises: [
Promise<AddonMessagesOfflineMessagesDBRecord[]>,
Promise<AddonMessagesOfflineConversationMessagesDBRecord[]>,
] = [
site.getDb().getRecords(MESSAGES_TABLE, { deviceoffline: 1 }),
site.getDb().getRecords(CONVERSATION_MESSAGES_TABLE, { deviceoffline: 1 }),
];
const [ const [
messages, messages,
conversations, conversations,
]: [ ] = await Promise.all([
AddonMessagesOfflineMessagesDBRecord[], site.getDb().getRecords<AddonMessagesOfflineMessagesDBRecord>(MESSAGES_TABLE, { deviceoffline: 1 }),
AddonMessagesOfflineConversationMessagesDBRecord[], site.getDb().getRecords<AddonMessagesOfflineConversationMessagesDBRecord>(
] = await Promise.all(promises); CONVERSATION_MESSAGES_TABLE,
{ deviceoffline: 1 },
),
]);
const messageResult: const messageResult:
(AddonMessagesOfflineConversationMessagesDBRecordFormatted | AddonMessagesOfflineMessagesDBRecordFormatted)[] = AddonMessagesOfflineAnyMessagesFormatted[] =
this.parseMessages(messages); this.parseMessages(messages);
const formattedConv = this.parseConversationMessages(conversations); const formattedConv = this.parseConversationMessages(conversations);
@ -130,28 +123,19 @@ export class AddonMessagesOfflineProvider {
*/ */
async getAllMessages( async getAllMessages(
siteId?: string, siteId?: string,
): Promise<(AddonMessagesOfflineConversationMessagesDBRecordFormatted | AddonMessagesOfflineMessagesDBRecordFormatted)[]> { ): Promise<AddonMessagesOfflineAnyMessagesFormatted[]> {
const site = await CoreSites.instance.getSite(siteId); const site = await CoreSites.instance.getSite(siteId);
const promises: [
Promise<AddonMessagesOfflineMessagesDBRecord[]>,
Promise<AddonMessagesOfflineConversationMessagesDBRecord[]>,
] = [
site.getDb().getAllRecords(MESSAGES_TABLE),
site.getDb().getAllRecords(CONVERSATION_MESSAGES_TABLE),
];
const [ const [
messages, messages,
conversations, conversations,
]: [ ] = await Promise.all([
AddonMessagesOfflineMessagesDBRecord[], site.getDb().getAllRecords<AddonMessagesOfflineMessagesDBRecord>(MESSAGES_TABLE),
AddonMessagesOfflineConversationMessagesDBRecord[], site.getDb().getAllRecords<AddonMessagesOfflineConversationMessagesDBRecord>(CONVERSATION_MESSAGES_TABLE),
] = await Promise.all(promises); ]);
const messageResult: const messageResult:
(AddonMessagesOfflineConversationMessagesDBRecordFormatted | AddonMessagesOfflineMessagesDBRecordFormatted)[] = AddonMessagesOfflineAnyMessagesFormatted[] =
this.parseMessages(messages); this.parseMessages(messages);
const formattedConv = this.parseConversationMessages(conversations); const formattedConv = this.parseConversationMessages(conversations);
@ -348,7 +332,7 @@ export class AddonMessagesOfflineProvider {
* @return Promise resolved if stored, rejected if failure. * @return Promise resolved if stored, rejected if failure.
*/ */
async setMessagesDeviceOffline( async setMessagesDeviceOffline(
messages: (AddonMessagesOfflineMessagesDBRecordFormatted | AddonMessagesOfflineConversationMessagesDBRecordFormatted)[], messages: AddonMessagesOfflineAnyMessagesFormatted[],
value: boolean, value: boolean,
siteId?: string, siteId?: string,
): Promise<void> { ): Promise<void> {
@ -381,3 +365,20 @@ export class AddonMessagesOfflineProvider {
} }
export class AddonMessagesOffline extends makeSingleton(AddonMessagesOfflineProvider) {} export class AddonMessagesOffline extends makeSingleton(AddonMessagesOfflineProvider) {}
export type AddonMessagesOfflineMessagesDBRecordFormatted = AddonMessagesOfflineMessagesDBRecord & {
pending?: boolean; // Will be likely true.
text?: string; // Copy of smallmessage.
};
export type AddonMessagesOfflineConversationMessagesDBRecordFormatted =
Omit<AddonMessagesOfflineConversationMessagesDBRecord, 'conversation'> &
{
conversation?: AddonMessagesConversation; // Data about the conversation.
pending: boolean; // Will be always true.
useridfrom?: number; // User Id who send the message, will be likely us.
};
export type AddonMessagesOfflineAnyMessagesFormatted =
AddonMessagesOfflineConversationMessagesDBRecordFormatted | AddonMessagesOfflineMessagesDBRecordFormatted;

View File

@ -14,7 +14,9 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreSyncBaseProvider } from '@classes/base-sync'; import { CoreSyncBaseProvider } from '@classes/base-sync';
import { AddonMessagesOffline } from './messages-offline'; import {
AddonMessagesOffline, AddonMessagesOfflineAnyMessagesFormatted,
} from './messages-offline';
import { import {
AddonMessagesProvider, AddonMessagesProvider,
AddonMessages, AddonMessages,
@ -28,10 +30,6 @@ import { CoreApp } from '@services/app';
import { CoreConstants } from '@/core/constants'; import { CoreConstants } from '@/core/constants';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import {
AddonMessagesOfflineConversationMessagesDBRecordFormatted,
AddonMessagesOfflineMessagesDBRecordFormatted,
} from './database/messages';
import { CoreTextErrorObject, CoreTextUtils } from '@services/utils/text'; import { CoreTextErrorObject, CoreTextUtils } from '@services/utils/text';
import { CoreSiteWSPreSets } from '@classes/site'; import { CoreSiteWSPreSets } from '@classes/site';
@ -177,7 +175,7 @@ export class AddonMessagesSyncProvider extends CoreSyncBaseProvider<AddonMessage
}; };
const groupMessagingEnabled = AddonMessages.instance.isGroupMessagingEnabled(); const groupMessagingEnabled = AddonMessages.instance.isGroupMessagingEnabled();
let messages: (AddonMessagesOfflineMessagesDBRecordFormatted | AddonMessagesOfflineConversationMessagesDBRecordFormatted)[]; let messages: AddonMessagesOfflineAnyMessagesFormatted[];
const errors: (string | CoreError | CoreTextErrorObject)[] = []; const errors: (string | CoreError | CoreTextErrorObject)[] = [];
if (conversationId) { if (conversationId) {

View File

@ -17,7 +17,12 @@ import { CoreLogger } from '@singletons/logger';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreUser, CoreUserBasicData } from '@features/user/services/user'; import { CoreUser, CoreUserBasicData } from '@features/user/services/user';
import { AddonMessagesOffline } from './messages-offline'; import {
AddonMessagesOffline,
AddonMessagesOfflineAnyMessagesFormatted,
AddonMessagesOfflineConversationMessagesDBRecordFormatted,
AddonMessagesOfflineMessagesDBRecordFormatted,
} from './messages-offline';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
@ -25,10 +30,6 @@ import { CoreSite, CoreSiteWSPreSets } from '@classes/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 {
AddonMessagesOfflineConversationMessagesDBRecordFormatted,
AddonMessagesOfflineMessagesDBRecordFormatted,
} from './database/messages';
import { AddonMessagesMainMenuHandlerService } from './handlers/mainmenu'; import { AddonMessagesMainMenuHandlerService } from './handlers/mainmenu';
const ROOT_CACHE_KEY = 'mmaMessages:'; const ROOT_CACHE_KEY = 'mmaMessages:';
@ -554,7 +555,7 @@ export class AddonMessagesProvider {
* @return Promise resolved with the WS data. * @return Promise resolved with the WS data.
* @deprecatedonmoodle since Moodle 3.6 * @deprecatedonmoodle since Moodle 3.6
*/ */
async getAllContacts(siteId?: string): Promise<AddonMessagesGetContactsResult> { async getAllContacts(siteId?: string): Promise<AddonMessagesGetContactsWSResponse> {
siteId = siteId || CoreSites.instance.getCurrentSiteId(); siteId = siteId || CoreSites.instance.getCurrentSiteId();
const contacts = await this.getContacts(siteId); const contacts = await this.getContacts(siteId);
@ -580,7 +581,7 @@ export class AddonMessagesProvider {
* @param siteId Site ID. If not defined, use current site. * @param siteId Site ID. If not defined, use current site.
* @return Promise resolved with the WS data. * @return Promise resolved with the WS data.
*/ */
async getBlockedContacts(siteId?: string): Promise<AddonMessagesGetBlockedUsersResult> { async getBlockedContacts(siteId?: string): Promise<AddonMessagesGetBlockedUsersWSResponse> {
const site = await CoreSites.instance.getSite(siteId); const site = await CoreSites.instance.getSite(siteId);
const userId = site.getUserId(); const userId = site.getUserId();
@ -606,7 +607,7 @@ export class AddonMessagesProvider {
* @return Promise resolved with the WS data. * @return Promise resolved with the WS data.
* @deprecatedonmoodle since Moodle 3.6 * @deprecatedonmoodle since Moodle 3.6
*/ */
async getContacts(siteId?: string): Promise<AddonMessagesGetContactsResult> { async getContacts(siteId?: string): Promise<AddonMessagesGetContactsWSResponse> {
const site = await CoreSites.instance.getSite(siteId); const site = await CoreSites.instance.getSite(siteId);
const preSets: CoreSiteWSPreSets = { const preSets: CoreSiteWSPreSets = {
@ -614,10 +615,10 @@ export class AddonMessagesProvider {
updateFrequency: CoreSite.FREQUENCY_OFTEN, updateFrequency: CoreSite.FREQUENCY_OFTEN,
}; };
const contacts = await site.read<AddonMessagesGetContactsResult>('core_message_get_contacts', undefined, preSets); const contacts = await site.read<AddonMessagesGetContactsWSResponse>('core_message_get_contacts', undefined, preSets);
// Filter contacts with negative ID, they are notifications. // Filter contacts with negative ID, they are notifications.
const validContacts: AddonMessagesGetContactsResult = { const validContacts: AddonMessagesGetContactsWSResponse = {
online: [], online: [],
offline: [], offline: [],
strangers: [], strangers: [],
@ -809,7 +810,11 @@ export class AddonMessagesProvider {
newestmessagesfirst: newestFirst, newestmessagesfirst: newestFirst,
}; };
const conversation = await site.read<AddonMessagesConversationFormatted>('core_message_get_conversation', params, preSets); const conversation = await site.read<AddonMessagesGetConversationWSResponse>(
'core_message_get_conversation',
params,
preSets,
);
return this.formatConversation(conversation, userId); return this.formatConversation(conversation, userId);
} }
@ -2467,10 +2472,10 @@ export class AddonMessagesProvider {
toUserId: number, toUserId: number,
message: string, message: string,
siteId?: string, siteId?: string,
): Promise<{ sent: boolean; message: AddonMessagesSendInstantMessagesMessage }> { ): Promise<AddonMessagesSendMessageResults> {
// Convenience function to store a message to be synchronized later. // Convenience function to store a message to be synchronized later.
const storeOffline = async (): Promise<{ sent: boolean; message: AddonMessagesSendInstantMessagesMessage }> => { const storeOffline = async (): Promise<AddonMessagesSendMessageResults> => {
const entry = await AddonMessagesOffline.instance.saveMessage(toUserId, message, siteId); const entry = await AddonMessagesOffline.instance.saveMessage(toUserId, message, siteId);
return { return {
@ -2599,13 +2604,13 @@ export class AddonMessagesProvider {
conversation: AddonMessagesConversation, conversation: AddonMessagesConversation,
message: string, message: string,
siteId?: string, siteId?: string,
): Promise<{ sent: boolean; message: AddonMessagesSendMessagesToConversationMessage }> { ): Promise<AddonMessagesSendMessageResults> {
const site = await CoreSites.instance.getSite(siteId); const site = await CoreSites.instance.getSite(siteId);
siteId = site.getId(); siteId = site.getId();
// Convenience function to store a message to be synchronized later. // Convenience function to store a message to be synchronized later.
const storeOffline = async(): Promise<{ sent: boolean; message: AddonMessagesSendMessagesToConversationMessage }> => { const storeOffline = async(): Promise<AddonMessagesSendMessageResults> => {
const entry = await AddonMessagesOffline.instance.saveConversationMessage(conversation, message, siteId); const entry = await AddonMessagesOffline.instance.saveConversationMessage(conversation, message, siteId);
return { return {
@ -2789,21 +2794,17 @@ export class AddonMessagesProvider {
* @param messages Array of messages containing the key 'timecreated'. * @param messages Array of messages containing the key 'timecreated'.
* @return Messages sorted with most recent last. * @return Messages sorted with most recent last.
*/ */
sortMessages( sortMessages(messages: AddonMessagesConversationMessageFormatted[]): AddonMessagesConversationMessageFormatted[];
messages: AddonMessagesConversationMessageFormatted[],
): AddonMessagesConversationMessageFormatted[];
sortMessages( sortMessages(
messages: (AddonMessagesGetMessagesMessage | AddonMessagesOfflineMessagesDBRecordFormatted)[], messages: (AddonMessagesGetMessagesMessage | AddonMessagesOfflineMessagesDBRecordFormatted)[],
): (AddonMessagesGetMessagesMessage | AddonMessagesOfflineMessagesDBRecordFormatted)[]; ): (AddonMessagesGetMessagesMessage | AddonMessagesOfflineMessagesDBRecordFormatted)[];
sortMessages( sortMessages(messages: AddonMessagesOfflineAnyMessagesFormatted[]): AddonMessagesOfflineAnyMessagesFormatted[];
messages: (AddonMessagesOfflineMessagesDBRecordFormatted | AddonMessagesOfflineConversationMessagesDBRecordFormatted)[],
): (AddonMessagesOfflineMessagesDBRecordFormatted | AddonMessagesOfflineConversationMessagesDBRecordFormatted)[];
sortMessages( sortMessages(
messages: (AddonMessagesGetMessagesMessage | AddonMessagesOfflineMessagesDBRecordFormatted)[] | messages: (AddonMessagesGetMessagesMessage | AddonMessagesOfflineMessagesDBRecordFormatted)[] |
(AddonMessagesOfflineMessagesDBRecordFormatted | AddonMessagesOfflineConversationMessagesDBRecordFormatted)[] | AddonMessagesOfflineAnyMessagesFormatted[] |
AddonMessagesConversationMessageFormatted[], AddonMessagesConversationMessageFormatted[],
): (AddonMessagesGetMessagesMessage | AddonMessagesOfflineMessagesDBRecordFormatted)[] | ): (AddonMessagesGetMessagesMessage | AddonMessagesOfflineMessagesDBRecordFormatted)[] |
(AddonMessagesOfflineMessagesDBRecordFormatted | AddonMessagesOfflineConversationMessagesDBRecordFormatted)[] | AddonMessagesOfflineAnyMessagesFormatted[] |
AddonMessagesConversationMessageFormatted[] { AddonMessagesConversationMessageFormatted[] {
return messages.sort((a, b) => { return messages.sort((a, b) => {
// Pending messages last. // Pending messages last.
@ -2831,7 +2832,7 @@ export class AddonMessagesProvider {
* *
* @param contactTypes List of contacts grouped in types. * @param contactTypes List of contacts grouped in types.
*/ */
protected storeUsersFromAllContacts(contactTypes: AddonMessagesGetContactsResult): void { protected storeUsersFromAllContacts(contactTypes: AddonMessagesGetContactsWSResponse): void {
for (const x in contactTypes) { for (const x in contactTypes) {
CoreUser.instance.storeUsers(contactTypes[x]); CoreUser.instance.storeUsers(contactTypes[x]);
} }
@ -2945,6 +2946,11 @@ type AddonMessagesGetConversationWSParams = {
newestmessagesfirst?: boolean; // Order messages by newest first. newestmessagesfirst?: boolean; // Order messages by newest first.
}; };
/**
* Data returned by core_message_get_conversation WS.
*/
type AddonMessagesGetConversationWSResponse = AddonMessagesConversation;
/** /**
* Params of core_message_get_self_conversation WS. * Params of core_message_get_self_conversation WS.
*/ */
@ -2955,7 +2961,6 @@ type AddonMessagesGetSelfConversationWSParams = {
newestmessagesfirst?: boolean; // Order messages by newest first. newestmessagesfirst?: boolean; // Order messages by newest first.
}; };
/** /**
* Conversation with some calculated data. * Conversation with some calculated data.
*/ */
@ -3172,7 +3177,7 @@ type AddonMessagesGetBlockedUsersWSParams = {
/** /**
* Result of WS core_message_get_blocked_users. * Result of WS core_message_get_blocked_users.
*/ */
export type AddonMessagesGetBlockedUsersResult = { export type AddonMessagesGetBlockedUsersWSResponse = {
users: AddonMessagesBlockedUser[]; // List of blocked users. users: AddonMessagesBlockedUser[]; // List of blocked users.
warnings?: CoreWSExternalWarning[]; warnings?: CoreWSExternalWarning[];
}; };
@ -3189,7 +3194,7 @@ export type AddonMessagesBlockedUser = {
/** /**
* Result of WS core_message_get_contacts. * Result of WS core_message_get_contacts.
*/ */
export type AddonMessagesGetContactsResult = { export type AddonMessagesGetContactsWSResponse = {
online: AddonMessagesGetContactsContact[]; // List of online contacts. online: AddonMessagesGetContactsContact[]; // List of online contacts.
offline: AddonMessagesGetContactsContact[]; // List of offline contacts. offline: AddonMessagesGetContactsContact[]; // List of offline contacts.
strangers: AddonMessagesGetContactsContact[]; // List of users that are not in the user's contact list but have sent a message. strangers: AddonMessagesGetContactsContact[]; // List of users that are not in the user's contact list but have sent a message.
@ -3416,6 +3421,14 @@ export type AddonMessagesSendMessagesToConversationMessage = {
timecreated: number; // The timecreated timestamp for the message. timecreated: number; // The timecreated timestamp for the message.
}; };
/**
* Result for Send Messages functions trying online or storing in offline.
*/
export type AddonMessagesSendMessageResults = {
sent: boolean;
message: AddonMessagesSendMessagesToConversationMessage | AddonMessagesSendInstantMessagesMessage;
};
/** /**
* Calculated data for core_message_get_contacts. * Calculated data for core_message_get_contacts.
*/ */