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
26 #include "thconversations.h"
29 thrasher_destroy_conversation(PurpleConversation
*conv
) {
30 purple_debug_info("thrasher", "destroy conversation\n");
34 thrasher_find_conversation_with_account(PurpleAccount
* pa
,
36 PurpleConversation
*conv
;
38 /* For testing and the initial build we're recreating a
39 * conversation *every time*
41 conv
= purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM
, who
, pa
);
43 /* If not, create a new one */
45 conv
= purple_conversation_new(PURPLE_CONV_TYPE_IM
, pa
, who
);
53 thrasher_write_conv(PurpleConversation
*conv
,
57 PurpleMessageFlags flags
,
59 PurpleAccount
*account
;
60 account
= purple_conversation_get_account(conv
);
62 /* libpurple throws write_conv on every recv and send */
63 if (flags
!= PURPLE_MESSAGE_RECV
)
66 purple_debug_info("thrasher",
67 "Incoming message:\n");
69 thrasher_wrapper_incoming_msg(thrasher_account_get_jid(account
),
75 purple_debug_info("thrasher",
77 purple_conversation_get_name(conv
),
78 purple_utf8_strftime("(%H:%M:%S)", localtime(&mtime
)),
85 thrasher_outgoing_chatstate(PurpleAccount
* pa
,
87 PurpleTypingState chatstate
) {
88 g_return_val_if_fail(pa
!= NULL
, FALSE
);
89 g_return_val_if_fail(recipient
!= NULL
, FALSE
);
91 PurpleConversation
*conv
92 = thrasher_find_conversation_with_account(pa
, recipient
);
93 g_return_val_if_fail(conv
!= NULL
, FALSE
);
95 PurpleConnection
*gc
= purple_conversation_get_gc(conv
);
100 unsigned int timeout
= serv_send_typing(gc
, recipient
, chatstate
);
101 if (chatstate
== PURPLE_TYPING
) {
102 /* TODO: if the prpl requests the typing notification be resent
103 * after timeout, "normal" UIs can check get_type_again() each
104 * keystroke. Should Thrasher add a event loop timeout? (and rm it
105 * if the conv ended or the state was no longer typing...)
107 PurpleConvIm
*im
= PURPLE_CONV_IM(conv
);
108 purple_conv_im_set_type_again(im
, timeout
);
113 /* incoming_chatstate_cb(pa, who):
115 * Account "pa" got a typing notification state change from the contact "who".
118 incoming_chatstate_cb(PurpleAccount
*pa
,
120 PurpleConversation
*conv
121 = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM
,
125 || purple_conversation_get_type(conv
) != PURPLE_CONV_TYPE_IM
) {
129 PurpleConvIm
*im
= PURPLE_CONV_IM(conv
);
134 thrasher_wrapper_incoming_chatstate(pa
,
136 purple_conv_im_get_typing_state(im
));
140 thrasher_conversations_get_handle() {
145 static PurpleConversationUiOps thrasher_conv_uiops
=
147 NULL
, /* create_conversation */
148 thrasher_destroy_conversation
, /* destroy_conversation */
149 NULL
, /* write_chat */
151 thrasher_write_conv
, /* write_conv */
152 NULL
, /* chat_add_users */
153 NULL
, /* chat_rename_user */
154 NULL
, /* chat_remove_users */
155 NULL
, /* chat_update_user */
157 NULL
, /* has_focus */
158 NULL
, /* custom_smiley_add */
159 NULL
, /* custom_smiley_write */
160 NULL
, /* custom_smiley_close */
161 NULL
, /* send_confirm */
169 thrasher_conversations_init(void) {
170 purple_conversations_set_ui_ops(&thrasher_conv_uiops
);
172 purple_signal_connect(purple_conversations_get_handle(),
174 thrasher_conversations_get_handle(),
175 PURPLE_CALLBACK(incoming_chatstate_cb
),
177 purple_signal_connect(purple_conversations_get_handle(),
178 "buddy-typing-stopped",
179 thrasher_conversations_get_handle(),
180 PURPLE_CALLBACK(incoming_chatstate_cb
),