Handling new buddy request. 12/49212/1
authormoon87.park <moon87.park@samsung.com>
Thu, 8 Oct 2015 07:40:32 +0000 (16:40 +0900)
committerpolu.sandeep <polu.sandeep@samsung.com>
Thu, 8 Oct 2015 12:36:54 +0000 (21:36 +0900)
Change-Id: I61c3396367c5e55fec1c74b58ef793cc5bbe8f26

19 files changed:
TelegramTizen/inc/logger.h
TelegramTizen/inc/server_requests.h
TelegramTizen/inc/tg_db_wrapper.h
TelegramTizen/src/contact_selection_view.c
TelegramTizen/src/group_chat_entry_view.c
TelegramTizen/src/server_requests.c
TelegramTizen/src/telegramtizen.c
TelegramTizen/src/tg_db_wrapper.c
TelegramTizen/src/tg_messaging_view.c
TelegramTizen/src/tg_user_main_view.c
TelegramTizen/tg_utils/tg_common.h
tg-engine-service/inc/server_response.h
tg-engine-service/inc/tg_db_wrapper.h
tg-engine-service/mtprotocol/structures.c
tg-engine-service/src/server_response.c
tg-engine-service/src/tg-engine-service.c
tg-engine-service/src/tg_db_wrapper.c
tg-engine-service/tg_engine/tg_engine.c
tg-engine-service/tg_engine/tg_engine.h

index e046266..d63c3d3 100644 (file)
         LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
         __func__, __LINE__, ##arg)
 
+#define LOGI(fmt, arg...) dlog_print(DLOG_INFO, \
+        LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
+        __func__, __LINE__, ##arg)
+
 #define DBG(fmt, arg...) dlog_print(DLOG_DEBUG, \
         LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
         __func__, __LINE__, ##arg)
 
+#define LOGD(fmt, arg...) dlog_print(DLOG_DEBUG, \
+        LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
+        __func__, __LINE__, ##arg)
+
 #define WARN(fmt, arg...) dlog_print(DLOG_WARN, \
         LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
         __func__, __LINE__, ##arg)
         LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
         __func__, __LINE__, ##arg)
 
