From 0db1ca412b54f4c14c10fca6a159eb0266cb44a8 Mon Sep 17 00:00:00 2001 From: "polu.sandeep" Date: Tue, 3 Nov 2015 21:19:53 +0900 Subject: [PATCH] Modified UI as per UX guidelines Change-Id: I15fe77b7010f8d140dbac2943b9bfadefa535052 --- TelegramTizen/inc/server_requests.h | 49 ++-- TelegramTizen/res/edje/telegram_init_screen.edc | 138 ++++++++-- TelegramTizen/src/contact_selection_view.c | 15 +- TelegramTizen/src/group_chat_entry_view.c | 132 ++++++++-- TelegramTizen/src/server_requests.c | 325 +++++++++++++++++++----- TelegramTizen/src/telegramtizen.c | 59 ++++- TelegramTizen/src/tg_add_contact.c | 2 +- TelegramTizen/src/tg_chat_info_view.c | 8 +- TelegramTizen/src/tg_edit_name_view.c | 2 +- TelegramTizen/src/tg_first_registration.c | 2 +- TelegramTizen/src/tg_login.c | 6 +- TelegramTizen/src/tg_main_item_deletion_view.c | 2 +- TelegramTizen/src/tg_registration.c | 2 +- TelegramTizen/src/tg_search_message_view.c | 2 +- TelegramTizen/src/tg_search_peer_view.c | 39 ++- TelegramTizen/src/tg_select_buddy_from_list.c | 6 +- TelegramTizen/src/tg_set_username_view.c | 2 +- TelegramTizen/src/tg_settings_view.c | 31 ++- TelegramTizen/src/tg_user_info_view.c | 6 +- TelegramTizen/src/tg_user_main_view.c | 10 +- TelegramTizen/tg_utils/tg_common.h | 1 + tg-engine-service/inc/server_response.h | 2 + tg-engine-service/src/server_response.c | 28 ++ tg-engine-service/src/tg-engine-service.c | 72 ++++-- tg-engine-service/tg_engine/tg_engine.c | 87 ++++++- tg-engine-service/tg_engine/tg_engine.h | 1 + 26 files changed, 808 insertions(+), 221 deletions(-) diff --git a/TelegramTizen/inc/server_requests.h b/TelegramTizen/inc/server_requests.h index d6926df..a991378 100644 --- a/TelegramTizen/inc/server_requests.h +++ b/TelegramTizen/inc/server_requests.h @@ -10,33 +10,34 @@ #include "tg_common.h" -void send_request_for_restart_server(service_client* service_client); -void send_request_for_logout(service_client* service_client); -void send_request_for_registration(service_client* service_client, const char* phone_number, Eina_Bool through_sms); -void send_request_for_profile_registration(service_client* service_client, const char* first_name, const char* last_name); -void send_request_for_validation(service_client* service_client, const char* sms_code); +void send_request_for_restart_server(appdata_s *ad, service_client* service_client); +void send_request_for_logout(appdata_s *ad, service_client* service_client); +void send_request_for_registration(appdata_s *ad, service_client* service_client, const char* phone_number, Eina_Bool through_sms); +void send_request_for_profile_registration(appdata_s *ad, service_client* service_client, const char* first_name, const char* last_name); +void send_request_for_validation(appdata_s *ad, service_client* service_client, const char* sms_code); // type_of_chat 0-buddy, 1-group_chat 2-encrpted_chat void send_request_for_message_transport(appdata_s *ad, service_client* service_client, const int buddy_id, const int message_id, const int msg_type, const char* data, const int type_of_chat); -void send_request_for_marked_as_read(service_client* service_client, const int buddy_id, const int type_of_chat); -void send_delete_selected_group_chats_request(service_client* service_client, Eina_List *sel_grp_chats); -void send_delete_group_chat_request(service_client* service_client, const int chat_id); -void send_add_buddy_request(service_client* service_client, const int buddy_id, const char *first_name, const char *last_name, const char *phone_number); -void send_delete_buddy_request(service_client* service_client, const int buddy_id); -void send_block_buddy_request(service_client* service_client, const int buddy_id); -void send_unblock_buddy_request(service_client* service_client, const int buddy_id); -Eina_Bool send_request_for_media_downloading(service_client* service_client, const int buddy_id, const long long media_id); +void send_request_for_marked_as_read(appdata_s *ad, service_client* service_client, const int buddy_id, const int type_of_chat); +void send_delete_selected_group_chats_request(appdata_s *ad, service_client* service_client, Eina_List *sel_grp_chats); +void send_delete_group_chat_request(appdata_s *ad, service_client* service_client, const int chat_id); +void send_add_buddy_request(appdata_s *ad, service_client* service_client, const int buddy_id, const char *first_name, const char *last_name, const char *phone_number); +void send_start_secret_chat_request(appdata_s *ad, service_client* service_client, const int buddy_id); +void send_delete_buddy_request(appdata_s *ad, service_client* service_client, const int buddy_id); +void send_block_buddy_request(appdata_s *ad, service_client* service_client, const int buddy_id); +void send_unblock_buddy_request(appdata_s *ad, service_client* service_client, const int buddy_id); +Eina_Bool send_request_for_media_downloading(appdata_s *ad, service_client* service_client, const int buddy_id, const long long media_id); void send_request_for_media_transport(appdata_s *ad, service_client* service_client, const int buddy_id, const int message_id, const int media_id, const int msg_type, const char* file_path, const int type_of_chat); -void send_group_creation_request_to_server(service_client* service_client, Eina_List* buddy_list, const char* group_name, const char* group_image); +void send_group_creation_request_to_server(appdata_s *ad, service_client* service_client, Eina_List* buddy_list, const char* group_name, const char* group_image); -void send_add_buddy_to_group_chat_request(service_client* service_client, int user_id, int chat_id); -void send_set_group_chat_new_title_request(service_client* service_client, int user_id, const char* new_title); -void send_set_group_chat_profile_pic_request(service_client* service_client, int user_id, const char* file_path); -void send_set_profile_pic_request(service_client* service_client, int user_id, const char* file_path); -void send_set_username_request(service_client* service_client, int user_id, const char* username); -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); -void send_update_display_name_request(service_client* service_client, int user_id, const char* first_name, const char* last_name); +void send_add_buddy_to_group_chat_request(appdata_s *ad, service_client* service_client, int user_id, int chat_id); +void send_set_group_chat_new_title_request(appdata_s *ad, service_client* service_client, int user_id, const char* new_title); +void send_set_group_chat_profile_pic_request(appdata_s *ad, service_client* service_client, int user_id, const char* file_path); +void send_set_profile_pic_request(appdata_s *ad, service_client* service_client, int user_id, const char* file_path); +void send_set_username_request(appdata_s *ad, service_client* service_client, int user_id, const char* username); +void send_remove_buddy_from_group_chat_request(appdata_s *ad, service_client* service_client, int user_id, int chat_id); +void send_request_for_delete_notifications(appdata_s *ad, service_client* service_client); +void send_request_for_server_connection_status(appdata_s *ad, service_client* service_client); +void send_update_chat_request(appdata_s *ad, service_client* service_client, const int chat_id); +void send_update_display_name_request(appdata_s *ad, service_client* service_client, int user_id, const char* first_name, const char* last_name); #endif /* SERVER_REQUESTS_H_ */ diff --git a/TelegramTizen/res/edje/telegram_init_screen.edc b/TelegramTizen/res/edje/telegram_init_screen.edc index 6d14dd1..f156659 100644 --- a/TelegramTizen/res/edje/telegram_init_screen.edc +++ b/TelegramTizen/res/edje/telegram_init_screen.edc @@ -1990,6 +1990,23 @@ group } } + group { + name: "add_contact_custom_item"; + parts { + part { + name: "swallow.item"; + type: SWALLOW; + description { + state: default 0.0; + min: 720 440; + rel1.relative: 0.0 0.0; + rel2.relative: 1.0 1.0; + color: 0 0 0 0; + } + } + } + } + group { name: "main_list_custom_sent_item"; parts { @@ -2836,16 +2853,16 @@ group { name: "group_chat_entry"; parts{ - part{ - name: "group_chat_entry_box,bg"; - type:RECT; - description{ - state: "default" 0.0; - rel1 { relative: 0.0 0.0; } - rel2 { relative: 1.0 0.2; } - color: 255 255 255 255; - } - } + part { + name: "view_bg"; + type: RECT; + description { + state: "default" 0.0; + rel1 { relative: 0.0 0.0; } + rel2 { relative: 1.0 0.2; } + color: 255 255 255 255; + } + } part{ name: "swallow.group_chat_entry_box"; type:SWALLOW; @@ -2896,26 +2913,42 @@ group { name: "group_chat_photo_name_entry"; parts{ + part{ + name: "swallow.cam_box, bg"; + type: RECT; + description{ + state: "default" 0.0; + rel1 { relative: 0.0 0.0; } + rel2 { relative: 1.0 0.9; } + color: 255 255 255 255; + } + } + part{ name: "swallow.cam_box"; - type:SWALLOW; + type: SWALLOW; description{ state: "default" 0.0; - rel1 { relative: 0.1 0.2; } - rel2 { relative: 0.25 0.8; } - } + rel1 { relative: 0.0 0.0; } + rel2 { relative: 1.0 0.9; } + color: 0 0 0 0; + } } - - part { - name: "entry_box,bg"; - type: RECT; - description { - state: "default" 0.0; - rel1 { relative: 0.3 0.3; } - rel2 { relative: 0.95 0.65; } - color: 222 222 222 222; - } - } + + part{ + name: "swallow.entry_box,bg"; + type: IMAGE; + description{ + state: "default" 0.0; + rel1 { relative: 0.28 0.65; } + rel2 { relative: 0.9 0.68; } + max: 800 2; + image { + normal: "telegram_date_divider.#.png"; + } + color: 0 0 0 51; + } + } part{ name: "swallow.entry_box"; @@ -2923,7 +2956,7 @@ group description{ state: "default" 0.0; rel1 { relative: 0.3 0.3;} - rel2 { relative: 0.95 0.65;} + rel2 { relative: 0.87 0.65;} color: 50 100 255 255; } } @@ -2979,6 +3012,59 @@ group } } + + + + group { + name: "group_circle_layout"; + parts { + part { + name: masking_bg; + type: RECT; + precise_is_inside: 1; + description { + state: default 0.0; + rel1.relative: 0.0 0.0; + rel2.relative: 1.0 1.0; + color: 250 250 250 0; + } + } + part { + name: masking; + type: IMAGE; + precise_is_inside: 1; + description { + state: default 0.0; + rel1.relative: 0.0 0.0; + rel2.relative: 1.0 1.0; + image.normal: camera_btn_gallery_mask.png; + } + } + part { + name: content_bg; + type: RECT; + clip_to: masking; + description { + state: default 0.0; + rel1.relative: 0.0 -0.4; + rel2.relative: 1.0 1.4; + color: 250 250 250 255; + } + } + part { + name: content; + type: SWALLOW; + clip_to: masking; + description { + state: default 0.0; + rel1.relative: 0.0 -0.4; + rel2.relative: 1.0 1.4; + } + } + } + } + + images { image: "telegram_attach_image_round_bg.#.png" COMP; image: "telegram_attach_image_round_line.#.png" COMP; diff --git a/TelegramTizen/src/contact_selection_view.c b/TelegramTizen/src/contact_selection_view.c index 51112f7..4cf652d 100644 --- a/TelegramTizen/src/contact_selection_view.c +++ b/TelegramTizen/src/contact_selection_view.c @@ -103,12 +103,13 @@ char* on_buddy_name_get_cb(void *data, Evas_Object *obj, const char *part) user_data_with_pic_s* item = eina_list_nth(list, id - 1); user_data_s* user = item->use_data; - char* user_name = replace(user->print_name, '_', " "); - char buf[512] = {'\0'}; - snprintf(buf, 512, "%s", user_name); - free(user_name); - return strdup(buf); - + if (user && user->print_name) { + char* user_name = replace(user->print_name, '_', " "); + char buf[512] = {'\0'}; + snprintf(buf, 512, "%s", user_name); + free(user_name); + return strdup(buf); + } } } @@ -285,7 +286,7 @@ void on_done_buton_clicked(void *data, Evas_Object *object, void *event_info) if (selected_item_count > 1) { appdata_s* ad = data; - elm_naviframe_item_pop(ad->nf); + // elm_naviframe_item_pop(ad->nf); // Load chat name entry view launch_group_chat_name_entry_view(ad); } else { diff --git a/TelegramTizen/src/group_chat_entry_view.c b/TelegramTizen/src/group_chat_entry_view.c index f1caae4..ab88411 100644 --- a/TelegramTizen/src/group_chat_entry_view.c +++ b/TelegramTizen/src/group_chat_entry_view.c @@ -21,9 +21,9 @@ char* on_image_load_text_get_cb(void *data, Evas_Object *obj, const char *part) { int id = (int) data; if (id == 0) { - return strdup("Camera"); + return strdup(_("IDS_TGRAM_OPT_FROM_GALLERY_ABB2")); } else { - return strdup("Gallery"); + return strdup(_("IDS_TGRAM_OPT_TAKE_PICTURE_ABB")); } } @@ -39,6 +39,7 @@ void on_camera_result_cb(app_control_h request, app_control_h reply, app_control file_path = strdup(path_arryay[i]); evas_object_data_set(user_data, "image_path", (void*)file_path); elm_image_file_set(user_data, file_path, NULL); + evas_object_color_set(user_data, 255, 255, 255, 255); break; } } @@ -63,7 +64,7 @@ void on_image_load_option_selected_cb(void *data, Evas_Object *obj, void *event_ return; } - if (id == 0) { + if (id == 1) { app_control_set_operation(app_control, APP_CONTROL_OPERATION_CREATE_CONTENT); app_control_set_mime(app_control, "image/jpg"); app_control_send_launch_request(app_control, &on_camera_result_cb, cam_icon); @@ -91,7 +92,7 @@ void on_image_load_options_cb(void *data, Evas_Object *obj, void *event_info) popup = elm_popup_add(win); elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0); eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL); - elm_object_part_text_set(popup, "title,text", "Load image from"); + elm_object_part_text_set(popup, "title,text", i18n_get_text("IDS_TGRAM_HEADER_SELECT_IMAGE_ABB2")); evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_data_set(popup, "cam_icon", cam_icon); @@ -124,7 +125,8 @@ void on_image_load_options_cb(void *data, Evas_Object *obj, void *event_info) void on_group_buddy_selected(void *data, Evas_Object *obj, void *event_info) { - // nothing to do + Elm_Object_Item *it = event_info; + elm_genlist_item_selected_set(it, EINA_FALSE); } char* on_group_buddy_name_get_cb(void *data, Evas_Object *obj, const char *part) @@ -183,14 +185,14 @@ Evas_Object* on_group_buddy_selection_part_content_get_cb(void *data, Evas_Objec char edj_path[PATH_MAX] = {0, }; app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX); Evas_Object* user_pic_layout = elm_layout_add(obj); - elm_layout_file_set(user_pic_layout, edj_path, "circle_layout"); + elm_layout_file_set(user_pic_layout, edj_path, "search_circle_layout"); evas_object_size_hint_weight_set(user_pic_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(user_pic_layout); elm_object_part_content_set(user_pic_layout, "content", profile_pic); eo = elm_layout_add(obj); - elm_layout_theme_set(eo, "layout", "list/C/type.3", "default"); + elm_layout_theme_set(eo, "layout", "list/B/type.2", "default"); elm_layout_content_set(eo, "elm.swallow.content", user_pic_layout); } return eo; @@ -219,10 +221,13 @@ void on_group_chat_done_buton_clicked(void *data, Evas_Object *object, void *eve } Eina_List* selected_buddies = evas_object_data_get(name_entry, "selected_buddies"); - Evas_Object* cam_icon = evas_object_data_get(name_entry, "cam_icon"); + //Evas_Object* cam_icon = evas_object_data_get(name_entry, "cam_icon"); + Evas_Object* cam_icon = evas_object_data_get(ad->nf, "group_chat_profile_pic"); char* img_file_path = evas_object_data_get(cam_icon, "image_path"); - send_group_creation_request_to_server(ad->service_client, selected_buddies, group_name, img_file_path); + show_loading_popup(ad); + + send_group_creation_request_to_server(ad, ad->service_client, selected_buddies, group_name, img_file_path); eina_list_free(selected_buddies); } @@ -242,6 +247,42 @@ void on_group_chat_cancel_buton_clicked(void *data, Evas_Object *object, void *e elm_panel_hidden_set(ad->panel, EINA_FALSE); } +char* group_chat_entry_requested_cb(void *data, Evas_Object *obj, const char *part) +{ + //int id = (int) data; + return NULL; +} + +Evas_Object* group_chat_pic_requested_cb(void *data, Evas_Object *obj, const char *part) +{ + Evas_Object *eo = NULL; + if (!strcmp(part, "elm.icon.left") || !strcmp(part, "elm.icon.1") || !strcmp(part, "elm.swallow.icon") ) { + appdata_s* ad = evas_object_data_get(obj, "app_data"); + int id = (int) data; + if (id == 0) { + Evas_Object *profile_pic = NULL; + profile_pic = create_image_object_from_file(ui_utils_get_resource(DEFAULT_LIST_THUMB_MULTI_PIC), ad->nf); + evas_object_color_set(profile_pic, 45, 165, 224, 255); + evas_object_data_set(profile_pic, "app_data", ad); + evas_object_smart_callback_add(profile_pic, "clicked", on_image_load_options_cb, (void*)profile_pic); + char edj_path[PATH_MAX] = {0, }; + app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX); + Evas_Object* user_pic_layout = elm_layout_add(ad->nf); + elm_layout_file_set(user_pic_layout, edj_path, "group_circle_layout"); + evas_object_size_hint_weight_set(user_pic_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(user_pic_layout); + elm_object_part_content_set(user_pic_layout, "content", profile_pic); + evas_object_data_set(ad->nf, "group_chat_profile_pic", profile_pic); + + eo = elm_layout_add(obj); + elm_layout_theme_set(eo, "layout", "list/B/type.1", "default"); + elm_layout_content_set(eo, "elm.swallow.content", user_pic_layout); + } + } + return eo; +} + void launch_group_chat_name_entry_view(void *data) { appdata_s* ad = data; @@ -268,25 +309,67 @@ void launch_group_chat_name_entry_view(void *data) evas_object_show(entry_layout); elm_object_part_content_set(main_layout, "swallow.group_chat_entry_box", entry_layout); +#if 0 Evas_Object* cam_icon = elm_image_add(main_layout); elm_image_file_set(cam_icon, ui_utils_get_resource(CAMERA_ICON), NULL); evas_object_show(cam_icon); +#endif +#if 0 + + Evas_Object *cam_icon = create_image_object_from_file(ui_utils_get_resource(DEFAULT_LIST_THUMB_MULTI_PIC), main_layout); + evas_object_color_set(cam_icon, 45, 165, 224, 255); + + + Evas_Object *user_pic_layout = elm_layout_add(ad->nf); + elm_layout_file_set(user_pic_layout, edj_path, "search_circle_layout"); + evas_object_size_hint_weight_set(user_pic_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(user_pic_layout); + elm_object_part_content_set(user_pic_layout, "content", cam_icon); Evas_Object* eo = elm_layout_add(main_layout); - elm_layout_theme_set(eo, "layout", "list/C/type.3", "default"); - elm_layout_content_set(eo, "elm.swallow.content", cam_icon); + elm_layout_theme_set(eo, "layout", "list/B/type.1", "default"); + elm_layout_content_set(eo, "elm.swallow.content", user_pic_layout); evas_object_smart_callback_add(cam_icon, "clicked", on_image_load_options_cb, (void*)cam_icon); elm_object_part_content_set(entry_layout, "swallow.cam_box", eo); +#endif + + /********************* list *************************/ + + + Evas_Object *list = elm_genlist_add(ad->nf); + elm_list_mode_set(list, ELM_LIST_COMPRESS); + elm_genlist_mode_set(list, ELM_LIST_COMPRESS); + evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(list); + + elm_object_part_content_set(entry_layout, "swallow.cam_box", list); + + evas_object_data_set(ad->nf, "group_chat_entry_list", list); + evas_object_data_set(list, "app_data", ad); + static Elm_Genlist_Item_Class itc1; + itc1.item_style = "type1"; + itc1.func.text_get = group_chat_entry_requested_cb; + itc1.func.content_get = group_chat_pic_requested_cb; + itc1.func.state_get = NULL; + itc1.func.del = NULL; + + elm_genlist_item_append(list, &itc1, (void*) 0, NULL, ELM_GENLIST_ITEM_NONE, on_group_buddy_selected, (void*)ad); + + + /******************** list *************************/ + Evas_Object* name_entry = elm_entry_add(main_layout); elm_entry_single_line_set(name_entry, EINA_TRUE); + limit_filter_data.max_char_count = 20; + elm_entry_markup_filter_append(name_entry, elm_entry_filter_limit_size, &limit_filter_data); evas_object_show(name_entry); elm_object_part_content_set(entry_layout, "swallow.entry_box", name_entry); - - Eina_List* selected_buddies = NULL; for (int i = 0 ; i < eina_list_count(ad->buddy_list) ; i++) { @@ -303,8 +386,11 @@ void launch_group_chat_name_entry_view(void *data) evas_object_size_hint_weight_set(contact_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(contact_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL); + char res_str[256] = {'\0'}; + sprintf(res_str, i18n_get_text("IDS_TGRAM_BODY_PD_PARTICIPANTS"), eina_list_count(selected_buddies)); + char count_str[256] = {'\0'}; - sprintf(count_str, "  %d contacts selected", eina_list_count(selected_buddies)); + sprintf(count_str, "  %s", res_str); elm_object_text_set(contact_lbl, count_str); elm_object_part_content_set(main_layout, "swallow.contacts_header", contact_lbl); @@ -323,12 +409,12 @@ void launch_group_chat_name_entry_view(void *data) evas_object_data_set(buddy_gen_list, "app_data", ad); evas_object_data_set(buddy_gen_list, "selected_buddies", (void*)selected_buddies); - evas_object_data_set(cam_icon, "app_data", ad); - evas_object_data_set(cam_icon, "selected_buddies", (void*)selected_buddies); + //evas_object_data_set(cam_icon, "app_data", ad); + //evas_object_data_set(cam_icon, "selected_buddies", (void*)selected_buddies); evas_object_data_set(name_entry, "app_data", ad); evas_object_data_set(name_entry, "selected_buddies", (void*)selected_buddies); - evas_object_data_set(name_entry, "cam_icon", cam_icon); + //evas_object_data_set(name_entry, "cam_icon", cam_icon); itc.item_style = "default_style"; itc.func.text_get = on_group_buddy_name_get_cb; @@ -353,16 +439,16 @@ void launch_group_chat_name_entry_view(void *data) Elm_Object_Item* chat_nav_item = elm_naviframe_item_push(ad->nf, "New Group", NULL, NULL, scroller, NULL); - Evas_Object* done_btn = elm_button_add(ad->layout); - elm_object_style_set(done_btn, "naviframe/title_icon"); + Evas_Object *done_btn = elm_button_add(ad->nf); + elm_object_style_set(done_btn, "naviframe/title_right"); + elm_object_text_set(done_btn, i18n_get_text("IDS_TGRAM_ACBUTTON_DONE_ABB")); evas_object_smart_callback_add(done_btn, "clicked", on_group_chat_done_buton_clicked, name_entry); - elm_object_text_set(done_btn, "Done"); evas_object_show(done_btn); - Evas_Object* cancel_btn = elm_button_add(ad->layout); - elm_object_style_set(cancel_btn, "naviframe/title_icon"); + Evas_Object *cancel_btn = elm_button_add(ad->nf); + elm_object_style_set(cancel_btn, "naviframe/title_left"); + elm_object_text_set(cancel_btn, i18n_get_text("IDS_TGRAM_ACBUTTON_CANCEL_ABB")); evas_object_smart_callback_add(cancel_btn, "clicked", on_group_chat_cancel_buton_clicked, ad); - elm_object_text_set(cancel_btn, "Cancel"); evas_object_show(cancel_btn); elm_object_item_part_content_set(chat_nav_item, "title_right_btn", done_btn); diff --git a/TelegramTizen/src/server_requests.c b/TelegramTizen/src/server_requests.c index 0808fe8..f4d18e3 100644 --- a/TelegramTizen/src/server_requests.c +++ b/TelegramTizen/src/server_requests.c @@ -7,33 +7,44 @@ #include "server_requests.h" #include "tg_db_wrapper.h" +static void failed_to_communicate_server(appdata_s *ad) +{ + if (!ad) + return; + hide_loading_popup(ad); + show_toast(ad, "Check your network settings."); +} -void send_request_for_restart_server(service_client* service_client) +void send_request_for_restart_server(appdata_s *ad, service_client* service_client) { bundle *msg; int result; if (!service_client) { // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { LOGE("Failed to create a bundle"); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "restart_server") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -41,36 +52,41 @@ void send_request_for_restart_server(service_client* service_client) if(result != SVC_RES_OK) { // error LOGE("Failed to send a service message"); + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_request_for_logout(service_client* service_client) +void send_request_for_logout(appdata_s *ad, service_client* service_client) { bundle *msg; int result; if (!service_client) { // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { LOGE("Failed to create a bundle"); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "logout_telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -78,49 +94,56 @@ void send_request_for_logout(service_client* service_client) if(result != SVC_RES_OK) { // error LOGE("Failed to send a service message"); + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_request_for_registration(service_client* service_client, const char* phone_number, Eina_Bool through_sms) +void send_request_for_registration(appdata_s *ad, service_client* service_client, const char* phone_number, Eina_Bool through_sms) { bundle *msg; int result; if (!service_client || !phone_number) { // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { LOGE("Failed to create a bundle"); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "registration") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "phone_number", phone_number) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "through_sms", (through_sms) ? "true" : "false") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -128,101 +151,111 @@ void send_request_for_registration(service_client* service_client, const char* p if(result != SVC_RES_OK) { // error LOGE("Failed to send a service message"); + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_request_for_profile_registration(service_client* service_client, const char* first_name, const char* last_name) +void send_request_for_profile_registration(appdata_s *ad, service_client* service_client, const char* first_name, const char* last_name) { bundle *msg; int result; if (!service_client || !first_name || !last_name) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "profile_registration") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "first_name", first_name) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "last_name", last_name) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } result = service_client_send_message(service_client, msg); - if(result != SVC_RES_OK) { - // error + if (result != SVC_RES_OK) { + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_request_for_validation(service_client* service_client, const char* sms_code) +void send_request_for_validation(appdata_s *ad, service_client* service_client, const char* sms_code) { bundle *msg; int result; if (!service_client || !sms_code) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "code_validation") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "sms_code", sms_code) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } result = service_client_send_message(service_client, msg); if (result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_add_buddy_request(service_client* service_client, const int buddy_id, const char *first_name, const char *last_name, const char *phone_number) +void send_add_buddy_request(appdata_s *ad, service_client* service_client, const int buddy_id, const char *first_name, const char *last_name, const char *phone_number) { if (!service_client) { - // error + failed_to_communicate_server(ad); return; } bundle *msg; @@ -230,18 +263,21 @@ void send_add_buddy_request(service_client* service_client, const int buddy_id, int result; msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "add_buddy") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id); @@ -249,35 +285,39 @@ void send_add_buddy_request(service_client* service_client, const int buddy_id, if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "first_name", first_name) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "last_name", last_name) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "phone_number", phone_number) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_update_chat_request(service_client* service_client, const int chat_id) +void send_update_chat_request(appdata_s *ad, service_client* service_client, const int chat_id) { if (!service_client) { // error @@ -288,18 +328,21 @@ void send_update_chat_request(service_client* service_client, const int chat_id) int result; msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "update_chat_info") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } snprintf(tmp, sizeof(tmp) - 1, "%d", chat_id); @@ -307,21 +350,22 @@ void send_update_chat_request(service_client* service_client, const int chat_id) if (bundle_add_str(msg, "chat_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_delete_buddy_request(service_client* service_client, const int buddy_id) +void send_start_secret_chat_request(appdata_s *ad, service_client* service_client, const int buddy_id) { if (!service_client) { - // error + failed_to_communicate_server(ad); return; } bundle *msg; @@ -329,18 +373,66 @@ void send_delete_buddy_request(service_client* service_client, const int buddy_i int result; msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); + return; + } + + if (bundle_add_str(msg, "command", "start_secret_chat") != 0) { + ERR("Failed to add data by key to bundle"); + bundle_free(msg); + failed_to_communicate_server(ad); + return; + } + snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id); + + if (bundle_add_str(msg, "buddy_id", tmp) != 0) { + ERR("Failed to add data by key to bundle"); + bundle_free(msg); + failed_to_communicate_server(ad); + return; + } + + result = service_client_send_message(service_client, msg); + if(result != SVC_RES_OK) { + failed_to_communicate_server(ad); + } + bundle_free(msg); +} + + +void send_delete_buddy_request(appdata_s *ad, service_client* service_client, const int buddy_id) +{ + if (!service_client) { + failed_to_communicate_server(ad); + return; + } + bundle *msg; + char tmp[50]; + int result; + msg = bundle_create(); + if (!msg) { + failed_to_communicate_server(ad); + return; + } + + if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { + ERR("Failed to add data by key to bundle"); + bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "delete_buddy") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id); @@ -348,21 +440,22 @@ void send_delete_buddy_request(service_client* service_client, const int buddy_i if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_block_buddy_request(service_client* service_client, const int buddy_id) +void send_block_buddy_request(appdata_s *ad, service_client* service_client, const int buddy_id) { if (!service_client) { - // error + failed_to_communicate_server(ad); return; } bundle *msg; @@ -370,18 +463,21 @@ void send_block_buddy_request(service_client* service_client, const int buddy_id int result; msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "block_buddy") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id); @@ -389,17 +485,18 @@ void send_block_buddy_request(service_client* service_client, const int buddy_id if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_unblock_buddy_request(service_client* service_client, const int buddy_id) +void send_unblock_buddy_request(appdata_s *ad, service_client* service_client, const int buddy_id) { if (!service_client) { // error @@ -410,18 +507,21 @@ void send_unblock_buddy_request(service_client* service_client, const int buddy_ int result; msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "unblock_buddy") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id); @@ -429,12 +529,13 @@ void send_unblock_buddy_request(service_client* service_client, const int buddy_ if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } @@ -442,10 +543,10 @@ void send_unblock_buddy_request(service_client* service_client, const int buddy_ -void send_delete_selected_group_chats_request(service_client* service_client, Eina_List *sel_grp_chats) +void send_delete_selected_group_chats_request(appdata_s *ad, service_client* service_client, Eina_List *sel_grp_chats) { if (!service_client || !sel_grp_chats) { - // error + failed_to_communicate_server(ad); return; } bundle *msg; @@ -454,18 +555,21 @@ void send_delete_selected_group_chats_request(service_client* service_client, Ei int result; msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "delete_selected_group_chats_request") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -478,6 +582,7 @@ void send_delete_selected_group_chats_request(service_client* service_client, Ei if (bundle_add_str(msg, "list_size", cnt_str) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -490,23 +595,23 @@ void send_delete_selected_group_chats_request(service_client* service_client, Ei if (bundle_add_str(msg, chat_id_key, tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } - -void send_delete_group_chat_request(service_client* service_client, const int chat_id) +void send_delete_group_chat_request(appdata_s *ad, service_client* service_client, const int chat_id) { if (!service_client) { - // error + failed_to_communicate_server(ad); return; } bundle *msg; @@ -514,18 +619,21 @@ void send_delete_group_chat_request(service_client* service_client, const int ch int result; msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "delete_group_chat_request") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } snprintf(tmp, sizeof(tmp) - 1, "%d", chat_id); @@ -533,41 +641,45 @@ void send_delete_group_chat_request(service_client* service_client, const int ch if (bundle_add_str(msg, "chat_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_request_for_marked_as_read(service_client* service_client, const int buddy_id, const int type_of_chat) +void send_request_for_marked_as_read(appdata_s *ad, service_client* service_client, const int buddy_id, const int type_of_chat) { bundle *msg; char tmp[50]; int result; if (!service_client) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "marked_as_read") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -576,6 +688,7 @@ void send_request_for_marked_as_read(service_client* service_client, const int b if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -583,12 +696,13 @@ void send_request_for_marked_as_read(service_client* service_client, const int b if (bundle_add_str(msg, "type_of_chat", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } @@ -603,24 +717,27 @@ void send_request_for_message_transport(appdata_s *ad, service_client* service_c char *msg_type_str = NULL; char *type_of_chat_str = NULL; if (!service_client || !data) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "message_transport") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -629,6 +746,7 @@ void send_request_for_message_transport(appdata_s *ad, service_client* service_c if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -637,6 +755,7 @@ void send_request_for_message_transport(appdata_s *ad, service_client* service_c if (bundle_add_str(msg, "message_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -645,12 +764,14 @@ void send_request_for_message_transport(appdata_s *ad, service_client* service_c if (bundle_add_str(msg, "message_type", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "message_data", data) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -660,6 +781,7 @@ void send_request_for_message_transport(appdata_s *ad, service_client* service_c if (bundle_add_str(msg, "type_of_chat", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -667,6 +789,7 @@ void send_request_for_message_transport(appdata_s *ad, service_client* service_c if (result != SVC_RES_OK || !ad->is_server_ready) { // error insert_unsent_message_to_db("Tizen Telegram", "message_transport", buddy_id_str, msg_id_str, msg_type_str, data, type_of_chat_str); + failed_to_communicate_server(ad); } bundle_free(msg); @@ -703,24 +826,27 @@ void send_request_for_media_transport(appdata_s *ad, service_client* service_cli char *msg_type_str = NULL; char *type_of_chat_str = NULL; if (!service_client) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "media_transport") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -729,6 +855,7 @@ void send_request_for_media_transport(appdata_s *ad, service_client* service_cli if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -737,6 +864,7 @@ void send_request_for_media_transport(appdata_s *ad, service_client* service_cli if (bundle_add_str(msg, "message_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -745,6 +873,7 @@ void send_request_for_media_transport(appdata_s *ad, service_client* service_cli if (bundle_add_str(msg, "media_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -753,6 +882,7 @@ void send_request_for_media_transport(appdata_s *ad, service_client* service_cli if (bundle_add_str(msg, "message_type", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -760,12 +890,14 @@ void send_request_for_media_transport(appdata_s *ad, service_client* service_cli if (bundle_add_str(msg, "file_path", file_path) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } } else { if (bundle_add_str(msg, "file_path", "") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } } @@ -775,12 +907,14 @@ void send_request_for_media_transport(appdata_s *ad, service_client* service_cli if (bundle_add_str(msg, "type_of_chat", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } result = service_client_send_message(service_client, msg); if (result != SVC_RES_OK || !ad->is_server_ready) { insert_unsent_media_message_to_db("Tizen Telegram", "message_transport", buddy_id_str, msg_id_str, media_id_str, msg_type_str, file_path, type_of_chat_str); + failed_to_communicate_server(ad); } bundle_free(msg); @@ -807,7 +941,7 @@ void send_request_for_media_transport(appdata_s *ad, service_client* service_cli } -Eina_Bool send_request_for_media_downloading(service_client* service_client, const int buddy_id, const long long media_id) +Eina_Bool send_request_for_media_downloading(appdata_s *ad, service_client* service_client, const int buddy_id, const long long media_id) { bundle *msg; char tmp[50]; @@ -815,23 +949,27 @@ Eina_Bool send_request_for_media_downloading(service_client* service_client, con if (!service_client) { // error + failed_to_communicate_server(ad); return EINA_FALSE; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return EINA_FALSE; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return EINA_FALSE; } if (bundle_add_str(msg, "command", "media_download_request") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return EINA_FALSE; } @@ -839,25 +977,27 @@ Eina_Bool send_request_for_media_downloading(service_client* service_client, con if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); + failed_to_communicate_server(ad); bundle_free(msg); } - snprintf(tmp, sizeof(tmp) - 1, "%lld", media_id); if (bundle_add_str(msg, "media_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { + failed_to_communicate_server(ad); return EINA_FALSE; } bundle_free(msg); return EINA_TRUE; } -void send_group_creation_request_to_server(service_client* service_client, Eina_List* buddy_list, const char* group_name, const char* group_image) +void send_group_creation_request_to_server(appdata_s *ad, service_client* service_client, Eina_List* buddy_list, const char* group_name, const char* group_image) { bundle *msg; int count; @@ -870,24 +1010,27 @@ void send_group_creation_request_to_server(service_client* service_client, Eina_ int result; if (!service_client || !buddy_list || !group_name) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "group_creation_request") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -897,6 +1040,7 @@ void send_group_creation_request_to_server(service_client* service_client, Eina_ if (bundle_add_str(msg, "count", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -914,6 +1058,7 @@ void send_group_creation_request_to_server(service_client* service_client, Eina_ if (bundle_add_str(msg, buddy_id_key, tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -923,6 +1068,7 @@ void send_group_creation_request_to_server(service_client* service_client, Eina_ if (bundle_add_str(msg, "group_name", group_name) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -930,49 +1076,53 @@ void send_group_creation_request_to_server(service_client* service_client, Eina_ if (bundle_add_str(msg, "group_image", group_image) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } } else { if (bundle_add_str(msg, "group_image", "") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); - } -void send_set_group_chat_new_title_request(service_client* service_client, int user_id, const char* new_title) +void send_set_group_chat_new_title_request(appdata_s *ad, service_client* service_client, int user_id, const char* new_title) { bundle *msg; char tmp[50]; int result; if (!service_client || !new_title) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "set_group_chat_new_title_request") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -981,21 +1131,23 @@ void send_set_group_chat_new_title_request(service_client* service_client, int u if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } if (bundle_add_str(msg, "new_title", new_title) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_remove_buddy_from_group_chat_request(service_client* service_client, int user_id, int chat_id) +void send_remove_buddy_from_group_chat_request(appdata_s *ad, service_client* service_client, int user_id, int chat_id) { bundle *msg; char tmp[50]; @@ -1003,24 +1155,27 @@ void send_remove_buddy_from_group_chat_request(service_client* service_client, i int result; if (!service_client) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "remove_buddy_from_chat_request") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -1029,6 +1184,7 @@ void send_remove_buddy_from_group_chat_request(service_client* service_client, i if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } snprintf(ctmp, sizeof(ctmp) - 1, "%d", chat_id); @@ -1036,17 +1192,17 @@ void send_remove_buddy_from_group_chat_request(service_client* service_client, i if (bundle_add_str(msg, "chat_id", ctmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } - result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_add_buddy_to_group_chat_request(service_client* service_client, int user_id, int chat_id) +void send_add_buddy_to_group_chat_request(appdata_s *ad, service_client* service_client, int user_id, int chat_id) { bundle *msg; char tmp[50]; @@ -1054,24 +1210,27 @@ void send_add_buddy_to_group_chat_request(service_client* service_client, int us int result; if (!service_client) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "add_new_buddy_to_chat_request") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -1080,6 +1239,7 @@ void send_add_buddy_to_group_chat_request(service_client* service_client, int us if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } snprintf(ctmp, sizeof(ctmp) - 1, "%d", chat_id); @@ -1087,41 +1247,44 @@ void send_add_buddy_to_group_chat_request(service_client* service_client, int us if (bundle_add_str(msg, "chat_id", ctmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } - result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_set_group_chat_profile_pic_request(service_client* service_client, int user_id, const char* file_path) +void send_set_group_chat_profile_pic_request(appdata_s *ad, service_client* service_client, int user_id, const char* file_path) { bundle *msg; char tmp[50]; int result; if (!service_client || !file_path) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "set_group_chat_profile_pic_request") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -1130,45 +1293,50 @@ void send_set_group_chat_profile_pic_request(service_client* service_client, int if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } if (bundle_add_str(msg, "file_path", file_path) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_set_profile_pic_request(service_client* service_client, int user_id, const char* file_path) +void send_set_profile_pic_request(appdata_s *ad, service_client* service_client, int user_id, const char* file_path) { bundle *msg; char tmp[50]; int result; if (!service_client || !file_path) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "set_profile_pic_request") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -1177,45 +1345,50 @@ void send_set_profile_pic_request(service_client* service_client, int user_id, c if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } if (bundle_add_str(msg, "file_path", file_path) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_update_display_name_request(service_client* service_client, int user_id, const char* first_name, const char* last_name) +void send_update_display_name_request(appdata_s *ad, service_client* service_client, int user_id, const char* first_name, const char* last_name) { bundle *msg; char tmp[50]; int result; if (!service_client || !first_name || !last_name) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "update_display_name_request") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -1224,51 +1397,57 @@ void send_update_display_name_request(service_client* service_client, int user_i if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } if (bundle_add_str(msg, "first_name", first_name) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } if (bundle_add_str(msg, "last_name", last_name) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_set_username_request(service_client* service_client, int user_id, const char* username) +void send_set_username_request(appdata_s *ad, service_client* service_client, int user_id, const char* username) { bundle *msg; char tmp[50]; int result; if (!service_client || !username) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "set_username_request") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -1277,46 +1456,51 @@ void send_set_username_request(service_client* service_client, int user_id, cons if (bundle_add_str(msg, "buddy_id", tmp) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } if (bundle_add_str(msg, "username", username) != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); } result = service_client_send_message(service_client, msg); if(result != SVC_RES_OK) { - // error + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_request_for_delete_notifications(service_client* service_client) +void send_request_for_delete_notifications(appdata_s *ad, service_client* service_client) { bundle *msg; int result; if (!service_client) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { LOGE("Failed to create a bundle"); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "delete_all_notifications") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -1324,36 +1508,40 @@ void send_request_for_delete_notifications(service_client* service_client) if(result != SVC_RES_OK) { // error LOGE("Failed to send a service message"); + failed_to_communicate_server(ad); } bundle_free(msg); } -void send_request_for_server_connection_status(service_client* service_client) +void send_request_for_server_connection_status(appdata_s *ad, service_client* service_client) { bundle *msg; int result; if (!service_client) { - // error + failed_to_communicate_server(ad); return; } msg = bundle_create(); if (!msg) { LOGE("Failed to create a bundle"); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } if (bundle_add_str(msg, "command", "server_connection_status") != 0) { ERR("Failed to add data by key to bundle"); bundle_free(msg); + failed_to_communicate_server(ad); return; } @@ -1361,6 +1549,7 @@ void send_request_for_server_connection_status(service_client* service_client) if(result != SVC_RES_OK) { // error LOGE("Failed to send a service message"); + failed_to_communicate_server(ad); } bundle_free(msg); diff --git a/TelegramTizen/src/telegramtizen.c b/TelegramTizen/src/telegramtizen.c index 80864c7..8aa5b26 100644 --- a/TelegramTizen/src/telegramtizen.c +++ b/TelegramTizen/src/telegramtizen.c @@ -17,6 +17,7 @@ #include "tg_settings_view.h" #include "device_contacts_manager.h" +static Eina_Bool on_load_main_view_requested(void *data); static void free_app_data(appdata_s *app_data, Eina_Bool destroy_server); static int init_service(appdata_s *app); static void popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info) @@ -2321,6 +2322,8 @@ static int on_new_group_added(appdata_s *app, bundle *const rec_msg) { int result = SVC_RES_FAIL; + +#if 0 char* chat_id_str = NULL; result = bundle_get_str(rec_msg, "chat_id", &chat_id_str); @@ -2330,22 +2333,38 @@ static int on_new_group_added(appdata_s *app, bundle *const rec_msg) 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); + hide_loading_popup(app); + refresh_main_list_view(app, EINA_FALSE); } } else { + + hide_loading_popup(app); + if (app->main_item) { + elm_naviframe_item_pop_to(app->main_item); + app->current_app_state = TG_USER_MAIN_VIEW_STATE; + } + 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); + refresh_main_list_view(app, EINA_FALSE); } - 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); - hide_loading_popup(app); +#else + load_registered_user_data(app); + load_buddy_list_data(app); + load_unknown_buddy_list_data(app); + load_peer_data(app); + load_main_list_data(app); + + if (app->main_item) { + elm_naviframe_item_pop_to(app->main_item); + } + ecore_timer_add(1, on_load_main_view_requested, app); +#endif return result; } @@ -2583,7 +2602,11 @@ static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg) result = bundle_get_str(rec_msg, "command", &rec_key_val); - if (strcmp(rec_key_val, "registration_done") == 0) { + if (strcmp(rec_key_val, "server_not_initialized") == 0) { + hide_loading_popup(app); + show_toast(app, "Please check your network connection."); + return result; + } else if (strcmp(rec_key_val, "registration_done") == 0) { char* is_success_val = NULL; result = bundle_get_str(rec_msg, "is_success", &is_success_val); @@ -3015,6 +3038,11 @@ tg_main_list_item_s* get_latest_item(appdata_s *ad, peer_with_pic_s *item) void app_nf_back_cb(void *data, Evas_Object *obj, void *event_info) { appdata_s *ad = data; + if (ad->loading_popup) { + show_toast(ad, "Please wait. request in progress"); + return; + } + switch(ad->current_app_state) { case TG_INIT_SCREEN_STATE: elm_win_lower(ad->win); @@ -3091,10 +3119,12 @@ void app_nf_back_cb(void *data, Evas_Object *obj, void *event_info) elm_naviframe_item_pop(ad->nf); ad->current_app_state = TG_SETTINGS_SCREEN_STATE; break; +#if 0 case TG_ADD_CONTACT_STATE: elm_naviframe_item_pop(ad->nf); ad->current_app_state = TG_SET_USER_INFO_STATE; break; +#endif case TG_SET_CHAT_INFO_STATE: case TG_SET_USER_INFO_STATE: elm_naviframe_item_pop(ad->nf); @@ -3120,7 +3150,7 @@ void app_nf_back_cb(void *data, Evas_Object *obj, void *event_info) elm_exit(); break; case TG_LOGIN_STATE: - send_request_for_restart_server(ad->service_client); + send_request_for_restart_server(ad, ad->service_client); if (ad->timer_value > 0) { Ecore_Timer* timer = evas_object_data_get(ad->nf, "code_timer"); if (timer) @@ -3152,6 +3182,11 @@ void app_nf_back_cb(void *data, Evas_Object *obj, void *event_info) //evas_object_show(ad->panel); //refresh_buddy_list(ad); break; + case TG_ADD_CONTACT_STATE: + elm_naviframe_item_pop(ad->nf); + ad->current_app_state = TG_PEER_SEARCH_VIEW_STATE; + show_floating_button(ad); + break; case TG_BUDDY_LIST_SELECTION_STATE: if (ad->buddy_list) { for (int i = 0 ; i < eina_list_count(ad->buddy_list) ; i++) { @@ -3172,7 +3207,7 @@ void app_nf_back_cb(void *data, Evas_Object *obj, void *event_info) } } elm_naviframe_item_pop(ad->nf); - ad->current_app_state = TG_BUDDY_LIST_STATE; + ad->current_app_state = TG_BUDDY_LIST_SELECTION_STATE; //evas_object_show(ad->panel); //elm_panel_hidden_set(ad->panel, EINA_FALSE); //refresh_buddy_list(ad); @@ -3208,11 +3243,12 @@ void _btn_clicked(void* data, Evas_Object* btn, void* ev) bundle_free(msg); } -static Eina_Bool on_load_main_view_requested(void *data) +Eina_Bool on_load_main_view_requested(void *data) { appdata_s *ad = data; if (ad) { elm_naviframe_item_pop(ad->nf); + hide_loading_popup(ad); launch_user_main_view_cb(ad); int unread_msg_cnt = get_number_of_unread_messages(); int err = badge_set_count(TELEGRAM_APP_ID, unread_msg_cnt); @@ -3368,6 +3404,7 @@ static bool app_create(void *data) ad->panel = NULL; ad->is_server_ready = EINA_FALSE; ad->contact_list = NULL; + ad->main_item = NULL; //ad->msg_count = 0; create_base_gui(ad); int err = badge_new(TELEGRAM_APP_ID); diff --git a/TelegramTizen/src/tg_add_contact.c b/TelegramTizen/src/tg_add_contact.c index 8fda670..f723598 100644 --- a/TelegramTizen/src/tg_add_contact.c +++ b/TelegramTizen/src/tg_add_contact.c @@ -54,7 +54,7 @@ static void on_contact_name_entry_done_clicked(void *data, Evas_Object *obj, voi char* phone_num = get_buddy_phone_num_from_id(ad->peer_in_cahtting_data->use_data->peer_id); - send_add_buddy_request(ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id, first_name, last_name, phone_num); + send_add_buddy_request(ad, ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id, first_name, last_name, phone_num); free(first_name); diff --git a/TelegramTizen/src/tg_chat_info_view.c b/TelegramTizen/src/tg_chat_info_view.c index e09d131..644daf0 100644 --- a/TelegramTizen/src/tg_chat_info_view.c +++ b/TelegramTizen/src/tg_chat_info_view.c @@ -212,7 +212,7 @@ void on_chat_image_select_result_cb(app_control_h request, app_control_h reply, Evas_Object *profile_pic = evas_object_data_get(ad->nf, "user_chat_profile_pic"); if (profile_pic) { elm_image_file_set(profile_pic, file_path, NULL); - send_set_group_chat_profile_pic_request(ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id, file_path); + send_set_group_chat_profile_pic_request(ad, ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id, file_path); } } break; @@ -461,7 +461,7 @@ static void on_entry_pop_up_ok_clicked_cb(void *data, Evas_Object *obj, void *ev if (new_title) { //send request to server. int chat_id = ad->peer_in_cahtting_data->use_data->peer_id; - send_set_group_chat_new_title_request(ad->service_client, chat_id, new_title); + send_set_group_chat_new_title_request(ad, ad->service_client, chat_id, new_title); } } evas_object_del(popup); @@ -553,7 +553,7 @@ void on_chat_info_longpress_clicked_cb(void *data, Evas_Object *obj, void *event if (ad->selected_buddy_item) { user_data_s *sel_user = ad->selected_buddy_item; show_loading_popup(ad); - send_remove_buddy_from_group_chat_request(ad->service_client, ad->selected_buddy_item->user_id.id, ad->peer_in_cahtting_data->use_data->peer_id); + send_remove_buddy_from_group_chat_request(ad, ad->service_client, ad->selected_buddy_item->user_id.id, ad->peer_in_cahtting_data->use_data->peer_id); } } } @@ -619,7 +619,7 @@ void on_chat_info_menu_option_selected_cb(void *data, Evas_Object *obj, void *ev peer_with_pic_s *sel_item = ad->peer_in_cahtting_data; tg_peer_info_s *user_data = sel_item->use_data; show_loading_popup(ad); - send_delete_group_chat_request(ad->service_client, user_data->peer_id); + send_delete_group_chat_request(ad, ad->service_client, user_data->peer_id); } else { } diff --git a/TelegramTizen/src/tg_edit_name_view.c b/TelegramTizen/src/tg_edit_name_view.c index 77075c6..c1e9409 100644 --- a/TelegramTizen/src/tg_edit_name_view.c +++ b/TelegramTizen/src/tg_edit_name_view.c @@ -53,7 +53,7 @@ static void on_name_entry_done_clicked(void *data, Evas_Object *obj, void *event /* FIXME : Write the request for edit name */ - send_update_display_name_request(ad->service_client, ad->current_user_data->user_id.id, first_name, last_name); + send_update_display_name_request(ad, ad->service_client, ad->current_user_data->user_id.id, first_name, last_name); free(first_name); free(last_name); diff --git a/TelegramTizen/src/tg_first_registration.c b/TelegramTizen/src/tg_first_registration.c index 41ff715..4e577b1 100644 --- a/TelegramTizen/src/tg_first_registration.c +++ b/TelegramTizen/src/tg_first_registration.c @@ -48,7 +48,7 @@ static void on_name_entry_done_clicked(void *data, Evas_Object *obj, void *event } char* first_name = trim((char*)tfirst_name); char* last_name = trim((char*)tlast_name); - send_request_for_profile_registration(ad->service_client, first_name, last_name); + send_request_for_profile_registration(ad, ad->service_client, first_name, last_name); show_loading_popup(ad); free(first_name); free(last_name); diff --git a/TelegramTizen/src/tg_login.c b/TelegramTizen/src/tg_login.c index 29d4cc6..06a863a 100644 --- a/TelegramTizen/src/tg_login.c +++ b/TelegramTizen/src/tg_login.c @@ -29,7 +29,7 @@ static void on_naviframe_cancel_clicked(void *data, Evas_Object *obj, void *even if (!ad) return; - send_request_for_restart_server(ad->service_client); + send_request_for_restart_server(ad, ad->service_client); Ecore_Timer* timer = evas_object_data_get(ad->nf, "code_timer"); if (timer) @@ -59,7 +59,7 @@ static void on_code_entry_done_clicked(void *data, Evas_Object *obj, void *event ecore_timer_del(timer); } - send_request_for_validation(ad->service_client, val); + send_request_for_validation(ad, ad->service_client, val); show_loading_popup(ad); } #else @@ -98,7 +98,7 @@ static Eina_Bool on_code_timer_cb(void* data) snprintf(temp_txt, sizeof(temp_txt), i18n_get_text("IDS_TGRAM_BODY_TELEGRAM_WILL_CALL_IN_P1SD_CP2SD"), 0, 0); // send request to get phone call - send_request_for_registration(ad->service_client, ad->phone_number, EINA_FALSE); + send_request_for_registration(ad, ad->service_client, ad->phone_number, EINA_FALSE); return ECORE_CALLBACK_CANCEL; } diff --git a/TelegramTizen/src/tg_main_item_deletion_view.c b/TelegramTizen/src/tg_main_item_deletion_view.c index e846094..effb45c 100644 --- a/TelegramTizen/src/tg_main_item_deletion_view.c +++ b/TelegramTizen/src/tg_main_item_deletion_view.c @@ -272,7 +272,7 @@ void on_delete_selected_items_clicked(void *data, Evas_Object *object, void *eve } if (sel_grp_chat && eina_list_count(sel_grp_chat) > 0) { - send_delete_selected_group_chats_request(ad->service_client, sel_grp_chat); + send_delete_selected_group_chats_request(ad, ad->service_client, sel_grp_chat); } else { refresh_main_list_view(ad, EINA_FALSE); elm_naviframe_item_pop(ad->nf); diff --git a/TelegramTizen/src/tg_registration.c b/TelegramTizen/src/tg_registration.c index bdb3c79..e79e069 100644 --- a/TelegramTizen/src/tg_registration.c +++ b/TelegramTizen/src/tg_registration.c @@ -59,7 +59,7 @@ static void on_naviframe_done_clicked(void *data, Evas_Object *obj, void *event_ strcpy(phone_number, cunt_code); strcat(phone_number, phone_num); ad->phone_number = strdup(phone_number); - send_request_for_registration(ad->service_client, ad->phone_number, EINA_TRUE); + send_request_for_registration(ad, ad->service_client, ad->phone_number, EINA_TRUE); show_loading_popup(ad); } else { diff --git a/TelegramTizen/src/tg_search_message_view.c b/TelegramTizen/src/tg_search_message_view.c index db681ce..81a585c 100644 --- a/TelegramTizen/src/tg_search_message_view.c +++ b/TelegramTizen/src/tg_search_message_view.c @@ -69,7 +69,7 @@ static void on_main_chat_item_selected(void *data, Evas_Object *obj, void *event // 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); + send_update_chat_request(ad, ad->service_client, sel_item->peer_id); return; } } diff --git a/TelegramTizen/src/tg_search_peer_view.c b/TelegramTizen/src/tg_search_peer_view.c index a205e05..df67af0 100755 --- a/TelegramTizen/src/tg_search_peer_view.c +++ b/TelegramTizen/src/tg_search_peer_view.c @@ -443,12 +443,29 @@ static char *_get_name_text_cb(void *data, Evas_Object *obj, const char *part) static Evas_Object *_get_picture_cb(void *data, Evas_Object *obj, const char *part) { - if (0 == strcmp(part, "contents")) { + //if (0 == strcmp(part, "contents")) { + if (!strcmp(part, "elm.swallow.content")) { +#if 0 Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(obj)); evas_object_color_set(rect, 0, 0, 255, 255); evas_object_resize(rect, 720, 440); evas_object_show(rect); return rect; +#else + char edj_path[PATH_MAX] = {0, }; + app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX); + Evas_Object* layout = elm_layout_add(obj); + elm_layout_file_set(layout, edj_path, "add_contact_custom_item"); + evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(layout); + Evas_Object *profile_pic = create_image_object_from_file(ui_utils_get_resource(TG_CALLER_ID_IMAGE), obj); + elm_image_fill_outside_set(profile_pic, EINA_TRUE); + elm_image_aspect_fixed_set(profile_pic, EINA_FALSE); + evas_object_color_set(profile_pic, 45, 165, 224, 255); + elm_object_part_content_set(layout, "swallow.item", profile_pic); + return layout; +#endif } return NULL; } @@ -459,7 +476,7 @@ static void _append_picture_item(Evas_Object *genlist, appdata_s *ad) Elm_Object_Item *item = NULL; itc = elm_genlist_item_class_new(); - itc->item_style = "input.1image"; + itc->item_style = "full"; itc->func.text_get = NULL; itc->func.content_get = _get_picture_cb; itc->func.state_get = NULL; @@ -588,11 +605,25 @@ static Evas_Object* create_genlist(appdata_s *ad, Evas_Object *layout) return list; } +static void on_new_contact_done_clicked(void *data, Evas_Object *obj, void *event_info) +{ + appdata_s* ad = data; +} + +static void on_new_contact_cancel_clicked(void *data, Evas_Object *obj, void *event_info) +{ + appdata_s* ad = data; + elm_naviframe_item_pop(ad->nf); + ad->current_app_state = TG_PEER_SEARCH_VIEW_STATE; + show_floating_button(ad); +} + int on_create_new_contact(appdata_s* ad) { if (!ad) return 0; + delete_floating_button(ad); ad->current_app_state = TG_ADD_CONTACT_STATE; char edj_path[PATH_MAX] = {0, }; @@ -617,12 +648,12 @@ int on_create_new_contact(appdata_s* ad) Evas_Object *done_btn = elm_button_add(ad->nf); elm_object_style_set(done_btn, "naviframe/title_right"); elm_object_text_set(done_btn, i18n_get_text("IDS_TGRAM_ACBUTTON_DONE_ABB")); - //evas_object_smart_callback_add(done_btn, "clicked", on_name_entry_done_clicked, ad); + evas_object_smart_callback_add(done_btn, "clicked", on_new_contact_done_clicked, ad); Evas_Object *cancel_btn = elm_button_add(ad->nf); elm_object_style_set(cancel_btn, "naviframe/title_left"); elm_object_text_set(cancel_btn, i18n_get_text("IDS_TGRAM_ACBUTTON_CANCEL_ABB")); - //evas_object_smart_callback_add(cancel_btn, "clicked", on_naviframe_cancel_clicked, ad); + evas_object_smart_callback_add(cancel_btn, "clicked", on_new_contact_cancel_clicked, ad); elm_object_item_part_content_set(navi_item, "title_right_btn", done_btn); elm_object_item_part_content_set(navi_item, "title_left_btn", cancel_btn); diff --git a/TelegramTizen/src/tg_select_buddy_from_list.c b/TelegramTizen/src/tg_select_buddy_from_list.c index 263a9ee..5dbeb3d 100644 --- a/TelegramTizen/src/tg_select_buddy_from_list.c +++ b/TelegramTizen/src/tg_select_buddy_from_list.c @@ -90,14 +90,14 @@ Evas_Object* on_buddy_select_list_image_requested(void *data, Evas_Object *obj, char edj_path[PATH_MAX] = {0, }; app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX); Evas_Object* user_pic_layout = elm_layout_add(ad->nf); - elm_layout_file_set(user_pic_layout, edj_path, "circle_layout"); + elm_layout_file_set(user_pic_layout, edj_path, "search_circle_layout"); evas_object_size_hint_weight_set(user_pic_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(user_pic_layout); elm_object_part_content_set(user_pic_layout, "content", profile_pic); eo = elm_layout_add(obj); - elm_layout_theme_set(eo, "layout", "list/C/type.3", "default"); + elm_layout_theme_set(eo, "layout", "list/B/type.2", "default"); elm_layout_content_set(eo, "elm.swallow.content", user_pic_layout); } return eo; @@ -118,7 +118,7 @@ static void on_buddy_add_to_chat_ok_selected(void *data, Evas_Object *obj, void if (ad->peer_in_cahtting_data && ad->peer_in_cahtting_data->use_data) { show_loading_popup(ad); - send_add_buddy_to_group_chat_request(ad->service_client, ad->selected_buddy_item->user_id.id, ad->peer_in_cahtting_data->use_data->peer_id); + send_add_buddy_to_group_chat_request(ad, ad->service_client, ad->selected_buddy_item->user_id.id, ad->peer_in_cahtting_data->use_data->peer_id); elm_naviframe_item_pop(ad->nf); ad->current_app_state = TG_SET_CHAT_INFO_STATE; } diff --git a/TelegramTizen/src/tg_set_username_view.c b/TelegramTizen/src/tg_set_username_view.c index 018e98b..6050cb6 100644 --- a/TelegramTizen/src/tg_set_username_view.c +++ b/TelegramTizen/src/tg_set_username_view.c @@ -41,7 +41,7 @@ static void on_naviframe_username_done_clicked(void *data, Evas_Object *obj, voi if (strlen(user_name) < MIN_USERNAME_LENGTH) { show_toast(ad, "Username should not be less than 5 characters"); } else { - send_set_username_request(ad->service_client, ad->current_user_data->user_id.id, user_name); + send_set_username_request(ad, ad->service_client, ad->current_user_data->user_id.id, user_name); show_loading_popup(ad); } free(user_name); diff --git a/TelegramTizen/src/tg_settings_view.c b/TelegramTizen/src/tg_settings_view.c index 3e88717..7aed67e 100644 --- a/TelegramTizen/src/tg_settings_view.c +++ b/TelegramTizen/src/tg_settings_view.c @@ -262,7 +262,7 @@ void on_image_select_result_cb(app_control_h request, app_control_h reply, app_c appdata_s *ad = (appdata_s*)user_data; if (ad) { show_loading_popup(ad); - send_set_profile_pic_request(ad->service_client, ad->current_user_data->user_id.id, file_path); + send_set_profile_pic_request(ad, ad->service_client, ad->current_user_data->user_id.id, file_path); } break; } @@ -288,7 +288,7 @@ void on_image_request_option_selected_cb(void *data, Evas_Object *obj, void *eve return; } - if (id == 1) { + if (id == 1) { app_control_set_operation(app_control, APP_CONTROL_OPERATION_CREATE_CONTENT); app_control_set_mime(app_control, "image/jpg"); app_control_send_launch_request(app_control, &on_image_select_result_cb, ad); @@ -682,17 +682,40 @@ char* _text_requested_cb(void *data, Evas_Object *obj, const char *part) appdata_s* ad = evas_object_data_get(obj, "app_data"); char *user_name = NULL; + char *first_name = NULL; + char *last_name = NULL; if (!strcmp(part,"elm.text.main.left.top") || !strcmp(part,"elm.text")){ switch(id) { case 0: //return replace(ad->current_user_data->print_name, '_', " "); - +#if 0 user_name = (char*)malloc(strlen(ad->current_user_data->first_name) + strlen(" ") + strlen(ad->current_user_data->last_name) + 1); strcpy(user_name, ad->current_user_data->first_name); strcat(user_name, " "); strcat(user_name, ad->current_user_data->last_name); return user_name; +#else + first_name = ad->current_user_data->first_name; + last_name = ad->current_user_data->last_name; + + + if (!first_name || strstr(first_name ,"null") != 0) { + first_name = NULL; + } + if (!first_name && !last_name) { + first_name = ""; + } + + 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); + return user_name; +#endif case 1: return strdup(i18n_get_text("IDS_TGRAM_OPT_SET_BACKGROUND_IMAGE_ABB")); default: @@ -767,7 +790,7 @@ static void _logout_btn_clicked_cb(void *data, Evas_Object *obj, void *event_inf if (popup) { evas_object_del(popup); } - send_request_for_logout(ad->service_client); + send_request_for_logout(ad, ad->service_client); show_loading_popup(ad); } diff --git a/TelegramTizen/src/tg_user_info_view.c b/TelegramTizen/src/tg_user_info_view.c index 100b6c3..95907c6 100644 --- a/TelegramTizen/src/tg_user_info_view.c +++ b/TelegramTizen/src/tg_user_info_view.c @@ -176,9 +176,9 @@ static void on_user_block_ok_selected(void *data, Evas_Object *obj, void *event_ show_loading_popup(ad); peer_with_pic_s *sel_item = ad->peer_in_cahtting_data; if (get_buddy_block_status(sel_item->use_data->peer_id) == 1) { - send_unblock_buddy_request(ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id); + send_unblock_buddy_request(ad, ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id); } else { - send_block_buddy_request(ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id); + send_block_buddy_request(ad, ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id); } } @@ -237,7 +237,7 @@ static void on_user_delete_ok_selected(void *data, Evas_Object *obj, void *event //send_add_buddy_request(ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id); } else { show_loading_popup(ad); - send_delete_buddy_request(ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id); + send_delete_buddy_request(ad, ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id); } } diff --git a/TelegramTizen/src/tg_user_main_view.c b/TelegramTizen/src/tg_user_main_view.c index 05680ca..e5f53f6 100644 --- a/TelegramTizen/src/tg_user_main_view.c +++ b/TelegramTizen/src/tg_user_main_view.c @@ -443,7 +443,7 @@ void on_chat_long_press_option_selected_cb(void *data, Evas_Object *obj, void *e //send group chat delete request show_loading_popup(ad); - send_delete_group_chat_request(ad->service_client, sel_item->peer_id); + send_delete_group_chat_request(ad, ad->service_client, sel_item->peer_id); } else { @@ -539,7 +539,7 @@ void on_main_chat_item_selected(void *data, Evas_Object *obj, void *event_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); + send_update_chat_request(ad, ad->service_client, sel_item->peer_id); return; } } @@ -1227,8 +1227,8 @@ void launch_user_main_view_cb(appdata_s* ad) ad->is_tg_initilized = EINA_TRUE; char edj_path[PATH_MAX] = {0, }; app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX); - send_request_for_server_connection_status(ad->service_client); - send_request_for_delete_notifications(ad->service_client); + send_request_for_server_connection_status(ad, ad->service_client); + send_request_for_delete_notifications(ad, ad->service_client); Evas_Object* scroller = elm_scroller_add(ad->nf); elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE); @@ -1326,7 +1326,7 @@ void launch_user_main_view_cb(appdata_s* ad) evas_object_smart_callback_add(search_btn, "unpressed", on_search_icon_unpressed, search_icon); #endif - elm_naviframe_item_push(ad->nf, i18n_get_text("IDS_TGRAM_HEADER_TELEGRAM"), NULL, NULL, scroller, NULL); + ad->main_item = elm_naviframe_item_push(ad->nf, i18n_get_text("IDS_TGRAM_HEADER_TELEGRAM"), NULL, NULL, scroller, NULL); #if 0 Elm_Object_Item* navi_item = elm_naviframe_item_push(ad->nf, "Telegram", NULL, NULL, scroller, NULL); diff --git a/TelegramTizen/tg_utils/tg_common.h b/TelegramTizen/tg_utils/tg_common.h index a3c013c..e3d6f36 100644 --- a/TelegramTizen/tg_utils/tg_common.h +++ b/TelegramTizen/tg_utils/tg_common.h @@ -581,6 +581,7 @@ typedef struct appdata { Evas_Object *menu_popup; //int msg_count; Eina_List *contact_list; + Elm_Naviframe_Item *main_item; } appdata_s; extern void show_toast(appdata_s* ad, char* value); diff --git a/tg-engine-service/inc/server_response.h b/tg-engine-service/inc/server_response.h index a6c84df..cbcc506 100644 --- a/tg-engine-service/inc/server_response.h +++ b/tg-engine-service/inc/server_response.h @@ -20,6 +20,7 @@ extern void process_delete_selected_group_chats_request(tg_engine_data_s* tg_dat extern void process_add_user_request(tg_engine_data_s* tg_data, int buddy_id, char *first_name, char *last_name, char *phone_num); 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_send_secret_chat_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); extern void process_send_media_command(int buddy_id, int message_id, int media_id, int msg_type, char* file_path, int type_of_chat); @@ -35,6 +36,7 @@ extern void process_set_username_command(tg_engine_data_s *tg_data, int buddy_id extern void process_update_display_name_command(tg_engine_data_s *tg_data, int buddy_id, const char *first_name, const char *last_name); extern void send_add_contacts_request(tg_engine_data_s *tg_data); +extern void send_server_not_initialized_response(tg_engine_data_s *tg_data); extern void send_registration_response(tg_engine_data_s *tg_data, Eina_Bool is_success); extern void send_request_code_again(tg_engine_data_s *tg_data); extern void send_request_phone_num_again(tg_engine_data_s *tg_data); diff --git a/tg-engine-service/src/server_response.c b/tg-engine-service/src/server_response.c index d6fefff..cfae8da 100644 --- a/tg-engine-service/src/server_response.c +++ b/tg-engine-service/src/server_response.c @@ -105,6 +105,13 @@ void process_update_chat_request(tg_engine_data_s* tg_data, int chat_id) do_update_chat_info(chat_id); } +void process_send_secret_chat_request(tg_engine_data_s* tg_data, int buddy_id) +{ + if (!tgl_engine_get_TLS()) { + return; + } + request_for_secret_chat(buddy_id); +} void process_delete_user_request(tg_engine_data_s* tg_data, int buddy_id) { @@ -514,6 +521,27 @@ void send_add_contacts_request(tg_engine_data_s *tg_data) bundle_free(msg); } +void send_server_not_initialized_response(tg_engine_data_s *tg_data) +{ + 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", "server_not_initialized") != 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_contacts_and_chats_load_done_response(tg_engine_data_s *tg_data, Eina_Bool is_success) { bundle *msg = bundle_create(); diff --git a/tg-engine-service/src/tg-engine-service.c b/tg-engine-service/src/tg-engine-service.c index 9e7bef3..a39cc5e 100644 --- a/tg-engine-service/src/tg-engine-service.c +++ b/tg-engine-service/src/tg-engine-service.c @@ -39,8 +39,45 @@ static int _on_tg_server_msg_received_cb(void *data, bundle *const rec_msg) } process_registration_command(tg_data, ph_no_key_val, th_sms); + return result; - } else if (strcmp(cmd_key_val, "logout_telegram") == 0) { + } + + if (strcmp(cmd_key_val, "code_validation") == 0) { + + char* sms_code_val = NULL; + res = bundle_get_str(rec_msg, "sms_code", &sms_code_val); + process_validation_command(tg_data, sms_code_val); + return result; + } + + if (strcmp(cmd_key_val, "profile_registration") == 0) { + + char* first_name = NULL; + char* last_name = NULL; + + res = bundle_get_str(rec_msg, "first_name", &first_name); + if (res == BUNDLE_ERROR_NONE && first_name) { + tg_data->first_name = strdup(first_name); + } + + res = bundle_get_str(rec_msg, "last_name", &last_name); + if (res == BUNDLE_ERROR_NONE && last_name) { + tg_data->last_name = strdup(last_name); + } + + if (tg_data->tg_state == TG_ENGINE_STATE_PROFILE_FIRST_NAME_REGISTRATION && tg_data->get_string) { + tg_data->get_string(tgl_engine_get_TLS(), tg_data->first_name, tg_data->callback_arg); + } + return result; + } + + if (!tg_data->is_login_activated) { + send_server_not_initialized_response(tg_data); + return result; + } + + if (strcmp(cmd_key_val, "logout_telegram") == 0) { //process_logout_command(tg_data); @@ -122,12 +159,6 @@ static int _on_tg_server_msg_received_cb(void *data, bundle *const rec_msg) } else if (strcmp(cmd_key_val, "restart_server") == 0) { on_restart_service_requested(tg_data); - } else if (strcmp(cmd_key_val, "code_validation") == 0) { - - char* sms_code_val = NULL; - res = bundle_get_str(rec_msg, "sms_code", &sms_code_val); - process_validation_command(tg_data, sms_code_val); - } else if (strcmp(cmd_key_val, "message_transport") == 0) { char* buddy_id_str = NULL; @@ -220,6 +251,15 @@ static int _on_tg_server_msg_received_cb(void *data, bundle *const rec_msg) process_update_chat_request(tg_data, chat_id); + } else if (strcmp(cmd_key_val, "start_secret_chat") == 0) { + + char* buddy_id_str = NULL; + res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str); + int buddy_id = atoi(buddy_id_str); + + process_send_secret_chat_request(tg_data, buddy_id); + + } else if (strcmp(cmd_key_val, "delete_buddy") == 0) { char* buddy_id_str = NULL; @@ -282,24 +322,6 @@ static int _on_tg_server_msg_received_cb(void *data, bundle *const rec_msg) process_send_media_command(buddy_id, message_id, media_id, msg_type, file_path_str, type_of_chat); - } else if (strcmp(cmd_key_val, "profile_registration") == 0) { - - char* first_name = NULL; - char* last_name = NULL; - - res = bundle_get_str(rec_msg, "first_name", &first_name); - if (res == BUNDLE_ERROR_NONE && first_name) { - tg_data->first_name = strdup(first_name); - } - - res = bundle_get_str(rec_msg, "last_name", &last_name); - if (res == BUNDLE_ERROR_NONE && last_name) { - tg_data->last_name = strdup(last_name); - } - - if (tg_data->tg_state == TG_ENGINE_STATE_PROFILE_FIRST_NAME_REGISTRATION && tg_data->get_string) { - tg_data->get_string(tgl_engine_get_TLS(), tg_data->first_name, tg_data->callback_arg); - } } else if (strcmp(cmd_key_val, "device_contact_list") == 0) { char* count_str = NULL; diff --git a/tg-engine-service/tg_engine/tg_engine.c b/tg-engine-service/tg_engine/tg_engine.c index e29c79e..9ab5198 100644 --- a/tg-engine-service/tg_engine/tg_engine.c +++ b/tg-engine-service/tg_engine/tg_engine.c @@ -1213,10 +1213,49 @@ void on_requested_update_chat_received(struct tgl_state *TLS, void *callback_ext 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->flags == 144) { + return; + } + int msg_count = get_number_of_messages(msg_table); + if (msg_count <= 0) { + if (chat_info->admin_id > 0) { + set_date_item_to_table(msg_table, chat_info->date); + tgl_peer_id_t admin_id; + admin_id.id = chat_info->admin_id; + admin_id.type = TGL_PEER_USER; + + tgl_peer_t* UC = tgl_peer_get(TLS, admin_id); + int msg_len = strlen(UC->user.first_name) + strlen(" created the group") + 1; + char* creator_name = (char*)malloc(msg_len); + strcpy(creator_name, UC->user.first_name); + strcat(creator_name, " created the group"); + struct tgl_message msg; + int cur_time = chat_info->date; + msg.to_id = chat_info->id; + msg.from_id = admin_id; + msg.id = cur_time; + msg.message = creator_name; + msg.message_len = msg_len; + msg.unread = 0; + msg.date = cur_time; + msg.media.type = tgl_message_media_none; + msg.service = 1; + msg.out = 0; + + insert_buddy_msg_to_db(&msg); + free(creator_name); + //send_message_received_response(TLS->callback_data, msg.from_id.id, msg.to_id.id, msg.id, tgl_get_peer_type(msg.to_id)); + } + + } + + free(msg_table); + if (!chat_info->user_list) { tgl_do_get_chat_info(TLS, chat_info->id, 0, &on_chat_info_received, NULL); return; @@ -1875,6 +1914,28 @@ static Eina_Bool on_load_buddy_history_requested(void *data) return ECORE_CALLBACK_CANCEL; } +static Eina_Bool send_login_activated_response(void *data) +{ + struct tgl_state *TLS = data; + if (TLS) { + tg_engine_data_s *tg_data = TLS->callback_data; + send_response_for_server_connection_status(tg_data, tg_data->is_login_activated); + } + return ECORE_CALLBACK_CANCEL; +} + + +static Eina_Bool send_chat_loading_is_done_response(void *data) +{ + struct tgl_state *TLS = data; + if (TLS) { + send_contacts_and_chats_load_done_response(TLS->callback_data, EINA_TRUE); + ecore_timer_add(3, send_login_activated_response, TLS); + } + return ECORE_CALLBACK_CANCEL; +} + + void on_contacts_received(struct tgl_state *TLS, void *callback_extra, int success, int size, struct tgl_user *contacts[]) { tg_engine_data_s *tg_data = TLS->callback_data; @@ -1898,15 +1959,15 @@ void on_contacts_received(struct tgl_state *TLS, void *callback_extra, int succe // inform client that contact loading is done. //send_contacts_load_done_response(EINA_TRUE); - send_contacts_and_chats_load_done_response(TLS->callback_data, EINA_TRUE); for (int i = size - 1; i >= 0; i--) { struct tgl_user *buddy = contacts[i]; tgl_do_get_user_info(TLS, buddy->id, 0, on_buddy_info_loaded, NULL); } - send_response_for_server_connection_status(tg_data, tg_data->is_login_activated); + ecore_timer_add(3, on_send_unsent_messages_requested, TLS); ecore_timer_add(6, on_load_buddy_history_requested, TLS); + ecore_timer_add(12, send_chat_loading_is_done_response, TLS); } @@ -2511,7 +2572,6 @@ void update_user_display_name(tg_engine_data_s *tg_data, int buddy_id, const cha } } - void create_new_group(tg_engine_data_s *tg_data, Eina_List* buddy_ids, const char *group_name, const char *group_icon) { if (!buddy_ids || ! group_name) { @@ -2879,6 +2939,25 @@ void logout_telegram(tg_engine_data_s *tg_data) } +void on_secret_chat_request_sent(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_secret_chat *E) +{ + int buddy_id = (int)callback_extra; + tg_engine_data_s *tg_data = TLS->callback_data; + if (success) { + + } else { + + } +} + +void request_for_secret_chat(int buddy_id) +{ + tgl_peer_id_t peer_id; + peer_id.id = buddy_id; + peer_id.type = TGL_PEER_USER; + tgl_do_create_secret_chat(s_info.TLS, peer_id, on_secret_chat_request_sent, (void*)(buddy_id)); +} + void do_delete_buddy(int buddy_id) { tgl_peer_id_t peer_id; diff --git a/tg-engine-service/tg_engine/tg_engine.h b/tg-engine-service/tg_engine/tg_engine.h index edeb4e7..dec0737 100644 --- a/tg-engine-service/tg_engine/tg_engine.h +++ b/tg-engine-service/tg_engine/tg_engine.h @@ -177,6 +177,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 delete_selected_group_chat(tg_engine_data_s *tg_data, Eina_List *sel_grp_chats); extern void do_delete_buddy(int buddy_id); +extern void request_for_secret_chat(int buddy_id); extern void do_add_buddy(int buddy_id, char *first_name, char *last_name, char *phone_num); extern void do_update_chat_info(int chat_id); extern void do_unblock_buddy(int buddy_id); -- 2.7.4