[polari] chatView: Linkify channel names
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] chatView: Linkify channel names
- Date: Sat, 27 Feb 2016 01:00:52 +0000 (UTC)
commit 0b101034a4e662a67498b9977d1cb20bdfcc3fcc
Author: Florian Müllner <fmuellner gnome org>
Date: Sun Feb 7 16:18:12 2016 +0100
chatView: Linkify channel names
Now that we handle irc:// links, it makes sense to turn mentions
of #channel-names into clickable links to assist the user in joining
the mentioned channel, provided the channel is on the same network.
https://bugzilla.gnome.org/show_bug.cgi?id=762673
src/chatView.js | 11 ++++++++---
src/utils.js | 10 ++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 8e0a0b2..f441031 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -1194,8 +1194,12 @@ const ChatView = new Lang.Class({
if (message.shouldHighlight)
tags.push(this._lookupTag('highlight'));
+ let params = this._room.account.dup_parameters_vardict().deep_unpack();
+ let server = params.server.deep_unpack();
+
let text = message.text;
- let urls = Utils.findUrls(text);
+ let channels = Utils.findChannels(text, server);
+ let urls = Utils.findUrls(text).concat(channels).sort((u1,u2) => u1.pos - u2.pos);
let pos = 0;
for (let i = 0; i < urls.length; i++) {
let url = urls[i];
@@ -1204,10 +1208,11 @@ const ChatView = new Lang.Class({
let tag = this._createUrlTag(url.url);
this._view.get_buffer().tag_table.add(tag);
- this._insertWithTags(iter, url.url,
+ let name = url.name ? url.name : url.url;
+ this._insertWithTags(iter, name,
tags.concat(this._lookupTag('url'), tag));
- pos = url.pos + url.url.length;
+ pos = url.pos + name.length;
}
this._insertWithTags(iter, text.substr(pos), tags);
},
diff --git a/src/utils.js b/src/utils.js
index 2c63918..edb9e5d 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -73,6 +73,7 @@ const _urlRegexp = new RegExp(
')' +
')', 'gi');
+const _channelRegexp = new RegExp('(^| )#([\\w\\+\\.-]+)','g');
let debugInit = false;
let debugEnabled = false;
@@ -162,6 +163,15 @@ function findUrls(str) {
return res;
}
+function findChannels(str, server) {
+ let res = [], match;
+ while ((match = _channelRegexp.exec(str)))
+ res.push({ url: 'irc://%s/%s'.format(server, match[2]),
+ name: '#' + match[2],
+ pos: match.index + match[1].length });
+ return res;
+}
+
function openURL(url, timestamp) {
let ctx = Gdk.Display.get_default().get_app_launch_context();
ctx.set_timestamp(timestamp);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]