Apply latest changes 64/50264/1
authorpolu.sandeep <polu.sandeep@samsung.com>
Tue, 27 Oct 2015 09:48:59 +0000 (18:48 +0900)
committerpolu.sandeep <polu.sandeep@samsung.com>
Tue, 27 Oct 2015 09:48:59 +0000 (18:48 +0900)
Change-Id: Icbf46c6cfdf4a7660f96709f25b818a3a0a42a96

16 files changed:
TelegramTizen/inc/server_requests.h
TelegramTizen/inc/tg_settings_view.h
TelegramTizen/src/server_requests.c
TelegramTizen/src/telegramtizen.c
TelegramTizen/src/tg_edit_name_view.c
TelegramTizen/src/tg_settings_view.c
TelegramTizen/src/tg_user_main_view.c
TelegramTizen/tg_utils/tg_common.c
TelegramTizen/tg_utils/tg_common.h
tg-engine-service/inc/server_response.h
tg-engine-service/inc/tg_db_wrapper.h
tg-engine-service/src/server_response.c
tg-engine-service/src/tg-engine-service.c
tg-engine-service/src/tg_db_wrapper.c
tg-engine-service/tg_engine/tg_engine.c
tg-engine-service/tg_engine/tg_engine.h

index 37f2142..2ac52d5 100644 (file)
@@ -35,5 +35,6 @@ void send_remove_buddy_from_group_chat_request(service_client* service_client, i
 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);
 
 #endif /* SERVER_REQUESTS_H_ */
index dab52b1..48b588f 100644 (file)
@@ -13,5 +13,6 @@
 
 extern void launch_settings_screen(appdata_s* ad);
 
+extern void refresh_settings_screen(appdata_s* ad);
 
 #endif /* TG_SETTINGS_VIEW_H_ */
index 0782d0a..d391dc8 100644 (file)
@@ -1114,6 +1114,59 @@ void send_set_profile_pic_request(service_client* service_client, int user_id, c
        bundle_free(msg);
 }
 
+void send_update_display_name_request(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
+               return;
+       }
+
+       msg = bundle_create();
+       if (!msg) {
+               return;
+       }
+
+       if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0)     {
+               ERR("Failed to add data by key to bundle");
+               bundle_free(msg);
+               return;
+       }
+
+       if (bundle_add_str(msg, "command", "update_display_name_request") != 0) {
+               ERR("Failed to add data by key to bundle");
+               bundle_free(msg);
+               return;
+       }
+
+       snprintf(tmp, sizeof(tmp) - 1, "%d", user_id);
+
+       if (bundle_add_str(msg, "buddy_id", tmp) != 0)  {
+               ERR("Failed to add data by key to bundle");
+               bundle_free(msg);
+       }
+
+       if (bundle_add_str(msg, "first_name", first_name) != 0) {
+               ERR("Failed to add data by key to bundle");
+               bundle_free(msg);
+       }
+
+       if (bundle_add_str(msg, "last_name", last_name) != 0)   {
+               ERR("Failed to add data by key to bundle");
+               bundle_free(msg);
+       }
+
+       result = service_client_send_message(service_client, msg);
+       if(result != SVC_RES_OK) {
+               // error
+       }
+       bundle_free(msg);
+}
+
+
 void send_set_username_request(service_client* service_client, int user_id, const char* username)
 {
        bundle *msg;
index a2d5c8c..77b5d02 100644 (file)
@@ -14,6 +14,7 @@
 #include "ucol.h"
 #include <notification.h>
 #include <badge.h>
+#include "tg_settings_view.h"
 
 static void popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
 {
@@ -389,15 +390,17 @@ void load_main_list_data(appdata_s *ad)
                                                                tgl_media_s *media_msg = NULL;
                                                                media_msg = get_media_details_from_db(atoll(msg->media_id));
 
-/*                                                             if (msg->message && strlen(msg->message) > 0) {
-                                                                       item->last_message = strdup(msg->message);
+                                                               if (media_msg && media_msg->doc_type) {
+                                                                       item->last_message = strdup(media_msg->doc_type);
+                                                                       free_media_details(media_msg);
                                                                } else {
-                                                                       item->last_message = strdup("Document");
-                                                               }*/
-
-                                                               item->last_message = strdup(media_msg->doc_type);
+                                                                       if (msg->message && strlen(msg->message) > 0) {
+                                                                               item->last_message = strdup(msg->message);
+                                                                       } else {
+                                                                               item->last_message = strdup("Document");
+                                                                       }
+                                                               }
 
-                                                               free_media_details(media_msg);
                                                        } else if(media_type == tgl_message_media_geo) {
                                                                item->last_message = strdup("Geo location");
                                                        } else if(media_type == tgl_message_media_contact) {
@@ -2014,6 +2017,63 @@ static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg)
                                }
                        }
                }
