/** * @module Favorites */ import { Subscription } from 'rxjs'; import { RBEvent } from '../../models/event.model'; import { Favorite, FavoriteRB } from '../../models/favorite.model'; import { Contact } from '../../models/contact.model'; import { ConversationRB, Conversation } from '../../models/conversation.model'; import { User } from '../../models'; import { Bubble } from '../../models/bubble.model'; import { EventableService, Service } from '../../services/service'; import { MaybeArray } from '../../typings/helpers'; /** @internal */ export declare const FAVORITES_SVC = "FavoritesService"; /** * @eventProperty * Favorites service events send to other services * Can listen to it via `FavoritesService.subscribe()` API */ export declare enum FavoritesServiceEvents { /** * @eventProperty * This `RBEvent` is sent when a new favorite has been created. * * **Event Data** * - **favorite**: The new created favorite (as Favorite) */ ON_FAVORITE_CREATED = "ON_FAVORITE_CREATED", /** * @eventProperty * This `RBEvent` is sent when a favorite has been deleted. * * **Event Data** * - **id**: The id (as string) of the favorite that has been deleted */ ON_FAVORITE_DELETED = "ON_FAVORITE_DELETED", /** * @eventProperty * This `RBEvent` is sent when a favorite has been moved in the list. * * **Event Data** * - **favorite**: The favorite that has been moved in the list (as Favorite) * - **position**: The new position (starting from 0) of this favorite in the list */ ON_FAVORITES_ORDER_CHANGED = "ON_FAVORITES_ORDER_CHANGED", /** * @internal * @eventProperty * This `RBEvent` is sent only when the favorite is related to a personal directory contact and this last has been updated. * * **Event Data** * - **favorite**: The updated favorite (as Favorite) */ ON_FAVORITE_CONTACT_UPDATED = "ON_FAVORITE_CONTACT_UPDATED" } export interface IFavoritesServiceEvents { /** * @eventProperty * This `RBEvent` is sent when a new favorite has been created. */ ON_FAVORITE_CREATED: { /** * The new created favorite (as Favorite) */ favorite: Favorite; }; /** * @eventProperty * This `RBEvent` is sent when a favorite has been deleted. */ ON_FAVORITE_DELETED: { /** * The id (as string) of the favorite that has been deleted */ id: string; }; /** * @eventProperty * This `RBEvent` is sent when a favorite has been moved in the list. */ ON_FAVORITES_ORDER_CHANGED: { /** * The favorite that has been moved in the list (as Favorite) */ favorite: Favorite; /** * The new position (starting from 0) of this favorite in the list */ position: number; }; /** * @internal * @eventProperty * This `RBEvent` is sent only when the favorite is related to a personal directory contact and this last has been updated. */ ON_FAVORITE_CONTACT_UPDATED: { /** * The updated favorite (as Favorite) */ favorite: Favorite; }; /** * @internal * @eventProperty * This `RBEvent` is sent only when the favorites are refreshed after a connection/reconnection */ ON_FAVORITES_REFRESH: unknown; } export interface FavoritesService extends EventableService { /** * Subscribe to the favorites updates, all events are of RBEvent * @param callback - The callback function that will be called when events are received * @param eventNames - (optional) array of event to listen * @returns Returns RxJS Subscription */ subscribe(callback: (event: RBEvent) => any, eventNames?: FavoritesServiceEvents | FavoritesServiceEvents[]): Subscription; /** * Get the complete list of my favorites with an array of Favorite. */ getFavorites(): Favorite[]; /** * Add the peer specified by its object to favorites list. * The item is specified by its object instance (User or Bubble) and must be one of the following: A user, a bubble, a bot, * a directory contact (from Personal Contacts or Business Contacts directories) or a Microsoft Azure AD user/Microsoft O365 contact. * A ON_FAVORITE_CREATED event is sent afterwards at the completion of the operation to notify about the favorite creation. * @param peerRef - Reference of the peer to add to favorites list. */ addToFavorites(peerRef: User | Bubble): Promise; /** * Delete the favorite specified by its identifier. * A ON_FAVORITE_DELETED event is sent afterwards at the completion of the operation to notify about the favorite deletion. * @param id - Favorite unique identifier. */ deleteFavorite(id: string): Promise; /** * Remove a peer specified by its object reference from favorites list. * A ON_FAVORITE_DELETED event is sent afterwards at the completion of the operation to notify about the favorite deletion. * @param peerRef - Reference of the peer to remove from favorites list. */ deleteFromFavorites(peerRef: User | Bubble | null): Promise; /** * Move a favorite in the favorites list. * The favorite specified by its object reference, is moved to the index specified in the parameter. * In addition, all existing favorites from this index will also have their positions automatically shifted by 1. * A ON_FAVORITES_ORDER_CHANGED event is sent afterwards at the completion of the operation to notify about the favorite's move. * @param favorite - Reference of the favorite to move in the favorites list. * @param position - The new position (starting from 0) of this favorite in the list. */ moveFavoritePosition(favorite: Favorite, position: number): Promise; } /** * @internal */ export declare class FavoritesServiceRB extends Service implements FavoritesService { private xmppManagementHandler; private conversationServiceSubscription; private readonly rxSubject; private xmppService; private mainService; private errorHelperService; private authService; private logger; private contactService; private profileService; private companyDirectoryService; private office365AdService; private bubbleService?; private conversationService?; favorites: FavoriteRB[]; /** * Returns the Favorite service singleton */ static getInstance(): FavoritesServiceRB; static build(): FavoritesServiceRB; private constructor(); start(): Promise; connect(): Promise; private attachHandlers; private removeHandlers; stop(): Promise; reconnect(): Promise; /** * Subscribe to the favorites updates, all events are of RBEvent * @param callback - The callback function that will be called when events are received * @param eventNames - (optional) array of event to listen * @returns Returns RxJS Subscription */ subscribe(callback: (event: RBEvent) => any, eventNames?: MaybeArray): Subscription; /** * {@inheritdoc} */ events(...eventNames: EventNames[]): import("rxjs").Observable>>; /** * @public * @param name - the name of the event * @param data - the data to be send (an object) * FavoritesService events send to other services via sendEvent() * Can listen to it via FavoritesServiceRB.subscribe() API */ private sendEvent; /** * Management of ConversationServiceEvent.ON_SERVICE_STARTED event reception * Associate a conversation (if it exists) with all defined favorites. * If a conversation is found, it is also tagged as a favorite. */ private updateConversationsForFavorites; /** * Management of a favorite when a conversation is created or deleted: * - Reception of ON_CONVERSATION_REMOVED event (conversation deleted) * - Explicit call (For example 'conversationServiceEventHandler' at conversation creation) * If a favorite associated to the given conversation is found * - the conversation field associated to this favorite is updated (conv stored or reset) * - the conversation is tagged as a favorite. * @param conversation - The created or deleted conversation * @param removed - Flag indicating whether the conversation is deleted (if false, it means it is created) */ updateFavoriteConversations(conversation: Conversation, removed?: boolean): void; /** * Management of XMPP management message * @param stanza - The received stanza. */ private onManagementMessageReceived; /** * Checks whether the favorite itype s associated with a directory contact such as ... * - Rainbow Personal or Business directory * - Microsoft Azure Active Directory * - Microsoft Outlook contacts * @param type - Type of favorite to check */ private isDirectoryFavorite; /** * Get the list of favorites from the server. * Promise resolution with an array of all favorites. */ private getFavoritesFromServer; /** * Add a peer specified by its id and type to favorites list * The item is specified by its Id and must be one of the following types: user, bubble, bot, * directory contact (from personal directory, business directory) and O365 (Microsoft Azure) directory contact * @param peerId - Id of the peer marked as favorite * @param type - Type of favorite */ private addServerFavorite; /** * Create a new favorite as a FavoriteRB model * In addition to the info linked to the favorite itself (Id, position, type, peer Id), the peer object (Instance of Buble, Contact..) * is also is also stored in the favorite. * @param id - Id of the favorite. * @param peerId - Id of the peer linked to the favorite: userId, bubbleId, botId, directoryId or office365Id * @param type - Type of the favorite peer: user/bubble/bot/directory/office365 */ private createFavorite; /** * This function is mainly used to manage directory contact * @param favorite - The favorite to update. * @param contact - The contact associated to the favorite. */ updateFavoriteContact(favorite: Favorite, contact: Contact): void; /** * Search for a favorite associated with the specified contact * If found, the favorite data is updated with this contact. * Useful to update the displayed data (name, avatar) in the favorite list * This function is mainly used to manage personal directory contact * @param contact - The updated contact associated to the favorite. */ searchAndUpdateFavoriteContact(contact: Contact): void; /** * Check if the specified peer (a user, bubble, direcoty contact...) is marked as favorite. * @param peerId - The updated contact associated to the favorite. */ isFavoriteConversation(peerId: string): boolean; /** * Add or remove a favorite from a conversation * It will be checked whether there is a favorite with the contact linked to the conversation. * If so, the bookmark will be deleted; if not, it will be created. * @param conversation - The conversation that may be associated to the favorite. */ toggleFavorite(conversation: ConversationRB): Promise; /** * Retrieves the conversation associated with a selected favorite * The selected favorite is specified via the peer Id, which is the id of the contact or bubble. * The selected favorite must have a conversation, so it can not be a favorite representing * a directory contact (business/personal/o365) for which there is no conversation. * @param peerId - Id of the peer marked as favorite */ getFavoriteConversation(peerId: string): Promise; /** * Get the list of my favorites. */ getFavorites(): Favorite[]; /** * Add the peer specified by its object to favorites list * The item is specified by its object instance (User or Bubble) and must be one of the following: A user, a bubble, a bot, * a directory contact (from Personal Contacts or Business Contacts directories) or a Microsoft Azure AD user/Microsoft O365 contact. * A ON_FAVORITE_CREATED event is sent afterwards at the completion of the operation to notify about the favorite creation. * @param peerRef - Reference of the peer to add to favorites list */ addToFavorites(peerRef: User | Bubble): Promise; /** * Delete the favorite specified by its identifier. * The deletion is done on server side. * A ON_FAVORITE_DELETED event is sent afterwards at the completion of the operation to notify about the favorite deletion. * @param favoriteId - Favorite unique identifier */ deleteFavorite(favoriteId: string): Promise; /** * Delete the favorite specified by its identifier. * The deletion is done on server side. * A ON_FAVORITE_DELETED event is sent afterwards at the completion of the operation to notify about the favorite deletion. * @param peerRef - Reference of the peer to remove from favorites list */ deleteFromFavorites(peerRef: User | Bubble | null): Promise; /** * Move a favorite in the favorites list. * The favorite specified by its object reference, is moved to the index specified in the parameter. * In addition, all existing favorites from this index will also have their positions automatically shifted by 1. * A ON_FAVORITES_ORDER_CHANGED event is sent afterwards at the completion of the operation to notify about the favorite's move. * @param favorite - Reference of the favorite to move in the favorites list. * @param position - The new position (starting from 0) of this favorite in the list. */ moveFavoritePosition(favorite: Favorite, position: number): Promise; } //# sourceMappingURL=favorites.service.d.ts.map