From 1be69b1f8c6097ed3ab6e77aaf315026646cf656 Mon Sep 17 00:00:00 2001 From: "polu.sandeep" Date: Tue, 22 Dec 2015 13:50:39 +0900 Subject: [PATCH] Resolved Badge count isse. Implemented logout feature. Change-Id: Id18f8e85b0d400dd601f14645f7e4a4d801aeeff --- TelegramTizen/inc/tg_db_wrapper.h | 2 + TelegramTizen/src/telegramtizen.c | 135 +++++++++++++++++++++--------- TelegramTizen/src/tg_db_wrapper.c | 39 +++++++++ TelegramTizen/src/tg_messaging_view.c | 11 +++ tg-engine-service/src/tg-engine-service.c | 3 +- tg-engine-service/tg_engine/tg_engine.c | 4 +- 6 files changed, 152 insertions(+), 42 deletions(-) diff --git a/TelegramTizen/inc/tg_db_wrapper.h b/TelegramTizen/inc/tg_db_wrapper.h index d537cb7..eaa9657 100644 --- a/TelegramTizen/inc/tg_db_wrapper.h +++ b/TelegramTizen/inc/tg_db_wrapper.h @@ -235,6 +235,8 @@ int get_unread_message_count(char* table_name); extern void update_msg_into_db(tg_message_s *M, char* table_name); +extern Eina_Bool set_all_rows_read(const char *table_name); + void get_buddy_contact_details_from_db(int buddy_id, char **first_name, char **last_name, char **phone_number); char* get_buddy_name_from_id(int buddy_id); diff --git a/TelegramTizen/src/telegramtizen.c b/TelegramTizen/src/telegramtizen.c index e17c309..ea92e4c 100644 --- a/TelegramTizen/src/telegramtizen.c +++ b/TelegramTizen/src/telegramtizen.c @@ -2424,6 +2424,8 @@ static int on_buddy_contact_updated(appdata_s *app, bundle *const rec_msg) char* update_msg = NULL; result = bundle_get_str(rec_msg, "update_message", &update_msg); + // reload contact + return result; } @@ -2638,6 +2640,18 @@ static int on_user_status_updated(appdata_s *app, bundle *const rec_msg) return result; } +Eina_Bool on_logout_completed(void *data) +{ + appdata_s *ad = data; + if (ad) { + elm_naviframe_item_pop(ad->nf); + ad->current_app_state = TG_REGISTRATION_STATE; + launch_init_screen(ad); + } + return ECORE_CALLBACK_CANCEL; +} + + static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg) { int result = SVC_RES_FAIL; @@ -2685,11 +2699,8 @@ static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg) show_toast(app,"Server connection failed. please check network connection"); hide_loading_popup(app); } else if (strcmp(rec_key_val, "logout_completed") == 0) { - elm_naviframe_item_pop(app->nf); - elm_naviframe_item_pop(app->nf); - free_app_data(app, EINA_TRUE); - hide_loading_popup(app); + free_app_data(app, EINA_TRUE); app->phone_number = NULL; app->buddy_list = NULL; @@ -2722,8 +2733,10 @@ static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg) } init_service(app); - app->current_app_state = TG_REGISTRATION_STATE; - launch_init_screen(app); + hide_loading_popup(app); + elm_naviframe_item_pop(app->nf); + ecore_timer_add(1, on_logout_completed, app); + } if (strcmp(rec_key_val, "contacts_and_chats_load_done") == 0) { @@ -2926,11 +2939,24 @@ tg_main_list_item_s* get_latest_item(appdata_s *ad, peer_with_pic_s *item) } else if(media_type == tgl_message_media_photo) { item->last_message = strdup("Image"); } else if(media_type == tgl_message_media_document) { - if (msg->message && strlen(msg->message) > 0) { - item->last_message = strdup(msg->message); + tgl_media_s *media_msg = NULL; + media_msg = get_media_details_from_db(atoll(msg->media_id)); + + if (media_msg && media_msg->doc_type) { + if (strlen(media_msg->doc_type) > 0) { + item->last_message = strdup(media_msg->doc_type); + } else { + item->last_message = strdup("Document"); + } + free_media_details(media_msg); } else { - item->last_message = strdup("Document"); + if (msg->message && strlen(msg->message) > 0) { + item->last_message = strdup(msg->message); + } else { + item->last_message = strdup("Document"); + } } + } else if(media_type == tgl_message_media_geo) { item->last_message = strdup("Geo location"); } else if(media_type == tgl_message_media_contact) { @@ -2949,7 +2975,7 @@ tg_main_list_item_s* get_latest_item(appdata_s *ad, peer_with_pic_s *item) main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s)); main_list_item->peer_id = peer_info->peer_id; main_list_item->peer_type = peer_info->peer_type; - if (get_buddy_unknown_status(peer_info->peer_id)) { + if ((peer_info->peer_type == TGL_PEER_USER) && get_buddy_unknown_status(peer_info->peer_id)) { //set phone number main_list_item->peer_print_name = strdup(get_buddy_phone_num_from_id(peer_info->peer_id)); } else { @@ -2964,37 +2990,47 @@ tg_main_list_item_s* get_latest_item(appdata_s *ad, peer_with_pic_s *item) main_list_item->last_msg_status = msg->msg_state; main_list_item->last_msg_service = msg->service; main_list_item->number_of_unread_msgs = get_unread_message_count(tablename); - if (peer_info->photo_path) { - main_list_item->profile_pic_path = strdup(peer_info->photo_path); - } else { - main_list_item->profile_pic_path = NULL; - } + 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 (!first_name && !last_name && phone_num) { - first_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 (!last_name) { - last_name = ""; + if (!first_name && !last_name && phone_num) { + first_name = phone_num; + } + + 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 { main_list_item->buddy_display_name = strdup(""); } + + if (peer_info->photo_path) { + main_list_item->profile_pic_path = strdup(peer_info->photo_path); + } else { + main_list_item->profile_pic_path = NULL; + } main_list_item->user_name_lbl = NULL; main_list_item->status_lbl = NULL; main_list_item->date_lbl = NULL; @@ -3021,7 +3057,7 @@ tg_main_list_item_s* get_latest_item(appdata_s *ad, peer_with_pic_s *item) main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s)); main_list_item->peer_id = peer_info->peer_id; main_list_item->peer_type = peer_info->peer_type; - if (get_buddy_unknown_status(peer_info->peer_id)) { + if ((peer_info->peer_type == TGL_PEER_USER) && get_buddy_unknown_status(peer_info->peer_id)) { //set phone number main_list_item->peer_print_name = strdup(get_buddy_phone_num_from_id(peer_info->peer_id)); } else { @@ -3036,12 +3072,6 @@ tg_main_list_item_s* get_latest_item(appdata_s *ad, peer_with_pic_s *item) main_list_item->last_msg_id = -1; main_list_item->last_msg_status = -1; main_list_item->number_of_unread_msgs = 0; - if (peer_info->photo_path) { - main_list_item->profile_pic_path = strdup(peer_info->photo_path); - } else { - main_list_item->profile_pic_path = NULL; - } - if (peer_info->peer_type == TGL_PEER_USER) { char *user_name = NULL; char *first_name = NULL; @@ -3049,11 +3079,15 @@ tg_main_list_item_s* get_latest_item(appdata_s *ad, peer_with_pic_s *item) 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 && !last_name && phone_num) { first_name = phone_num; } - if (!last_name) { + if (!last_name || strstr(last_name ,"null") != 0) { last_name = ""; } user_name = (char*)malloc(strlen(first_name) + strlen(" ") + strlen(last_name) + 1); @@ -3067,6 +3101,11 @@ tg_main_list_item_s* get_latest_item(appdata_s *ad, peer_with_pic_s *item) main_list_item->buddy_display_name = strdup(""); } + if (peer_info->photo_path) { + main_list_item->profile_pic_path = strdup(peer_info->photo_path); + } else { + main_list_item->profile_pic_path = NULL; + } main_list_item->user_name_lbl = NULL; main_list_item->status_lbl = NULL; main_list_item->date_lbl = NULL; @@ -3109,6 +3148,16 @@ void app_nf_back_cb(void *data, Evas_Object *obj, void *event_info) if (ad->main_list) { if (ad->main_item_in_cahtting_data) { + + int buddy_id = ad->main_item_in_cahtting_data->peer_id; + char* tablename = get_table_name_from_number(buddy_id); + + Eina_Bool res = set_all_rows_read(tablename); + if (!res) { + //failed. + } + free(tablename); + tg_main_list_item_s* old_item = ad->main_item_in_cahtting_data; ad->main_list = eina_list_remove(ad->main_list, ad->main_item_in_cahtting_data); if (old_item->peer_print_name) { @@ -3148,6 +3197,14 @@ void app_nf_back_cb(void *data, Evas_Object *obj, void *event_info) if (ad->peer_in_cahtting_data) { peer_with_pic_s *item = ad->peer_in_cahtting_data; if (item) { + int buddy_id = item->use_data->peer_id; + char* tablename = get_table_name_from_number(buddy_id); + Eina_Bool res = set_all_rows_read(tablename); + if (!res) { + //failed. + } + free(tablename); + tg_peer_info_s* peer_info = item->use_data; if(peer_info) { //if (peer_info->last_msg_id > 0) { diff --git a/TelegramTizen/src/tg_db_wrapper.c b/TelegramTizen/src/tg_db_wrapper.c index 2a1fcc7..6d6d019 100644 --- a/TelegramTizen/src/tg_db_wrapper.c +++ b/TelegramTizen/src/tg_db_wrapper.c @@ -1829,7 +1829,46 @@ tg_message_s* get_latest_message_from_message_table(char* table_name) } } return message; +} + +Eina_Bool set_all_rows_read(const char *table_name) +{ + if (!table_name) + return EINA_FALSE; + + Eina_List* col_names = NULL; + col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNREAD); + + Eina_List* col_types = NULL; + col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER); + + Eina_List* col_values = NULL; + int un_read_res = 0; + col_values = eina_list_append(col_values, &(un_read_res)); + + char* where_clause = NULL; + char usr_str[50]; + int un_read = 1; + sprintf(usr_str,"%d", un_read); + where_clause = (char*)malloc(strlen(MESSAGE_INFO_TABLE_UNREAD) + strlen(" = ") + strlen(usr_str) + 1); + strcpy(where_clause, MESSAGE_INFO_TABLE_UNREAD); + strcat(where_clause, " = "); + strcat(where_clause, usr_str); + + Eina_Bool ret = update_table(table_name, col_names, col_types, col_values, where_clause); + + if(!ret) { + //("error: database creation failed"); + } else { + } + + free(where_clause); + eina_list_free(col_names); + eina_list_free(col_types); + eina_list_free(col_values); + + return EINA_TRUE; } void update_msg_into_db(tg_message_s *M, char* table_name) diff --git a/TelegramTizen/src/tg_messaging_view.c b/TelegramTizen/src/tg_messaging_view.c index 6fa6622..2f76aee 100644 --- a/TelegramTizen/src/tg_messaging_view.c +++ b/TelegramTizen/src/tg_messaging_view.c @@ -1446,11 +1446,13 @@ Evas_Object *on_message_item_content_get_cb(void *data, Evas_Object *obj, const //Eina_Bool is_blur_image = EINA_FALSE; if (msg) { +#if 0 if (msg->unread) { msg->unread = 0; update_msg_into_db(msg, tablename); ad->is_last_msg_changed = EINA_TRUE; } +#endif if (msg->out) { } else { @@ -3680,6 +3682,15 @@ void launch_messaging_view_cb(appdata_s* ad, int user_id) Eina_Bool ret = load_chat_history(chat_scroller); + int buddy_id = sel_item->use_data->peer_id; + char* tablename = get_table_name_from_number(buddy_id); + + Eina_Bool res = set_all_rows_read(tablename); + if (!res) { + //failed. + } + free(tablename); + if (!ret) { LOGD("There is no message in chat room"); // show no messages diff --git a/tg-engine-service/src/tg-engine-service.c b/tg-engine-service/src/tg-engine-service.c index c430ca1..2719f0c 100644 --- a/tg-engine-service/src/tg-engine-service.c +++ b/tg-engine-service/src/tg-engine-service.c @@ -139,7 +139,6 @@ static int _on_tg_server_msg_received_cb(void *data, bundle *const rec_msg) #else int ret = recursive_dir_delete(DEFAULT_TELEGRAM_PATH); #endif - send_response_for_logout(tg_data); tgl_engine_var_init(); tg_db_init(); tg_data->tg_state = TG_ENGINE_STATE_NONE; @@ -161,6 +160,8 @@ static int _on_tg_server_msg_received_cb(void *data, bundle *const rec_msg) //send event to application + send_response_for_logout(tg_data); + } else if (strcmp(cmd_key_val, "restart_server") == 0) { on_restart_service_requested(tg_data); diff --git a/tg-engine-service/tg_engine/tg_engine.c b/tg-engine-service/tg_engine/tg_engine.c index dc698fb..7b7df3e 100644 --- a/tg-engine-service/tg_engine/tg_engine.c +++ b/tg-engine-service/tg_engine/tg_engine.c @@ -2237,7 +2237,7 @@ void on_contacts_received(struct tgl_state *TLS, void *callback_extra, int succe 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); + insert_peer_into_database(UC, 0, 0, 0); } } @@ -3241,7 +3241,7 @@ void on_new_buddy_added(struct tgl_state *TLS,void *callback_extra, int success, 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); + insert_peer_into_database(UC, 0, 0, 0); } tgl_do_get_user_info(TLS, buddy->id, 0, on_buddy_info_loaded, NULL); -- 2.7.4