void tgp_msg_recv (struct tgl_state *TLS, struct tgl_message *M) { connection_data *conn = TLS->ev_base; struct tgp_msg_loading *C = tgp_msg_loading_init (TRUE, M); if (M->date != 0 && M->date < tgp_msg_oldest_relevant_ts (TLS)) { debug ("Message from %d on %d too old, ignored.", tgl_get_peer_id (M->from_id), M->date); return; } if (M->media.type == tgl_message_media_photo) { C->done = FALSE; tgl_do_load_photo (TLS, M->media.photo, tgp_msg_on_loaded_document, C); } if (M->media.type == tgl_message_media_document_encr && M->media.encr_document->flags & TGLDF_IMAGE && !(M->media.encr_document->flags & TGLDF_STICKER)) { C->done = FALSE; tgl_do_load_encr_document (TLS, M->media.encr_document, tgp_msg_on_loaded_document, C); } #ifdef HAVE_LIBWEBP if (M->media.type == tgl_message_media_document && M->media.document->flags & TGLDF_STICKER) { C->done = FALSE; tgl_do_load_document (TLS, M->media.document, tgp_msg_on_loaded_document, C); } #endif if (M->media.type == tgl_message_media_geo) { // TODO: load geo thumbnail } g_queue_push_tail (conn->new_messages, C); tgp_msg_process_in_ready (TLS); }
void tgp_msg_recv (struct tgl_state *TLS, struct tgl_message *M) { connection_data *conn = TLS->ev_base; struct tgp_msg_loading *C = tgp_msg_loading_init (TRUE, M); if (M->date != 0 && M->date < tgp_msg_oldest_relevant_ts (TLS)) { debug ("Message from %d on %d too old, ignored.", tgl_get_peer_id (M->from_id), M->date); return; } if (M->media.type == tgl_message_media_photo) { C->done = FALSE; tgl_do_load_photo (TLS, &M->media.photo, tgp_msg_on_loaded_photo, C); } if (M->media.type == tgl_message_media_geo) { // TODO: load geo thumbnail } g_queue_push_tail (conn->new_messages, C); tgp_msg_process_ready (TLS); }
void tgp_msg_recv (struct tgl_state *TLS, struct tgl_message *M) { connection_data *conn = TLS->ev_base; if (M->flags & (TGLMF_EMPTY | TGLMF_DELETED)) { return; } if (!(M->flags & TGLMF_CREATED)) { return; } if (!(M->flags | TGLMF_UNREAD) && M->date != 0 && M->date < tgp_msg_oldest_relevant_ts (TLS)) { debug ("Message from %d on %d too old, ignored.", tgl_get_peer_id (M->from_id), M->date); return; } struct tgp_msg_loading *C = tgp_msg_loading_init (M); if (! (M->flags & TGLMF_SERVICE)) { // handle all messages that need to load content before they can be displayed if (M->media.type != tgl_message_media_none) { switch (M->media.type) { case tgl_message_media_photo: { // include the "bad photo" check from telegram-cli interface.c:3287 to avoid crashes when fetching history // TODO: find out the reason for this behavior if (M->media.photo) { ++ C->pending; tgl_do_load_photo (TLS, M->media.photo, tgp_msg_on_loaded_document, C); } break; } // documents that are stickers or images will be displayed just like regular photo messages // and need to be lodaed beforehand case tgl_message_media_document: case tgl_message_media_video: case tgl_message_media_audio: if (M->media.document->flags & TGLDF_STICKER || M->media.document->flags & TGLDF_IMAGE) { ++ C->pending; tgl_do_load_document (TLS, M->media.document, tgp_msg_on_loaded_document, C); } break; case tgl_message_media_document_encr: if (M->media.encr_document->flags & TGLDF_STICKER || M->media.encr_document->flags & TGLDF_IMAGE) { ++ C->pending; tgl_do_load_encr_document (TLS, M->media.encr_document, tgp_msg_on_loaded_document, C); } break; case tgl_message_media_geo: // TODO: load geo thumbnail break; default: // prevent Clang warnings ... break; } } } if (tgl_get_peer_type (M->to_id) == TGL_PEER_CHAT) { tgl_peer_t *P = tgl_peer_get (TLS, M->to_id); g_warn_if_fail(P); if (P && ! P->chat.user_list_size) { // To display a chat the full name of every single user is needed, but the updates received from the server only // contain the names of users mentioned in the events. In order to display a messages we always need to fetch the // full chat info first. If the user list is empty, this means that we still haven't fetched the full chat information. // assure that there is only one chat info request for every // chat to avoid causing FLOOD_WAIT_X errors that will lead to delays or dropped messages gpointer to_ptr = GINT_TO_POINTER(tgl_get_peer_id (M->to_id)); if (! g_hash_table_lookup (conn->pending_chat_info, to_ptr)) { ++ C->pending; tgl_do_get_chat_info (TLS, M->to_id, FALSE, tgp_msg_on_loaded_chat_full, C); g_hash_table_replace (conn->pending_chat_info, to_ptr, to_ptr); } } } g_queue_push_tail (conn->new_messages, C); tgp_msg_process_in_ready (TLS); }