Fixed the bug on displaying images on message view 60/58460/1
authorKyuho Jo <kyuho.jo@samsung.com>
Mon, 1 Feb 2016 08:18:09 +0000 (17:18 +0900)
committerKyuho Jo <kyuho.jo@samsung.com>
Mon, 1 Feb 2016 08:18:09 +0000 (17:18 +0900)
Change-Id: Ib593ae42ccd91289679ed1fbf66435e0d8c302ac
Signed-off-by: Kyuho Jo <kyuho.jo@samsung.com>
TelegramTizen/db_manager/tg_db_manager.c
TelegramTizen/src/telegramtizen.c
TelegramTizen/src/tg_db_wrapper.c
TelegramTizen/src/tg_messaging_view.c
TelegramTizen/tg_utils/tg_common.c

index ff596f7..a779a0e 100644 (file)
@@ -281,7 +281,7 @@ Eina_Bool create_index(const char* table_name, const char *column_name)
        }
 
        char* err_msg = 0;
-       char *query_format = "CREATE INDEX tg_index_%s ON %s (%s);";
+       char *query_format = "CREATE INDEX tg_index_%s_%s ON %s (%s);";
        char *query_string = NULL;
        int   query_length = strlen(query_format) + strlen(table_name) + (strlen(column_name) * 2) + 20;
        int   ret;
@@ -294,7 +294,7 @@ Eina_Bool create_index(const char* table_name, const char *column_name)
                return EINA_FALSE;
        }
 
-       snprintf(query_string, query_length, query_format, column_name, table_name, column_name);
+       snprintf(query_string, query_length, query_format, table_name, column_name, table_name, column_name);
 
        sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
 
