MOBILE-3321 user: Decouple event constants
parent
73ee4df1ec
commit
2dbb620994
|
@ -17,7 +17,7 @@ import { Component, Input, OnInit, OnChanges, OnDestroy, SimpleChange } from '@a
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import { CoreUserProvider, CoreUserBasicData } from '@features/user/services/user';
|
import { USER_PROFILE_PICTURE_UPDATED, CoreUserBasicData } from '@features/user/services/user';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreNetwork } from '@services/network';
|
import { CoreNetwork } from '@services/network';
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ export class CoreUserAvatarComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
this.currentUserId = CoreSites.getCurrentSiteUserId();
|
this.currentUserId = CoreSites.getCurrentSiteUserId();
|
||||||
|
|
||||||
this.pictureObserver = CoreEvents.on(
|
this.pictureObserver = CoreEvents.on(
|
||||||
CoreUserProvider.PROFILE_PICTURE_UPDATED,
|
USER_PROFILE_PICTURE_UPDATED,
|
||||||
(data) => {
|
(data) => {
|
||||||
if (data.userId == this.userId) {
|
if (data.userId == this.userId) {
|
||||||
this.avatarUrl = data.picture;
|
this.avatarUrl = data.picture;
|
||||||
|
|
|
@ -21,7 +21,7 @@ import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreTextUtils } from '@services/utils/text';
|
import { CoreTextUtils } from '@services/utils/text';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import { CoreUser, CoreUserProfile, CoreUserProvider } from '@features/user/services/user';
|
import { CoreUser, CoreUserProfile, USER_PROFILE_PICTURE_UPDATED, USER_PROFILE_REFRESHED } from '@features/user/services/user';
|
||||||
import { CoreUserHelper } from '@features/user/services/user-helper';
|
import { CoreUserHelper } from '@features/user/services/user-helper';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreIonLoadingElement } from '@classes/ion-loading';
|
import { CoreIonLoadingElement } from '@classes/ion-loading';
|
||||||
|
@ -65,7 +65,7 @@ export class CoreUserAboutPage implements OnInit, OnDestroy {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.obsProfileRefreshed = CoreEvents.on(CoreUserProvider.PROFILE_REFRESHED, (data) => {
|
this.obsProfileRefreshed = CoreEvents.on(USER_PROFILE_REFRESHED, (data) => {
|
||||||
if (!this.user || !data.user) {
|
if (!this.user || !data.user) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ export class CoreUserAboutPage implements OnInit, OnDestroy {
|
||||||
await CoreSites.updateSiteInfo(this.site.getId());
|
await CoreSites.updateSiteInfo(this.site.getId());
|
||||||
} catch {
|
} catch {
|
||||||
// Cannot update site info. Assume the profile image is the right one.
|
// Cannot update site info. Assume the profile image is the right one.
|
||||||
CoreEvents.trigger(CoreUserProvider.PROFILE_PICTURE_UPDATED, {
|
CoreEvents.trigger(USER_PROFILE_PICTURE_UPDATED, {
|
||||||
userId: this.userId,
|
userId: this.userId,
|
||||||
picture: this.user.profileimageurl,
|
picture: this.user.profileimageurl,
|
||||||
}, this.site.getId());
|
}, this.site.getId());
|
||||||
|
@ -158,7 +158,7 @@ export class CoreUserAboutPage implements OnInit, OnDestroy {
|
||||||
await this.refreshUser();
|
await this.refreshUser();
|
||||||
} else {
|
} else {
|
||||||
// Now they're the same, send event to use the right avatar in the rest of the app.
|
// Now they're the same, send event to use the right avatar in the rest of the app.
|
||||||
CoreEvents.trigger(CoreUserProvider.PROFILE_PICTURE_UPDATED, {
|
CoreEvents.trigger(USER_PROFILE_PICTURE_UPDATED, {
|
||||||
userId: this.userId,
|
userId: this.userId,
|
||||||
picture: this.user.profileimageurl,
|
picture: this.user.profileimageurl,
|
||||||
}, this.site.getId());
|
}, this.site.getId());
|
||||||
|
@ -181,7 +181,7 @@ export class CoreUserAboutPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
const profileImageURL = await CoreUser.changeProfilePicture(result.itemid, this.userId, this.site.getId());
|
const profileImageURL = await CoreUser.changeProfilePicture(result.itemid, this.userId, this.site.getId());
|
||||||
|
|
||||||
CoreEvents.trigger(CoreUserProvider.PROFILE_PICTURE_UPDATED, {
|
CoreEvents.trigger(USER_PROFILE_PICTURE_UPDATED, {
|
||||||
userId: this.userId,
|
userId: this.userId,
|
||||||
picture: profileImageURL,
|
picture: profileImageURL,
|
||||||
}, this.site.getId());
|
}, this.site.getId());
|
||||||
|
@ -210,7 +210,7 @@ export class CoreUserAboutPage implements OnInit, OnDestroy {
|
||||||
event?.complete();
|
event?.complete();
|
||||||
|
|
||||||
if (this.user) {
|
if (this.user) {
|
||||||
CoreEvents.trigger(CoreUserProvider.PROFILE_REFRESHED, {
|
CoreEvents.trigger(USER_PROFILE_REFRESHED, {
|
||||||
courseId: this.courseId,
|
courseId: this.courseId,
|
||||||
userId: this.userId,
|
userId: this.userId,
|
||||||
user: this.user,
|
user: this.user,
|
||||||
|
|
|
@ -21,7 +21,7 @@ import { CoreSite } from '@classes/site';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import { CoreUser, CoreUserProfile, CoreUserProvider } from '@features/user/services/user';
|
import { CoreUser, CoreUserProfile, USER_PROFILE_REFRESHED } from '@features/user/services/user';
|
||||||
import { CoreUserHelper } from '@features/user/services/user-helper';
|
import { CoreUserHelper } from '@features/user/services/user-helper';
|
||||||
import {
|
import {
|
||||||
CoreUserDelegate,
|
CoreUserDelegate,
|
||||||
|
@ -64,7 +64,7 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
|
||||||
users?: CoreUserSwipeItemsManager;
|
users?: CoreUserSwipeItemsManager;
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute) {
|
constructor(private route: ActivatedRoute) {
|
||||||
this.obsProfileRefreshed = CoreEvents.on(CoreUserProvider.PROFILE_REFRESHED, (data) => {
|
this.obsProfileRefreshed = CoreEvents.on(USER_PROFILE_REFRESHED, (data) => {
|
||||||
if (!this.user || !data.user) {
|
if (!this.user || !data.user) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
|
||||||
event?.complete();
|
event?.complete();
|
||||||
|
|
||||||
if (this.user) {
|
if (this.user) {
|
||||||
CoreEvents.trigger(CoreUserProvider.PROFILE_REFRESHED, {
|
CoreEvents.trigger(USER_PROFILE_REFRESHED, {
|
||||||
courseId: this.courseId,
|
courseId: this.courseId,
|
||||||
userId: this.userId,
|
userId: this.userId,
|
||||||
user: this.user,
|
user: this.user,
|
||||||
|
|
|
@ -18,11 +18,24 @@ import { Subject, BehaviorSubject } from 'rxjs';
|
||||||
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
|
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreEvents } from '@singletons/events';
|
import { CoreEvents } from '@singletons/events';
|
||||||
import { CoreUserProfile, CoreUserProvider } from './user';
|
import { CoreUserProfile, USER_PROFILE_REFRESHED } from './user';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { CoreCourses, CoreCourseUserAdminOrNavOptionIndexed } from '@features/courses/services/courses';
|
import { CoreCourses, CoreCourseUserAdminOrNavOptionIndexed } from '@features/courses/services/courses';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
|
|
||||||
|
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 {
|
||||||
|
[USER_DELEGATE_UPDATE_HANDLER_EVENT]: CoreUserUpdateHandlerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface that all user profile handlers must implement.
|
* Interface that all user profile handlers must implement.
|
||||||
*/
|
*/
|
||||||
|
@ -168,6 +181,11 @@ export interface CoreUserProfileHandlerToDisplay {
|
||||||
type: string;
|
type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delegate update handler event.
|
||||||
|
*/
|
||||||
|
export const USER_DELEGATE_UPDATE_HANDLER_EVENT = 'CoreUserDelegate_update_handler_event';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to interact with plugins to be shown in user profile. Provides functions to register a plugin
|
* Service to interact with plugins to be shown in user profile. Provides functions to register a plugin
|
||||||
* and notify an update in the data.
|
* and notify an update in the data.
|
||||||
|
@ -188,11 +206,6 @@ export class CoreUserDelegateService extends CoreDelegate<CoreUserProfileHandler
|
||||||
*/
|
*/
|
||||||
static readonly TYPE_ACTION = 'action';
|
static readonly TYPE_ACTION = 'action';
|
||||||
|
|
||||||
/**
|
|
||||||
* Update handler information event.
|
|
||||||
*/
|
|
||||||
static readonly UPDATE_HANDLER_EVENT = 'CoreUserDelegate_update_handler_event';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache object that checks enabled for use.
|
* Cache object that checks enabled for use.
|
||||||
*/
|
*/
|
||||||
|
@ -206,7 +219,7 @@ export class CoreUserDelegateService extends CoreDelegate<CoreUserProfileHandler
|
||||||
constructor() {
|
constructor() {
|
||||||
super('CoreUserDelegate', true);
|
super('CoreUserDelegate', true);
|
||||||
|
|
||||||
CoreEvents.on(CoreUserDelegateService.UPDATE_HANDLER_EVENT, (data) => {
|
CoreEvents.on(USER_DELEGATE_UPDATE_HANDLER_EVENT, (data) => {
|
||||||
const handlersData = this.getHandlersData(data.userId, data.context, data.contextId);
|
const handlersData = this.getHandlersData(data.userId, data.context, data.contextId);
|
||||||
|
|
||||||
// Search the handler.
|
// Search the handler.
|
||||||
|
@ -225,7 +238,7 @@ export class CoreUserDelegateService extends CoreDelegate<CoreUserProfileHandler
|
||||||
this.clearHandlerCache();
|
this.clearHandlerCache();
|
||||||
});
|
});
|
||||||
|
|
||||||
CoreEvents.on(CoreUserProvider.PROFILE_REFRESHED, (data) => {
|
CoreEvents.on(USER_PROFILE_REFRESHED, (data) => {
|
||||||
const context = data.courseId ? CoreUserDelegateContext.COURSE : CoreUserDelegateContext.SITE;
|
const context = data.courseId ? CoreUserDelegateContext.COURSE : CoreUserDelegateContext.SITE;
|
||||||
this.clearHandlerCache(data.userId, context, data.courseId);
|
this.clearHandlerCache(data.userId, context, data.courseId);
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,7 +27,6 @@ import { CoreStatusWithWarningsWSResponse, CoreWSExternalWarning } from '@servic
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreError } from '@classes/errors/error';
|
||||||
import { USERS_TABLE_NAME, CoreUserDBRecord } from './database/user';
|
import { USERS_TABLE_NAME, CoreUserDBRecord } from './database/user';
|
||||||
import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications';
|
import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications';
|
||||||
import { CoreUserDelegateService, CoreUserUpdateHandlerData } from './user-delegate';
|
|
||||||
|
|
||||||
const ROOT_CACHE_KEY = 'mmUser:';
|
const ROOT_CACHE_KEY = 'mmUser:';
|
||||||
|
|
||||||
|
@ -39,13 +38,22 @@ 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 {
|
||||||
[CoreUserProvider.PROFILE_REFRESHED]: CoreUserProfileRefreshedData;
|
[USER_PROFILE_REFRESHED]: CoreUserProfileRefreshedData;
|
||||||
[CoreUserProvider.PROFILE_PICTURE_UPDATED]: CoreUserProfilePictureUpdatedData;
|
[USER_PROFILE_PICTURE_UPDATED]: CoreUserProfilePictureUpdatedData;
|
||||||
[CoreUserDelegateService.UPDATE_HANDLER_EVENT]: CoreUserUpdateHandlerData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Profile picture updated event.
|
||||||
|
*/
|
||||||
|
export const USER_PROFILE_REFRESHED = 'CoreUserProfileRefreshed';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Profile picture updated event.
|
||||||
|
*/
|
||||||
|
export const USER_PROFILE_PICTURE_UPDATED = 'CoreUserProfilePictureUpdated';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to provide user functionalities.
|
* Service to provide user functionalities.
|
||||||
*/
|
*/
|
||||||
|
@ -53,8 +61,6 @@ declare module '@singletons/events' {
|
||||||
export class CoreUserProvider {
|
export class CoreUserProvider {
|
||||||
|
|
||||||
static readonly PARTICIPANTS_LIST_LIMIT = 50; // Max of participants to retrieve in each WS call.
|
static readonly PARTICIPANTS_LIST_LIMIT = 50; // Max of participants to retrieve in each WS call.
|
||||||
static readonly PROFILE_REFRESHED = 'CoreUserProfileRefreshed';
|
|
||||||
static readonly PROFILE_PICTURE_UPDATED = 'CoreUserProfilePictureUpdated';
|
|
||||||
|
|
||||||
protected logger: CoreLogger;
|
protected logger: CoreLogger;
|
||||||
|
|
||||||
|
@ -841,20 +847,6 @@ export class CoreUserProvider {
|
||||||
}
|
}
|
||||||
export const CoreUser = makeSingleton(CoreUserProvider);
|
export const CoreUser = makeSingleton(CoreUserProvider);
|
||||||
|
|
||||||
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 {
|
|
||||||
[CoreUserProvider.PROFILE_REFRESHED]: CoreUserProfileRefreshedData;
|
|
||||||
[CoreUserProvider.PROFILE_PICTURE_UPDATED]: CoreUserProfilePictureUpdatedData;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data passed to PROFILE_REFRESHED event.
|
* Data passed to PROFILE_REFRESHED event.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue