Fixed delete message issue. 62/59262/1
authorpolu.sandeep <polu.sandeep@samsung.com>
Fri, 12 Feb 2016 02:50:09 +0000 (11:50 +0900)
committerpolu.sandeep <polu.sandeep@samsung.com>
Fri, 12 Feb 2016 02:50:09 +0000 (11:50 +0900)
Fixed invite friend issue.
Fixed change background issue.

Change-Id: If02d8d7cdad03ba332452cf532ceca7999bafb05

TelegramTizen/contacts_utils/device_contacts_manager.c
TelegramTizen/inc/tg_db_wrapper.h
TelegramTizen/src/telegramtizen.c
TelegramTizen/src/tg_db_wrapper.c
TelegramTizen/src/tg_main_item_deletion_view.c
TelegramTizen/src/tg_settings_view.c
TelegramTizen/tg_utils/tg_common.c
tg-engine-service/inc/tg_db_wrapper.h
tg-engine-service/src/tg_db_wrapper.c
tg-engine-service/tg_engine/tg_engine.c

index 8f525b4..310cc8f 100644 (file)
@@ -130,7 +130,20 @@ 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);
+                                               char *temp_phone = NULL;
+                                               if (contact_data->phone_number[0] == '0') {
+                                                       temp_phone = (char*)malloc(strlen(contact_data->phone_number));
+                                                       int i = 0, j = 1;
+                                                       for (;contact_data->phone_number[j] != '\0'; j++, i++) {
+                                                               temp_phone[i] = contact_data->phone_number[j];
+                                                       }
+                                                       temp_phone[i] = '\0';
+                                               } else {
+                                                       temp_phone = strdup(contact_data->phone_number);
+                                               }
+                                               LOGE("buddy phone number: %s", temp_phone);
+                                               is_tg_contact = is_phone_number_exists_in_buddy_list(temp_phone);
+                                               free(temp_phone);
                                        }
 
                                        if (contact_data->phone_number == NULL || is_tg_contact) {
index 1884b42..b8eaa00 100644 (file)
@@ -289,6 +289,8 @@ Eina_Bool delete_date_messages_from_table(char *tablename);
 
 Eina_Bool is_phone_number_exists_in_buddy_list(const char *phone_num);
 
+Eina_Bool mark_group_chat_as_unknown(int chat_id);
+
 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
index 930e731..8764791 100644 (file)
@@ -487,6 +487,11 @@ void load_main_list_data(appdata_s *ad)
                if (item) {
                        tg_peer_info_s* peer_info = item->use_data;
                        if (peer_info) {
+
+                               if (peer_info->peer_type == TGL_PEER_CHAT && peer_info->is_unknown == 1) {
+                                       continue;
+                               }
+
                                //if (peer_info->last_msg_id > 0) {
 
                                        // get message from message table.
@@ -4107,7 +4112,6 @@ void recursive_dir_copy(const char *source_dir, const char *target_dir)
        src_dir_stack = NULL;
        tar_dir_stack = NULL;
 
-
        src_dir = strdup(source_dir);
        tar_dir = strdup(target_dir);
 
@@ -4162,6 +4166,27 @@ void recursive_dir_copy(const char *source_dir, const char *target_dir)
        } while (src_dir != NULL);
 }
 
+void move_downloaded_files()
+{
+       // create download directory.
+       struct stat st = {0};
+       char dest_download_dir[512] = {0,};
+       sprintf(dest_download_dir, "%s/%s", app_get_shared_data_path(), "downloads");
+       if (stat(dest_download_dir, &st) == -1) {
+               mkdir(dest_download_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
+       }
+
+       LOGE("dest Download directory: %s", dest_download_dir);
+       // create download directory.
+       char target_download_dir[512] = {0,};
+       sprintf(target_download_dir, "%s/%s/%s", app_get_data_path(), "telegram_tizen", "downloads");
+
+       LOGE("target Download directory: %s", target_download_dir);
+       recursive_dir_copy(target_download_dir, dest_download_dir);
+       remove_directory(target_download_dir);
+}
+
+
 Eina_Bool dirExists(const char *path)
 {
     struct stat info;
@@ -4174,6 +4199,320 @@ Eina_Bool dirExists(const char *path)
         return EINA_FALSE;
 }
 
+void update_downloaded_video_thumb_paths_in_media_info_table()
+{
+       LOGE("Update media info table thumb files");
+       char *table_name = MEDIA_INFO_TABLE_NAME;
+       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_TEXT);
+
+       Eina_List* col_names = NULL;
+       col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_ID);
+       col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE);
+
+       Eina_List* vals = get_values_from_table_sync(table_name, col_names, col_types, NULL, TG_DBMGR_NOLIMITED, TG_DBMGR_NOLIMITED);
+       int val_size = eina_list_count(vals);
+       if (vals && val_size > 0) {
+               for (int i = 0; i < val_size; i++) {
+                       Eina_List* row_vals = eina_list_nth(vals, i);
+                       int user_id = 0;
+                       char *file_path = NULL;
+
+                       int *temp_user_id = (int*)eina_list_nth(row_vals, 0);
+                       if (temp_user_id) {
+                               user_id  = *temp_user_id;
+                               free(temp_user_id);
+                       }
+
+                       file_path = (char*)eina_list_nth(row_vals, 1);
+
+                       if (file_path) {
+                               if (strlen(file_path) > 0 && strncmp(file_path, "/opt/usr/media/telegram/telegram_tizen", strlen("/opt/usr/media/telegram/telegram_tizen")) == 0) {
+                                       // update file name in db
+                                       char *new_path = str_replace(new_path, "/opt/usr/media/telegram/telegram_tizen", app_get_shared_data_path());
+                                       if (!new_path)
+                                               continue;
+                                       LOGE("Old file path: %s", file_path);
+                                       LOGE("New file path: %s", new_path);
+
+                                       //update database.
+                                       Eina_List* new_col_types = NULL;
+                                       new_col_types = eina_list_append(new_col_types, TG_DB_COLUMN_TEXT);
+
+                                       Eina_List* new_col_names = NULL;
+                                       new_col_names = eina_list_append(new_col_names, MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE);
+
+                                       Eina_List* new_col_values = NULL;
+                                       new_col_values = eina_list_append(new_col_values, new_path);
+
+                                       char* where_clause = NULL;
+                                       char usr_str[50];
+                                       sprintf(usr_str, "%d", user_id);
+                                       where_clause = (char*)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = ") + strlen(usr_str) + 1);
+                                       strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID);
+                                       strcat(where_clause, " = ");
+                                       strcat(where_clause, usr_str);
+
+                                       Eina_Bool ret = update_table(table_name, new_col_names, new_col_types, new_col_values, where_clause);
+
+                                       if (!ret) {
+                                               LOGE("Media info table update failed.");
+                                       } else {
+                                               LOGE("Media info table update success.");
+                                       }
+                                       free(where_clause);
+                                       eina_list_free(new_col_types);
+                                       eina_list_free(new_col_names);
+                                       eina_list_free(new_col_values);
+                               }
+
+                               free(file_path);
+                       }
+
+                       eina_list_free(row_vals);
+               }
+       }
+       eina_list_free(col_types);
+       eina_list_free(col_names);
+}
+
+
+void update_downloaded_file_paths_in_media_info_table()
+{
+       LOGE("Update media info table");
+       char *table_name = MEDIA_INFO_TABLE_NAME;
+       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_TEXT);
+
+       Eina_List* col_names = NULL;
+       col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_ID);
+       col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FILE_PATH);
+
+       Eina_List* vals = get_values_from_table_sync(table_name, col_names, col_types, NULL, TG_DBMGR_NOLIMITED, TG_DBMGR_NOLIMITED);
+       int val_size = eina_list_count(vals);
+       if (vals && val_size > 0) {
+               for (int i = 0; i < val_size; i++) {
+                       Eina_List* row_vals = eina_list_nth(vals, i);
+                       int user_id = 0;
+                       char *file_path = NULL;
+
+                       int *temp_user_id = (int*)eina_list_nth(row_vals, 0);
+                       if (temp_user_id) {
+                               user_id  = *temp_user_id;
+                               free(temp_user_id);
+                       }
+
+                       file_path = (char*)eina_list_nth(row_vals, 1);
+
+                       if (file_path) {
+                               if (strlen(file_path) > 0 && strncmp(file_path, "/opt/usr/media/telegram/telegram_tizen", strlen("/opt/usr/media/telegram/telegram_tizen")) == 0) {
+                                       // update file name in db
+
+                                       char *new_path = str_replace(new_path, "/opt/usr/media/telegram/telegram_tizen", app_get_shared_data_path());
+                                       if (!new_path)
+                                               continue;
+                                       LOGE("Old file path: %s", file_path);
+                                       LOGE("New file path: %s", new_path);
+
+                                       //update database.
+                                       Eina_List* new_col_types = NULL;
+                                       new_col_types = eina_list_append(new_col_types, TG_DB_COLUMN_TEXT);
+
+                                       Eina_List* new_col_names = NULL;
+                                       new_col_names = eina_list_append(new_col_names, MEDIA_INFO_TABLE_FILE_PATH);
+
+                                       Eina_List* new_col_values = NULL;
+                                       new_col_values = eina_list_append(new_col_values, new_path);
+
+                                       char* where_clause = NULL;
+                                       char usr_str[50];
+                                       sprintf(usr_str, "%d", user_id);
+                                       where_clause = (char*)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = ") + strlen(usr_str) + 1);
+                                       strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID);
+                                       strcat(where_clause, " = ");
+                                       strcat(where_clause, usr_str);
+
+                                       Eina_Bool ret = update_table(table_name, new_col_names, new_col_types, new_col_values, where_clause);
+
+                                       if (!ret) {
+                                               LOGE("Media info table update failed.");
+                                       } else {
+                                               LOGE("Media info table update success.");
+                                       }
+                                       free(where_clause);
+                                       eina_list_free(new_col_types);
+                                       eina_list_free(new_col_names);
+                                       eina_list_free(new_col_values);
+                               }
+
+                               free(file_path);
+                       }
+
+                       eina_list_free(row_vals);
+               }
+       }
+       eina_list_free(col_types);
+       eina_list_free(col_names);
+}
+
+
+void update_downloaded_file_paths_in_chat_info_table()
+{
+       LOGE("Update chat info table");
+       char *table_name = CHAT_INFO_TABLE_NAME;
+       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_TEXT);
+
+       Eina_List* col_names = NULL;
+       col_names = eina_list_append(col_names, CHAT_INFO_TABLE_CHAT_ID);
+       col_names = eina_list_append(col_names, CHAT_INFO_TABLE_PHOTO_PATH);
+
+       Eina_List* vals = get_values_from_table_sync(table_name, col_names, col_types, NULL, TG_DBMGR_NOLIMITED, TG_DBMGR_NOLIMITED);
+       int val_size = eina_list_count(vals);
+       if (vals && val_size > 0) {
+               for (int i = 0; i < val_size; i++) {
+                       Eina_List* row_vals = eina_list_nth(vals, i);
+                       int user_id = 0;
+                       char *file_path = NULL;
+
+                       int *temp_user_id = (int*)eina_list_nth(row_vals, 0);
+                       if (temp_user_id) {
+                               user_id  = *temp_user_id;
+                               free(temp_user_id);
+                       }
+
+                       file_path = (char*)eina_list_nth(row_vals, 1);
+
+                       if (file_path) {
+                               if (strlen(file_path) > 0 && strncmp(file_path, "/opt/usr/media/telegram/telegram_tizen", strlen("/opt/usr/media/telegram/telegram_tizen")) == 0) {
+                                       // update file name in db
+                                       char *new_path = str_replace(file_path, "/opt/usr/media/telegram/telegram_tizen", app_get_shared_data_path());
+                                       if (!new_path)
+                                               continue;
+                                       LOGE("Old file path: %s", file_path);
+                                       LOGE("New file path: %s", new_path);
+
+                                       //update database.
+                                       Eina_List* new_col_types = NULL;
+                                       new_col_types = eina_list_append(new_col_types, TG_DB_COLUMN_TEXT);
+
+                                       Eina_List* new_col_names = NULL;
+                                       new_col_names = eina_list_append(new_col_names, CHAT_INFO_TABLE_PHOTO_PATH);
+
+                                       Eina_List* new_col_values = NULL;
+                                       new_col_values = eina_list_append(new_col_values, new_path);
+
+                                       char* where_clause = NULL;
+                                       char usr_str[50];
+                                       sprintf(usr_str, "%d", user_id);
+                                       where_clause = (char*)malloc(strlen(CHAT_INFO_TABLE_CHAT_ID) + strlen(" = ") + strlen(usr_str) + 1);
+                                       strcpy(where_clause, CHAT_INFO_TABLE_CHAT_ID);
+                                       strcat(where_clause, " = ");
+                                       strcat(where_clause, usr_str);
+
+                                       Eina_Bool ret = update_table(table_name, new_col_names, new_col_types, new_col_values, where_clause);
+
+                                       if (!ret) {
+                                               LOGE("Chat info table update failed.");
+                                       } else {
+                                               LOGE("Chat info table update success.");
+                                       }
+                                       free(where_clause);
+                                       eina_list_free(new_col_types);
+                                       eina_list_free(new_col_names);
+                                       eina_list_free(new_col_values);
+                               }
+
+                               free(file_path);
+                       }
+
+                       eina_list_free(row_vals);
+               }
+       }
+       eina_list_free(col_types);
+       eina_list_free(col_names);
+}
+
+void update_downloaded_file_paths_in_buddy_info_table(const char *table_name)
+{
+       LOGE("Update %s", table_name);
+       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_TEXT);
+
+       Eina_List* col_names = NULL;
+       col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_ID);
+       col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+
+       Eina_List* vals = get_values_from_table_sync(table_name, col_names, col_types, NULL, TG_DBMGR_NOLIMITED, TG_DBMGR_NOLIMITED);
+       int val_size = eina_list_count(vals);
+       if (vals && val_size > 0) {
+               for (int i = 0; i < val_size; i++) {
+                       Eina_List* row_vals = eina_list_nth(vals, i);
+                       int user_id = 0;
+                       char *file_path = NULL;
+
+                       int *temp_user_id = (int*)eina_list_nth(row_vals, 0);
+                       if (temp_user_id) {
+                               user_id  = *temp_user_id;
+                               free(temp_user_id);
+                       }
+
+                       file_path = (char*)eina_list_nth(row_vals, 1);
+
+                       if (file_path) {
+                               if (strlen(file_path) > 0 && strncmp(file_path, "/opt/usr/media/telegram/telegram_tizen", strlen("/opt/usr/media/telegram/telegram_tizen")) == 0) {
+                                       // update file name in db
+                                       char *new_path = str_replace(file_path, "/opt/usr/media/telegram/telegram_tizen", app_get_shared_data_path());
+                                       if (!new_path)
+                                               continue;
+                                       LOGE("Old file path: %s", file_path);
+                                       LOGE("New file path: %s", new_path);
+
+                                       //update database.
+                                       Eina_List* new_col_types = NULL;
+                                       new_col_types = eina_list_append(new_col_types, TG_DB_COLUMN_TEXT);
+
+                                       Eina_List* new_col_names = NULL;
+                                       new_col_names = eina_list_append(new_col_names, USER_INFO_TABLE_PHOTO_PATH);
+
+                                       Eina_List* new_col_values = NULL;
+                                       new_col_values = eina_list_append(new_col_values, new_path);
+
+                                       char* where_clause = NULL;
+                                       char usr_str[50];
+                                       sprintf(usr_str, "%d", user_id);
+                                       where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(usr_str) + 1);
+                                       strcpy(where_clause, USER_INFO_TABLE_USER_ID);
+                                       strcat(where_clause, " = ");
+                                       strcat(where_clause, usr_str);
+
+                                       Eina_Bool ret = update_table(table_name, new_col_names, new_col_types, new_col_values, where_clause);
+
+                                       if (!ret) {
+                                               LOGE("Buddy info table update failed.");
+                                       } else {
+                                               LOGE("Buddy info table update success.");
+                                       }
+                                       free(where_clause);
+                                       eina_list_free(new_col_types);
+                                       eina_list_free(new_col_names);
+                                       eina_list_free(new_col_values);
+                               }
+
+                               free(file_path);
+                       }
+
+                       eina_list_free(row_vals);
+               }
+       }
+       eina_list_free(col_types);
+       eina_list_free(col_names);
+}
+
 static bool app_create(void *data)
 {
        /*
@@ -4188,6 +4527,14 @@ static bool app_create(void *data)
                char *new_dir = app_get_data_path();
                recursive_dir_copy(OLD_DIR, new_dir);
                remove_directory(OLD_DIR);
+               move_downloaded_files();
+               // update downloaded image paths in DB
+               update_downloaded_file_paths_in_buddy_info_table(BUDDY_INFO_TABLE_NAME);
+               update_downloaded_file_paths_in_buddy_info_table(USER_INFO_TABLE_NAME);
+               update_downloaded_file_paths_in_buddy_info_table(PEER_INFO_TABLE_NAME);
+               update_downloaded_file_paths_in_chat_info_table();
+               update_downloaded_file_paths_in_media_info_table();
+               update_downloaded_video_thumb_paths_in_media_info_table();
        }
 
        tg_db_init();
index 9ce3d73..c1aef87 100644 (file)
@@ -4470,3 +4470,43 @@ Eina_Bool delete_date_messages_from_table(char *tablename)
        free(var_query);
        return EINA_TRUE;
 }
+
+Eina_Bool mark_group_chat_as_unknown(int chat_id)
+{
+
+       char *table_name = PEER_INFO_TABLE_NAME;
+
+       Eina_List* col_names = NULL;
+       col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_UNKNOWN_PEER);
+
+       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 = 1;
+       col_values = eina_list_append(col_values, &(un_read_res));
+
+       char* where_clause = NULL;
+       char usr_str[50];
+
+       sprintf(usr_str, "%d", chat_id);
+       where_clause = (char*)malloc(strlen(PEER_INFO_TABLE_CHAT_ID) + strlen(" = ") + strlen(usr_str) + 1);
+       strcpy(where_clause, PEER_INFO_TABLE_CHAT_ID);
+       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;
+}
index a2e3a66..6c5bda6 100644 (file)
@@ -19,6 +19,7 @@
 #include "tg_main_item_deletion_view.h"
 #include "tg_user_main_view.h"
 #include "tg_db_manager.h"
+#include "tg_db_wrapper.h"
 #include "server_requests.h"
 
 static Evas_Object* create_image_object_from_file(const char *icon_name, Evas_Object *parent)
@@ -301,42 +302,21 @@ void on_delete_selected_items_clicked(void *data, Evas_Object *object, void *eve
                if (sel_item && sel_item->is_selected) {
                        if (sel_item->peer_type == TGL_PEER_USER) {
                                char* tablename = get_table_name_from_number(sel_item->peer_id);
-                               delete_all_records(tablename);
+                               //delete_all_records(tablename);
+                               mark_all_records_for_deletion(tablename);
+                               // delete date messages
+                               delete_date_messages_from_table(tablename);
                                free(tablename);
-#if 0
-                               // delete from main list
-                               if (sel_item->peer_print_name) {
-                                       free(sel_item->peer_print_name);
-                                       sel_item->peer_print_name = NULL;
-                               }
-                               if (sel_item->last_message) {
-                                       free(sel_item->last_message);
-                                       sel_item->last_message = NULL;
-                               }
-                               if (sel_item->profile_pic_path) {
-                                       free(sel_item->profile_pic_path);
-                                       sel_item->profile_pic_path = NULL;
-                               }
-                               sel_item->date_lbl = NULL;
-                               sel_item->msg_status_lbl = NULL;
-                               sel_item->main_item_layout = NULL;
-                               sel_item->profile_pic = NULL;
-                               sel_item->profile_pic_path = NULL;
-                               sel_item->status_lbl = NULL;
-                               sel_item->user_name_lbl = NULL;
-                               //ad->main_list
-                               ad->main_list = eina_list_remove(ad->main_list, sel_item);
-#endif
+                               send_delete_all_messages_request(ad, ad->service_client, sel_item->peer_id, sel_item->peer_type);
                        } else if (sel_item->peer_type == TGL_PEER_CHAT) {
+                               // mark group chat as unknown.
+                               mark_group_chat_as_unknown(sel_item->peer_id);
                                sel_grp_chat = eina_list_append(sel_grp_chat, sel_item);
                        }
                        num_of_sel_items++;
                }
        }
 
-
-
-
        if (num_of_sel_items <= 0) {
                show_toast(ad, "Select items to delete.");
                return;
index e12dee4..b4eb5df 100644 (file)
@@ -445,8 +445,6 @@ void on_chat_bg_change_option_selected_cb(void *data, Evas_Object *obj, void *ev
                app_control_set_mime(app_control, "image/jpg");
                app_control_send_launch_request(app_control, &on_chat_bg_select_result_cb, ad);
        } else {
-               app_control_set_launch_mode(app_control, APP_CONTROL_LAUNCH_MODE_GROUP);
-               app_control_set_app_id(app_control, "ug-gallery-efl");
                app_control_set_operation(app_control, APP_CONTROL_OPERATION_PICK);
                app_control_set_mime(app_control, "image/*");
                app_control_send_launch_request(app_control, &on_chat_bg_select_result_cb, ad);
index 85a7b5b..3bb472d 100644 (file)
@@ -285,7 +285,6 @@ void launch_app_control(appdata_s *ad, char *media_type, char *url)
        app_control_set_operation(app_control, APP_CONTROL_OPERATION_VIEW);
        if (strstr(media_type, "video") != NULL) {
                app_control_set_mime(app_control,"video/*");
-               app_control_set_app_id(app_control, "com.samsung.video-player-lite");
        } else if (strstr(media_type, "audio") != NULL) {
                app_control_set_mime(app_control,"audio/*");
        } else if (strstr(media_type, "image") != NULL) {
index b4cc7b1..3b123f0 100644 (file)
@@ -294,4 +294,6 @@ Eina_List* get_all_message_ids_from_table(char *table_name);
 
 Eina_Bool delete_message_from_table(char *tablename, int msg_id);
 
+Eina_List* get_chat_ids_to_be_deleted();
+
 #endif /* TG_DB_WRAPPER_H_ */
index 4cb444c..86d7eff 100644 (file)
@@ -5281,6 +5281,59 @@ Eina_Bool is_user_present_buddy_table(int peer_id)
        return ret;
 }
 
