@solid-data-modules/chats-ldo
Version:
A library to mangage chats in Solid Pods built with LDO
100 lines • 3.29 kB
TypeScript
import { ConnectedLdoDataset } from "@ldo/connected";
import { SolidConnectedPlugin, SolidContainer, SolidContainerUri, SolidLeaf } from "@ldo/connected-solid";
import { ChatMessageShape, ChatShape } from "./.ldo/longChat.typings.js";
export declare class Chat {
readonly containerResource: SolidContainer;
readonly chatResource: SolidLeaf;
todaysMessageResource?: SolidLeaf;
private dataset;
private mostRecentMessageDate;
private subscriptionCallback?;
private subscriptionId?;
private clearNewDayTrigger?;
private internalCallback?;
constructor(containerUri: SolidContainerUri, dataset: ConnectedLdoDataset<SolidConnectedPlugin[]>);
/**
* ===========================================================================
* HELPERS
* ===========================================================================
*/
private onNewDay;
/**
* Gets the resource for today's messages. If it doesn't exist, create it.
*/
private getOrCreateTodaysMessageResource;
/**
* Ensures today's message resource is identified
*/
private ensureTodaysMessageResource;
/**
* Given a message resource, find the message resource that is chronologically
* previous to this one. Return undefined if there is none.
* @param currentResource
*/
private getPreviousMessageResource;
/**
* Begins notification subscription with today's message resource
*/
private startNotificationSubscription;
/**
* Ends notification subscription with today's message resource
*/
private endNotificationSubscription;
/**
* Returns the messages in a resource sorted in order of most recent to least
* recent
* @param resource
*/
private getMessagesForMessageResource;
/**
* ===========================================================================
* PUBLIC METHODS
* ===========================================================================
*/
/**
* Creates a chat. Throws an error if it already esists
* @param chatInfo
*/
createChat(chatInfo: ChatShape): Promise<void>;
/**
* Gets a chat's info
* @returns
*/
getChatInfo(): Promise<ChatShape>;
setChatInfo(chatInfo: Partial<ChatShape>): Promise<void>;
/**
* Deletes this chat
*/
deleteChat(): Promise<void>;
/**
* Deletes the given message
* @param messageId
*/
removeMessage(messageId: string): Promise<void>;
/**
* Sends a message to the chat
* @param content
* @param makerWebId
*/
sendMessage(content: string, makerWebId: string): Promise<void>;
/**
* Returns an iterator to fetch paginated messages.
* @returns
*/
getMessageIterator(): AsyncGenerator<ChatMessageShape[]>;
/**
* Subscribe to new incoming messages for this chat
* @param callback
* @returns
*/
subscribeToMessages(callback: (message: ChatMessageShape[]) => void): Promise<void>;
/**
* Unsubscribe from notifications
*/
unsubscribeFromMessages(): Promise<void>;
/**
* Call this before destroying the class to clean up listeners.
*/
destroy(): Promise<void>;
}
//# sourceMappingURL=Chat.d.ts.map