+       } else if (strcmp(rec_key_val, "self_profile_name_updated") == 0) {
+
+               Eina_Bool is_success = EINA_FALSE;
+               char *is_success_val = NULL;
+               result = bundle_get_str(rec_msg, "is_success", &is_success_val);
+               if (strncmp("true", is_success_val, strlen("true")) == 0) {
+                       is_success = EINA_TRUE;
+                       show_toast(app, "Username updated successfully.");
+               } else {
+                       is_success = EINA_FALSE;
+                       show_toast(app, "Username not updated. Username already exist or please check your network connection.");
+               }
+
+               if (is_success) {
+
+                       char *first_name = NULL;
+                       result = bundle_get_str(rec_msg, "first_name", &first_name);
+                       if (!first_name) {
+                               first_name = "";
+                       }
+
+                       char *last_name = NULL;
+                       result = bundle_get_str(rec_msg, "last_name", &last_name);
+                       if (!last_name) {
+                               last_name = "";
+                       }
+
+                       if (app->current_user_data->first_name) {
+                               free(app->current_user_data->first_name);
+                               app->current_user_data->first_name = NULL;
+                       }
+
+                       if (app->current_user_data->last_name) {
+                               free(app->current_user_data->last_name);
+                               app->current_user_data->last_name = NULL;
+                       }
+
+                       if (first_name) {
+                               app->current_user_data->first_name = strdup(first_name);
+                       }
+
+                       if (last_name) {
+                               app->current_user_data->last_name = strdup(last_name);
+                       }
+
+                       if (app->current_app_state == TG_SETTINGS_EDIT_NAME_STATE) {
+                               appdata_s* ad = data;
+                               elm_naviframe_item_pop(ad->nf);
+                               ad->current_app_state = TG_SETTINGS_SCREEN_STATE;
+                               refresh_settings_screen(ad);
+                       }
+
+               } else {
+
+               }
+               hide_loading_popup(app);
+
        } else if (strcmp(rec_key_val, "self_username_updated") == 0) {
 
                Eina_Bool is_success = EINA_FALSE;
@@ -2740,6 +2800,11 @@ void app_nf_back_cb(void *data, Evas_Object *obj, void *event_info)
                        //evas_object_show(ad->panel);
                        //elm_panel_hidden_set(ad->panel, EINA_FALSE);
                        break;
+               case TG_SETTINGS_EDIT_NAME_STATE:
+                       elm_naviframe_item_pop(ad->nf);
+                       ad->current_app_state = TG_SETTINGS_SCREEN_STATE;
+                       delete_floating_button(ad);
+                       break;
                case TG_REGISTRATION_STATE:
                        elm_win_lower(ad->win);
                        elm_exit();
index 479fd1a..77075c6 100644 (file)
@@ -7,7 +7,7 @@
 
 
 #include "tg_edit_name_view.h"
-
+#include "server_requests.h"
 
 
 static void on_first_name_change_enable_ok_button(void *data, Evas_Object *obj, void *event_info)
@@ -29,8 +29,9 @@ static void on_first_name_change_enable_ok_button(void *data, Evas_Object *obj,
 static void on_naviframe_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_SETTINGS_SCREEN_STATE;
+       delete_floating_button(ad);
 }
 
 static void on_name_entry_done_clicked(void *data, Evas_Object *obj, void *event_info)
@@ -52,8 +53,11 @@ 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);
+
        free(first_name);
        free(last_name);
