2 This file is part of Telegram application for tizen
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "telegramtizen.h"
23 #include "tg_splash_screen.h"
24 #include "tg_registration.h"
25 #include "tg_db_wrapper.h"
27 #include "tg_first_registration.h"
28 #include "server_requests.h"
29 #include "tg_init_screen.h"
30 #include "tg_user_main_view.h"
31 #include "tg_messaging_view.h"
32 #include "tg_start_messaging_view.h"
33 #include "tg_user_info_view.h"
34 #include "tg_chat_info_view.h"
36 #include "tg_settings_view.h"
37 #include "device_contacts_manager.h"
38 #include "tg_search_peer_view.h"
40 #include "tg_common.h"
43 static void free_app_data(appdata_s *app_data, Eina_Bool destroy_server);
44 static int init_service(appdata_s *app);
45 static void popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
50 static void popup_timeout_cb(void *data, Evas_Object *obj, void *event_info)
55 void show_toast(appdata_s *ad, char* value)
58 Evas_Object *win = ad->win;
59 popup = elm_popup_add(win);
60 elm_object_style_set(popup, "toast");
61 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
62 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
64 char buf[512] = {'\0'};
65 snprintf(buf, sizeof(buf), "<font_size=30><color=#000000>%s</color></font_size>", value);
67 //elm_object_part_text_set(popup,"elm.text", buf);
68 elm_object_text_set(popup, buf);
69 evas_object_smart_callback_add(popup, "block,clicked", popup_block_clicked_cb, win);
70 elm_popup_timeout_set(popup, 2.0);
71 evas_object_smart_callback_add(popup, "timeout", popup_timeout_cb, NULL);
72 evas_object_show(popup);
75 static int _app_send_response(appdata_s *app, bundle *const msg)
77 int res = SVC_RES_FAIL;
78 res = service_client_send_message(app->service_client, msg);
83 void load_list_of_countries(appdata_s *ad)
88 const char *file_name = ui_utils_get_resource(TG_LIST_OF_COUNTIRES);
105 fd = open(file_name, O_RDONLY);
109 file_size = lseek(fd, 0L, SEEK_END);
110 if ((int)file_size == -1) {
115 if (lseek(fd, 0L, SEEK_SET) < 0) {
118 ad->country_code_buffer = malloc(file_size);
119 if (!ad->country_code_buffer) {
123 if (read(fd, ad->country_code_buffer, file_size) != file_size) {
135 ptr = ad->country_code_buffer;
141 ptrToShortName = NULL;
142 ptrToFullName = NULL;
145 if (ptrToCode == NULL) {
149 } else if (*ptr == ';') {
151 state = STATE_SHORT_NAME;
155 case STATE_SHORT_NAME:
156 if (ptrToShortName == NULL) {
157 ptrToShortName = ptr;
158 } else if (*ptr == ';') {
160 state = STATE_FULL_NAME;
164 case STATE_FULL_NAME:
165 if (ptrToFullName == NULL) {
167 } else if (*ptr == '\r' || *ptr == '\n') {
169 dlog_print(DLOG_DEBUG, LOG_TAG, "[%s] [%s] [%s]", ptrToCode, ptrToShortName, ptrToFullName);
170 ad->country_codes_list = eina_list_append(ad->country_codes_list, ptrToCode);
171 ad->country_names_list = eina_list_append(ad->country_names_list, ptrToFullName);
183 void load_registered_user_data(appdata_s *ad)
185 Eina_List *user_info = get_registered_user_info();
189 //show_toast(ad, "User info not loaded");
192 if (ad->current_user_data) {
193 free_user_data(ad->current_user_data);
194 ad->current_user_data = NULL;
197 ad->current_user_data = (user_data_s*)malloc(sizeof(user_data_s));
198 memset(ad->current_user_data, 0, sizeof(user_data_s));
201 Eina_List *row_vals = NULL;
203 EINA_LIST_FREE(user_info, row_vals) {
207 int *temp_user_id = (int *)eina_list_nth(row_vals, 0);
209 int user_id = *temp_user_id;
212 ad->user_id.id = user_id;
213 ad->user_id.type = TGL_PEER_USER;
215 ad->current_user_data->user_id.id = user_id;
216 ad->current_user_data->user_id.type = TGL_PEER_USER;
219 ad->current_user_data->print_name = (char *)eina_list_nth(row_vals, 1);
221 int *temp_struct_ver = (int *)eina_list_nth(row_vals, 2);
222 if (temp_struct_ver) {
223 ad->current_user_data->structure_version = *temp_struct_ver;
224 free(temp_struct_ver);
227 ad->current_user_data->photo_path = (char *)eina_list_nth(row_vals, 3);
229 int *temp_photo_id = (int *)eina_list_nth(row_vals, 4);
231 ad->current_user_data->photo_id = *temp_photo_id;
235 ad->current_user_data->first_name = (char *)eina_list_nth(row_vals, 5);
237 ad->current_user_data->last_name = (char *)eina_list_nth(row_vals, 6);
239 char *phone_no = (char *)eina_list_nth(row_vals, 7);
240 ad->current_user_data->phone = phone_no;
242 int *temp_access_hash = (int *)eina_list_nth(row_vals, 8);
243 if (temp_access_hash) {
244 ad->current_user_data->access_hash = *temp_access_hash;
245 free(temp_access_hash);
248 ad->current_user_data->real_first_name = (char *)eina_list_nth(row_vals, 9);
250 ad->current_user_data->real_last_name = (char *)eina_list_nth(row_vals, 10);
252 char *user_name = (char *)eina_list_nth(row_vals, 11);
253 ad->current_user_data->username = user_name;
255 int *temp_online_status = (int *)eina_list_nth(row_vals, 12);
256 if (temp_online_status) {
257 ad->current_user_data->online = *temp_online_status;
258 free(temp_online_status);
261 int *temp_last_seen = (int *)eina_list_nth(row_vals, 13);
262 if (temp_last_seen) {
263 ad->current_user_data->last_seen = *temp_last_seen;
264 free(temp_last_seen);
268 EINA_LIST_FREE(row_vals, val) {
275 eina_list_free(user_info);
278 void load_peer_data(appdata_s *ad)
285 peer_with_pic_s* pic_item = NULL;
286 EINA_LIST_FREE(ad->peer_list, pic_item) {
289 tg_peer_info_s* item = pic_item->use_data;
291 if (item->print_name) {
292 free(item->print_name);
293 item->print_name = NULL;
295 if (item->photo_path) {
296 free(item->photo_path);
297 item->photo_path = NULL;
299 pic_item->contact_icon = NULL;
300 pic_item->msg_object = NULL;
301 pic_item->name_object = NULL;
307 ad->peer_list = NULL;
310 Eina_List *peer_details = get_all_peer_details(NULL);
312 Eina_List *ts_msg = NULL;
313 EINA_LIST_FREE(peer_details, ts_msg) {
314 tg_peer_info_s* peer_info = (tg_peer_info_s*)malloc(sizeof(*peer_info));
315 memset(peer_info, 0, sizeof(tg_peer_info_s));
317 int *temp_peer_id = (int *)eina_list_nth(ts_msg, 0);
319 peer_info->peer_id = *temp_peer_id;
323 int *temp_peer_type = (int *)eina_list_nth(ts_msg, 1);
324 if (temp_peer_type) {
325 peer_info->peer_type = *temp_peer_type;
326 free(temp_peer_type);
329 int *temp_flags = (int *)eina_list_nth(ts_msg, 2);
331 peer_info->flags = *temp_flags;
335 char *temp_msg_id = (char *)eina_list_nth(ts_msg, 3);
337 peer_info->last_msg_id = atoll(temp_msg_id);
340 peer_info->last_msg_id = 0;
343 int *temp_last_msg_date = (int *)eina_list_nth(ts_msg, 4);
344 if (temp_last_msg_date) {
345 peer_info->last_msg_date = *temp_last_msg_date;
346 free(temp_last_msg_date);
349 peer_info->print_name = (char *)eina_list_nth(ts_msg, 5);
351 int *temp_struct_ver = (int *)eina_list_nth(ts_msg, 6);
352 if (temp_struct_ver) {
353 peer_info->struct_version = *temp_struct_ver;
354 free(temp_struct_ver);
357 int *temp_no_unread = (int *)eina_list_nth(ts_msg, 7);
358 if (temp_no_unread) {
359 peer_info->no_of_unread_msgs = *temp_no_unread;
360 free(temp_no_unread);
363 int *temp_last_seen = (int *)eina_list_nth(ts_msg, 8);
364 if (temp_last_seen) {
365 peer_info->last_seen_time = *temp_last_seen;
366 free(temp_last_seen);
369 peer_info->photo_path = (char *)eina_list_nth(ts_msg, 9);
371 int *temp_pic_id = (int *)eina_list_nth(ts_msg, 10);
373 peer_info->photo_id = *temp_pic_id;
376 int *temp_unknown = (int *)eina_list_nth(ts_msg, 11);
378 peer_info->is_unknown = *temp_unknown;
382 eina_list_free(ts_msg);
384 peer_with_pic_s *item = (peer_with_pic_s*) malloc(sizeof(*item));
385 memset(item, 0, sizeof(peer_with_pic_s));
386 item->use_data = peer_info;
387 ad->peer_list = eina_list_append(ad->peer_list, item);
392 void load_main_list_data(appdata_s *ad)
394 if (!ad || !ad->peer_list)
397 tg_main_list_item_s* main_item = NULL;
398 EINA_LIST_FREE(ad->main_list, main_item) {
400 if (main_item->peer_print_name)
401 free(main_item->peer_print_name);
402 main_item->peer_print_name = NULL;
404 if (main_item->last_message)
405 free(main_item->last_message);
406 main_item->last_message = NULL;
408 if (main_item->profile_pic_path)
409 free(main_item->profile_pic_path);
410 main_item->profile_pic_path = NULL;
412 if (main_item->buddy_display_name)
413 free(main_item->buddy_display_name);
414 main_item->buddy_display_name = NULL;
416 main_item->date_lbl = NULL;
417 main_item->msg_status_lbl = NULL;
418 main_item->profile_pic = NULL;
419 main_item->profile_pic_path = NULL;
420 main_item->status_lbl = NULL;
421 main_item->user_name_lbl = NULL;
422 main_item->main_item_layout = NULL;
424 ad->main_list = NULL;
427 peer_with_pic_s *item = NULL;
428 EINA_LIST_FOREACH(ad->peer_list, l, item) {
430 tg_peer_info_s* peer_info = item->use_data;
434 if (peer_info->peer_type == TGL_PEER_CHAT &&
435 get_buddy_unknown_status(peer_info->peer_id))
438 //if (peer_info->last_msg_id > 0) {
440 // get message from message table.
442 char* tablename = get_table_name_from_number(peer_info->peer_id);
443 tg_message_s *msg = get_latest_message_from_message_table(tablename, EINA_FALSE);
448 if (msg->message && strlen(msg->message) > 0) {
449 item->last_message = strdup(msg->message);
451 item->last_message = strdup(" ");
455 int media_type = msg->media_type;
456 if (media_type == tgl_message_media_none) {
457 item->last_message = strdup(msg->message ? msg->message : " ");
458 } else if (media_type == tgl_message_media_photo) {
459 item->last_message = strdup("Image");
460 } else if (media_type == tgl_message_media_document) {
461 tgl_media_s *media_msg = NULL;
462 media_msg = get_media_details_from_db(atoll(msg->media_id));
464 if (media_msg && media_msg->doc_type) {
465 if (strlen(media_msg->doc_type) > 0) {
466 item->last_message = strdup(media_msg->doc_type);
468 item->last_message = strdup("Document");
470 free_media_details(media_msg);
472 if (msg->message && strlen(msg->message) > 0) {
473 item->last_message = strdup(msg->message);
475 item->last_message = strdup("Document");
479 } else if (media_type == tgl_message_media_geo) {
480 item->last_message = strdup("Geo location");
481 } else if (media_type == tgl_message_media_contact) {
482 item->last_message = strdup("Contact");
483 } else if (media_type == tgl_message_media_unsupported) {
484 item->last_message = strdup(" ");
485 } else if (media_type == tgl_message_media_photo_encr) {
486 item->last_message = strdup("Image encrypted");
487 } else if (media_type == tgl_message_media_document_encr) {
488 item->last_message = strdup("Document encrypted");
490 item->last_message = strdup(" ");
494 tg_main_list_item_s* main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s));
495 memset(main_list_item, 0, sizeof(tg_main_list_item_s));
496 main_list_item->peer_id = peer_info->peer_id;
497 main_list_item->peer_type = peer_info->peer_type;
499 set_peer_names(peer_info, main_list_item);
501 main_list_item->last_seen_time = msg->date;
502 main_list_item->last_msg_id = msg->msg_id;
503 main_list_item->last_message = strdup(item->last_message);
504 main_list_item->last_msg_type = msg->media_type;
505 main_list_item->is_out_msg = msg->out;
506 main_list_item->last_msg_status = msg->msg_state;
507 main_list_item->last_msg_service = msg->service;
508 main_list_item->number_of_unread_msgs = get_unread_message_count(tablename);
510 if (peer_info->photo_path)
511 main_list_item->profile_pic_path = strdup(peer_info->photo_path);
513 ad->main_list = eina_list_append(ad->main_list, main_list_item);
515 // delete message object
522 msg->media_id = NULL;
528 item->last_message = strdup(" ");
529 if (peer_info->peer_type == TGL_PEER_CHAT) {
530 tg_main_list_item_s* main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s));
531 memset(main_list_item, 0, sizeof(tg_main_list_item_s));
532 main_list_item->peer_id = peer_info->peer_id;
533 main_list_item->peer_type = peer_info->peer_type;
535 set_peer_names(peer_info, main_list_item);
537 main_list_item->last_seen_time = peer_info->last_seen_time;
538 main_list_item->last_message = strdup(item->last_message);
539 main_list_item->last_msg_type = -1;
540 main_list_item->last_msg_service = 0;
541 main_list_item->is_out_msg = -1;
542 main_list_item->last_msg_id = -1;
543 main_list_item->last_msg_status = -1;
544 main_list_item->number_of_unread_msgs = 0;
546 if (peer_info->photo_path)
547 main_list_item->profile_pic_path = strdup(peer_info->photo_path);
548 ad->main_list = eina_list_append(ad->main_list, main_list_item);
559 void load_unknown_buddy_list_data(appdata_s *ad)
565 user_data_with_pic_s *item = NULL;
566 EINA_LIST_FREE(ad->unknown_buddy_list, item) {
567 user_data_s* user_data = item->use_data;
569 if (user_data->print_name)
570 free(user_data->print_name);
571 user_data->print_name = NULL;
573 if (user_data->photo_path)
574 free(user_data->photo_path);
575 user_data->photo_path = NULL;
577 if (user_data->first_name)
578 free(user_data->first_name);
579 user_data->first_name = NULL;
581 if (user_data->last_name)
582 free(user_data->last_name);
583 user_data->last_name = NULL;
585 if (user_data->phone)
586 free(user_data->phone);
587 user_data->phone = NULL;
589 if (user_data->real_first_name)
590 free(user_data->real_first_name);
591 user_data->real_first_name = NULL;
593 if (user_data->real_last_name)
594 free(user_data->real_last_name);
595 user_data->real_last_name = NULL;
597 if (user_data->username)
598 free(user_data->username);
599 user_data->username = NULL;
604 ad->unknown_buddy_list = NULL;
606 Eina_List *user_info = get_unknown_buddy_list_info();
609 //show_toast(ad, "User info not loaded");
613 Eina_List *row_vals = NULL;
614 EINA_LIST_FREE(user_info, row_vals) {
616 int *temp_user_id = (int *)eina_list_nth(row_vals, 0);
617 if (ad->user_id.id == (*temp_user_id)) {
619 EINA_LIST_FREE(row_vals, val) {
626 user_data_s *user_data = (user_data_s*)malloc(sizeof(*user_data));
627 memset(user_data, 0, sizeof(user_data_s));
628 user_data->is_selected = EINA_FALSE;
631 user_data->user_id.id = *temp_user_id;
632 user_data->user_id.type = TGL_PEER_USER;
636 user_data->print_name = (char *)eina_list_nth(row_vals, 1);
638 int *temp_struct_ver = (int *)eina_list_nth(row_vals, 2);
639 if (temp_struct_ver) {
640 user_data->structure_version = *temp_struct_ver;
641 free(temp_struct_ver);
644 user_data->photo_path = (char *)eina_list_nth(row_vals, 3);
646 int *temp_photo_id = (int *)eina_list_nth(row_vals, 4);
648 user_data->photo_id = *temp_photo_id;
652 user_data->first_name = (char *)eina_list_nth(row_vals, 5);
654 user_data->last_name = (char *)eina_list_nth(row_vals, 6);
656 user_data->phone = (char *)eina_list_nth(row_vals, 7);
658 int *temp_access_hash = (int *)eina_list_nth(row_vals, 8);
659 if (temp_access_hash) {
660 user_data->access_hash = *temp_access_hash;
661 free(temp_access_hash);
664 user_data->real_first_name = (char *)eina_list_nth(row_vals, 9);
666 user_data->real_last_name = (char *)eina_list_nth(row_vals, 10);
668 user_data->username = (char *)eina_list_nth(row_vals, 11);
670 int *temp_online_status = (int *)eina_list_nth(row_vals, 12);
671 if (temp_online_status) {
672 user_data->online = *temp_online_status;
673 free(temp_online_status);
676 int *temp_last_seen = (int *)eina_list_nth(row_vals, 13);
677 if (temp_last_seen) {
678 user_data->last_seen = *temp_last_seen;
679 free(temp_last_seen);
682 int *temp_is_blocked = (int *)eina_list_nth(row_vals, 14);
683 if (temp_is_blocked) {
684 user_data->is_blocked = *temp_is_blocked;
685 free(temp_is_blocked);
688 int *temp_is_deleted = (int *)eina_list_nth(row_vals, 15);
689 if (temp_is_deleted) {
690 user_data->is_deleted = *temp_is_deleted;
691 free(temp_is_deleted);
694 int *temp_is_unknown = (int *)eina_list_nth(row_vals, 16);
695 if (temp_is_unknown) {
696 user_data->is_unknown = *temp_is_unknown;
697 free(temp_is_unknown);
699 user_data->highlight_name = NULL;
701 user_data_with_pic_s *item = (user_data_with_pic_s *)malloc(sizeof(*item));
702 memset(item, 0, sizeof(user_data_with_pic_s));
703 item->use_data = user_data;
704 ad->unknown_buddy_list = eina_list_append(ad->unknown_buddy_list, item);
706 eina_list_free(row_vals);
710 void load_buddy_list_data(appdata_s *ad)
716 user_data_with_pic_s *item = NULL;
717 EINA_LIST_FREE(ad->buddy_list, item) {
718 user_data_s* user_data = item->use_data;
720 if (user_data->print_name)
721 free(user_data->print_name);
722 user_data->print_name = NULL;
724 if (user_data->photo_path)
725 free(user_data->photo_path);
726 user_data->photo_path = NULL;
728 if (user_data->first_name)
729 free(user_data->first_name);
730 user_data->first_name = NULL;
732 if (user_data->last_name)
733 free(user_data->last_name);
734 user_data->last_name = NULL;
736 if (user_data->phone)
737 free(user_data->phone);
738 user_data->phone = NULL;
740 if (user_data->real_first_name)
741 free(user_data->real_first_name);
742 user_data->real_first_name = NULL;
744 if (user_data->real_last_name)
745 free(user_data->real_last_name);
746 user_data->real_last_name = NULL;
748 if (user_data->username)
749 free(user_data->username);
750 user_data->username = NULL;
752 if (user_data->highlight_name)
753 free(user_data->highlight_name);
754 user_data->highlight_name = NULL;
759 ad->buddy_list = NULL;
761 Eina_List *user_info = get_buddy_list_info();
765 //show_toast(ad, "User info not loaded");
769 Eina_List *row_vals = NULL;
770 EINA_LIST_FREE(user_info, row_vals) {
773 int *temp_user_id = (int *)eina_list_nth(row_vals, 0);
774 if (ad->user_id.id == (*temp_user_id)) {
776 EINA_LIST_FREE(row_vals, val) {
783 user_data_s *user_data = (user_data_s *)malloc(sizeof(*user_data));
784 memset(user_data, 0, sizeof(user_data_s));
785 user_data->is_selected = EINA_FALSE;
789 user_data->user_id.id = *temp_user_id;
790 user_data->user_id.type = TGL_PEER_USER;
794 user_data->print_name = (char *)eina_list_nth(row_vals, 1);
796 int *temp_struct_ver = (int *)eina_list_nth(row_vals, 2);
797 if (temp_struct_ver) {
798 user_data->structure_version = *temp_struct_ver;
799 free(temp_struct_ver);
802 user_data->photo_path = (char *)eina_list_nth(row_vals, 3);
804 int *temp_photo_id = (int *)eina_list_nth(row_vals, 4);
806 user_data->photo_id = *temp_photo_id;
810 user_data->first_name = (char *)eina_list_nth(row_vals, 5);
812 user_data->last_name = (char *)eina_list_nth(row_vals, 6);
814 user_data->phone = (char *)eina_list_nth(row_vals, 7);
816 int *temp_access_hash = (int *)eina_list_nth(row_vals, 8);
817 if (temp_access_hash) {
818 user_data->access_hash = *temp_access_hash;
819 free(temp_access_hash);
822 user_data->real_first_name = (char *)eina_list_nth(row_vals, 9);
824 user_data->real_last_name = (char *)eina_list_nth(row_vals, 10);
826 user_data->username = (char *)eina_list_nth(row_vals, 11);
828 int *temp_online_status = (int *)eina_list_nth(row_vals, 12);
829 if (temp_online_status) {
830 user_data->online = *temp_online_status;
831 free(temp_online_status);
834 int *temp_last_seen = (int *)eina_list_nth(row_vals, 13);
835 if (temp_last_seen) {
836 user_data->last_seen = *temp_last_seen;
837 free(temp_last_seen);
840 int *temp_is_blocked = (int *)eina_list_nth(row_vals, 14);
841 if (temp_is_blocked) {
842 user_data->is_blocked = *temp_is_blocked;
843 free(temp_is_blocked);
846 int *temp_is_deleted = (int *)eina_list_nth(row_vals, 15);
847 if (temp_is_deleted) {
848 user_data->is_deleted = *temp_is_deleted;
849 free(temp_is_deleted);
852 int *temp_is_unknown = (int *)eina_list_nth(row_vals, 16);
853 if (temp_is_unknown) {
854 user_data->is_unknown = *temp_is_unknown;
855 free(temp_is_unknown);
857 user_data->highlight_name = NULL;
859 user_data_with_pic_s *item = (user_data_with_pic_s *) malloc(sizeof(*item));
860 memset(item, 0, sizeof(user_data_with_pic_s));
861 item->use_data = user_data;
862 item->contact_icon = NULL;
863 ad->buddy_list = eina_list_append(ad->buddy_list, item);
864 eina_list_free(row_vals);
869 static int on_contacts_loaded(appdata_s *app, bundle *const rec_msg)
871 int result = SVC_RES_FAIL;
872 char* is_success_val = NULL;
873 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
874 if (strncmp("true", is_success_val, strlen("true")) == 0) {
878 load_registered_user_data(app);
880 if (app->current_app_state == TG_LOGIN_STATE || app->current_app_state == TG_REGISTRATION_STATE || app->current_app_state == TG_PROFILE_REGISTRATION_STATE) {
881 // Launch buddy list view
882 load_buddy_list_data(app);
883 load_unknown_buddy_list_data(app);
885 load_main_list_data(app);
886 elm_naviframe_item_pop(app->nf);
887 elm_naviframe_item_pop(app->nf);
888 //launch_buddy_list_cb(app);
890 //launch_user_main_view_cb(app);
891 launch_start_messaging_view(app);
893 } else if (app->current_app_state == TG_BUDDY_LIST_STATE) {
894 ////refresh_buddy_list(app);
901 show_toast(app, "Error: loading contacts");
903 hide_loading_popup(app);
908 static int on_contacts_and_chats_loaded(appdata_s *app, bundle *const rec_msg)
910 int result = SVC_RES_FAIL;
911 char* is_success_val = NULL;
912 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
913 if (strncmp("true", is_success_val, strlen("true")) == 0) {
916 //Eina_List *user_info = get_registered_user_info();
917 load_registered_user_data(app);
919 if (app->current_app_state == TG_LOGIN_STATE || app->current_app_state == TG_REGISTRATION_STATE || app->current_app_state == TG_PROFILE_REGISTRATION_STATE) {
920 // Launch buddy list view
921 load_buddy_list_data(app);
922 load_unknown_buddy_list_data(app);
924 load_main_list_data(app);
925 elm_naviframe_item_pop(app->nf);
926 elm_naviframe_item_pop(app->nf);
927 //launch_buddy_list_cb(app);
928 launch_user_main_view_cb(app);
929 } else if (app->current_app_state == TG_BUDDY_LIST_STATE) {
930 app->current_app_state = TG_BUDDY_LIST_STATE;
931 evas_object_show(app->panel);
932 //elm_panel_hidden_set(app->panel, EINA_FALSE);
933 ////refresh_buddy_list(app);
940 show_toast(app, "Error: loading contacts");
942 hide_loading_popup(app);
946 static int on_group_chat_updated(appdata_s *app, bundle *const rec_msg)
948 int result = SVC_RES_FAIL;
949 char *chat_id_str = NULL;
950 result = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
951 int chat_id = atoi(chat_id_str);
954 app->main_item_in_cahtting_data = NULL;
955 app->peer_in_cahtting_data = NULL;
958 tg_main_list_item_s *item = NULL;
959 EINA_LIST_FOREACH(app->main_list, l, item) {
962 if (item->peer_id == chat_id) {
963 app->main_item_in_cahtting_data = item;
969 peer_with_pic_s* pic_item = NULL;
971 EINA_LIST_FOREACH(app->peer_list, l, pic_item) {
976 tg_peer_info_s* item = pic_item->use_data;
977 if (item->peer_id == chat_id) {
978 app->peer_in_cahtting_data = pic_item;
985 launch_messaging_view_cb(app, buddy_id);
986 hide_loading_popup(app);
990 static int on_group_chat_info_changed_response(appdata_s *app, bundle *const rec_msg)
992 int result = SVC_RES_FAIL;
993 char *chat_id_str = NULL;
994 result = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
995 int chat_id = atoi(chat_id_str);
997 char *type_of_change = NULL;
998 result = bundle_get_str(rec_msg, "type_of_change", &type_of_change);
1001 peer_with_pic_s *peer_item = get_peer_info(chat_id);
1002 tg_main_list_item_s *latest_item = get_latest_item(app, peer_item);
1005 Eina_List *l = NULL;
1006 peer_with_pic_s *pitem = NULL;
1007 EINA_LIST_FOREACH(app->peer_list, l, pitem) {
1010 if (pitem->use_data->peer_id == chat_id) {
1011 app->peer_list = eina_list_remove(app->peer_list, pitem);
1017 tg_main_list_item_s *item = NULL;
1018 EINA_LIST_FOREACH(app->main_list, l, item) {
1022 if (item->peer_id == chat_id) {
1023 app->main_list = eina_list_remove(app->main_list, item);
1028 app->peer_list = eina_list_prepend(app->peer_list, peer_item);
1029 app->main_list = eina_list_prepend(app->main_list, latest_item);
1030 refresh_main_list_view(app, EINA_TRUE);
1032 if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->peer_in_cahtting_data
1033 && app->peer_in_cahtting_data->use_data->peer_id == chat_id) {
1035 app->peer_in_cahtting_data = peer_item;
1036 app->main_item_in_cahtting_data = latest_item;
1038 on_group_chat_info_changed(app, type_of_change);
1041 if (app->current_app_state == TG_SET_CHAT_INFO_STATE && app->peer_in_cahtting_data
1042 && app->peer_in_cahtting_data->use_data->peer_id == chat_id) {
1044 app->peer_in_cahtting_data = peer_item;
1045 app->main_item_in_cahtting_data = latest_item;
1047 on_group_chat_info_changed(app, type_of_change);
1049 on_group_chat_info_updated(app, type_of_change);
1052 hide_loading_popup(app);
1057 static int on_new_buddy_added_or_deleted_from_group_chat(appdata_s *app, bundle *const rec_msg, char *rec_key_val)
1059 int result = SVC_RES_FAIL;
1060 char* buddy_id_str = NULL;
1061 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
1062 int buddy_id = atoi(buddy_id_str);
1064 Eina_Bool is_success = EINA_FALSE;
1065 char* is_success_val = NULL;
1066 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
1067 if (strncmp("true", is_success_val, strlen("true")) == 0) {
1068 is_success = EINA_TRUE;
1070 is_success = EINA_FALSE;
1073 if (app->current_app_state == TG_SET_CHAT_INFO_STATE && app->peer_in_cahtting_data
1074 && app->peer_in_cahtting_data->use_data->peer_id == buddy_id) {
1075 hide_loading_popup(app);
1076 if (strcmp(rec_key_val, "group_chat_new_buddy_added_response") == 0) {
1077 show_toast(app, "Failed to add new buddy to chat.");
1078 } else if (strcmp(rec_key_val, "group_chat_buddy_deleted_response") == 0) {
1079 show_toast(app, "Failed to delete buddy to chat.");
1082 hide_loading_popup(app);
1086 static int on_group_chat_name_changed(appdata_s *app, bundle *const rec_msg)
1088 int result = SVC_RES_FAIL;
1089 char* buddy_id_str = NULL;
1090 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
1091 int buddy_id = atoi(buddy_id_str);
1093 Eina_Bool is_success = EINA_FALSE;
1094 char* is_success_val = NULL;
1095 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
1096 if (strncmp("true", is_success_val, strlen("true")) == 0) {
1097 is_success = EINA_TRUE;
1099 is_success = EINA_FALSE;
1102 if (app->current_app_state == TG_SET_CHAT_INFO_STATE && app->peer_in_cahtting_data
1103 && app->peer_in_cahtting_data->use_data->peer_id == buddy_id) {
1105 hide_loading_popup(app);
1106 show_toast(app, "Failed to rename the chat title.");
1108 hide_loading_popup(app);
1113 static int on_server_connection_status_changed(appdata_s *app, bundle *const rec_msg)
1115 int result = SVC_RES_FAIL;
1116 Eina_Bool is_success = EINA_FALSE;
1117 char* is_success_val = NULL;
1118 result = bundle_get_str(rec_msg, "connection_status", &is_success_val);
1119 if (strncmp("true", is_success_val, strlen("true")) == 0) {
1120 is_success = EINA_TRUE;
1122 is_success = EINA_FALSE;
1125 app->is_server_ready = is_success;
1129 static int on_buddy_profile_pic_updated(appdata_s *app, bundle *const rec_msg)
1131 int result = SVC_RES_FAIL;
1132 char* user_id_str = NULL;
1133 result = bundle_get_str(rec_msg, "user_id", &user_id_str);
1134 int user_id = atoi(user_id_str);
1135 char* pic_file_path = NULL;
1136 result = bundle_get_str(rec_msg, "file_path", &pic_file_path);
1137 if (result == SVC_RES_FAIL || !pic_file_path || strlen(pic_file_path) <= 0 || access(pic_file_path, F_OK) == -1) {
1138 //pic_file_path = (char *)ui_utils_get_resource(DEFAULT_PROFILE_PIC);
1142 // update profile pic if buddy list view is present.
1143 if (user_id == app->user_id.id) {
1147 // update buddy list in appdata.
1149 Eina_List *l = NULL;
1150 user_data_with_pic_s *uitem = NULL;
1151 EINA_LIST_FOREACH(app->buddy_list, l, uitem) {
1154 if (uitem->use_data->user_id.id == user_id) {
1155 if (uitem->use_data->photo_path) {
1156 free(uitem->use_data->photo_path);
1157 uitem->use_data->photo_path = NULL;
1159 uitem->use_data->photo_path = strdup(pic_file_path);
1160 if (uitem->contact_icon) {
1161 elm_image_file_set(uitem->contact_icon, pic_file_path, NULL);
1162 evas_object_color_set(uitem->contact_icon, 0, 0, 0, 0);
1170 peer_with_pic_s *pitem = NULL;
1171 EINA_LIST_FOREACH(app->peer_list, l, pitem) {
1175 if (pitem->use_data->peer_id == user_id) {
1176 if (pitem->use_data->photo_path) {
1177 free(pitem->use_data->photo_path);
1178 pitem->use_data->photo_path = NULL;
1180 pitem->use_data->photo_path = strdup(pic_file_path);
1181 if (pitem->contact_icon) {
1182 elm_image_file_set(pitem->contact_icon, pic_file_path, NULL);
1183 evas_object_color_set(pitem->contact_icon, 0, 0, 0, 0);
1191 tg_main_list_item_s *item = NULL;
1192 EINA_LIST_FOREACH(app->main_list, l, item) {
1196 if (item->peer_id == user_id) {
1197 if (item->profile_pic_path) {
1198 free(item->profile_pic_path);
1199 item->profile_pic_path = NULL;
1201 item->profile_pic_path = strdup(pic_file_path);
1202 if (item->profile_pic) {
1203 elm_image_file_set(item->profile_pic, pic_file_path, NULL);
1204 evas_object_color_set(item->profile_pic, 0, 0, 0, 0);
1209 if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->peer_in_cahtting_data && app->peer_in_cahtting_data->use_data
1210 && app->peer_in_cahtting_data->use_data->peer_id == user_id) {
1211 on_chat_profile_pic_changed(app, pic_file_path);
1213 if (app->current_app_state == TG_SET_CHAT_INFO_STATE && app->peer_in_cahtting_data && app->peer_in_cahtting_data->use_data
1214 && app->peer_in_cahtting_data->use_data->peer_id == user_id) {
1215 //on_chat_profile_pic_changed(app, pic_file_path);
1216 //show_toast(app, "Chat profile picture updated successfully.");
1223 static int on_message_received_from_buddy(appdata_s *app, bundle *const rec_msg, Eina_Bool with_date)
1225 int result = SVC_RES_FAIL;
1228 if (!app->peer_in_cahtting_data || !app->peer_in_cahtting_data->use_data) {
1229 LOGE("Wrong status, previous chatting data are freed!!!");
1234 char* from_id_str = NULL;
1235 result = bundle_get_str(rec_msg, "from_id", &from_id_str);
1236 int from_id = atoi(from_id_str);
1238 char* to_id_str = NULL;
1239 result = bundle_get_str(rec_msg, "to_id", &to_id_str);
1240 int to_id = atoi(to_id_str);
1242 char* msg_id_str = NULL;
1243 result = bundle_get_str(rec_msg, "message_id", &msg_id_str);
1244 long long message_id = atoll(msg_id_str);
1246 char* type_of_chat_str = NULL;
1247 result = bundle_get_str(rec_msg, "type_of_chat", &type_of_chat_str);
1248 int type_of_chat = atoi(type_of_chat_str);
1250 if (from_id == app->user_id.id) {
1251 // sent by the user. May be from another device.
1254 //load message from the received info.
1255 // get phone number using buddy id.
1257 Eina_Bool is_user_present_in_main_list = EINA_FALSE;
1259 if (type_of_chat == TGL_PEER_USER) {
1260 id_to_check = from_id;
1262 id_to_check = to_id;
1265 if (type_of_chat == TGL_PEER_USER) {
1266 if ((app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE || app->current_app_state == TG_SET_USER_INFO_STATE) &&
1267 app->peer_in_cahtting_data && app->peer_in_cahtting_data->use_data->peer_id == from_id) {
1269 char* date_id_str = NULL;
1270 result = bundle_get_str(rec_msg, "date_id", &date_id_str);
1271 int date_id = atoi(date_id_str);
1272 on_text_message_received_from_buddy(app, date_id, type_of_chat);
1275 on_text_message_received_from_buddy(app, message_id, type_of_chat);
1280 } else if (type_of_chat == TGL_PEER_CHAT) {
1281 if ((app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE || app->current_app_state == TG_SET_CHAT_INFO_STATE) &&
1282 app->peer_in_cahtting_data && app->peer_in_cahtting_data->use_data->peer_id == to_id) {
1283 char* tablename = get_table_name_from_number(to_id);
1284 tg_message_s* msg = get_message_from_message_table(message_id, tablename);
1288 char* date_id_str = NULL;
1289 result = bundle_get_str(rec_msg, "date_id", &date_id_str);
1290 int date_id = atoi(date_id_str);
1291 on_text_message_received_from_buddy(app, date_id, type_of_chat);
1293 on_text_message_received_from_buddy(app, message_id, type_of_chat);
1295 on_text_message_received_from_buddy(app, message_id, type_of_chat);
1299 msg->message = NULL;
1302 if (msg->media_id) {
1303 free(msg->media_id);
1304 msg->media_id = NULL;
1313 Eina_List *l = NULL;
1314 tg_main_list_item_s *sel_item = NULL;
1315 EINA_LIST_FOREACH(app->main_list, l, sel_item) {
1317 if (sel_item->peer_id != id_to_check) {
1321 // update last message
1322 char* tablename = get_table_name_from_number(sel_item->peer_id);
1323 tg_message_s* msg = get_message_from_message_table(message_id, tablename);
1326 if (msg->service == 2) {
1329 msg->message = NULL;
1332 if (msg->media_id) {
1333 free(msg->media_id);
1334 msg->media_id = NULL;
1340 if (msg->service == 1) {
1341 if (msg->message && strlen(msg->message) > 0) {
1342 sel_item->last_message = strdup(msg->message);
1344 sel_item->last_message = strdup(" ");
1348 int media_type = msg->media_type;
1349 if (media_type == tgl_message_media_none) {
1350 if (msg->message && strlen(msg->message) > 0) {
1351 sel_item->last_message = strdup(msg->message);
1353 sel_item->last_message = strdup(" ");
1355 } else if (media_type == tgl_message_media_photo) {
1356 sel_item->last_message = strdup("Image");
1357 } else if (media_type == tgl_message_media_document) {
1360 if (msg->message && strlen(msg->message) > 0) {
1361 sel_item->last_message = strdup(msg->message);
1363 sel_item->last_message = strdup("Document");
1366 tgl_media_s *media_msg = NULL;
1367 media_msg = get_media_details_from_db(atoll(msg->media_id));
1368 sel_item->last_message = strdup(media_msg->doc_type);
1369 free_media_details(media_msg);
1371 } else if (media_type == tgl_message_media_geo) {
1372 sel_item->last_message = strdup("Geo location");
1373 } else if (media_type == tgl_message_media_contact) {
1374 sel_item->last_message = strdup("Contact");
1375 } else if (media_type == tgl_message_media_unsupported) {
1376 sel_item->last_message = strdup(" ");
1377 } else if (media_type == tgl_message_media_photo_encr) {
1378 sel_item->last_message = strdup("Image encrypted");
1379 } else if (media_type == tgl_message_media_document_encr) {
1380 sel_item->last_message = strdup("Document encrypted");
1382 sel_item->last_message = strdup(" ");
1385 sel_item->last_msg_id = msg->msg_id;
1386 sel_item->last_msg_type = msg->media_type;
1387 sel_item->is_out_msg = msg->out;
1388 sel_item->last_msg_status = msg->msg_state;
1389 sel_item->last_seen_time = msg->date;
1390 sel_item->number_of_unread_msgs = get_unread_message_count(tablename);
1392 if (sel_item->profile_pic) {
1396 if (sel_item->user_name_lbl) {
1400 if (sel_item->status_lbl) {
1401 char* org_msg = NULL;
1402 if (sel_item->last_message) {
1403 org_msg = sel_item->last_message;
1407 elm_object_text_set(sel_item->status_lbl, "");
1409 char status_buf[126] = {'\0'};
1412 if (msg->service == 1 || msg->service == 2) {
1413 sel_item->last_msg_service = 1;
1416 sel_item->last_msg_service = 0;
1420 snprintf(status_buf, sizeof(status_buf), "<font=Tizen:style=Bold color=%s align=left><font_size=26>%.*s</font_size></font>", color, 40, org_msg);
1421 elm_object_text_set(sel_item->status_lbl, status_buf);
1424 if (sel_item->date_lbl) {
1425 Eina_Bool is_today = compare_date_with_current_date(sel_item->last_seen_time);
1428 elm_object_text_set(sel_item->date_lbl, "<font=Tizen:style=Normal color=#000000 align=center><font_size=25>Today</font_size></font>");
1432 char time_str[256] = { 0, };
1435 t = sel_item->last_seen_time;
1436 (void)localtime_r(&t, <);
1437 if (strftime(res, sizeof(res), "%d/%b/%Y", <) == 0) {
1438 strcpy(res, "unknown");
1441 snprintf(time_str, sizeof(time_str), "<font=Tizen:style=Normal color=#000000 align=center><font_size=25>%s</font_size></font>", res);
1442 elm_object_text_set(sel_item->date_lbl, time_str);
1445 if (sel_item->msg_status_lbl) {
1446 Evas_Object* temp_lbl = elm_object_part_content_get(sel_item->msg_status_lbl, "swallow.status");
1448 evas_object_del(temp_lbl);
1451 Evas_Object* num_lbl = elm_label_add(app->nf);
1452 elm_object_style_set(num_lbl, "transparent");
1453 char unread_msgs[256];
1454 sprintf(unread_msgs, "<font=Tizen:style=Bold color=#ffffff align=center><font_size=25>%d</font_size></font>", sel_item->number_of_unread_msgs);
1455 elm_object_text_set(num_lbl, unread_msgs);
1456 evas_object_size_hint_weight_set(num_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1457 evas_object_size_hint_align_set(num_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
1458 evas_object_show(num_lbl);
1460 char edj_path[PATH_MAX] = {0, };
1461 app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
1462 Evas_Object* msg_status = elm_layout_add(app->nf);
1463 elm_layout_file_set(msg_status, edj_path, "circle_item");
1464 evas_object_size_hint_weight_set(msg_status, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1465 evas_object_size_hint_align_set(msg_status, EVAS_HINT_FILL, EVAS_HINT_FILL);
1466 evas_object_show(msg_status);
1467 elm_object_part_content_set(msg_status, "content", num_lbl);
1469 elm_object_part_content_set(sel_item->msg_status_lbl, "swallow.status", msg_status);
1474 msg->message = NULL;
1477 if (msg->media_id) {
1478 free(msg->media_id);
1479 msg->media_id = NULL;
1485 is_user_present_in_main_list = EINA_TRUE;
1487 app->main_list = eina_list_remove(app->main_list, sel_item);
1488 app->main_list = eina_list_prepend(app->main_list, sel_item);
1489 refresh_main_list_view(app, EINA_FALSE);
1493 if (!is_user_present_in_main_list) {
1494 peer_with_pic_s *peer_item = get_peer_info(id_to_check);
1496 tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
1498 app->main_list = eina_list_prepend(app->main_list, latest_item);
1499 refresh_main_list_view(app, EINA_TRUE);
1504 if (app->s_app_visible_state == APP_STATE_IN_BACKGROUND ||
1505 app->current_app_state != TG_USER_MAIN_VIEW_STATE)
1506 display_badge_with_notification(get_number_of_unread_messages(), app);
1511 static int on_message_with_date_received_from_buddy(appdata_s *app, bundle *const rec_msg)
1513 return on_message_received_from_buddy(app, rec_msg, EINA_TRUE);
1516 static int on_new_contact_added(appdata_s *app, bundle *const rec_msg)
1518 int result = SVC_RES_FAIL;
1519 char* buddy_id_str = NULL;
1520 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
1521 int buddy_id = atoi(buddy_id_str);
1523 Eina_Bool is_success = EINA_FALSE;
1524 char* is_success_val = NULL;
1525 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
1526 if (strncmp("true", is_success_val, strlen("true")) == 0) {
1527 is_success = EINA_TRUE;
1529 is_success = EINA_FALSE;
1532 load_buddy_list_data(app);
1533 load_peer_data(app);
1535 //show_toast(app, "Failed to add contact. Please try after sometime.");
1537 hide_loading_popup(app);
1538 if (app->current_app_state == TG_ADD_CONTACT_STATE) {
1539 on_new_contact_added_response_received(app, buddy_id, is_success);
1544 static int on_buddy_re_added_to_chat(appdata_s *app, bundle *const rec_msg)
1546 int result = SVC_RES_FAIL;
1547 char* buddy_id_str = NULL;
1548 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
1549 int buddy_id = atoi(buddy_id_str);
1551 Eina_Bool is_success = EINA_FALSE;
1552 char* is_success_val = NULL;
1553 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
1554 if (strncmp("true", is_success_val, strlen("true")) == 0) {
1555 is_success = EINA_TRUE;
1557 is_success = EINA_FALSE;
1560 if (app->current_app_state == TG_SET_USER_INFO_STATE) {
1561 on_user_added_response_received(app, buddy_id, is_success);
1563 hide_loading_popup(app);
1567 static int on_buddy_deleted_from_friends_list(appdata_s *ad, bundle *const rec_msg)
1569 int result = SVC_RES_FAIL;
1570 char* buddy_id_str = NULL;
1571 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
1572 int buddy_id = atoi(buddy_id_str);
1574 Eina_Bool is_success = EINA_FALSE;
1575 char* is_success_val = NULL;
1576 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
1577 if (strncmp("true", is_success_val, strlen("true")) == 0) {
1578 is_success = EINA_TRUE;
1580 is_success = EINA_FALSE;
1583 if (is_success && ad->current_app_state == TG_SET_USER_INFO_STATE) {
1584 //on_user_deleted_response_received(app, buddy_id, is_success);
1585 show_loading_popup(ad);
1586 elm_naviframe_item_pop(ad->nf);
1587 ad->current_app_state = TG_CHAT_MESSAGING_VIEW_STATE;
1588 ad->peer_in_cahtting_data = NULL;
1589 ad->main_item_in_cahtting_data = NULL;
1590 ad->buddy_in_cahtting_data = NULL;
1591 elm_naviframe_item_pop(ad->nf);
1592 load_registered_user_data(ad);
1593 load_buddy_list_data(ad);
1594 load_unknown_buddy_list_data(ad);
1596 load_main_list_data(ad);
1599 Eina_List *l = NULL;
1600 tg_main_list_item_s* main_list_item = NULL;
1601 EINA_LIST_FOREACH(ad->main_list, l, main_list_item) {
1602 if (main_list_item && main_list_item->peer_id == buddy_id) {
1603 ad->main_list = eina_list_remove(ad->main_list, main_list_item);
1604 ad->main_list = eina_list_prepend(ad->main_list, main_list_item);
1609 ecore_timer_add(1, on_load_main_view_requested, ad);
1611 hide_loading_popup(ad);
1616 static int on_buddy_blocked(appdata_s *app, bundle *const rec_msg)
1618 int result = SVC_RES_FAIL;
1620 char* buddy_id_str = NULL;
1621 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
1622 int buddy_id = atoi(buddy_id_str);
1624 Eina_Bool is_success = EINA_FALSE;
1625 char* is_success_val = NULL;
1626 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
1627 if (strncmp("true", is_success_val, strlen("true")) == 0) {
1628 is_success = EINA_TRUE;
1630 is_success = EINA_FALSE;
1633 if (app->current_app_state == TG_SET_USER_INFO_STATE) {
1634 on_user_block_response_received(app, buddy_id, is_success);
1636 hide_loading_popup(app);
1641 static int on_buddy_unblocked(appdata_s *app, bundle *const rec_msg)
1643 int result = SVC_RES_FAIL;
1645 char* buddy_id_str = NULL;
1646 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
1647 int buddy_id = atoi(buddy_id_str);
1649 Eina_Bool is_success = EINA_FALSE;
1650 char* is_success_val = NULL;
1651 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
1652 if (strncmp("true", is_success_val, strlen("true")) == 0) {
1653 is_success = EINA_TRUE;
1655 is_success = EINA_FALSE;
1658 if (app->current_app_state == TG_SET_USER_INFO_STATE) {
1659 on_user_unblock_response_received(app, buddy_id, is_success);
1661 hide_loading_popup(app);
1666 static int on_delete_selected_group_chats(appdata_s *ad, bundle *const rec_msg)
1668 int result = SVC_RES_OK;
1670 if (app->current_app_state == TG_USER_MAIN_VIEW_SELECTION_STATE) {
1671 elm_naviframe_item_pop(app->nf);
1672 app->current_app_state = TG_USER_MAIN_VIEW_STATE;
1673 show_floating_button(app);
1674 load_buddy_list_data(app);
1675 load_unknown_buddy_list_data(app);
1676 load_peer_data(app);
1677 load_main_list_data(app);
1678 refresh_main_list_view(app, EINA_FALSE);
1680 hide_loading_popup(app);
1682 load_registered_user_data(ad);
1683 load_buddy_list_data(ad);
1684 load_unknown_buddy_list_data(ad);
1686 load_main_list_data(ad);
1687 if (ad->main_item) {
1688 elm_naviframe_item_pop_to(ad->main_item);
1690 ecore_timer_add(1, on_load_main_view_requested, ad);
1695 static int on_group_chat_deleted_response(appdata_s *app, bundle *const rec_msg)
1697 int result = SVC_RES_FAIL;
1699 char* chat_id_str = NULL;
1700 result = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
1701 int chat_id = atoi(chat_id_str);
1703 Eina_Bool is_success = EINA_FALSE;
1704 char* is_success_val = NULL;
1705 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
1706 if (strncmp("true", is_success_val, strlen("true")) == 0) {
1707 is_success = EINA_TRUE;
1709 is_success = EINA_FALSE;
1713 Eina_List *l = NULL;
1714 peer_with_pic_s *pitem = NULL;
1715 EINA_LIST_FOREACH(app->peer_list, l, pitem) {
1719 if (pitem->use_data->peer_id == chat_id) {
1720 app->peer_list = eina_list_remove(app->peer_list, pitem);
1726 tg_main_list_item_s *item = NULL;
1727 EINA_LIST_FOREACH(app->main_list, l, item) {
1728 if (item->peer_id == chat_id) {
1729 app->main_list = eina_list_remove(app->main_list, item);
1734 refresh_main_list_view(app, EINA_FALSE);
1736 if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->peer_in_cahtting_data
1737 && app->peer_in_cahtting_data->use_data->peer_id == chat_id) {
1739 app->peer_in_cahtting_data = NULL;
1740 app->main_item_in_cahtting_data = NULL;
1742 elm_naviframe_item_pop(app->nf);
1743 app->current_app_state = TG_USER_MAIN_VIEW_STATE;
1744 show_floating_button(app);
1747 if (app->current_app_state == TG_SET_CHAT_INFO_STATE && app->peer_in_cahtting_data
1748 && app->peer_in_cahtting_data->use_data->peer_id == chat_id) {
1749 on_group_chat_deleted(app, chat_id);
1753 show_toast(app, "Failed to delete chat");
1755 hide_loading_popup(app);
1760 static int on_message_sent_to_buddy(appdata_s *app, bundle *const rec_msg)
1762 int result = SVC_RES_FAIL;
1764 char* buddy_id_str = NULL;
1765 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
1766 int buddy_id = atoi(buddy_id_str);
1768 char* msg_id_str = NULL;
1769 result = bundle_get_str(rec_msg, "message_id", &msg_id_str);
1770 int message_id = atoi(msg_id_str);
1772 char* table_name = NULL;
1773 result = bundle_get_str(rec_msg, "table_name", &table_name);
1776 Eina_Bool is_success = EINA_FALSE;
1777 char* is_success_val = NULL;
1778 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
1779 if (strncmp("true", is_success_val, strlen("true")) == 0) {
1780 is_success = EINA_TRUE;
1782 is_success = EINA_FALSE;
1783 show_toast(app, "message sent failed");
1786 char* type_of_chat_str = NULL;
1787 result = bundle_get_str(rec_msg, "type_of_chat", &type_of_chat_str);
1788 int type_of_chat = atoi(type_of_chat_str);
1790 tg_message_s* msg = get_message_from_message_table(message_id, table_name);
1793 if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->peer_in_cahtting_data && app->peer_in_cahtting_data->use_data->peer_id == buddy_id) {
1794 // update message to sent state
1795 on_text_message_state_changed(app, msg, type_of_chat);
1798 if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
1799 Eina_List *l = NULL;
1800 tg_main_list_item_s *sel_item = NULL;
1801 EINA_LIST_FOREACH(app->main_list, l, sel_item) {
1802 if (sel_item->peer_id == buddy_id && sel_item->last_msg_id == message_id) {
1803 if (sel_item->msg_status_lbl) {
1804 elm_image_file_set(sel_item->msg_status_lbl, ui_utils_get_resource(MESSAGE_SENT_ICON), NULL);
1813 msg->message = NULL;
1816 if (msg->media_id) {
1817 free(msg->media_id);
1818 msg->media_id = NULL;
1825 static int on_self_profile_pic_updated(appdata_s *app, bundle *const rec_msg)
1827 int result = SVC_RES_FAIL;
1828 Eina_Bool is_success = EINA_FALSE;
1829 char *is_success_val = NULL;
1830 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
1831 if (strncmp("true", is_success_val, strlen("true")) == 0) {
1832 is_success = EINA_TRUE;
1833 show_toast(app, "profile picture updated successfully.");
1835 is_success = EINA_FALSE;
1836 show_toast(app, "profile picture not updated.");
1840 char *file_path = NULL;
1841 result = bundle_get_str(rec_msg, "file_path", &file_path);
1843 if (app->current_user_data->photo_path) {
1844 free(app->current_user_data->photo_path);
1845 app->current_user_data->photo_path = NULL;
1848 app->current_user_data->photo_path = strdup(file_path);
1849 Evas_Object* profile_pic = evas_object_data_get(app->nf, "main_user_profile_pic");
1851 elm_image_file_set(profile_pic, file_path, NULL);
1854 if (app->current_app_state == TG_SETTINGS_SCREEN_STATE) {
1855 Evas_Object* set_pro_pic = evas_object_data_get(app->nf, "settings_user_profile_pic");
1857 elm_image_file_set(set_pro_pic, file_path, NULL);
1861 hide_loading_popup(app);
1865 static int on_self_profile_name_updated(appdata_s *app, bundle *const rec_msg)
1867 int result = SVC_RES_FAIL;
1868 Eina_Bool is_success = EINA_FALSE;
1869 char *is_success_val = NULL;
1870 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
1871 if (strncmp("true", is_success_val, strlen("true")) == 0) {
1872 is_success = EINA_TRUE;
1873 show_toast(app, "Username updated successfully.");
1875 is_success = EINA_FALSE;
1876 show_toast(app, "Username not updated. Username already exist or please check your network connection.");
1881 char *first_name = NULL;
1882 result = bundle_get_str(rec_msg, "first_name", &first_name);
1887 char *last_name = NULL;
1888 result = bundle_get_str(rec_msg, "last_name", &last_name);
1893 if (app->current_user_data->first_name) {
1894 free(app->current_user_data->first_name);
1895 app->current_user_data->first_name = NULL;
1898 if (app->current_user_data->last_name) {
1899 free(app->current_user_data->last_name);
1900 app->current_user_data->last_name = NULL;
1904 app->current_user_data->first_name = strdup(first_name);
1908 app->current_user_data->last_name = strdup(last_name);
1911 if (app->current_app_state == TG_SETTINGS_EDIT_NAME_STATE) {
1912 elm_naviframe_item_pop(app->nf);
1913 app->current_app_state = TG_SETTINGS_SCREEN_STATE;
1914 refresh_settings_screen(app);
1920 hide_loading_popup(app);
1924 static int on_self_username_updated(appdata_s *app, bundle *const rec_msg)
1926 int result = SVC_RES_FAIL;
1927 Eina_Bool is_success = EINA_FALSE;
1928 char *is_success_val = NULL;
1929 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
1930 if (strncmp("true", is_success_val, strlen("true")) == 0) {
1931 is_success = EINA_TRUE;
1932 show_toast(app, "Username updated successfully.");
1934 is_success = EINA_FALSE;
1935 show_toast(app, "Username not updated. Username already exist or please check your network connection.");
1939 char *username = NULL;
1940 result = bundle_get_str(rec_msg, "username", &username);
1942 if (app->current_user_data->username) {
1943 free(app->current_user_data->username);
1944 app->current_user_data->username = NULL;
1947 app->current_user_data->username = strdup(username);
1950 if (app->current_app_state == TG_SETTINGS_SCREEN_STATE || app->current_app_state == TG_SET_USERNAME_STATE) {
1951 Evas_Object *name_lbl = evas_object_data_get(app->nf, "settings_user_name_label");
1953 char buf[512] = {'\0'};
1954 snprintf(buf, 512, "<font=Tizen:style=Bold color=#000000 align=left><font_size=40>%s</font_size></font>", app->current_user_data->username);
1955 elm_object_text_set(name_lbl, buf);
1958 if (app->current_app_state == TG_SET_USERNAME_STATE) {
1959 elm_naviframe_item_pop(app->nf);
1960 app->current_app_state = TG_SETTINGS_SCREEN_STATE;
1963 hide_loading_popup(app);
1968 static int on_message_read_by_buddy(appdata_s *app, bundle *const rec_msg)
1970 int result = SVC_RES_FAIL;
1971 char* buddy_id_str = NULL;
1972 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
1973 int buddy_id = atoi(buddy_id_str);
1975 char* msg_id_str = NULL;
1976 result = bundle_get_str(rec_msg, "message_id", &msg_id_str);
1977 int message_id = atoi(msg_id_str);
1979 char* table_name = NULL;
1980 result = bundle_get_str(rec_msg, "table_name", &table_name);
1982 char* phone_number = NULL;
1983 result = bundle_get_str(rec_msg, "phone_number", &phone_number);
1985 char* type_of_chat_str = NULL;
1986 result = bundle_get_str(rec_msg, "type_of_chat", &type_of_chat_str);
1987 int type_of_chat = atoi(type_of_chat_str);
1989 tg_message_s* msg = get_message_from_message_table(message_id, table_name);
1992 if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->peer_in_cahtting_data && app->peer_in_cahtting_data->use_data->peer_id == buddy_id) {
1993 // update message to sent state
1994 on_text_message_state_changed(app, msg, type_of_chat);
1997 if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
1999 Eina_List *l = NULL;
2000 tg_main_list_item_s *sel_item = NULL;
2001 EINA_LIST_FOREACH(app->main_list, l, sel_item) {
2003 if (sel_item->peer_id == buddy_id && sel_item->last_msg_id == message_id) {
2005 if (sel_item->msg_status_lbl) {
2006 elm_image_file_set(sel_item->msg_status_lbl, ui_utils_get_resource(MESSAGE_READ_ICON), NULL);
2016 msg->message = NULL;
2019 if (msg->media_id) {
2020 free(msg->media_id);
2021 msg->media_id = NULL;
2029 static int on_media_message_download_completed(appdata_s *app, bundle *const rec_msg)
2031 LOGE("Media download14");
2032 int result = SVC_RES_FAIL;
2033 char* buddy_id_str = NULL;
2034 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
2035 int buddy_id = atoi(buddy_id_str);
2037 char* to_id_str = NULL;
2038 result = bundle_get_str(rec_msg, "to_peer_id", &to_id_str);
2039 int to_id = atoi(to_id_str);
2041 char* media_id_str = NULL;
2042 result = bundle_get_str(rec_msg, "media_id", &media_id_str);
2043 long long media_id = atoll(media_id_str);
2045 char* file_name = NULL;
2046 result = bundle_get_str(rec_msg, "file_name", &file_name);
2048 //file_name == "failed_to_load"
2050 if (file_name && strstr(file_name, "failed_to_load") != NULL) {
2052 show_toast(app, "media download failed.");
2055 char* caption = NULL;
2056 result = bundle_get_str(rec_msg, "caption", &caption);
2059 if (file_name && app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->peer_in_cahtting_data
2060 && app->peer_in_cahtting_data->use_data->peer_id == to_id) {
2061 // update media to sent state
2062 LOGE("Media download15");
2063 on_media_download_completed(app, buddy_id, media_id, file_name, caption);
2065 LOGE("Media download16");
2069 static int on_video_message_thumb_download_completed(appdata_s *app, bundle *const rec_msg)
2071 int result = SVC_RES_FAIL;
2072 char* buddy_id_str = NULL;
2073 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
2074 int buddy_id = atoi(buddy_id_str);
2076 char* to_id_str = NULL;
2077 result = bundle_get_str(rec_msg, "to_peer_id", &to_id_str);
2078 int to_id = atoi(to_id_str);
2080 char* media_id_str = NULL;
2081 result = bundle_get_str(rec_msg, "media_id", &media_id_str);
2082 long long media_id = atoll(media_id_str);
2084 char* file_name = NULL;
2085 result = bundle_get_str(rec_msg, "file_name", &file_name);
2087 char* caption = NULL;
2088 result = bundle_get_str(rec_msg, "caption", &caption);
2090 if (file_name && app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->peer_in_cahtting_data
2091 && app->peer_in_cahtting_data->use_data->peer_id == to_id) {
2092 // update thumbnail icon
2093 on_video_thumb_download_completed(app, buddy_id, media_id, file_name, caption);
2098 static int on_new_buddy_added_to_contacts(appdata_s *app, bundle *const rec_msg)
2100 int result = SVC_RES_FAIL;
2101 char* buddy_id_str = NULL;
2102 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
2104 int buddy_id = atoi(buddy_id_str);
2105 peer_with_pic_s *peer_item = get_peer_info(buddy_id);
2106 tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
2108 app->main_list = eina_list_prepend(app->main_list, latest_item);
2109 refresh_main_list_view(app, EINA_TRUE);
2111 hide_loading_popup(app);
2116 static int on_new_group_added(appdata_s *app, bundle *const rec_msg)
2118 int result = SVC_RES_FAIL;
2122 char* chat_id_str = NULL;
2123 result = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
2125 int chat_id = atoi(chat_id_str);
2126 peer_with_pic_s *peer_item = get_peer_info(chat_id);
2127 if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
2128 tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
2130 app->main_list = eina_list_prepend(app->main_list, latest_item);
2131 hide_loading_popup(app);
2132 refresh_main_list_view(app, EINA_FALSE);
2136 hide_loading_popup(app);
2137 if (app->main_item) {
2138 elm_naviframe_item_pop_to(app->main_item);
2139 app->current_app_state = TG_USER_MAIN_VIEW_STATE;
2142 tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
2144 app->main_list = eina_list_prepend(app->main_list, latest_item);
2145 refresh_main_list_view(app, EINA_FALSE);
2149 app->peer_list = eina_list_prepend(app->peer_list, peer_item);
2151 load_registered_user_data(app);
2152 load_buddy_list_data(app);
2153 load_unknown_buddy_list_data(app);
2154 load_peer_data(app);
2155 load_main_list_data(app);
2157 if (app->main_item) {
2158 elm_naviframe_item_pop_to(app->main_item);
2161 ecore_timer_add(1, on_load_main_view_requested, app);
2166 static int on_buddy_contact_updated(appdata_s *app, bundle *const rec_msg)
2168 int result = SVC_RES_FAIL;
2169 char* buddy_id_str = NULL;
2170 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
2171 //int buddy_id = atoi(buddy_id_str);
2173 char* update_msg = NULL;
2174 result = bundle_get_str(rec_msg, "update_message", &update_msg);
2181 static int on_buddy_status_updated(appdata_s *app, bundle *const rec_msg)
2183 int result = SVC_RES_FAIL;
2184 char* buddy_id_str = NULL;
2185 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
2186 int buddy_id = atoi(buddy_id_str);
2187 // update to online or last seen, if current view is conversation.
2190 if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->buddy_in_cahtting_data && app->buddy_in_cahtting_data->use_data->user_id.id == buddy_id) {
2191 on_user_presence_state_changed(app, buddy_id);
2196 static int on_typing_status_updated(appdata_s *app, bundle *const rec_msg)
2198 int result = SVC_RES_FAIL;
2199 char* buddy_id_str = NULL;
2200 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
2201 int buddy_id = atoi(buddy_id_str);
2203 char* buddy_name = NULL;
2204 result = bundle_get_str(rec_msg, "buddy_name", &buddy_name);
2206 const char *type_status_str;
2208 result = bundle_get_str(rec_msg, "type_status", &type_status_str);
2209 enum tgl_typing_status type_status = atoi(type_status_str);
2212 char* type_status_message = NULL;
2214 switch (type_status) {
2215 case tgl_typing_none:
2216 type_status_message = "doing nothing";
2218 case tgl_typing_typing:
2219 type_status_message = "typing...";
2221 case tgl_typing_cancel:
2222 type_status_message = "deleting typed message";
2224 case tgl_typing_record_video:
2225 type_status_message = "recording video";
2227 case tgl_typing_upload_video:
2228 type_status_message = "uploading video";
2230 case tgl_typing_record_audio:
2231 type_status_message = "recording audio";
2233 case tgl_typing_upload_audio:
2234 type_status_message = "uploading audio";
2236 case tgl_typing_upload_photo:
2237 type_status_message = "uploading photo";
2239 case tgl_typing_upload_document:
2240 type_status_message = "uploading document";
2242 case tgl_typing_geo:
2243 type_status_message = "choosing location";
2245 case tgl_typing_choose_contact:
2246 type_status_message = "choosing contact";
2249 type_status_message = "";
2253 // update UI. may be contacts view or conversation view.
2254 if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
2255 Eina_List *l = NULL;
2256 tg_main_list_item_s *sel_item = NULL;
2257 EINA_LIST_FOREACH(app->main_list, l, sel_item) {
2258 if (sel_item->peer_id != buddy_id) {
2261 // update last message
2263 if (sel_item->profile_pic) {
2267 if (sel_item->user_name_lbl) {
2271 if (sel_item->status_lbl) {
2272 char status_buf[512] = {'\0'};
2273 snprintf(status_buf, sizeof(status_buf), "<font=Tizen:style=Bold color=#158CB0 align=left><font_size=30>%.*s</font_size></font>", 25, type_status_message);
2274 elm_object_text_set(sel_item->status_lbl, status_buf);
2277 if (sel_item->date_lbl) {
2280 if (sel_item->msg_status_lbl) {
2288 if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->buddy_in_cahtting_data && app->buddy_in_cahtting_data->use_data->user_id.id == buddy_id) {
2289 on_user_status_changed(app, type_status_message);
2296 static int on_user_status_updated(appdata_s *app, bundle *const rec_msg)
2298 int result = SVC_RES_FAIL;
2299 char* buddy_id_str = NULL;
2300 result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
2301 int buddy_id = atoi(buddy_id_str);
2303 char* buddy_name = NULL;
2304 result = bundle_get_str(rec_msg, "buddy_name", &buddy_name);
2306 if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
2307 Eina_List *l = NULL;
2308 tg_main_list_item_s *sel_item = NULL;
2309 EINA_LIST_FOREACH(app->main_list, l, sel_item) {
2310 if (sel_item->peer_id != buddy_id) {
2313 // update last message
2315 if (sel_item->profile_pic) {
2319 if (sel_item->user_name_lbl) {
2323 if (sel_item->status_lbl) {
2324 char status_buf[126] = {'\0'};
2325 snprintf(status_buf, sizeof(status_buf), "<font=Tizen:style=Normal color=#A4A4A4 align=left><font_size=26>%.*s</font_size></font>", 29, sel_item->last_message ? sel_item->last_message : "");
2326 elm_object_text_set(sel_item->status_lbl, status_buf);
2329 if (sel_item->date_lbl) {
2332 if (sel_item->msg_status_lbl) {
2339 if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->buddy_in_cahtting_data && app->buddy_in_cahtting_data->use_data->user_id.id == buddy_id) {
2340 on_user_presence_state_changed(app, buddy_id);
2346 Eina_Bool on_logout_completed(void *data)
2348 appdata_s *ad = data;
2350 elm_naviframe_item_pop(ad->nf);
2351 ad->current_app_state = TG_REGISTRATION_STATE;
2352 launch_init_screen(ad);
2354 return ECORE_CALLBACK_CANCEL;
2357 Eina_Bool on_start_server_requested(void *data)
2359 appdata_s *ad = data;
2361 launch_tg_server(ad);
2363 return ECORE_CALLBACK_CANCEL;
2367 static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg)
2369 int result = SVC_RES_FAIL;
2370 RETVM_IF(!data, result, "Data is NULL");
2371 appdata_s *app = data;
2372 char *rec_key_val = NULL;
2375 result = bundle_get_str(rec_msg, "command", &rec_key_val);
2377 LOGI("MSG recv = %s", rec_key_val);
2379 if (strcmp(rec_key_val, "server_not_initialized") == 0) {
2380 hide_loading_popup(app);
2382 } else if (strcmp(rec_key_val, "server_restart_notification") == 0) {
2383 hide_loading_popup(app);
2384 if (!app->is_waiting_for_phone_num)
2385 show_toast(app, "Network error. Please try again");
2387 ecore_timer_add(1, on_start_server_requested, app);
2388 } else if (strcmp(rec_key_val, "registration_done") == 0) {
2390 char* is_success_val = NULL;
2391 result = bundle_get_str(rec_msg, "is_success", &is_success_val);
2392 if (app->login_timer)
2393 ecore_timer_del(app->login_timer);
2394 app->login_timer = NULL;
2396 if (strncmp("true", is_success_val, strlen("true")) == 0) {
2397 //show_toast(app, is_success_val);
2398 // Launch login view
2399 //elm_naviframe_item_pop(app->nf);
2400 launch_login_cb(data);
2403 show_toast(app, "Error: registration");
2405 hide_loading_popup(app);
2407 } else if (strcmp(rec_key_val, "name_registration_request") == 0) {
2409 elm_naviframe_item_pop(app->nf);
2410 elm_naviframe_item_pop(app->nf);
2411 launch_first_registration_cb(app);
2412 hide_loading_popup(app);
2414 } else if (strcmp(rec_key_val, "request_reg_code_again") == 0) {
2415 show_toast(app, "Please enter a valid code.");
2416 hide_loading_popup(app);
2417 } else if (strcmp(rec_key_val, "request_phone_num_again") == 0) {
2418 show_toast(app, "Please enter a valid phone number.");
2419 hide_loading_popup(app);
2420 } else if (strcmp(rec_key_val, "request_phone_new_num") == 0) {
2421 app->is_waiting_for_phone_num = EINA_TRUE;
2422 } else if (strcmp(rec_key_val, "server_connection_failed") == 0) {
2423 show_toast(app, "Server connection failed. please check network connection");
2424 hide_loading_popup(app);
2425 } else if (strcmp(rec_key_val, "logout_completed") == 0) {
2427 free_app_data(app, EINA_TRUE);
2428 hide_loading_popup(app);
2429 app->phone_number = NULL;
2430 app->buddy_list = NULL;
2431 app->unknown_buddy_list = NULL;
2432 app->known_buddy_list = NULL;
2433 app->main_list = NULL;
2434 app->peer_list = NULL;
2435 app->search_peer_list = NULL;
2436 app->is_first_time_registration = EINA_FALSE;
2438 app->loaded_msg_list = NULL;
2439 app->loading_popup = NULL;
2440 app->current_user_data = NULL;
2441 app->is_tg_initilized = EINA_FALSE;
2442 app->chat_background = NULL;
2443 app->msg_popup = NULL;
2444 app->s_notififcation = NULL;
2446 app->is_server_ready = EINA_FALSE;
2447 app->is_waiting_for_phone_num = EINA_FALSE;
2448 app->login_timer = NULL;
2449 app->contact_list = NULL;
2451 char *chat_bg = NULL;
2452 preference_get_string(TG_CHAT_BG_PREFERENCE, &chat_bg);
2454 app->chat_background = strdup(chat_bg);
2457 if (!app->chat_background) {
2458 app->chat_background = strdup(ui_utils_get_resource(TG_CHAT_DEFAULT_BG));
2459 preference_set_string(TG_CHAT_BG_PREFERENCE, app->chat_background);
2464 elm_naviframe_item_pop(app->nf);
2465 //ecore_timer_add(1, on_logout_completed, app);
2466 elm_naviframe_item_pop(app->nf);
2467 app->current_app_state = TG_REGISTRATION_STATE;
2468 launch_init_screen(app);
2470 } else if (strcmp(rec_key_val, "server_connection_status") == 0) {
2471 return on_server_connection_status_changed(data, rec_msg);
2474 if (strcmp(rec_key_val, "contacts_and_chats_load_done") == 0) {
2475 app->is_tg_initilized = EINA_TRUE;
2477 if (!app->is_tg_initilized) {
2481 if (strcmp(rec_key_val, "contacts_load_done") == 0) {
2483 return on_contacts_loaded(data, rec_msg);
2485 } else if (strcmp(rec_key_val, "contacts_and_chats_load_done") == 0) {
2487 return on_contacts_and_chats_loaded(data, rec_msg);
2489 } else if (strcmp(rec_key_val, "response_group_chat_updated") == 0) {
2491 return on_group_chat_updated(data, rec_msg);
2493 } else if (strcmp(rec_key_val, "group_chat_updated") == 0) {
2495 return on_group_chat_info_changed_response(data, rec_msg);
2497 } else if ((strcmp(rec_key_val, "group_chat_new_buddy_added_response") == 0) || (strcmp(rec_key_val, "group_chat_buddy_deleted_response") == 0)) {
2499 return on_new_buddy_added_or_deleted_from_group_chat(data, rec_msg, rec_key_val);
2501 } else if (strcmp(rec_key_val, "group_chat_rename_response") == 0) {
2503 return on_group_chat_name_changed(data, rec_msg);
2505 } else if (strcmp(rec_key_val, "buddy_profile_pic_updated") == 0) {
2507 return on_buddy_profile_pic_updated(data, rec_msg);
2509 } else if (strcmp(rec_key_val, "message_received") == 0) {
2511 return on_message_received_from_buddy(data, rec_msg, EINA_FALSE);
2513 } else if (strcmp(rec_key_val, "message_received_with_date") == 0) {
2515 return on_message_with_date_received_from_buddy(data, rec_msg);
2517 } else if (strcmp(rec_key_val, "buddy_readded") == 0) {
2519 return on_buddy_re_added_to_chat(data, rec_msg);
2521 } else if (strcmp(rec_key_val, "new_contact_added") == 0) {
2523 return on_new_contact_added(data, rec_msg);
2525 } else if (strcmp(rec_key_val, "buddy_deleted") == 0) {
2527 return on_buddy_deleted_from_friends_list(data, rec_msg);
2529 } else if (strcmp(rec_key_val, "buddy_blocked") == 0) {
2531 return on_buddy_blocked(data, rec_msg);
2533 } else if (strcmp(rec_key_val, "buddy_unblocked") == 0) {
2535 return on_buddy_unblocked(data, rec_msg);
2537 } else if (strcmp(rec_key_val, "selected_group_chats_deleted_response") == 0) {
2539 return on_delete_selected_group_chats(data, rec_msg);
2541 } else if (strcmp(rec_key_val, "group_chat_deleted_response") == 0) {
2543 return on_group_chat_deleted_response(data, rec_msg);
2545 } else if (strcmp(rec_key_val, "message_sent_to_buddy") == 0) {
2547 return on_message_sent_to_buddy(data, rec_msg);
2549 } else if (strcmp(rec_key_val, "self_profile_picture_updated") == 0) {
2551 return on_self_profile_pic_updated(data, rec_msg);
2553 } else if (strcmp(rec_key_val, "self_profile_name_updated") == 0) {
2555 return on_self_profile_name_updated(data, rec_msg);
2557 } else if (strcmp(rec_key_val, "self_username_updated") == 0) {
2559 return on_self_username_updated(data, rec_msg);
2561 } else if (strcmp(rec_key_val, "message_read_by_buddy") == 0) {
2563 return on_message_read_by_buddy(data, rec_msg);
2565 } else if (strcmp(rec_key_val, "media_download_completed") == 0) {
2567 return on_media_message_download_completed(data, rec_msg);
2569 } else if (strcmp(rec_key_val, "video_thumb_download_completed") == 0) {
2571 return on_video_message_thumb_download_completed(data, rec_msg);
2573 } else if (strcmp(rec_key_val, "add_contacts_request") == 0) {
2574 // Not to be handled.
2575 } else if (strcmp(rec_key_val, "new_buddy_added") == 0) {
2577 return on_new_buddy_added_to_contacts(data, rec_msg);
2579 } else if (strcmp(rec_key_val, "new_group_added") == 0) {
2581 return on_new_group_added(data, rec_msg);
2583 } else if (strcmp(rec_key_val, "contact_updated") == 0) {
2585 return on_buddy_contact_updated(data, rec_msg);
2587 } else if (strcmp(rec_key_val, "buddy_status_updated") == 0) {
2589 return on_buddy_status_updated(data, rec_msg);
2591 } else if (strcmp(rec_key_val, "type_status_updated") == 0) {
2593 return on_typing_status_updated(data, rec_msg);
2595 } else if (strcmp(rec_key_val, "user_status_updated") == 0) {
2597 return on_user_status_updated(data, rec_msg);
2606 int init_service(appdata_s *app)
2608 int result = SVC_RES_FAIL;
2609 RETVM_IF(!app, result, "Application data is NULL");
2611 app->service_client = service_client_create();
2612 RETVM_IF(!app->service_client, result, "Failed to create service client");
2614 result = service_client_register_port(app->service_client, TELEGRAM_CLIENT_PORT_NAME);
2615 if (result != SVC_RES_OK) {
2616 ERR("Failed to register service client port");
2617 service_client_destroy(app->service_client);
2618 app->service_client = NULL;
2622 result = _service_client_set_remote_data(app->service_client, TELEGRAM_SERVER_APP_NAME, TELEGRAM_SERVER_PORT_NAME);
2624 result = service_client_register_msg_receive_callback(app->service_client, _on_service_client_msg_received_cb, app);
2625 if (result != SVC_RES_OK) {
2626 ERR("Failed to register service client on message receive callback");
2627 service_client_destroy(app->service_client);
2628 app->service_client = NULL;
2634 void win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
2640 tg_main_list_item_s* get_latest_item(appdata_s *ad, peer_with_pic_s *item)
2642 tg_main_list_item_s* main_list_item = NULL;
2646 tg_peer_info_s* peer_info = item->use_data;
2650 // get message from message table.
2652 char* tablename = get_table_name_from_number(peer_info->peer_id);
2653 tg_message_s* msg = get_latest_message_from_message_table(tablename, EINA_FALSE);
2658 if (msg->message && strlen(msg->message) > 0) {
2659 item->last_message = strdup(msg->message);
2661 item->last_message = strdup(" ");
2665 int media_type = msg->media_type;
2666 if (media_type == tgl_message_media_none) {
2667 if (msg->message && strlen(msg->message) > 0) {
2668 item->last_message = strdup(msg->message);
2670 item->last_message = strdup(" ");
2672 } else if (media_type == tgl_message_media_photo) {
2673 item->last_message = strdup("Image");
2674 } else if (media_type == tgl_message_media_document) {
2675 tgl_media_s *media_msg = NULL;
2676 media_msg = get_media_details_from_db(atoll(msg->media_id));
2678 if (media_msg && media_msg->doc_type) {
2679 if (strlen(media_msg->doc_type) > 0) {
2680 item->last_message = strdup(media_msg->doc_type);
2682 item->last_message = strdup("Document");
2684 free_media_details(media_msg);
2686 if (msg->message && strlen(msg->message) > 0) {
2687 item->last_message = strdup(msg->message);
2689 item->last_message = strdup("Document");
2693 } else if (media_type == tgl_message_media_geo) {
2694 item->last_message = strdup("Geo location");
2695 } else if (media_type == tgl_message_media_contact) {
2696 item->last_message = strdup("Contact");
2697 } else if (media_type == tgl_message_media_unsupported) {
2698 item->last_message = strdup(" ");
2699 } else if (media_type == tgl_message_media_photo_encr) {
2700 item->last_message = strdup("Image encrypted");
2701 } else if (media_type == tgl_message_media_document_encr) {
2702 item->last_message = strdup("Document encrypted");
2704 item->last_message = strdup(" ");
2708 main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s));
2709 memset(main_list_item, 0, sizeof(tg_main_list_item_s));
2710 main_list_item->peer_id = peer_info->peer_id;
2711 main_list_item->peer_type = peer_info->peer_type;
2713 set_peer_names(peer_info, main_list_item);
2715 main_list_item->last_seen_time = msg->date;
2716 main_list_item->last_msg_id = msg->msg_id;
2717 main_list_item->last_message = strdup(item->last_message);
2718 main_list_item->last_msg_type = msg->media_type;
2719 main_list_item->is_out_msg = msg->out;
2720 main_list_item->last_msg_status = msg->msg_state;
2721 main_list_item->last_msg_service = msg->service;
2722 main_list_item->number_of_unread_msgs = get_unread_message_count(tablename);
2724 if (peer_info->photo_path)
2725 main_list_item->profile_pic_path = strdup(peer_info->photo_path);
2727 // delete message object
2730 msg->message = NULL;
2733 if (msg->media_id) {
2734 free(msg->media_id);
2735 msg->media_id = NULL;
2742 item->last_message = strdup(" ");
2743 if (peer_info->peer_type == TGL_PEER_CHAT) {
2744 main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s));
2745 memset(main_list_item, 0, sizeof(tg_main_list_item_s));
2746 main_list_item->peer_id = peer_info->peer_id;
2747 main_list_item->peer_type = peer_info->peer_type;
2749 set_peer_names(peer_info, main_list_item);
2751 main_list_item->last_seen_time = peer_info->last_seen_time;
2752 main_list_item->last_message = strdup(item->last_message);
2753 main_list_item->last_msg_type = -1;
2754 main_list_item->last_msg_service = 0;
2755 main_list_item->is_out_msg = -1;
2756 main_list_item->last_msg_id = -1;
2757 main_list_item->last_msg_status = -1;
2758 main_list_item->number_of_unread_msgs = 0;
2760 if (peer_info->photo_path && strlen(peer_info->photo_path) > 0)
2761 main_list_item->profile_pic_path = strdup(peer_info->photo_path);
2772 return main_list_item;
2775 void app_nf_back_cb(void *data, Evas_Object *obj, void *event_info)
2777 appdata_s *ad = data;
2778 if (ad->loading_popup) {
2779 show_toast(ad, "Please wait. request in progress");
2783 switch (ad->current_app_state) {
2784 case TG_INIT_SCREEN_STATE:
2785 elm_win_lower(ad->win);
2788 case TG_USER_MAIN_VIEW_STATE:
2789 if (!ad->menu_popup) {
2790 elm_win_lower(ad->win);
2794 case TG_CHAT_MESSAGING_VIEW_STATE:
2796 if (ad->main_item_in_cahtting_data) {
2797 int buddy_id = ad->main_item_in_cahtting_data->peer_id;
2798 char* tablename = get_table_name_from_number(buddy_id);
2800 Eina_Bool res = set_all_rows_read(tablename);
2806 tg_main_list_item_s* old_item = ad->main_item_in_cahtting_data;
2807 ad->main_list = eina_list_remove(ad->main_list, ad->main_item_in_cahtting_data);
2808 if (old_item->peer_print_name) {
2809 free(old_item->peer_print_name);
2810 old_item->peer_print_name = NULL;
2812 if (old_item->last_message) {
2813 free(old_item->last_message);
2814 old_item->last_message = NULL;
2816 if (old_item->profile_pic_path) {
2817 free(old_item->profile_pic_path);
2818 old_item->profile_pic_path = NULL;
2820 if (old_item->buddy_display_name) {
2821 free(old_item->buddy_display_name);
2822 old_item->buddy_display_name = NULL;
2825 old_item->date_lbl = NULL;
2826 old_item->msg_status_lbl = NULL;
2827 old_item->main_item_layout = NULL;
2828 old_item->profile_pic = NULL;
2829 old_item->profile_pic_path = NULL;
2830 old_item->status_lbl = NULL;
2831 old_item->user_name_lbl = NULL;
2832 ad->main_item_in_cahtting_data = NULL;
2833 if (ad->peer_in_cahtting_data) {
2834 peer_with_pic_s *item = ad->peer_in_cahtting_data;
2835 tg_main_list_item_s* latest_item = get_latest_item(ad, item);
2837 ad->main_list = eina_list_prepend(ad->main_list, latest_item);
2840 refresh_main_list_view(ad, EINA_FALSE);
2842 if (ad->peer_in_cahtting_data) {
2843 peer_with_pic_s *item = ad->peer_in_cahtting_data;
2845 int buddy_id = item->use_data->peer_id;
2846 char* tablename = get_table_name_from_number(buddy_id);
2847 Eina_Bool res = set_all_rows_read(tablename);
2853 tg_peer_info_s* peer_info = item->use_data;
2855 //if (peer_info->last_msg_id > 0) {
2857 // get message from message table.
2859 char* tablename = get_table_name_from_number(peer_info->peer_id);
2860 //tg_message_s* msg = get_message_from_message_table(peer_info->last_msg_id, tablename);
2861 tg_message_s* msg = get_latest_message_from_message_table(tablename, EINA_FALSE);
2866 if (msg->message && strlen(msg->message) > 0) {
2867 item->last_message = strdup(msg->message);
2869 item->last_message = strdup(" ");
2873 int media_type = msg->media_type;
2874 if (media_type == tgl_message_media_none) {
2875 if (msg->message && strlen(msg->message) > 0) {
2876 item->last_message = strdup(msg->message);
2878 item->last_message = strdup(" ");
2880 } else if (media_type == tgl_message_media_photo) {
2881 item->last_message = strdup("Image");
2882 } else if (media_type == tgl_message_media_document) {
2883 tgl_media_s *media_msg = NULL;
2884 media_msg = get_media_details_from_db(atoll(msg->media_id));
2886 if (media_msg && media_msg->doc_type) {
2887 if (strlen(media_msg->doc_type) > 0) {
2888 item->last_message = strdup(media_msg->doc_type);
2890 item->last_message = strdup("Document");
2892 free_media_details(media_msg);
2894 if (msg->message && strlen(msg->message) > 0) {
2895 item->last_message = strdup(msg->message);
2897 item->last_message = strdup("Document");
2901 } else if (media_type == tgl_message_media_geo) {
2902 item->last_message = strdup("Geo location");
2903 } else if (media_type == tgl_message_media_contact) {
2904 item->last_message = strdup("Contact");
2905 } else if (media_type == tgl_message_media_unsupported) {
2906 item->last_message = strdup(" ");
2907 } else if (media_type == tgl_message_media_photo_encr) {
2908 item->last_message = strdup("Image encrypted");
2909 } else if (media_type == tgl_message_media_document_encr) {
2910 item->last_message = strdup("Document encrypted");
2912 item->last_message = strdup(" ");
2916 tg_main_list_item_s* main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s));
2917 memset(main_list_item, 0, sizeof(tg_main_list_item_s));
2918 main_list_item->peer_id = peer_info->peer_id;
2919 main_list_item->peer_type = peer_info->peer_type;
2921 set_peer_names(peer_info, main_list_item);
2923 main_list_item->last_seen_time = msg->date;
2924 main_list_item->last_msg_id = msg->msg_id;
2925 main_list_item->last_message = strdup(item->last_message);
2926 main_list_item->last_msg_type = msg->media_type;
2927 main_list_item->is_out_msg = msg->out;
2928 main_list_item->last_msg_status = msg->msg_state;
2929 main_list_item->last_msg_service = msg->service;
2930 main_list_item->number_of_unread_msgs = get_unread_message_count(tablename);
2932 if (peer_info->photo_path)
2933 main_list_item->profile_pic_path = strdup(peer_info->photo_path);
2935 ad->main_list = eina_list_prepend(ad->main_list, main_list_item);
2937 // delete message object
2940 msg->message = NULL;
2943 if (msg->media_id) {
2944 free(msg->media_id);
2945 msg->media_id = NULL;
2952 item->last_message = strdup(" ");
2953 if (peer_info->peer_type == TGL_PEER_CHAT) {
2954 tg_main_list_item_s* main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s));
2955 memset(main_list_item, 0, sizeof(tg_main_list_item_s));
2956 main_list_item->peer_id = peer_info->peer_id;
2957 main_list_item->peer_type = peer_info->peer_type;
2959 set_peer_names(peer_info, main_list_item);
2961 main_list_item->last_seen_time = peer_info->last_seen_time;
2962 main_list_item->last_message = strdup(item->last_message);
2963 main_list_item->last_msg_type = -1;
2964 main_list_item->last_msg_service = 0;
2965 main_list_item->is_out_msg = -1;
2966 main_list_item->last_msg_id = -1;
2967 main_list_item->last_msg_status = -1;
2968 main_list_item->number_of_unread_msgs = 0;
2970 if (peer_info->photo_path)
2971 main_list_item->profile_pic_path = strdup(peer_info->photo_path);
2973 ad->main_list = eina_list_prepend(ad->main_list, main_list_item);
2984 refresh_main_list_view(ad, EINA_TRUE);
2988 elm_naviframe_item_pop(ad->nf);
2989 ad->current_app_state = TG_USER_MAIN_VIEW_STATE;
2990 show_floating_button(ad);
2992 case TG_SELECT_BUDDY_VIEW:
2993 elm_naviframe_item_pop(ad->nf);
2994 ad->current_app_state = TG_SET_CHAT_INFO_STATE;
2996 case TG_SET_USERNAME_STATE:
2997 elm_naviframe_item_pop(ad->nf);
2998 ad->current_app_state = TG_SETTINGS_SCREEN_STATE;
3001 case TG_ADD_CONTACT_STATE:
3002 elm_naviframe_item_pop(ad->nf);
3003 ad->current_app_state = TG_SET_USER_INFO_STATE;
3006 case TG_SET_CHAT_INFO_STATE:
3007 case TG_SET_USER_INFO_STATE:
3008 elm_naviframe_item_pop(ad->nf);
3009 ad->current_app_state = TG_CHAT_MESSAGING_VIEW_STATE;
3011 case TG_USER_MAIN_VIEW_SELECTION_STATE:
3012 case TG_PEER_SEARCH_VIEW_STATE:
3013 case TG_START_MESSAGING_VIEW_STATE:
3014 case TG_SETTINGS_SCREEN_STATE:
3015 elm_naviframe_item_pop(ad->nf);
3016 ad->current_app_state = TG_USER_MAIN_VIEW_STATE;
3017 show_floating_button(ad);
3018 //evas_object_show(ad->panel);
3019 //elm_panel_hidden_set(ad->panel, EINA_FALSE);
3021 case TG_SETTINGS_EDIT_NAME_STATE:
3022 elm_naviframe_item_pop(ad->nf);
3023 ad->current_app_state = TG_SETTINGS_SCREEN_STATE;
3024 delete_floating_button(ad);
3026 case TG_COUNTRY_SELECTION_VIEW:
3027 elm_naviframe_item_pop(ad->nf);
3028 ad->current_app_state = TG_REGISTRATION_STATE;
3030 case TG_REGISTRATION_STATE:
3031 elm_win_lower(ad->win);
3034 case TG_LOGIN_STATE:
3035 send_request_for_restart_server(ad, ad->service_client);
3036 if (ad->timer_value > 0) {
3037 Ecore_Timer* timer = evas_object_data_get(ad->nf, "code_timer");
3039 ecore_timer_del(timer);
3042 elm_naviframe_item_pop(ad->nf);
3043 ad->current_app_state = TG_REGISTRATION_STATE;
3045 case TG_PROFILE_REGISTRATION_STATE:
3046 /* ad->current_app_state = TG_REGISTRATION_STATE;
3047 elm_naviframe_item_pop(ad->nf);*/
3048 elm_win_lower(ad->win);
3051 case TG_BUDDY_LIST_STATE:
3052 evas_object_data_set(ad->nf, "buddy_list", NULL);
3053 elm_win_lower(ad->win);
3056 case TG_BUDDY_CHAT_CONV_STATE:
3057 ad->buddy_in_cahtting_data = NULL;
3058 if (ad->loaded_msg_list) {
3059 eina_list_free(ad->loaded_msg_list);
3060 ad->loaded_msg_list = NULL;
3062 elm_naviframe_item_pop(ad->nf);
3063 ad->current_app_state = TG_BUDDY_LIST_STATE;
3064 //evas_object_show(ad->panel);
3065 //refresh_buddy_list(ad);
3067 case TG_ADD_CONTACT_STATE:
3068 elm_naviframe_item_pop(ad->nf);
3069 if (ad->is_loading_from_profile_view) {
3070 ad->is_loading_from_profile_view = EINA_FALSE;
3071 ad->current_app_state = TG_SET_USER_INFO_STATE;
3072 } else if (ad->is_loading_from_msg_view) {
3073 ad->is_loading_from_msg_view = EINA_FALSE;
3074 ad->current_app_state = TG_CHAT_MESSAGING_VIEW_STATE;
3076 ad->current_app_state = TG_PEER_SEARCH_VIEW_STATE;
3077 show_floating_button(ad);
3080 case TG_BUDDY_LIST_SELECTION_STATE:
3082 Eina_List *l = NULL;
3083 user_data_with_pic_s *item = NULL;
3084 EINA_LIST_FOREACH(ad->buddy_list, l, item) {
3087 user_data_s* user = item->use_data;
3088 user->is_selected = EINA_FALSE;
3090 elm_naviframe_item_pop(ad->nf);
3091 ad->current_app_state = TG_PEER_SEARCH_VIEW_STATE;
3094 case TG_GROUP_CHAT_NAME_ENTRY_STATE:
3096 Eina_List *l = NULL;
3097 user_data_with_pic_s *item = NULL;
3098 EINA_LIST_FOREACH(ad->buddy_list, l, item) {
3102 user_data_s* user = item->use_data;
3103 user->is_selected = EINA_FALSE;
3105 elm_naviframe_item_pop(ad->nf);
3106 ad->current_app_state = TG_BUDDY_LIST_SELECTION_STATE;
3107 //evas_object_show(ad->panel);
3108 //elm_panel_hidden_set(ad->panel, EINA_FALSE);
3109 //refresh_buddy_list(ad);
3118 layout_back_cb(void *data, Evas_Object *obj, void *event_info)
3120 appdata_s *ad = data;
3121 /* Let window go to hide state. */
3122 elm_win_lower(ad->win);
3125 void _btn_clicked(void* data, Evas_Object* btn, void* ev)
3127 appdata_s *ad = data;
3128 bundle *msg = bundle_create();
3129 if (bundle_add_str(msg, "tizen_app", "Hello service") != 0) {
3130 ERR("Failed to add data by key to bundle");
3134 int result = _app_send_response(ad, msg);
3135 if (result != SVC_RES_OK) {
3141 Eina_Bool on_load_main_view_requested(void *data)
3143 appdata_s *ad = data;
3145 elm_naviframe_item_pop(ad->nf);
3146 hide_loading_popup(ad);
3147 ad->is_loading_from_msg_view = EINA_FALSE;
3148 ad->is_loading_from_profile_view = EINA_FALSE;
3149 launch_user_main_view_cb(ad);
3150 display_badge(get_number_of_unread_messages(), ad, EINA_FALSE);
3152 return ECORE_CALLBACK_CANCEL;
3155 Eina_Bool on_init_view_requested(void *data)
3157 appdata_s *ad = data;
3159 Eina_List *user_info = get_registered_user_info();
3161 elm_naviframe_item_pop(ad->nf);
3162 ad->current_app_state = TG_REGISTRATION_STATE;
3163 launch_init_screen(ad);
3165 //show_toast(ad, "user already registered");
3166 load_registered_user_data(ad);
3167 load_buddy_list_data(ad);
3168 load_unknown_buddy_list_data(ad);
3170 load_main_list_data(ad);
3171 eina_list_free(user_info);
3172 ecore_timer_add(2, on_load_main_view_requested, ad);
3175 return ECORE_CALLBACK_CANCEL;
3178 void on_tg_service_result_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
3180 if (result == APP_CONTROL_ERROR_NONE)
3181 LOGE("Server launched successfully.");
3183 LOGE("Server not launched.");
3186 void launch_tg_server(void *data)
3188 appdata_s *ad = data;
3189 app_control_h app_control = NULL;
3190 int ret = APP_CONTROL_ERROR_NONE;
3192 ret = app_control_create(&app_control);
3193 ret_if (APP_CONTROL_ERROR_NONE != ret);
3195 ret = app_control_set_app_id(app_control, TELEGRAM_SERVER_APP_NAME);
3196 goto_if (APP_CONTROL_ERROR_NONE != ret, out);
3198 ret = app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
3199 goto_if (APP_CONTROL_ERROR_NONE != ret, out);
3201 ret = app_control_send_launch_request(app_control, &on_tg_service_result_cb, ad);
3202 goto_if (APP_CONTROL_ERROR_NONE != ret, out);
3205 app_control_destroy(app_control);
3208 static void create_base_gui(appdata_s *ad)
3210 ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
3211 elm_win_conformant_set(ad->win, EINA_TRUE);
3212 elm_win_autodel_set(ad->win, EINA_TRUE);
3214 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
3215 /* Telegram guideline 720 x 1280 */
3216 elm_app_base_scale_set(2.6);
3218 if (elm_win_wm_rotation_supported_get(ad->win)) {
3219 int rots[2] = {0, 180};
3220 elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), sizeof(rots) / sizeof(int));
3222 ad->target_direction = tg_get_device_orientation();
3223 char edj_path[PATH_MAX] = {0, };
3224 app_get_resource(TELEGRAM_CUSTOM_WINSET_EDJ, edj_path, (int)PATH_MAX);
3226 Elm_Theme *theme = elm_theme_new();
3227 elm_theme_extension_add(NULL, edj_path);
3229 evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
3231 ad->conform = elm_conformant_add(ad->win);
3232 evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3233 elm_win_resize_object_add(ad->win, ad->conform);
3234 evas_object_show(ad->conform);
3236 ad->layout = elm_layout_add(ad->conform);
3237 evas_object_size_hint_weight_set(ad->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3239 //elm_layout_theme_set(ad->layout, "layout", "drawer", "panel");
3240 elm_layout_theme_set(ad->layout, "layout", "application", "default");
3241 evas_object_show(ad->layout);
3243 elm_object_content_set(ad->conform, ad->layout);
3244 ad->nf = elm_naviframe_add(ad->layout);
3246 ad->current_app_state = TG_SPLASH_SCREEN_STATE;
3247 launch_splash_screen_cb(ad);
3248 elm_object_part_content_set(ad->layout, "elm.swallow.content", ad->nf);
3249 eext_object_event_callback_add(ad->nf, EEXT_CALLBACK_BACK, app_nf_back_cb, ad);
3251 evas_object_show(ad->win);
3253 // check for user info
3256 char *chat_bg = NULL;
3257 preference_get_string(TG_CHAT_BG_PREFERENCE, &chat_bg);
3259 ad->chat_background = strdup(chat_bg);
3262 if (!ad->chat_background) {
3263 ad->chat_background = strdup(ui_utils_get_resource(TG_CHAT_DEFAULT_BG));
3264 preference_set_string(TG_CHAT_BG_PREFERENCE, ad->chat_background);
3266 launch_tg_server(ad);
3267 ecore_timer_add(5, on_init_view_requested, ad);
3272 char *build_a_path(const char *path, const char *filename)
3277 len = strlen(path) + strlen(filename) + 2;
3282 snprintf(ret, len, "%s/%s", path, filename);
3286 int remove_directory(const char *path)
3288 DIR *d = opendir(path);
3289 size_t path_len = strlen(path);
3298 while (!r && (p=readdir(d)))
3304 /* Skip the names "." and ".." as we don't want to recurse on them. */
3305 if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, ".."))
3310 len = path_len + strlen(p->d_name) + 2;
3314 struct stat statbuf;
3316 snprintf(buf, len, "%s/%s", path, p->d_name);
3318 if (!stat(buf, &statbuf)) {
3319 if (S_ISDIR(statbuf.st_mode)) {
3320 r2 = remove_directory(buf);
3343 Eina_Bool copy_file_another_dir(const char *source_file, const char *target_file)
3345 FILE *source, *target;
3347 source = fopen(source_file, "rb+");
3354 target = fopen(target_file, "wb+");
3362 char buffer[1024] = {0}; /*Buffer to store files content*/
3365 while((size = fread(buffer, 1, 1024, source)) != 0)
3367 fwrite(buffer, 1, size, target);
3375 void recursive_dir_copy(const char *source_dir, const char *target_dir)
3378 struct dirent *src_files;
3379 Eina_List *src_dir_stack;
3380 Eina_List *tar_dir_stack;
3386 src_dir_stack = NULL;
3387 tar_dir_stack = NULL;
3389 src_dir = strdup(source_dir);
3390 tar_dir = strdup(target_dir);
3393 open_src = opendir(src_dir);
3394 while((src_files = readdir(open_src))) {
3395 if (src_files->d_type == DT_DIR) {
3398 if (src_files->d_name[0] == '.' && (src_files->d_name[1] == '\0' || (src_files->d_name[1] == '.' && src_files->d_name[2] == '\0'))) {
3402 char *temp_dest = build_a_path(tar_dir, src_files->d_name);
3403 mkdir(temp_dest, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
3405 char *temp_src = build_a_path(src_dir, src_files->d_name);
3407 src_dir_stack = eina_list_prepend(src_dir_stack, temp_src);
3408 tar_dir_stack = eina_list_prepend(tar_dir_stack, temp_dest);
3411 // copy file to target src_dir.
3412 char *temp_src = build_a_path(src_dir, src_files->d_name);
3413 char *temp_dest = build_a_path(tar_dir, src_files->d_name);
3414 //int ret = rename(temp_src, temp_dest);
3415 Eina_Bool ret = copy_file_another_dir(temp_src, temp_dest);
3417 // file copy success
3419 // file copy failed.
3432 src_dir = eina_list_nth(src_dir_stack, 0);
3434 src_dir_stack = eina_list_remove(src_dir_stack, src_dir);
3436 tar_dir = eina_list_nth(tar_dir_stack, 0);
3438 tar_dir_stack = eina_list_remove(tar_dir_stack, tar_dir);
3440 } while (src_dir != NULL);
3443 void move_downloaded_files()
3445 // create download directory.
3446 struct stat st = {0};
3447 char dest_download_dir[512] = {0,};
3448 sprintf(dest_download_dir, "%s/%s", app_get_shared_data_path(), "downloads");
3449 if (stat(dest_download_dir, &st) == -1) {
3450 mkdir(dest_download_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
3453 LOGE("dest Download directory: %s", dest_download_dir);
3454 // create download directory.
3455 char target_download_dir[512] = {0,};
3456 sprintf(target_download_dir, "%s/%s/%s", app_get_data_path(), "telegram_tizen", "downloads");
3458 LOGE("target Download directory: %s", target_download_dir);
3459 recursive_dir_copy(target_download_dir, dest_download_dir);
3460 remove_directory(target_download_dir);
3464 Eina_Bool dirExists(const char *path)
3468 if (stat(path, &info) != 0)
3470 else if (info.st_mode & S_IFDIR)
3476 static void update_downloaded_video_thumb_paths(const char *table_name, const char *col_one, const char *column_two)
3478 LOGE("Update media info table thumb files");
3479 if (!table_name || !col_one || !column_two)
3482 Eina_List *col_types = NULL;
3483 col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
3484 col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
3486 Eina_List *col_names = NULL;
3487 col_names = eina_list_append(col_names, col_one);
3488 col_names = eina_list_append(col_names, column_two);
3490 Eina_List *vals = get_values_from_table_sync(table_name, col_names, col_types, NULL, TG_DBMGR_NOLIMITED, TG_DBMGR_NOLIMITED);
3491 int val_size = eina_list_count(vals);
3492 if (vals && val_size > 0) {
3493 Eina_List *row_vals = NULL;
3494 EINA_LIST_FREE(vals, row_vals) {
3496 char *file_path = NULL;
3498 int *temp_user_id = (int *)eina_list_nth(row_vals, 0);
3500 user_id = *temp_user_id;
3504 file_path = (char *)eina_list_nth(row_vals, 1);
3507 eina_list_free(row_vals);
3511 if (strlen(file_path) > 0 && strncmp(file_path, "/opt/usr/media/telegram/telegram_tizen", strlen("/opt/usr/media/telegram/telegram_tizen")) == 0) {
3512 // update file name in db
3513 char *new_path = str_replace(new_path, "/opt/usr/media/telegram/telegram_tizen", app_get_shared_data_path());
3516 eina_list_free(row_vals);
3519 LOGE("Old file path: %s", file_path);
3520 LOGE("New file path: %s", new_path);
3523 Eina_List *new_col_types = NULL;
3524 new_col_types = eina_list_append(new_col_types, TG_DB_COLUMN_TEXT);
3526 Eina_List *new_col_names = NULL;
3527 new_col_names = eina_list_append(new_col_names, column_two);
3529 Eina_List *new_col_values = NULL;
3530 new_col_values = eina_list_append(new_col_values, new_path);
3532 char* where_clause = NULL;
3534 int str_size = strlen(col_one) + strlen(" = ") + 10 + 1;
3535 where_clause = (char *)malloc(str_size);
3536 snprintf(where_clause, str_size, "%s = %d", col_one, user_id);
3537 Eina_Bool ret = update_table(table_name, new_col_names, new_col_types, new_col_values, where_clause);
3539 LOGE("Media info table update failed.");
3541 LOGE("Media info table update success.");
3544 eina_list_free(new_col_types);
3545 eina_list_free(new_col_names);
3546 eina_list_free(new_col_values);
3551 eina_list_free(row_vals);
3554 eina_list_free(col_types);
3555 eina_list_free(col_names);
3558 void update_downloaded_video_thumb_paths_in_media_info_table()
3560 update_downloaded_video_thumb_paths(MEDIA_INFO_TABLE_NAME, MEDIA_INFO_TABLE_MEDIA_ID, MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE);
3564 void update_downloaded_file_paths_in_media_info_table()
3566 update_downloaded_video_thumb_paths(MEDIA_INFO_TABLE_NAME, MEDIA_INFO_TABLE_MEDIA_ID, MEDIA_INFO_TABLE_FILE_PATH);
3570 void update_downloaded_file_paths_in_chat_info_table()
3572 update_downloaded_video_thumb_paths(CHAT_INFO_TABLE_NAME, CHAT_INFO_TABLE_CHAT_ID, CHAT_INFO_TABLE_PHOTO_PATH);
3576 void update_downloaded_file_paths_in_buddy_info_table(const char *table_name)
3578 LOGE("Update %s", table_name);
3579 update_downloaded_video_thumb_paths(table_name, USER_INFO_TABLE_USER_ID, USER_INFO_TABLE_PHOTO_PATH);
3582 static bool app_create(void *data)
3585 Hook to take necessary actions before main event loop starts
3586 Initialize UI resources and application's data
3587 If this function returns true, the main loop of application starts
3588 If this function returns false, the application is terminated
3591 appdata_s *ad = data;
3592 if (dirExists(OLD_DIR)) {
3593 char *new_dir = app_get_data_path();
3594 recursive_dir_copy(OLD_DIR, new_dir);
3595 remove_directory(OLD_DIR);
3596 move_downloaded_files();
3597 // update downloaded image paths in DB
3598 update_downloaded_file_paths_in_buddy_info_table(BUDDY_INFO_TABLE_NAME);
3599 update_downloaded_file_paths_in_buddy_info_table(USER_INFO_TABLE_NAME);
3600 update_downloaded_file_paths_in_buddy_info_table(PEER_INFO_TABLE_NAME);
3601 update_downloaded_file_paths_in_chat_info_table();
3602 update_downloaded_file_paths_in_media_info_table();
3603 update_downloaded_video_thumb_paths_in_media_info_table();
3607 bindtextdomain(PACKAGE, "/opt/usr/apps/org.tizen.telegram_tizen_client/res/locale");
3609 ad->phone_number = NULL;
3610 ad->buddy_list = NULL;
3611 ad->unknown_buddy_list = NULL;
3612 ad->known_buddy_list = NULL;
3613 ad->main_list = NULL;
3614 ad->peer_list = NULL;
3615 ad->search_peer_list = NULL;
3616 ad->is_first_time_registration = EINA_FALSE;
3618 ad->loaded_msg_list = NULL;
3619 ad->loading_popup = NULL;
3620 ad->current_user_data = NULL;
3621 ad->is_tg_initilized = EINA_FALSE;
3622 ad->chat_background = NULL;
3623 ad->msg_popup = NULL;
3624 ad->s_notififcation = NULL;
3626 ad->is_server_ready = EINA_FALSE;
3627 ad->is_waiting_for_phone_num = EINA_FALSE;
3628 ad->login_timer = NULL;
3629 ad->contact_list = NULL;
3630 ad->main_item = NULL;
3631 ad->country_codes_list = NULL;
3632 ad->country_names_list = NULL;
3633 //ad->msg_count = 0;
3635 create_base_gui(ad);
3636 int err = badge_add(TELEGRAM_APP_ID);
3637 if (BADGE_ERROR_NONE != err) {
3638 LOGE("Badge add is failed, %d", err);
3645 app_control(app_control_h app_control, void *data)
3647 /* Handle the launch request. */
3651 app_pause(void *data)
3653 appdata_s *app_data = data;
3657 app_data->s_app_visible_state = APP_STATE_IN_BACKGROUND;
3658 display_badge(get_number_of_unread_messages(), app_data, EINA_FALSE);
3662 app_resume(void *data)
3664 appdata_s *app_data = data;
3666 app_data->s_app_visible_state = APP_STATE_IN_FOREGROUND;
3670 void free_app_data(appdata_s *app_data, Eina_Bool destroy_server)
3675 display_badge(get_number_of_unread_messages(), app_data, EINA_FALSE);
3677 eina_list_free(app_data->country_codes_list);
3678 eina_list_free(app_data->country_names_list);
3679 free(app_data->country_code_buffer);
3681 if (app_data->panel) {
3682 Evas_Object *panel_list = evas_object_data_get(app_data->panel, "panel_list");
3684 evas_object_del(panel_list);
3685 evas_object_del(app_data->panel);
3686 app_data->panel = NULL;
3689 if (app_data->phone_number)
3690 free(app_data->phone_number);
3691 app_data->phone_number = NULL;
3693 if (app_data->sms_code)
3694 free(app_data->sms_code);
3695 app_data->sms_code = NULL;
3697 if (app_data->current_user_data)
3698 free_user_data(app_data->current_user_data);
3700 if (app_data->chat_background)
3701 app_data->chat_background = NULL;
3703 if (app_data && app_data->s_notififcation)
3704 notification_delete_all(NOTIFICATION_TYPE_NOTI);
3705 app_data->s_notififcation = NULL;
3707 peer_with_pic_s* pic_item = NULL;
3708 EINA_LIST_FREE(app_data->peer_list, pic_item) {
3709 tg_peer_info_s* item = pic_item->use_data;
3711 if (item->print_name)
3712 free(item->print_name);
3713 item->print_name = NULL;
3714 if (item->photo_path)
3715 free(item->photo_path);
3716 item->photo_path = NULL;
3717 pic_item->contact_icon = NULL;
3718 pic_item->msg_object = NULL;
3719 pic_item->name_object = NULL;
3724 app_data->peer_list = NULL;
3726 tg_main_list_item_s* main_item = NULL;
3727 EINA_LIST_FREE(app_data->main_list, main_item) {
3729 if (main_item->peer_print_name) {
3730 free(main_item->peer_print_name);
3731 main_item->peer_print_name = NULL;
3733 if (main_item->last_message) {
3734 free(main_item->last_message);
3735 main_item->last_message = NULL;
3737 if (main_item->profile_pic_path) {
3738 free(main_item->profile_pic_path);
3739 main_item->profile_pic_path = NULL;
3741 if (main_item->buddy_display_name) {
3742 free(main_item->buddy_display_name);
3743 main_item->buddy_display_name = NULL;
3745 main_item->date_lbl = NULL;
3746 main_item->msg_status_lbl = NULL;
3747 main_item->main_item_layout = NULL;
3748 main_item->profile_pic = NULL;
3749 main_item->profile_pic_path = NULL;
3750 main_item->status_lbl = NULL;
3751 main_item->user_name_lbl = NULL;
3753 app_data->main_list = NULL;
3755 user_data_with_pic_s* item = NULL;
3756 EINA_LIST_FREE(app_data->buddy_list, item) {
3759 user_data_s* user_data = item->use_data;
3761 if (user_data->print_name) {
3762 free(user_data->print_name);
3763 user_data->print_name = NULL;
3766 if (user_data->photo_path) {
3767 free(user_data->photo_path);
3768 user_data->photo_path = NULL;
3771 if (user_data->first_name) {
3772 free(user_data->first_name);
3773 user_data->first_name = NULL;
3776 if (user_data->last_name) {
3777 free(user_data->last_name);
3778 user_data->last_name = NULL;
3781 if (user_data->phone) {
3782 free(user_data->phone);
3783 user_data->phone = NULL;
3785 if (user_data->real_first_name) {
3786 free(user_data->real_first_name);
3787 user_data->real_first_name = NULL;
3790 if (user_data->real_last_name) {
3791 free(user_data->real_last_name);
3792 user_data->real_last_name = NULL;
3795 if (user_data->username) {
3796 free(user_data->username);
3797 user_data->username = NULL;
3799 if (user_data->highlight_name) {
3800 free(user_data->highlight_name);
3801 user_data->highlight_name = NULL;
3806 app_data->buddy_list = NULL;
3809 EINA_LIST_FREE(app_data->unknown_buddy_list, item) {
3814 user_data_s* user_data = item->use_data;
3816 if (user_data->print_name) {
3817 free(user_data->print_name);
3818 user_data->print_name = NULL;
3821 if (user_data->photo_path) {
3822 free(user_data->photo_path);
3823 user_data->photo_path = NULL;
3826 if (user_data->first_name) {
3827 free(user_data->first_name);
3828 user_data->first_name = NULL;
3831 if (user_data->last_name) {
3832 free(user_data->last_name);
3833 user_data->last_name = NULL;
3836 if (user_data->phone) {
3837 free(user_data->phone);
3838 user_data->phone = NULL;
3840 if (user_data->real_first_name) {
3841 free(user_data->real_first_name);
3842 user_data->real_first_name = NULL;
3845 if (user_data->real_last_name) {
3846 free(user_data->real_last_name);
3847 user_data->real_last_name = NULL;
3850 if (user_data->username) {
3851 free(user_data->username);
3852 user_data->username = NULL;
3854 if (user_data->highlight_name) {
3855 free(user_data->highlight_name);
3856 user_data->highlight_name = NULL;
3861 app_data->unknown_buddy_list = NULL;
3863 EINA_LIST_FREE(app_data->known_buddy_list, item) {
3864 user_data_s* user_data = item->use_data;
3866 if (user_data->print_name)
3867 free(user_data->print_name);
3868 user_data->print_name = NULL;
3870 if (user_data->photo_path)
3871 free(user_data->photo_path);
3872 user_data->photo_path = NULL;
3874 if (user_data->first_name)
3875 free(user_data->first_name);
3876 user_data->first_name = NULL;
3878 if (user_data->last_name)
3879 free(user_data->last_name);
3880 user_data->last_name = NULL;
3882 if (user_data->phone)
3883 free(user_data->phone);
3884 user_data->phone = NULL;
3886 if (user_data->real_first_name)
3887 free(user_data->real_first_name);
3888 user_data->real_first_name = NULL;
3890 if (user_data->real_last_name)
3891 free(user_data->real_last_name);
3892 user_data->real_last_name = NULL;
3894 if (user_data->username)
3895 free(user_data->username);
3896 user_data->username = NULL;
3897 if (user_data->highlight_name)
3898 free(user_data->highlight_name);
3899 user_data->highlight_name = NULL;
3904 app_data->known_buddy_list = NULL;
3906 eina_list_free(app_data->loaded_msg_list);
3907 app_data->loaded_msg_list = NULL;
3909 if (app_data->service_client && destroy_server) {
3910 service_client_destroy(app_data->service_client);
3911 app_data->service_client = NULL;
3913 free_contact_list(app_data->contact_list);
3918 app_terminate(void *data)
3920 free_app_data(data, EINA_TRUE);
3924 ui_app_lang_changed(app_event_info_h event_info, void *user_data)
3926 /*APP_EVENT_LANGUAGE_CHANGED*/
3927 char *locale = NULL;
3928 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
3930 setlocale(LC_ALL, locale);
3931 elm_language_set(locale);
3938 TelegramAppDirection tg_get_device_orientation()
3940 TelegramAppDirection target_direction;
3942 switch (app_get_device_orientation()) {
3943 case APP_DEVICE_ORIENTATION_90:
3944 target_direction = TELEGRAM_TARGET_DIRECTION_LANDSCAPE_INVERSE;
3946 case APP_DEVICE_ORIENTATION_180:
3947 target_direction = TELEGRAM_TARGET_DIRECTION_PORTRAIT_INVERSE;
3949 case APP_DEVICE_ORIENTATION_270:
3950 target_direction = TELEGRAM_TARGET_DIRECTION_LANDSCAPE;
3952 case APP_DEVICE_ORIENTATION_0:
3954 target_direction = TELEGRAM_TARGET_DIRECTION_PORTRAIT;
3958 return target_direction;
3961 void update_current_view(appdata_s *ad)
3966 switch (ad->current_app_state) {
3967 case TG_USER_MAIN_VIEW_STATE:
3968 refresh_main_list_view(ad, EINA_FALSE);
3970 case TG_CHAT_MESSAGING_VIEW_STATE:
3971 refresh_messaging_view(ad);
3980 static void ui_app_orient_changed(app_event_info_h event_info, void *user_data)
3982 appdata_s *ad = user_data;
3986 TelegramAppDirection target_direction;
3987 app_device_orientation_e orientation;
3989 if (app_event_get_device_orientation(event_info, &orientation) != 0) {
3993 switch (orientation) {
3994 case APP_DEVICE_ORIENTATION_90:
3995 target_direction = TELEGRAM_TARGET_DIRECTION_LANDSCAPE_INVERSE;
3997 case APP_DEVICE_ORIENTATION_180:
3998 target_direction = TELEGRAM_TARGET_DIRECTION_PORTRAIT_INVERSE;
4000 case APP_DEVICE_ORIENTATION_270:
4001 target_direction = TELEGRAM_TARGET_DIRECTION_LANDSCAPE;
4003 case APP_DEVICE_ORIENTATION_0:
4005 target_direction = TELEGRAM_TARGET_DIRECTION_PORTRAIT;
4009 if (target_direction != ad->target_direction) {
4010 ad->target_direction = target_direction;
4011 update_current_view(ad);
4017 static void ui_app_region_changed(app_event_info_h event_info, void *user_data)
4021 static void ui_app_low_battery(app_event_info_h event_info, void *user_data)
4025 static void ui_app_low_memory(app_event_info_h event_info, void *user_data)
4029 int main(int argc, char *argv[])
4031 appdata_s ad = {0,};
4034 ui_app_lifecycle_callback_s event_callback = {0,};
4035 app_event_handler_h handlers[5] = {NULL, };
4037 event_callback.create = app_create;
4038 event_callback.terminate = app_terminate;
4039 event_callback.pause = app_pause;
4040 event_callback.resume = app_resume;
4041 event_callback.app_control = app_control;
4043 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
4044 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
4045 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
4046 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
4047 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
4048 ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);
4050 ret = ui_app_main(argc, argv, &event_callback, &ad);
4051 if (ret != APP_ERROR_NONE) {
4052 dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() is failed. err = %d", ret);