void pending_reads_send_all (struct tgl_state *TLS) { if (! purple_account_get_bool (tls_get_pa (TLS), TGP_KEY_SEND_READ_NOTIFICATIONS, TGP_DEFAULT_SEND_READ_NOTIFICATIONS)) { debug ("automatic read recipes disabled, not sending recipes"); return; } if (! p2tgl_status_is_present (purple_account_get_active_status (tls_get_pa (TLS)))) { debug ("user is not present, not sending recipes"); return; } debug ("sending all pending recipes"); g_hash_table_foreach (tls_get_data (TLS)->pending_reads, tgl_do_mark_read_gw, TLS); g_hash_table_remove_all (tls_get_data (TLS)->pending_reads); }
static void tgp_info_load_photo_done (struct tgl_state *TLS, void *extra, int success, const char *filename) { tgl_peer_t *P = extra; g_return_if_fail(success); gchar *img = NULL; size_t len; GError *err = NULL; g_file_get_contents (filename, &img, &len, &err); if (err) { failure ("getting file contents for %s failed: %s", filename, err->message); return; } if (tgl_get_peer_type (P->id) == TGL_PEER_USER || tgl_get_peer_type (P->id) == TGL_PEER_ENCR_CHAT) { PurpleBuddy *B = tgp_blist_buddy_find (TLS, P->id); g_return_if_fail(B); purple_buddy_icons_set_for_user (tls_get_pa (TLS), purple_buddy_get_name (B), (guchar*) img, len, NULL); tgp_info_update_photo_id (&B->node, P->user.photo_big.local_id); } else { PurpleChat *C = tgp_blist_chat_find (TLS, P->id); g_return_if_fail(C); purple_buddy_icons_node_set_custom_icon (&C->node, (guchar*) img, len); tgp_info_update_photo_id (&C->node, P->user.photo_big.local_id); } }
void tgp_msg_sys_out (struct tgl_state *TLS, const char *msg, tgl_peer_id_t to_id, int no_log) { int flags = PURPLE_MESSAGE_SYSTEM; if (no_log) { flags |= PURPLE_MESSAGE_NO_LOG; } time_t now; time (&now); switch (tgl_get_peer_type (to_id)) { case TGL_PEER_CHAT: p2tgl_got_chat_in (TLS, to_id, to_id, msg, flags, now); break; case TGL_PEER_USER: case TGL_PEER_ENCR_CHAT: { const char *name = tgp_blist_lookup_purple_name (TLS, to_id); PurpleConversation *conv = p2tgl_find_conversation_with_account (TLS, to_id); g_return_if_fail (name); if (! conv) { conv = purple_conversation_new (PURPLE_CONV_TYPE_IM, tls_get_pa (TLS), name); } purple_conversation_write (conv, name, msg, flags, now); break; } } }
void tgp_chat_on_loaded_chat_full (struct tgl_state *TLS, struct tgl_chat *C) { PurpleChat *PC = tgp_blist_chat_find (TLS, C->id); if (!PC) { PC = p2tgl_chat_new (TLS, C); if (purple_account_get_bool (tls_get_pa (TLS), TGP_KEY_JOIN_GROUP_CHATS, TGP_DEFAULT_JOIN_GROUP_CHATS)) { purple_blist_add_chat (PC, tgp_blist_group_init ("Telegram Chats"), NULL); } } p2tgl_chat_update (TLS, PC, C->id, C->admin_id, C->print_title); }
PurpleChat *p2tgl_chat_new (struct tgl_state *TLS, struct tgl_chat *chat) { return purple_chat_new (tls_get_pa (TLS), chat->title, tgp_chat_info_new (TLS, chat)); }