format
This commit is contained in:
+283
-274
@@ -37,433 +37,442 @@ export default class ChatModel {
|
||||
info: ChatInfoFileContent; /* load function called in constructor */
|
||||
|
||||
get secondaryChannels(): string[] {
|
||||
return this.info.secondaryChannels.sort(localeCompare);
|
||||
return this.info.secondaryChannels.sort(localeCompare);
|
||||
}
|
||||
|
||||
get color(): Colors {
|
||||
const color = this.info.color as Colors;
|
||||
if ([...Object.values(Colors)].includes(color)) return color;
|
||||
return Colors.Standard;
|
||||
const color = this.info.color as Colors;
|
||||
if ([...Object.values(Colors)].includes(color)) return color;
|
||||
return Colors.Standard;
|
||||
}
|
||||
|
||||
// handler managers
|
||||
readonly chatMessageHandlerManager: HandlerManager<ChatMessage> =
|
||||
new HandlerManager();
|
||||
new HandlerManager();
|
||||
readonly reactionHandlerManager: HandlerManager<ChatMessageReaction> =
|
||||
new HandlerManager();
|
||||
new HandlerManager();
|
||||
readonly changeHandlerManager: HandlerManager<null> = new HandlerManager();
|
||||
|
||||
// paths
|
||||
readonly getBasePath = (): string[] => {
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPaths.Chat,
|
||||
filePaths.chat.chatBase(this.id),
|
||||
);
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPaths.Chat,
|
||||
filePaths.chat.chatBase(this.id),
|
||||
);
|
||||
};
|
||||
|
||||
readonly getInfoPath = (): string[] => {
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPaths.Chat,
|
||||
filePaths.chat.info(this.id),
|
||||
);
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPaths.Chat,
|
||||
filePaths.chat.info(this.id),
|
||||
);
|
||||
};
|
||||
|
||||
readonly getColorPath = (): string[] => {
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPaths.Chat,
|
||||
filePaths.chat.color(this.id),
|
||||
);
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPaths.Chat,
|
||||
filePaths.chat.color(this.id),
|
||||
);
|
||||
};
|
||||
|
||||
readonly getMessageDirPath = (): string[] => {
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPaths.Chat,
|
||||
filePaths.chat.messages(this.id),
|
||||
);
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPaths.Chat,
|
||||
filePaths.chat.messages(this.id),
|
||||
);
|
||||
};
|
||||
|
||||
readonly getMessagePath = (id: string): string[] => {
|
||||
return [...this.getMessageDirPath(), id];
|
||||
return [...this.getMessageDirPath(), id];
|
||||
};
|
||||
|
||||
readonly getReactionDirPath = (): string[] => {
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPaths.Chat,
|
||||
filePaths.chat.reactions(this.id),
|
||||
);
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPaths.Chat,
|
||||
filePaths.chat.reactions(this.id),
|
||||
);
|
||||
};
|
||||
readonly getReactionPath = (id: string): string[] => {
|
||||
return [...this.getReactionDirPath(), id];
|
||||
return [...this.getReactionDirPath(), id];
|
||||
};
|
||||
|
||||
readonly getPreviousFilterPath = (): string[] => {
|
||||
return [StorageModelSubPaths.Chat, ...filePaths.chat.previousFilter(this.id)];
|
||||
}
|
||||
return [
|
||||
StorageModelSubPaths.Chat,
|
||||
...filePaths.chat.previousFilter(this.id),
|
||||
];
|
||||
};
|
||||
|
||||
// handlers
|
||||
readonly handleMessage = (body: string): void => {
|
||||
const chatMessage: ChatMessage | null = parseValidObject(
|
||||
body,
|
||||
ChatMessageReference,
|
||||
);
|
||||
if (chatMessage == null) return;
|
||||
const chatMessage: ChatMessage | null = parseValidObject(
|
||||
body,
|
||||
ChatMessageReference,
|
||||
);
|
||||
if (chatMessage == null) return;
|
||||
|
||||
chatMessage.status = ChatMessageStatuses.Received;
|
||||
chatMessage.status = ChatMessageStatuses.Received;
|
||||
|
||||
this.addMessage(chatMessage);
|
||||
this.addMessage(chatMessage);
|
||||
|
||||
if (chatMessage.stringifiedFile) return;
|
||||
this.setReadStatus(true);
|
||||
if (chatMessage.stringifiedFile) return;
|
||||
this.setReadStatus(true);
|
||||
};
|
||||
|
||||
readonly handleReaction = (reaction: ChatMessageReaction | any): void => {
|
||||
if (
|
||||
!checkMatchesObjectStructure(reaction, ChatMessageReactionReference)
|
||||
)
|
||||
return;
|
||||
const reactionPath: string[] = this.getReactionPath(reaction.fileId);
|
||||
if (
|
||||
!checkMatchesObjectStructure(reaction, ChatMessageReactionReference)
|
||||
)
|
||||
return;
|
||||
const reactionPath: string[] = this.getReactionPath(reaction.fileId);
|
||||
|
||||
if (reaction.isDeleting == true) {
|
||||
this.storageModel.remove(reactionPath);
|
||||
} else {
|
||||
this.storageModel.writeStringifiable(reactionPath, reaction);
|
||||
}
|
||||
this.reactionHandlerManager.trigger(reaction);
|
||||
if (reaction.isDeleting == true) {
|
||||
this.storageModel.remove(reactionPath);
|
||||
} else {
|
||||
this.storageModel.writeStringifiable(reactionPath, reaction);
|
||||
}
|
||||
this.reactionHandlerManager.trigger(reaction);
|
||||
};
|
||||
|
||||
readonly handleMessageSent = (chatMessage: ChatMessage): void => {
|
||||
chatMessage.status = ChatMessageStatuses.Sent;
|
||||
this.addMessage(chatMessage);
|
||||
chatMessage.status = ChatMessageStatuses.Sent;
|
||||
this.addMessage(chatMessage);
|
||||
};
|
||||
|
||||
// settings
|
||||
readonly setName = (name: string): void => {
|
||||
this.info.name = name;
|
||||
this.storeInfo();
|
||||
this.syncInfo();
|
||||
this.subscribe();
|
||||
this.info.name = name;
|
||||
this.storeInfo();
|
||||
this.syncInfo();
|
||||
this.subscribe();
|
||||
};
|
||||
|
||||
readonly setSecondaryChannels = (secondaryChannels: string[]): void => {
|
||||
this.info.secondaryChannels = secondaryChannels;
|
||||
this.storeInfo();
|
||||
this.info.secondaryChannels = secondaryChannels;
|
||||
this.storeInfo();
|
||||
};
|
||||
|
||||
readonly setEncryptionKey = (key: string): void => {
|
||||
this.info.encryptionKey = key;
|
||||
this.storeInfo();
|
||||
this.info.encryptionKey = key;
|
||||
this.storeInfo();
|
||||
};
|
||||
|
||||
readonly setColor = (color: Colors): void => {
|
||||
this.info.color = color;
|
||||
this.syncInfo();
|
||||
this.storeInfo();
|
||||
this.info.color = color;
|
||||
this.syncInfo();
|
||||
this.storeInfo();
|
||||
};
|
||||
|
||||
// messaging
|
||||
readonly addMessage = async (chatMessage: ChatMessage): Promise<void> => {
|
||||
await this.decryptMessage(chatMessage);
|
||||
await this.decryptMessage(chatMessage);
|
||||
|
||||
// message
|
||||
if (chatMessage.body != "") {
|
||||
const messagePath: string[] = this.getMessagePath(chatMessage.id);
|
||||
this.storageModel.writeStringifiable(messagePath, chatMessage);
|
||||
this.chatMessageHandlerManager.trigger(chatMessage);
|
||||
}
|
||||
// message
|
||||
if (chatMessage.body != "") {
|
||||
const messagePath: string[] = this.getMessagePath(chatMessage.id);
|
||||
this.storageModel.writeStringifiable(messagePath, chatMessage);
|
||||
this.chatMessageHandlerManager.trigger(chatMessage);
|
||||
}
|
||||
|
||||
// file
|
||||
this.fileModel.handleStringifiedFileContent(
|
||||
chatMessage.stringifiedFile,
|
||||
);
|
||||
// file
|
||||
this.fileModel.handleStringifiedFileContent(
|
||||
chatMessage.stringifiedFile,
|
||||
);
|
||||
};
|
||||
|
||||
readonly getNameAndChannel = (): [string, string] | false => {
|
||||
const senderName: string = this.settingsModel.username;
|
||||
if (senderName == "") return false;
|
||||
const senderName: string = this.settingsModel.username;
|
||||
if (senderName == "") return false;
|
||||
|
||||
const allChannels: string[] = [this.id];
|
||||
for (const secondaryChannel of this.info.secondaryChannels) {
|
||||
allChannels.push(secondaryChannel);
|
||||
}
|
||||
const allChannels: string[] = [this.id];
|
||||
for (const secondaryChannel of this.info.secondaryChannels) {
|
||||
allChannels.push(secondaryChannel);
|
||||
}
|
||||
|
||||
const combinedChannel: string = allChannels.join("/");
|
||||
const combinedChannel: string = allChannels.join("/");
|
||||
|
||||
return [senderName, combinedChannel];
|
||||
return [senderName, combinedChannel];
|
||||
};
|
||||
|
||||
readonly sendMessage = async (
|
||||
body: string,
|
||||
inlineReplyId?: string,
|
||||
fileContent?: FileContent<string>,
|
||||
): Promise<string|false> => {
|
||||
const nameAndChannel = this.getNameAndChannel();
|
||||
if (nameAndChannel == false) return false;
|
||||
const [senderName, combinedChannel] = nameAndChannel;
|
||||
body: string,
|
||||
inlineReplyId?: string,
|
||||
fileContent?: FileContent<string>,
|
||||
): Promise<string | false> => {
|
||||
const nameAndChannel = this.getNameAndChannel();
|
||||
if (nameAndChannel == false) return false;
|
||||
const [senderName, combinedChannel] = nameAndChannel;
|
||||
|
||||
const chatMessage: ChatMessage = await ChatModel.createChatMessage(
|
||||
combinedChannel,
|
||||
senderName,
|
||||
this.info.encryptionKey,
|
||||
body,
|
||||
inlineReplyId,
|
||||
fileContent,
|
||||
);
|
||||
const chatMessage: ChatMessage = await ChatModel.createChatMessage(
|
||||
combinedChannel,
|
||||
senderName,
|
||||
this.info.encryptionKey,
|
||||
body,
|
||||
inlineReplyId,
|
||||
fileContent,
|
||||
);
|
||||
|
||||
this.addMessage(chatMessage);
|
||||
this.connectionModel.sendMessageOrStore(chatMessage);
|
||||
return chatMessage.id;
|
||||
this.addMessage(chatMessage);
|
||||
this.connectionModel.sendMessageOrStore(chatMessage);
|
||||
return chatMessage.id;
|
||||
};
|
||||
|
||||
readonly decryptMessage = async (
|
||||
chatMessage: ChatMessage,
|
||||
chatMessage: ChatMessage,
|
||||
): Promise<void> => {
|
||||
const decryptedBody: string = await decryptString(
|
||||
chatMessage.body,
|
||||
this.info.encryptionKey,
|
||||
);
|
||||
const decryptedFile: string = await decryptString(
|
||||
chatMessage.stringifiedFile ?? "",
|
||||
this.info.encryptionKey,
|
||||
);
|
||||
chatMessage.body = decryptedBody;
|
||||
chatMessage.stringifiedFile = decryptedFile;
|
||||
const decryptedBody: string = await decryptString(
|
||||
chatMessage.body,
|
||||
this.info.encryptionKey,
|
||||
);
|
||||
const decryptedFile: string = await decryptString(
|
||||
chatMessage.stringifiedFile ?? "",
|
||||
this.info.encryptionKey,
|
||||
);
|
||||
chatMessage.body = decryptedBody;
|
||||
chatMessage.stringifiedFile = decryptedFile;
|
||||
};
|
||||
|
||||
readonly sendReaction = async (
|
||||
messageId: string,
|
||||
content: ReactionSymbols,
|
||||
isDeleting: boolean = false,
|
||||
messageId: string,
|
||||
content: ReactionSymbols,
|
||||
isDeleting: boolean = false,
|
||||
): Promise<void> => {
|
||||
const nameAndChannel = this.getNameAndChannel();
|
||||
if (nameAndChannel == false) return;
|
||||
const [senderName] = nameAndChannel;
|
||||
const nameAndChannel = this.getNameAndChannel();
|
||||
if (nameAndChannel == false) return;
|
||||
const [senderName] = nameAndChannel;
|
||||
|
||||
const reaction = ChatModel.createMessageReaction(
|
||||
messageId,
|
||||
senderName,
|
||||
content,
|
||||
isDeleting,
|
||||
);
|
||||
this.sendMessage("", undefined, reaction);
|
||||
this.handleReaction(reaction);
|
||||
const reaction = ChatModel.createMessageReaction(
|
||||
messageId,
|
||||
senderName,
|
||||
content,
|
||||
isDeleting,
|
||||
);
|
||||
this.sendMessage("", undefined, reaction);
|
||||
this.handleReaction(reaction);
|
||||
};
|
||||
|
||||
readonly subscribe = (): void => {
|
||||
this.connectionModel.addChannel(this.id);
|
||||
this.connectionModel.addChannel(this.id);
|
||||
};
|
||||
|
||||
readonly setReadStatus = (hasUnreadMessages: boolean): void => {
|
||||
this.info.hasUnreadMessages = hasUnreadMessages;
|
||||
this.storeInfo();
|
||||
this.info.hasUnreadMessages = hasUnreadMessages;
|
||||
this.storeInfo();
|
||||
};
|
||||
|
||||
// storage
|
||||
readonly storeInfo = (): void => {
|
||||
this.storageModel.writeStringifiable(this.getInfoPath(), this.info);
|
||||
this.storageModel.writeStringifiable(this.getInfoPath(), this.info);
|
||||
};
|
||||
|
||||
readonly syncInfo = (): void => {
|
||||
this.sendMessage("", undefined, this.info);
|
||||
}
|
||||
this.sendMessage("", undefined, this.info);
|
||||
};
|
||||
|
||||
readonly storeFilter = (filter: string): void => {
|
||||
this.storageModel.write(this.getPreviousFilterPath(), filter);
|
||||
}
|
||||
this.storageModel.write(this.getPreviousFilterPath(), filter);
|
||||
};
|
||||
|
||||
readonly getFilter = (): string=> {
|
||||
return this.storageModel.read(this.getPreviousFilterPath()) || "";
|
||||
}
|
||||
readonly getFilter = (): string => {
|
||||
return this.storageModel.read(this.getPreviousFilterPath()) || "";
|
||||
};
|
||||
|
||||
readonly delete = () => {
|
||||
// untrack
|
||||
this.chatListModel.untrackChat(this);
|
||||
// untrack
|
||||
this.chatListModel.untrackChat(this);
|
||||
|
||||
// delete
|
||||
const dirPath: string[] = this.getBasePath();
|
||||
this.storageModel.removeRecursively(dirPath);
|
||||
// delete
|
||||
const dirPath: string[] = this.getBasePath();
|
||||
this.storageModel.removeRecursively(dirPath);
|
||||
};
|
||||
|
||||
// load
|
||||
readonly loadInfo = (): void => {
|
||||
let info: ChatInfoFileContent | null = this.storageModel.readStringifiable(
|
||||
this.getInfoPath(),
|
||||
ChatInfoReference,
|
||||
);
|
||||
this.info = (info || ChatModel.generateChatInfo("0", "0", Colors.Standard));
|
||||
this.storeInfo();
|
||||
let info: ChatInfoFileContent | null =
|
||||
this.storageModel.readStringifiable(
|
||||
this.getInfoPath(),
|
||||
ChatInfoReference,
|
||||
);
|
||||
this.info =
|
||||
info || ChatModel.generateChatInfo("0", "0", Colors.Standard);
|
||||
this.storeInfo();
|
||||
};
|
||||
|
||||
readonly handleInfo = (info: ChatInfoFileContent): void => {
|
||||
this.info = info;
|
||||
this.changeHandlerManager.trigger(null);
|
||||
this.storeInfo();
|
||||
}
|
||||
this.info = info;
|
||||
this.changeHandlerManager.trigger(null);
|
||||
this.storeInfo();
|
||||
};
|
||||
|
||||
get messages(): ChatMessage[] {
|
||||
const messageIds: string[] = this.storageModel.list(
|
||||
this.getMessageDirPath(),
|
||||
);
|
||||
if (!Array.isArray(messageIds)) return [];
|
||||
const messageIds: string[] = this.storageModel.list(
|
||||
this.getMessageDirPath(),
|
||||
);
|
||||
if (!Array.isArray(messageIds)) return [];
|
||||
|
||||
const chatMessages: ChatMessage[] = [];
|
||||
for (const messageId of messageIds) {
|
||||
const messagePath: string[] = this.getMessagePath(messageId);
|
||||
const chatMessage: ChatMessage | null =
|
||||
this.storageModel.readStringifiable(
|
||||
messagePath,
|
||||
ChatMessageReference,
|
||||
);
|
||||
if (chatMessage == null) continue;
|
||||
chatMessages.push(chatMessage);
|
||||
}
|
||||
const chatMessages: ChatMessage[] = [];
|
||||
for (const messageId of messageIds) {
|
||||
const messagePath: string[] = this.getMessagePath(messageId);
|
||||
const chatMessage: ChatMessage | null =
|
||||
this.storageModel.readStringifiable(
|
||||
messagePath,
|
||||
ChatMessageReference,
|
||||
);
|
||||
if (chatMessage == null) continue;
|
||||
chatMessages.push(chatMessage);
|
||||
}
|
||||
|
||||
const sorted = chatMessages.sort((a, b) =>
|
||||
a.dateSent.localeCompare(b.dateSent),
|
||||
);
|
||||
return sorted;
|
||||
const sorted = chatMessages.sort((a, b) =>
|
||||
a.dateSent.localeCompare(b.dateSent),
|
||||
);
|
||||
return sorted;
|
||||
}
|
||||
|
||||
get reactions(): ChatMessageReaction[] {
|
||||
const reactionIds: string[] = this.storageModel.list(
|
||||
this.getReactionDirPath(),
|
||||
);
|
||||
if (!Array.isArray(reactionIds)) return [];
|
||||
const reactionIds: string[] = this.storageModel.list(
|
||||
this.getReactionDirPath(),
|
||||
);
|
||||
if (!Array.isArray(reactionIds)) return [];
|
||||
|
||||
const reactions: ChatMessageReaction[] = [];
|
||||
for (const reactionId of reactionIds) {
|
||||
const reactionPath: string[] = this.getReactionPath(reactionId);
|
||||
const reaction: ChatMessageReaction | null =
|
||||
this.storageModel.readStringifiable(
|
||||
reactionPath,
|
||||
ChatMessageReactionReference,
|
||||
);
|
||||
if (reaction == null) continue;
|
||||
reactions.push(reaction);
|
||||
}
|
||||
const reactions: ChatMessageReaction[] = [];
|
||||
for (const reactionId of reactionIds) {
|
||||
const reactionPath: string[] = this.getReactionPath(reactionId);
|
||||
const reaction: ChatMessageReaction | null =
|
||||
this.storageModel.readStringifiable(
|
||||
reactionPath,
|
||||
ChatMessageReactionReference,
|
||||
);
|
||||
if (reaction == null) continue;
|
||||
reactions.push(reaction);
|
||||
}
|
||||
|
||||
return reactions;
|
||||
return reactions;
|
||||
}
|
||||
|
||||
// init
|
||||
constructor(
|
||||
storageModel: StorageModel,
|
||||
connectionModel: ConnectionModel,
|
||||
settingsModel: SettingsModel,
|
||||
chatListModel: ChatListModel,
|
||||
chatId: string,
|
||||
storageModel: StorageModel,
|
||||
connectionModel: ConnectionModel,
|
||||
settingsModel: SettingsModel,
|
||||
chatListModel: ChatListModel,
|
||||
chatId: string,
|
||||
) {
|
||||
this.id = chatId;
|
||||
this.connectionModel = connectionModel;
|
||||
this.settingsModel = settingsModel;
|
||||
this.storageModel = storageModel;
|
||||
this.chatListModel = chatListModel;
|
||||
this.id = chatId;
|
||||
this.connectionModel = connectionModel;
|
||||
this.settingsModel = settingsModel;
|
||||
this.storageModel = storageModel;
|
||||
this.chatListModel = chatListModel;
|
||||
|
||||
this.loadInfo();
|
||||
this.subscribe();
|
||||
this.loadInfo();
|
||||
this.subscribe();
|
||||
|
||||
this.fileModel = new FileModel(
|
||||
this.storageModel,
|
||||
this.settingsModel,
|
||||
this,
|
||||
);
|
||||
this.fileModel = new FileModel(
|
||||
this.storageModel,
|
||||
this.settingsModel,
|
||||
this,
|
||||
);
|
||||
}
|
||||
|
||||
// utility
|
||||
static splitChannel(channelString: string): string[] {
|
||||
return channelString.split("/");
|
||||
return channelString.split("/");
|
||||
}
|
||||
|
||||
static generateChatInfo = (name: string, id: string, color: Colors): ChatInfoFileContent => {
|
||||
const file = FileModel.createFileContent(id, "chat-info");
|
||||
static generateChatInfo = (
|
||||
name: string,
|
||||
id: string,
|
||||
color: Colors,
|
||||
): ChatInfoFileContent => {
|
||||
const file = FileModel.createFileContent(id, "chat-info");
|
||||
|
||||
return {
|
||||
...file,
|
||||
return {
|
||||
...file,
|
||||
|
||||
name,
|
||||
secondaryChannels: [],
|
||||
encryptionKey: "",
|
||||
color,
|
||||
hasUnreadMessages: false,
|
||||
};
|
||||
name,
|
||||
secondaryChannels: [],
|
||||
encryptionKey: "",
|
||||
color,
|
||||
hasUnreadMessages: false,
|
||||
};
|
||||
};
|
||||
|
||||
static createChatMessage = async (
|
||||
channel: string,
|
||||
sender: string,
|
||||
encryptionKey: string,
|
||||
body: string,
|
||||
inlineReplyId?: string,
|
||||
fileContent?: FileContent<string>,
|
||||
channel: string,
|
||||
sender: string,
|
||||
encryptionKey: string,
|
||||
body: string,
|
||||
inlineReplyId?: string,
|
||||
fileContent?: FileContent<string>,
|
||||
): Promise<ChatMessage> => {
|
||||
const chatMessage: ChatMessage = {
|
||||
dataVersion: DATA_VERSION,
|
||||
const chatMessage: ChatMessage = {
|
||||
dataVersion: DATA_VERSION,
|
||||
|
||||
id: v4(),
|
||||
id: v4(),
|
||||
|
||||
channel,
|
||||
sender,
|
||||
body,
|
||||
dateSent: createTimestamp(),
|
||||
inlineReplyId,
|
||||
channel,
|
||||
sender,
|
||||
body,
|
||||
dateSent: createTimestamp(),
|
||||
inlineReplyId,
|
||||
|
||||
status: ChatMessageStatuses.Outbox,
|
||||
stringifiedFile: "",
|
||||
};
|
||||
if (fileContent != undefined) {
|
||||
const stringifiedFile: string = stringify(fileContent);
|
||||
chatMessage.stringifiedFile = stringifiedFile;
|
||||
}
|
||||
status: ChatMessageStatuses.Outbox,
|
||||
stringifiedFile: "",
|
||||
};
|
||||
if (fileContent != undefined) {
|
||||
const stringifiedFile: string = stringify(fileContent);
|
||||
chatMessage.stringifiedFile = stringifiedFile;
|
||||
}
|
||||
|
||||
if (encryptionKey != "") {
|
||||
chatMessage.body = await encryptString(
|
||||
chatMessage.body,
|
||||
encryptionKey,
|
||||
);
|
||||
chatMessage.stringifiedFile = await encryptString(
|
||||
chatMessage.stringifiedFile,
|
||||
encryptionKey,
|
||||
);
|
||||
}
|
||||
if (encryptionKey != "") {
|
||||
chatMessage.body = await encryptString(
|
||||
chatMessage.body,
|
||||
encryptionKey,
|
||||
);
|
||||
chatMessage.stringifiedFile = await encryptString(
|
||||
chatMessage.stringifiedFile,
|
||||
encryptionKey,
|
||||
);
|
||||
}
|
||||
|
||||
return chatMessage;
|
||||
return chatMessage;
|
||||
};
|
||||
|
||||
static createMessageReaction = (
|
||||
messageId: string,
|
||||
sender: string,
|
||||
content: ReactionSymbols,
|
||||
isDeleting: boolean,
|
||||
messageId: string,
|
||||
sender: string,
|
||||
content: ReactionSymbols,
|
||||
isDeleting: boolean,
|
||||
): ChatMessageReaction => {
|
||||
const fileContent: FileContent<"reaction"> =
|
||||
FileModel.createFileContent(v4(), "reaction");
|
||||
const reaction: ChatMessageReaction = {
|
||||
...fileContent,
|
||||
fileId: ChatModel.createMessageReactionId(messageId, sender),
|
||||
const fileContent: FileContent<"reaction"> =
|
||||
FileModel.createFileContent(v4(), "reaction");
|
||||
const reaction: ChatMessageReaction = {
|
||||
...fileContent,
|
||||
fileId: ChatModel.createMessageReactionId(messageId, sender),
|
||||
|
||||
messageId,
|
||||
sender,
|
||||
content,
|
||||
isDeleting,
|
||||
};
|
||||
return reaction;
|
||||
messageId,
|
||||
sender,
|
||||
content,
|
||||
isDeleting,
|
||||
};
|
||||
return reaction;
|
||||
};
|
||||
|
||||
static createMessageReactionId = (
|
||||
messageId: string,
|
||||
sender: string,
|
||||
messageId: string,
|
||||
sender: string,
|
||||
): string => {
|
||||
return messageId + sender;
|
||||
return messageId + sender;
|
||||
};
|
||||
}
|
||||
|
||||
// types
|
||||
export enum ReactionSymbols {
|
||||
ThumbsUp = "👍",
|
||||
Check = "✅",
|
||||
Stop = "🛑",
|
||||
Attention = "❗️",
|
||||
DoubleAttention = "‼️",
|
||||
Question = "❓",
|
||||
Check = "✅",
|
||||
Stop = "🛑",
|
||||
Attention = "❗️",
|
||||
DoubleAttention = "‼️",
|
||||
Question = "❓",
|
||||
}
|
||||
|
||||
export interface ChatInfoFileContent extends FileContent<"chat-info"> {
|
||||
@@ -478,9 +487,9 @@ export interface ChatInfoFileContent extends FileContent<"chat-info"> {
|
||||
|
||||
export enum ChatMessageStatuses {
|
||||
Outbox = "outbox",
|
||||
Sent = "sent",
|
||||
Received = "received",
|
||||
Other = "other",
|
||||
Sent = "sent",
|
||||
Received = "received",
|
||||
Other = "other",
|
||||
}
|
||||
|
||||
export interface ChatMessage extends ValidObject {
|
||||
@@ -498,7 +507,7 @@ export interface ChatMessage extends ValidObject {
|
||||
}
|
||||
|
||||
export interface ChatMessageReaction
|
||||
extends ValidObject, FileContent<"reaction"> {
|
||||
extends ValidObject, FileContent<"reaction"> {
|
||||
readonly messageId: string;
|
||||
readonly sender: string;
|
||||
readonly content: ReactionSymbols | string;
|
||||
@@ -552,4 +561,4 @@ export const ChatMessageReactionReference: ChatMessageReaction = {
|
||||
content: "",
|
||||
|
||||
isDeleting: false,
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user