purple: fix possible gsize vs. size_t incompatibilty
[siplcs.git] / src / purple / purple-chat.c
blobab6002eb9c6fa94e9ba97cfe9f9b6831d4b20f8e
1 /**
2 * @file purple-chat.c
4 * pidgin-sipe
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
25 #include <time.h>
27 #include <glib.h>
29 #include "conversation.h"
30 #include "server.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,
41 const gchar *uri,
42 gboolean is_new)
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,
54 int id,
55 const gchar *title,
56 const gchar *nick,
57 gboolean rejoin)
59 struct sipe_backend_private *purple_private = sipe_public->backend_private;
60 PurpleConversation *conv = NULL;
62 if (rejoin) {
63 /* can't be find by chat id as it won't survive acc reinstantation */
64 if (title) {
65 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT,
66 title,
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,
77 id,
78 title);
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,
84 const gchar *uri)
86 return purple_conv_chat_find_user(BACKEND_SESSION_TO_PURPLE_CONV_CHAT(backend_session),
87 uri);
90 gboolean sipe_backend_chat_is_operator(struct sipe_backend_session *backend_session,
91 const gchar *uri)
93 return (purple_conv_chat_user_get_flags(BACKEND_SESSION_TO_PURPLE_CONV_CHAT(backend_session),
94 uri) & PURPLE_CBFLAGS_OP)
95 == PURPLE_CBFLAGS_OP;
98 void sipe_backend_chat_message(struct sipe_core_public *sipe_public,
99 int id,
100 const gchar *from,
101 const gchar *html)
103 struct sipe_backend_private *purple_private = sipe_public->backend_private;
104 serv_got_chat_in(purple_private->gc,
106 from,
107 PURPLE_MESSAGE_RECV,
108 html,
109 time(NULL));
112 void sipe_backend_chat_operator(struct sipe_backend_session *backend_session,
113 const gchar *uri)
115 purple_conv_chat_user_set_flags(BACKEND_SESSION_TO_PURPLE_CONV_CHAT(backend_session),
116 uri,
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();
133 while (entry) {
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);
141 entry = entry->next;
145 void sipe_backend_chat_remove(struct sipe_backend_session *backend_session,
146 const gchar *uri)
148 purple_conv_chat_remove_user(BACKEND_SESSION_TO_PURPLE_CONV_CHAT(backend_session),
149 uri,
150 NULL /* reason */);
153 void sipe_backend_chat_topic(struct sipe_backend_session *backend_session,
154 const gchar *topic)
156 purple_conv_chat_set_topic(BACKEND_SESSION_TO_PURPLE_CONV_CHAT(backend_session),
157 NULL,
158 topic);
162 Local Variables:
163 mode: c
164 c-file-style: "bsd"
165 indent-tabs-mode: t
166 tab-width: 8
167 End: