comparison mcabber/src/jabglue.c @ 475:fa49ac0bb8f3

Add "/room topic", and display topic changes
author Mikael Berthe <mikael@lilotux.net>
date Sun, 02 Oct 2005 23:36:39 +0200
parents 27efa1e2671a
children 47cfa3779549
comparison
equal deleted inserted replaced
474:27efa1e2671a 475:fa49ac0bb8f3
338 338
339 hk_mystatuschange(0, mystatus, st, msg); 339 hk_mystatuschange(0, mystatus, st, msg);
340 mystatus = st; 340 mystatus = st;
341 } 341 }
342 342
343 void jb_send_msg(const char *jid, const char *text, int type) 343 void jb_send_msg(const char *jid, const char *text, int type,
344 { 344 const char *subject)
345 {
346 xmlnode x;
345 gchar *strtype; 347 gchar *strtype;
346 gchar *buffer = to_utf8(text); 348 gchar *buffer = to_utf8(text);
347 349
348 if (!online) return; 350 if (!online) return;
349 351
350 if (type == ROSTER_TYPE_ROOM) 352 if (type == ROSTER_TYPE_ROOM)
351 strtype = TMSG_GROUPCHAT; 353 strtype = TMSG_GROUPCHAT;
352 else 354 else
353 strtype = TMSG_CHAT; 355 strtype = TMSG_CHAT;
354 356
355 xmlnode x = jutil_msgnew(strtype, (char*)jid, 0, (char*)buffer); 357 x = jutil_msgnew(strtype, (char*)jid, 0, (char*)buffer);
358 if (subject) {
359 xmlnode y;
360 char *bs = to_utf8(subject);
361 y = xmlnode_insert_tag(x, "subject");
362 xmlnode_insert_cdata(y, bs, (unsigned) -1);
363 if (bs) g_free(bs);
364 }
356 jab_send(jc, x); 365 jab_send(jc, x);
357 xmlnode_free(x); 366 xmlnode_free(x);
358 g_free(buffer); 367 g_free(buffer);
359 jb_reset_keepalive(); 368 jb_reset_keepalive();
360 } 369 }
836 845
837 body = xmlnode_get_tag_data(packet->x, "body"); 846 body = xmlnode_get_tag_data(packet->x, "body");
838 847
839 p = xmlnode_get_tag_data(packet->x, "subject"); 848 p = xmlnode_get_tag_data(packet->x, "subject");
840 if (p != NULL) { 849 if (p != NULL) {
841 if (type && !strcmp(type, "groupchat")) { 850 if (type && !strcmp(type, TMSG_GROUPCHAT)) { // Room topic
842 // That's a room topic 851 gchar *mbuf;
843 } else { 852 gchar *subj_noutf8 = from_utf8(p);
853 // Get the room (s) and the nickname (r)
854 s = g_strdup(from);
855 r = strchr(s, '/');
856 if (r) *r++ = 0;
857 else r = s;
858 // Display inside the room window
859 mbuf = g_strdup_printf("%s has set the topic to: %s", r,
860 (subj_noutf8 ? subj_noutf8 : "(?)"));
861 scr_WriteIncomingMessage(s, mbuf, 0, HBB_PREFIX_INFO);
862 if (subj_noutf8) g_free(subj_noutf8);
863 g_free(s);
864 g_free(mbuf);
865 } else { // Chat message
844 tmp = g_new(char, (body ? strlen(body) : 0) + strlen(p) + 4); 866 tmp = g_new(char, (body ? strlen(body) : 0) + strlen(p) + 4);
845 *tmp = '['; 867 *tmp = '[';
846 strcpy(tmp+1, p); 868 strcpy(tmp+1, p);
847 strcat(tmp, "]\n"); 869 strcat(tmp, "]\n");
848 if (body) strcat(tmp, body); 870 if (body) strcat(tmp, body);