diff --git a/msglog.c b/msglog.c index 8064060..3aba098 100644 --- a/msglog.c +++ b/msglog.c @@ -72,3 +72,43 @@ void fatal(const char* format, ...) { va_end (ap); info ("\n"); } + +const char *print_flags_update (unsigned flags) { + static char *text = NULL; + const char *names[16] = { + "CREATED", + "DELETED", + "PHONE", + "CONTACT", + "PHOTO", + "BLOCKED", + "REAL_NAME", + "NAME", + "REQUESTED", + "WORKING", + "FLAGS", + "TITLE", + "ADMIN", + "MEMBERS", + "ACCESS_HASH", + "USERNAME" + }; + if (text) { + g_free (text); + text = NULL; + } + for (int i = 0; i < 16; i ++) { + if (flags & 1) { + char *new; + if (text) { + new = g_strconcat (text, " ", names[i], NULL); + g_free (text); + } else { + new = g_strdup (names[i]); + } + text = new; + } + flags >>= 1; + } + return (const char*)text; +} diff --git a/msglog.h b/msglog.h index 7e728b4..ef05872 100644 --- a/msglog.h +++ b/msglog.h @@ -24,4 +24,4 @@ void info(const char* format, ...); void warning(const char* format, ...); void failure(const char* format, ...); void fatal(const char* format, ...); - +const char *print_flags_update (unsigned update); diff --git a/telegram-purple.c b/telegram-purple.c index 9c57b3e..4304201 100644 --- a/telegram-purple.c +++ b/telegram-purple.c @@ -116,6 +116,7 @@ static void _update_buddy (struct tgl_state *TLS, tgl_peer_t *user, unsigned fla } static void update_user_handler (struct tgl_state *TLS, struct tgl_user *user, unsigned flags) { + debug ("update_user_handler() flags: %s", print_flags_update (flags)); if (tgl_get_peer_id (TLS->our_id) == tgl_get_peer_id (user->id) && (flags & (TGL_UPDATE_NAME | TGL_UPDATE_CONTACT))) { // own user object, do not add that user to the buddy list but make the ID known to the name lookup and // set the print name as the name to be displayed in IM chats instead of the login name (the phone number) @@ -172,7 +173,7 @@ static void update_user_status_handler (struct tgl_state *TLS, struct tgl_user * static void update_secret_chat_handler (struct tgl_state *TLS, struct tgl_secret_chat *U, unsigned flags) { PurpleBuddy *buddy = tgp_blist_buddy_find (TLS, U->id); connection_data *conn = TLS->ev_base; - debug ("update_secret_chat_handler: state=%d", U->state); + debug ("update_secret_chat_handler() flags: %s", print_flags_update (flags)); if (flags & TGL_UPDATE_CREATED) { tgp_blist_peer_add_purple_name (TLS, U->id, U->print_name); @@ -211,10 +212,11 @@ static void update_secret_chat_handler (struct tgl_state *TLS, struct tgl_secret } static void update_chat_handler (struct tgl_state *TLS, struct tgl_chat *chat, unsigned flags) { + debug ("update_chat_handler() flags: %s", print_flags_update(flags)); + if (flags & TGL_UPDATE_CREATED) { tgp_blist_peer_add_purple_name (TLS, chat->id, chat->print_title); } - if (! (flags & TGL_UPDATE_CREATED)) { PurpleChat *ch = tgp_blist_chat_find (TLS, chat->id);