From c65d7e26a7a58180a61221e9070688ff9621676d Mon Sep 17 00:00:00 2001 From: "polu.sandeep" Date: Fri, 4 Dec 2015 11:05:43 +0900 Subject: [PATCH] Added delete, forward message APIs and implemented offline message feature. Change-Id: I758556d703bdf0ecea6ea029ba0b467473b03837 --- tg-engine-service/inc/server_response.h | 2 + tg-engine-service/inc/tg_db_wrapper.h | 2 + tg-engine-service/src/server_response.c | 16 +++ tg-engine-service/src/tg-engine-service.c | 43 ++++++- tg-engine-service/src/tg_db_wrapper.c | 184 ++++++++++++++++++++++++++++++ tg-engine-service/tg_engine/tg_engine.c | 167 +++++++++++++++++++++------ tg-engine-service/tg_engine/tg_engine.h | 2 + 7 files changed, 378 insertions(+), 38 deletions(-) diff --git a/tg-engine-service/inc/server_response.h b/tg-engine-service/inc/server_response.h index 567373e..67a8724 100644 --- a/tg-engine-service/inc/server_response.h +++ b/tg-engine-service/inc/server_response.h @@ -14,6 +14,8 @@ extern void process_registration_command(tg_engine_data_s *tg_data, char *phone_ extern void process_validation_command(tg_engine_data_s *tg_data, char *code); extern void process_logout_command(tg_engine_data_s *tg_data); extern void process_send_message_command(int buddy_id, int message_id, int msg_type, char* msg_data, int type_of_chat); +extern void process_typing_status_to_buddy_command(int buddy_id, int type_of_chat, int typing_status); +extern void process_forward_message_command(int to_id, int type_of_chat, int from_id, int message_id, int temp_message_id); extern void process_marked_as_read_command(int buddy_id, int type_of_chat); extern void process_delete_group_chat_request(tg_engine_data_s* tg_data, int chat_id); extern void process_delete_selected_group_chats_request(tg_engine_data_s* tg_data, Eina_List *sel_grp_chats); diff --git a/tg-engine-service/inc/tg_db_wrapper.h b/tg-engine-service/inc/tg_db_wrapper.h index 95943f9..599350b 100644 --- a/tg-engine-service/inc/tg_db_wrapper.h +++ b/tg-engine-service/inc/tg_db_wrapper.h @@ -245,6 +245,8 @@ Eina_Bool is_chat_id_already_exists(struct tgl_chat *C); struct tgl_message* get_latest_message_from_message_table(char* table_name); +struct tgl_message* get_message_from_message_tableby_message_id(char* table_name, int id); + int insert_current_date_to_table(char* tb_name); struct tgl_media* get_media_details_from_db(long long media_id); diff --git a/tg-engine-service/src/server_response.c b/tg-engine-service/src/server_response.c index 6cd5bff..79e42af 100644 --- a/tg-engine-service/src/server_response.c +++ b/tg-engine-service/src/server_response.c @@ -65,6 +65,22 @@ void process_logout_command(tg_engine_data_s *tg_data) logout_telegram(tg_data); } +void process_forward_message_command(int to_id, int type_of_chat, int from_id, int message_id, int temp_message_id) +{ + if (!tgl_engine_get_TLS()) { + return; + } + forward_message_to_buddy(to_id, type_of_chat, from_id, message_id, temp_message_id); +} + +void process_typing_status_to_buddy_command(int buddy_id, int type_of_chat, int typing_status) +{ + if (!tgl_engine_get_TLS()) { + return; + } + send_typing_status_to_buddy(buddy_id, type_of_chat, typing_status); +} + void process_send_message_command(int buddy_id, int message_id, int msg_type, char* msg_data, int type_of_chat) { if (!msg_data || !tgl_engine_get_TLS()) { diff --git a/tg-engine-service/src/tg-engine-service.c b/tg-engine-service/src/tg-engine-service.c index 45a5462..a20d2b5 100644 --- a/tg-engine-service/src/tg-engine-service.c +++ b/tg-engine-service/src/tg-engine-service.c @@ -156,9 +156,49 @@ static int _on_tg_server_msg_received_cb(void *data, bundle *const rec_msg) //send event to application - } else if (strcmp(cmd_key_val, "restart_server") == 0) { on_restart_service_requested(tg_data); + + } else if (strcmp(cmd_key_val, "send_typing_status") == 0) { + + char* buddy_id_str = NULL; + res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str); + int buddy_id = atoi(buddy_id_str); + + char* type_of_chat_str = NULL; + res = bundle_get_str(rec_msg, "type_of_chat", &type_of_chat_str); + int type_of_chat = atoi(type_of_chat_str); + + char* typing_status_str = NULL; + res = bundle_get_str(rec_msg, "typing_status", &typing_status_str); + int typing_status = atoi(typing_status_str); + + process_typing_status_to_buddy_command(buddy_id, type_of_chat, typing_status); + + } else if (strcmp(cmd_key_val, "message_forward") == 0) { + + char* from_id_str = NULL; + res = bundle_get_str(rec_msg, "from_id", &from_id_str); + int from_id = atoi(from_id_str); + + char* to_id_str = NULL; + res = bundle_get_str(rec_msg, "to_id", &to_id_str); + int to_id = atoi(to_id_str); + + char* type_of_chat_str = NULL; + res = bundle_get_str(rec_msg, "type_of_chat", &type_of_chat_str); + int type_of_chat = atoi(type_of_chat_str); + + char* message_id_str = NULL; + res = bundle_get_str(rec_msg, "message_id", &message_id_str); + int message_id = atoi(message_id_str); + + char* temp_message_id_str = NULL; + res = bundle_get_str(rec_msg, "temp_message_id", &temp_message_id_str); + int temp_message_id = atoi(temp_message_id_str); + + process_forward_message_command(to_id, type_of_chat, from_id, message_id, temp_message_id); + } else if (strcmp(cmd_key_val, "message_transport") == 0) { char* buddy_id_str = NULL; @@ -683,6 +723,7 @@ bool service_app_create(void *data) tg_data->current_chat_index = 0; tg_data->buddy_list = NULL; tg_data->current_buddy_index = 0; + tg_data->is_first_time_registration = EINA_FALSE; //tg_data->is_loading_completed = EINA_FALSE; RETVM_IF(!tg_data->tg_server, SVC_RES_FAIL, "Failed to create proxy client"); diff --git a/tg-engine-service/src/tg_db_wrapper.c b/tg-engine-service/src/tg_db_wrapper.c index d3fae68..28bf77b 100644 --- a/tg-engine-service/src/tg_db_wrapper.c +++ b/tg-engine-service/src/tg_db_wrapper.c @@ -710,6 +710,11 @@ int set_date_item_to_table(char* tb_name, int recent_msg_date) if (old_lt.tm_mday == new_lt.tm_mday && old_lt.tm_mon == new_lt.tm_mon && old_lt.tm_year == new_lt.tm_year) { // no need of new date + if (last_msg->message) { + free(last_msg->message); + } + free(last_msg); + return -1; } else { int cur_time = recent_msg_date; @@ -741,6 +746,12 @@ int set_date_item_to_table(char* tb_name, int recent_msg_date) date_msg.unread = 0; date_msg.out = 0; insert_msg_into_db(&date_msg, tb_name, t); + + if (last_msg->message) { + free(last_msg->message); + } + free(last_msg); + return date_msg.id; } @@ -798,6 +809,11 @@ int update_current_date_to_table(char* tb_name, int recent_msg_date) if (old_lt.tm_mday == new_lt.tm_mday && old_lt.tm_mon == new_lt.tm_mon && old_lt.tm_year == new_lt.tm_year) { // no need of new date + if (last_msg->message) { + free(last_msg->message); + } + free(last_msg); + return -1; } else { int cur_time = time(NULL); @@ -829,6 +845,11 @@ int update_current_date_to_table(char* tb_name, int recent_msg_date) date_msg.unread = 0; date_msg.out = 0; insert_msg_into_db(&date_msg, tb_name, t); + if (last_msg->message) { + free(last_msg->message); + } + free(last_msg); + return date_msg.id; } @@ -887,6 +908,11 @@ int insert_current_date_to_table(char* tb_name) if (old_lt.tm_mday == new_lt.tm_mday && old_lt.tm_mon == new_lt.tm_mon && old_lt.tm_year == new_lt.tm_year) { // no need of new date + if (last_msg->message) { + free(last_msg->message); + } + free(last_msg); + return -1; } else { int cur_time = time(NULL); @@ -918,6 +944,11 @@ int insert_current_date_to_table(char* tb_name) date_msg.unread = 0; date_msg.out = 0; insert_msg_into_db(&date_msg, tb_name, t); + if (last_msg->message) { + free(last_msg->message); + } + free(last_msg); + return date_msg.id; } @@ -1039,6 +1070,158 @@ struct tgl_message* get_latest_message_from_message_table(char* table_name) free(temp_flags); } + int *temp_fwd_from_id = (int*)eina_list_nth(ts_msg, 2); + if (temp_fwd_from_id) { + message->fwd_from_id.id = *temp_fwd_from_id; + free(temp_fwd_from_id); + } + + int *temp_fwd_date = (int*)eina_list_nth(ts_msg, 3); + if (temp_fwd_date) { + message->fwd_date = *temp_fwd_date; + free(temp_fwd_date); + } + + + int *temp_from_id = (int*)eina_list_nth(ts_msg, 4); + if (temp_from_id) { + message->from_id.id = *temp_from_id; + free(temp_from_id); + } + + int *temp_to_id = (int*)eina_list_nth(ts_msg, 5); + if (temp_to_id) { + message->to_id.id = *temp_to_id; + free(temp_to_id); + } + + int *temp_out = (int*)eina_list_nth(ts_msg, 6); + if (temp_out) { + message->out = *temp_out; + free(temp_out); + } + + int *temp_unread = (int*)eina_list_nth(ts_msg, 7); + if (temp_unread) { + message->unread = *temp_unread; + free(temp_unread); + } + + int *temp_date = (int*)eina_list_nth(ts_msg, 8); + if (temp_date) { + message->date = *temp_date; + free(temp_date); + } + + int *temp_service = (int*)eina_list_nth(ts_msg, 9); + if (temp_service) { + message->service = *temp_service; + free(temp_service); + } + + char *temp_msg = (char*)eina_list_nth(ts_msg, 10); + if (temp_msg) { + message->message = strdup(temp_msg); + free(temp_msg); + } + + int *temp_message_state = (int*)eina_list_nth(ts_msg, 11); + if (temp_message_state) { + message->msg_state = *temp_message_state; + free(temp_message_state); + } + + int *temp_message_len = (int*)eina_list_nth(ts_msg, 12); + if (temp_message_len) { + message->message_len = *temp_message_len; + free(temp_message_len); + } + + int *temp_media_type = (int*)eina_list_nth(ts_msg, 13); + if (temp_media_type) { + message->media.type = *temp_media_type; + free(temp_media_type); + } + // to do, get media id based on media type + } + return message; +} + + +struct tgl_message* get_message_from_message_tableby_message_id(char *table_name, int msg_id) +{ + struct tgl_message* message = NULL; + Eina_List* message_details = NULL; + + Eina_List* col_names = NULL; + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_ID); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FLAGS); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_FROM_ID); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_DATE); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FROM_ID); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_TO_ID); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_OUT_MSG); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNREAD); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_DATE); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_SERVICE); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_STATE); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_LENGTH); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_TYPE); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_ID); + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNIQUE_ID); + + Eina_List* col_types = NULL; + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT); + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT); + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + + char* where_clause = NULL; + char msg_id_str[50]; + sprintf(msg_id_str,"%d",msg_id); + where_clause = (char*)malloc(strlen(MESSAGE_INFO_TABLE_MESSAGE_ID) + strlen(" = ") + strlen(msg_id_str) + 1); + strcpy(where_clause, MESSAGE_INFO_TABLE_MESSAGE_ID); + strcat(where_clause, " = "); + strcat(where_clause, msg_id_str); + + //message_details = get_values_from_table_sync_order_by(table_name, col_names, col_types, MESSAGE_INFO_TABLE_DATE, EINA_FALSE, where_clause); + message_details = get_values_from_table_sync(table_name, col_names, col_types, where_clause); + + eina_list_free(col_names); + eina_list_free(col_types); + free(where_clause); + + if (message_details && eina_list_count(message_details) > 0) { + Eina_List* ts_msg = eina_list_nth(message_details, 0); + + message = (struct tgl_message*)malloc(sizeof(struct tgl_message)); + + + int *temp_msg_id = (int*)eina_list_nth(ts_msg, 0); + if (temp_msg_id) { + message->id = *temp_msg_id; + free(temp_msg_id); + } + + int *temp_flags = (int*)eina_list_nth(ts_msg, 1); + if (temp_flags) { + message->flags = *temp_flags; + free(temp_flags); + } + int *temp_fwd_from_id = (int*)eina_list_nth(ts_msg, 2); if (temp_fwd_from_id) { @@ -1210,6 +1393,7 @@ void update_peer_info_database(tgl_peer_t* UC, int is_unknown) strcat(where_clause, " = "); strcat(where_clause, user_id_str); ret = update_table(table_name, col_names, col_types, col_values, where_clause); + free(where_clause); } else { } diff --git a/tg-engine-service/tg_engine/tg_engine.c b/tg-engine-service/tg_engine/tg_engine.c index 2d4ebe8..3127776 100644 --- a/tg-engine-service/tg_engine/tg_engine.c +++ b/tg-engine-service/tg_engine/tg_engine.c @@ -518,7 +518,7 @@ void tg_get_string(struct tgl_state *TLS, const char *prompt, int flags, void(*c if (tg_data->tg_state == TG_ENGINE_STATE_REGISTRATION) { send_request_phone_num_again(tg_data); } else { - tg_data->is_first_time_registration = EINA_TRUE; + //tg_data->is_first_time_registration = EINA_TRUE; tg_data->tg_state = TG_ENGINE_STATE_REGISTRATION; if (tg_data && tg_data->phone_number) { tg_data->get_string(TLS, tg_data->phone_number, tg_data->callback_arg); @@ -583,7 +583,7 @@ void tg_logged_in(struct tgl_state *TLS) tgl_peer_id_t t_id; t_id.id = TLS->our_id; t_id.type = TGL_PEER_USER; - tg_data->is_first_time_registration = EINA_TRUE; + //tg_data->is_first_time_registration = EINA_TRUE; create_data_base_tables(); tgl_do_get_user_info(TLS, t_id, offline_mode, &on_user_info_loaded, NULL); } @@ -1957,43 +1957,21 @@ static Eina_Bool send_chat_loading_is_done_response(void *data) return ECORE_CALLBACK_CANCEL; } - -void on_contacts_received(struct tgl_state *TLS, void *callback_extra, int success, int size, struct tgl_user *contacts[]) +void on_offline_chat_received(struct tgl_state *TLS, void *callback_extra, int success, int size, struct tgl_message *list[]) { - //tg_engine_data_s *tg_data = TLS->callback_data; - for (int i = size - 1; i >= 0; i--) { - struct tgl_user *buddy = contacts[i]; - char* msg_table = get_table_name_from_number(buddy->id.id); - create_buddy_msg_table(msg_table); - free(msg_table); - - if (buddy->id.id == 333000 || buddy->id.id == 777000) { - buddy->is_unknown = 1; - } else { - buddy->is_unknown = 0; + tg_engine_data_s *tg_data = TLS->callback_data; + for (int i = 0; i < size; i++) { + struct tgl_message* message = list[i]; + if (message->service || message->from_id.id == tg_data->id.id) { + continue; } - init_insert_buddy_into_db(BUDDY_INFO_TABLE_NAME, buddy); - tgl_peer_t* UC = tgl_peer_get(TLS, buddy->id); - if (UC) { - init_insert_peer_into_database(UC, 0, 0, 0); + Eina_Bool ret = insert_buddy_msg_to_db(message); + if (ret) { + tg_msg_receive(s_info.TLS, message); } } - - // inform client that contact loading is done. - //send_contacts_load_done_response(EINA_TRUE); - - for (int i = size - 1; i >= 0; i--) { - struct tgl_user *buddy = contacts[i]; - tgl_do_get_user_info(TLS, buddy->id, 0, on_buddy_info_loaded, NULL); - } - //send_response_for_server_connection_status(tg_data, tg_data->is_login_activated); - ecore_timer_add(3, on_send_unsent_messages_requested, TLS); - ecore_timer_add(6, on_load_buddy_history_requested, TLS); - //ecore_timer_add(12, send_chat_loading_is_done_response, TLS); - send_contacts_and_chats_load_done_response(TLS->callback_data, EINA_TRUE); } - void on_contacts_and_chats_loaded(struct tgl_state *TLS, void *callback_extra, int success, int size, tgl_peer_id_t peers[], int last_msg_id[], int unread_count[]) { tg_engine_data_s *tg_data = TLS->callback_data; @@ -2013,13 +1991,28 @@ void on_contacts_and_chats_loaded(struct tgl_state *TLS, void *callback_extra, i } // insert into peer table - insert_peer_into_database(UC, last_msg_id[i], unread_count[i], 0); switch (tgl_get_peer_type(peers[i])) { case TGL_PEER_USER: tg_data->buddy_list = eina_list_append(tg_data->buddy_list, UC); + + // check peer exists in peer table / buddy table + Eina_Bool is_buddy_present = is_user_present_buddy_table(UC->id.id); + if (!is_buddy_present) { + struct tgl_user* buddy = &(UC->user); + if (buddy) { + char* msg_table = get_table_name_from_number(buddy->id.id); + create_buddy_msg_table(msg_table); + free(msg_table); + + buddy->is_unknown = 1; + init_insert_buddy_into_db(BUDDY_INFO_TABLE_NAME, buddy); + insert_peer_into_database(UC, last_msg_id[i], unread_count[i], 1); + } + } break; case TGL_PEER_CHAT: tg_data->chat_list = eina_list_append(tg_data->chat_list, UC); + insert_peer_into_database(UC, last_msg_id[i], unread_count[i], 0); break; case TGL_PEER_ENCR_CHAT: // To-Do @@ -2027,8 +2020,77 @@ void on_contacts_and_chats_loaded(struct tgl_state *TLS, void *callback_extra, i default: break; } + + if (UC->id.id == 55544761) { + printf("Dummy id\n"); + } + + if (!tg_data->is_first_time_registration) { + struct tgl_message *last_msg = UC->last; + if (last_msg) { + // check last message in message table + char* msg_table = get_table_name_from_number(UC->id.id); + + struct tgl_message* org_last_msg = get_message_from_message_tableby_message_id(msg_table, last_msg->id); + + if (!org_last_msg) { + tgl_do_get_history(s_info.TLS, UC->id, 10, 0, on_offline_chat_received, UC); + } else { + if (org_last_msg->message) { + free(org_last_msg->message); + } + free(org_last_msg); + } + + free(msg_table); + } + } } + + ecore_timer_add(3, on_send_unsent_messages_requested, TLS); +#if 0 tgl_do_update_contact_list(TLS, on_contacts_received, NULL); +#else + send_contacts_and_chats_load_done_response(TLS->callback_data, EINA_TRUE); +#endif +} + +void on_contacts_received(struct tgl_state *TLS, void *callback_extra, int success, int size, struct tgl_user *contacts[]) +{ + //tg_engine_data_s *tg_data = TLS->callback_data; + for (int i = size - 1; i >= 0; i--) { + struct tgl_user *buddy = contacts[i]; + char* msg_table = get_table_name_from_number(buddy->id.id); + create_buddy_msg_table(msg_table); + free(msg_table); + + if (buddy->id.id == 333000 || buddy->id.id == 777000) { + buddy->is_unknown = 1; + } else { + buddy->is_unknown = 0; + } + init_insert_buddy_into_db(BUDDY_INFO_TABLE_NAME, buddy); + tgl_peer_t* UC = tgl_peer_get(TLS, buddy->id); + if (UC) { + init_insert_peer_into_database(UC, 0, 0, 0); + } + } + + // inform client that contact loading is done. + //send_contacts_load_done_response(EINA_TRUE); + + for (int i = size - 1; i >= 0; i--) { + struct tgl_user *buddy = contacts[i]; + tgl_do_get_user_info(TLS, buddy->id, 0, on_buddy_info_loaded, NULL); + } +#if 0 + //send_response_for_server_connection_status(tg_data, tg_data->is_login_activated); + ecore_timer_add(3, on_send_unsent_messages_requested, TLS); + //ecore_timer_add(6, on_load_buddy_history_requested, TLS); + send_contacts_and_chats_load_done_response(TLS->callback_data, EINA_TRUE); +#else + tgl_do_get_dialog_list(TLS, on_contacts_and_chats_loaded, NULL); +#endif } void add_contacts_to_account(struct tgl_state *TLS) @@ -2041,7 +2103,9 @@ void add_contacts_to_account(struct tgl_state *TLS) if (!contact_list || eina_list_count(contact_list) <= 0) { // no contacts avilable. empty contact list. - tgl_do_get_dialog_list(TLS, on_contacts_and_chats_loaded, NULL); + //tgl_do_get_dialog_list(TLS, on_contacts_and_chats_loaded, NULL); + // sandeep + tgl_do_update_contact_list(TLS, on_contacts_received, NULL); if (contact_list) { eina_list_free(contact_list); } @@ -2052,7 +2116,9 @@ void add_contacts_to_account(struct tgl_state *TLS) add_contacts_to_user(tg_data, size, contact_list); } else { eina_list_free(contact_list); - tgl_do_get_dialog_list(TLS, on_contacts_and_chats_loaded, NULL); + // sandeep + //tgl_do_get_dialog_list(TLS, on_contacts_and_chats_loaded, NULL); + tgl_do_update_contact_list(TLS, on_contacts_received, NULL); } } } @@ -2071,13 +2137,19 @@ void on_user_info_loaded(struct tgl_state *TLS, void *extra, int success, struct buddy->is_unknown = 0; init_insert_buddy_into_db(USER_INFO_TABLE_NAME, buddy); +#if 0 if (tg_data->is_first_time_registration) { // send contact list to add friends. //send_add_contacts_request(tg_data); add_contacts_to_account(TLS); } else { - tgl_do_get_dialog_list(TLS, on_contacts_and_chats_loaded, NULL); + // sandeep + //tgl_do_get_dialog_list(TLS, on_contacts_and_chats_loaded, NULL); + tgl_do_update_contact_list(TLS, on_contacts_received, NULL); } +#else + add_contacts_to_account(TLS); +#endif } void on_message_sent_to_buddy(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *message) @@ -3146,6 +3218,27 @@ void on_new_msg_requested_chat_info_received(struct tgl_state *TLS, void *callba free(msg_table); } #endif + +void forward_message_to_buddy(int to_id, int type_of_chat, int from_id, int message_id, int temp_message_id) +{ + char *msg_table = get_table_name_from_number(from_id); + struct tgl_message* msg = get_message_from_message_table(temp_message_id, msg_table); + + if (msg) { + tgl_peer_id_t id_to_send; + id_to_send.id = type_of_chat; + tgl_do_forward_message(s_info.TLS, id_to_send, message_id, &on_message_sent_to_buddy, (void*)(msg)); + } + free(msg_table); +} + +void send_typing_status_to_buddy(int buddy_id, int type_of_chat, int typing_status) +{ + tgl_peer_id_t id_to_send; + id_to_send.id = type_of_chat; + tgl_do_send_typing(s_info.TLS, id_to_send, typing_status, NULL, NULL); +} + void send_message_to_buddy(int buddy_id, int message_id, int msg_type, char *msg_data, int type_of_chat) { // get type of chat from buddy_id. diff --git a/tg-engine-service/tg_engine/tg_engine.h b/tg-engine-service/tg_engine/tg_engine.h index 459575a..643eaab 100644 --- a/tg-engine-service/tg_engine/tg_engine.h +++ b/tg-engine-service/tg_engine/tg_engine.h @@ -164,6 +164,8 @@ typedef struct contact_data { extern void send_do_mark_read_messages(int buddy_id, int type_of_chat); extern void send_message_to_buddy(int buddy_id, int message_id, int msg_type, char* msg_data, int type_of_chat); +extern void send_typing_status_to_buddy(int buddy_id, int type_of_chat, int typing_status); +extern void forward_message_to_buddy(int to_id, int type_of_chat, int from_id, int message_id, int temp_message_id); extern void send_media_to_buddy(int buddy_id, int message_id, int media_id, int msg_type, char* file_path, int type_of_chat); extern void logout_telegram(tg_engine_data_s *tg_data); extern void media_download_request(tg_engine_data_s *tg_data, int buddy_id, long long media_id); -- 2.7.4