[polari/wip/fmuellner/nickserv: 53/62] room: Emit ::identify-sent signal when detecting authbot identification
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/fmuellner/nickserv: 53/62] room: Emit ::identify-sent signal when detecting authbot identification
- Date: Mon, 29 Aug 2016 12:21:27 +0000 (UTC)
commit c1918ee333798d95ef83812573ffb0321a33bd5f
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Aug 2 19:03:28 2016 +0200
room: Emit ::identify-sent signal when detecting authbot identification
We want to offer users that have their nickname registered with an
authbot like NickServ the option to store the password and handle
the identification automatically when connecting. For that we need
to detect the "identify" command sent to a bot first - asking the
user whether the password should be saved will be done differently
depending on whether the command is actually send from the room's
view or via a /msg command (or GNOME Shell's chat integration) instead,
so handling the detection in a shared component as the room itself
makes sense.
In the future we might want to hide authbot channels entirely from the
UI unless the user explicitly initiates the communication, in which
case the detection/signal would be better off in the channel. However
that would be more involved as it involves implementing a custom client
factor, so this should do for now ...
https://bugzilla.gnome.org/show_bug.cgi?id=709982
src/lib/polari-room.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/src/lib/polari-room.c b/src/lib/polari-room.c
index 84dbcbe..b82a07b 100644
--- a/src/lib/polari-room.c
+++ b/src/lib/polari-room.c
@@ -45,6 +45,7 @@ struct _PolariRoomPrivate {
guint self_contact_notify_id;
guint invalidated_id;
guint group_contacts_changed_id;
+ guint message_sent_id;
TpProxySignalConnection *properties_changed_id;
};
@@ -78,6 +79,8 @@ enum
MEMBERS_CHANGED,
+ IDENTIFY_SENT,
+
LAST_SIGNAL
};
@@ -85,6 +88,8 @@ static guint signals[LAST_SIGNAL];
static GRegex *color_code_regex = NULL;
+static GRegex *identify_message_regex = NULL;
+
G_DEFINE_TYPE_WITH_PRIVATE (PolariRoom, polari_room, G_TYPE_OBJECT)
static void polari_room_set_channel (PolariRoom *room, TpChannel *channel);
@@ -379,6 +384,42 @@ on_group_contacts_changed (TpChannel *channel,
}
static void
+on_message_sent (TpTextChannel *channel,
+ TpSignalledMessage *message,
+ guint flags,
+ char *token,
+ gpointer user_data)
+{
+ PolariRoom *room = user_data;
+ PolariRoomPrivate *priv = room->priv;
+ GMatchInfo *match;
+ char *text, *stripped_text;
+
+ if (priv->type != TP_HANDLE_TYPE_CONTACT)
+ return;
+
+ text = tp_message_to_text (TP_MESSAGE (message), NULL);
+ stripped_text = g_strstrip (text);
+
+ if (G_UNLIKELY (identify_message_regex == NULL))
+ identify_message_regex = g_regex_new ("^identify (?:(\\w+) )?(\\S+)$",
+ G_REGEX_OPTIMIZE, 0, NULL);
+ if (g_regex_match (identify_message_regex, stripped_text, 0, &match))
+ {
+ char *username = g_match_info_fetch (match, 1);
+ char *password = g_match_info_fetch (match, 2);
+
+ g_signal_emit (room, signals[IDENTIFY_SENT], 0, username, password);
+
+ g_free (username);
+ g_free (password);
+ }
+
+ g_match_info_free (match);
+ g_free (text);
+}
+
+static void
on_channel_invalidated (TpProxy *channel,
guint domain,
int code,
@@ -575,6 +616,7 @@ polari_room_set_channel (PolariRoom *room,
if (priv->channel)
{
g_signal_handler_disconnect (priv->channel, priv->group_contacts_changed_id);
+ g_signal_handler_disconnect (priv->channel, priv->message_sent_id);
g_signal_handler_disconnect( priv->channel, priv->invalidated_id);
g_signal_handler_disconnect (tp_channel_get_connection (priv->channel),
priv->self_contact_notify_id);
@@ -610,6 +652,9 @@ polari_room_set_channel (PolariRoom *room,
priv->group_contacts_changed_id =
g_signal_connect (channel, "group-contacts-changed",
G_CALLBACK (on_group_contacts_changed), room);
+ priv->message_sent_id =
+ g_signal_connect ( channel, "message-sent",
+ G_CALLBACK (on_message_sent), room);
priv->invalidated_id =
g_signal_connect (channel, "invalidated",
G_CALLBACK (on_channel_invalidated), room);
@@ -848,6 +893,14 @@ polari_room_class_init (PolariRoomClass *klass)
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
+
+ signals[IDENTIFY_SENT] =
+ g_signal_new ("identify-sent",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]