@atlaskit/mention
Version:
A React component used to display user profiles in a list for 'Mention' functionality
159 lines (158 loc) • 5.49 kB
TypeScript
import { type Presence } from '../types';
import { AbstractResource, type ResourceProvider } from './MentionResource';
export interface PresenceMap {
[userId: string]: Presence;
}
/**
* Configuration for the PresenceResource, which manages real-time user
* presence (online/offline/busy/focus status) by querying a GraphQL-based
* presence service.
*/
export interface PresenceResourceConfig {
/**
* The activation ID for the current product instance, used to build
* the `atl-attribution` header for presence service requests.
*/
activationId?: string;
/**
* A custom cache implementation for storing presence data. If not provided,
* a {@link DefaultPresenceCache} is used with the specified `cacheExpiry`.
*/
cache?: PresenceCache;
/**
* The expiry time in milliseconds for cached presence entries.
* Defaults to 20,000ms (20 seconds) when using the default cache.
*/
cacheExpiry?: number;
/**
* The cloud ID (organization ID) of the Atlassian site. Required.
* Used as the `organizationId` variable in the presence GraphQL query.
*/
cloudId: string;
/**
* Custom HTTP headers to include in presence service requests.
*/
headers?: Record<string, string>;
/**
* A custom parser for transforming raw presence service responses into
* a {@link PresenceMap}. If not provided, a {@link DefaultPresenceParser} is used,
* which maps `'available'` → `'online'` and `'unavailable'` → `'offline'`.
*/
parser?: PresenceParser;
/**
* The product identifier (e.g. `'confluence'`, `'jira'`) passed as the
* `product` variable in the presence GraphQL query to scope results.
*/
productId?: string;
/**
* The base URL of the presence service endpoint. Required.
* A trailing slash will be appended automatically if not present.
*/
url: string;
}
export interface PresenceCache {
contains(userId: string): boolean;
get(userId: string): Presence;
getBulk(userIds: string[]): PresenceMap;
getMissingUserIds(userIds: string[]): string[];
update(presUpdate: PresenceMap): void;
}
export interface PresenceResponse {
data: Data;
}
export interface Data {
PresenceBulk: PresenceBulk[];
}
export interface PresenceBulk {
date: null | string;
message: null | string;
state: null | string;
stateMetadata?: string;
type: null | string;
userId: string;
}
export interface PresenceParser {
mapState(state: string): string;
parse(response: PresenceResponse): PresenceMap;
}
export interface PresenceProvider extends ResourceProvider<PresenceMap> {
refreshPresence(userIds: string[]): void;
}
declare class AbstractPresenceResource extends AbstractResource<PresenceMap> implements PresenceProvider {
refreshPresence(userIds: string[]): void;
protected notifyListeners(presences: PresenceMap): void;
}
declare class PresenceResource extends AbstractPresenceResource {
private config;
private presenceCache;
private presenceParser;
constructor(config: PresenceResourceConfig);
refreshPresence(userIds: string[]): void;
private retrievePresence;
private queryDirectoryForPresences;
private static cleanUrl;
}
export declare class DefaultPresenceCache implements PresenceCache {
private static readonly defaultTimeout;
private static readonly defaultFlushTrigger;
private cache;
private size;
private expiryInMillis;
private flushTrigger;
constructor(cacheTimeout?: number, cacheTrigger?: number);
/**
* Precondition: _delete is only called internally if userId exists in cache
* Removes cache entry
* @param userId
*/
private _delete;
/**
* Checks a cache entry and calls delete if the info has expired
* @param userId
*/
private _deleteIfExpired;
/**
* Cleans expired entries from cache
*/
private _removeExpired;
/**
* Checks if a user exists in the cache
* @param userId
*/
contains(userId: string): boolean;
/**
* Retrieves a presence from the cache after checking for expired entries
* @param userId - to index the cache
* @returns Presence - the presence that matches the userId
*/
get(userId: string): Presence;
/**
* Retrieve multiple presences at once from the cache
* @param userIds - to index the cache
* @returns PresenceMap - A map of userIds to cached Presences
*/
getBulk(userIds: string[]): PresenceMap;
/**
* For a given list of ids, returns a subset
* of all the ids with missing cache entries.
* @param userIds - to index the cache
* @returns string[] - ids missing from the cache
*/
getMissingUserIds(userIds: string[]): string[];
/**
* Precondition: presMap only contains ids of users not in cache
* expired users must first be removed then reinserted with updated presence
* Updates the cache by adding the new Presence entries and setting the expiry time
* @param presMap
*/
update(presMap: PresenceMap): void;
}
export declare class DefaultPresenceParser implements PresenceParser {
static FOCUS_STATE: string;
mapState(state: string): string;
parse(response: PresenceResponse): PresenceMap;
private static extractState;
private static isFocusState;
}
export { AbstractPresenceResource };
export default PresenceResource;