Fixed bug that on channel tree deletion the channel tree gets not updated

canary
WolverinDEV 2020-06-11 10:47:25 +02:00
parent 9b77978f8e
commit f0ca5ff83f
4 changed files with 18 additions and 6 deletions

View File

@ -1,4 +1,7 @@
# Changelog:
* **11.06.20**
- Fixed channel tree deletions
* **10.06.20**
- Finalize the channel file explorer
- Reworked the file transfer system

View File

@ -488,9 +488,10 @@ export class ChannelEntry extends ChannelTreeEntry<ChannelEvents> {
name: tr("Delete channel"),
invalidPermission: !flagDelete,
callback: () => {
const client = this.channelTree.client;
this.channelTree.client.serverConnection.send_command("channeldelete", {cid: this.channelId}).then(() => {
this.channelTree.client.sound.play(Sound.CHANNEL_DELETED);
})
client.sound.play(Sound.CHANNEL_DELETED);
});
}
},
contextmenu.Entry.HR(),

View File

@ -17,6 +17,8 @@ import {ClientEntry as ClientEntryView} from "./Client";
import {ChannelEntry, ChannelEvents} from "tc-shared/ui/channel";
import {ServerEntry} from "tc-shared/ui/server";
import {ClientEntry, ClientType} from "tc-shared/ui/client";
import * as log from "tc-shared/log";
import {LogCategory} from "tc-shared/log";
const viewStyle = require("./View.scss");
@ -211,6 +213,7 @@ export class ChannelTreeView extends ReactComponentBase<ChannelTreeViewPropertie
}
private rebuild_tree() {
log.debug(LogCategory.CHANNEL, tr("Rebuilding the channel tree"));
const tree = this.props.tree;
{
let index = this.flat_tree.length;

View File

@ -208,6 +208,8 @@ export class ChannelTree {
constructor(client) {
this.events = new Registry<ChannelTreeEvents>();
this.events.enable_debug("channel-tree");
this.client = client;
this.view = React.createRef();
this.view_move = React.createRef();
@ -305,15 +307,15 @@ export class ChannelTree {
try {
if(!this.channels.remove(channel))
log.warn(LogCategory.CHANNEL, tr("Deleting an unknown channel!"));
channel.children(false).forEach(e => this.deleteChannel(e));
channel.children(false).forEach(e => this.deleteChannel(e));
if(channel.clients(false).length !== 0) {
log.warn(LogCategory.CHANNEL, tr("Deleting a non empty channel! This could cause some errors."));
for(const client of channel.clients(false))
this.deleteClient(client, false);
}
const is_root_tree = !!channel.parent;
const is_root_tree = !channel.parent;
this.unregisterChannelFromTree(channel);
if(is_root_tree) this.events.fire("notify_root_channel_changed");
} finally {
@ -345,14 +347,14 @@ export class ChannelTree {
}
private unregisterChannelFromTree(channel: ChannelEntry, new_parent?: ChannelEntry) {
let oldChannelParent;
if(channel.parent) {
if(channel.parent.child_channel_head === channel)
channel.parent.child_channel_head = channel.channel_next;
/* We need only trigger this once.
If the new parent is equal to the old one with applying the "new" parent this event will get triggered */
if(new_parent !== channel.parent)
channel.parent.events.fire("notify_children_changed");
oldChannelParent = channel.parent;
}
if(channel.channel_previous)
@ -370,6 +372,9 @@ export class ChannelTree {
channel.channel_next = undefined;
channel.channel_previous = undefined;
channel.parent = undefined;
if(oldChannelParent && oldChannelParent !== new_parent)
oldChannelParent.events.fire("notify_children_changed");
}
moveChannel(channel: ChannelEntry, channel_previous: ChannelEntry, parent: ChannelEntry) {