| 26 |
26 |
| 27 #include "purpleircv3connection.h" |
27 #include "purpleircv3connection.h" |
| 28 #include "purpleircv3core.h" |
28 #include "purpleircv3core.h" |
| 29 |
29 |
| 30 /****************************************************************************** |
30 /****************************************************************************** |
| |
31 * Helpers |
| |
32 *****************************************************************************/ |
| |
33 static void |
| |
34 purple_ircv3_add_contact_to_conversation(PurpleContact *contact, |
| |
35 PurpleConversation *conversation) |
| |
36 { |
| |
37 PurpleConversationMember *member = NULL; |
| |
38 |
| |
39 member = purple_conversation_find_member(conversation, |
| |
40 PURPLE_CONTACT_INFO(contact)); |
| |
41 |
| |
42 if(!PURPLE_IS_CONVERSATION_MEMBER(member)) { |
| |
43 purple_conversation_add_member(conversation, |
| |
44 PURPLE_CONTACT_INFO(contact), |
| |
45 TRUE, NULL); |
| |
46 } |
| |
47 } |
| |
48 |
| |
49 /****************************************************************************** |
| 31 * General Commands |
50 * General Commands |
| 32 *****************************************************************************/ |
51 *****************************************************************************/ |
| |
52 gboolean |
| |
53 purple_ircv3_message_handler_join(G_GNUC_UNUSED IbisClient *client, |
| |
54 G_GNUC_UNUSED const char *command, |
| |
55 IbisMessage *message, |
| |
56 gpointer data) |
| |
57 { |
| |
58 PurpleIRCv3Connection *connection = data; |
| |
59 PurpleContact *contact = NULL; |
| |
60 PurpleConversation *conversation = NULL; |
| |
61 GStrv params = NULL; |
| |
62 guint n_params = 0; |
| |
63 char *nick = NULL; |
| |
64 const char *source = NULL; |
| |
65 const char *conversation_name = NULL; |
| |
66 |
| |
67 source = ibis_message_get_source(message); |
| |
68 ibis_source_parse(source, &nick, NULL, NULL); |
| |
69 if(purple_strempty(nick)) { |
| |
70 /* We _shouldn't_ be able to get an empty nick, but just in case... */ |
| |
71 g_clear_pointer(&nick, g_free); |
| |
72 |
| |
73 /* TODO: write message about being unable to parse source to status |
| |
74 * window. |
| |
75 */ |
| |
76 |
| |
77 return TRUE; |
| |
78 } |
| |
79 |
| |
80 contact = purple_ircv3_connection_find_or_create_contact(connection, nick); |
| |
81 purple_contact_info_set_sid(PURPLE_CONTACT_INFO(contact), source); |
| |
82 |
| |
83 g_free(nick); |
| |
84 |
| |
85 params = ibis_message_get_params(message); |
| |
86 n_params = g_strv_length(params); |
| |
87 |
| |
88 /* A normal join command has the channel as the only parameter. */ |
| |
89 if(n_params == 1) { |
| |
90 conversation_name = params[0]; |
| |
91 } else { |
| |
92 /* TODO: write this to join to the status window saying we didn't know |
| |
93 * how to parse it. |
| |
94 */ |
| |
95 |
| |
96 return TRUE; |
| |
97 } |
| |
98 |
| |
99 conversation = purple_ircv3_connection_find_or_create_conversation(connection, |
| |
100 conversation_name); |
| |
101 purple_ircv3_add_contact_to_conversation(contact, conversation); |
| |
102 |
| |
103 return TRUE; |
| |
104 } |
| |
105 |
| |
106 gboolean |
| |
107 purple_ircv3_message_handler_part(G_GNUC_UNUSED IbisClient *client, |
| |
108 G_GNUC_UNUSED const char *command, |
| |
109 IbisMessage *message, |
| |
110 gpointer data) |
| |
111 { |
| |
112 PurpleIRCv3Connection *connection = data; |
| |
113 PurpleAccount *account = NULL; |
| |
114 PurpleContact *contact = NULL; |
| |
115 PurpleConversation *conversation = NULL; |
| |
116 PurpleConversationManager *manager = NULL; |
| |
117 GStrv params = NULL; |
| |
118 guint n_params = 0; |
| |
119 char *reason = NULL; |
| |
120 char *nick = NULL; |
| |
121 const char *conversation_name = NULL; |
| |
122 const char *source = NULL; |
| |
123 |
| |
124 params = ibis_message_get_params(message); |
| |
125 if(g_strv_length(params) == 0) { |
| |
126 /* TODO: mention unparsable message in the status window. */ |
| |
127 return TRUE; |
| |
128 } |
| |
129 |
| |
130 /* TODO: The spec says servers _SHOULD NOT_ send a comma separated list of |
| |
131 * channels, but we should support that at some point just in case. |
| |
132 */ |
| |
133 conversation_name = params[0]; |
| |
134 |
| |
135 account = purple_connection_get_account(PURPLE_CONNECTION(connection)); |
| |
136 manager = purple_conversation_manager_get_default(); |
| |
137 conversation = purple_conversation_manager_find_with_id(manager, account, |
| |
138 conversation_name); |
| |
139 |
| |
140 if(!PURPLE_IS_CONVERSATION(conversation)) { |
| |
141 /* TODO: write status message unknown channel. */ |
| |
142 |
| |
143 return TRUE; |
| |
144 } |
| |
145 |
| |
146 source = ibis_message_get_source(message); |
| |
147 ibis_source_parse(source, &nick, NULL, NULL); |
| |
148 if(purple_strempty(nick)) { |
| |
149 /* We _shouldn't_ be able to get an empty nick, but just in case... */ |
| |
150 g_clear_pointer(&nick, g_free); |
| |
151 |
| |
152 /* TODO: write message about being unable to parse source to status |
| |
153 * window. |
| |
154 */ |
| |
155 |
| |
156 return TRUE; |
| |
157 } |
| |
158 |
| |
159 /* We do want to find or create the contact, even on a part, because we |
| |
160 * could have connected to a BNC and we weren't told about the contact yet. |
| |
161 */ |
| |
162 contact = purple_ircv3_connection_find_or_create_contact(connection, nick); |
| |
163 g_free(nick); |
| |
164 |
| |
165 /* If a part message was given, join the remaining parameters with a space. |
| |
166 */ |
| |
167 if(n_params > 1) { |
| |
168 reason = g_strjoinv(" ", params + 1); |
| |
169 } |
| |
170 |
| |
171 purple_conversation_remove_member(conversation, |
| |
172 PURPLE_CONTACT_INFO(contact), TRUE, |
| |
173 reason); |
| |
174 |
| |
175 g_clear_pointer(&reason, g_free); |
| |
176 |
| |
177 return TRUE; |
| |
178 } |
| |
179 |
| 33 gboolean |
180 gboolean |
| 34 purple_ircv3_message_handler_privmsg(G_GNUC_UNUSED IbisClient *client, |
181 purple_ircv3_message_handler_privmsg(G_GNUC_UNUSED IbisClient *client, |
| 35 const char *command, |
182 const char *command, |
| 36 IbisMessage *ibis_message, gpointer data) |
183 IbisMessage *ibis_message, gpointer data) |
| 37 { |
184 { |
| 77 } |
224 } |
| 78 conversation = purple_ircv3_connection_find_or_create_conversation(connection, |
225 conversation = purple_ircv3_connection_find_or_create_conversation(connection, |
| 79 target); |
226 target); |
| 80 /* Find or create the contact. */ |
227 /* Find or create the contact. */ |
| 81 contact = purple_ircv3_connection_find_or_create_contact(connection, nick); |
228 contact = purple_ircv3_connection_find_or_create_contact(connection, nick); |
| 82 if(PURPLE_IS_CONTACT(contact)) { |
229 purple_contact_info_set_sid(PURPLE_CONTACT_INFO(contact), source); |
| 83 PurpleConversationMember *member = NULL; |
230 |
| 84 |
231 purple_ircv3_add_contact_to_conversation(contact, conversation); |
| 85 /* Update the contact's sid as it may have changed. */ |
|
| 86 purple_contact_info_set_sid(PURPLE_CONTACT_INFO(contact), source); |
|
| 87 |
|
| 88 /* Make sure the contact is in the conversation. */ |
|
| 89 member = purple_conversation_find_member(conversation, |
|
| 90 PURPLE_CONTACT_INFO(contact)); |
|
| 91 if(!PURPLE_IS_CONVERSATION_MEMBER(member)) { |
|
| 92 purple_conversation_add_member(conversation, |
|
| 93 PURPLE_CONTACT_INFO(contact), |
|
| 94 FALSE, NULL); |
|
| 95 } |
|
| 96 } |
|
| 97 |
232 |
| 98 if(purple_strequal(command, IBIS_MSG_NOTICE)) { |
233 if(purple_strequal(command, IBIS_MSG_NOTICE)) { |
| 99 flags |= PURPLE_MESSAGE_NOTIFY; |
234 flags |= PURPLE_MESSAGE_NOTIFY; |
| 100 } |
235 } |
| 101 |
236 |