From c6e1e287137907d9fbbefb5d682c9d9caa99c314 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 12 Aug 2018 19:46:40 +0200 Subject: [PATCH] Added channel description bbcode --- .gitmodules | 3 +++ index.php | 1 + js/ui/channel.ts | 27 ++++++++++++++++++++++++++- js/ui/frames/SelectedItemInfo.ts | 17 +++++++++++++++++ templates.html | 2 -- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 281318a1..132f34bd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,3 +8,6 @@ [submodule "asm/libraries/tommath"] path = asm/libraries/tommath url = http://git.mcgalaxy.de:8090/WolverinDEV/tommath.git +[submodule "vendor/bbcode"] + path = vendor/bbcode + url = https://github.com/WolverinDEV/Extendible-BBCode-Parser.git diff --git a/index.php b/index.php index 49f3fc12..ec6756f1 100644 --- a/index.php +++ b/index.php @@ -40,6 +40,7 @@ + diff --git a/js/ui/channel.ts b/js/ui/channel.ts index 5fa4d5d4..22fc12da 100644 --- a/js/ui/channel.ts +++ b/js/ui/channel.ts @@ -20,7 +20,6 @@ class ChannelProperties { channel_topic: string = ""; channel_password: string = ""; - channel_description: string = ""; channel_codec: number = 4; channel_codec_quality: number = 0; @@ -60,6 +59,10 @@ class ChannelEntry { private _tag_channel: JQuery; private _cachedPassword: string; + private _cached_channel_description: string = undefined; + private _cached_channel_description_promise: Promise = undefined; + private _cached_channel_description_promise_resolve: any = undefined; + private _cached_channel_description_promise_reject: any = undefined; constructor(channelId, channelName, parent = null, prevChannel = null) { this.properties = new ChannelProperties(); @@ -81,6 +84,20 @@ class ChannelEntry { return this._formatedChannelName ? this._formatedChannelName : this.properties.channel_name; } + getChannelDescription() : Promise { + if(this._cached_channel_description) return new Promise(resolve => resolve(this._cached_channel_description)); + if(this._cached_channel_description_promise) return this._cached_channel_description_promise; + + this.channelTree.client.serverConnection.sendCommand("channelgetdescription", {cid: this.channelId}).catch(error => { + this._cached_channel_description_promise_reject(error); + }); + + return this._cached_channel_description_promise = new Promise((resolve, reject) => { + this._cached_channel_description_promise_resolve = resolve; + this._cached_channel_description_promise_reject = reject; + }); + } + parentChannel() { return this.parent; } hasParent(){ return this.parent != null; } getChannelId(){ return this.channelId; } @@ -461,6 +478,14 @@ class ChannelEntry { (this.properties.channel_flag_password ? $.fn.show : $.fn.hide).apply(this.channelTag().find(".icons .icon_password")); else if(key == "channel_needed_talk_power") (this.properties.channel_needed_talk_power > 0 ? $.fn.show : $.fn.hide).apply(this.channelTag().find(".icons .icon_moderated")); + else if(key == "channel_description") { + this._cached_channel_description = undefined; + if(this._cached_channel_description_promise_resolve) + this._cached_channel_description_promise_resolve(value); + this._cached_channel_description_promise = undefined; + this._cached_channel_description_promise_resolve = undefined; + this._cached_channel_description_promise_reject = undefined; + } if(key == "channel_maxclients" || key == "channel_maxfamilyclients" || key == "channel_flag_private" || key == "channel_flag_password") this.updateChannelTypeIcon(); } diff --git a/js/ui/frames/SelectedItemInfo.ts b/js/ui/frames/SelectedItemInfo.ts index f8bb23da..5775949b 100644 --- a/js/ui/frames/SelectedItemInfo.ts +++ b/js/ui/frames/SelectedItemInfo.ts @@ -1,4 +1,5 @@ /// +/// abstract class InfoManagerBase { private timers: NodeJS.Timer[] = []; @@ -244,6 +245,22 @@ class ChannelInfoManager extends InfoManager { for(let key in channel.properties) properties["property_" + key] = channel.properties[key]; + let tag_channel_description = $.spawn("div"); + properties["bbcode_channel_description"] = tag_channel_description; + + channel.getChannelDescription().then(description => { + let result = XBBCODE.process({ + text: description, + escapeHtml: true, + addInLineBreaks: true + }); + if(result.error) { + console.log("BBCode parse error: %o", result.errorQueue); + } + + tag_channel_description.html(result.html); + }); + let rendered = $("#tmpl_selected_channel").renderTag([properties]); rendered.find("node").each((index, element) => { $(element).replaceWith(properties[$(element).attr("key")]); }); html_tag.append(rendered); diff --git a/templates.html b/templates.html index a621b749..b1529cdf 100644 --- a/templates.html +++ b/templates.html @@ -701,11 +701,9 @@ - {{if property_channel_description }}
- {{/if}} \ No newline at end of file