comparison mcabber/src/hooks.c @ 447:03bb57383cea

Initial Multi-User Chat support This patch adds basic MUC support. We now can: - join an existing room; - create and unlock a room using the /rawxml command; - set our nickname; - send/receive chatgroup messages; - see the members of the room; - leave the room. Chatroom logging is currently disabled, as it could do some unexpected things.
author Mikael Berthe <mikael@lilotux.net>
date Sun, 25 Sep 2005 01:01:44 +0200
parents b44be19d6229
children 39e173645f9c
comparison
equal deleted inserted replaced
446:9f4e9e9aaf08 447:03bb57383cea
28 #include "histolog.h" 28 #include "histolog.h"
29 #include "hbuf.h" 29 #include "hbuf.h"
30 30
31 static char *extcmd; 31 static char *extcmd;
32 32
33 inline void hk_message_in(const char *jid, time_t timestamp, const char *msg, 33 inline void hk_message_in(const char *jid, const char *resname,
34 const char *type) 34 time_t timestamp, const char *msg, const char *type)
35 { 35 {
36 int new_guy = FALSE; 36 int new_guy = FALSE;
37 int message_flags; 37 int is_groupchat = FALSE;
38 int message_flags = 0;
39 guint rtype = ROSTER_TYPE_USER;
40 char *wmsg;
41 GSList *roster_usr;
42
43 if (type && !strcmp(type, "groupchat")) {
44 rtype = ROSTER_TYPE_ROOM;
45 is_groupchat = TRUE;
46 if (!resname) {
47 message_flags = HBB_PREFIX_INFO;
48 resname = "";
49 }
50 wmsg = g_strdup_printf("<%s> %s", resname, msg);
51 } else {
52 wmsg = (char*) msg;
53 }
38 54
39 // If this user isn't in the roster, we add it 55 // If this user isn't in the roster, we add it
40 if (!roster_exists(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT)) { 56 roster_usr = roster_find(jid, jidsearch,
41 roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER); 57 rtype|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM);
58 if (!roster_usr) {
59 roster_add_user(jid, NULL, NULL, rtype);
42 new_guy = TRUE; 60 new_guy = TRUE;
61 } else {
62 if (buddy_gettype(roster_usr->data) == ROSTER_TYPE_ROOM)
63 is_groupchat = TRUE;
43 } 64 }
44 65
45 if (type && !strcmp(type, "error")) { 66 if (type && !strcmp(type, "error")) {
46 message_flags = HBB_PREFIX_ERR | HBB_PREFIX_IN; 67 message_flags = HBB_PREFIX_ERR | HBB_PREFIX_IN;
47 scr_LogPrint(LPRINT_LOGNORM, "Error message received from <%s>", jid); 68 scr_LogPrint(LPRINT_LOGNORM, "Error message received from <%s>", jid);
48 } else 69 }
49 message_flags = 0;
50 70
51 // Note: the hlog_write should not be called first, because in some 71 // Note: the hlog_write should not be called first, because in some
52 // cases scr_WriteIncomingMessage() will load the history and we'd 72 // cases scr_WriteIncomingMessage() will load the history and we'd
53 // have the message twice... 73 // have the message twice...
54 scr_WriteIncomingMessage(jid, msg, timestamp, message_flags); 74 scr_WriteIncomingMessage(jid, wmsg, timestamp, message_flags);
75
55 // We don't log the message if it is an error message 76 // We don't log the message if it is an error message
56 if (!(message_flags & HBB_PREFIX_ERR)) 77 // or if it is a groupchat message
57 hlog_write_message(jid, timestamp, FALSE, msg); 78 // XXX We could use an option here to know if we should write GC messages...
79 if (!is_groupchat && !(message_flags & HBB_PREFIX_ERR))
80 hlog_write_message(jid, timestamp, FALSE, wmsg);
81
58 // External command 82 // External command
59 hk_ext_cmd(jid, 'M', 'R', NULL); 83 if (!is_groupchat)
84 hk_ext_cmd(jid, 'M', 'R', NULL);
85
60 // We need to rebuild the list if the sender is unknown or 86 // We need to rebuild the list if the sender is unknown or
61 // if the sender is offline/invisible and hide_offline_buddies is set 87 // if the sender is offline/invisible and hide_offline_buddies is set
62 if (new_guy || 88 if (new_guy ||
63 (roster_getstatus(jid, NULL) == offline && 89 (roster_getstatus(jid, NULL) == offline &&
64 buddylist_get_hide_offline_buddies())) 90 buddylist_get_hide_offline_buddies()))
65 { 91 {
66 buddylist_build(); 92 buddylist_build();
67 update_roster = TRUE; 93 update_roster = TRUE;
68 } 94 }
95
96 if (rtype == ROSTER_TYPE_ROOM) g_free(wmsg);
69 } 97 }
70 98
71 inline void hk_message_out(const char *jid, time_t timestamp, const char *msg) 99 inline void hk_message_out(const char *jid, time_t timestamp, const char *msg)
72 { 100 {
73 scr_WriteOutgoingMessage(jid, msg); 101 scr_WriteOutgoingMessage(jid, msg);