@corva/chat-core 0.1.11 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -56,6 +56,7 @@ interface AppCommentData {
56
56
  };
57
57
  settingsSnapshotId?: string;
58
58
  isTruncated?: boolean;
59
+ mentionUserIds?: string[];
59
60
  /** Transient: app settings at forward time. Saved to snapshot storage, never sent in the message. */
60
61
  settings?: Record<string, unknown>;
61
62
  }
@@ -208,6 +209,7 @@ interface AppCommentWirePayload {
208
209
  };
209
210
  snpId?: string;
210
211
  trunc?: boolean;
212
+ m?: string;
211
213
  }
212
214
 
213
215
  interface FeedItemData {
@@ -321,6 +323,7 @@ interface UploadFile {
321
323
  interface MessageFormData {
322
324
  text: string;
323
325
  roomId: string;
326
+ mentionUserIds?: Readonly<Record<string, string | null>>;
324
327
  threadId?: string;
325
328
  file?: UploadFile;
326
329
  files?: UploadFile[];
@@ -605,6 +608,8 @@ type UserStatus = 'online' | 'away' | 'busy' | 'offline';
605
608
  declare const ASSET_CHAT_PREFIXES: Record<ChatAssetType, string>;
606
609
  declare const ASSET_NOUN: Record<SelectableAssetType, string>;
607
610
  declare const ASSET_API_FIELDS: Record<ChatAssetType, string[]>;
611
+ declare const MENTION_BOUNDARY_SOURCE = "(?<=^|[\\s([{\"',;!?*>\u201C\u2018\u00AB])";
612
+ declare const MENTION_USERNAME_SOURCE = "[\\p{L}\\p{M}\\p{N}_.+-]*[\\p{L}\\p{M}\\p{N}_+-]";
608
613
  declare const MENTION_REPLACE_PATTERN: RegExp;
609
614
  declare const MENTION_SPLIT_PATTERN: RegExp;
610
615
  declare const REVOLT_SYSTEM_USER_ID = "00000000000000000000000000";
@@ -767,6 +772,52 @@ declare function isUserOnline(user: User): boolean;
767
772
 
768
773
  declare function isVisibleUnread(sub: Subscription, isRoomDisallowed: (roomId: string) => boolean): boolean;
769
774
 
775
+ type MentionFormat = 'id' | 'username' | 'platform';
776
+ interface TextSegment {
777
+ type: 'text';
778
+ value: string;
779
+ }
780
+ interface MentionSegment {
781
+ type: 'mention';
782
+ format: MentionFormat;
783
+ raw: string;
784
+ userId?: string;
785
+ username?: string;
786
+ corvaUserId?: string;
787
+ label?: string;
788
+ }
789
+ type MentionTextSegment = TextSegment | MentionSegment;
790
+ type MentionDisplayResolver = (segment: MentionSegment) => string | undefined;
791
+ declare function tokenizeMentions(text: string): MentionTextSegment[];
792
+ declare function toReadableText(text: string, resolve: MentionDisplayResolver): string;
793
+ declare function encodeMentionsForSend(text: string, resolveUserId: (username: string) => string | undefined): string;
794
+ /** User ids by lowercased username; `null` keeps the name as plain text. */
795
+ type MentionUserIds = Readonly<Record<string, string | null>>;
796
+ interface EditableMentionText {
797
+ text: string;
798
+ userIds: Readonly<Record<string, string>>;
799
+ }
800
+ declare function decodeMentionsForEdit(text: string, resolveUsername: (userId: string) => string | undefined): EditableMentionText;
801
+ declare function getMentionedUserIds(text: string): string[];
802
+
803
+ interface MentionLookupOptions {
804
+ roomId?: string;
805
+ }
806
+ declare function findMentionUserById(id: string): User | undefined;
807
+ declare function findMentionUserByUsername(username: string, { roomId }?: MentionLookupOptions): User | undefined;
808
+ declare const resolveMentionDisplayName: MentionDisplayResolver;
809
+ declare const isUnknownMention: (segment: MentionSegment) => boolean;
810
+ declare const getMentionLabel: (segment: MentionSegment) => string;
811
+ declare function getMentionSearchHandle(segment: MentionSegment): string | undefined;
812
+ declare function getPlatformMentionUserIds(text: string): string[];
813
+ declare const toReadableMentionText: (text: string) => string;
814
+ declare const toEditableMentionText: (text: string) => EditableMentionText;
815
+
816
+ interface OutgoingMentionOptions extends MentionLookupOptions {
817
+ userIds?: MentionUserIds;
818
+ }
819
+ declare function encodeOutgoingMentions(content: string, { userIds, ...options }?: OutgoingMentionOptions): string;
820
+
770
821
  interface ParsedCorvaMessage {
771
822
  messageType: string;
772
823
  alert?: AlertData;
@@ -789,6 +840,7 @@ declare function buildForwardMessageContent(sourceChannelId: string, messageId:
789
840
  * the body is truncated and `trunc` flag is set for lazy-fetching.
790
841
  */
791
842
  declare function buildAppCommentMessageContent(data: AppCommentData): string;
843
+ declare function mapCorvaMessageNote(content: string, map: (note: string) => string): string;
792
844
  /**
793
845
  * Detects the $$CORVA:: prefix in message content
794
846
  * and parses the JSON payload into internal types.
@@ -1124,6 +1176,8 @@ declare const createGroupSubscription: (groupId: string, name: string, owner: {
1124
1176
  declare const createDMSubscription: (roomId: string, recipient?: User) => Subscription;
1125
1177
  declare const addOrUpdateSubscription: (subscriptions: Subscription[], newSubscription: Subscription) => Subscription[];
1126
1178
  declare const removeSubscription: (subscriptions: Subscription[], roomId: string) => Subscription[];
1179
+ /** The last-acked id to hydrate a room with, from the server's unread pointer. */
1180
+ declare const getHydratedAckedId: (rid: string, serverAcked: string | undefined) => string | undefined;
1127
1181
 
1128
1182
  /** Requests against corva-api. The host adds the base URL, the Corva JWT and query encoding. */
1129
1183
  interface CorvaApiAdapter {
@@ -1276,6 +1330,7 @@ declare function getCorvaUserFields(corvaUser: StoredCorvaUser): {
1276
1330
  role: string | undefined;
1277
1331
  id: string | number;
1278
1332
  };
1333
+ declare function getCorvaUserName(corvaUser: StoredCorvaUser): string | undefined;
1279
1334
  declare function createCorvaUserService(): {
1280
1335
  setMapping(revoltUserId: string, corvaUser: StoredCorvaUser): void;
1281
1336
  getCorvaUser(revoltUserId: string): StoredCorvaUser | undefined;
@@ -1416,7 +1471,7 @@ interface MessageStore {
1416
1471
  sendMessage: (data: MessageFormData) => Promise<unknown>;
1417
1472
  retrySendMessage: (tempId: string) => Promise<unknown>;
1418
1473
  dismissFailedMessage: (tempId: string) => void;
1419
- editMessage: (messageId: string, content: string) => Promise<void>;
1474
+ editMessage: (messageId: string, content: string, mentionUserIds?: Readonly<Record<string, string | null>>) => Promise<void>;
1420
1475
  deleteMessage: (messageId: string) => Promise<void>;
1421
1476
  pinMessage: (messageId: string) => Promise<void>;
1422
1477
  unpinMessage: (messageId: string) => Promise<void>;
@@ -1747,4 +1802,4 @@ declare const createSocketEventHandlers: (config: SocketEventHandlersConfig) =>
1747
1802
 
1748
1803
  declare const installUnreadWatcher: () => void;
1749
1804
 
1750
- export { ALERT_SEVERITY, ASSET_API_FIELDS, ASSET_CHAT_PREFIXES, ASSET_NOUN, type AckScheduler, type AlertData, type AlertSeverity, type AlertWirePayload, type AppCommentAttachment, type AppCommentData, type AppCommentWirePayload, type AppStateAdapter, type AskCorvaData, type AskCorvaWirePayload, type AssetChatChannel, type AssetChatSession, type AssetStore, type Attachment, type AuthStore, CHANNEL_NAME_MAX_LENGTH, CHANNEL_TYPES, CORVA_JOIN_MESSAGE_TYPE, CORVA_MESSAGE_TYPES, CORVA_SYS_PREFIX, type ChannelAsset, type ChannelContentFilter, type ChannelContentFilterStore, type ChannelContentFilters, type ChannelNameValidation, type ChannelNotificationPreference, type ChannelNotificationSetting, type ChannelUnread, type ChatAsset, type ChatAssetIdentity, type ChatAssetType, type ChatDates, type ChatHost, type ChatNotifier, type ChatPlatform, type CorvaAPIUser, type CorvaApiAdapter, type CorvaRevoltAuthResponse, type CorvaSystemMessage, type CorvaUser, type CorvaUserService, DATE_SEPARATOR_LABELS, DEFAULT_CHANNEL_CONTENT_FILTER, DEFAULT_CHANNEL_CONTENT_FILTERS, DEFAULT_CHANNEL_PREFERENCE, DEFAULT_FAVORITE_ROOMS_SETTINGS, DEFAULT_HIDDEN_ROOMS_SETTINGS, DEFAULT_NOTIFICATION_PREFERENCES, DEFAULT_NOTIFICATION_SETTINGS, DEFAULT_ROOM_LIST_ORDER, DIRECT_MESSAGE_PLACEHOLDER, type ExternalChannel, type FavoriteRoomsSettings, type FavoriteRoomsStore, type FeedItemData, type FeedWirePayload, type FileAttachment, type FilterEntityWindow, type ForwardWirePayload, type ForwardedFrom, GENERAL_CHAT_NAME, type HiddenRoomsSettings, type HttpClient, type HttpClientConfig, HttpError, type HttpRequestInit, type HttpResponseLike, type JoinRequired, type JoinWirePayload, type KeyValueStorage, type LocatorContext, type LoginCredentials, MAX_ATTACHMENT_SIZE_BYTES, MAX_ATTACHMENT_SIZE_MB, MAX_NAVIGATION_HISTORY, MENTION_REPLACE_PATTERN, MENTION_SPLIT_PATTERN, MUTE_PRESET_OPTIONS, type MemberStore, type Message, type MessageCache, type MessageFormData, type MessageStore, NOTIFICATION_DESTINATIONS, NOTIFICATION_SETTING_ALL, NOTIFICATION_SETTING_MENTIONS, NOTIFICATION_SETTING_NOTHING, type NavigationEntry, type NavigationHistoryStore, type NotificationDestination, type NotificationPreferences, type NotificationSettings, type NotificationStore, PAUSE_INDEFINITELY, PAUSE_PRESETS, PAUSE_PRESET_OPTIONS, type PausePreset, type PausePresetOption, REVOLT_SYSTEM_USER_ID, ROOM_LIST_ORDER, type ReadyChannelData, type RevoltAPIInstance, type RevoltChannel, type RevoltIncomingMessagePayload, type RevoltLoginResponse, type RevoltMessage, type RevoltMessageResponse, type RevoltSocketConfig, type RevoltSocketEventHandlers, type RevoltSocketInstance, type RevoltUploadResponse, type RevoltUserResponse, type Room, type RoomListOrder, type RoomStore, type RoomType, SESSION_STORAGE_KEY, SIDEBAR_SECTIONS, SIDEBAR_TABS, SOFT_DELETE_MARKER, SYSTEM_MESSAGE_TEXTS, type SaveSessionParams, type SelectableAssetType, type SessionData, SessionManager, type SharedFile, type SharedRefs, type SidebarSectionKey, type SidebarTabKey, type SocketCloseEventLike, type SocketEventHandlersConfig, type StoredChannelPreference, type Subscription, type TracesViewportRequest, type TypingManager, type UIStore, type UploadAndSendResult, type UploadFile, type UploadedFile, type User, type UserStatus, type ViewportDeepLink, type ViewportIndexCurve, type ViewportMode, WEBSOCKET_CONNECTING, WEBSOCKET_OPEN, type WebSocketLike, type WireSeverity, addMessage, addOrUpdateSubscription, alertMessageAsText, assetStore, authStore, buildAppCommentMessageContent, buildAskCorvaMessageContent, buildFinalMessage, buildForwardMessageContent, buildGroupChannelName, canDeleteMessage, canEditMessage, channelContentFilterStore, channelToAsset, chatToastStore, clearLastOpenedRoom, compareByActivity, compareByName, compareByRecencyDesc, configureChat, configureChatStorage, createAckScheduler, createCorvaUserService, createDMSubscription, createGroupSubscription, createHttpClient, createLatestWinsQueue, createMemoryStorage, createMessageCache, createRevoltAPI, createRevoltSocket, createRoomTaskQueue, createSocketEventHandlers, createSoftDeletedMessage, createTypingManager, deriveAllowedChatAsset, enrichWithCorvaData, ensureChatSession, extractTimestampFromULID, failOptimisticMessage, favoriteRoomsStore, findGeneralRoom, formatAssetChatName, getAppCommentAttachments, getAssetChatChannel, getAssetChatSession, getAssetTypeFromDisplayName, getChatHost, getChatStorage, getCorvaUserFields, getExternalChannel, getLastOpenedRoom, getMessageTimestamp, getPauseUntil, getReactionCount, getRoomDisplayName, getSystemMessageWithCorvaNames, getUserDisplayName, getUserSecondaryText, handleUnauthorized, hasReactions, hasUserReacted, initChat, installUnreadWatcher, isAlertMessage, isAppCommentMessage, isAskCorvaMessage, isChannelMuted, isChatAssetTypeAllowed, isChatStorageConfigured, isCurrentRoomSelection, isDeepEqual, isDefaultChannelPreference, isDisallowedAssetChatRoom, isDmGroup, isExternalServerChannel, isForwardedMessage, isGeneralRoom, isNotificationsPaused, isPauseActive, isSoftDeletedMessage, isSystemMessage, isUnread, isUserOnline, isValidPausePreset, isVisibleUnread, keepChatUsed, loadUntilFound, memberStore, messageStore, navigationHistoryStore, notificationStore, onChatStorageConfigured, parseCorvaSystemMessage, prepareRoomSelection, removeMessageFromList, removeSubscription, resetAssetStore, resetAuthStore, resetChannelContentFilterStore, resetChatAssetPermissionsSnapshot, resetChatHost, resetFavoriteRoomsStore, resetMemberStore, resetMessageStore, resetNavigationHistoryStore, resetNotificationStore, resetRoomStore, resetUIStore, roomStore, saveLastChatActivity, saveLastOpenedRoom, searchMessages, searchRooms, searchUsers, selectCanGoBack, selectCanGoForward, setAllowedChatAssetTypes, settleOptimisticMessage, sharedRefs, sortChannels, sortDMs, sortMessagesByTime, sortUsersByStatus, stripPlatformMentions, uiStore, updateMessageInList, uploadAndSend, validateChannelName, waitForNextPaint, wasRecentlyActive, withChannelPreferenceDefaults };
1805
+ export { ALERT_SEVERITY, ASSET_API_FIELDS, ASSET_CHAT_PREFIXES, ASSET_NOUN, type AckScheduler, type AlertData, type AlertSeverity, type AlertWirePayload, type AppCommentAttachment, type AppCommentData, type AppCommentWirePayload, type AppStateAdapter, type AskCorvaData, type AskCorvaWirePayload, type AssetChatChannel, type AssetChatSession, type AssetStore, type Attachment, type AuthStore, CHANNEL_NAME_MAX_LENGTH, CHANNEL_TYPES, CORVA_JOIN_MESSAGE_TYPE, CORVA_MESSAGE_TYPES, CORVA_SYS_PREFIX, type ChannelAsset, type ChannelContentFilter, type ChannelContentFilterStore, type ChannelContentFilters, type ChannelNameValidation, type ChannelNotificationPreference, type ChannelNotificationSetting, type ChannelUnread, type ChatAsset, type ChatAssetIdentity, type ChatAssetType, type ChatDates, type ChatHost, type ChatNotifier, type ChatPlatform, type CorvaAPIUser, type CorvaApiAdapter, type CorvaRevoltAuthResponse, type CorvaSystemMessage, type CorvaUser, type CorvaUserService, DATE_SEPARATOR_LABELS, DEFAULT_CHANNEL_CONTENT_FILTER, DEFAULT_CHANNEL_CONTENT_FILTERS, DEFAULT_CHANNEL_PREFERENCE, DEFAULT_FAVORITE_ROOMS_SETTINGS, DEFAULT_HIDDEN_ROOMS_SETTINGS, DEFAULT_NOTIFICATION_PREFERENCES, DEFAULT_NOTIFICATION_SETTINGS, DEFAULT_ROOM_LIST_ORDER, DIRECT_MESSAGE_PLACEHOLDER, type EditableMentionText, type ExternalChannel, type FavoriteRoomsSettings, type FavoriteRoomsStore, type FeedItemData, type FeedWirePayload, type FileAttachment, type FilterEntityWindow, type ForwardWirePayload, type ForwardedFrom, GENERAL_CHAT_NAME, type HiddenRoomsSettings, type HttpClient, type HttpClientConfig, HttpError, type HttpRequestInit, type HttpResponseLike, type JoinRequired, type JoinWirePayload, type KeyValueStorage, type LocatorContext, type LoginCredentials, MAX_ATTACHMENT_SIZE_BYTES, MAX_ATTACHMENT_SIZE_MB, MAX_NAVIGATION_HISTORY, MENTION_BOUNDARY_SOURCE, MENTION_REPLACE_PATTERN, MENTION_SPLIT_PATTERN, MENTION_USERNAME_SOURCE, MUTE_PRESET_OPTIONS, type MemberStore, type MentionDisplayResolver, type MentionFormat, type MentionLookupOptions, type MentionSegment, type MentionTextSegment, type MentionUserIds, type Message, type MessageCache, type MessageFormData, type MessageStore, NOTIFICATION_DESTINATIONS, NOTIFICATION_SETTING_ALL, NOTIFICATION_SETTING_MENTIONS, NOTIFICATION_SETTING_NOTHING, type NavigationEntry, type NavigationHistoryStore, type NotificationDestination, type NotificationPreferences, type NotificationSettings, type NotificationStore, type OutgoingMentionOptions, PAUSE_INDEFINITELY, PAUSE_PRESETS, PAUSE_PRESET_OPTIONS, type PausePreset, type PausePresetOption, REVOLT_SYSTEM_USER_ID, ROOM_LIST_ORDER, type ReadyChannelData, type RevoltAPIInstance, type RevoltChannel, type RevoltIncomingMessagePayload, type RevoltLoginResponse, type RevoltMessage, type RevoltMessageResponse, type RevoltSocketConfig, type RevoltSocketEventHandlers, type RevoltSocketInstance, type RevoltUploadResponse, type RevoltUserResponse, type Room, type RoomListOrder, type RoomStore, type RoomType, SESSION_STORAGE_KEY, SIDEBAR_SECTIONS, SIDEBAR_TABS, SOFT_DELETE_MARKER, SYSTEM_MESSAGE_TEXTS, type SaveSessionParams, type SelectableAssetType, type SessionData, SessionManager, type SharedFile, type SharedRefs, type SidebarSectionKey, type SidebarTabKey, type SocketCloseEventLike, type SocketEventHandlersConfig, type StoredChannelPreference, type Subscription, type TextSegment, type TracesViewportRequest, type TypingManager, type UIStore, type UploadAndSendResult, type UploadFile, type UploadedFile, type User, type UserStatus, type ViewportDeepLink, type ViewportIndexCurve, type ViewportMode, WEBSOCKET_CONNECTING, WEBSOCKET_OPEN, type WebSocketLike, type WireSeverity, addMessage, addOrUpdateSubscription, alertMessageAsText, assetStore, authStore, buildAppCommentMessageContent, buildAskCorvaMessageContent, buildFinalMessage, buildForwardMessageContent, buildGroupChannelName, canDeleteMessage, canEditMessage, channelContentFilterStore, channelToAsset, chatToastStore, clearLastOpenedRoom, compareByActivity, compareByName, compareByRecencyDesc, configureChat, configureChatStorage, createAckScheduler, createCorvaUserService, createDMSubscription, createGroupSubscription, createHttpClient, createLatestWinsQueue, createMemoryStorage, createMessageCache, createRevoltAPI, createRevoltSocket, createRoomTaskQueue, createSocketEventHandlers, createSoftDeletedMessage, createTypingManager, decodeMentionsForEdit, deriveAllowedChatAsset, encodeMentionsForSend, encodeOutgoingMentions, enrichWithCorvaData, ensureChatSession, extractTimestampFromULID, failOptimisticMessage, favoriteRoomsStore, findGeneralRoom, findMentionUserById, findMentionUserByUsername, formatAssetChatName, getAppCommentAttachments, getAssetChatChannel, getAssetChatSession, getAssetTypeFromDisplayName, getChatHost, getChatStorage, getCorvaUserFields, getCorvaUserName, getExternalChannel, getHydratedAckedId, getLastOpenedRoom, getMentionLabel, getMentionSearchHandle, getMentionedUserIds, getMessageTimestamp, getPauseUntil, getPlatformMentionUserIds, getReactionCount, getRoomDisplayName, getSystemMessageWithCorvaNames, getUserDisplayName, getUserSecondaryText, handleUnauthorized, hasReactions, hasUserReacted, initChat, installUnreadWatcher, isAlertMessage, isAppCommentMessage, isAskCorvaMessage, isChannelMuted, isChatAssetTypeAllowed, isChatStorageConfigured, isCurrentRoomSelection, isDeepEqual, isDefaultChannelPreference, isDisallowedAssetChatRoom, isDmGroup, isExternalServerChannel, isForwardedMessage, isGeneralRoom, isNotificationsPaused, isPauseActive, isSoftDeletedMessage, isSystemMessage, isUnknownMention, isUnread, isUserOnline, isValidPausePreset, isVisibleUnread, keepChatUsed, loadUntilFound, mapCorvaMessageNote, memberStore, messageStore, navigationHistoryStore, notificationStore, onChatStorageConfigured, parseCorvaSystemMessage, prepareRoomSelection, removeMessageFromList, removeSubscription, resetAssetStore, resetAuthStore, resetChannelContentFilterStore, resetChatAssetPermissionsSnapshot, resetChatHost, resetFavoriteRoomsStore, resetMemberStore, resetMessageStore, resetNavigationHistoryStore, resetNotificationStore, resetRoomStore, resetUIStore, resolveMentionDisplayName, roomStore, saveLastChatActivity, saveLastOpenedRoom, searchMessages, searchRooms, searchUsers, selectCanGoBack, selectCanGoForward, setAllowedChatAssetTypes, settleOptimisticMessage, sharedRefs, sortChannels, sortDMs, sortMessagesByTime, sortUsersByStatus, stripPlatformMentions, toEditableMentionText, toReadableMentionText, toReadableText, tokenizeMentions, uiStore, updateMessageInList, uploadAndSend, validateChannelName, waitForNextPaint, wasRecentlyActive, withChannelPreferenceDefaults };