2021-01-10 16:36:57 +00:00
|
|
|
import {ConnectionHandler} from "../../../ConnectionHandler";
|
2020-12-09 12:36:56 +00:00
|
|
|
import {EventHandler} from "../../../events";
|
2021-01-10 16:36:57 +00:00
|
|
|
import {LogCategory, logError} from "../../../log";
|
2020-12-09 12:36:56 +00:00
|
|
|
import {tr} from "../../../i18n/localize";
|
2020-12-09 19:44:33 +00:00
|
|
|
import {AbstractConversationUiEvents} from "./AbstractConversationDefinitions";
|
2020-12-09 12:36:56 +00:00
|
|
|
import {AbstractConversationController} from "./AbstractConversationController";
|
|
|
|
import {
|
2020-12-09 13:22:22 +00:00
|
|
|
ChannelConversation,
|
|
|
|
ChannelConversationEvents,
|
2020-12-09 12:36:56 +00:00
|
|
|
ChannelConversationManager,
|
|
|
|
ChannelConversationManagerEvents
|
|
|
|
} from "tc-shared/conversations/ChannelConversationManager";
|
2020-12-09 19:44:33 +00:00
|
|
|
import {ChannelConversationUiEvents} from "tc-shared/ui/frames/side/ChannelConversationDefinitions";
|
2020-12-09 12:36:56 +00:00
|
|
|
|
|
|
|
export class ChannelConversationController extends AbstractConversationController<
|
2020-12-09 19:44:33 +00:00
|
|
|
ChannelConversationUiEvents,
|
2020-12-09 12:36:56 +00:00
|
|
|
ChannelConversationManager,
|
|
|
|
ChannelConversationManagerEvents,
|
|
|
|
ChannelConversation,
|
|
|
|
ChannelConversationEvents
|
|
|
|
> {
|
2020-12-09 19:44:33 +00:00
|
|
|
private connection: ConnectionHandler;
|
|
|
|
private connectionListener: (() => void)[];
|
2020-12-09 12:36:56 +00:00
|
|
|
|
2020-12-09 19:44:33 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.connectionListener = [];
|
2020-12-09 12:36:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
spawnExternalModal("conversation", this.uiEvents, {
|
|
|
|
handlerId: this.connection.handlerId,
|
|
|
|
noFirstMessageOverlay: false,
|
|
|
|
messagesDeletable: true
|
|
|
|
}).open().then(() => {
|
|
|
|
console.error("Opened");
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
|
2021-01-22 12:34:43 +00:00
|
|
|
this.uiEvents.registerHandler(this, true);
|
2020-12-09 19:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
this.connectionListener.forEach(callback => callback());
|
|
|
|
this.connectionListener = [];
|
|
|
|
|
2021-01-22 12:34:43 +00:00
|
|
|
this.uiEvents.unregisterHandler(this);
|
2020-12-09 19:44:33 +00:00
|
|
|
super.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
setConnectionHandler(connection: ConnectionHandler) {
|
|
|
|
if(this.connection === connection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.connectionListener.forEach(callback => callback());
|
|
|
|
this.connectionListener = [];
|
|
|
|
|
|
|
|
this.connection = connection;
|
|
|
|
if(connection) {
|
|
|
|
/* FIXME: Update cross channel talk state! */
|
|
|
|
this.setConversationManager(connection.getChannelConversations());
|
|
|
|
} else {
|
|
|
|
this.setConversationManager(undefined);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler<AbstractConversationUiEvents>("action_delete_message")
|
|
|
|
private handleMessageDelete(event: AbstractConversationUiEvents["action_delete_message"]) {
|
|
|
|
const conversation = this.conversationManager?.findConversationById(event.chatId);
|
2020-12-09 12:36:56 +00:00
|
|
|
if(!conversation) {
|
2021-01-10 16:36:57 +00:00
|
|
|
logError(LogCategory.CLIENT, tr("Tried to delete a chat message from an unknown conversation with id %s"), event.chatId);
|
2020-12-09 12:36:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation.deleteMessage(event.uniqueId);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected registerConversationEvents(conversation: ChannelConversation) {
|
|
|
|
super.registerConversationEvents(conversation);
|
2020-12-09 13:22:22 +00:00
|
|
|
|
2020-12-09 12:36:56 +00:00
|
|
|
this.currentSelectedListener.push(conversation.events.on("notify_messages_deleted", event => {
|
|
|
|
this.uiEvents.fire_react("notify_chat_message_delete", { messageIds: event.messages, chatId: conversation.getChatId() });
|
|
|
|
}));
|
2020-12-09 13:22:22 +00:00
|
|
|
|
|
|
|
this.currentSelectedListener.push(conversation.events.on("notify_conversation_mode_changed", () => {
|
|
|
|
this.reportStateToUI(conversation);
|
|
|
|
}));
|
2020-12-09 12:36:56 +00:00
|
|
|
}
|
|
|
|
}
|