+
+Eina_List* get_chat_ids_to_be_deleted()
+{
+       Eina_List* peer_details = NULL;
+       char *table_name = PEER_INFO_TABLE_NAME;
+       Eina_List* col_names = NULL;
+       col_names = eina_list_append(col_names, PEER_INFO_TABLE_CHAT_ID);
+
+       Eina_List* col_types = NULL;
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+       char peer_type_str[50];
+       sprintf(peer_type_str, "%d", 2);
+
+       char unknown_str[50];
+       sprintf(unknown_str, "%d", 1);
+
+       char* where_clause = (char*)malloc(strlen(PEER_INFO_TABLE_PEER_TYPE) + strlen(" = ") + strlen(peer_type_str) + strlen(" AND ") + strlen(USER_INFO_TABLE_IS_UNKNOWN_PEER) + strlen(" = ") + strlen(unknown_str) + 1);
+       strcpy(where_clause, PEER_INFO_TABLE_PEER_TYPE);
+       strcat(where_clause, " = ");
+       strcat(where_clause, peer_type_str);
+       strcat(where_clause, " AND ");
+       strcat(where_clause, USER_INFO_TABLE_IS_UNKNOWN_PEER);
+       strcat(where_clause, " = ");
+       strcat(where_clause, unknown_str);
+       peer_details = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+       free(where_clause);
+
+       Eina_List *chat_id_list = NULL;
+
+       if (peer_details) {
+               for (int i = 0; i < eina_list_count(peer_details) ; i++) {
+                       Eina_List* id_list = eina_list_nth(peer_details, i);
+                       int chat_id = -1;
+                       if (id_list && eina_list_count(id_list) > 0) {
+                               int *temp_msg_id = (int*)eina_list_nth(id_list, 0);
+                               if (temp_msg_id) {
+                                       chat_id  = *temp_msg_id;
+                                       chat_id_list = eina_list_append(chat_id_list, (void*)chat_id);
+                                       free(temp_msg_id);
+                               }
+                               eina_list_free(id_list);
+                       }
+               }
+               eina_list_free(peer_details);
+       }
+       eina_list_free(col_names);
+       eina_list_free(col_types);
+
+       return chat_id_list;
+}
+
+
 Eina_Bool is_user_present_peer_table(int peer_id)
 {
        Eina_Bool ret = EINA_FALSE;
index d7dc197..bb9ca41 100644 (file)
@@ -1997,6 +1997,25 @@ static Eina_Bool send_chat_loading_is_done_response(void *data)
 }
 #endif
 
