From 49769fb0b7e9b6ccdcc5b7726f5fd606922b7d61 Mon Sep 17 00:00:00 2001 From: "polu.sandeep" Date: Fri, 27 Nov 2015 11:06:41 +0900 Subject: [PATCH] Implemented Unknown user handling in group chat and one to one chat. Implemented message deletion APIs. Implemented use profile pic update notification in messaging view. Change-Id: Ibd1da842c77fcdd86ff0c47f48c23337a557141c --- TelegramTizen/inc/tg_messaging_view.h | 1 + TelegramTizen/src/telegramtizen.c | 46 +++++++++++++-------- TelegramTizen/src/tg_messaging_view.c | 13 ++++++ tg-engine-service/inc/server_response.h | 2 + tg-engine-service/inc/tg_db_wrapper.h | 1 + tg-engine-service/src/server_response.c | 59 +++++++++++++++++++++++++++ tg-engine-service/src/tg-engine-service.c | 12 ++++++ tg-engine-service/src/tg_db_wrapper.c | 37 +++++++++++++++++ tg-engine-service/tg_engine/tg_engine.c | 48 ++++++++++++++++++++-- tg-engine-service/tg_engine/tg_engine.h | 1 + tg-engine-service/tg_engine_utils/tg_common.h | 5 +++ 11 files changed, 203 insertions(+), 22 deletions(-) diff --git a/TelegramTizen/inc/tg_messaging_view.h b/TelegramTizen/inc/tg_messaging_view.h index 7045906..3da1a20 100644 --- a/TelegramTizen/inc/tg_messaging_view.h +++ b/TelegramTizen/inc/tg_messaging_view.h @@ -18,6 +18,7 @@ extern void on_media_download_completed(appdata_s* ad, int buddy_id, long long m extern void on_user_presence_state_changed(appdata_s* ad, int buddy_id); extern void on_user_status_changed(appdata_s* ad, char* status); extern void on_group_chat_info_changed(appdata_s *ad, char *type_of_change); +extern void on_chat_profile_pic_changed(appdata_s *ad, char *file_path); extern void on_messaging_menu_button_clicked(void *data, Evas_Object *obj, void *event_info); extern void refresh_messaging_view(appdata_s *ad); #endif /* TG_MESSAGING_VIEW_H_ */ diff --git a/TelegramTizen/src/telegramtizen.c b/TelegramTizen/src/telegramtizen.c index 30607a5..7c715cd 100644 --- a/TelegramTizen/src/telegramtizen.c +++ b/TelegramTizen/src/telegramtizen.c @@ -441,28 +441,32 @@ void load_main_list_data(appdata_s *ad) if (peer_info->peer_type == TGL_PEER_USER) { - char *user_name = NULL; - char *first_name = NULL; - char *last_name = NULL; - char *phone_num = NULL; - get_buddy_contact_details_from_db(peer_info->peer_id, &first_name, &last_name, &phone_num); + if (peer_info->is_unknown == 1) { + main_list_item->buddy_display_name = get_buddy_phone_num_from_id(peer_info->peer_id); + } else { + char *user_name = NULL; + char *first_name = NULL; + char *last_name = NULL; + char *phone_num = NULL; + get_buddy_contact_details_from_db(peer_info->peer_id, &first_name, &last_name, &phone_num); - if (!first_name || strstr(first_name ,"null") != 0) { - first_name = NULL; - } + if (!first_name || strstr(first_name ,"null") != 0) { + first_name = NULL; + } - if (!first_name && !last_name && phone_num) { - first_name = phone_num; - } + if (!first_name && !last_name && phone_num) { + first_name = phone_num; + } - if (!last_name || strstr(last_name ,"null") != 0) { - last_name = ""; + if (!last_name || strstr(last_name ,"null") != 0) { + last_name = ""; + } + user_name = (char*)malloc(strlen(first_name) + strlen(" ") + strlen(last_name) + 1); + strcpy(user_name, first_name); + strcat(user_name, " "); + strcat(user_name, last_name); + main_list_item->buddy_display_name = user_name; } - user_name = (char*)malloc(strlen(first_name) + strlen(" ") + strlen(last_name) + 1); - strcpy(user_name, first_name); - strcat(user_name, " "); - strcat(user_name, last_name); - main_list_item->buddy_display_name = user_name; } else if (peer_info->peer_type == TGL_PEER_CHAT) { main_list_item->buddy_display_name = replace(peer_info->print_name, '_', " "); } else { @@ -1478,6 +1482,12 @@ static int on_buddy_profile_pic_updated(appdata_s *app, bundle *const rec_msg) } } } + + if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->peer_in_cahtting_data + && app->peer_in_cahtting_data->use_data->peer_id == user_id) { + on_chat_profile_pic_changed(app, pic_file_path); + } + } return result; } diff --git a/TelegramTizen/src/tg_messaging_view.c b/TelegramTizen/src/tg_messaging_view.c index e1bac60..4c93b9b 100644 --- a/TelegramTizen/src/tg_messaging_view.c +++ b/TelegramTizen/src/tg_messaging_view.c @@ -350,6 +350,19 @@ static Evas_Object *create_image_object_from_file(const char *icon_name, Evas_Ob return icon; } +void on_chat_profile_pic_changed(appdata_s *ad, char *file_path) +{ + if (!ad || !file_path) { + return; + } + + Evas_Object *profile_image = evas_object_data_get(ad->nf, "profile_picture"); + if (profile_image) { + elm_image_file_set(profile_image, file_path, NULL); + } + +} + void on_group_chat_info_changed(appdata_s *ad, char *type_of_change) { if (!ad || !type_of_change) { diff --git a/tg-engine-service/inc/server_response.h b/tg-engine-service/inc/server_response.h index cbcc506..567373e 100644 --- a/tg-engine-service/inc/server_response.h +++ b/tg-engine-service/inc/server_response.h @@ -20,6 +20,7 @@ extern void process_delete_selected_group_chats_request(tg_engine_data_s* tg_dat extern void process_add_user_request(tg_engine_data_s* tg_data, int buddy_id, char *first_name, char *last_name, char *phone_num); extern void process_update_chat_request(tg_engine_data_s* tg_data, int chat_id); extern void process_delete_user_request(tg_engine_data_s* tg_data, int buddy_id); +extern void process_delete_message_request(tg_engine_data_s* tg_data, int buddy_id, int message_id); extern void process_send_secret_chat_request(tg_engine_data_s* tg_data, int buddy_id); extern void process_block_user_request(tg_engine_data_s* tg_data, int buddy_id); extern void process_unblock_user_request(tg_engine_data_s* tg_data, int buddy_id); @@ -34,6 +35,7 @@ extern void process_remove_buddy_from_chat_command(tg_engine_data_s *tg_data, in extern void process_set_group_chat_profile_pic_command(tg_engine_data_s *tg_data, int buddy_id, const char *file_path); extern void process_set_username_command(tg_engine_data_s *tg_data, int buddy_id, const char *username); extern void process_update_display_name_command(tg_engine_data_s *tg_data, int buddy_id, const char *first_name, const char *last_name); +extern void send_message_deleted_response(tg_engine_data_s *tg_data, int buddy_id, int message_id, Eina_Bool is_success); extern void send_add_contacts_request(tg_engine_data_s *tg_data); extern void send_server_not_initialized_response(tg_engine_data_s *tg_data); diff --git a/tg-engine-service/inc/tg_db_wrapper.h b/tg-engine-service/inc/tg_db_wrapper.h index 8d8645e..95943f9 100644 --- a/tg-engine-service/inc/tg_db_wrapper.h +++ b/tg-engine-service/inc/tg_db_wrapper.h @@ -268,6 +268,7 @@ Eina_List* get_all_unsent_media_messages(); Eina_List* get_all_unsent_text_messages(); void delete_message_from_unsent_db(int message_id); void delete_media_from_unsent_db(int message_id); +Eina_Bool is_user_present_buddy_table(int id); Eina_Bool is_user_present_peer_table(int id); Eina_Bool is_user_present_chat_table(int id); diff --git a/tg-engine-service/src/server_response.c b/tg-engine-service/src/server_response.c index cfae8da..6cd5bff 100644 --- a/tg-engine-service/src/server_response.c +++ b/tg-engine-service/src/server_response.c @@ -121,6 +121,14 @@ void process_delete_user_request(tg_engine_data_s* tg_data, int buddy_id) do_delete_buddy(buddy_id); } +void process_delete_message_request(tg_engine_data_s* tg_data, int buddy_id, int message_id) +{ + if (!tgl_engine_get_TLS()) { + return; + } + do_delete_message(buddy_id, message_id); +} + void process_block_user_request(tg_engine_data_s* tg_data, int buddy_id) { if (!tgl_engine_get_TLS()) { @@ -1115,6 +1123,57 @@ void send_buddy_deleted_response(tg_engine_data_s *tg_data, int buddy_id, Eina_B bundle_free(msg); } +void send_message_deleted_response(tg_engine_data_s *tg_data, int buddy_id, int message_id, Eina_Bool is_success) +{ + bundle *msg = bundle_create(); + if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { + ERR("Failed to add data by key to bundle"); + bundle_free(msg); + } + + if (bundle_add_str(msg, "command", "message_deleted") != 0) { + ERR("Failed to add data by key to bundle"); + bundle_free(msg); + } + + char usr_id_str[50]; + sprintf(usr_id_str,"%d",buddy_id); + + if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) { + ERR("Failed to add data by key to bundle"); + bundle_free(msg); + } + + char msg_id_str[50]; + sprintf(msg_id_str,"%d",message_id); + + if (bundle_add_str(msg, "message_id", msg_id_str) != 0) { + ERR("Failed to add data by key to bundle"); + bundle_free(msg); + } + + + if (is_success) { + if (bundle_add_str(msg, "is_success", "true") != 0) { + ERR("Failed to add data by key to bundle"); + bundle_free(msg); + } + } else { + if (bundle_add_str(msg, "is_success", "false") != 0) { + ERR("Failed to add data by key to bundle"); + bundle_free(msg); + } + } + int result = SVC_RES_FAIL; + result = tg_server_send_message(tg_data->tg_server, msg); + + if(result != SVC_RES_OK) { + // error: cient not ready + } + bundle_free(msg); +} + + void send_buddy_blocked_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success) { bundle *msg = bundle_create(); diff --git a/tg-engine-service/src/tg-engine-service.c b/tg-engine-service/src/tg-engine-service.c index 2a39cbe..45a5462 100644 --- a/tg-engine-service/src/tg-engine-service.c +++ b/tg-engine-service/src/tg-engine-service.c @@ -268,6 +268,18 @@ static int _on_tg_server_msg_received_cb(void *data, bundle *const rec_msg) process_delete_user_request(tg_data, buddy_id); + } else if (strcmp(cmd_key_val, "delete_message") == 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* message_id_str = NULL; + res = bundle_get_str(rec_msg, "message_id", &message_id_str); + int message_id = atoi(message_id_str); + + process_delete_message_request(tg_data, buddy_id, message_id); + } else if (strcmp(cmd_key_val, "block_buddy") == 0) { char* buddy_id_str = NULL; diff --git a/tg-engine-service/src/tg_db_wrapper.c b/tg-engine-service/src/tg_db_wrapper.c index afe1187..d3fae68 100644 --- a/tg-engine-service/src/tg_db_wrapper.c +++ b/tg-engine-service/src/tg_db_wrapper.c @@ -5005,6 +5005,43 @@ int get_number_of_unread_messages() return no_of_unread; } +Eina_Bool is_user_present_buddy_table(int peer_id) +{ + Eina_Bool ret = EINA_FALSE; + + Eina_List* peer_details = NULL; + char* table_name = BUDDY_INFO_TABLE_NAME; + + Eina_List* col_names = NULL; + col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME); + + Eina_List* col_types = NULL; + col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT); + + char chat_id_str[50]; + sprintf(chat_id_str, "%d", peer_id); + + char* where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(chat_id_str) + 1); + strcpy(where_clause, USER_INFO_TABLE_USER_ID); + strcat(where_clause, " = "); + strcat(where_clause, chat_id_str); + + peer_details = get_values_from_table_sync(table_name, col_names, col_types, where_clause); + free(where_clause); + if (peer_details) { + for (int i = 0; i < eina_list_count(peer_details) ; i++) { + Eina_List* ts_msg = eina_list_nth(peer_details, i); + ret = EINA_TRUE; + eina_list_free(ts_msg); + break; + } + eina_list_free(peer_details); + } + eina_list_free(col_names); + eina_list_free(col_types); + return ret; +} + Eina_Bool is_user_present_peer_table(int peer_id) { Eina_Bool ret = EINA_FALSE; diff --git a/tg-engine-service/tg_engine/tg_engine.c b/tg-engine-service/tg_engine/tg_engine.c index 857f8a7..2d4ebe8 100644 --- a/tg-engine-service/tg_engine/tg_engine.c +++ b/tg-engine-service/tg_engine/tg_engine.c @@ -1006,7 +1006,7 @@ void on_new_chat_info_received(struct tgl_state *TLS, void *callback_extra, int if (chat_info->user_list) { for (int i = 0; i < chat_info->user_list_size; i++) { int user_id = chat_info->user_list[i].user_id; - Eina_Bool is_present_in_db = is_user_present_peer_table(user_id); + Eina_Bool is_present_in_db = is_user_present_buddy_table(user_id); char* tb_name = get_table_name_from_number(user_id); create_buddy_msg_table(tb_name); if (!is_present_in_db) { @@ -1492,7 +1492,7 @@ void tg_msg_receive(struct tgl_state *TLS, struct tgl_message *M) } #else char* tb_name = get_table_name_from_number(user_id); - Eina_Bool is_present_in_db = is_user_present_peer_table(user_id); + Eina_Bool is_present_in_db = is_user_present_buddy_table(user_id); create_buddy_msg_table(tb_name); if (!is_present_in_db) { tgl_do_get_user_info(TLS, M->from_id, 0, on_new_buddy_info_loaded, M); @@ -1553,7 +1553,7 @@ void tg_msg_receive(struct tgl_state *TLS, struct tgl_message *M) // check whether user is present or not - Eina_Bool is_present_in_peer_db = is_user_present_peer_table(user_id); + Eina_Bool is_present_in_peer_db = is_user_present_buddy_table(user_id); if (!is_present_in_peer_db) { tgl_do_get_chat_info(TLS, M->to_id, 0, &on_requested_chat_info_received, M); @@ -1819,6 +1819,21 @@ void on_chat_info_received(struct tgl_state *TLS, void *callback_extra, int succ if (!chat_info->user_list) { tgl_do_get_chat_info(TLS, chat_info->id, 0, &on_chat_info_received, NULL); return; + } else { + for (int i = 0; i < chat_info->user_list_size; i++) { + int user_id = chat_info->user_list[i].user_id; + Eina_Bool is_present_in_db = is_user_present_buddy_table(user_id); + char* tb_name = get_table_name_from_number(user_id); + create_buddy_msg_table(tb_name); + if (!is_present_in_db) { + // add to buddy table + tgl_peer_id_t from_id; + from_id.id = user_id; + from_id.type = TGL_PEER_USER; + tgl_do_get_user_info(TLS, from_id, 0, on_new_buddy_info_loaded, NULL); + } + free(tb_name); + } } tg_data = TLS->callback_data; @@ -1945,7 +1960,7 @@ static Eina_Bool send_chat_loading_is_done_response(void *data) 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; + //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); @@ -2099,6 +2114,10 @@ void on_message_sent_to_buddy(struct tgl_state *TLS, void *callback_extra, int s char* tb_name = get_table_name_from_number(org_msg->to_id.id); update_msg_into_db(org_msg, tb_name, org_msg->id); if (org_msg->media.type == tgl_message_media_photo || org_msg->media.type == tgl_message_media_document || message->media.type == tgl_message_media_geo) { + if (org_msg->media.type == tgl_message_media_photo) { + org_msg->media.photo.sizes_num = 0; + org_msg->media.photo.sizes = NULL; + } update_sent_media_info_in_db(org_msg, (long long)org_msg->id); } send_message_sent_to_buddy_response(tg_data, org_msg->to_id.id, org_msg->id, tb_name, EINA_FALSE, tgl_get_peer_type(org_msg->to_id)); @@ -2974,6 +2993,27 @@ void do_delete_buddy(int buddy_id) tgl_do_del_contact(s_info.TLS, peer_id, &on_user_delete_response , (void*)(buddy_id)); } +void on_message_deleted(struct tgl_state *TLS, void *callback_extra, int success) +{ + msg_container_s *msg_details = (msg_container_s*)callback_extra; + tg_engine_data_s *tg_data = TLS->callback_data; + if (success) { + // update database + send_message_deleted_response(tg_data, msg_details->buddy_id, msg_details->message_id, EINA_TRUE); + } else { + send_message_deleted_response(tg_data, msg_details->buddy_id, msg_details->message_id, EINA_FALSE); + } +} + +void do_delete_message(int buddy_id, int message_id) +{ + msg_container_s *msg_details = (msg_container_s*)malloc(sizeof(msg_container_s)); + msg_details->buddy_id = buddy_id; + msg_details->message_id = message_id; + tgl_do_delete_msg(s_info.TLS, message_id, &on_message_deleted , (void*)(msg_details)); +} + + void do_block_buddy(int buddy_id) { tgl_peer_id_t peer_id; diff --git a/tg-engine-service/tg_engine/tg_engine.h b/tg-engine-service/tg_engine/tg_engine.h index dec0737..459575a 100644 --- a/tg-engine-service/tg_engine/tg_engine.h +++ b/tg-engine-service/tg_engine/tg_engine.h @@ -177,6 +177,7 @@ extern void free_contact_data(Eina_List *contact_data); extern void leave_group_chat(tg_engine_data_s *tg_data, int group_chat_id); extern void delete_selected_group_chat(tg_engine_data_s *tg_data, Eina_List *sel_grp_chats); extern void do_delete_buddy(int buddy_id); +extern void do_delete_message(int buddy_id, int message_id); extern void request_for_secret_chat(int buddy_id); extern void do_add_buddy(int buddy_id, char *first_name, char *last_name, char *phone_num); extern void do_update_chat_info(int chat_id); diff --git a/tg-engine-service/tg_engine_utils/tg_common.h b/tg-engine-service/tg_engine_utils/tg_common.h index 6829724..40ecc9b 100644 --- a/tg-engine-service/tg_engine_utils/tg_common.h +++ b/tg-engine-service/tg_engine_utils/tg_common.h @@ -25,6 +25,11 @@ typedef enum MESSAGE_STATE { TG_MESSAGE_STATE_UNKNOWN } TG_MESSAGE_STATE; +typedef struct msg_container { + int buddy_id; + int message_id; +} msg_container_s; + extern char *ui_utils_get_resource(const char *res_name); extern char *get_table_name_from_number(const int id); -- 2.7.4