2015-01-28 18:41:41 +01:00
|
|
|
/*
|
|
|
|
This file is part of telegram-purple
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
|
|
|
|
2015-03-12 01:47:57 +01:00
|
|
|
Copyright Matthias Jentsch 2014-2015
|
2015-01-28 18:41:41 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tgp-chat.h"
|
2015-03-07 16:13:44 +01:00
|
|
|
#include "msglog.h"
|
2015-01-28 18:41:41 +01:00
|
|
|
|
|
|
|
void chat_add_all_users (PurpleConversation *pc, struct tgl_chat *chat) {
|
2015-01-28 19:43:42 +01:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < chat->user_list_size; i++) {
|
2015-01-28 18:41:41 +01:00
|
|
|
struct tgl_chat_user *uid = (chat->user_list + i);
|
|
|
|
int flags = (chat->admin_id == uid->user_id ? PURPLE_CBFLAGS_FOUNDER : PURPLE_CBFLAGS_NONE);
|
|
|
|
p2tgl_conv_add_user (pc, *uid, NULL, flags, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void chat_users_update (struct tgl_state *TLS, struct tgl_chat *chat) {
|
|
|
|
PurpleConversation *pc = purple_find_chat(tg_get_conn(TLS), tgl_get_peer_id(chat->id));
|
|
|
|
if (pc) {
|
|
|
|
purple_conv_chat_clear_users (purple_conversation_get_chat_data(pc));
|
|
|
|
chat_add_all_users (pc, chat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PurpleConversation *chat_show (PurpleConnection *gc, int id) {
|
|
|
|
connection_data *conn = purple_connection_get_protocol_data(gc);
|
|
|
|
PurpleConversation *convo = purple_find_chat (gc, id);
|
2015-05-30 15:55:13 +02:00
|
|
|
PurpleConvChat *chat = purple_conversation_get_chat_data (convo);
|
2015-03-07 16:13:44 +01:00
|
|
|
tgl_peer_t *P = tgl_peer_get (conn->TLS, TGL_MK_CHAT(id));
|
|
|
|
|
2015-05-30 15:55:13 +02:00
|
|
|
if (! P) {
|
|
|
|
warning ("Chat %d not existing, not showing...", id);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (! convo || (chat && purple_conv_chat_has_left (chat))) {
|
2015-01-28 18:41:41 +01:00
|
|
|
convo = p2tgl_got_joined_chat (conn->TLS, &P->chat);
|
|
|
|
}
|
2015-05-30 15:55:13 +02:00
|
|
|
chat_users_update (conn->TLS, &P->chat);
|
2015-01-28 18:41:41 +01:00
|
|
|
|
2015-03-12 01:38:17 +01:00
|
|
|
return convo;
|
2015-01-28 18:41:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int chat_is_member (int who, struct tgl_chat *chat) {
|
2015-01-28 19:43:42 +01:00
|
|
|
int i;
|
2015-07-24 14:28:00 +02:00
|
|
|
for (i = 0; i < chat->user_list_size; i++) if ((chat->user_list + i)->user_id == who) {
|
2015-01-28 18:41:41 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|