Translate incoming typing notifications from libpurple into chatstates.
[thrasher.git] / thconversations.c
blob1f9b4789c5b007efc0239f56076cd27aa10e5c14
1 /*
2 * Thrasher Bird - XMPP transport via libpurple
3 * Copyright (C) 2008 Barracuda Networks, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Thrasher Bird; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
20 #include <glib.h>
21 #include "thrasher.h"
22 #include "thperl.h"
24 #include <purple.h>
26 #include "thconversations.h"
28 /* incoming_chatstate_cb(pa, who):
30 * Account "pa" got a typing notification state change from the contact "who".
32 static void
33 incoming_chatstate_cb(PurpleAccount *pa,
34 const char *who) {
35 PurpleConversation *conv
36 = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
37 who,
38 pa);
39 if (! conv
40 || purple_conversation_get_type(conv) != PURPLE_CONV_TYPE_IM) {
41 return;
44 PurpleConvIm *im = PURPLE_CONV_IM(conv);
45 if (! im) {
46 return;
49 thrasher_wrapper_incoming_chatstate(pa,
50 who,
51 purple_conv_im_get_typing_state(im));
54 static gpointer
55 thrasher_conversations_get_handle() {
56 static int handle;
57 return &handle;
60 void
61 thrasher_conversations_init(void) {
62 purple_signal_connect(purple_conversations_get_handle(),
63 "buddy-typing",
64 thrasher_conversations_get_handle(),
65 PURPLE_CALLBACK(incoming_chatstate_cb),
66 NULL);
67 purple_signal_connect(purple_conversations_get_handle(),
68 "buddy-typing-stopped",
69 thrasher_conversations_get_handle(),
70 PURPLE_CALLBACK(incoming_chatstate_cb),
71 NULL);