Don't automatically add all chats to the buddy list
This should fix issue where left chats show up in the blist and cannot be removed anymore and broken Adium bookmarks. This patch should make the whole chat handling much more native to libpurple, in which chats are added through the chatlist, the join-chat window or automatically when incoming messages are received. Add a new option "Add chats to buddy list" in case anyone wants the old behavior.
This commit is contained in:
parent
ce51b0bb68
commit
c3f48b9835
6 changed files with 85 additions and 20 deletions
|
@ -30,7 +30,6 @@
|
|||
#import <AIUtilities/AIImageAdditions.h>
|
||||
#import <AIUtilities/AIMenuAdditions.h>
|
||||
|
||||
|
||||
#include "telegram-purple.h"
|
||||
|
||||
@implementation TelegramAccount
|
||||
|
@ -61,6 +60,20 @@
|
|||
[self purpleAccount];
|
||||
purple_signal_connect (purple_conversations_get_handle(), "chat-buddy-joined",
|
||||
[self purpleAccount], PURPLE_CALLBACK(chat_buddy_joined), (__bridge void *)(self));
|
||||
|
||||
// Storing chats in the blist breaks Adium bookmarks. Adium doesn't
|
||||
// show those chats anyway, so we can just safely delete those.
|
||||
PurpleBlistNode *node = purple_blist_get_root();
|
||||
while (node) {
|
||||
if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
|
||||
PurpleChat *ch = PURPLE_CHAT(node);
|
||||
if (purple_chat_get_account(ch) == account) {
|
||||
NSLog (@"Removing chat from blist: %s", ch->alias);
|
||||
purple_blist_remove_chat (ch);
|
||||
}
|
||||
}
|
||||
node = purple_blist_node_next (node, 0);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didDisconnect
|
||||
|
@ -218,4 +231,23 @@ void chat_buddy_joined (PurpleConversation *conv, const char *name,
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Re-create the chat's join options.
|
||||
*/
|
||||
- (NSDictionary *)extractChatCreationDictionaryFromConversation:(PurpleConversation *)conv
|
||||
{
|
||||
connection_data *conn = purple_connection_get_protocol_data (purple_conversation_get_gc (conv));
|
||||
|
||||
const char *name = purple_conversation_get_name (conv);
|
||||
tgl_peer_t *P = tgl_peer_get_by_name (conn->TLS, purple_conversation_get_title (conv));
|
||||
if (P) {
|
||||
return [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSString stringWithFormat:@"%d", tgl_get_peer_id(P->id)], @"id",
|
||||
[NSString stringWithUTF8String: name], @"subject",
|
||||
[NSString stringWithFormat:@"%d", P->chat.admin_id], @"owner",
|
||||
nil];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -324,26 +324,45 @@ static void on_userpic_loaded (struct tgl_state *TLS, void *extra, int success,
|
|||
|
||||
static void on_get_dialog_list_done (struct tgl_state *TLS, void *callback_extra, int success, int size,
|
||||
tgl_peer_id_t peers[], int last_msg_id[], int unread_count[]) {
|
||||
|
||||
connection_data *conn = TLS->ev_base;
|
||||
|
||||
int i = size - 1;
|
||||
for (; i >= 0; i--) if (tgl_get_peer_type (peers[i]) == TGL_PEER_USER) {
|
||||
for (; i >= 0; i--) {
|
||||
tgl_peer_t *UC = tgl_peer_get (TLS, peers[i]);
|
||||
|
||||
if (tgl_get_peer_id (peers[i]) != TLS->our_id) {
|
||||
PurpleBuddy *buddy = p2tgl_buddy_find (TLS, peers[i]);
|
||||
if (! buddy) {
|
||||
buddy = p2tgl_buddy_new (TLS, UC);
|
||||
purple_blist_add_buddy (buddy, NULL, tggroup, NULL);
|
||||
|
||||
if (UC->user.photo_id) {
|
||||
debug ("tgl_do_get_user_info(%s)", UC->print_name);
|
||||
tgl_do_get_user_info (TLS, UC->id, 0, on_user_get_info, get_user_info_data_new (0, UC->id));
|
||||
switch (tgl_get_peer_type (peers[i])) {
|
||||
case TGL_PEER_USER:
|
||||
assert (UC);
|
||||
if (tgl_get_peer_id (UC->id) != TLS->our_id) {
|
||||
PurpleBuddy *buddy = p2tgl_buddy_find (TLS, UC->id);
|
||||
if (! buddy) {
|
||||
buddy = p2tgl_buddy_new (TLS, UC);
|
||||
purple_blist_add_buddy (buddy, NULL, tggroup, NULL);
|
||||
|
||||
if (UC->user.photo_id) {
|
||||
debug ("tgl_do_get_user_info(%s)", UC->print_name);
|
||||
tgl_do_get_user_info (TLS, UC->id, 0, on_user_get_info, get_user_info_data_new (0, UC->id));
|
||||
}
|
||||
}
|
||||
|
||||
p2tgl_prpl_got_user_status (TLS, UC->id, &UC->user.status);
|
||||
p2tgl_prpl_got_set_status_mobile (TLS, UC->id);
|
||||
} else {
|
||||
p2tgl_connection_set_display_name (TLS, UC);
|
||||
}
|
||||
}
|
||||
|
||||
p2tgl_prpl_got_user_status (TLS, UC->id, &UC->user.status);
|
||||
p2tgl_prpl_got_set_status_mobile (TLS, UC->id);
|
||||
} else {
|
||||
p2tgl_connection_set_display_name (TLS, UC);
|
||||
break;
|
||||
|
||||
case TGL_PEER_CHAT:
|
||||
assert (UC);
|
||||
if (UC->chat.users_num > 0 && purple_account_get_bool (conn->pa, TGP_KEY_JOIN_GROUP_CHATS, TGP_DEFAULT_JOIN_GROUP_CHATS)) {
|
||||
PurpleChat *PC = p2tgl_chat_find (TLS, UC->id);
|
||||
if (!PC) {
|
||||
PC = p2tgl_chat_new (TLS, &UC->chat);
|
||||
purple_blist_add_chat (PC, NULL, NULL);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -892,6 +911,13 @@ static void tgprpl_init (PurplePlugin *plugin) {
|
|||
TGP_KEY_HISTORY_RETRIEVAL_THRESHOLD,
|
||||
TGP_DEFAULT_HISTORY_RETRIEVAL_THRESHOLD);
|
||||
prpl_info.protocol_options = g_list_append (prpl_info.protocol_options, opt);
|
||||
|
||||
// Chats
|
||||
|
||||
opt = purple_account_option_bool_new ("Add group chats to buddy list",
|
||||
TGP_KEY_JOIN_GROUP_CHATS,
|
||||
TGP_DEFAULT_JOIN_GROUP_CHATS);
|
||||
prpl_info.protocol_options = g_list_append (prpl_info.protocol_options, opt);
|
||||
|
||||
|
||||
// Read notifications
|
||||
|
|
|
@ -50,6 +50,9 @@
|
|||
#define TGP_DEFAULT_HISTORY_RETRIEVAL_THRESHOLD 14
|
||||
#define TGP_KEY_HISTORY_RETRIEVAL_THRESHOLD "history-retrieve-days"
|
||||
|
||||
#define TGP_DEFAULT_JOIN_GROUP_CHATS FALSE
|
||||
#define TGP_KEY_JOIN_GROUP_CHATS "auto-join-group-chats"
|
||||
|
||||
#define TGP_KEY_HISTORY_SYNC_ALL "history-sync-all"
|
||||
#define TGP_DEFAULT_HISTORY_SYNC_ALL FALSE
|
||||
|
||||
|
|
|
@ -68,8 +68,6 @@ PurpleConversation *p2tgl_find_conversation_with_account (struct tgl_state *TLS,
|
|||
void p2tgl_conversation_write (PurpleConversation *conv, tgl_peer_id_t who, const char *message, int flags, int date);
|
||||
PurpleConversation *p2tgl_conversation_new (struct tgl_state *TLS, tgl_peer_id_t who);
|
||||
|
||||
PurpleChat *p2tgl_chat_new (struct tgl_state *TLS, struct tgl_chat *chat);
|
||||
void p2tgl_chat_update (PurpleChat *chat, tgl_peer_id_t id, int admin_id, const char *subject);
|
||||
PurpleChat *p2tgl_chat_find (struct tgl_state *TLS, tgl_peer_id_t chat);
|
||||
|
||||
void *p2tgl_notify_userinfo(struct tgl_state *TLS, tgl_peer_id_t user, PurpleNotifyUserInfo *user_info, PurpleNotifyCloseCallback cb, gpointer user_data);
|
||||
|
|
|
@ -53,10 +53,14 @@ void p2tgl_chat_update (PurpleChat *chat, tgl_peer_id_t id, int admin_id, const
|
|||
}
|
||||
|
||||
void tgp_chat_on_loaded_chat_full (struct tgl_state *TLS, struct tgl_chat *C) {
|
||||
connection_data *conn = TLS->ev_base;
|
||||
|
||||
PurpleChat *PC = p2tgl_chat_find (TLS, C->id);
|
||||
if (!PC) {
|
||||
PC = p2tgl_chat_new (TLS, C);
|
||||
purple_blist_add_chat (PC, NULL, NULL);
|
||||
if (purple_account_get_bool (conn->pa, TGP_KEY_JOIN_GROUP_CHATS, TGP_DEFAULT_JOIN_GROUP_CHATS)) {
|
||||
purple_blist_add_chat (PC, NULL, NULL);
|
||||
}
|
||||
}
|
||||
p2tgl_chat_update (PC, C->id, C->admin_id, C->print_title);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "tgp-2prpl.h"
|
||||
#include <purple.h>
|
||||
|
||||
PurpleChat *p2tgl_chat_new (struct tgl_state *TLS, struct tgl_chat *chat);
|
||||
|
||||
void tgp_chat_on_loaded_chat_full (struct tgl_state *TLS, struct tgl_chat *C);
|
||||
PurpleConversation *tgp_chat_show (struct tgl_state *TLS, struct tgl_chat *C);
|
||||
void tgp_chat_users_update (struct tgl_state *TLS, struct tgl_chat *C);
|
||||
|
|
Loading…
Add table
Reference in a new issue