+#define LOGE(fmt, arg...) dlog_print(DLOG_ERROR, \
+        LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
+        __func__, __LINE__, ##arg)
+
 #define RETM_IF(expr, fmt, arg...) \
 { \
     if (expr) { \
index 00f5950..de98757 100644 (file)
@@ -34,5 +34,6 @@ void send_set_username_request(service_client* service_client, int user_id, cons
 void send_remove_buddy_from_group_chat_request(service_client* service_client, int user_id, int chat_id);
 void send_request_for_delete_notifications(service_client* service_client);
 void send_request_for_server_connection_status(service_client* service_client);
+void send_update_chat_request(service_client* service_client, const int chat_id);
 
 #endif /* SERVER_REQUESTS_H_ */
index bc63b6f..2255592 100644 (file)
 #define MEDIA_INFO_TABLE_DOCUMENT_DC "doc_dc" //text
 #define MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE "video_thumb" //text
 
+#define MESSAGE_INFO_TABLE_MESSAGE_ROW_ID "msg_row_id"
 #define MESSAGE_INFO_TABLE_MESSAGE_ID "msg_id"
 #define MESSAGE_INFO_TABLE_FLAGS "flags"
 #define MESSAGE_INFO_TABLE_FWD_FROM_ID "fwd_from_id"
@@ -248,6 +249,8 @@ int get_media_size_from_db(long long media_id);
 
 int get_number_of_unread_messages();
 
+void create_buddy_msg_table(const char* table_name);
+
 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 8554ccf..89c55d9 100644 (file)
@@ -306,7 +306,9 @@ void launch_contact_selction_view(void *data)
 
        Evas_Object* buddy_gen_list = elm_genlist_add(ad->nf);
        elm_list_mode_set(buddy_gen_list, ELM_LIST_COMPRESS);
-       elm_genlist_decorate_mode_set(buddy_gen_list, ELM_LIST_COMPRESS);
+
+       // FIXME: Deprecated API
+       // elm_genlist_decorate_mode_set(buddy_gen_list, ELM_LIST_COMPRESS);
        evas_object_size_hint_weight_set(buddy_gen_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(buddy_gen_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
 
index 7b3ea66..dfabe52 100644 (file)
@@ -315,7 +315,8 @@ void launch_group_chat_name_entry_view(void *data)
 
        Evas_Object* buddy_gen_list = elm_genlist_add(ad->nf);
        elm_list_mode_set(buddy_gen_list, ELM_LIST_COMPRESS);
-       elm_genlist_decorate_mode_set(buddy_gen_list, ELM_LIST_COMPRESS);
+       // FIXME: Deprecated API
+       //elm_genlist_decorate_mode_set(buddy_gen_list, ELM_LIST_COMPRESS);
        evas_object_size_hint_weight_set(buddy_gen_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(buddy_gen_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
 
index d5e9ad6..8dd23e1 100644 (file)
@@ -183,6 +183,47 @@ void send_add_buddy_request(service_client* service_client, const int buddy_id)
        bundle_free(msg);
 }
 
+void send_update_chat_request(service_client* service_client, const int chat_id)
+{
+       if (!service_client) {
+               // error
+               return;
+       }
+       bundle *msg;
+       char tmp[50];
+       int result;
+       msg = bundle_create();
+       if (!msg) {
+               return;
+       }
+
+       if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0)     {
+               ERR("Failed to add data by key to bundle");
+               bundle_free(msg);
+               return;
+       }
+
+       if (bundle_add_str(msg, "command", "update_chat_info") != 0) {
+               ERR("Failed to add data by key to bundle");
+               bundle_free(msg);
+               return;
+       }
+       snprintf(tmp, sizeof(tmp) - 1, "%d", chat_id);
+
+       if (bundle_add_str(msg, "chat_id", tmp) != 0)   {
+               ERR("Failed to add data by key to bundle");
+               bundle_free(msg);
+               return;
+       }
+
+       result = service_client_send_message(service_client, msg);
+       if(result != SVC_RES_OK) {
+               // error
+       }
+       bundle_free(msg);
+}
+
+
 void send_delete_buddy_request(service_client* service_client, const int buddy_id)
 {
        if (!service_client) {
index e9eec21..9c92d2a 100644 (file)
@@ -941,6 +941,37 @@ static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg)
                        // error handling
                        show_toast(app, "Error: loading contacts");
                }
+       } else if (strcmp(rec_key_val, "reponse_group_chat_updated") == 0) {
+
+               char *chat_id_str = NULL;
+               result = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
+               int chat_id = atoi(chat_id_str);
+
+               int buddy_id = -1;
+               app->main_item_in_cahtting_data = NULL;
+               app->peer_in_cahtting_data = NULL;
+               for (int i = 0 ; i < eina_list_count(app->main_list) ; i++) {
+                       tg_main_list_item_s *item = eina_list_nth(app->main_list, i);
+                       if (item->peer_id == chat_id) {
+                               app->main_item_in_cahtting_data = item;
+                               break;
+                       }
+               }
+
+               for (int i = 0; i < eina_list_count(app->peer_list); i++) {
+                       peer_with_pic_s* pic_item = eina_list_nth(app->peer_list, i);
+                       tg_peer_info_s* item = pic_item->use_data;
+
+                       if (item->peer_id == chat_id) {
+                               app->peer_in_cahtting_data = pic_item;
+                               buddy_id = i;
+                               break;
+                       }
+               }
+
+               launch_messaging_view_cb(app, buddy_id);
+               hide_loading_popup(app);
+
        } else if (strcmp(rec_key_val, "group_chat_updated") == 0) {
 
                char *chat_id_str = NULL;
@@ -1174,20 +1205,18 @@ static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg)
                //load message from the received info.
                // get phone number using buddy id.
 
-
+               Eina_Bool is_user_present_in_main_list = EINA_FALSE;
+               int id_to_check;
+               if (type_of_chat == TGL_PEER_USER) {
+                       id_to_check = from_id;
+               } else {
+                       id_to_check = to_id;
+               }
                if (app->main_list) {
                        int main_list_size = eina_list_count(app->main_list);
                        for (int i = 0; i < main_list_size; i++) {
                                tg_main_list_item_s* sel_item = eina_list_nth(app->main_list, i);
 
-                               int id_to_check;
-                               if (type_of_chat == TGL_PEER_USER) {
-                                       id_to_check = from_id;
-                               } else {
-                                       id_to_check = to_id;
-                               }
-
-
                                if (sel_item->peer_id == id_to_check ) {
 
                                        // update last message
@@ -1358,11 +1387,27 @@ static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg)
                                        }
 
                                        free(tablename);
+                                       is_user_present_in_main_list = EINA_TRUE;
+
+                                       app->main_list = eina_list_remove(app->main_list, sel_item);
+                                       app->main_list = eina_list_prepend(app->main_list, sel_item);
+                                       refresh_main_list_view(app, EINA_FALSE);
                                        break;
                                }
                        }
                }
 
+               if (!is_user_present_in_main_list) {
+                        peer_with_pic_s *peer_item = get_peer_info(id_to_check);
+                        if (peer_item) {
+                                tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
+                                if (latest_item) {
+                                        app->main_list = eina_list_prepend(app->main_list, latest_item);
+                                        refresh_main_list_view(app, EINA_TRUE);
+                                }
+                        }
+               }
+
                if (type_of_chat == TGL_PEER_USER) {
                        if ((app->current_app_state ==  TG_CHAT_MESSAGING_VIEW_STATE || app->current_app_state ==  TG_SET_USER_INFO_STATE) && app->peer_in_cahtting_data
                                        && app->peer_in_cahtting_data->use_data->peer_id == from_id) {
@@ -1824,46 +1869,44 @@ static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg)
                        }
                        eina_list_free(contacts_list);
                }
+       } else if (strcmp(rec_key_val, "new_buddy_added") == 0) {
+               char* buddy_id_str = NULL;
+               result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+
+               int buddy_id = atoi(buddy_id_str);
+               peer_with_pic_s *peer_item = get_peer_info(buddy_id);
+               tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
+               if (latest_item) {
+                       app->main_list = eina_list_prepend(app->main_list, latest_item);
+                       refresh_main_list_view(app, EINA_TRUE);
+               }
+
        } else if (strcmp(rec_key_val, "new_group_added") == 0) {
 
                char* chat_id_str = NULL;
                result = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
 
-
-#if 0
-
-               // get group chat details from database.(chat info)
-               // tg_chat_info_s* chat_info = get_chat_info(chat_id);
-
-               load_buddy_list_data(app);
-               load_group_chat_data(app);
-               load_peer_data(app);
-               load_main_list_data(app);
-               if (app->current_app_state == TG_BUDDY_LIST_STATE) {
-                       //refresh_buddy_list(app);
-                       show_toast(app, "new group created");
-               } else {
-                       elm_naviframe_item_pop(app->nf);
-                       //refresh_buddy_list(app);
-               }
-#else
                 int chat_id = atoi(chat_id_str);
                 peer_with_pic_s *peer_item = get_peer_info(chat_id);
                if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
                        tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
-                       app->main_list = eina_list_prepend(app->main_list, latest_item);
-                       refresh_main_list_view(app, EINA_TRUE);
+                       if (latest_item) {
+                               app->main_list = eina_list_prepend(app->main_list, latest_item);
+                               refresh_main_list_view(app, EINA_TRUE);
+                       }
                } else {
                        tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
-                       app->main_list = eina_list_prepend(app->main_list, latest_item);
-                       refresh_main_list_view(app, EINA_TRUE);
+                       if (latest_item) {
+                               app->main_list = eina_list_prepend(app->main_list, latest_item);
+                               refresh_main_list_view(app, EINA_TRUE);
+                       }
                        elm_naviframe_item_pop(app->nf);
                        app->current_app_state = TG_USER_MAIN_VIEW_STATE;
                        evas_object_show(app->panel);
                        //elm_panel_hidden_set(app->panel, EINA_FALSE);
                }
                app->peer_list = eina_list_prepend(app->peer_list, peer_item);