+       show_loading_popup(ad);
 }
 
 void launch_editname_screen(appdata_s* ad)
@@ -63,7 +67,7 @@ void launch_editname_screen(appdata_s* ad)
                return;
        }
 
-       //ad->current_app_state = TG_SETTINGS_SCREEN_STATE;
+       ad->current_app_state = TG_SETTINGS_EDIT_NAME_STATE;
 
        char edj_path[PATH_MAX] = {0, };
        app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
index 7065aaa..1a53de4 100644 (file)
@@ -681,11 +681,18 @@ char* _text_requested_cb(void *data, Evas_Object *obj, const char *part)
        int id = (int) data;
 
        appdata_s* ad = evas_object_data_get(obj, "app_data");
-
+       char *user_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, '_', " ");
+                               //return replace(ad->current_user_data->print_name, '_', " ");
+
+                               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;
+
                        case 1:
                                return strdup(i18n_get_text("IDS_TGRAM_OPT_SET_BACKGROUND_IMAGE_ABB"));
                        default:
@@ -940,6 +947,16 @@ static Eina_Bool _pop_cb(void *data, Elm_Object_Item *it)
        return EINA_TRUE;
 }
 
+void refresh_settings_screen(appdata_s* ad)
+{
+       if (!ad)
+               return;
+       Evas_Object *list = evas_object_data_get(ad->nf, "settings_list");
+       if (list) {
+               elm_genlist_realized_items_update(list);
+       }
+}
+
 void launch_settings_screen(appdata_s* ad)
 {
        if (!ad) {
@@ -962,6 +979,8 @@ void launch_settings_screen(appdata_s* ad)
 
        evas_object_data_set(list, "app_data", ad);
 
+       evas_object_data_set(ad->nf, "settings_list", list);
+
        itc.item_style = "type1";
        itc.func.text_get = _text_requested_cb;
        itc.func.content_get = _content_requested_cb;
index d07a50c..05680ca 100644 (file)
@@ -346,7 +346,7 @@ void on_chat_long_press_option_selected_cb(void *data, Evas_Object *obj, void *e
                        free(tablename);
 
                        //change item in list
-                       sel_item->last_message = strdup(" ");
+                       sel_item->last_message = strdup("");
                        sel_item->last_msg_id = -1;
                        sel_item->last_msg_type = -1;
                        sel_item->is_out_msg = -1;
@@ -383,6 +383,7 @@ void on_chat_long_press_option_selected_cb(void *data, Evas_Object *obj, void *e
                                        elm_object_text_set(sel_item->date_lbl,time_str);
                                }
                        }
+#if 0
                        if (sel_item->msg_status_lbl) {
                                Evas_Object* temp_lbl = elm_object_part_content_get(sel_item->msg_status_lbl, "swallow.status");
                                if (temp_lbl) {
@@ -396,6 +397,11 @@ void on_chat_long_press_option_selected_cb(void *data, Evas_Object *obj, void *e
                                evas_object_show(num_lbl);
                                elm_object_part_content_set(sel_item->msg_status_lbl, "swallow.status", num_lbl);
                        }
+#endif
+                       Evas_Object *buddy_list = evas_object_data_get(ad->nf, "buddy_list");
+                       if (buddy_list) {
+                               elm_genlist_realized_items_update(buddy_list);
+                       }
 
                } else {
 
@@ -653,7 +659,7 @@ Evas_Object* on_chat_item_load_requested(void *data, Evas_Object *obj, const cha
                evas_object_show(layout);
                Evas_Object* item_layout = elm_layout_add(ad->nf);
                if (ad->target_direction == TELEGRAM_TARGET_DIRECTION_LANDSCAPE_INVERSE || ad->target_direction == TELEGRAM_TARGET_DIRECTION_LANDSCAPE) {
-                       if ((item->last_message == NULL) || (strlen(item->last_message) <= 0) || (strcmp(item->last_message, " ") == 0) || (item->number_of_unread_msgs == 0 &&(!item->is_out_msg || !item->last_msg_service))) {
+                       if ((item->last_message == NULL) || (strlen(item->last_message) <= 0) || (strcmp(item->last_message, " ") == 0)) {
                                elm_layout_file_set(item_layout, edj_path, "main_list_custom_no_msg_item_land");
                                is_empty_msg = EINA_TRUE;
                        } else {
@@ -664,7 +670,7 @@ Evas_Object* on_chat_item_load_requested(void *data, Evas_Object *obj, const cha
                                }
                        }
                } else {
-                       if ((item->last_message == NULL) || (strlen(item->last_message) <= 0) || (strcmp(item->last_message, " ") == 0) || (item->number_of_unread_msgs == 0 &&(!item->is_out_msg || !item->last_msg_service))) {
+                       if ((item->last_message == NULL) || (strlen(item->last_message) <= 0) || (strcmp(item->last_message, " ") == 0)) {
                                elm_layout_file_set(item_layout, edj_path, "main_list_custom_no_msg_item");
                                is_empty_msg = EINA_TRUE;
                        } else {
@@ -734,7 +740,7 @@ Evas_Object* on_chat_item_load_requested(void *data, Evas_Object *obj, const cha
                /*************************** user name ***************************************/
 
 #if 0
-               char* user_name = replace(item->peer_print_name, '_', "");
+               char* user_name = replace(item->peer_print_name, '_', " ");
 #endif
                char buf[512] = {'\0'};
                snprintf(buf, 512, "<font=Tizen:style=Bold color=#000000 align=left><font_size=35>%s</font_size></font>", item->buddy_display_name);
@@ -1125,7 +1131,7 @@ static void ctxpopup_search_select_cb(void *data, Evas_Object *obj, void *event_
                LOGE("ad is NULL");
                return;
        }
-
+       delete_floating_button(ad);
        _ctxpopup_dismiss_cb(ad, NULL, NULL);
 
        /* please input here when search menu is clicked */
index 55508d0..68302ae 100644 (file)
@@ -465,7 +465,8 @@ void create_floating_button(appdata_s* ad)
                return;
 
     Evas_Object *icon = elm_image_add(ad->nf);
-    elm_image_file_set(icon, ui_utils_get_resource(TG_ICON_FLOATING_PENCIL), NULL);
+
+   // elm_image_file_set(icon, ui_utils_get_resource(TG_ICON_FLOATING_PENCIL), NULL);
     evas_object_show(icon);
        ad->floating_btn = eext_floatingbutton_add(ad->layout);
        evas_object_color_set(ad->floating_btn, 255, 255, 255, 255);
@@ -478,6 +479,7 @@ void create_floating_button(appdata_s* ad)
        elm_object_part_content_set(btn, "icon", icon);
 
        evas_object_data_set(ad->floating_btn, "image", icon);
+       update_floating_button(ad, ad->current_app_state);
 }
 
 void delete_floating_button(appdata_s* ad)
@@ -486,7 +488,9 @@ void delete_floating_button(appdata_s* ad)
                return;
 
        if (ad->floating_btn){
-               elm_layout_signal_emit(ad->floating_btn, "elm,state,floatingbutton,hidden", "elm");
+               //elm_layout_signal_emit(ad->floating_btn, "elm,state,floatingbutton,hidden", "elm");
+               evas_object_del(ad->floating_btn);
+               ad->floating_btn = NULL;
        }
 }
 
@@ -494,11 +498,16 @@ void show_floating_button(appdata_s* ad)
 {
        if (!ad)
                return;
-
+#if 0
        if (ad->floating_btn){
                update_floating_button(ad, ad->current_app_state);
                elm_layout_signal_emit(ad->floating_btn, "elm,state,floatingbutton,visible", "elm");
        }
+#else
+       delete_floating_button(ad);
+       create_floating_button(ad);
+#endif
+
 }
 
 void update_floating_button(appdata_s* ad, int mode)
index 484cb24..bb0f425 100644 (file)
@@ -296,6 +296,7 @@ typedef enum state_of_app {
        TG_CHAT_MESSAGING_VIEW_STATE,
        TG_PEER_SEARCH_VIEW_STATE,
        TG_SETTINGS_SCREEN_STATE,
+       TG_SETTINGS_EDIT_NAME_STATE,
        TG_SET_USERNAME_STATE,
        TG_SET_USER_INFO_STATE,
        TG_SET_CHAT_INFO_STATE,
index d5fc258..2ec926e 100644 (file)
@@ -31,6 +31,7 @@ extern void process_add_new_buddy_to_chat_command(tg_engine_data_s *tg_data, int
 extern void process_remove_buddy_from_chat_command(tg_engine_data_s *tg_data, int s_buddy_id, int s_chat_id);
 extern void process_set_group_chat_profile_pic_command(tg_engine_data_s *tg_data, int buddy_id, const char *file_path);
 extern void process_set_username_command(tg_engine_data_s *tg_data, int buddy_id, const char *username);
+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_registration_response(tg_engine_data_s *tg_data, Eina_Bool is_success);
@@ -66,5 +67,6 @@ extern void send_group_chat_new_buddy_response(tg_engine_data_s *tg_data, int pe
 extern void send_group_chat_delete_buddy_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success);
 extern void send_response_for_server_connection_status(tg_engine_data_s *tg_data, Eina_Bool connection_status);
 
+extern void send_self_profile_name_updated_response(tg_engine_data_s *tg_data, char *first_name, char *last_name, Eina_Bool is_success);
 extern void send_response_to_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id);
 #endif /* SERVER_RESPONSE_H_ */
index bb08845..8d8645e 100644 (file)
@@ -262,6 +262,7 @@ void update_buddy_delete_db(char* table_name, int id, int delete_item);
 Eina_List* get_all_peer_ids();
 int get_number_of_unread_messages();
 int get_unread_message_count(char* table_name);
+int get_number_of_messages(char* table_name);
 
 Eina_List* get_all_unsent_media_messages();
 Eina_List* get_all_unsent_text_messages();
@@ -272,4 +273,6 @@ Eina_Bool is_user_present_chat_table(int id);
 
 int update_current_date_to_table(char* tb_name, int recent_msg_date);
 
+int set_date_item_to_table(char* tb_name, int recent_msg_date);
+
 #endif /* TG_DB_WRAPPER_H_ */
index c2762fc..c33126a 100644 (file)
@@ -177,6 +177,11 @@ void process_set_profile_pic_command(tg_engine_data_s *tg_data, int buddy_id, co
        set_profile_picture(tg_data, buddy_id, file_path);
 }
 
+void process_update_display_name_command(tg_engine_data_s *tg_data, int buddy_id, const char *first_name, const char *last_name)
+{
+       update_user_display_name(tg_data, buddy_id, first_name, last_name);
+}
+
 void process_set_username_command(tg_engine_data_s *tg_data, int buddy_id, const char *username)
 {
        set_user_name(tg_data, buddy_id, username);
@@ -457,6 +462,51 @@ void send_contacts_and_chats_load_done_response(tg_engine_data_s *tg_data, Eina_
        bundle_free(msg);
 }
 
+void send_self_profile_name_updated_response(tg_engine_data_s *tg_data, char *first_name, char *last_name, Eina_Bool is_success)
+{
+       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", "self_profile_name_updated") != 0) {
+               ERR("Failed to add data by key to bundle");
+               bundle_free(msg);
+       }
+
+       if (bundle_add_str(msg, "first_name", first_name) != 0) {
+               ERR("Failed to add data by key to bundle");
+               bundle_free(msg);
+       }
+
+       if (bundle_add_str(msg, "last_name", last_name) != 0) {
+               ERR("Failed to add data by key to bundle");
+               bundle_free(msg);
+       }
+
+       if (is_success) {
+               if (bundle_add_str(msg, "is_success", "true") != 0) {
+                       ERR("Failed to add data by key to bundle");
+                       bundle_free(msg);
+               }
+       } else {
+               if (bundle_add_str(msg, "is_success", "false") != 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_self_user_name_updated_response(tg_engine_data_s *tg_data, char *username, Eina_Bool is_success)
 {
        bundle *msg = bundle_create();
index f7fecdf..29a9ea4 100644 (file)
@@ -374,6 +374,25 @@ static int _on_tg_server_msg_received_cb(void *data, bundle *const rec_msg)
                char *file_path = NULL;
                res = bundle_get_str(rec_msg, "file_path", &file_path);
                process_set_profile_pic_command(tg_data, buddy_id, file_path);
+
+       } else if (strcmp(cmd_key_val, "update_display_name_request") == 0) {
+
+               char *buddy_id_str = NULL;
+               res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+
+               int buddy_id = 0;
+               if (buddy_id_str) {
+                       buddy_id = atoi(buddy_id_str);
+               }
+
+               char *first_name = NULL;
+               res = bundle_get_str(rec_msg, "first_name", &first_name);
+
+               char *last_name = NULL;
+               res = bundle_get_str(rec_msg, "last_name", &last_name);
+
+               process_update_display_name_command(tg_data, buddy_id, first_name, last_name);
+
        } else if (strcmp(cmd_key_val, "set_username_request") == 0) {
 
                char *buddy_id_str = NULL;
index bdd6660..afe1187 100644 (file)
@@ -690,6 +690,95 @@ void create_buddy_msg_table(const char* table_name)
        eina_list_free(col_types);
 }
 
+
+int set_date_item_to_table(char* tb_name, int recent_msg_date)
+{
+       struct tgl_message* last_msg = get_latest_message_from_message_table(tb_name);
+       if (last_msg) {
+               int old_date = last_msg->date;
+               time_t old_t = old_date;
+
+               struct tm old_lt;
+               (void) localtime_r(&old_t, &old_lt);
+
+
+               int cur_time = recent_msg_date;
+               time_t new_t = cur_time;
+
+               struct tm new_lt;
+               (void) localtime_r(&new_t, &new_lt);
+
+               if (old_lt.tm_mday == new_lt.tm_mday && old_lt.tm_mon == new_lt.tm_mon && old_lt.tm_year == new_lt.tm_year) {
+                       // no need of new date
+                       return -1;
+               } else {
+                       int cur_time = recent_msg_date;
+                       time_t t = cur_time;
+
+                       char *format = NULL;
+                       format = "%a, %d%b. %Y";
+
+                       struct tm lt;
+                       char res[256];
+                       (void) localtime_r(&t, &lt);
+
+                       if (strftime(res, sizeof(res), format, &lt) == 0) {
+                               (void) fprintf(stderr,  "strftime(3): cannot format supplied "
+                                               "date/time into buffer of size %u "
+                                               "using: '%s'\n",
+                                               sizeof(res), format);
+                       }
+
+                       srand(time(NULL));
+                       int r = rand();
+                       struct tgl_message date_msg;
+                       date_msg.id = r;
+                       date_msg.media.type = tgl_message_media_none;
+                       date_msg.date = recent_msg_date - 1;
+                       date_msg.message = res;
+                       date_msg.message_len = strlen(res);
+                       date_msg.service = 2;
+                       date_msg.unread = 0;
+                       date_msg.out = 0;
+                       insert_msg_into_db(&date_msg, tb_name, t);
+                       return date_msg.id;
+               }
+
+       } else {
+               int cur_time = recent_msg_date;
+               time_t t = cur_time;
+
+               char *format = NULL;
+               format = "%a, %d%b. %Y";
+
+               struct tm lt;
+               char res[256];
+               (void) localtime_r(&t, &lt);
+
+               if (strftime(res, sizeof(res), format, &lt) == 0) {
+                       (void) fprintf(stderr,  "strftime(3): cannot format supplied "
+                                       "date/time into buffer of size %u "
+                                       "using: '%s'\n",
+                                       sizeof(res), format);
+               }
+               srand(time(NULL));
+               int r = rand();
+               struct tgl_message date_msg;
+               date_msg.id = r;
+               date_msg.media.type = tgl_message_media_none;
+               date_msg.date = recent_msg_date - 1;
+               date_msg.message = res;
+               date_msg.message_len = strlen(res);
+               date_msg.service = 2;
+               date_msg.unread = 0;
+               date_msg.out = 0;
+               insert_msg_into_db(&date_msg, tb_name, t);
+               return date_msg.id;
+       }
+       return -1;
+}
+
+
 int update_current_date_to_table(char* tb_name, int recent_msg_date)
 {
        struct tgl_message* last_msg = get_latest_message_from_message_table(tb_name);
@@ -4860,6 +4949,18 @@ int get_unread_message_count(char* table_name)
        return num_of_rows;
 }
 
+int get_number_of_messages(char* table_name)
+{
+       // number of rows, having out == 1 and unread == 0
+       if (!table_name) {
+               return 0;
+       }
+       int num_of_rows = 0;
+       num_of_rows = get_number_of_rows(table_name, NULL);
+       return num_of_rows;
+}
+
+
 Eina_List* get_all_peer_ids()
 {
        Eina_List* peer_details = NULL;
@@ -4909,7 +5010,7 @@ Eina_Bool is_user_present_peer_table(int peer_id)
        Eina_Bool ret = EINA_FALSE;
 
        Eina_List* peer_details = NULL;
-       char* table_name = BUDDY_INFO_TABLE_NAME;
+       char* table_name = PEER_INFO_TABLE_NAME;
 
        Eina_List* col_names = NULL;
        col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME);
index 806d852..2922b39 100644 (file)
@@ -831,6 +831,10 @@ void tg_chat_update(struct tgl_state *TLS, struct tgl_chat* chat_info, unsigned
        tg_engine_data_s *tg_data;
        tg_data = TLS->callback_data;
 
+       if (chat_info && chat_info->flags == 144) {
+               return;
+       }
+
        if (flags == TGL_GROUP_CHAT_CREATED) {
 #if 0
                insert_chat_info_to_db(chat_info, NULL);
@@ -1714,8 +1718,45 @@ void on_chat_info_received(struct tgl_state *TLS, void *callback_extra, int succ
        if (!chat_info) {
                return;
        }
+       if (chat_info->flags == 144) {
+               return;
+       }
        msg_table = get_table_name_from_number(chat_info->id.id);
        create_buddy_msg_table(msg_table);
+
+       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);
@@ -2433,6 +2474,26 @@ void set_user_name(tg_engine_data_s *tg_data, int buddy_id, const char *username
        }
 }
 
+void on_profile_name_changed(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *buddy)
+{
+       tg_engine_data_s *tg_data = callback_extra;
+       if (success) {
+               // update db
+               update_buddy_into_db(USER_INFO_TABLE_NAME, buddy);
+               update_buddy_into_db(BUDDY_INFO_TABLE_NAME, buddy);
+               send_self_profile_name_updated_response(tg_data, buddy->first_name, buddy->last_name, EINA_TRUE);
+       } else {
+               send_self_profile_name_updated_response(tg_data, "", "", EINA_FALSE);
+       }
+}
+
+void update_user_display_name(tg_engine_data_s *tg_data, int buddy_id, const char *first_name, const char *last_name)
+{
+       if (first_name && last_name) {
+               tgl_do_set_profile_name(tgl_engine_get_TLS(), first_name, last_name, on_profile_name_changed, tg_data);
+       }
+}
+
 
 void create_new_group(tg_engine_data_s *tg_data, Eina_List* buddy_ids, const char *group_name, const char *group_icon)
 {
index 5e25f65..33438c9 100644 (file)
@@ -169,6 +169,7 @@ extern void add_contacts_to_user(tg_engine_data_s *tg_data, int size, Eina_List*
 extern void create_new_group(tg_engine_data_s *tg_data, Eina_List* buddy_ids, const char* group_name, const char* group_icon);
 extern void set_profile_picture(tg_engine_data_s *tg_data, int buddy_id, const char *file_path);
 extern void set_user_name(tg_engine_data_s *tg_data, int buddy_id, const char *username);
+extern void update_user_display_name(tg_engine_data_s *tg_data, int buddy_id, const char *first_name, const char *last_name);
 extern void request_for_code_via_call(struct tgl_state *TLS, char* phone_no, Eina_Bool trough_sms);
 extern void free_contact_data(Eina_List *contact_data);
 extern void leave_group_chat(tg_engine_data_s *tg_data, int group_chat_id);