6 * Copyright (C) 2010 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2009 pier11 <pier11@operamail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "conversation.h"
32 #include "sipe-backend.h"
33 #include "sipe-core.h"
35 #include "purple-private.h"
37 #define BACKEND_SESSION_TO_PURPLE_CONV_CHAT(s) \
38 (PURPLE_CONV_CHAT(((PurpleConversation *)s)))
40 void sipe_backend_chat_add(struct sipe_backend_session
*backend_session
,
44 purple_conv_chat_add_user(BACKEND_SESSION_TO_PURPLE_CONV_CHAT(backend_session
),
45 uri
, NULL
, PURPLE_CBFLAGS_NONE
, is_new
);
48 void sipe_backend_chat_close(struct sipe_backend_session
*backend_session
)
50 purple_conv_chat_clear_users(BACKEND_SESSION_TO_PURPLE_CONV_CHAT(backend_session
));
53 struct sipe_backend_session
*sipe_backend_chat_create(struct sipe_core_public
*sipe_public
,
59 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
60 PurpleConversation
*conv
= NULL
;
63 /* can't be find by chat id as it won't survive acc reinstantation */
65 conv
= purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT
,
67 purple_private
->account
);
69 /* to be able to rejoin existing chat/window */
70 if (conv
&& !purple_conv_chat_has_left(PURPLE_CONV_CHAT(conv
))) {
71 PURPLE_CONV_CHAT(conv
)->left
= TRUE
;
75 /* create prpl chat */
76 conv
= serv_got_joined_chat(purple_private
->gc
,
79 purple_conv_chat_set_nick(PURPLE_CONV_CHAT(conv
), nick
);
80 return((struct sipe_backend_session
*) conv
);
83 gboolean
sipe_backend_chat_find(struct sipe_backend_session
*backend_session
,
86 return purple_conv_chat_find_user(BACKEND_SESSION_TO_PURPLE_CONV_CHAT(backend_session
),
90 gboolean
sipe_backend_chat_is_operator(struct sipe_backend_session
*backend_session
,
93 return (purple_conv_chat_user_get_flags(BACKEND_SESSION_TO_PURPLE_CONV_CHAT(backend_session
),
94 uri
) & PURPLE_CBFLAGS_OP
)
98 void sipe_backend_chat_message(struct sipe_core_public
*sipe_public
,
103 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
104 serv_got_chat_in(purple_private
->gc
,
112 void sipe_backend_chat_operator(struct sipe_backend_session
*backend_session
,
115 purple_conv_chat_user_set_flags(BACKEND_SESSION_TO_PURPLE_CONV_CHAT(backend_session
),
117 PURPLE_CBFLAGS_NONE
| PURPLE_CBFLAGS_OP
);
121 * Allows to send typed messages from chat window again after
122 * account reinstantiation.
124 * @TODO: is this really necessary? No other purple protocol plugin
125 * seems to have this kind of code...
127 void sipe_backend_chat_rejoin_all(struct sipe_core_public
*sipe_public
)
130 struct sipe_backend_private
*purple_private
= sipe_public
->backend_private
;
131 GList
*entry
= purple_get_chats();
134 PurpleConversation
*conv
= entry
->data
;
135 if ((purple_conversation_get_gc(conv
) == purple_private
->gc
) &&
136 purple_conv_chat_has_left(PURPLE_CONV_CHAT(conv
))) {
137 PURPLE_CONV_CHAT(conv
)->left
= FALSE
;
138 purple_conversation_update(conv
,
139 PURPLE_CONV_UPDATE_CHATLEFT
);
145 void sipe_backend_chat_remove(struct sipe_backend_session
*backend_session
,
148 purple_conv_chat_remove_user(BACKEND_SESSION_TO_PURPLE_CONV_CHAT(backend_session
),
153 void sipe_backend_chat_topic(struct sipe_backend_session
*backend_session
,
156 purple_conv_chat_set_topic(BACKEND_SESSION_TO_PURPLE_CONV_CHAT(backend_session
),