-#endif
+
        } else if (strcmp(rec_key_val, "contact_updated") == 0) {
 
 
index 81e0501..522e1d9 100644 (file)
@@ -3516,3 +3516,55 @@ int get_number_of_unread_messages()
        eina_list_free(peer_details);
        return no_of_unread;
 }
+
+void create_buddy_msg_table(const char* table_name)
+{
+       if(!table_name) {
+               return;
+       }
+       // create user info table
+       Eina_List* col_names = NULL;
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_ROW_ID);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_ID);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FLAGS);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_FROM_ID);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_DATE);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FROM_ID);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_TO_ID);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_OUT_MSG);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNREAD);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_DATE);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_SERVICE);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_STATE);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_LENGTH);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_TYPE);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_ID);
+       col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNIQUE_ID);
+
+       Eina_List* col_types = NULL;
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_AUTO_INC_KEY);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+       col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+       Eina_Bool ret = create_table(table_name, col_names, col_types);
+       if(!ret) {
+               //("error: database creation failed");
+       }
+       eina_list_free(col_names);
+       eina_list_free(col_types);
+}
index 5040572..b51e42a 100644 (file)
@@ -743,7 +743,8 @@ Evas_Object* on_message_item_content_get_cb(void *data, Evas_Object *obj, const
                        elm_entry_context_menu_disabled_set(entry, EINA_TRUE);
 
                        //elm_entry_magnifier_disabled_set(entry, EINA_TRUE);
-                       elm_entry_selection_handler_disabled_set(entry, EINA_TRUE);
+                       // FIXME: Deprecated API
+                       //elm_entry_selection_handler_disabled_set(entry, EINA_TRUE);
 
                        char *sender_name = NULL;
                        if(msg->out) {
@@ -1998,7 +1999,8 @@ void launch_messaging_view_cb(appdata_s* ad, int user_id)
        elm_object_style_set(chat_conv_list, "solid/default");
        evas_object_size_hint_weight_set(chat_conv_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(chat_conv_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
-       elm_genlist_realization_mode_set(chat_conv_list, EINA_TRUE);
+       // FIXME: Deprecated API
+       //elm_genlist_realization_mode_set(chat_conv_list, EINA_TRUE);
        //evas_object_color_set(chat_conv_list, 255 , 255, 255, 255);
 #endif
 
index 296cc09..52d87f4 100644 (file)
@@ -13,6 +13,7 @@
 #include "tg_settings_view.h"
 #include "tg_db_manager.h"
 #include "server_requests.h"
+#include "tg_db_wrapper.h"
 
 static Evas_Object *create_image_object_from_file(const char *icon_name, Evas_Object *parent)
 {
@@ -541,6 +542,19 @@ void on_main_chat_item_selected(void *data, Evas_Object *obj, void *event_info)
        ad->peer_in_cahtting_data = NULL;
        int buddy_id = -1;
        if (sel_item) {
+
+               if (sel_item->peer_type == TGL_PEER_CHAT) {
+
+                       tg_chat_info_s* chat_info = get_chat_info(sel_item->peer_id);
+                       if (!chat_info) {
+                               // request chat info
+                               //show_toast(ad, "Loading chat info. Please wait.");
+                               show_loading_popup(ad);
+                               send_update_chat_request(ad->service_client, sel_item->peer_id);
+                               return;
+                       }
+               }
+
                if (sel_item->peer_type == TGL_PEER_USER) {
                        for (int i = 0; i < eina_list_count(ad->buddy_list); i++) {
                                user_data_with_pic_s *item = eina_list_nth(ad->buddy_list, i);
@@ -614,6 +628,9 @@ Evas_Object* on_buddy_photo_requested(void *data, Evas_Object *obj, const char *
        int id = (int) data;
        appdata_s* ad = evas_object_data_get(obj, "app_data");
        tg_main_list_item_s* item = eina_list_nth(ad->main_list, id);
+       if (!item) {
+               return eo;
+       }
 
        if (!strcmp(part, "elm.swallow.icon")) {
                int size = eina_list_count(ad->main_list);
index 599d3a7..d7cdeea 100644 (file)
@@ -37,6 +37,9 @@
 #define TELEGRAM_POPUP_VIEW_EDJ        "edje/telegram_custom_popup.edj"
 #define TELEGRAM_GENLIST_THEME_EDJ     "edje/telegram_genlist_theme.edj"
 
+#define TELEGRAM_START_SCREEN_EDJ      "edje/telegram_start_screen.edj"
+
+
 
 #define GRP_MAIN "main"
 #define DEFAULT_TELEGRAM_PATH "/opt/usr/media/telegram/"
index f6cdc9f..5648f65 100644 (file)
@@ -16,6 +16,7 @@ extern void process_send_message_command(int buddy_id, int message_id, int msg_t
 extern void process_marked_as_read_command(int buddy_id, int type_of_chat);
 extern void process_delete_group_chat_request(tg_engine_data_s* tg_data, int chat_id);
 extern void process_add_user_request(tg_engine_data_s* tg_data, int buddy_id);
+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_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);
@@ -45,6 +46,7 @@ extern void send_message_read_by_buddy_response(tg_engine_data_s *tg_data, int b
 extern void send_media_download_completed_response(tg_engine_data_s *tg_data, int buddy_id, int to_id, long long media_id, const char* filename);
 extern void send_video_thumb_download_completed_response(tg_engine_data_s *tg_data, int buddy_id, int to_id, long long media_id, const char* filename);
 extern void send_new_group_added_response(tg_engine_data_s *tg_data, int chat_id);
+extern void send_new_buddy_added_response(tg_engine_data_s *tg_data, int buddy_id);
 extern void send_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id, const char *type_of_change);
 extern void send_chat_profile_pic_updated_response(tg_engine_data_s *tg_data, int chat_id, char* filename);
 extern void send_contact_updated_response(tg_engine_data_s *tg_data, int buddy_id, char* update_message);
@@ -61,4 +63,6 @@ extern void send_buddy_unblocked_response(tg_engine_data_s *tg_data, int buddy_i
 extern void send_group_chat_new_buddy_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success);
 extern void send_group_chat_delete_buddy_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success);
 extern void send_response_for_server_connection_status(tg_engine_data_s *tg_data, Eina_Bool connection_status);
+
+extern void send_response_to_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id);
 #endif /* SERVER_RESPONSE_H_ */
index 9960e76..e59ed49 100644 (file)
@@ -261,5 +261,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_peer_table(int id);
+Eina_Bool is_user_present_chat_table(int id);
 
 #endif /* TG_DB_WRAPPER_H_ */
index f5bc7a0..8c70a1f 100644 (file)
@@ -1839,6 +1839,9 @@ void tgls_free_message_media(struct tgl_state *TLS, struct tgl_message_media *M)
 
 void tgls_free_message_action(struct tgl_state *TLS, struct tgl_message_action *M)
 {
+       if (!M) {
+               return;
+       }
        switch (M->type) {
        case tgl_message_action_none:
                return;
@@ -1877,8 +1880,11 @@ void tgls_free_message_action(struct tgl_state *TLS, struct tgl_message_action *
                        vlogprintf(E_ERROR, "type = 0x%08x\n", M->type);
                        assert(0);*/
        }
+       // sandeep
+       /*
        vlogprintf(E_ERROR, "type = 0x%08x\n", M->type);
        assert(0);
+       */
 }
 
 void tgls_clear_message(struct tgl_state *TLS, struct tgl_message *M)
index 72c48d0..66a2286 100644 (file)
@@ -79,6 +79,14 @@ void process_add_user_request(tg_engine_data_s* tg_data, int buddy_id)
        do_add_buddy(buddy_id);
 }
 
+void process_update_chat_request(tg_engine_data_s* tg_data, int chat_id)
+{
+       if (!tgl_engine_get_TLS()) {
+               return;
+       }
+       do_update_chat_info(chat_id);
+}
+
 
 void process_delete_user_request(tg_engine_data_s* tg_data, int buddy_id)
 {
@@ -238,6 +246,65 @@ void send_new_group_added_response(tg_engine_data_s *tg_data, int chat_id)
        bundle_free(msg);
 }
 
+void send_new_buddy_added_response(tg_engine_data_s *tg_data, int buddy_id)
+{
+       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", "new_buddy_added") != 0) {
+               ERR("Failed to add data by key to bundle");
+               bundle_free(msg);
+       }
+
+       char buddy_id_str[50];
+       sprintf(buddy_id_str,"%d",buddy_id);
+       if (bundle_add_str(msg, "buddy_id", buddy_id_str) != 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_response_to_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id)
+{
+       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", "reponse_group_chat_updated") != 0) {
+               ERR("Failed to add data by key to bundle");
+               bundle_free(msg);
+       }
+
+       char chat_id_str[50];
+       sprintf(chat_id_str,"%d",chat_id);
+       if (bundle_add_str(msg, "chat_id", chat_id_str) != 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_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id, const char *type_of_change)
 {
        bundle *msg = bundle_create();
index 1fc5c2f..d36cd0e 100644 (file)
@@ -88,6 +88,13 @@ static int _on_tg_server_msg_received_cb(void *data, bundle *const rec_msg)
        int buddy_id = atoi(buddy_id_str);
 
        process_add_user_request(tg_data, buddy_id);
+    } else if (strcmp(cmd_key_val, "update_chat_info") == 0) {
+
+       char* chat_id_str = NULL;
+       res = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
+       int chat_id = atoi(chat_id_str);
+
+       process_update_chat_request(tg_data, chat_id);
 
     } else if (strcmp(cmd_key_val, "delete_buddy") == 0) {
 
index f421cfe..ec4dde9 100644 (file)
@@ -4627,3 +4627,76 @@ int get_number_of_unread_messages()
        return no_of_unread;
 }
 
+Eina_Bool is_user_present_peer_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_chat_table(int peer_id)
+{
+       Eina_Bool ret = EINA_FALSE;
+
+       Eina_List* peer_details = NULL;
+       char* table_name = CHAT_INFO_TABLE_NAME;
+
+       Eina_List* col_names = NULL;
+       col_names = eina_list_append(col_names, CHAT_INFO_TABLE_PRINT_TITLE);
+
+       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(CHAT_INFO_TABLE_CHAT_ID) + strlen(" = ") + strlen(chat_id_str) + 1);
+       strcpy(where_clause, CHAT_INFO_TABLE_CHAT_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;
+}
index 68750ee..ba14574 100644 (file)
@@ -51,7 +51,8 @@ static void on_chat_info_received(struct tgl_state *TLS, void *callback_extra, i
 static void on_buddy_info_loaded(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U);
 static void on_chat_pic_loaded(struct tgl_state *TLS, void *callback_extra, int success, char *filename);
 static void on_document_download_completed(struct tgl_state *TLS, void *callback_extra, int success, char *filename);
-
+static void on_buddy_pic_loaded(struct tgl_state *TLS, void *callback_extra, int success, char *filename);
+static void on_new_buddy_info_loaded(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U);
 void tgl_engine_var_init(void)
 {
        s_info.default_username = NULL;
@@ -974,6 +975,23 @@ void on_new_chat_info_received(struct tgl_state *TLS, void *callback_extra, int
                return;
        }
 
+       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);
+                       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;
 
        tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
@@ -1102,7 +1120,124 @@ static Eina_Bool on_msg_received_cb(void *data)
        return ECORE_CALLBACK_CANCEL;
 }
 
+void on_requested_chat_info_received(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_chat *chat_info)
+{
+       tg_engine_data_s *tg_data;
+
+       struct tgl_message *M = callback_extra;
 
+       char *msg_table;
+
+
+       if (!chat_info) {
+               return;
+       }
+       if (!chat_info->user_list) {
+               tgl_do_get_chat_info(TLS, chat_info->id, 0, &on_requested_chat_info_received, callback_extra);
+               return;
+       }
+
+       tg_data = TLS->callback_data;
+
+       msg_table = get_table_name_from_number(chat_info->id.id);
+
+       create_buddy_msg_table(msg_table);
+
+       insert_chat_info_to_db(chat_info, NULL);
+       struct tgl_photo *pic = &(chat_info->photo);
+       if(pic) {
+               tgl_do_load_photo(TLS, pic ,&on_chat_pic_loaded,chat_info);
+       }
+
+       // send message
+       int msg_id = insert_current_date_to_table(msg_table);
+       if (msg_id > 0) {
+               send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, msg_id, tgl_get_peer_type(M->to_id));
+               struct tg_temp_msg_data *msg_data = (struct tg_temp_msg_data*)malloc(sizeof(struct tg_temp_msg_data));
+               msg_data->M = M;
+               msg_data->TLS = TLS;
+               msg_data->send_timer = ecore_timer_add(3, on_msg_received_cb, msg_data);
+       } else {
+               if (M->media.type != tgl_message_media_none && (M->media.document.flags & FLAG_DOCUMENT_AUDIO)) {
+                       M->message = strdup("Audio");
+                       M->message_len = strlen("Audio");
+               } else if (M->media.type != tgl_message_media_none && (M->media.document.flags & FLAG_DOCUMENT_VIDEO)) {
+                       M->message = strdup("Video");
+                       M->message_len = strlen("Video");
+               }
+               insert_buddy_msg_to_db(M);
+               if(M->media.type != tgl_message_media_none) {
+                       insert_media_info_to_db(M, "");
+                       if (M->media.type != tgl_message_media_none && (M->media.document.flags & FLAG_DOCUMENT_VIDEO)) {
+                               tgl_do_load_document_thumb(TLS, &(M->media.document), on_video_thumb_loaded, M);
+                               return;
+                       }
+               }
+               // inform to application
+               send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
+       }
+
+       free(msg_table);
+}
+
+
+void on_requested_update_chat_received(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_chat *chat_info)
+{
+       tg_engine_data_s *tg_data;
+       char *msg_table;
+       msg_table = get_table_name_from_number(chat_info->id.id);
+       create_buddy_msg_table(msg_table);
+       free(msg_table);
+       if (!chat_info) {
+               return;
+       }
+       if (!chat_info->user_list) {
+               tgl_do_get_chat_info(TLS, chat_info->id, 0, &on_chat_info_received, NULL);
+               return;
+       }
+
+       tg_data = TLS->callback_data;
+
+       insert_chat_info_to_db(chat_info, NULL);
+       struct tgl_photo *pic = &(chat_info->photo);
+       if(pic) {
+               tgl_do_load_photo(TLS, pic ,&on_chat_pic_loaded,chat_info);
+       }
+       //char *type_of_change = strdup("add_user");
+       tgl_peer_t* chat_UC = tgl_peer_get(TLS, chat_info->id);
+       insert_chat_info_to_db(chat_info, NULL);
+       insert_peer_into_database(chat_UC, 0, 0);
+       send_response_to_group_chat_updated_response(tg_data, chat_info->id.id);
+       //free(type_of_change);
+}
+
+void do_update_chat_info(int chat_id)
+{
+       tgl_peer_id_t to_id;
+       to_id.id = chat_id;
+       to_id.type = TGL_PEER_CHAT;
+       tgl_do_get_chat_info(s_info.TLS, to_id, 0, &on_requested_update_chat_received, NULL);
+}
+
+void on_new_buddy_info_loaded(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U)
+{
+       if(!U) {
+               return;
+       }
+       tg_engine_data_s *tg_data = TLS->callback_data;
+       if (U->id.id == tg_data->id.id) {
+               return;
+       }
+       tgl_peer_t* UC = tgl_peer_get(TLS, U->id);
+       insert_peer_into_database(UC, 0, 0);
+       insert_buddy_into_db(BUDDY_INFO_TABLE_NAME, U);
+       struct tgl_photo* pic = &(U->photo);
+       if(pic) {
+               tgl_do_load_photo(TLS, pic ,&on_buddy_pic_loaded,U);
+       }
+
+       send_new_buddy_added_response(tg_data, U->id.id);
+}
 
 void tg_msg_receive(struct tgl_state *TLS, struct tgl_message *M)
 {
@@ -1249,7 +1384,14 @@ void tg_msg_receive(struct tgl_state *TLS, struct tgl_message *M)
                                } else if (tgl_get_peer_type(M->to_id) == TGL_PEER_CHAT) {
                                        user_id = M->to_id.id;
                                }
+
+                               Eina_Bool is_present_in_db = is_user_present_peer_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_do_get_user_info(TLS, M->from_id, 0, on_new_buddy_info_loaded, NULL);
+                               }
 
                                int msg_id = insert_current_date_to_table(tb_name);
                                free(tb_name);
@@ -1301,6 +1443,23 @@ void tg_msg_receive(struct tgl_state *TLS, struct tgl_message *M)
                                } else if (tgl_get_peer_type(M->to_id) == TGL_PEER_CHAT) {
                                        user_id = M->to_id.id;
                                }
+
+                               // check whether user is present or not
+
+                               Eina_Bool is_present_in_peer_db = is_user_present_peer_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);
+                                       return;
+                               }
+
+                               Eina_Bool is_present_in_chat_db = is_user_present_chat_table(user_id);
+                               if (!is_present_in_chat_db) {
+                                       //sandeep
+                                       tgl_do_get_chat_info(TLS, M->to_id, 0, &on_requested_chat_info_received, M);
+                                       return;
+                               }
+
                                char* tb_name = get_table_name_from_number(user_id);
                                int msg_id = insert_current_date_to_table(tb_name);
                                free(tb_name);
@@ -1510,6 +1669,9 @@ void on_chat_info_received(struct tgl_state *TLS, void *callback_extra, int succ
        if (!chat_info) {
                return;
        }
+       msg_table = get_table_name_from_number(chat_info->id.id);
+       create_buddy_msg_table(msg_table);
+       free(msg_table);
        if (!chat_info->user_list) {
                tgl_do_get_chat_info(TLS, chat_info->id, 0, &on_chat_info_received, NULL);
                return;
@@ -1517,17 +1679,11 @@ void on_chat_info_received(struct tgl_state *TLS, void *callback_extra, int succ
 
        tg_data = TLS->callback_data;
 
-       msg_table = get_table_name_from_number(chat_info->id.id);
-
-       create_buddy_msg_table(msg_table);
-
        insert_chat_info_to_db(chat_info, NULL);
        struct tgl_photo *pic = &(chat_info->photo);
        if(pic) {
                tgl_do_load_photo(TLS, pic ,&on_chat_pic_loaded,chat_info);
        }
-       free(msg_table);
-
 }
 
 void on_buddy_info_loaded(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U)
index 3d4488a..8d862b6 100644 (file)
@@ -168,6 +168,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 do_delete_buddy(int buddy_id);
 extern void do_add_buddy(int buddy_id);
+extern void do_update_chat_info(int chat_id);
 extern void do_unblock_buddy(int buddy_id);
 extern void do_block_buddy(int buddy_id);
 extern void set_group_chat_profile_picture(tg_engine_data_s *tg_data, int buddy_id, const char *file_path);