add basic thread view
This commit is contained in:
@@ -2,6 +2,7 @@ import StorageModel, { storageKeys } from "./storageModel";
|
||||
|
||||
import { ChatModel } from "./chatModel";
|
||||
import ConnectionModel from "./connectionModel";
|
||||
import { Message } from "udn-frontend";
|
||||
import SettingsModel from "./settingsModel";
|
||||
import { localeCompare } from "./Utility/utility";
|
||||
import { v4 } from "uuid";
|
||||
@@ -15,6 +16,23 @@ export default class ChatListModel {
|
||||
chatModels = new Set<ChatModel>();
|
||||
sortedPrimaryChannels: string[] = [];
|
||||
|
||||
// handlers
|
||||
messageHandler = (data: Message): void => {
|
||||
for (const chatModel of this.chatModels) {
|
||||
const channel: string | undefined = data.messageChannel;
|
||||
const body: string | undefined = data.messageBody;
|
||||
if (channel == undefined) return;
|
||||
if (body == undefined) return;
|
||||
|
||||
const allChannels = channel.split("/");
|
||||
for (const channel of allChannels) {
|
||||
if (channel != chatModel.info.primaryChannel) continue;
|
||||
chatModel.handleMessage(channel, body);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// store & add
|
||||
addChatModel = (chatModel: ChatModel) => {
|
||||
this.chatModels.add(chatModel);
|
||||
@@ -57,7 +75,7 @@ export default class ChatListModel {
|
||||
getIndexOfPrimaryChannel(primaryChannel: string): number {
|
||||
return this.sortedPrimaryChannels.indexOf(primaryChannel);
|
||||
}
|
||||
|
||||
|
||||
// restore
|
||||
loadChats = (): void => {
|
||||
const chatDir = storageKeys.chats;
|
||||
@@ -75,10 +93,16 @@ export default class ChatListModel {
|
||||
};
|
||||
|
||||
// init
|
||||
constructor(storageModel: StorageModel, settingsModel: SettingsModel, connectionModel: ConnectionModel) {
|
||||
constructor(
|
||||
storageModel: StorageModel,
|
||||
settingsModel: SettingsModel,
|
||||
connectionModel: ConnectionModel
|
||||
) {
|
||||
this.storageModel = storageModel;
|
||||
this.settingsModel = settingsModel;
|
||||
this.connectionModel = connectionModel;
|
||||
this.loadChats();
|
||||
|
||||
connectionModel.setMessageHandler(this.messageHandler);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user