+void delete_pending_group_chats(tg_engine_data_s *tg_data)
+{
+       Eina_List* id_list = get_chat_ids_to_be_deleted();
+       if (id_list && eina_list_count(id_list) > 0) {
+               for (int i = 0; i < eina_list_count(id_list); i++) {
+                       int chat_id_val = (int)eina_list_nth(id_list, i);
+                       if (chat_id_val > 0) {
+                               tgl_peer_id_t chat_id;
+                               chat_id.id = chat_id_val;
+                               chat_id.type = TGL_PEER_CHAT;
+
+                               tgl_peer_id_t self_id = tg_data->id;
+
+                               tgl_do_del_user_from_chat(s_info.TLS, chat_id, self_id, NULL, NULL);
+                       }
+               }
+       }
+}
+
 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;
@@ -2041,6 +2060,7 @@ void on_offline_chat_received(struct tgl_state *TLS, void *callback_extra, int s
                }
        }
        if (!is_offline_msg_requested) {
+               delete_pending_group_chats(tg_data);
                send_contacts_and_chats_load_done_response(TLS->callback_data, EINA_TRUE);
        }
 }
@@ -2145,6 +2165,7 @@ static Eina_Bool on_load_offline_messages(void *data)
                }
 
                if (!is_offline_msg_requested) {
+                       delete_pending_group_chats(tg_data);
                        send_contacts_and_chats_load_done_response(TLS->callback_data, EINA_TRUE);
                }
        }
@@ -3803,7 +3824,8 @@ void parse_config(void)
                //printf("File successfully deleted\n");
        }
 
-       tasprintf(&s_info.downloads_directory, "%s%s/%s", app_get_data_path(), CONFIG_DIRECTORY, DOWNLOADS_DIRECTORY);
+       //tasprintf(&s_info.downloads_directory, "%s%s/%s", app_get_data_path(), CONFIG_DIRECTORY, DOWNLOADS_DIRECTORY);
+       tasprintf(&s_info.downloads_directory, "%s/%s", app_get_shared_data_path(), DOWNLOADS_DIRECTORY);
 
        if (s_info.binlog_enabled) {
                tasprintf(&s_info.binlog_file_name, "%s%s/%s", app_get_data_path(), CONFIG_DIRECTORY, BINLOG_FILE);