# HG changeset patch
# Node ID 33a7f302f6f410f2802b13c4a87554884cea6d49
# Parent  26d30c0db9a56c80ac1e6f5766cd01c56edeb69b
diff --git a/im.pidgin.Pidgin3.yml b/im.pidgin.Pidgin3.yml
--- a/im.pidgin.Pidgin3.yml
+++ b/im.pidgin.Pidgin3.yml
@@ -63,8 +63,8 @@
     sources:
       - type: archive
         archive-type: tar-xz
-        url: https://sourceforge.net/projects/pidgin/files/ibis/0.8.2/ibis-0.8.2.tar.xz/download
-        sha256: cd5c5fdfed9912baa56f8219b7839ca165480b993d362cbda4be4c2fdc627c91
+        url: https://sourceforge.net/projects/pidgin/files/ibis/0.9.0/ibis-0.9.0.tar.xz/download
+        sha256: 43251c44fc97205804fd28b79b355ff27659f172a7b542de24aa596cbde3d852
   - name: xeme
     buildsystem: meson
     config-opts:
diff --git a/protocols/ircv3/meson.build b/protocols/ircv3/meson.build
--- a/protocols/ircv3/meson.build
+++ b/protocols/ircv3/meson.build
@@ -20,7 +20,7 @@
 	subdir_done()
 endif
 
-ibis_dep = dependency('ibis', version : '>= 0.8.2')
+ibis_dep = dependency('ibis', version : '>= 0.9.0')
 
 ircv3_filebase = f'purple-@purple_api_major_version@-ircv3'
 ircv3_filebase = f'purple-@purple_api_major_version@-ircv3'
diff --git a/protocols/ircv3/purpleircv3connection.c b/protocols/ircv3/purpleircv3connection.c
--- a/protocols/ircv3/purpleircv3connection.c
+++ b/protocols/ircv3/purpleircv3connection.c
@@ -476,6 +476,9 @@
 	g_signal_connect_object(client, "message::" IBIS_MSG_PART,
 	                        G_CALLBACK(purple_ircv3_message_handler_part),
 	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_MSG_NICK,
+	                        G_CALLBACK(purple_ircv3_message_handler_nick),
+	                        connection, G_CONNECT_DEFAULT);
 	g_signal_connect_object(client, "message::" IBIS_MSG_QUIT,
 	                        G_CALLBACK(purple_ircv3_message_handler_quit),
 	                        connection, G_CONNECT_DEFAULT);
diff --git a/protocols/ircv3/purpleircv3messagehandlers.c b/protocols/ircv3/purpleircv3messagehandlers.c
--- a/protocols/ircv3/purpleircv3messagehandlers.c
+++ b/protocols/ircv3/purpleircv3messagehandlers.c
@@ -555,3 +555,55 @@
 
 	return TRUE;
 }
+
+gboolean
+purple_ircv3_message_handler_nick(G_GNUC_UNUSED IbisClient *client,
+                                  G_GNUC_UNUSED const char *command,
+                                  IbisMessage *ibis_message,
+                                  gpointer data)
+{
+	PurpleIRCv3Connection *connection = data;
+	PurpleContact *contact = NULL;
+	PurpleContactInfo *info = NULL;
+	IbisTags *tags = NULL;
+	GStrv params = NULL;
+	guint n_params = 0;
+	char *new_source = NULL;
+	char *user = NULL;
+	char *host = NULL;
+	const char *source = NULL;
+	const char *nick = NULL;
+
+	params = ibis_message_get_params(ibis_message);
+	n_params = g_strv_length(params);
+
+	if(n_params != 1) {
+		g_message("received NICK with %d params, expected 1", n_params);
+		return FALSE;
+	}
+
+	nick = params[0];
+	source = ibis_message_get_source(ibis_message);
+	ibis_source_parse(source, NULL, &user, &host);
+	new_source = ibis_source_serialize(nick, user, host);
+	g_clear_pointer(&user, g_free);
+	g_clear_pointer(&host, g_free);
+
+	contact = purple_ircv3_connection_find_or_create_contact(connection,
+	                                                         ibis_message);
+	info = PURPLE_CONTACT_INFO(contact);
+
+	/* If the account tag doesn't exist, we need to update the id property of
+	 * the contact.
+	 */
+	tags = ibis_message_get_tags(ibis_message);
+	if(!ibis_tags_exists(tags, IBIS_TAG_ACCOUNT)) {
+		purple_contact_info_set_id(info, nick);
+	}
+
+	purple_contact_info_set_display_name(info, nick);
+	purple_contact_info_set_sid(info, new_source);
+	g_clear_pointer(&new_source, g_free);
+
+	return TRUE;
+}
diff --git a/protocols/ircv3/purpleircv3messagehandlers.h b/protocols/ircv3/purpleircv3messagehandlers.h
--- a/protocols/ircv3/purpleircv3messagehandlers.h
+++ b/protocols/ircv3/purpleircv3messagehandlers.h
@@ -45,6 +45,7 @@
 G_GNUC_INTERNAL gboolean purple_ircv3_message_handler_privmsg(IbisClient *client, const char *command, IbisMessage *message, gpointer data);
 G_GNUC_INTERNAL gboolean purple_ircv3_message_handler_topic(IbisClient *client, const char *command, IbisMessage *message, gpointer data);
 G_GNUC_INTERNAL gboolean purple_ircv3_message_handler_quit(IbisClient *client, const char *command, IbisMessage *message, gpointer data);
+G_GNUC_INTERNAL gboolean purple_ircv3_message_handler_nick(IbisClient *client, const char *command, IbisMessage *message, gpointer data);
 
 G_END_DECLS
 
diff --git a/subprojects/ibis.wrap b/subprojects/ibis.wrap
--- a/subprojects/ibis.wrap
+++ b/subprojects/ibis.wrap
@@ -1,4 +1,4 @@
 [wrap-hg]
 directory = ibis
 url = https://keep.imfreedom.org/ibis/ibis
-revision = v0.8.2
+revision = v0.9.0
