2021-01-10 16:36:57 +00:00
|
|
|
import {ConnectionHandler} from "../../../ConnectionHandler";
|
2021-04-27 11:30:33 +00:00
|
|
|
import {EventHandler} from "tc-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";
|
2021-04-29 12:51:30 +00:00
|
|
|
import {AbstractConversationController, SelectedConversation} from "./AbstractConversationController";
|
2020-12-09 12:36:56 +00:00
|
|
|
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";
|
2021-04-29 12:51:30 +00:00
|
|
|
import {spawnModalChannelChat} from "tc-shared/ui/modal/channel-chat/Controller";
|
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
|
|
|
|
2021-01-22 12:34:43 +00:00
|
|
|
this.uiEvents.registerHandler(this, true);
|
2021-04-29 12:51:30 +00:00
|
|
|
this.uiEvents.on("action_popout_chat", () => {
|
|
|
|
const conversation = this.getCurrentConversation();
|
|
|
|
if(!conversation) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spawnModalChannelChat(this.connection, conversation);
|
|
|
|
});
|
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());
|
2021-04-29 12:51:30 +00:00
|
|
|
this.setSelectedConversation("conversation-manager-selected");
|
2020-12-09 19:44:33 +00:00
|
|
|
} else {
|
|
|
|
this.setConversationManager(undefined);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 12:51:30 +00:00
|
|
|
setSelectedConversation(conversation: SelectedConversation<ChannelConversation>) {
|
|
|
|
super.setSelectedConversation(conversation);
|
|
|
|
}
|
|
|
|
|
2020-12-09 19:44:33 +00:00
|
|
|
@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);
|
|
|
|
}
|
|
|
|
|
2021-04-29 12:51:30 +00:00
|
|
|
protected registerConversationEvents(conversation: ChannelConversation): (() => void)[] {
|
|
|
|
const events = super.registerConversationEvents(conversation);
|
2020-12-09 13:22:22 +00:00
|
|
|
|
2021-04-29 12:51:30 +00:00
|
|
|
events.push(conversation.events.on("notify_messages_deleted", event => {
|
2020-12-09 12:36:56 +00:00
|
|
|
this.uiEvents.fire_react("notify_chat_message_delete", { messageIds: event.messages, chatId: conversation.getChatId() });
|
|
|
|
}));
|
2020-12-09 13:22:22 +00:00
|
|
|
|
2021-04-29 12:51:30 +00:00
|
|
|
events.push(conversation.events.on("notify_conversation_mode_changed", () => {
|
2020-12-09 13:22:22 +00:00
|
|
|
this.reportStateToUI(conversation);
|
|
|
|
}));
|
2021-04-29 12:51:30 +00:00
|
|
|
|
|
|
|
return events;
|
2020-12-09 12:36:56 +00:00
|
|
|
}
|
|
|
|
}
|