@@ -328,34 +328,15 @@ Eina_Bool get_values_from_table(const char* table_name, Eina_List* column_names,
        if (!table_name) {
                return EINA_FALSE;
        }
-       sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
-       /*****No rows identification*****/
 
-       char* row_cnt_qry = (char*)malloc(strlen("SELECT COUNT(*) FROM ") + strlen(table_name) + strlen(";") +1);
-       strcpy(row_cnt_qry, "SELECT COUNT(*) FROM ");
-       strcat(row_cnt_qry, table_name);
-       strcat(row_cnt_qry, ";");
-
-       int no_of_rows = 0;
-       //ret = sqlite3_exec(s_info.db,var_query, callback,(void*)s_info.db, &err_msg);
-
-       sqlite3_stmt *stmt;
-       if (sqlite3_prepare_v2(db, row_cnt_qry, -1, &stmt, NULL) == SQLITE_OK) {
-               if (sqlite3_step(stmt) == SQLITE_ERROR) {
-                       no_of_rows = 0;
-               } else {
-                       no_of_rows = sqlite3_column_int(stmt, 0);
-               }
-               sqlite3_finalize(stmt);
-       }
-       close_database(db);
-       free(row_cnt_qry);
-       if(no_of_rows <= 0) {
-               return EINA_FALSE;
+       /*****No rows identification*****/
+       if (get_number_of_rows(table_name, NULL) == 0) {
+               DBG("There are no rows on [%s]", table_name);
+               return NULL;
        }
 
        /********************************/
-       db = create_database(DEFAULT_TG_DATABASE_PATH);
+       sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
        int ret = 0 ;
        char* err_msg = 0;
        //int col_count = eina_list_count(column_names);
index 6736f95..57b035f 100644 (file)
@@ -1694,10 +1694,9 @@ static int on_message_received_from_buddy(appdata_s *app, bundle *const rec_msg,
                                int date_id = atoi(date_id_str);
                                on_text_message_received_from_buddy(app, date_id, type_of_chat);
                                wait_for(1);
-                               on_text_message_received_from_buddy(app, message_id, type_of_chat);
-                       } else {
-                               on_text_message_received_from_buddy(app, message_id, type_of_chat);
                        }
+                       on_text_message_received_from_buddy(app, message_id, type_of_chat);
+
                        return result;
                }
 
index 821d091..8b0a649 100644 (file)
@@ -4336,10 +4336,12 @@ void create_buddy_msg_table(const char* table_name)
 
        Eina_Bool ret = create_table(table_name, col_names, col_types);
        if (!ret) {
-               //("error: database creation failed");
+               DBG("create_table failed");
+       }
+       else {
+               /* Create index only when creating a table is suceeded */
+               create_index(table_name, "date");
        }
-
-       create_index(table_name, "date");
 
        eina_list_free(col_names);
        eina_list_free(col_types);
index 5c106ef..e14c57b 100644 (file)
@@ -1142,7 +1142,7 @@ static Evas_Object * item_provider(void *data, Evas_Object *entry, const char *i
                Evas_Object* chat_scroller = data;
                appdata_s* ad = evas_object_data_get(chat_scroller, "app_data");
                int user_id = (int)evas_object_data_get(chat_scroller, "user_id");
-               int message_id = (int)evas_object_data_get(chat_scroller, "message_id");
+               int message_id = (int)evas_object_data_get(entry, "message_id");
 
                peer_with_pic_s *sel_item =  eina_list_nth(ad->peer_list, user_id);
                int buddy_id = sel_item->use_data->peer_id;
@@ -1466,6 +1466,7 @@ Evas_Object *on_message_item_content_get_cb(void *data, Evas_Object *obj, const
 
        if (data == NULL) {
                ERR("Invalid Parameter.");
+               return NULL;
        }
 
        char edj_path[PATH_MAX] = {0, };
@@ -1546,8 +1547,6 @@ Evas_Object *on_message_item_content_get_cb(void *data, Evas_Object *obj, const
 
                                return layout;
                        }
-                       evas_object_data_set(entry, "chat_list", (void*)chat_scroller);
-                       evas_object_data_set(entry, "message_id", (void*)msg->msg_id);
 
                        if (msg->media_type != tgl_message_media_none) {
                                entry = elm_entry_add(obj);
@@ -1558,6 +1557,10 @@ Evas_Object *on_message_item_content_get_cb(void *data, Evas_Object *obj, const
                        } else {
                                entry = elm_label_add(obj);
                        }
+
+                       evas_object_data_set(entry, "message_id", (void*)msg->msg_id);
+                       evas_object_data_set(entry, "chat_list", (void*)chat_scroller);
+
                        layout = elm_layout_add(obj);
 
                        if (msg->out) {
@@ -1781,44 +1784,48 @@ void on_text_message_received_from_buddy(appdata_s* ad, long long message_id, in
        Evas_Object* chat_scroller = evas_object_data_get(ad->nf, "chat_list");
        Evas_Object *message = NULL;
 
-       if (msg) {
-               // update peer table
-               if (peer_item) {
-                       peer_item->last_msg_id = msg->msg_id;
-                       peer_item->last_msg_date =  msg->date;
-                       insert_or_update_peer_into_database(peer_item);
-               }
+       if (msg == NULL) {
+               ERR("msg not found");
+               return;
+       }
 
-               Evas_Object *layout = evas_object_data_get(ad->nf, "main_layout");
-               if (layout) {
-                       int is_end_edge = (int) evas_object_data_get(layout, "is_end_edge");
-                       if (!is_end_edge) {
-                               Evas_Object *bubble_layout = NULL;
-                               bubble_layout = elm_object_part_content_get(layout, "swallow.messagebubble");
+       // update peer table
+       if (peer_item) {
+               peer_item->last_msg_id = msg->msg_id;
+               peer_item->last_msg_date =  msg->date;
+               insert_or_update_peer_into_database(peer_item);
+       }
 
-                               int user_id = (int) evas_object_data_get(chat_scroller, "user_id");
-                               peer_with_pic_s *sel_item =  eina_list_nth(ad->peer_list, user_id);
-                               char *sender_name = NULL;
-                               if (sel_item->use_data->peer_type == TGL_PEER_USER) {
-                                       sender_name = replace(sel_item->use_data->print_name, '_', " ");
-                               } else if (sel_item->use_data->peer_type == TGL_PEER_CHAT) {
-                                       int from_id = msg->from_id;
-                                       // get name of buddy
-                                       char* buddy_name = get_buddy_name_from_id(from_id);
-                                       if (buddy_name) {
-                                               sender_name = replace(buddy_name, '_', " ");
-                                               free(buddy_name);
-                                       }
-                               } else {
-                                       sender_name = replace(sel_item->use_data->print_name, '_', " ");
+       Evas_Object *layout = evas_object_data_get(ad->nf, "main_layout");
+       if (layout) {
+               int is_end_edge = (int) evas_object_data_get(layout, "is_end_edge");
+               if (!is_end_edge) {
+                       Evas_Object *bubble_layout = NULL;
+                       bubble_layout = elm_object_part_content_get(layout, "swallow.messagebubble");
+
+                       int user_id = (int) evas_object_data_get(chat_scroller, "user_id");
+                       peer_with_pic_s *sel_item =  eina_list_nth(ad->peer_list, user_id);
+                       char *sender_name = NULL;
+                       if (sel_item->use_data->peer_type == TGL_PEER_USER) {
+                               sender_name = replace(sel_item->use_data->print_name, '_', " ");
+                       } else if (sel_item->use_data->peer_type == TGL_PEER_CHAT) {
+                               int from_id = msg->from_id;
+                               // get name of buddy
+                               char* buddy_name = get_buddy_name_from_id(from_id);
+                               if (buddy_name) {
+                                       sender_name = replace(buddy_name, '_', " ");
+                                       free(buddy_name);
                                }
-
-                               elm_object_part_text_set(bubble_layout, "text_name", sender_name);
-                               elm_object_part_text_set(bubble_layout, "text_message", msg->message);
-                               elm_object_signal_emit(layout, "show", "bubblemessage");
+                       } else {
+                               sender_name = replace(sel_item->use_data->print_name, '_', " ");
                        }
+
+                       elm_object_part_text_set(bubble_layout, "text_name", sender_name);
+                       elm_object_part_text_set(bubble_layout, "text_message", msg->message);
+                       elm_object_signal_emit(layout, "show", "bubblemessage");
                }
        }
+
        free(tablename);
 
        message = on_message_item_content_get_cb((void *)msg, chat_scroller, "elm.icon.entry");
index b42ce9e..85a7b5b 100644 (file)
@@ -94,13 +94,9 @@ Evas_Object* create_circle_button(Evas_Object *parent, char* text, char* filepat
 
 char* get_table_name_from_number(const int id)
 {
-       char id_str[50];
-       sprintf(id_str, "%d", id);
-       char* msg_table = (char*)malloc(strlen("tg_") + strlen(id_str) + strlen("_msg") + 1);
-       strcpy(msg_table, "tg_");
-       strcat(msg_table, id_str);
-       strcat(msg_table, "_msg");
-       return msg_table;
+       char id_str[64];
+       snprintf(id_str, sizeof(id_str), "tg_%d_msg", id);
+       return strdup(id_str);
 }
 
 char* get_budy_state(appdata_s* ad, int buddy_id)