From 0bef0e5b17d5d270418bd1d50ac0f6071d56b0d2 Mon Sep 17 00:00:00 2001 From: "polu.sandeep" Date: Wed, 16 Dec 2015 13:21:48 +0900 Subject: [PATCH] Resolved Contact duplication in buddy list view Change-Id: I98b0e83680dc6f0e758a3ad7a48f33786f1de42f --- .../contacts_utils/device_contacts_manager.c | 9 ++++- TelegramTizen/inc/tg_db_wrapper.h | 2 + TelegramTizen/src/tg_db_wrapper.c | 46 +++++++++++++++++++++- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/TelegramTizen/contacts_utils/device_contacts_manager.c b/TelegramTizen/contacts_utils/device_contacts_manager.c index e3aa858..634830a 100644 --- a/TelegramTizen/contacts_utils/device_contacts_manager.c +++ b/TelegramTizen/contacts_utils/device_contacts_manager.c @@ -6,6 +6,7 @@ #include "device_contacts_manager.h" #include "tg_common.h" +#include "tg_db_wrapper.h" #include "logger.h" bool sc_cdetails_get_contact_val(sc_common_contact_fields field_type, int contact_id, char **value) @@ -114,9 +115,13 @@ Eina_List* get_contact_list_from_device_db() } } + // check contact exist in buddylist + Eina_Bool is_tg_contact = EINA_FALSE; + if (contact_data->phone_number) { + is_tg_contact = is_phone_number_exists_in_buddy_list(contact_data->phone_number); + } - if (contact_data->phone_number == NULL) { - + if (contact_data->phone_number == NULL || is_tg_contact) { if (contact_data->display_name) { free(contact_data->display_name); diff --git a/TelegramTizen/inc/tg_db_wrapper.h b/TelegramTizen/inc/tg_db_wrapper.h index 7cbc026..d537cb7 100644 --- a/TelegramTizen/inc/tg_db_wrapper.h +++ b/TelegramTizen/inc/tg_db_wrapper.h @@ -272,6 +272,8 @@ Eina_Bool mark_all_records_for_deletion(char *tablename); Eina_Bool delete_date_messages_from_table(char *tablename); +Eina_Bool is_phone_number_exists_in_buddy_list(const char *phone_num); + Eina_Bool insert_unsent_message_to_db(const char *app_name, const char *command, const char *buddy_id, const char *msg_id, const char *msg_type, const char * msg_data, const char *type_of_chat); Eina_Bool insert_unsent_media_message_to_db(const char *app_name, const char *command, const char *buddy_id, const char *msg_id, const char *media_id, const char *msg_type, const char *file_path, const char *type_of_chat); #if 0 diff --git a/TelegramTizen/src/tg_db_wrapper.c b/TelegramTizen/src/tg_db_wrapper.c index 4554394..2a1fcc7 100644 --- a/TelegramTizen/src/tg_db_wrapper.c +++ b/TelegramTizen/src/tg_db_wrapper.c @@ -1282,6 +1282,50 @@ char* get_buddy_name_from_id(int buddy_id) return profile_name; } +Eina_Bool is_phone_number_exists_in_buddy_list(const char *phone_num) +{ + Eina_Bool is_exist = EINA_FALSE; + if (!phone_num) + return is_exist; + + char* table_name = BUDDY_INFO_TABLE_NAME; + Eina_List* col_names = NULL; + col_names = eina_list_append(col_names, USER_INFO_TABLE_PHONE_NO); + + Eina_List* col_types = NULL; + col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT); + + char *where_clause = NULL; + where_clause = (char *)malloc(strlen(USER_INFO_TABLE_PHONE_NO) + strlen(" LIKE '") + strlen("%") + strlen(phone_num) + strlen("%'") + 1); + strcpy(where_clause, USER_INFO_TABLE_PHONE_NO); + strcat(where_clause, " LIKE '"); + strcat(where_clause, "%"); + strcat(where_clause, phone_num); + strcat(where_clause, "%'"); + + Eina_List* buddy_details_array = get_values_from_table_sync(table_name, col_names, col_types, where_clause); + free(where_clause); + + if (buddy_details_array && eina_list_count(buddy_details_array) > 0) { + Eina_List* buddy_details = eina_list_nth(buddy_details_array, 0); + if (buddy_details && eina_list_count(buddy_details) > 0) { + char* name = (char*)eina_list_nth(buddy_details, 0); + + if (name && strlen(name) > 0) { + is_exist = EINA_TRUE; + } + free(name); + eina_list_free(buddy_details); + } + + eina_list_free(buddy_details_array); + } + + eina_list_free(col_names); + eina_list_free(col_types); + return is_exist; +} + char* get_buddy_phone_num_from_id(int buddy_id) { Eina_List* buddy_details_array = NULL; @@ -1306,8 +1350,6 @@ char* get_buddy_phone_num_from_id(int buddy_id) buddy_details_array = get_values_from_table_sync(table_name, col_names, col_types, where_clause); free(where_clause); - - if (buddy_details_array && eina_list_count(buddy_details_array) > 0) { Eina_List* buddy_details = eina_list_nth(buddy_details_array, 0); if (buddy_details && eina_list_count(buddy_details) > 0) { -- 2.7.4