comparison mcabber/src/hooks.c @ 477:d11e5ce2582c

Improve hk_message_in() - Show when we have a private message in a chat room - Add an option ("log_muc_conf") to enable chat room logging
author Mikael Berthe <mikael@lilotux.net>
date Mon, 03 Oct 2005 21:49:48 +0200
parents 644b8bf9ca4d
children b82428ac107d
comparison
equal deleted inserted replaced
476:88f026a75e66 477:d11e5ce2582c
25 #include "hooks.h" 25 #include "hooks.h"
26 #include "screen.h" 26 #include "screen.h"
27 #include "roster.h" 27 #include "roster.h"
28 #include "histolog.h" 28 #include "histolog.h"
29 #include "hbuf.h" 29 #include "hbuf.h"
30 #include "settings.h"
30 31
31 static char *extcmd; 32 static char *extcmd;
32 33
33 inline void hk_message_in(const char *jid, const char *resname, 34 inline void hk_message_in(const char *jid, const char *resname,
34 time_t timestamp, const char *msg, const char *type) 35 time_t timestamp, const char *msg, const char *type)
35 { 36 {
36 int new_guy = FALSE; 37 int new_guy = FALSE;
37 int is_groupchat = FALSE; 38 int is_groupchat = FALSE; // groupchat message
39 int is_room = FALSE; // window is a room window
40 int log_muc_conf = FALSE;
38 int message_flags = 0; 41 int message_flags = 0;
39 guint rtype = ROSTER_TYPE_USER; 42 guint rtype = ROSTER_TYPE_USER;
40 char *wmsg; 43 char *wmsg = NULL, *bmsg = NULL;
41 GSList *roster_usr; 44 GSList *roster_usr;
42 45
43 if (type && !strcmp(type, "groupchat")) { 46 if (type && !strcmp(type, "groupchat")) {
44 rtype = ROSTER_TYPE_ROOM; 47 rtype = ROSTER_TYPE_ROOM;
45 is_groupchat = TRUE; 48 is_groupchat = TRUE;
49 log_muc_conf = settings_opt_get_int("log_muc_conf");
46 if (!resname) { 50 if (!resname) {
47 message_flags = HBB_PREFIX_INFO; 51 message_flags = HBB_PREFIX_INFO;
48 resname = ""; 52 resname = "";
49 } 53 }
50 wmsg = g_strdup_printf("<%s> %s", resname, msg); 54 wmsg = bmsg = g_strdup_printf("<%s> %s", resname, msg);
51 } else { 55 } else {
52 wmsg = (char*) msg; 56 wmsg = (char*) msg;
53 } 57 }
54 58
55 // If this user isn't in the roster, we add it 59 // If this user isn't in the roster, we add it
56 roster_usr = roster_find(jid, jidsearch, 60 roster_usr = roster_find(jid, jidsearch,
57 rtype|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM); 61 rtype|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM);
58 if (!roster_usr) { 62 if (!roster_usr) {
59 roster_add_user(jid, NULL, NULL, rtype);
60 new_guy = TRUE; 63 new_guy = TRUE;
61 } else { 64 roster_usr = roster_add_user(jid, NULL, NULL, rtype);
62 if (buddy_gettype(roster_usr->data) == ROSTER_TYPE_ROOM) 65 if (!roster_usr) { // Shouldn't happen...
63 is_groupchat = TRUE; 66 scr_LogPrint(LPRINT_LOGNORM, "ERROR: unable to add buddy!");
67 if (bmsg) g_free(bmsg);
68 return;
69 }
70 }
71
72 is_room = !!(buddy_gettype(roster_usr->data) & ROSTER_TYPE_ROOM);
73
74 if (!is_groupchat && is_room) {
75 // This is a private message from a room participant
76 wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", resname, msg);
64 } 77 }
65 78
66 if (type && !strcmp(type, "error")) { 79 if (type && !strcmp(type, "error")) {
67 message_flags = HBB_PREFIX_ERR | HBB_PREFIX_IN; 80 message_flags = HBB_PREFIX_ERR | HBB_PREFIX_IN;
68 scr_LogPrint(LPRINT_LOGNORM, "Error message received from <%s>", jid); 81 scr_LogPrint(LPRINT_LOGNORM, "Error message received from <%s>", jid);
71 // Note: the hlog_write should not be called first, because in some 84 // Note: the hlog_write should not be called first, because in some
72 // cases scr_WriteIncomingMessage() will load the history and we'd 85 // cases scr_WriteIncomingMessage() will load the history and we'd
73 // have the message twice... 86 // have the message twice...
74 scr_WriteIncomingMessage(jid, wmsg, timestamp, message_flags); 87 scr_WriteIncomingMessage(jid, wmsg, timestamp, message_flags);
75 88
76 // We don't log the message if it is an error message 89 // - We don't log the message if it is an error message
77 // or if it is a groupchat message 90 // - We don't log the message if it is a private conf. message
78 // XXX We could use an option here to know if we should write GC messages... 91 // - We don't log the message if it is groupchat message and the log_muc_conf
79 if (!is_groupchat && !(message_flags & HBB_PREFIX_ERR)) 92 // option is off (and it is not a history line)
93 if (!(message_flags & HBB_PREFIX_ERR) &&
94 (!is_room || (is_groupchat && log_muc_conf && !timestamp)))
80 hlog_write_message(jid, timestamp, FALSE, wmsg); 95 hlog_write_message(jid, timestamp, FALSE, wmsg);
81 96
82 // External command 97 // External command
83 // (We do not call hk_ext_cmd() for history lines in MUC) 98 // - We do not call hk_ext_cmd() for history lines in MUC
84 if (!is_groupchat || !timestamp) 99 // - We do call hk_ext_cmd() for private messages in a room
100 if ((is_groupchat && !timestamp) || !is_groupchat)
85 hk_ext_cmd(jid, (is_groupchat ? 'G' : 'M'), 'R', NULL); 101 hk_ext_cmd(jid, (is_groupchat ? 'G' : 'M'), 'R', NULL);
86 102
87 // We need to rebuild the list if the sender is unknown or 103 // We need to rebuild the list if the sender is unknown or
88 // if the sender is offline/invisible and hide_offline_buddies is set 104 // if the sender is offline/invisible and hide_offline_buddies is set
89 if (new_guy || 105 if (new_guy ||
90 (roster_getstatus(jid, NULL) == offline && 106 (buddy_getstatus(roster_usr->data, NULL) == offline &&
91 buddylist_get_hide_offline_buddies())) 107 buddylist_get_hide_offline_buddies()))
92 { 108 {
93 buddylist_build(); 109 buddylist_build();
94 update_roster = TRUE; 110 update_roster = TRUE;
95 } 111 }
96 112
97 if (rtype == ROSTER_TYPE_ROOM) g_free(wmsg); 113 if (bmsg) g_free(bmsg);
98 } 114 }
99 115
100 inline void hk_message_out(const char *jid, time_t timestamp, const char *msg) 116 inline void hk_message_out(const char *jid, time_t timestamp, const char *msg)
101 { 117 {
102 scr_WriteOutgoingMessage(jid, msg); 118 scr_WriteOutgoingMessage(jid, msg);