# HG changeset patch
# Node ID 3251340ea2da366f68a7562bd06d26d37a074dbe
# Parent  e6df74d36862dd5f35d5275b5456500ab6b5c7f1
diff --git a/protocols/ircv3/purpleircv3messagehandlers.c b/protocols/ircv3/purpleircv3messagehandlers.c
--- a/protocols/ircv3/purpleircv3messagehandlers.c
+++ b/protocols/ircv3/purpleircv3messagehandlers.c
@@ -60,6 +60,82 @@
 	return member;
 }
 
+static void
+purple_ircv3_add_badges_to_member(PurpleConversationMember *member,
+                                  IbisClient *client, const char *nick)
+{
+	PurpleBadgeManager *manager = NULL;
+	PurpleBadges *badges = NULL;
+	char *prefixes = NULL;
+	char *iter = NULL;
+
+	g_return_if_fail(PURPLE_IS_CONVERSATION_MEMBER(member));
+	g_return_if_fail(IBIS_IS_CLIENT(client));
+
+	badges = purple_conversation_member_get_badges(member);
+	manager = purple_badge_manager_get_default();
+	prefixes = ibis_client_get_source_prefix(client, nick);
+	iter = prefixes;
+
+	while(iter != NULL) {
+		PurpleBadge *badge = NULL;
+		const char *id = NULL;
+		const char *mnemonic = NULL;
+		int priority = 0;
+
+		switch(g_utf8_get_char(iter)) {
+		case '~':
+			id = "ircv3-badge-founder";
+			priority = 500;
+			mnemonic = "~";
+			break;
+		case '&':
+			id = "ircv3-badge-protected";
+			priority = 400;
+			mnemonic = "&";
+			break;
+		case '@':
+			id = "ircv3-badge-operator";
+			priority = 300;
+			mnemonic = "@";
+			break;
+		case '%':
+			id = "ircv3-badge-halfop";
+			priority = 200;
+			mnemonic = "%%";
+			break;
+		case '+':
+			id = "ircv3-badge-voice";
+			priority = 100;
+			mnemonic = "+";
+			break;
+		}
+
+		if(id == NULL) {
+			break;
+		}
+
+		badge = purple_badge_manager_find(manager, id);
+		if(!PURPLE_IS_BADGE(badge)) {
+			badge = purple_badge_new(id, priority, id, mnemonic);
+			purple_badge_manager_add(manager, badge);
+
+			/* The manager holds a reference but we need to ditch our reference
+			 * so we unref the instance and use the manager's reference.
+			 */
+			g_object_unref(badge);
+		}
+
+		purple_badges_add_badge(badges, badge);
+
+		g_clear_object(&badge);
+
+		iter = g_utf8_next_char(iter);
+	}
+
+	g_free(prefixes);
+}
+
 /******************************************************************************
  * General Commands
  *****************************************************************************/
@@ -227,6 +303,7 @@
 
 		for(guint i = 0; i < g_strv_length(nicks); i++) {
 			PurpleContact *contact = NULL;
+			PurpleConversationMember *member = NULL;
 			const char *nick = nicks[i];
 			char *stripped = NULL;
 
@@ -241,9 +318,12 @@
 				purple_contact_manager_add(manager, contact);
 			}
 
-			purple_conversation_members_add_member(members,
-			                                       PURPLE_CONTACT_INFO(contact),
-			                                       FALSE, NULL);
+			member = purple_conversation_members_add_member(members,
+			                                                PURPLE_CONTACT_INFO(contact),
+			                                                FALSE, NULL);
+
+			purple_ircv3_add_badges_to_member(member, client, nick);
+
 			g_free(stripped);
 		}
 	}
diff --git a/protocols/ircv3/resources/icons/64x64/status/ircv3-badge-founder.png b/protocols/ircv3/resources/icons/64x64/status/ircv3-badge-founder.png
new file mode 100644
index 0000000000000000000000000000000000000000..111c28bf02cbc0df0286fc1eab70b7071f647d0f
GIT binary patch
diff --git a/protocols/ircv3/resources/icons/64x64/status/ircv3-badge-halfop.png b/protocols/ircv3/resources/icons/64x64/status/ircv3-badge-halfop.png
new file mode 100644
index 0000000000000000000000000000000000000000..ddd2b90fe448779bbc848554228dde825959fc2a
GIT binary patch
diff --git a/protocols/ircv3/resources/icons/64x64/status/ircv3-badge-operator.png b/protocols/ircv3/resources/icons/64x64/status/ircv3-badge-operator.png
new file mode 100644
index 0000000000000000000000000000000000000000..7bac0b3530b189e032129d689182f8e860188d56
GIT binary patch
diff --git a/protocols/ircv3/resources/icons/64x64/status/ircv3-badge-protected.png b/protocols/ircv3/resources/icons/64x64/status/ircv3-badge-protected.png
new file mode 100644
index 0000000000000000000000000000000000000000..c4510cf781f7cc02cad848de98bacd124b5067fa
GIT binary patch
diff --git a/protocols/ircv3/resources/icons/64x64/status/ircv3-badge-voice.png b/protocols/ircv3/resources/icons/64x64/status/ircv3-badge-voice.png
new file mode 100644
index 0000000000000000000000000000000000000000..0811417374bf84b310a88ebb3272954076e2fb5a
GIT binary patch
diff --git a/protocols/ircv3/resources/icons/64x64/status/ircv3-badges.xcf b/protocols/ircv3/resources/icons/64x64/status/ircv3-badges.xcf
new file mode 100644
index 0000000000000000000000000000000000000000..73fa6163139fb62de58513669477d815c914acf8
GIT binary patch
diff --git a/protocols/ircv3/resources/ircv3.gresource.xml b/protocols/ircv3/resources/ircv3.gresource.xml
--- a/protocols/ircv3/resources/ircv3.gresource.xml
+++ b/protocols/ircv3/resources/ircv3.gresource.xml
@@ -4,5 +4,10 @@
     <file>icons/16x16/apps/im-ircv3.png</file>
     <file>icons/22x22/apps/im-ircv3.png</file>
     <file>icons/48x48/apps/im-ircv3.png</file>
+    <file>icons/64x64/status/ircv3-badge-founder.png</file>
+    <file>icons/64x64/status/ircv3-badge-halfop.png</file>
+    <file>icons/64x64/status/ircv3-badge-operator.png</file>
+    <file>icons/64x64/status/ircv3-badge-protected.png</file>
+    <file>icons/64x64/status/ircv3-badge-voice.png</file>
   </gresource>
 </gresources>
