Mercurial > hg
comparison mcabber/src/hooks.c @ 567:6f490c725999
Handle "/me " in messages
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 03 Dec 2005 00:24:05 +0100 |
parents | 87165382e4ce |
children | afc2bd38b15c |
comparison
equal
deleted
inserted
replaced
566:467fec046a9b | 567:6f490c725999 |
---|---|
40 int is_groupchat = FALSE; // groupchat message | 40 int is_groupchat = FALSE; // groupchat message |
41 int is_room = FALSE; // window is a room window | 41 int is_room = FALSE; // window is a room window |
42 int log_muc_conf = FALSE; | 42 int log_muc_conf = FALSE; |
43 int message_flags = 0; | 43 int message_flags = 0; |
44 guint rtype = ROSTER_TYPE_USER; | 44 guint rtype = ROSTER_TYPE_USER; |
45 char *wmsg = NULL, *bmsg = NULL; | 45 char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL; |
46 GSList *roster_usr; | 46 GSList *roster_usr; |
47 | 47 |
48 if (type && !strcmp(type, "groupchat")) { | 48 if (type && !strcmp(type, "groupchat")) { |
49 rtype = ROSTER_TYPE_ROOM; | 49 rtype = ROSTER_TYPE_ROOM; |
50 is_groupchat = TRUE; | 50 is_groupchat = TRUE; |
52 if (!resname) { | 52 if (!resname) { |
53 message_flags = HBB_PREFIX_INFO; | 53 message_flags = HBB_PREFIX_INFO; |
54 resname = ""; | 54 resname = ""; |
55 } | 55 } |
56 wmsg = bmsg = g_strdup_printf("<%s> %s", resname, msg); | 56 wmsg = bmsg = g_strdup_printf("<%s> %s", resname, msg); |
57 if (!strncmp(msg, "/me ", 4)) | |
58 wmsg = mmsg = g_strdup_printf("*%s %s", resname, msg+4); | |
57 } else { | 59 } else { |
58 wmsg = (char*) msg; | 60 if (!strncmp(msg, "/me ", 4)) |
61 wmsg = mmsg = g_strdup_printf("*%s %s", jid, msg+4); | |
62 else | |
63 wmsg = (char*) msg; | |
59 } | 64 } |
60 | 65 |
61 // If this user isn't in the roster, we add it | 66 // If this user isn't in the roster, we add it |
62 roster_usr = roster_find(jid, jidsearch, 0); | 67 roster_usr = roster_find(jid, jidsearch, 0); |
63 if (!roster_usr) { | 68 if (!roster_usr) { |
64 new_guy = TRUE; | 69 new_guy = TRUE; |
65 roster_usr = roster_add_user(jid, NULL, NULL, rtype); | 70 roster_usr = roster_add_user(jid, NULL, NULL, rtype); |
66 if (!roster_usr) { // Shouldn't happen... | 71 if (!roster_usr) { // Shouldn't happen... |
67 scr_LogPrint(LPRINT_LOGNORM, "ERROR: unable to add buddy!"); | 72 scr_LogPrint(LPRINT_LOGNORM, "ERROR: unable to add buddy!"); |
68 if (bmsg) g_free(bmsg); | 73 if (bmsg) g_free(bmsg); |
74 if (mmsg) g_free(mmsg); | |
69 return; | 75 return; |
70 } | 76 } |
71 } else if (is_groupchat) { | 77 } else if (is_groupchat) { |
72 // Make sure the type is ROOM | 78 // Make sure the type is ROOM |
73 buddy_settype(roster_usr->data, ROSTER_TYPE_ROOM); | 79 buddy_settype(roster_usr->data, ROSTER_TYPE_ROOM); |
75 | 81 |
76 is_room = !!(buddy_gettype(roster_usr->data) & ROSTER_TYPE_ROOM); | 82 is_room = !!(buddy_gettype(roster_usr->data) & ROSTER_TYPE_ROOM); |
77 | 83 |
78 if (!is_groupchat && is_room) { | 84 if (!is_groupchat && is_room) { |
79 // This is a private message from a room participant | 85 // This is a private message from a room participant |
80 if (!resname) resname = ""; | 86 if (!resname) |
87 resname = ""; | |
81 wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", resname, msg); | 88 wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", resname, msg); |
89 if (!strncmp(msg, "/me ", 4)) | |
90 wmsg = mmsg = g_strdup_printf("PRIV#*%s %s", resname, msg+4); | |
82 } | 91 } |
83 | 92 |
84 if (type && !strcmp(type, "error")) { | 93 if (type && !strcmp(type, "error")) { |
85 message_flags = HBB_PREFIX_ERR | HBB_PREFIX_IN; | 94 message_flags = HBB_PREFIX_ERR | HBB_PREFIX_IN; |
86 scr_LogPrint(LPRINT_LOGNORM, "Error message received from <%s>", jid); | 95 scr_LogPrint(LPRINT_LOGNORM, "Error message received from <%s>", jid); |
88 | 97 |
89 // Note: the hlog_write should not be called first, because in some | 98 // Note: the hlog_write should not be called first, because in some |
90 // cases scr_WriteIncomingMessage() will load the history and we'd | 99 // cases scr_WriteIncomingMessage() will load the history and we'd |
91 // have the message twice... | 100 // have the message twice... |
92 scr_WriteIncomingMessage(jid, wmsg, timestamp, message_flags); | 101 scr_WriteIncomingMessage(jid, wmsg, timestamp, message_flags); |
102 | |
103 // We don't log the modified message, but the original one | |
104 if (wmsg == mmsg) | |
105 wmsg = bmsg; | |
93 | 106 |
94 // - We don't log the message if it is an error message | 107 // - We don't log the message if it is an error message |
95 // - We don't log the message if it is a private conf. message | 108 // - We don't log the message if it is a private conf. message |
96 // - We don't log the message if it is groupchat message and the log_muc_conf | 109 // - We don't log the message if it is groupchat message and the log_muc_conf |
97 // option is off (and it is not a history line) | 110 // option is off (and it is not a history line) |
114 buddylist_build(); | 127 buddylist_build(); |
115 update_roster = TRUE; | 128 update_roster = TRUE; |
116 } | 129 } |
117 | 130 |
118 if (bmsg) g_free(bmsg); | 131 if (bmsg) g_free(bmsg); |
132 if (mmsg) g_free(mmsg); | |
119 } | 133 } |
120 | 134 |
121 // hk_message_out() | 135 // hk_message_out() |
122 // nick should be set for private messages in a chat room, and null for | 136 // nick should be set for private messages in a chat room, and null for |
123 // normal messages. | 137 // normal messages. |
124 inline void hk_message_out(const char *jid, const char *nick, | 138 inline void hk_message_out(const char *jid, const char *nick, |
125 time_t timestamp, const char *msg) | 139 time_t timestamp, const char *msg) |
126 { | 140 { |
127 char *wmsg = NULL, *bmsg = NULL; | 141 char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL;; |
128 | 142 |
129 if (nick) wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", nick, msg); | 143 if (nick) { |
130 else wmsg = (char*)msg; | 144 wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", nick, msg); |
145 } else { | |
146 wmsg = (char*)msg; | |
147 if (!strncmp(msg, "/me ", 4)) { | |
148 const char *myid = settings_opt_get("username"); | |
149 if (myid) | |
150 wmsg = mmsg = g_strdup_printf("*%s %s", settings_opt_get("username"), | |
151 msg+4); | |
152 } | |
153 } | |
131 | 154 |
132 // Note: the hlog_write should not be called first, because in some | 155 // Note: the hlog_write should not be called first, because in some |
133 // cases scr_WriteOutgoingMessage() will load the history and we'd | 156 // cases scr_WriteOutgoingMessage() will load the history and we'd |
134 // have the message twice... | 157 // have the message twice... |
135 scr_WriteOutgoingMessage(jid, wmsg); | 158 scr_WriteOutgoingMessage(jid, wmsg); |
139 | 162 |
140 // External command | 163 // External command |
141 hk_ext_cmd(jid, 'M', 'S', NULL); | 164 hk_ext_cmd(jid, 'M', 'S', NULL); |
142 | 165 |
143 if (bmsg) g_free(bmsg); | 166 if (bmsg) g_free(bmsg); |
167 if (mmsg) g_free(mmsg); | |
144 } | 168 } |
145 | 169 |
146 inline void hk_statuschange(const char *jid, const char *resname, gchar prio, | 170 inline void hk_statuschange(const char *jid, const char *resname, gchar prio, |
147 time_t timestamp, enum imstatus status, | 171 time_t timestamp, enum imstatus status, |
148 const char *status_msg) | 172 const char *status_msg) |