}
ret = sqlite3_exec(db,var_query, NULL, NULL, &err_msg);
+ free(var_query);
close_database(db);
if( ret != SQLITE_OK ){
sqlite3_free(err_msg);
return EINA_TRUE;
}
-int get_number_of_rows(const char *table_name, char* where_clause)
+int get_number_of_rows(char* table_name, char* where_clause)
{
int no_of_rows = 0;
if (!table_name) {
*val_int = temp;
row_vals = eina_list_append(row_vals, val_int);
} else if(!strcmp(col_type, "TEXT") || !strcmp(col_type, "TEXT PRIMARY KEY NOT NULL")) {
- char* val_text = strdup((const char *)sqlite3_column_text(stmt, col));
+ char *temp_val = (char*)sqlite3_column_text(stmt, col);
+ char *val_text = NULL;
+ if (temp_val) {
+ val_text = strdup(temp_val);
+ } else {
+ val_text = strdup("");
+ }
row_vals = eina_list_append(row_vals, val_text);
}
}
int ret;
const char *type;
int col;
-
sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
char* where_clause = NULL;
- if (!db) {
- return NULL;
- }
-
if (wc) {
where_clause = (char*)malloc(strlen("WHERE ") + strlen(wc) + 1);
strcpy(where_clause, "WHERE ");
strcat(where_clause, wc);
}
+
if (!table_name || !column_names) {
- close_database(db);
return NULL;
}
query_len += strlen(" FROM ");
query_len += strlen(table_name) + 1;
- query_len += (wc ? strlen(wc) + 7 : 0);
+ query_len += (where_clause ? strlen(where_clause) : 0);
query_len += 2;
query = malloc(query_len);
if (!query) {
- close_database(db);
return NULL;
}
ptr++;
}
- ptr += sprintf(ptr, " FROM %s", table_name);
- if (wc) {
- ptr += sprintf(ptr, " WHERE %s", wc);
- }
+ ptr += sprintf(ptr, " FROM %s %s;", table_name, where_clause ? where_clause : "");
LOGD("Query: %s", query);
return NULL;
}
+
while(sqlite3_step(stmt) == SQLITE_ROW) {
col = 0;
record = NULL;
return result;
}
+
int tg_db_init(void)
{
+#if 0
int ret;
if (s_info.db) {
if(ret != SQLITE_OK) {
return EINA_FALSE;
}
-
+#endif
return EINA_TRUE;
}
int tg_db_fini(void)
{
+#if 0
if (!s_info.db) {
return EINA_FALSE;
}
sqlite3_close(s_info.db);
s_info.db = NULL;
+#endif
return EINA_TRUE;
}
"username, online, last_seen " \
"FROM user_info_table WHERE user_id = ?", -1, &stmt, NULL);
if (ret != SQLITE_OK) {
- close_database(db);
return NULL;
}
ret = sqlite3_bind_int(stmt, 1, user_id->id);
if (ret != SQLITE_OK) {
sqlite3_finalize(stmt);
- close_database(db);
return NULL;
}
result = eina_list_append(result, info);
}
- sqlite3_finalize(stmt);
close_database(db);
+ sqlite3_finalize(stmt);
return result;
}
ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
if (ret != SQLITE_OK) {
LOGE("Failed to bind a text");
- close_database(db);
return NULL;
}
sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
ret = sqlite3_prepare_v2(db, "SELECT peer_type, flags, last_msg_id, last_msg_date, print_name, struct_version, no_of_unread_msgs, last_seen_time, photo_path, photo_id FROM ? WHERE peer_id = ?", -1, &stmt, NULL);
if (ret != SQLITE_OK) {
- close_database(db);
return NULL;
}
ret = sqlite3_bind_text(stmt, 1, table, -1, SQLITE_TRANSIENT);
if (ret != SQLITE_OK) {
sqlite3_finalize(stmt);
- close_database(db);
return NULL;
}
ret = sqlite3_bind_int(stmt, 2, peer_id);
if (ret != SQLITE_OK) {
sqlite3_finalize(stmt);
- close_database(db);
return NULL;
}
if (sqlite3_step(stmt) != SQLITE_ROW) {
sqlite3_finalize(stmt);
- close_database(db);
return NULL;
}
info = calloc(1, sizeof(*info));
if (!info) {
sqlite3_finalize(stmt);
- close_database(db);
return NULL;
}
sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
ret = sqlite3_prepare_v2(db, "SELECT msg_id, flags, fwd_from_id, fwd_date, from_id, to_id, out, unread, date, service, message, msg_state, message_len, media_type, media_id, unique_id FROM ?", -1, &stmt, NULL);
if (ret != SQLITE_OK) {
- close_database(db);
return NULL;
}
ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
if (ret != SQLITE_OK) {
sqlite3_finalize(stmt);
- close_database(db);
return NULL;
}
return result;
}
-char *tg_db_get_image_path_from_db(int media_id)
+Eina_Bool delete_all_records(char *tablename)
{
- return NULL;
+ if (!tablename) {
+ return EINA_FALSE;
+ }
+ char *var_query = (char*)malloc(strlen("DELETE FROM ") + strlen(tablename) + strlen(";") + 1);
+ strcpy(var_query, "DELETE FROM ");
+ strcat(var_query, tablename);
+ strcat(var_query, ";");
+ int ret;
+ char* err_msg = 0;
+ sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
+ ret = sqlite3_exec(db,var_query, NULL, NULL, &err_msg);
+ close_database(db);
+ if( ret != SQLITE_OK ){
+ sqlite3_free(err_msg);
+ return EINA_FALSE;
+ }
+ free(var_query);
+ return EINA_TRUE;
}
extern Eina_Bool get_values_from_table(const char* table_name, Eina_List* column_names, int (*callback)(void*,int,char**,char**), const char* where_clause, void* data_to_callback);
extern Eina_List* get_values_from_table_sync(const char* table_name, Eina_List* column_names, Eina_List* column_types, const char* where_clause);
extern Eina_List* get_values_from_table_sync_order_by(const char* table_name, Eina_List* column_names, Eina_List* column_types, const char* order_column, Eina_Bool is_asc, const char* where_clause);
-extern int get_number_of_rows(const char *table_name, char *where_clause);
+extern int get_number_of_rows(char* table_name, char* where_clause);
extern Eina_List *tg_db_get_user_info(tgl_peer_id_t *user_id);
extern Eina_List *tg_db_get_chat_info(const char *table_name);
extern tg_peer_info_s *tg_db_get_peer_info(const char *table, int peer_id);
extern Eina_List *tg_db_get_messages(const char *table_name);
+extern Eina_Bool delete_all_records(char *tablename);
extern int tg_db_init(void);
extern int tg_db_fini(void);
void send_request_for_profile_registration(service_client* service_client, const char* first_name, const char* last_name);
void send_request_for_validation(service_client* service_client, const char* sms_code);
// type_of_chat 0-buddy, 1-group_chat 2-encrpted_chat
-void send_request_for_message_transport(service_client* service_client, const int buddy_id, const int message_id, const int msg_type, const char* data, const int type_of_chat);
+void send_request_for_message_transport(appdata_s *ad, service_client* service_client, const int buddy_id, const int message_id, const int msg_type, const char* data, const int type_of_chat);
void send_request_for_marked_as_read(service_client* service_client, const int buddy_id, const int type_of_chat);
-void send_request_for_image_downloading(service_client* service_client, const int buddy_id, const long long media_id);
-void send_request_for_media_transport(service_client* service_client, const int buddy_id, const int message_id, const int media_id, const int msg_type, const char* file_path, const int type_of_chat);
+void send_delete_group_chat_request(service_client* service_client, const int chat_id);
+void send_add_buddy_request(service_client* service_client, const int buddy_id);
+void send_delete_buddy_request(service_client* service_client, const int buddy_id);
+void send_block_buddy_request(service_client* service_client, const int buddy_id);
+void send_unblock_buddy_request(service_client* service_client, const int buddy_id);
+Eina_Bool send_request_for_media_downloading(service_client* service_client, const int buddy_id, const long long media_id);
+void send_request_for_media_transport(appdata_s *ad, service_client* service_client, const int buddy_id, const int message_id, const int media_id, const int msg_type, const char* file_path, const int type_of_chat);
void send_contacts_list_to_server(service_client* service_client, Eina_List* contacts_list);
void send_group_creation_request_to_server(service_client* service_client, Eina_List* buddy_list, const char* group_name, const char* group_image);
+void send_add_buddy_to_group_chat_request(service_client* service_client, int user_id, int chat_id);
+void send_set_group_chat_new_title_request(service_client* service_client, int user_id, const char* new_title);
+void send_set_group_chat_profile_pic_request(service_client* service_client, int user_id, const char* file_path);
+void send_set_profile_pic_request(service_client* service_client, int user_id, const char* file_path);
+void send_set_username_request(service_client* service_client, int user_id, const char* username);
+void send_remove_buddy_from_group_chat_request(service_client* service_client, int user_id, int chat_id);
+void send_request_for_delete_notifications(service_client* service_client);
+void send_request_for_server_connection_status(service_client* service_client);
+
#endif /* SERVER_REQUESTS_H_ */
--- /dev/null
+/*
+ * tg_chat_info_view.h
+ *
+ * Created on: Oct 3, 2015
+ * Author: sandeep
+ */
+
+#ifndef TG_CHAT_INFO_VIEW_H_
+#define TG_CHAT_INFO_VIEW_H_
+
+#include "tg_common.h"
+
+extern void launch_chat_info_screen(appdata_s* ad, int peer_id);
+extern void on_group_chat_info_updated(appdata_s *ad, char *type_of_change);
+extern void on_group_chat_deleted(appdata_s *ad, int chat_id);
+
+#endif /* TG_CHAT_INFO_VIEW_H_ */
#include "tg_db_manager.h"
#include "tg_common.h"
+#define TG_SETTINGS_TABLE_NAME "tg_settings_table"
+#define TG_SETTINGS_ROW_ID "row_id"
+#define TG_SETTINGS_CHAT_BG "chat_bg"
+
+#define MESSAGE_TRANSPORT_TABLE_NAME "message_transport_table"
+
+#define MESSAGE_TRANSPORT_TABLE_ROW_ID "row_id"
+#define MESSAGE_TRANSPORT_TABLE_APP_NAME "app_name"
+#define MESSAGE_TRANSPORT_TABLE_COMMAND "command"
+#define MESSAGE_TRANSPORT_TABLE_BUDDY_ID "buddy_id"
+#define MESSAGE_TRANSPORT_TABLE_MESSAGE_ID "message_id"
+#define MESSAGE_TRANSPORT_TABLE_MESSAGE_TYPE "message_type"
+#define MESSAGE_TRANSPORT_TABLE_MESSAGE_DATA "message_data"
+#define MESSAGE_TRANSPORT_TABLE_TYPE_OF_CHAT "type_of_chat"
+
+#define MEDIA_TRANSPORT_TABLE_NAME "media_transport_table"
+
+#define MEDIA_TRANSPORT_TABLE_ROW_ID "row_id"
+#define MEDIA_TRANSPORT_TABLE_APP_NAME "app_name"
+#define MEDIA_TRANSPORT_TABLE_COMMAND "command"
+#define MEDIA_TRANSPORT_TABLE_BUDDY_ID "buddy_id"
+#define MEDIA_TRANSPORT_TABLE_MESSAGE_ID "message_id"
+#define MEDIA_TRANSPORT_TABLE_MEDIA_ID "media_id"
+#define MEDIA_TRANSPORT_TABLE_MESSAGE_TYPE "message_type"
+#define MEDIA_TRANSPORT_TABLE_FILE_PATH "file_path"
+#define MEDIA_TRANSPORT_TABLE_TYPE_OF_CHAT "type_of_chat"
+
+
+
#define USER_INFO_TABLE_NAME "user_info_table"
#define USER_INFO_TABLE_USER_ID "user_id"
#define USER_INFO_TABLE_USER_NAME "username"
#define USER_INFO_TABLE_ONLINE_STATUS "online"
#define USER_INFO_TABLE_LAST_SEEN_TIME "last_seen"
+#define USER_INFO_TABLE_IS_BLOCKED "is_blocked"
+#define USER_INFO_TABLE_IS_DELETED "is_deleted"
#define BUDDY_INFO_TABLE_NAME "buddy_info_table"
-
+#if 0
#define BUDDY_INFO_TABLE_BUDDY_ID "user_id"
#define BUDDY_INFO_TABLE_PRINT_NAME "print_name"
#define BUDDY_INFO_TABLE_STRUCTURE_VERSION "structure_version"
#define BUDDY_INFO_TABLE_BUDDY_NAME "username"
#define BUDDY_INFO_TABLE_ONLINE_STATUS "online"
#define BUDDY_INFO_TABLE_LAST_SEEN_TIME "last_seen"
-
+#endif
#define MEDIA_INFO_TABLE_NAME "media_info_table"
#define MEDIA_INFO_TABLE_MEDIA_ID "media_id"
#define MEDIA_INFO_TABLE_PHOTO_SIZE4 "photo_size4" //int
#define MEDIA_INFO_TABLE_PHOTO_DATA4 "photo_data4" //text
-
#define MEDIA_INFO_TABLE_PHONE_NO "phone"
#define MEDIA_INFO_TABLE_FIRST_NAME "first_name"
#define MEDIA_INFO_TABLE_LAST_NAME "last_name"
#define MEDIA_INFO_TABLE_FILE_PATH "file_path"
-
+#define MEDIA_INFO_TABLE_MIME_TYPE "mime_type" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_TYPE "doc_type" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_WIDTH "doc_width" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_HEIGHT "doc_height" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_DURATION "doc_duration" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_SIZE "doc_size" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_DC "doc_dc" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE "video_thumb" //text
#define MESSAGE_INFO_TABLE_MESSAGE_ID "msg_id"
#define MESSAGE_INFO_TABLE_FLAGS "flags"
#define TG_DB_COLUMN_INTEGER "INTEGER"
#define TG_DB_COLUMN_INTEGER_PRIMARY_KEY "INTEGER PRIMARY KEY NOT NULL"
+#define TG_DB_COLUMN_INTEGER_PRIMARY_AUTO_INC_KEY "INTEGER PRIMARY KEY AUTOINCREMENT"
#define TG_DB_COLUMN_TEXT "TEXT"
-extern void create_data_base_tables();
+void create_data_base_tables();
+
+Eina_List* get_registered_user_info();
+
+Eina_List* get_buddy_list_info();
+
+Eina_List* get_buddy_info(int buddy_id);
+
+char* get_profile_pic_path(int buddy_id);
+
+tg_message_s* get_message_from_message_table(long long msg_id, char* table_name);
+
+char* get_video_thumb_path_from_db(long long media_id);
+
+char* get_media_path_from_db(long long media_id);
+
+tg_chat_info_s* get_chat_info(int chat_id);
-extern Eina_List *get_registered_user_info();
+Eina_List* get_group_chat_details();
-extern Eina_List *get_buddy_list_info();
+Eina_List* get_all_peer_details(char* start_name);
-extern Eina_List *get_buddy_info(int buddy_id);
+peer_with_pic_s* get_peer_info(int peer_id);
-extern char *get_profile_pic_path(int buddy_id);
+void insert_or_update_peer_into_database(tg_peer_info_s* UC);
-extern tg_message_s *get_message_from_message_table(long long msg_id, const char *table_name);
+void insert_msg_into_db(tg_message_s *M, char* table_name, int unique_id);
+void insert_media_info_to_db(tg_message_s *M, char *file_path, int width, int height, int size, char *latitude, char *longitude, char *first_name, char *last_name, char *phone_number);
-extern char *get_image_path_from_db(long long media_id);
+Eina_List* get_image_details_from_db(long long media_id);
+Eina_List* get_image_sizes_from_db(long long media_id);
-extern tg_chat_info_s *get_chat_info(int chat_id);
+tg_message_s* get_latest_message_from_message_table(char* table_name);
+int get_unread_message_count(char* table_name);
-extern Eina_List *get_group_chat_details();
+extern void update_msg_into_db(tg_message_s *M, char* table_name);
-extern Eina_List *get_all_peer_details();
+char* get_buddy_name_from_id(int buddy_id);
-extern void insert_or_update_peer_into_database(tg_peer_info_s* UC);
+int get_buddy_online_status(int buddy_id);
-extern void insert_msg_into_db(tg_message_s *M, const char *table_name, int unique_id);
-extern void insert_media_info_to_db(tg_message_s *M, char* file_path, int width, int height, int size);
+int insert_current_date_to_table(char* tb_name);
-extern Eina_List *get_image_details_from_db(long long media_id);
-extern Eina_List *get_image_sizes_from_db(long long media_id);
+Eina_List* load_peer_data_by_name(char* name);
-extern tg_message_s *get_latest_message_from_message_table(const char *table_name);
-extern int get_unread_message_count(const char *table_name);
+tgl_media_s* get_media_details_from_db(long long media_id);
-extern void update_msg_into_db(tg_message_s *M, const char *table_name);
+void free_media_details(tgl_media_s *media_msg);
-extern char* get_buddy_name_from_id(int buddy_id);
+int get_media_size_from_db(long long media_id);
-extern int get_buddy_online_status(int buddy_id);
+int get_number_of_unread_messages();
+Eina_Bool insert_unsent_message_to_db(const char *app_name, const char *command, const char *buddy_id, const char *msg_id, const char *msg_type, const char * msg_data, const char *type_of_chat);
+Eina_Bool insert_unsent_media_message_to_db(const char *app_name, const char *command, const char *buddy_id, const char *msg_id, const char *media_id, const char *msg_type, const char *file_path, const char *type_of_chat);
+#if 0
+void set_chat_bg(char *file_path);
+char* get_chat_bg();
+#endif
#endif /* TG_DB_WRAPPER_H_ */
extern void launch_messaging_view_cb(appdata_s* ad, int user_id);
extern void on_text_message_received_from_buddy(appdata_s* ad, long long message_id, int type_of_chat);
extern void on_text_message_state_changed(appdata_s* ad, tg_message_s *msg, int type_of_chat);
+extern void on_video_thumb_download_completed(appdata_s* ad, int buddy_id, long long media_id, const char* file_path);
extern void on_media_download_completed(appdata_s* ad, int buddy_id, long long media_id, const char* file_path);
extern void on_user_presence_state_changed(appdata_s* ad, int buddy_id);
extern void on_user_status_changed(appdata_s* ad, char* status);
+extern void on_group_chat_info_changed(appdata_s *ad, char *type_of_change);
+extern void on_chat_profile_pic_changed(appdata_s *ad, char *file_path);
+extern void on_messaging_menu_button_clicked(void *data, Evas_Object *obj, void *event_info);
#endif /* TG_MESSAGING_VIEW_H_ */
#define TG_REGISTRATION_H_
#include "tg_common.h"
-extern void launch_registration_cb(appdata_s* ad);
+extern void launch_registration_cb(appdata_s *ad);
#endif /* TG_REGISTRATION_H_ */
--- /dev/null
+/*
+ * tg_search_peer_view.h
+ *
+ * Created on: Sep 18, 2015
+ * Author: sandeep
+ */
+
+#ifndef TG_SEARCH_PEER_VIEW_H_
+#define TG_SEARCH_PEER_VIEW_H_
+
+#include "tg_common.h"
+
+extern void launch_start_peer_search_view(appdata_s* ad);
+
+
+
+#endif /* TG_SEARCH_PEER_VIEW_H_ */
--- /dev/null
+/*
+ * tg_select_buddy_from_list.h
+ *
+ * Created on: Oct 3, 2015
+ * Author: sandeep
+ */
+
+#ifndef TG_SELECT_BUDDY_FROM_LIST_H_
+#define TG_SELECT_BUDDY_FROM_LIST_H_
+
+#include "tg_common.h"
+
+extern void launch_select_buddy_view(appdata_s* ad);
+
+
+
+#endif /* TG_SELECT_BUDDY_FROM_LIST_H_ */
--- /dev/null
+/*
+ * tg_set_username_view.h
+ *
+ * Created on: Sep 30, 2015
+ * Author: sandeep
+ */
+
+#ifndef TG_SET_USERNAME_VIEW_H_
+#define TG_SET_USERNAME_VIEW_H_
+
+
+#include "tg_common.h"
+
+extern void launch_set_username_cb(appdata_s *ad);
+
+
+#endif /* TG_SET_USERNAME_VIEW_H_ */
--- /dev/null
+/*
+ * tg_settings_view.h
+ *
+ * Created on: Sep 29, 2015
+ * Author: sandeep
+ */
+
+#ifndef TG_SETTINGS_VIEW_H_
+#define TG_SETTINGS_VIEW_H_
+
+
+#include "tg_common.h"
+
+extern void launch_settings_screen(appdata_s* ad);
+
+
+#endif /* TG_SETTINGS_VIEW_H_ */
--- /dev/null
+/*
+ * tg_user_info_view.h
+ *
+ * Created on: Oct 2, 2015
+ * Author: sandeep
+ */
+
+#ifndef TG_USER_INFO_VIEW_H_
+#define TG_USER_INFO_VIEW_H_
+
+
+#include "tg_common.h"
+
+extern void launch_user_info_screen(appdata_s* ad, int peer_id);
+extern void on_user_block_response_received(appdata_s *ad, int buddy_id, Eina_Bool is_success);
+extern void on_user_unblock_response_received(appdata_s *ad, int buddy_id, Eina_Bool is_success);
+extern void on_user_deleted_response_received(appdata_s *ad, int buddy_id, Eina_Bool is_success);
+extern void on_user_added_response_received(appdata_s *ad, int buddy_id, Eina_Bool is_success);
+
+#endif /* TG_USER_INFO_VIEW_H_ */
#include "tg_common.h"
extern void launch_user_main_view_cb(appdata_s* ad);
-extern void refresh_main_view_list(appdata_s* ad);
+extern void refresh_main_list_view(appdata_s* ad, Eina_Bool is_new_item);
+extern void reload_main_list_view(appdata_s* ad);
#endif /* TG_USER_MAIN_VIEW_H_ */
image: "ApplicationIcon.png" COMP;
image: "msg_in_photo.9.png" COMP;
image: "msg_out_photo.9.png" COMP;
- image: "call_btn_circle.png" COMP;
+ image: "call_btn_circle.png" COMP;
+ image: "Telegram-main-icon.png" COMP;
}
group
state: "default" 0.0;
rel1 { relative: 0.0 0.0; to, "swallow.splash_screen"; }
rel2 { relative: 1.0 1.0; to, "swallow.splash_screen"; }
- color: 0 0 0 0;
+ color: 255 255 255 255;
}
}
part{
type:IMAGE;
description{
state: "default" 0.0;
- rel1 { relative: 0.0 0.0; to, "swallow.splash_screen,bg"; }
- rel2 { relative: 1.0 1.0; to, "swallow.splash_screen,bg"; }
+ rel1 { relative: 0.3 0.2; to, "swallow.splash_screen,bg"; }
+ rel2 { relative: 0.7 0.4; to, "swallow.splash_screen,bg"; }
image {
- normal: "ApplicationIcon.png";
+ normal: "Telegram-main-icon.png";
}
}
}
--- /dev/null
+collections {
+ base_scale: 1.8;
+#define POPUP_CONTENT_DEFAULT_PADDING_TOP_MIN_INC 27
+#define POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 15
+#define POPUP_CONTENT_DEFAULT_PADDING_RIGHT_MIN_INC 15
+#define POPUP_CONTENT_DEFAULT_PADDING_BOTTOM_MIN_INC 27
+#define POPUP_EDITFIELD_LAYOUT_MINMAX_HEIGHT_INC 96
+
+#define POPUP_IMAGE_VIEW_LAYOUT_BG_MIN_INC 0 112
+#define POPUP_IMAGE_SWALLOW_CONTENT_PADDING_BOTTOM_MIN_INC 0 20
+#define POPUP_DESCRIPTION_DEFAULT_TEXT_FONT_SIZE_INC 38
+#define POPUP_CHECK_VIEW_LAYOUT_CONTENT_MIN_INC 0 162
+#define POPUP_CHECK_VIEW_LAYOUT_BOTTOM_MIN_INC 0 90
+#define POPUP_CHECK_VIEW_SWALLOW_END_MIN_INC 40 40
+#define POPUP_CHECK_VIEW_LAYOUT_MIN_INC 0 252
+
+#define POPUP_TEXT_INPUTTEXT_VIEW_LAYOUT_BG_MIN_INC 480 159
+
+#define POPUP_PROGRESSBAR_VIEW_LAYOUT_PADDING_INC 15 27
+#define POPUP_PROGRESSBAR_VIEW_LAYOUT_TEXT_FONT_SIZE_INC 0 38
+#define POPUP_PROGRESSBAR_VIEW_LAYOUT_BG_INC 0 69
+#define POPUP_PROGRESSBAR_VIEW_LAYOUT_BG_MIN_INC 0 161
+
+#define POPUP_PROGRESSBAR_2TEXT_VIEW_LAYOUT_BG_MIN_INC 0 193
+#define POPUP_PROGRESSBAR_VIEW_LAYOUT_SUBTEXT_FONT_SIZE_INC 0 32
+
+#define POPUP_GROUP_INDEX_BG_MIN_INC 0 52
+#define POPUP_GROUP_INDEX_PROCESSING_MIN_INC 28 28
+#define POPUP_GROUP_INDEX_PROCESSING_MAX_INC 28 28
+#define POPUP_GROUP_INDEX_PADDING_BEFORE_SWALLOW_MIN_INC 15 52
+#define POPUP_GROUP_INDEX_TEXT_MIN_INC 0 52
+
+#define POPUP_TEXT_SLIDER_VIEW_LAYOUT_MIN_INC 0 144
+#define POPUP_TEXT_SLIDER_PADDING_SIZE_INC 15 27
+#define POPUP_TEXT_SLIDER_TEXT_DISCRIPTION_MIN_INC 0 38
+#define POPUP_TEXT_SLIDER_BG_MIN_INC 0 42
+#define POPUP_SLIDER_PADDING_LEFT_MIN_INC 10 0
+
+#define POPUP_2TEXT_SLIDER_VIEW_LAYOUT_MIN_INC 0 176
+#define POPUP_TEXT_SLIDER_SUBTEXT_DISCRIPTION_MIN_INC 0 32
+
+#define POPUP_SCROLLABLE_TEXT_VIEW_BG_HEIGHT_INC 252
+
+#define POPUP_PROCESSING_SWALLOW_VIEW_LAYOUT_MIN_INC 36 36
+#define POPUP_PROCESSING_SWALLOW_VIEW_LAYOUT_MAX_INC 36 36
+#define POPUP_PROCESSING_SWALLOW_VIEW_LAYOUT_PADDING_AFTER_INC 15 90
+#define POPUP_PROCESSING_SWALLOW_VIEW_LAYOUT_TEXT_MIN_INC 0 90
+#define POPUP_PROCESSING_VIEW_LAYOUT_BG_MIN_INC 0 90
+
+#define POPUP_TEXT_FONT_SIZE1 30
+#define POPUP_TEXT_FONT_SIZE2 24
+#define POPUP_TEXT_FONT_SIZE3 27
+
+group { name: "popup_image_list_layout";
+ styles {
+ style { name: "popup_content_style";
+ base: "font=Tizen:style=Regular align=left font_size="POPUP_TEXT_FONT_SIZE1" color=#FFFFFF color_class=T023 wrap=mixed ellipsis=1.0 text_class=T023";
+ tag: "br" "\n";
+ tag: "tab" "\t";
+ }
+ }
+ parts {
+ part { name: "bg";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_IMAGE_VIEW_LAYOUT_BG_MIN_INC;
+ fixed: 1 0;
+ }
+ }
+ part { name: "pad_l";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 0.0 1.0;
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "pad_r";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 1.0 0.0;
+ rel2.relative: 1.0 1.0;
+ align: 1.0 0.0;
+ }
+ }
+ part { name: "pad_t";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ align: 0.0 0.0;
+ min: 0 POPUP_CONTENT_DEFAULT_PADDING_TOP_MIN_INC;
+ fixed: 0 1;
+ rel1 {
+ relative: 1.0 0.0;to_x: "pad_l";
+ }
+ rel2 {
+ relative: 0.0 0.0;to_x: "pad_r";
+ }
+ }
+ }
+ part { name: "elm.swallow.content.bg";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 1 0;
+ rel1 {
+ relative: 1.0 1.0;
+ to_x: "pad_l";
+ to_y: "pad_t";
+ }
+ rel2 {
+ relative: 0.0 0.0;
+ to_x: "pad_r";
+ to_y: "pad_b";
+ }
+ align: 0.5 0.5;
+ }
+ }
+ part { name: "elm.swallow.content";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 1 0;
+ rel1.to: "elm.swallow.content.bg";
+ rel2.to: "elm.swallow.content.bg";
+ }
+ }
+ part { name: "pad_b";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_IMAGE_SWALLOW_CONTENT_PADDING_BOTTOM_MIN_INC;
+ fixed: 0 1;
+ rel1 {
+ relative: 1.0 0.0;
+ to_x: "pad_l";
+ to_y: "elm.text";
+ }
+ rel2 {
+ relative: 0.0 0.0;
+ to_x: "pad_r";
+ to_y: "elm.text";
+ }
+ align: 0.0 1.0;
+ }
+ }
+ part { name: "elm.text";
+ type: TEXTBLOCK;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: 0 POPUP_DESCRIPTION_DEFAULT_TEXT_FONT_SIZE_INC;
+ fixed: 0 1;
+ align: 0.0 1.0;
+ rel1 {
+ relative: 1.0 0.0;
+ to_x: "pad_l";
+ to_y: "pad_bottom";
+ }
+ rel2 {
+ relative: 0.0 0.0;
+ to_x: "pad_r";
+ to_y: "pad_bottom";
+ }
+ text {
+ style: "popup_content_style";
+ min: 0 1;
+ }
+ }
+ }
+ part { name: "pad_bottom";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ align: 0.0 1.0;
+ min: 0 POPUP_CONTENT_DEFAULT_PADDING_BOTTOM_MIN_INC;
+ fixed: 0 1;
+ rel1 {
+ relative: 1.0 1.0;
+ to_x: "pad_l";
+ }
+ rel2 {
+ relative: 0.0 1.0;
+ to_x: "pad_r";
+ }
+ }
+ }
+ }
+}
+
+group { name: "popup_checkview_layout";
+ parts {
+ part { name: "bg";
+ scale: 1;
+ type: SPACER;
+ description { state: "default" 0.0;
+ min: POPUP_CHECK_VIEW_LAYOUT_MIN_INC;
+ fixed: 1 0;
+ }
+ }
+ part { name: "pad_l";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 0.0 1.0;
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "pad_r";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_RIGHT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 1.0 0.0;
+ rel2.relative: 1.0 1.0;
+ align: 1.0 0.0;
+ }
+ }
+ part { name: "elm.swallow.content";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 0 1;
+ min: POPUP_CHECK_VIEW_LAYOUT_CONTENT_MIN_INC;
+ align: 0.5 0.0;
+ rel2 {
+ relative: 1.0 0.0;
+ to: "pad_b";
+ }
+ }
+ }
+ part { name: "pad_b";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ align: 0.0 1.0;
+ min: POPUP_CHECK_VIEW_LAYOUT_BOTTOM_MIN_INC;
+ fixed: 0 1;
+ rel1.relative: 0.0 1.0;
+ }
+ }
+ part { name: "elm.swallow.end";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ align: 0.0 0.5;
+ min: POPUP_CHECK_VIEW_SWALLOW_END_MIN_INC;
+ fixed: 1 1;
+ rel1 {
+ relative: 1.0 1.0;
+ to_x: "pad_l";
+ to_y: "pad_b";
+ }
+ rel2 {
+ relative: 0.0 0.0;
+ to_x: "pad_r";
+ to_y: "pad_b";
+ }
+ }
+ }
+ }
+}
+
+group { name: "processing_view_layout";
+ styles {
+ style { name: "popup_processing_style";
+ base: "font=Tizen:style=Regular align=left font_size="POPUP_TEXT_FONT_SIZE1" color=#FFFFFF color_class=T123 wrap=mixed ellipsis=1.0 text_class=T123";
+ tag: "br" "\n";
+ tag: "tab" "\t";
+ }
+ }
+ parts {
+ part { name: "bg";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_PROCESSING_VIEW_LAYOUT_BG_MIN_INC;
+ fixed: 1 0;
+ }
+ }
+ part { name: "pad_l";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 0.0 1.0;
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "pad_r";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 1.0 0.0;
+ rel2.relative: 1.0 1.0;
+ align: 1.0 0.0;
+ }
+ }
+ part { name: "processing";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 1 1;
+ min: POPUP_PROCESSING_SWALLOW_VIEW_LAYOUT_MIN_INC;
+ max: POPUP_PROCESSING_SWALLOW_VIEW_LAYOUT_MAX_INC;
+ rel1 {
+ relative: 1.0 0.0;
+ to_x: "pad_l";
+ }
+ rel2 {
+ relative: 0.0 1.0;
+ to_x: "pad_r";
+ }
+ align: 0.0 0.5;
+ }
+ }
+ part { name: "pad_after_processing";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 1 1;
+ min: POPUP_PROCESSING_SWALLOW_VIEW_LAYOUT_PADDING_AFTER_INC;
+ rel1 {
+ relative: 1.0 0.0;
+ to: "processing";
+ }
+ rel2.to: "processing";
+ align: 0.0 0.5;
+ }
+ }
+ part { name: "elm.text";
+ type: TEXTBLOCK;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_PROCESSING_SWALLOW_VIEW_LAYOUT_TEXT_MIN_INC;
+ fixed: 0 1;
+ rel1 {
+ relative: 1.0 0.0;
+ to: "pad_after_processing";
+ }
+ rel2 {
+ relative: 0.0 1.0;
+ to_x: "pad_r";
+ }
+ align: 0.0 0.5;
+ text {
+ style: "popup_processing_style";
+ min: 0 1;
+ }
+ }
+ }
+ }
+}
+
+group { name: "popup_text_progressbar_view_layout";
+ styles {
+ style { name: "popup_progress_style";
+ base: "font=Tizen:style=Regular align=right font_size="14" color=#FFFFFF color_class=T056 wrap=mixed ellipsis=1.0 text_class=T056";
+ tag: "br" "\n";
+ tag: "tab" "\t";
+ }
+ }
+ parts {
+ part { name: "bg";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_PROGRESSBAR_VIEW_LAYOUT_BG_MIN_INC;
+ fixed: 1 0;
+ }
+ }
+ part { name: "pad_l_t";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_PROGRESSBAR_VIEW_LAYOUT_PADDING_INC;
+ max: POPUP_PROGRESSBAR_VIEW_LAYOUT_PADDING_INC;
+ fixed: 1 1;
+ rel2.relative: 0.0 0.0;
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "pad_r_t";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_PROGRESSBAR_VIEW_LAYOUT_PADDING_INC;
+ max: POPUP_PROGRESSBAR_VIEW_LAYOUT_PADDING_INC;
+ fixed: 1 1;
+ rel1.relative: 1.0 1.0;
+ align: 1.0 1.0;
+ }
+ }
+ part { name: "elm.text.description";
+ type: TEXTBLOCK;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 0 1;
+ min: POPUP_PROGRESSBAR_VIEW_LAYOUT_TEXT_FONT_SIZE_INC;
+ rel1 {
+ relative: 1.0 1.0;
+ to: "pad_l_t";
+ }
+ rel2 {
+ relative: 0.0 1.0;
+ to_x: "pad_r_t";
+ to_y: "pad_l_t";
+ }
+ text {
+ style: "popup_processing_style";
+ min: 0 1;
+ }
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "progressbar_bg";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 0 1;
+ min: POPUP_PROGRESSBAR_VIEW_LAYOUT_BG_INC;
+ rel1 {
+ relative: 1.0 1.0;
+ to_x: "pad_l_t";
+ to_y: "elm.text.description";
+ }
+ rel2 {
+ relative: 0.0 1.0;
+ to_x: "pad_r_t";
+ to_y: "elm.text.description";
+ }
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "progressbar";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 0 1;
+ rel1.to: "progressbar_bg";
+ rel2.to: "progressbar_bg";
+ }
+ }
+ }
+}
+
+group { name: "popup_2text_progressbar_view_layout";
+ styles {
+ style { name: "popup_subtext_style";
+ base: "font=Tizen:style=Regular align=left font_size="POPUP_TEXT_FONT_SIZE2" color=#FFFFFF color_class=T024 wrap=mixed ellipsis=1.0 text_class=T024";
+ tag: "br" "\n";
+ tag: "tab" "\t";
+ }
+ }
+ parts {
+ part { name: "bg";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_PROGRESSBAR_2TEXT_VIEW_LAYOUT_BG_MIN_INC;
+ fixed: 1 0;
+ }
+ }
+ part { name: "pad_l_t";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_PROGRESSBAR_VIEW_LAYOUT_PADDING_INC;
+ max: POPUP_PROGRESSBAR_VIEW_LAYOUT_PADDING_INC;
+ fixed: 1 1;
+ rel2.relative: 0.0 0.0;
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "pad_r_t";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_PROGRESSBAR_VIEW_LAYOUT_PADDING_INC;
+ max: POPUP_PROGRESSBAR_VIEW_LAYOUT_PADDING_INC;
+ fixed: 1 1;
+ rel1.relative: 1.0 1.0;
+ align: 1.0 1.0;
+ }
+ }
+ part { name: "elm.text.description";
+ type: TEXTBLOCK;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_PROGRESSBAR_VIEW_LAYOUT_TEXT_FONT_SIZE_INC;
+ fixed: 0 1;
+ rel1 {
+ relative: 1.0 1.0;
+ to: "pad_l_t";
+ }
+ rel2 {
+ relative: 0.0 1.0;
+ to_x: "pad_r_t";
+ to_y: "pad_l_t";
+ }
+ text {
+ style: "popup_processing_style";
+ min: 0 1;
+ }
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "elm.subtext.description";
+ type: TEXTBLOCK;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_PROGRESSBAR_VIEW_LAYOUT_SUBTEXT_FONT_SIZE_INC;
+ fixed: 0 1;
+ rel1 {
+ relative: 1.0 1.0;
+ to_x: "pad_l_t";
+ to_y: "elm.text.description";
+ }
+ rel2 {
+ relative: 0.0 1.0;
+ to_x: "pad_r_t";
+ to_y: "elm.text.description";
+ }
+ text {
+ style: "popup_subtext_style";
+ min: 0 1;
+ }
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "progressbar_bg";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 0 1;
+ min: POPUP_PROGRESSBAR_VIEW_LAYOUT_BG_INC;
+ rel1 {
+ relative: 1.0 1.0;
+ to_x: "pad_l_t";
+ to_y: "elm.subtext.description";
+ }
+ rel2 {
+ relative: 0.0 1.0;
+ to_x: "pad_r_t";
+ to_y: "elm.subtext.description";
+ }
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "progressbar";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 0 1;
+ rel1.to: "progressbar_bg";
+ rel2.to: "progressbar_bg";
+ }
+ }
+ }
+}
+
+group { name: "popup_groupindex_view_layout";
+ styles {
+ style { name: "popup_groupindex_style";
+ base: "font=Tizen:style=Regular align=right font_size="POPUP_TEXT_FONT_SIZE3" color=#FFFFFF color_class=T028 wrap=mixed ellipsis=1.0 text_class=T028";
+ tag: "br" "\n";
+ tag: "tab" "\t";
+ }
+ }
+ parts {
+ part { name: "bg";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ }
+ }
+ part { name: "pad_l";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 0.0 1.0;
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "pad_r";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_RIGHT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 1.0 0.0;
+ rel2.relative: 1.0 1.0;
+ align: 1.0 0.0;
+ }
+ }
+ part { name: "index_bg";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_GROUP_INDEX_BG_MIN_INC;
+ fixed: 0 1;
+ rel1 {
+ relative: 1.0 0.0;
+ to: "pad_l";
+ }
+ rel2 {
+ relative: 0.0 0.0;
+ to: "pad_r";
+ }
+ align: 0.5 0.0;
+ }
+ }
+ part { name: "processing";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_GROUP_INDEX_PROCESSING_MIN_INC;
+ max: POPUP_GROUP_INDEX_PROCESSING_MAX_INC;
+ rel1 {
+ relative: 1.0 0.0;
+ to: "index_bg";
+ }
+ rel2.to: "index_bg";
+ align: 1.0 0.5;
+ }
+ }
+ part { name: "pad_before_swallow";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_GROUP_INDEX_PADDING_BEFORE_SWALLOW_MIN_INC;
+ rel1 {
+ relative: 0.0 0.0;
+ to: "processing";
+ }
+ rel2 {
+ relative: 0.0 1.0;
+ to: "processing";
+ }
+ align: 1.0 0.5;
+ }
+ }
+ part { name: "elm.text";
+ type: TEXTBLOCK;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_GROUP_INDEX_TEXT_MIN_INC;
+ fixed: 0 1;
+ rel1 {
+ relative: 0.0 0.0;
+ to: "index_bg";
+ }
+ rel2 {
+ relative: 0.0 1.0;
+ to_x: "pad_before_swallow";
+ to_y: "index_bg";
+ }
+ align: 0.5 0.0;
+ text {
+ style: "popup_groupindex_style";
+ min: 0 1;
+ }
+ }
+ }
+ part { name: "genlist";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ rel1 {
+ relative: 0.0 1.0;
+ to_y: "index_bg";
+ }
+ align: 0.5 0.0;
+ }
+ }
+ }
+}
+
+group { name: "popup_text_slider_view_layout";
+ parts {
+ part { name: "bg";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_TEXT_SLIDER_VIEW_LAYOUT_MIN_INC;
+ fixed: 1 0;
+ }
+ }
+ part { name: "pad_l_t";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_TEXT_SLIDER_PADDING_SIZE_INC;
+ max: POPUP_TEXT_SLIDER_PADDING_SIZE_INC;
+ fixed: 1 1;
+ rel1 {
+ relative: 0.0 0.0;
+ }
+ rel2 {
+ relative: 0.0 0.0;
+ }
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "pad_r_t";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_TEXT_SLIDER_PADDING_SIZE_INC;
+ max: POPUP_TEXT_SLIDER_PADDING_SIZE_INC;
+ fixed: 1 1;
+ rel1.relative: 1.0 1.0;
+ rel2.relative: 1.0 1.0;
+ align: 1.0 1.0;
+ }
+ }
+ part { name: "elm.text.description";
+ type: TEXTBLOCK;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 0 1;
+ min: POPUP_TEXT_SLIDER_TEXT_DISCRIPTION_MIN_INC;
+ rel1 {
+ relative: 1.0 1.0;
+ to: "pad_l_t";
+ }
+ rel2 {
+ relative: 0.0 1.0;
+ to_x: "pad_r_t";
+ to_y: "pad_l_t";
+ }
+ text {
+ style: "popup_processing_style";
+ min: 0 1;
+ }
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "slider";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 0 1;
+ min: POPUP_TEXT_SLIDER_BG_MIN_INC;
+ rel1 {
+ relative: 1.0 0.0;
+ to_y: "pad_r_t";
+ to_x: "pad_l_t";
+ }
+ rel2 {
+ relative: 0.0 0.0;
+ to: "pad_r_t";
+ }
+ align: 0.0 1.0;
+ }
+ }
+ }
+}
+
+group { name: "popup_2text_slider_view_layout";
+ parts {
+ part { name: "bg";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_2TEXT_SLIDER_VIEW_LAYOUT_MIN_INC;
+ fixed: 1 0;
+ }
+ }
+ part { name: "pad_l_t";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_TEXT_SLIDER_PADDING_SIZE_INC;
+ max: POPUP_TEXT_SLIDER_PADDING_SIZE_INC;
+ fixed: 1 1;
+ rel1 {
+ relative: 0.0 0.0;
+ }
+ rel2 {
+ relative: 0.0 0.0;
+ }
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "pad_r_t";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_TEXT_SLIDER_PADDING_SIZE_INC;
+ max: POPUP_TEXT_SLIDER_PADDING_SIZE_INC;
+ fixed: 1 1;
+ rel1.relative: 1.0 1.0;
+ rel2.relative: 1.0 1.0;
+ align: 1.0 1.0;
+ }
+ }
+ part { name: "elm.text.description";
+ type: TEXTBLOCK;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 0 1;
+ min: POPUP_TEXT_SLIDER_TEXT_DISCRIPTION_MIN_INC;
+ rel1 {
+ relative: 1.0 1.0;
+ to: "pad_l_t";
+ }
+ rel2 {
+ relative: 0.0 1.0;
+ to_x: "pad_r_t";
+ to_y: "pad_l_t";
+ }
+ text {
+ style: "popup_processing_style";
+ min: 0 1;
+ }
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "elm.subtext.description";
+ type: TEXTBLOCK;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_TEXT_SLIDER_SUBTEXT_DISCRIPTION_MIN_INC;
+ fixed: 0 1;
+ rel1 {
+ relative: 1.0 1.0;
+ to_x: "pad_l_t";
+ to_y: "elm.text.description";
+ }
+ rel2 {
+ relative: 0.0 1.0;
+ to_x: "pad_r_t";
+ to_y: "elm.text.description";
+ }
+ text {
+ style: "popup_subtext_style";
+ min: 0 1;
+ }
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "slider";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ fixed: 0 1;
+ min: POPUP_TEXT_SLIDER_BG_MIN_INC;
+ rel1 {
+ relative: 1.0 0.0;
+ to_y: "pad_r_t";
+ to_x: "pad_l_t";
+ }
+ rel2 {
+ relative: 0.0 0.0;
+ to: "pad_r_t";
+ }
+ align: 0.0 1.0;
+ }
+ }
+ }
+}
+
+group { name: "popup_scrollable_text";
+ parts {
+ part { name: "bg";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: 0 POPUP_SCROLLABLE_TEXT_VIEW_BG_HEIGHT_INC;
+ max: -1 POPUP_SCROLLABLE_TEXT_VIEW_BG_HEIGHT_INC;
+ }
+ }
+ part { name: "elm.swallow.content";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ }
+ }
+ }
+}
+
+group { name: "popup_input_text";
+ parts {
+ part { name: "pad_l";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 0.0 1.0;
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "pad_r";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC 0;
+ fixed: 1 0;
+ rel1.relative: 1.0 0.0;
+ rel2.relative: 1.0 1.0;
+ align: 1.0 0.0;
+ }
+ }
+ part { name: "elm.swallow.content";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: 0 POPUP_EDITFIELD_LAYOUT_MINMAX_HEIGHT_INC;
+ max: -1 POPUP_EDITFIELD_LAYOUT_MINMAX_HEIGHT_INC;
+ align: 0.5 0.5;
+ rel1{
+ relative: 1.0 0.0 ;
+ to_x: "pad_l";
+ }
+ rel2{
+ relative: 0.0 1.0;
+ to_x: "pad_r";
+ }
+ }
+ }
+ }
+}
+
+group { name: "popup_text_input_text";
+ styles {
+ style { name: "popup_input_style";
+ base: "font=Tizen:style=Regular align=left font_size="POPUP_TEXT_FONT_SIZE1" color=#FFFFFF color_class=T123 wrap=mixed text_class=T123";
+ tag: "br" "\n";
+ tag: "tab" "\t";
+ }
+ }
+
+ parts {
+ part { name: "bg";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_TEXT_INPUTTEXT_VIEW_LAYOUT_BG_MIN_INC;
+ }
+ }
+ part { name: "pad_l_t";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC POPUP_CONTENT_DEFAULT_PADDING_TOP_MIN_INC;
+ max: POPUP_CONTENT_DEFAULT_PADDING_LEFT_MIN_INC POPUP_CONTENT_DEFAULT_PADDING_TOP_MIN_INC;
+ fixed: 1 1;
+ rel1.to: "bg";
+ rel2 {
+ relative: 0.0 0.0;
+ to: "bg";
+ }
+ align: 0.0 0.0;
+ }
+ }
+ part { name: "pad_r_b";
+ type: SPACER;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: POPUP_CONTENT_DEFAULT_PADDING_RIGHT_MIN_INC POPUP_CONTENT_DEFAULT_PADDING_TOP_MIN_INC;
+ max: POPUP_CONTENT_DEFAULT_PADDING_RIGHT_MIN_INC POPUP_CONTENT_DEFAULT_PADDING_TOP_MIN_INC;
+ fixed: 1 1;
+ rel1 {
+ relative: 1.0 1.0;
+ to: "bg";
+ }
+ rel2.to: "bg";
+ align: 1.0 1.0;
+ }
+ }
+ part { name: "elm.text.description";
+ type: TEXTBLOCK;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: 0 POPUP_DESCRIPTION_DEFAULT_TEXT_FONT_SIZE_INC;
+ rel1 {
+ relative: 1.0 1.0;
+ to: "pad_l_t";
+ }
+ rel2 {
+ relative: 0.0 0.0;
+ to_x: "pad_r_b";
+ to_y: "elm.swallow.content";
+ }
+ text {
+ style: "popup_input_style";
+ min: 0 1;
+ }
+ align: 0.5 0.0;
+ }
+ }
+ part { name: "elm.swallow.content";
+ type: SWALLOW;
+ scale: 1;
+ description { state: "default" 0.0;
+ min: 0 POPUP_EDITFIELD_LAYOUT_MINMAX_HEIGHT_INC;
+ max: -1 POPUP_EDITFIELD_LAYOUT_MINMAX_HEIGHT_INC;
+ fixed: 0 1;
+ align: 0.0 1.0;
+ rel1{
+ relative: 1.0 0.0 ;
+ to_x: "pad_l_t";
+ to_y: "pad_r_b";
+ }
+ rel2{
+ relative: 0.0 0.0;
+ to: "pad_r_b";
+ }
+ }
+ }
+ }
+}
+
+}
}
group {
- name: circle_layout;
+ name: "circle_layout";
parts {
part {
name: masking;
}
}
+ group {
+ name: "main_circle_layout";
+ parts {
+ part {
+ name: masking;
+ type: IMAGE;
+ precise_is_inside: 1;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.3 0.2;
+ rel2.relative: 0.7 0.8;
+ image.normal: camera_btn_gallery_mask.png;
+ }
+ }
+ part {
+ name: content;
+ type: SWALLOW;
+ clip_to: masking;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 1.0 1.0;
+ }
+ }
+ }
+ }
group {
type:SWALLOW;
description{
state: "default" 0.0;
- min: WIN_WIDTH 100;
- max: WIN_WIDTH 100;
+ min: 0 0;
+ max: 0 0;
fixed: 1 1;
align: 0 1;
rel1 { relative: 0.0 1.0; to: "bg"; }
state: "default" 0.0;
rel1 { relative: 0.0 0.0; }
rel2 { relative: 1.0 1.0; }
- color: 255 255 255 255;
+ color: 0 0 0 0;
}
- }
- part {
- name: "layout_divider,bg";
- type: RECT;
- description {
- state: "default" 0.0;
- rel1 { relative: 0.0 0.0; }
- rel2 { relative: 1.0 0.01; }
- color: 61 185 204 255;
- }
- }
+ }
+
part{
name: "swallow.smiely_icon";
type:SWALLOW;
description{
state: "default" 0.0;
- rel1 { relative: 0.05 0.2; }
- rel2 { relative: 0.15 0.92; }
+ rel1 { relative: 0.0 0.2; }
+ rel2 { relative: 0.1 0.92; }
}
}
type:SWALLOW;
description{
state: "default" 0.0;
- rel1 { relative: 0.16 0.1; }
- rel2 { relative: 0.74 0.9; }
+ rel1 { relative: 0.11 0.1; }
+ rel2 { relative: 0.79 0.9; }
}
}
part{
type:SWALLOW;
description{
state: "default" 0.0;
- rel1 { relative: 0.75 0.2; }
- rel2 { relative: 0.85 0.92; }
+ rel1 { relative: 0.79 0.2; }
+ rel2 { relative: 0.89 0.92; }
}
}
part{
type:SWALLOW;
description{
state: "default" 0.0;
- rel1 { relative: 0.87 0.1; }
- rel2 { relative: 0.97 0.97; }
+ rel1 { relative: 0.9 0.1; }
+ rel2 { relative: 1.0 0.97; }
}
}
}
state: "default" 0.0;
rel1 { relative: 0.0 0.0; }
rel2 { relative: 1.0 1.0; }
- color: 0 0 0 0;
+ color: 255 0 0 0;
}
}
part{
color: 0 0 0 0;
}
}
+
+ part{
+ name: "swallow.chat_play";
+ type:SWALLOW;
+ description{
+ state: "default" 0.0;
+ rel1 { relative: 0.4 0.45; }
+ rel2 { relative: 0.6 0.65; }
+ color: 255 0 0 255;
+ }
+ }
+
part{
name: "swallow.chat_send_time";
type:SWALLOW;
}
}
+
+ group
+ {
+ name: "chat_service_item_box";
+ parts{
+ part {
+ name: "chat_service_bg,color";
+ type: RECT;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.0 0.0; }
+ rel2 { relative: 1.0 1.0; }
+ color: 225 237 241 0;
+ }
+ }
+ part {
+ name: "chat_service_bg";
+ type: RECT;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.0 0.0; to, "swallow.chat_service_text"; }
+ rel2 { relative: 1.0 1.0; to, "swallow.chat_service_text"; }
+ color: 225 237 241 0;
+ }
+ }
+ part{
+ name: "chat_serv_image";
+ type:IMAGE;
+ description{
+ state: "default" 0.0;
+ rel1 { relative: 0.0 -0.2; to, "chat_service_bg"; }
+ rel2 { relative: 1.0 0.9; to, "chat_service_bg"; }
+ image {
+ border: 10 10 20 20;
+ normal: "msg_out_photo.9.png";
+ }
+ }
+ }
+ part{
+ name: "swallow.chat_service_text";
+ type:SWALLOW;
+ description{
+ state: "default" 0.0;
+ rel1 { relative: 0.1 0.2; }
+ rel2 { relative: 0.9 0.8; }
+ }
+ }
+ }
+ }
+
group
{
state: "default" 0.0;
rel1 { relative: 0.0 0.0; }
rel2 { relative: 1.0 1.0; }
- color: 225 237 241 255;
+ color: 225 237 241 0;
}
}
part{
type:SWALLOW;
description{
state: "default" 0.0;
- rel1 { relative: 0.4 0.1; }
- rel2 { relative: 0.7 0.9; }
+ rel1 { relative: 0.3 0.1; }
+ rel2 { relative: 0.8 0.9; }
color: 255 0 0 255;
}
}
state: "default" 0.0;
rel1 { relative: 0.0 0.0; }
rel2 { relative: 1.0 1.0; }
- color: 225 237 241 255;
+ color: 225 237 241 0;
}
}
part{
group {
name: "main_list_name_status_item";
parts {
+ part {
+ name: "swallow.name.rect";
+ type: RECT;
+ description {
+ state: default 0.0;
+ min: 150 0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 1.0 0.5;
+ color: 255 0 0 0;
+ }
+ }
part {
name: "swallow.name";
type: SWALLOW;
description {
state: default 0.0;
+ min: 150 0;
rel1.relative: 0.0 0.0;
rel2.relative: 1.0 0.5;
color: 255 0 0 255;
type: SWALLOW;
description {
state: default 0.0;
+ min: 150 0;
rel1.relative: 0.0 0.5;
rel2.relative: 1.0 1.0;
color: 0 255 0 255;
}
}
+
+ group {
+ name: "peer_search_main_layout";
+ parts {
+ part {
+ name: "swallow.search_area,bg";
+ type: RECT;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 1.0 0.1;
+ color: 222 222 222 222;
+ }
+ }
+
+ part {
+ name: "swallow.search_area";
+ type: SWALLOW;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 1.0 0.1;
+ }
+ }
+ part {
+ name: "swallow.peerlist";
+ type: SWALLOW;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.0 0.1;
+ rel2.relative: 1.0 1.0;
+ }
+ }
+
+ }
+ }
+
+ group {
+ name: "bubble_media_layout";
+ parts {
+ part {
+ name: "swallow.media_item";
+ type: SWALLOW;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 1.0 1.0;
+ color: 255 0 0 0;
+ }
+ description {
+ state: "landscape" 0.0;
+ inherit: "default" 0.0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 1.0 1.0;
+ }
+ }
+ }
+ programs {
+ program {
+ name: "change.view";
+ signal: "change,view";
+ source: "swallow.media_item";
+ action: STATE_SET "landscape" 0.0;
+ target: "swallow.media_item";
+ }
+ }
+ }
+
+ group {
+ name: "bubble_received_media_layout";
+ parts {
+ part {
+ name: "swallow.image_item";
+ type: SWALLOW;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 1.0 1.0;
+ color: 255 0 0 255;
+ }
+ }
+ part {
+ name: "swallow.download_btn";
+ type: SWALLOW;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.1 0.4;
+ rel2.relative: 0.9 0.6;
+ color: 0 255 0 255;
+ }
+ }
+ }
+ }
+
+ group {
+ name: "bubble_video_item_layout";
+ parts {
+ part {
+ name: "swallow.video_thumb_item";
+ type: SWALLOW;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 1.0 1.0;
+ color: 255 0 0 255;
+ }
+ }
+ part {
+ name: "swallow.play_btn";
+ type: SWALLOW;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.35 0.35;
+ rel2.relative: 0.65 0.65;
+ color: 0 255 0 255;
+ }
+ }
+ }
+ }
+
+
+ group {
+ name: "settings_screen";
+ parts {
+ part {
+ name: "pic_name_layout";
+ type: SWALLOW;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.0 0.0; }
+ rel2 { relative: 1.0 0.25; }
+ color: 61 185 204 255;
+ }
+ }
+ part {
+ name: "user_info,bg";
+ type: RECT;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.0 0.25; }
+ rel2 { relative: 1.0 0.32; }
+ color: 96 96 96 255;
+ }
+ }
+ part {
+ name: "user_info";
+ type: SWALLOW;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.0 0.25; }
+ rel2 { relative: 1.0 0.32; }
+ color: 255 255 255 255;
+ }
+ }
+ part {
+ name: "phone_num_layout";
+ type: SWALLOW;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.0 0.32; }
+ rel2 { relative: 1.0 0.63; }
+ color: 61 185 204 255;
+ }
+ }
+ part {
+ name: "settings_info,bg";
+ type: RECT;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.0 0.63; }
+ rel2 { relative: 1.0 0.70; }
+ color: 96 96 96 255;
+ }
+ }
+ part {
+ name: "settings_info";
+ type: SWALLOW;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.0 0.63; }
+ rel2 { relative: 1.0 0.70; }
+ color: 255 255 255 255;
+ }
+ }
+ part {
+ name: "setting_option_layout";
+ type: SWALLOW;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.0 0.70; }
+ rel2 { relative: 1.0 1.0; }
+ color: 255 255 255 255;
+ }
+ }
+ part {
+ name: "cam_layout";
+ type: SWALLOW;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.75 0.19; }
+ rel2 { relative: 0.95 0.32; }
+ color: 255 0 0 255;
+ }
+ }
+ }
+ }
+
+ group {
+ name: "set_user_name_layout";
+ parts {
+ part {
+ name: "set_user_name_layout,bg";
+ type: RECT;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.0 0.0;
+ rel2.relative: 1.0 1.0;
+ color: 255 255 255 255;
+ }
+ }
+ part {
+ name: "swallow.entry_box";
+ type: SWALLOW;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.1 0.05;
+ rel2.relative: 0.9 0.15;
+ color: 255 0 0 255;
+ }
+ }
+ part {
+ name: "swallow.entry_box,bg";
+ type: RECT;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.1 0.145;
+ rel2.relative: 0.9 0.15;
+ color: 0 0 255 255;
+ }
+ }
+ part {
+ name: "swallow.help_text_one";
+ type: SWALLOW;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.1 0.25;
+ rel2.relative: 0.9 0.45;
+ color: 0 255 0 255;
+ }
+ }
+ part {
+ name: "swallow.help_text_two";
+ type: SWALLOW;
+ description {
+ state: default 0.0;
+ rel1.relative: 0.1 0.47;
+ rel2.relative: 0.9 0.77;
+ color: 0 255 0 255;
+ }
+ }
+ }
+ }
+
+
+ group {
+ name: "chat_info_screen";
+ parts {
+ part {
+ name: "pic_name_layout";
+ type: SWALLOW;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.0 0.0; }
+ rel2 { relative: 1.0 0.25; }
+ color: 61 185 204 255;
+ }
+ }
+ part {
+ name: "user_info,bg";
+ type: RECT;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.0 0.25; }
+ rel2 { relative: 1.0 0.32; }
+ color: 96 96 96 255;
+ }
+ }
+ part {
+ name: "user_info";
+ type: SWALLOW;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.0 0.25; }
+ rel2 { relative: 1.0 0.32; }
+ color: 255 255 255 255;
+ }
+ }
+ part {
+ name: "phone_num_layout";
+ type: SWALLOW;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.0 0.32; }
+ rel2 { relative: 1.0 1.0; }
+ color: 61 185 204 255;
+ }
+ }
+ part {
+ name: "cam_layout";
+ type: SWALLOW;
+ description {
+ state: "default" 0.0;
+ rel1 { relative: 0.75 0.19; }
+ rel2 { relative: 0.95 0.32; }
+ color: 255 0 0 255;
+ }
+ }
+ }
+ }
}
type: RECT;
repeat_events: 1;
description { state: "default" 0.0;
- color: 225 237 241 255;
+ color: 225 237 241 0;
}
}
part { name: "elm.select_icon.pad";
type: RECT;
repeat_events: 1;
description { state: "default" 0.0;
- color: 225 237 241 255;
+ color: 225 237 241 0;
}
}
part { name: "elm.select_icon.pad";
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<res xmlns="http://tizen.org/ns/rm"/>
*/
#include "server_requests.h"
+#include "tg_db_wrapper.h"
#include "device_contacts_manager.h"
void send_request_for_registration(service_client* service_client, const char* phone_number, Eina_Bool through_sms)
bundle_free(msg);
}
+void send_add_buddy_request(service_client* service_client, const int buddy_id)
+{
+ if (!service_client) {
+ // error
+ return;
+ }
+ bundle *msg;
+ char tmp[50];
+ int result;
+ msg = bundle_create();
+ if (!msg) {
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "add_buddy") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+ snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", tmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ }
+ bundle_free(msg);
+}
+
+void send_delete_buddy_request(service_client* service_client, const int buddy_id)
+{
+ if (!service_client) {
+ // error
+ return;
+ }
+ bundle *msg;
+ char tmp[50];
+ int result;
+ msg = bundle_create();
+ if (!msg) {
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "delete_buddy") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+ snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", tmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ }
+ bundle_free(msg);
+}
+
+
+void send_block_buddy_request(service_client* service_client, const int buddy_id)
+{
+ if (!service_client) {
+ // error
+ return;
+ }
+ bundle *msg;
+ char tmp[50];
+ int result;
+ msg = bundle_create();
+ if (!msg) {
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "block_buddy") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+ snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", tmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ }
+ bundle_free(msg);
+}
+
+void send_unblock_buddy_request(service_client* service_client, const int buddy_id)
+{
+ if (!service_client) {
+ // error
+ return;
+ }
+ bundle *msg;
+ char tmp[50];
+ int result;
+ msg = bundle_create();
+ if (!msg) {
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "unblock_buddy") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+ snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", tmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ }
+ bundle_free(msg);
+}
+
+
+void send_delete_group_chat_request(service_client* service_client, const int chat_id)
+{
+ if (!service_client) {
+ // error
+ return;
+ }
+ bundle *msg;
+ char tmp[50];
+ int result;
+ msg = bundle_create();
+ if (!msg) {
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "delete_group_chat_request") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+ snprintf(tmp, sizeof(tmp) - 1, "%d", chat_id);
+
+ if (bundle_add_str(msg, "chat_id", tmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ }
+ bundle_free(msg);
+
+}
+
void send_request_for_marked_as_read(service_client* service_client, const int buddy_id, const int type_of_chat)
{
bundle *msg;
bundle_free(msg);
}
-void send_request_for_message_transport(service_client* service_client, const int buddy_id, const int message_id, const int msg_type, const char* data, const int type_of_chat)
+void send_request_for_message_transport(appdata_s *ad, service_client* service_client, const int buddy_id, const int message_id, const int msg_type, const char* data, const int type_of_chat)
{
char tmp[50];
bundle *msg;
int result;
-
+ char *buddy_id_str = NULL;
+ char *msg_id_str = NULL;
+ char *msg_type_str = NULL;
+ char *type_of_chat_str = NULL;
if (!service_client || !data) {
// error
return;
}
snprintf(tmp, sizeof(tmp), "%d", buddy_id);
-
+ buddy_id_str = strdup(tmp);
if (bundle_add_str(msg, "buddy_id", tmp) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
snprintf(tmp, sizeof(tmp) - 1, "%d", message_id);
-
+ msg_id_str = strdup(tmp);
if (bundle_add_str(msg, "message_id", tmp) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
snprintf(tmp, sizeof(tmp) - 1, "%d", msg_type);
-
+ msg_type_str = strdup(tmp);
if (bundle_add_str(msg, "message_type", tmp) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
snprintf(tmp, sizeof(tmp) - 1, "%d", type_of_chat);
-
+ type_of_chat_str = strdup(tmp);
if (bundle_add_str(msg, "type_of_chat", tmp) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
result = service_client_send_message(service_client, msg);
- if(result != SVC_RES_OK) {
+ if (result != SVC_RES_OK || !ad->is_server_ready) {
// error
+ insert_unsent_message_to_db("Tizen Telegram", "message_transport", buddy_id_str, msg_id_str, msg_type_str, data, type_of_chat_str);
}
bundle_free(msg);
+
+ if (buddy_id_str) {
+ free(buddy_id_str);
+ buddy_id_str = NULL;
+ }
+
+ if (msg_id_str) {
+ free(msg_id_str);
+ msg_id_str = NULL;
+ }
+
+ if (msg_type_str) {
+ free(msg_type_str);
+ msg_type_str = NULL;
+ }
+
+ if (type_of_chat_str) {
+ free(type_of_chat_str);
+ type_of_chat_str = NULL;
+ }
+
}
-void send_request_for_media_transport(service_client* service_client, const int buddy_id, const int message_id, const int media_id, const int msg_type, const char* file_path, const int type_of_chat)
+void send_request_for_media_transport(appdata_s *ad, service_client* service_client, const int buddy_id, const int message_id, const int media_id, const int msg_type, const char* file_path, const int type_of_chat)
{
bundle *msg;
char tmp[50];
int result;
-
- if (!service_client || !file_path) {
+ char *buddy_id_str = NULL;
+ char *msg_id_str = NULL;
+ char *media_id_str = NULL;
+ char *msg_type_str = NULL;
+ char *type_of_chat_str = NULL;
+ if (!service_client) {
// error
return;
}
}
snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id);
-
+ buddy_id_str = strdup(tmp);
if (bundle_add_str(msg, "buddy_id", tmp) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
snprintf(tmp, sizeof(tmp) - 1, "%d", message_id);
-
+ msg_id_str = strdup(tmp);
if (bundle_add_str(msg, "message_id", tmp) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
snprintf(tmp, sizeof(tmp) - 1, "%d", media_id);
+ media_id_str = strdup(tmp);
if (bundle_add_str(msg, "media_id", tmp) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
sprintf(tmp, "%d", msg_type);
-
+ msg_type_str = strdup(tmp);
if (bundle_add_str(msg, "message_type", tmp) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
return;
}
- if (bundle_add_str(msg, "file_path", file_path) != 0) {
- ERR("Failed to add data by key to bundle");
- bundle_free(msg);
- return;
+ if (file_path) {
+ if (bundle_add_str(msg, "file_path", file_path) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+ } else {
+ if (bundle_add_str(msg, "file_path", "") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
}
snprintf(tmp, sizeof(tmp) - 1, "%d", type_of_chat);
-
+ type_of_chat_str = strdup(tmp);
if (bundle_add_str(msg, "type_of_chat", tmp) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
result = service_client_send_message(service_client, msg);
- if(result != SVC_RES_OK) {
- // error
+ if (result != SVC_RES_OK || !ad->is_server_ready) {
+ insert_unsent_media_message_to_db("Tizen Telegram", "message_transport", buddy_id_str, msg_id_str, media_id_str, msg_type_str, file_path, type_of_chat_str);
}
bundle_free(msg);
+
+ if(buddy_id_str) {
+ free(buddy_id_str);
+ buddy_id_str = NULL;
+ }
+ if(msg_id_str) {
+ free(msg_id_str);
+ msg_id_str = NULL;
+ }
+ if(media_id_str) {
+ free(media_id_str);
+ media_id_str = NULL;
+ }
+ if(msg_type_str) {
+ free(msg_type_str);
+ msg_type_str = NULL;
+ }
+ if(type_of_chat_str) {
+ free(type_of_chat_str);
+ type_of_chat_str = NULL;
+ }
}
-void send_request_for_image_downloading(service_client* service_client, const int buddy_id, const long long media_id)
+Eina_Bool send_request_for_media_downloading(service_client* service_client, const int buddy_id, const long long media_id)
{
bundle *msg;
char tmp[50];
if (!service_client) {
// error
- return;
+ return EINA_FALSE;
}
msg = bundle_create();
if (!msg) {
- return;
+ return EINA_FALSE;
}
if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
+ return EINA_FALSE;
}
if (bundle_add_str(msg, "command", "media_download_request") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
+ return EINA_FALSE;
}
snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id);
result = service_client_send_message(service_client, msg);
if(result != SVC_RES_OK) {
- // error
+ return EINA_FALSE;
}
bundle_free(msg);
+ return EINA_TRUE;
}
void send_contacts_list_to_server(service_client* service_client, Eina_List* contacts_list)
bundle_free(msg);
}
+
+void send_set_group_chat_new_title_request(service_client* service_client, int user_id, const char* new_title)
+{
+ bundle *msg;
+ char tmp[50];
+ int result;
+
+ if (!service_client || !new_title) {
+ // error
+ return;
+ }
+
+ msg = bundle_create();
+ if (!msg) {
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "set_group_chat_new_title_request") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ snprintf(tmp, sizeof(tmp) - 1, "%d", user_id);
+
+ if (bundle_add_str(msg, "buddy_id", tmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (bundle_add_str(msg, "new_title", new_title) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ }
+ bundle_free(msg);
+}
+
+void send_remove_buddy_from_group_chat_request(service_client* service_client, int user_id, int chat_id)
+{
+ bundle *msg;
+ char tmp[50];
+ char ctmp[50];
+ int result;
+
+ if (!service_client) {
+ // error
+ return;
+ }
+
+ msg = bundle_create();
+ if (!msg) {
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "remove_buddy_from_chat_request") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ snprintf(tmp, sizeof(tmp) - 1, "%d", user_id);
+
+ if (bundle_add_str(msg, "buddy_id", tmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ snprintf(ctmp, sizeof(ctmp) - 1, "%d", chat_id);
+
+ if (bundle_add_str(msg, "chat_id", ctmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ }
+ bundle_free(msg);
+}
+
+void send_add_buddy_to_group_chat_request(service_client* service_client, int user_id, int chat_id)
+{
+ bundle *msg;
+ char tmp[50];
+ char ctmp[50];
+ int result;
+
+ if (!service_client) {
+ // error
+ return;
+ }
+
+ msg = bundle_create();
+ if (!msg) {
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "add_new_buddy_to_chat_request") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ snprintf(tmp, sizeof(tmp) - 1, "%d", user_id);
+
+ if (bundle_add_str(msg, "buddy_id", tmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ snprintf(ctmp, sizeof(ctmp) - 1, "%d", chat_id);
+
+ if (bundle_add_str(msg, "chat_id", ctmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ }
+ bundle_free(msg);
+}
+
+void send_set_group_chat_profile_pic_request(service_client* service_client, int user_id, const char* file_path)
+{
+ bundle *msg;
+ char tmp[50];
+ int result;
+
+ if (!service_client || !file_path) {
+ // error
+ return;
+ }
+
+ msg = bundle_create();
+ if (!msg) {
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "set_group_chat_profile_pic_request") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ snprintf(tmp, sizeof(tmp) - 1, "%d", user_id);
+
+ if (bundle_add_str(msg, "buddy_id", tmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (bundle_add_str(msg, "file_path", file_path) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ }
+ bundle_free(msg);
+}
+
+void send_set_profile_pic_request(service_client* service_client, int user_id, const char* file_path)
+{
+ bundle *msg;
+ char tmp[50];
+ int result;
+
+ if (!service_client || !file_path) {
+ // error
+ return;
+ }
+
+ msg = bundle_create();
+ if (!msg) {
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "set_profile_pic_request") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ snprintf(tmp, sizeof(tmp) - 1, "%d", user_id);
+
+ if (bundle_add_str(msg, "buddy_id", tmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (bundle_add_str(msg, "file_path", file_path) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ }
+ bundle_free(msg);
+}
+
+void send_set_username_request(service_client* service_client, int user_id, const char* username)
+{
+ bundle *msg;
+ char tmp[50];
+ int result;
+
+ if (!service_client || !username) {
+ // error
+ return;
+ }
+
+ msg = bundle_create();
+ if (!msg) {
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "set_username_request") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ snprintf(tmp, sizeof(tmp) - 1, "%d", user_id);
+
+ if (bundle_add_str(msg, "buddy_id", tmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (bundle_add_str(msg, "username", username) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ }
+ bundle_free(msg);
+}
+
+
+void send_request_for_delete_notifications(service_client* service_client)
+{
+ bundle *msg;
+ int result;
+
+ if (!service_client) {
+ // error
+ return;
+ }
+
+ msg = bundle_create();
+ if (!msg) {
+ LOGE("Failed to create a bundle");
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "delete_all_notifications") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ LOGE("Failed to send a service message");
+ }
+
+ bundle_free(msg);
+}
+
+void send_request_for_server_connection_status(service_client* service_client)
+{
+ bundle *msg;
+ int result;
+
+ if (!service_client) {
+ // error
+ return;
+ }
+
+ msg = bundle_create();
+ if (!msg) {
+ LOGE("Failed to create a bundle");
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "server_connection_status") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ LOGE("Failed to send a service message");
+ }
+
+ bundle_free(msg);
+}
-#include <errno.h>
#include "telegramtizen.h"
#include "tg_splash_screen.h"
#include "tg_registration.h"
#include "tg_user_main_view.h"
#include "tg_messaging_view.h"
#include "tg_start_messaging_view.h"
-#include "tg_common.h"
-
-static void popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+#include "tg_user_info_view.h"
+#include "tg_chat_info_view.h"
+#include <notification.h>
+#include <badge.h>
+static void
+popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
{
evas_object_del(obj);
}
-static void popup_timeout_cb(void *data, Evas_Object *obj, void *event_info)
+static void
+popup_timeout_cb(void *data, Evas_Object *obj, void *event_info)
{
evas_object_del(obj);
}
return res;
}
-static void load_registered_user_data(appdata_s *ad, Eina_List* user_info)
+void load_registered_user_data(appdata_s *ad)
{
- //Eina_List* user_info = get_registered_user_info();
+ Eina_List *user_info = get_registered_user_info();
if(!user_info) {
//error
show_toast(ad, "User info not loaded");
}
+ if (ad->current_user_data) {
+ free_user_data(ad->current_user_data);
+ ad->current_user_data = NULL;
+ }
+
+ ad->current_user_data = (user_data_s*)malloc(sizeof(user_data_s));
+
int row_count = eina_list_count(user_info);
for (int i = 0 ; i < row_count ; i++) {
ad->user_id.id = user_id;
ad->user_id.type = TGL_PEER_USER;
- ad->current_user_data.user_id.id = user_id;
- ad->current_user_data.user_id.type = TGL_PEER_USER;
-
+ ad->current_user_data->user_id.id = user_id;
+ ad->current_user_data->user_id.type = TGL_PEER_USER;
}
char *print_name = (char*)eina_list_nth(row_vals, 1);
if(print_name) {
- ad->current_user_data.print_name = strdup(print_name);
+ ad->current_user_data->print_name = strdup(print_name);
free(print_name);
+ } else {
+ ad->current_user_data->print_name = NULL;
}
int *temp_struct_ver = (int*)eina_list_nth(row_vals, 2);
if(temp_struct_ver) {
- ad->current_user_data.structure_version = *temp_struct_ver;
+ ad->current_user_data->structure_version = *temp_struct_ver;
free(temp_struct_ver);
}
char *photo_path = (char*)eina_list_nth(row_vals, 3);
if(photo_path) {
- ad->current_user_data.photo_path = strdup(photo_path);
+ ad->current_user_data->photo_path = strdup(photo_path);
free(photo_path);
+ } else {
+ ad->current_user_data->photo_path = NULL;
}
int *temp_photo_id = (int*)eina_list_nth(row_vals, 4);
if(temp_photo_id) {
- ad->current_user_data.photo_id = *temp_photo_id;
+ ad->current_user_data->photo_id = *temp_photo_id;
free(temp_photo_id);
}
char *first_name = (char*)eina_list_nth(row_vals, 5);
if(first_name) {
- ad->current_user_data.first_name = strdup(first_name);
+ ad->current_user_data->first_name = strdup(first_name);
free(first_name);
}
char *last_name = (char*)eina_list_nth(row_vals, 6);
if(last_name) {
- ad->current_user_data.last_name = strdup(last_name);
+ ad->current_user_data->last_name = strdup(last_name);
free(last_name);
+ } else {
+ ad->current_user_data->last_name = NULL;
}
char *phone_no = (char*)eina_list_nth(row_vals, 7);
if(phone_no) {
- ad->current_user_data.phone = strdup(phone_no);
+ ad->current_user_data->phone = strdup(phone_no);
free(phone_no);
+ } else {
+ ad->current_user_data->phone = NULL;
}
int *temp_access_hash = (int*)eina_list_nth(row_vals, 8);
if(temp_access_hash) {
- ad->current_user_data.access_hash = *temp_access_hash;
+ ad->current_user_data->access_hash = *temp_access_hash;
free(temp_access_hash);
}
char *real_first_name = (char*)eina_list_nth(row_vals, 9);
if(real_first_name) {
- ad->current_user_data.real_first_name = strdup(real_first_name);
+ ad->current_user_data->real_first_name = strdup(real_first_name);
free(real_first_name);
+ } else {
+ ad->current_user_data->real_first_name = NULL;
}
char *real_last_name = (char*)eina_list_nth(row_vals, 10);
if(real_last_name) {
- ad->current_user_data.real_last_name = strdup(real_last_name);
+ ad->current_user_data->real_last_name = strdup(real_last_name);
free(real_last_name);
+ } else {
+ ad->current_user_data->real_last_name = NULL;
}
char *user_name = (char*)eina_list_nth(row_vals, 11);
if(user_name) {
- ad->current_user_data.username = strdup(user_name);
+ ad->current_user_data->username = strdup(user_name);
free(user_name);
+ } else {
+ ad->current_user_data->username = NULL;
}
int *temp_online_status = (int*)eina_list_nth(row_vals, 12);
if(temp_online_status) {
- ad->current_user_data.online = *temp_online_status;
+ ad->current_user_data->online = *temp_online_status;
free(temp_online_status);
}
int *temp_last_seen = (int*)eina_list_nth(row_vals, 13);
if(temp_last_seen) {
- ad->current_user_data.last_seen = *temp_last_seen;
+ ad->current_user_data->last_seen = *temp_last_seen;
free(temp_last_seen);
}
ad->peer_list = NULL;
- Eina_List* peer_details = get_all_peer_details();
+ Eina_List* peer_details = get_all_peer_details(NULL);
for (int i = 0; i < eina_list_count(peer_details) ; i++) {
Eina_List* ts_msg = eina_list_nth(peer_details, i);
eina_list_free(peer_details);
}
+
+
void load_main_list_data(appdata_s *ad)
{
if (!ad || !ad->peer_list) {
int peer_count = eina_list_count(ad->peer_list);
+
for(int i = 0; i < peer_count; i++) {
peer_with_pic_s *item = eina_list_nth(ad->peer_list, i);
if (item) {
tg_peer_info_s* peer_info = item->use_data;
if(peer_info) {
- const char *tablename;
- tg_message_s *msg;
+ //if (peer_info->last_msg_id > 0) {
- tablename = tg_common_to_string("tg_%d_msg", peer_info->peer_id);
- if (!tablename) {
- ERR("Unable to convert a string for peer_id");
- return;
- }
+ // get message from message table.
- msg = get_latest_message_from_message_table(tablename);
- if (!msg) {
- ERR("Unable to get messages");
- return;
- }
+ char* tablename = get_table_name_from_number(peer_info->peer_id);
+ //tg_message_s* msg = get_message_from_message_table(peer_info->last_msg_id, tablename);
+ tg_message_s* msg = get_latest_message_from_message_table(tablename);
- if (msg) {
- if (msg->service) {
- if (msg->message && strlen(msg->message) > 0) {
- item->last_message = strdup(msg->message);
- } else {
- item->last_message = strdup(" ");
- }
- } else {
- switch (msg->media_type) {
- case tgl_message_media_none:
+ if (msg) {
+
+ if (msg->service) {
if (msg->message && strlen(msg->message) > 0) {
item->last_message = strdup(msg->message);
} else {
item->last_message = strdup(" ");
}
- break;
- case tgl_message_media_photo:
- item->last_message = strdup("Image");
- break;
- case tgl_message_media_document:
- item->last_message = strdup("Document");
- break;
- case tgl_message_media_geo:
- item->last_message = strdup("Geo location");
- break;
- case tgl_message_media_contact:
- item->last_message = strdup("Contact");
- break;
- case tgl_message_media_unsupported:
- item->last_message = strdup(" ");
- break;
- case tgl_message_media_photo_encr:
- item->last_message = strdup("Image encrypted");
- break;
- case tgl_message_media_document_encr:
- item->last_message = strdup("Document encrypted");
- break;
- default:
- item->last_message = strdup(" ");
- break;
+ } else {
+
+ int media_type = msg->media_type;
+ if(media_type == tgl_message_media_none) {
+ if (msg->message && strlen(msg->message) > 0) {
+ item->last_message = strdup(msg->message);
+ } else {
+ item->last_message = strdup(" ");
+ }
+ } else if(media_type == tgl_message_media_photo) {
+ item->last_message = strdup("Image");
+ } else if(media_type == tgl_message_media_document) {
+ if (msg->message && strlen(msg->message) > 0) {
+ item->last_message = strdup(msg->message);
+ } else {
+ item->last_message = strdup("Document");
+ }
+ } else if(media_type == tgl_message_media_geo) {
+ item->last_message = strdup("Geo location");
+ } else if(media_type == tgl_message_media_contact) {
+ item->last_message = strdup("Contact");
+ } else if(media_type == tgl_message_media_unsupported) {
+ item->last_message = strdup(" ");
+ } else if(media_type == tgl_message_media_photo_encr) {
+ item->last_message = strdup("Image encrypted");
+ } else if(media_type == tgl_message_media_document_encr) {
+ item->last_message = strdup("Document encrypted");
+ } else {
+ item->last_message = strdup(" ");
+ }
}
- }
- tg_main_list_item_s* main_list_item;
- main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s));
- main_list_item->peer_id = peer_info->peer_id;
- main_list_item->peer_type = peer_info->peer_type;
- main_list_item->peer_print_name = strdup(peer_info->print_name);
- main_list_item->last_seen_time = msg->date;
- main_list_item->profile_pic = NULL;
- main_list_item->last_msg_id = msg->msg_id;
- main_list_item->last_message = strdup(item->last_message);
- main_list_item->last_msg_type = msg->media_type;
- main_list_item->is_out_msg = msg->out;
- main_list_item->last_msg_status = msg->msg_state;
- main_list_item->last_msg_service = msg->service;
- main_list_item->number_of_unread_msgs = get_unread_message_count(tablename);
- if (peer_info->photo_path) {
- main_list_item->profile_pic_path = strdup(peer_info->photo_path);
- } else {
- main_list_item->profile_pic_path = NULL;
- }
- main_list_item->user_name_lbl = NULL;
- main_list_item->status_lbl = NULL;
- main_list_item->date_lbl = NULL;
- main_list_item->msg_status_lbl = NULL;
- ad->main_list = eina_list_append(ad->main_list, main_list_item);
+ tg_main_list_item_s* main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s));
+ main_list_item->peer_id = peer_info->peer_id;
+ main_list_item->peer_type = peer_info->peer_type;
+ main_list_item->peer_print_name = strdup(peer_info->print_name);
+ main_list_item->last_seen_time = msg->date;
+ main_list_item->profile_pic = NULL;
+ main_list_item->last_msg_id = msg->msg_id;
+ main_list_item->last_message = strdup(item->last_message);
+ main_list_item->last_msg_type = msg->media_type;
+ main_list_item->is_out_msg = msg->out;
+ main_list_item->last_msg_status = msg->msg_state;
+ main_list_item->last_msg_service = msg->service;
+ main_list_item->number_of_unread_msgs = get_unread_message_count(tablename);
+ if (peer_info->photo_path) {
+ main_list_item->profile_pic_path = strdup(peer_info->photo_path);
+ } else {
+ main_list_item->profile_pic_path = NULL;
+ }
+ main_list_item->user_name_lbl = NULL;
+ main_list_item->status_lbl = NULL;
+ main_list_item->date_lbl = NULL;
+ main_list_item->msg_status_lbl = NULL;
+ ad->main_list = eina_list_append(ad->main_list, main_list_item);
+
+ // delete message object
+ if(msg->message) {
+ free(msg->message);
+ msg->message = NULL;
+ }
- // delete message object
- if(msg->message) {
- free(msg->message);
- msg->message = NULL;
- }
+ if(msg->media_id) {
+ free(msg->media_id);
+ msg->media_id = NULL;
+ }
- // delete message object
- if(msg->message) {
- free(msg->message);
- msg->message = NULL;
- }
+ free(msg);
+ msg = NULL;
- if(msg->media_id) {
- free(msg->media_id);
- msg->media_id = NULL;
+ } else {
+ item->last_message = strdup(" ");
+ if (peer_info->peer_type == TGL_PEER_CHAT) {
+ tg_main_list_item_s* main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s));
+ main_list_item->peer_id = peer_info->peer_id;
+ main_list_item->peer_type = peer_info->peer_type;
+ main_list_item->peer_print_name = strdup(peer_info->print_name);
+ main_list_item->last_seen_time = peer_info->last_seen_time;
+ main_list_item->profile_pic = NULL;
+ main_list_item->last_message = strdup(item->last_message);
+ main_list_item->last_msg_type = -1;
+ main_list_item->last_msg_service = 0;
+ main_list_item->is_out_msg = -1;
+ main_list_item->last_msg_id = -1;
+ main_list_item->last_msg_status = -1;
+ main_list_item->number_of_unread_msgs = 0;
+ if (peer_info->photo_path) {
+ main_list_item->profile_pic_path = strdup(peer_info->photo_path);
+ } else {
+ main_list_item->profile_pic_path = NULL;
+ }
+ main_list_item->user_name_lbl = NULL;
+ main_list_item->status_lbl = NULL;
+ main_list_item->date_lbl = NULL;
+ main_list_item->msg_status_lbl = NULL;
+ ad->main_list = eina_list_append(ad->main_list, main_list_item);
+ }
}
- }
- ERR("strdup: %d", errno);
- } else {
- item->last_message = strdup(" ");
- if (peer_info->peer_type == TGL_PEER_CHAT) {
- tg_main_list_item_s* main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s));
- main_list_item->peer_id = peer_info->peer_id;
- main_list_item->peer_type = peer_info->peer_type;
- main_list_item->peer_print_name = strdup(peer_info->print_name);
- main_list_item->last_seen_time = peer_info->last_seen_time;
- main_list_item->profile_pic = NULL;
- main_list_item->last_message = strdup(item->last_message);
- main_list_item->last_msg_type = -1;
- main_list_item->last_msg_service = 0;
- main_list_item->is_out_msg = -1;
- main_list_item->last_msg_id = -1;
- main_list_item->last_msg_status = -1;
- main_list_item->number_of_unread_msgs = 0;
- if (peer_info->photo_path) {
- main_list_item->profile_pic_path = strdup(peer_info->photo_path);
- } else {
- main_list_item->profile_pic_path = NULL;
+ if (tablename) {
+ free(tablename);
+ tablename = NULL;
}
- main_list_item->user_name_lbl = NULL;
- main_list_item->status_lbl = NULL;
- main_list_item->date_lbl = NULL;
- main_list_item->msg_status_lbl = NULL;
- ad->main_list = eina_list_append(ad->main_list, main_list_item);
- }
- } // peer_info
- } // item
- } // for
-}
+ //}
+ }
+ }
+ }
+
+}
+#if 0
void load_group_chat_data(appdata_s *ad)
{
if (!ad) {
eina_list_free(chat_details);
}
-
+#endif
void load_buddy_list_data(appdata_s *ad)
{
if (!ad) {
free(temp_last_seen);
}
+ int *temp_is_blocked = (int*)eina_list_nth(row_vals, 14);
+ if(temp_is_blocked) {
+ user_data->is_blocked = *temp_is_blocked;
+ free(temp_is_blocked);
+ }
+
+ int *temp_is_deleted = (int*)eina_list_nth(row_vals, 15);
+ if(temp_is_deleted) {
+ user_data->is_deleted = *temp_is_deleted;
+ free(temp_is_deleted);
+ }
+
user_data_with_pic_s *item = (user_data_with_pic_s*) malloc(sizeof (user_data_with_pic_s));
item->use_data = user_data;
//item->pic_file_location = NULL;
eina_list_free(user_info);
}
-static void registration_done_handler(bundle *rec_msg, void *data)
-{
- appdata_s *app = data;
- char* is_success_val = NULL;
- int result;
-
- result = bundle_get_str(rec_msg, "is_success", &is_success_val);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
-
- if (strcmp("true", is_success_val) == 0) {
- // show_toast(app, is_success_val);
- // Launch login view
- elm_naviframe_item_pop(app->nf);
- launch_login_cb(data);
- } else {
- // error handling
- show_toast(app, "Error: registration");
- }
-}
-
-static void contacts_load_done_handler(bundle *rec_msg, void *data)
+static int _on_service_client_msg_received_cb(void *data, bundle *const rec_msg)
{
+ int result = SVC_RES_FAIL;
+ RETVM_IF(!data, result, "Data is NULL");
appdata_s *app = data;
- char* is_success_val = NULL;
- int result;
-
- result = bundle_get_str(rec_msg, "is_success", &is_success_val);
- if (strcmp("true", is_success_val) == 0) {
- // Load user data
- Eina_List* user_info;
+ char *rec_key_val = NULL;
- user_info = get_registered_user_info();
- load_registered_user_data(app, user_info);
- if (app->current_app_state == TG_LOGIN_STATE
- || app->current_app_state == TG_REGISTRATION_STATE
- || app->current_app_state == TG_PROFILE_REGISTRATION_STATE)
- {
- // Launch buddy list view
- load_buddy_list_data(app);
- load_group_chat_data(app);
- load_peer_data(app);
- load_main_list_data(app);
- elm_naviframe_item_pop(app->nf);
+ result = bundle_get_str(rec_msg, "command", &rec_key_val);
- //launch_buddy_list_cb(app);
+ if (strcmp(rec_key_val, "registration_done") == 0) {
- //launch_user_main_view_cb(app);
- launch_start_messaging_view(app);
+ char* is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "is_success", &is_success_val);
- } else if (app->current_app_state == TG_BUDDY_LIST_STATE) {
- ////refresh_buddy_list(app);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
+ //show_toast(app, is_success_val);
+ // Launch login view
+ //elm_naviframe_item_pop(app->nf);
+ launch_login_cb(data);
} else {
-
+ // error handling
+ show_toast(app, "Error: registration");
}
- } else {
- // error handling
- show_toast(app, "Error: loading contacts");
- }
-}
-
-static void contacts_and_chats_load_done_handler(bundle *rec_msg, void *data)
-{
- appdata_s *app = data;
- char* is_success_val = NULL;
- int result;
+ hide_loading_popup(app);
+ return result;
+ } else if (strcmp(rec_key_val, "name_registration_request") == 0) {
- result = bundle_get_str(rec_msg, "is_success", &is_success_val);
- if (result != BUNDLE_ERROR_NONE) {
- return;
+ elm_naviframe_item_pop(app->nf);
+ elm_naviframe_item_pop(app->nf);
+ launch_first_registration_cb(app);
+ hide_loading_popup(app);
+ return result;
}
- if (strcmp("true", is_success_val) == 0) {
- // Load user data
- Eina_List* user_info;
-
- user_info = get_registered_user_info();
- load_registered_user_data(app, user_info);
-
- if (app->current_app_state == TG_LOGIN_STATE
- || app->current_app_state == TG_REGISTRATION_STATE
- || app->current_app_state == TG_PROFILE_REGISTRATION_STATE)
- {
- // Launch buddy list view
- load_buddy_list_data(app);
- load_group_chat_data(app);
- load_peer_data(app);
- load_main_list_data(app);
- elm_naviframe_item_pop(app->nf);
- //launch_buddy_list_cb(app);
- launch_user_main_view_cb(app);
- } else if (app->current_app_state == TG_BUDDY_LIST_STATE) {
- app->current_app_state = TG_BUDDY_LIST_STATE;
- evas_object_show(app->panel);
- //elm_panel_hidden_set(app->panel, EINA_FALSE);
- ////refresh_buddy_list(app);
- } else {
-
- }
-
- } else {
- // error handling
- show_toast(app, "Error: loading contacts");
+ if (strcmp(rec_key_val, "contacts_and_chats_load_done") == 0) {
+ app->is_tg_initilized = EINA_TRUE;
+ }
+ if (!app->is_tg_initilized) {
+ return result;
}
-}
-static void buddy_profile_pic_updated_handler(bundle *rec_msg, void *data)
-{
- appdata_s *app = data;
- char *tmp;
- int user_id;
- char* pic_file_path = NULL;
- int result;
+ if (strcmp(rec_key_val, "contacts_load_done") == 0) {
+ char* is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "is_success", &is_success_val);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
- result = bundle_get_str(rec_msg, "user_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ // Load user data
- user_id = atoi(tmp);
+ load_registered_user_data(app);
- result = bundle_get_str(rec_msg, "file_path", &pic_file_path);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ if (app->current_app_state == TG_LOGIN_STATE || app->current_app_state == TG_REGISTRATION_STATE || app->current_app_state == TG_PROFILE_REGISTRATION_STATE) {
+ // Launch buddy list view
+ load_buddy_list_data(app);
+ //load_group_chat_data(app);
+ load_peer_data(app);
+ load_main_list_data(app);
+ elm_naviframe_item_pop(app->nf);
+ elm_naviframe_item_pop(app->nf);
+ //launch_buddy_list_cb(app);
- // update profile pic if buddy list view is present.
- if(user_id == app->user_id.id) {
- // registerd user.
- // to be handled
- } else {
- Eina_List *l;
- // update buddy list in appdata.
- user_data_with_pic_s *user_item;
- peer_with_pic_s *peer_item;
- tg_main_list_item_s *main_item;
-
- EINA_LIST_FOREACH(app->buddy_list, l, user_item) {
- if (user_item->use_data->user_id.id != user_id) {
- continue;
- }
-
- tmp = strdup(pic_file_path);
- if (!tmp) {
- /**
- * @todo
- * Failed to allocate heap
- */
- break;
- }
+ //launch_user_main_view_cb(app);
+ launch_start_messaging_view(app);
+
+ } else if (app->current_app_state == TG_BUDDY_LIST_STATE) {
+ ////refresh_buddy_list(app);
+ } else {
- if (user_item->use_data->photo_path) {
- free(user_item->use_data->photo_path);
}
- user_item->use_data->photo_path = tmp;
+ } else {
+ // error handling
+ show_toast(app, "Error: loading contacts");
+ }
+ } else if (strcmp(rec_key_val, "contacts_and_chats_load_done") == 0) {
+ char* is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "is_success", &is_success_val);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
+
+ // Load user data
+ //Eina_List* user_info = get_registered_user_info();
+ load_registered_user_data(app);
+
+ if (app->current_app_state == TG_LOGIN_STATE || app->current_app_state == TG_REGISTRATION_STATE || app->current_app_state == TG_PROFILE_REGISTRATION_STATE) {
+ // Launch buddy list view
+ load_buddy_list_data(app);
+ //load_group_chat_data(app);
+ load_peer_data(app);
+ load_main_list_data(app);
+ elm_naviframe_item_pop(app->nf);
+ elm_naviframe_item_pop(app->nf);
+ //launch_buddy_list_cb(app);
+ launch_user_main_view_cb(app);
+ } else if (app->current_app_state == TG_BUDDY_LIST_STATE) {
+ app->current_app_state = TG_BUDDY_LIST_STATE;
+ evas_object_show(app->panel);
+ //elm_panel_hidden_set(app->panel, EINA_FALSE);
+ ////refresh_buddy_list(app);
+ } else {
- if (user_item->contact_icon) {
- elm_image_file_set(user_item->contact_icon, user_item->use_data->photo_path, NULL);
}
- break;
+ } else {
+ // error handling
+ show_toast(app, "Error: loading contacts");
}
+ } else if (strcmp(rec_key_val, "group_chat_updated") == 0) {
- EINA_LIST_FOREACH(app->peer_list, l, peer_item) {
- if (peer_item->use_data->peer_id != user_id) {
- continue;
- }
+ char *chat_id_str = NULL;
+ result = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
+ int chat_id = atoi(chat_id_str);
- tmp = strdup(pic_file_path);
- if (!tmp) {
- break;
- }
+ char *type_of_change = NULL;
+ result = bundle_get_str(rec_msg, "type_of_change", &type_of_change);
- if (peer_item->use_data->photo_path) {
- free(peer_item->use_data->photo_path);
- }
- peer_item->use_data->photo_path = tmp;
+ peer_with_pic_s *peer_item = get_peer_info(chat_id);
+ tg_main_list_item_s *latest_item = get_latest_item(app, peer_item);
- if (peer_item->contact_icon) {
- elm_image_file_set(peer_item->contact_icon, peer_item->use_data->photo_path, NULL);
+ if(app->peer_list) {
+ int size = eina_list_count(app->peer_list);
+ for (int i = 0 ; i < size ; i++) {
+ peer_with_pic_s *item = eina_list_nth(app->peer_list, i);
+ if (item->use_data->peer_id == chat_id) {
+ app->peer_list = eina_list_remove(app->peer_list, item);
+ break;
+ }
}
-
- break;
}
- EINA_LIST_FOREACH(app->main_list, l, main_item) {
- if (main_item->peer_id != user_id) {
- continue;
+ if(app->main_list) {
+ int size = eina_list_count(app->main_list);
+ for (int i = 0 ; i < size ; i++) {
+ tg_main_list_item_s *item = eina_list_nth(app->main_list, i);
+ if (item->peer_id == chat_id) {
+ app->main_list = eina_list_remove(app->main_list, item);
+ break;
+ }
}
+ }
+ app->peer_list = eina_list_prepend(app->peer_list, peer_item);
+ app->main_list = eina_list_prepend(app->main_list, latest_item);
+ refresh_main_list_view(app, EINA_TRUE);
- tmp = strdup(pic_file_path);
- if (!tmp) {
- break;
- }
+ if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->peer_in_cahtting_data
+ && app->peer_in_cahtting_data->use_data->peer_id == chat_id) {
- if (main_item->profile_pic_path) {
- free(main_item->profile_pic_path);
- }
+ app->peer_in_cahtting_data = peer_item;
+ app->main_item_in_cahtting_data = latest_item;
- main_item->profile_pic_path = tmp;
+ on_group_chat_info_changed(app, type_of_change);
+ }
- if (main_item->profile_pic) {
- elm_image_file_set(main_item->profile_pic, main_item->profile_pic_path, NULL);
- }
+ if (app->current_app_state == TG_SET_CHAT_INFO_STATE && app->peer_in_cahtting_data
+ && app->peer_in_cahtting_data->use_data->peer_id == chat_id) {
- break;
- }
- }
-}
+ app->peer_in_cahtting_data = peer_item;
+ app->main_item_in_cahtting_data = latest_item;
-static void message_received_handler(bundle *rec_msg, void *data)
-{
- appdata_s *app = data;
- char* tmp;
- int from_id;
- int to_id;
- long long message_id;
- int type_of_chat;
- Eina_List *l;
- int result;
- //load message from the received info.
- // get phone number using buddy id.
- tg_main_list_item_s *sel_item;
- tg_message_s *msg;
- int id_to_check;
- char *tablename;
-
-
- result = bundle_get_str(rec_msg, "from_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ on_group_chat_info_changed(app, type_of_change);
- from_id = atoi(tmp);
+ on_group_chat_info_updated(app, type_of_change);
- result = bundle_get_str(rec_msg, "to_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ }
+ } else if ((strcmp(rec_key_val, "group_chat_new_buddy_added_response") == 0) || (strcmp(rec_key_val, "group_chat_buddy_deleted_response") == 0)) {
- to_id = atoi(tmp);
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- result = bundle_get_str(rec_msg, "message_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ Eina_Bool is_success = EINA_FALSE;
+ char* is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "is_success", &is_success_val);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
+ is_success = EINA_TRUE;
+ } else {
+ is_success = EINA_FALSE;
+ }
- message_id = atoll(tmp);
+ if (app->current_app_state == TG_SET_CHAT_INFO_STATE && app->peer_in_cahtting_data
+ && app->peer_in_cahtting_data->use_data->peer_id == buddy_id) {
+ hide_loading_popup(app);
+ if (strcmp(rec_key_val, "group_chat_new_buddy_added_response") == 0) {
+ show_toast(app, "Failed to add new buddy to chat.");
+ } else if (strcmp(rec_key_val, "group_chat_buddy_deleted_response") == 0) {
+ show_toast(app, "Failed to delete buddy to chat.");
+ }
+ }
- result = bundle_get_str(rec_msg, "type_of_chat", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- type_of_chat = atoi(tmp);
+ } else if (strcmp(rec_key_val, "group_chat_rename_response") == 0) {
- if (from_id == app->user_id.id) {
- // sent by the user. May be from another device.
- }
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- EINA_LIST_FOREACH(app->main_list, l, sel_item) {
- if (type_of_chat == TGL_PEER_USER) {
- id_to_check = from_id;
+ Eina_Bool is_success = EINA_FALSE;
+ char* is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "is_success", &is_success_val);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
+ is_success = EINA_TRUE;
} else {
- id_to_check = to_id;
+ is_success = EINA_FALSE;
}
- if (sel_item->peer_id != id_to_check) {
- continue;
- }
+ if (app->current_app_state == TG_SET_CHAT_INFO_STATE && app->peer_in_cahtting_data
+ && app->peer_in_cahtting_data->use_data->peer_id == buddy_id) {
- // update last message
- tablename = get_table_name_from_number(sel_item->peer_id);
- msg = get_message_from_message_table(message_id, tablename);
- if (!msg) {
- free(tablename);
- continue;
+ hide_loading_popup(app);
+ show_toast(app, "Failed to rename the chat title.");
}
-
- if (msg->service) {
- if (msg->message && msg->message[0] != '\0') {
- sel_item->last_message = strdup(msg->message);
- } else {
- sel_item->last_message = strdup(" ");
- }
+ } else if (strcmp(rec_key_val, "server_connection_status") == 0) {
+ Eina_Bool is_success = EINA_FALSE;
+ char* is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "connection_status", &is_success_val);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
+ is_success = EINA_TRUE;
} else {
- switch (msg->media_type) {
- case tgl_message_media_photo:
- sel_item->last_message = strdup("Image");
- break;
- case tgl_message_media_document:
- sel_item->last_message = strdup("Document");
- break;
- case tgl_message_media_geo:
- sel_item->last_message = strdup("Geo location");
- break;
- case tgl_message_media_contact:
- sel_item->last_message = strdup("Contact");
- break;
- case tgl_message_media_photo_encr:
- sel_item->last_message = strdup("Image encrypted");
- break;
- case tgl_message_media_document_encr:
- sel_item->last_message = strdup("Document encrypted");
- break;
- case tgl_message_media_none:
- if (msg->message && strlen(msg->message) > 0) {
- sel_item->last_message = strdup(msg->message);
- break;
- }
- case tgl_message_media_unsupported:
- default:
- sel_item->last_message = strdup(" ");
- break;
- }
- sel_item->last_msg_id = msg->msg_id;
- sel_item->last_msg_type = msg->media_type;
- sel_item->is_out_msg = msg->out;
- sel_item->last_msg_status = msg->msg_state;
- sel_item->last_seen_time = msg->date;
- sel_item->number_of_unread_msgs = get_unread_message_count(tablename);
- if (sel_item->profile_pic) {
+ is_success = EINA_FALSE;
+ }
- }
+ app->is_server_ready = is_success;
- if (sel_item->user_name_lbl) {
+ if (app->is_server_ready) {
+ show_toast(app, "server is ready");
+ } else {
+ show_toast(app, "server is not ready");
+ }
- }
+ } else if (strcmp(rec_key_val, "buddy_profile_pic_updated") == 0) {
+ char* user_id_str = NULL;
+ result = bundle_get_str(rec_msg, "user_id", &user_id_str);
+ int user_id = atoi(user_id_str);
- if (sel_item->status_lbl) {
- char* org_msg;
- int len_org_str;
- char res[25] = {'\0'};
- char status_buf[126] = {'\0'};
+ char* pic_file_path = NULL;
+ result = bundle_get_str(rec_msg, "file_path", &pic_file_path);
- if (sel_item->last_message) {
- org_msg = sel_item->last_message;
- } else {
- org_msg = "";
- }
+ if (!pic_file_path || strlen(pic_file_path) <= 0 || access(pic_file_path, F_OK ) == -1) {
+ pic_file_path = (char*)ui_utils_get_resource(DEFAULT_PROFILE_PIC);
+ }
- len_org_str = strlen(org_msg);
- if(len_org_str > 25) {
- strncpy(res, org_msg, 24);
- if(msg->service) {
- snprintf(status_buf, sizeof(status_buf) - 1,
- "<font=Tizen:style=Italic color=#158CB0 align=left><font_size=30>%s</font_size></font>", res);
- } else {
- snprintf(status_buf, sizeof(status_buf) - 1,
- "<font=Tizen:style=Italic color=#A4A4A4 align=left><font_size=30>%s</font_size></font>", res);
+
+ // update profile pic if buddy list view is present.
+ if(user_id == app->user_id.id) {
+ // registerd user.
+ // to be handled
+ } else {
+ // update buddy list in appdata.
+ if(app->buddy_list) {
+ int size = eina_list_count(app->buddy_list);
+ for (int i = 0 ; i < size ; i++) {
+ user_data_with_pic_s *item = eina_list_nth(app->buddy_list, i);
+ if (item->use_data->user_id.id == user_id) {
+ if (item->use_data->photo_path) {
+ free(item->use_data->photo_path);
+ item->use_data->photo_path = NULL;
+ }
+ item->use_data->photo_path = strdup(pic_file_path);
+ if (item->contact_icon) {
+ elm_image_file_set(item->contact_icon, pic_file_path, NULL);
+ }
+ break;
}
- } else {
- if(msg->service) {
- snprintf(status_buf, sizeof(status_buf) - 1,
- "<font=Tizen:style=Italic color=#158CB0 align=left><font_size=30>%s</font_size></font>", org_msg);
- } else {
- snprintf(status_buf, sizeof(status_buf) - 1,
- "<font=Tizen:style=Italic color=#A4A4A4 align=left><font_size=30>%s</font_size></font>", org_msg);
+ }
+ }
+ if(app->peer_list) {
+ int size = eina_list_count(app->peer_list);
+ for (int i = 0 ; i < size ; i++) {
+ peer_with_pic_s *item = eina_list_nth(app->peer_list, i);
+ if (item->use_data->peer_id == user_id) {
+ if (item->use_data->photo_path) {
+ free(item->use_data->photo_path);
+ item->use_data->photo_path = NULL;
+ }
+ item->use_data->photo_path = strdup(pic_file_path);
+ if (item->contact_icon) {
+ elm_image_file_set(item->contact_icon, pic_file_path, NULL);
+ }
+ break;
}
}
-
- elm_object_text_set(sel_item->status_lbl, status_buf);
}
- if (sel_item->date_lbl) {
- Eina_Bool is_today;
+ if(app->main_list) {
+ int size = eina_list_count(app->main_list);
+ for (int i = 0 ; i < size ; i++) {
+ tg_main_list_item_s *item = eina_list_nth(app->main_list, i);
+ if (item->peer_id == user_id) {
+ if (item->profile_pic_path) {
+ free(item->profile_pic_path);
+ item->profile_pic_path = NULL;
+ }
+ item->profile_pic_path = strdup(pic_file_path);
+ if (item->profile_pic) {
+ elm_image_file_set(item->profile_pic, pic_file_path, NULL);
+ }
+ break;
+ }
+ }
+ }
- is_today = compare_date_with_current_date(sel_item->last_seen_time);
- if (is_today) {
- elm_object_text_set(sel_item->date_lbl,
- "<font=Tizen:style=Italic color=#000000 align=center><font_size=25>Today</font_size></font>");
- } else {
- char *format;
- time_t t;
- struct tm lt;
- char res[256];
- char time_str[256]={0,};
-
- (void)localtime_r(&t, <);
- t = sel_item->last_seen_time;
- format = "%d/%b/%Y";
-
- if (strftime(res, sizeof(res), format, <) == 0) {
- (void)fprintf(stderr, "strftime(3): cannot format supplied "
- "date/time into buffer of size %u "
- "using: '%s'\n",
- sizeof(res), format);
- }
+ if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->peer_in_cahtting_data
+ && app->peer_in_cahtting_data->use_data->peer_id == user_id) {
+ on_chat_profile_pic_changed(app, pic_file_path);
+ }
- snprintf(time_str, sizeof(time_str) - 1,
- "<font=Tizen:style=Italic color=#000000 align=center><font_size=25>%s</font_size></font>", res);
+ if (app->current_app_state == TG_SET_CHAT_INFO_STATE && app->peer_in_cahtting_data
+ && app->peer_in_cahtting_data->use_data->peer_id == user_id) {
+ on_chat_profile_pic_changed(app, pic_file_path);
- elm_object_text_set(sel_item->date_lbl,time_str);
- }
- }
+ show_toast(app, "Chat profile picture updated successfully.");
+ }
- if (sel_item->msg_status_lbl) {
- Evas_Object *temp_lbl;
- Evas_Object *num_lbl;
- Evas_Object *msg_status;
- char unread_msgs[256];
- char edj_path[PATH_MAX] = {0, };
- temp_lbl = elm_object_part_content_unset(sel_item->msg_status_lbl, "swallow.status");
- if (temp_lbl) {
- evas_object_del(temp_lbl);
+ }
+ } else if (strcmp(rec_key_val, "message_received") == 0) {
+
+ char* from_id_str = NULL;
+ result = bundle_get_str(rec_msg, "from_id", &from_id_str);
+ int from_id = atoi(from_id_str);
+
+ char* to_id_str = NULL;
+ result = bundle_get_str(rec_msg, "to_id", &to_id_str);
+ int to_id = atoi(to_id_str);
+
+ char* msg_id_str = NULL;
+ result = bundle_get_str(rec_msg, "message_id", &msg_id_str);
+ long long message_id = atoll(msg_id_str);
+
+ char* type_of_chat_str = NULL;
+ result = bundle_get_str(rec_msg, "type_of_chat", &type_of_chat_str);
+ int type_of_chat = atoi(type_of_chat_str);
+
+ if (from_id == app->user_id.id) {
+ // sent by the user. May be from another device.
+ }
+
+ //load message from the received info.
+ // get phone number using buddy id.
+
+
+ if (app->main_list) {
+ int main_list_size = eina_list_count(app->main_list);
+ for (int i = 0; i < main_list_size; i++) {
+ tg_main_list_item_s* sel_item = eina_list_nth(app->main_list, i);
+
+ int id_to_check;
+ if (type_of_chat == TGL_PEER_USER) {
+ id_to_check = from_id;
+ } else {
+ id_to_check = to_id;
}
- num_lbl = elm_label_add(app->nf);
- elm_object_style_set(num_lbl, "transparent");
- snprintf(unread_msgs, -1,
- "<font=Tizen:style=Bold color=#ffffff align=center><font_size=25>%d</font_size></font>",
- sel_item->number_of_unread_msgs);
- elm_object_text_set(num_lbl, unread_msgs);
- evas_object_size_hint_weight_set(num_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(num_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_show(num_lbl);
- app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
- msg_status = elm_layout_add(app->nf);
- elm_layout_file_set(msg_status, edj_path, "circle_item");
- evas_object_size_hint_weight_set(msg_status, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(msg_status, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_show(msg_status);
- elm_object_part_content_set(msg_status, "content", num_lbl);
+ if (sel_item->peer_id == id_to_check ) {
+
+ // update last message
- elm_object_part_content_set(sel_item->msg_status_lbl, "swallow.status", msg_status);
- }
- } // else
- free(msg->message);
- msg->message = NULL;
+ char* tablename = get_table_name_from_number(sel_item->peer_id);
+ tg_message_s* msg = get_message_from_message_table(message_id, tablename);
- free(msg->media_id);
- msg->media_id = NULL;
+ if (msg) {
+ if (msg->service == 2) {
+ if(msg->message) {
+ free(msg->message);
+ msg->message = NULL;
+ }
- free(msg);
- free(tablename);
+ if(msg->media_id) {
+ free(msg->media_id);
+ msg->media_id = NULL;
+ }
+ free(msg);
+ return SVC_RES_OK;
+ }
- break;
- } // foreach
+ if (msg->service == 1) {
+ if (msg->message && strlen(msg->message) > 0) {
+ sel_item->last_message = strdup(msg->message);
+ } else {
+ sel_item->last_message = strdup(" ");
+ }
+ } else {
- if (type_of_chat == TGL_PEER_USER) {
- if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE
- && app->peer_in_cahtting_data
- && app->peer_in_cahtting_data->use_data->peer_id == from_id)
- {
- on_text_message_received_from_buddy(app, message_id, type_of_chat);
+ int media_type = msg->media_type;
+ if(media_type == tgl_message_media_none) {
+ if (msg->message && strlen(msg->message) > 0) {
+ sel_item->last_message = strdup(msg->message);
+ } else {
+ sel_item->last_message = strdup(" ");
+ }
+ } else if(media_type == tgl_message_media_photo) {
+ sel_item->last_message = strdup("Image");
+ } else if(media_type == tgl_message_media_document) {
+ if (msg->message && strlen(msg->message) > 0) {
+ sel_item->last_message = strdup(msg->message);
+ } else {
+ sel_item->last_message = strdup("Document");
+ }
+ } else if(media_type == tgl_message_media_geo) {
+ sel_item->last_message = strdup("Geo location");
+ } else if(media_type == tgl_message_media_contact) {
+ sel_item->last_message = strdup("Contact");
+ } else if(media_type == tgl_message_media_unsupported) {
+ sel_item->last_message = strdup(" ");
+ } else if(media_type == tgl_message_media_photo_encr) {
+ sel_item->last_message = strdup("Image encrypted");
+ } else if(media_type == tgl_message_media_document_encr) {
+ sel_item->last_message = strdup("Document encrypted");
+ } else {
+ sel_item->last_message = strdup(" ");
+ }
+ }
+ sel_item->last_msg_id = msg->msg_id;
+ sel_item->last_msg_type = msg->media_type;
+ sel_item->is_out_msg = msg->out;
+ sel_item->last_msg_status = msg->msg_state;
+ sel_item->last_seen_time = msg->date;
+ sel_item->number_of_unread_msgs = get_unread_message_count(tablename);
+
+ if (sel_item->profile_pic) {
+
+ }
+
+ if (sel_item->user_name_lbl) {
+
+ }
+
+ if (sel_item->status_lbl) {
+ char* org_msg = NULL;
+ if (sel_item->last_message) {
+ org_msg = sel_item->last_message;
+ } else {
+ org_msg = "";
+ }
+
+ int len_org_str = strlen(org_msg);
+
+ char res[25] = {'\0'};
+ char status_buf[126] = {'\0'};
+ if(len_org_str > 25) {
+ strncpy(res, org_msg, 24);
+ if(msg->service) {
+ sprintf(status_buf,"<font=Tizen:style=Italic color=#158CB0 align=left><font_size=30>%s</font_size></font>", res);
+ } else {
+ sprintf(status_buf,"<font=Tizen:style=Italic color=#A4A4A4 align=left><font_size=30>%s</font_size></font>", res);
+ }
+ } else {
+ if(msg->service) {
+ sprintf(status_buf, "<font=Tizen:style=Italic color=#158CB0 align=left><font_size=30>%s</font_size></font>", org_msg);
+ } else {
+ sprintf(status_buf, "<font=Tizen:style=Italic color=#A4A4A4 align=left><font_size=30>%s</font_size></font>", org_msg);
+ }
+ }
+ elm_object_text_set(sel_item->status_lbl, status_buf);
+ }
+
+ if (sel_item->date_lbl) {
+ Eina_Bool is_today = compare_date_with_current_date(sel_item->last_seen_time);
+
+ if (is_today) {
+ elm_object_text_set(sel_item->date_lbl, "<font=Tizen:style=Italic color=#000000 align=center><font_size=25>Today</font_size></font>");
+ } else {
+ char *format = NULL;
+ time_t t = sel_item->last_seen_time;
+ format = "%d/%b/%Y";
+ struct tm lt;
+ char res[256];
+ (void) localtime_r(&t, <);
+
+ if (strftime(res, sizeof(res), format, <) == 0) {
+ (void) fprintf(stderr, "strftime(3): cannot format supplied "
+ "date/time into buffer of size %u "
+ "using: '%s'\n",
+ sizeof(res), format);
+ }
+
+ char time_str[256]={0,};
+ snprintf(time_str, sizeof(time_str), "<font=Tizen:style=Italic color=#000000 align=center><font_size=25>%s</font_size></font>", res);
+
+ elm_object_text_set(sel_item->date_lbl,time_str);
+ }
+ }
+ if (sel_item->msg_status_lbl) {
+ Evas_Object* temp_lbl = elm_object_part_content_get(sel_item->msg_status_lbl, "swallow.status");
+ if (temp_lbl) {
+ evas_object_del(temp_lbl);
+ }
+
+ Evas_Object* num_lbl = elm_label_add(app->nf);
+ elm_object_style_set(num_lbl, "transparent");
+ char unread_msgs[256];
+ sprintf(unread_msgs, "<font=Tizen:style=Bold color=#ffffff align=center><font_size=25>%d</font_size></font>", sel_item->number_of_unread_msgs);
+ elm_object_text_set(num_lbl, unread_msgs);
+ evas_object_size_hint_weight_set(num_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(num_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(num_lbl);
+
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* msg_status = elm_layout_add(app->nf);
+ elm_layout_file_set(msg_status, edj_path, "circle_item");
+ evas_object_size_hint_weight_set(msg_status, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(msg_status, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(msg_status);
+ elm_object_part_content_set(msg_status, "content", num_lbl);
+
+ elm_object_part_content_set(sel_item->msg_status_lbl, "swallow.status", msg_status);
+
+ }
+ if(msg->message) {
+ free(msg->message);
+ msg->message = NULL;
+ }
+
+ if(msg->media_id) {
+ free(msg->media_id);
+ msg->media_id = NULL;
+ }
+ free(msg);
+ }
+
+ free(tablename);
+ break;
+ }
+ }
}
- } else if (type_of_chat == TGL_PEER_CHAT) {
- if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE
- && app->peer_in_cahtting_data
- && app->peer_in_cahtting_data->use_data->peer_id == to_id)
- {
- char *tablename;
- tablename = get_table_name_from_number(to_id);
- tg_message_s* msg = get_message_from_message_table(message_id, tablename);
- if (msg) {
- // To be handled.
+ if (type_of_chat == TGL_PEER_USER) {
+ if ((app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE || app->current_app_state == TG_SET_USER_INFO_STATE) && app->peer_in_cahtting_data
+ && app->peer_in_cahtting_data->use_data->peer_id == from_id) {
on_text_message_received_from_buddy(app, message_id, type_of_chat);
+ return result;
+ }
- free(msg->message);
- msg->message = NULL;
-
- free(msg->media_id);
- msg->media_id = NULL;
+ } else if (type_of_chat == TGL_PEER_CHAT) {
+ if ((app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE || app->current_app_state == TG_SET_CHAT_INFO_STATE) && app->peer_in_cahtting_data
+ && app->peer_in_cahtting_data->use_data->peer_id == to_id) {
+ char* tablename = get_table_name_from_number(to_id);
+ tg_message_s* msg = get_message_from_message_table(message_id, tablename);
+ if (msg) {
+ // To be handled.
+ on_text_message_received_from_buddy(app, message_id, type_of_chat);
+ if(msg->message) {
+ free(msg->message);
+ msg->message = NULL;
+ }
+ if(msg->media_id) {
+ free(msg->media_id);
+ msg->media_id = NULL;
+ }
+ }
free(msg);
+ free(tablename);
+ return result;
}
+ }
+
+ if (app->s_app_visible_state == APP_STATE_IN_BACKGROUND || app->current_app_state != TG_USER_MAIN_VIEW_STATE) {
+ // show notification
+ char *icon_path = (char*)ui_utils_get_resource(DEFAULT_TELEGRAM_ICON);
+ char *title = "Telegram";
+ char content[512];
- free(tablename);
+ int unread_msg_cnt = get_number_of_unread_messages();
+ sprintf(content, "%d new messages received.", unread_msg_cnt);
+
+ char *sound_track = NULL;
+ char *app_id = TELEGRAM_APP_ID;
+ tg_notification_create(app, icon_path, title, content, sound_track, app_id);
+ int err = badge_set_count(TELEGRAM_APP_ID, unread_msg_cnt);
+ if (BADGE_ERROR_NONE != err) {
+
+ }
}
- }
-}
-static void message_sent_to_buddy_handler(bundle *rec_msg, void *data)
-{
- appdata_s *app = data;
- char *tmp;
- int buddy_id = 0;
- int message_id = 0;
- int type_of_chat = 0;
- char *table_name;
- tg_message_s *msg;
- Eina_Bool is_success = EINA_FALSE;
- int result;
-
- result = bundle_get_str(rec_msg, "buddy_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- buddy_id = atoi(tmp);
+ } else if (strcmp(rec_key_val, "buddy_readded") == 0) {
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- result = bundle_get_str(rec_msg, "message_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- message_id = atoi(tmp);
+ Eina_Bool is_success = EINA_FALSE;
+ char* is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "is_success", &is_success_val);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
+ is_success = EINA_TRUE;
+ } else {
+ is_success = EINA_FALSE;
+ }
- result = bundle_get_str(rec_msg, "table_name", &table_name);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ if (app->current_app_state == TG_SET_USER_INFO_STATE) {
+ on_user_added_response_received(app, buddy_id, is_success);
+ }
- result = bundle_get_str(rec_msg, "is_success", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ } else if (strcmp(rec_key_val, "buddy_deleted") == 0) {
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- if (!strcmp(tmp, "true")) {
- is_success = EINA_TRUE;
- } else {
- show_toast(app, "message sent failed");
- }
+ Eina_Bool is_success = EINA_FALSE;
+ char* is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "is_success", &is_success_val);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
+ is_success = EINA_TRUE;
+ } else {
+ is_success = EINA_FALSE;
+ }
- result = bundle_get_str(rec_msg, "type_of_chat", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ if (app->current_app_state == TG_SET_USER_INFO_STATE) {
+ on_user_deleted_response_received(app, buddy_id, is_success);
+ }
- type_of_chat = atoi(tmp);
+ } else if (strcmp(rec_key_val, "buddy_blocked") == 0) {
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- msg = get_message_from_message_table(message_id, table_name);
- if (!msg) {
- return;
- }
+ Eina_Bool is_success = EINA_FALSE;
+ char* is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "is_success", &is_success_val);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
+ is_success = EINA_TRUE;
+ } else {
+ is_success = EINA_FALSE;
+ }
- 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)
- {
- // update message to sent state
- on_text_message_state_changed(app, msg, type_of_chat);
- }
+ if (app->current_app_state == TG_SET_USER_INFO_STATE) {
+ on_user_block_response_received(app, buddy_id, is_success);
+ }
- if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
- tg_main_list_item_s *sel_item;
- Eina_List *l;
+ } else if (strcmp(rec_key_val, "buddy_unblocked") == 0) {
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
+
+ Eina_Bool is_success = EINA_FALSE;
+ char* is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "is_success", &is_success_val);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
+ is_success = EINA_TRUE;
+ } else {
+ is_success = EINA_FALSE;
+ }
+
+ if (app->current_app_state == TG_SET_USER_INFO_STATE) {
+ on_user_unblock_response_received(app, buddy_id, is_success);
+ }
+
+ } else if (strcmp(rec_key_val, "group_chat_deleted_response") == 0) {
+ char* chat_id_str = NULL;
+ result = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
+ int chat_id = atoi(chat_id_str);
+
+ Eina_Bool is_success = EINA_FALSE;
+ char* is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "is_success", &is_success_val);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
+ is_success = EINA_TRUE;
+ } else {
+ is_success = EINA_FALSE;
+ }
- EINA_LIST_FOREACH(app->main_list, l, sel_item) {
- if (sel_item->peer_id == buddy_id && sel_item->last_msg_id != message_id) {
- continue;
+ if (is_success) {
+ if(app->peer_list) {
+ int size = eina_list_count(app->peer_list);
+ for (int i = 0 ; i < size ; i++) {
+ peer_with_pic_s *item = eina_list_nth(app->peer_list, i);
+ if (item->use_data->peer_id == chat_id) {
+ app->peer_list = eina_list_remove(app->peer_list, item);
+ break;
+ }
+ }
}
- if (sel_item->msg_status_lbl) {
- elm_image_file_set(sel_item->msg_status_lbl, ui_utils_get_resource(MESSAGE_SENT_ICON), NULL);
+ if(app->main_list) {
+ int size = eina_list_count(app->main_list);
+ for (int i = 0 ; i < size ; i++) {
+ tg_main_list_item_s *item = eina_list_nth(app->main_list, i);
+ if (item->peer_id == chat_id) {
+ app->main_list = eina_list_remove(app->main_list, item);
+ break;
+ }
+ }
}
+ refresh_main_list_view(app, EINA_FALSE);
- break;
+ if (app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->peer_in_cahtting_data
+ && app->peer_in_cahtting_data->use_data->peer_id == chat_id) {
+
+ app->peer_in_cahtting_data = NULL;
+ app->main_item_in_cahtting_data = NULL;
+
+ elm_naviframe_item_pop(app->nf);
+ app->current_app_state = TG_USER_MAIN_VIEW_STATE;
+ }
+
+ if (app->current_app_state == TG_SET_CHAT_INFO_STATE && app->peer_in_cahtting_data
+ && app->peer_in_cahtting_data->use_data->peer_id == chat_id) {
+ on_group_chat_deleted(app, chat_id);
+ }
+
+ } else {
+ show_toast(app, "Failed to delete chat");
}
- }
- free(msg->message);
- msg->message = NULL;
+ } else if (strcmp(rec_key_val, "message_sent_to_buddy") == 0) {
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- free(msg->media_id);
- msg->media_id = NULL;
+ char* msg_id_str = NULL;
+ result = bundle_get_str(rec_msg, "message_id", &msg_id_str);
+ int message_id = atoi(msg_id_str);
- free(msg);
-}
+ char* table_name = NULL;
+ result = bundle_get_str(rec_msg, "table_name", &table_name);
-static void message_read_by_buddy_handler(bundle *rec_msg, void *data)
-{
- appdata_s *app = data;
- char* table_name = NULL;
- char* phone_number = NULL;
- char *tmp;
- int buddy_id;
- int message_id;
- int type_of_chat;
- tg_message_s *msg;
- int result;
-
- result = bundle_get_str(rec_msg, "buddy_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- buddy_id = atoi(tmp);
- result = bundle_get_str(rec_msg, "message_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- message_id = atoi(tmp);
+ Eina_Bool is_success = EINA_FALSE;
+ char* is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "is_success", &is_success_val);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
+ is_success = EINA_TRUE;
+ } else {
+ is_success = EINA_FALSE;
+ show_toast(app, "message sent failed");
+ }
- result = bundle_get_str(rec_msg, "table_name", &table_name);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ char* type_of_chat_str = NULL;
+ result = bundle_get_str(rec_msg, "type_of_chat", &type_of_chat_str);
+ int type_of_chat = atoi(type_of_chat_str);
- result = bundle_get_str(rec_msg, "phone_number", &phone_number);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ tg_message_s* msg = get_message_from_message_table(message_id, table_name);
- result = bundle_get_str(rec_msg, "type_of_chat", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- type_of_chat = atoi(tmp);
+ if (msg ) {
+ 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) {
+ // update message to sent state
+ on_text_message_state_changed(app, msg, type_of_chat);
+ }
- msg = get_message_from_message_table(message_id, table_name);
+ if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
- if (!msg) {
- return;
- }
+ if (app->main_list) {
+ int main_list_size = eina_list_count(app->main_list);
+ for (int i = 0; i < main_list_size; i++) {
+ tg_main_list_item_s* sel_item = eina_list_nth(app->main_list, i);
+ if (sel_item->peer_id == buddy_id && sel_item->last_msg_id == message_id) {
- 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)
- {
- // update message to sent state
- on_text_message_state_changed(app, msg, type_of_chat);
- }
+ if (sel_item->msg_status_lbl) {
+ elm_image_file_set(sel_item->msg_status_lbl, ui_utils_get_resource(MESSAGE_SENT_ICON), NULL);
+ }
- if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
- Eina_List *l;
- tg_main_list_item_s *sel_item;
+ break;
+ }
+ }
+ }
- EINA_LIST_FOREACH(app->main_list, l, sel_item) {
- if (sel_item->peer_id != buddy_id || sel_item->last_msg_id != message_id) {
- continue;
+ }
+ if(msg->message) {
+ free(msg->message);
+ msg->message = NULL;
}
- if (sel_item->msg_status_lbl) {
- elm_image_file_set(sel_item->msg_status_lbl, ui_utils_get_resource(MESSAGE_READ_ICON), NULL);
+ if(msg->media_id) {
+ free(msg->media_id);
+ msg->media_id = NULL;
}
+ free(msg);
+ }
+ } else if (strcmp(rec_key_val, "self_profile_picture_updated") == 0) {
- break;
+ Eina_Bool is_success = EINA_FALSE;
+ char *is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "is_success", &is_success_val);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
+ is_success = EINA_TRUE;
+ show_toast(app, "profile picture updated successfully.");
+ } else {
+ is_success = EINA_FALSE;
+ show_toast(app, "profile picture not updated.");
}
- }
- free(msg->message);
- msg->message = NULL;
+ if (is_success) {
+ char *file_path = NULL;
+ result = bundle_get_str(rec_msg, "file_path", &file_path);
- free(msg->media_id);
- msg->media_id = NULL;
+ if (app->current_user_data->photo_path) {
+ free(app->current_user_data->photo_path);
+ app->current_user_data->photo_path = NULL;
+ }
- free(msg);
-}
+ app->current_user_data->photo_path = strdup(file_path);
+ Evas_Object* profile_pic = evas_object_data_get(app->nf, "main_user_profile_pic");
+ if (profile_pic) {
+ elm_image_file_set(profile_pic, file_path, NULL);
+ }
-static void media_download_completed_handler(bundle *rec_msg, void *data)
-{
- appdata_s *app = data;
- char *tmp;
- int buddy_id;
- int to_id;
- long long media_id;
- char* file_name = NULL;
- int result;
-
- result = bundle_get_str(rec_msg, "buddy_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- buddy_id = atoi(tmp);
+ if (app->current_app_state == TG_SETTINGS_SCREEN_STATE) {
- result = bundle_get_str(rec_msg, "to_peer_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- to_id = atoi(tmp);
+ }
+ }
+ } else if (strcmp(rec_key_val, "self_username_updated") == 0) {
- result = bundle_get_str(rec_msg, "media_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- media_id = atoll(tmp);
+ Eina_Bool is_success = EINA_FALSE;
+ char *is_success_val = NULL;
+ result = bundle_get_str(rec_msg, "is_success", &is_success_val);
+ if (strncmp("true", is_success_val, strlen("true")) == 0) {
+ is_success = EINA_TRUE;
+ show_toast(app, "Username updated successfully.");
+ } else {
+ is_success = EINA_FALSE;
+ show_toast(app, "Username not updated. Username already exist or please check your network connection.");
+ }
- result = bundle_get_str(rec_msg, "file_name", &file_name);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ if (is_success) {
+ char *username = NULL;
+ result = bundle_get_str(rec_msg, "username", &username);
- if (file_name
- && app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE
- && app->peer_in_cahtting_data
- && app->peer_in_cahtting_data->use_data->peer_id == to_id)
- {
- // update media to sent state
- on_media_download_completed(data, buddy_id, media_id, file_name);
- }
-}
+ if (app->current_user_data->username) {
+ free(app->current_user_data->username);
+ app->current_user_data->username = NULL;
+ }
-static void name_registration_request_handler(bundle *rec_msg, void *data)
-{
- appdata_s *app = data;
- launch_first_registration_cb(app);
-}
+ app->current_user_data->username = strdup(username);
-static void add_contacts_request_handler(bundle *rec_msg, void *data)
-{
- appdata_s *app = data;
- Eina_List *contacts_list = NULL;
- contact_data_s *contact_data;
- // load contacts
- if (sc_db_utils_connect()) {
- contacts_list = get_contact_list_from_device_db();
- sc_db_utils_disconnect();
- } else {
- // Failed to get contacts list
- }
+ if (app->current_app_state == TG_SETTINGS_SCREEN_STATE || app->current_app_state == TG_SET_USERNAME_STATE) {
+ Evas_Object *name_lbl = evas_object_data_get(app->nf, "settings_user_name_label");
+ if (name_lbl) {
+ char buf[512] = {'\0'};
+ snprintf(buf, 512, "<font=Tizen:style=Bold color=#000000 align=left><font_size=40>%s</font_size></font>", app->current_user_data->username);
+ elm_object_text_set(name_lbl, buf);
+ }
+ }
+ if (app->current_app_state == TG_SET_USERNAME_STATE) {
+ elm_naviframe_item_pop(app->nf);
+ app->current_app_state = TG_SETTINGS_SCREEN_STATE;
+ }
+ }
- if (eina_list_count(contacts_list) <= 0) {
- // no contacts avilable. empty contact list.
- return;
- }
+ } else if (strcmp(rec_key_val, "message_read_by_buddy") == 0) {
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- send_contacts_list_to_server(app->service_client, contacts_list);
+ char* msg_id_str = NULL;
+ result = bundle_get_str(rec_msg, "message_id", &msg_id_str);
+ int message_id = atoi(msg_id_str);
- EINA_LIST_FREE(contacts_list, contact_data) {
- free(contact_data->display_name);
- free(contact_data->first_name);
- free(contact_data->last_name);
- free(contact_data->phone_number);
- free(contact_data);
- }
-}
+ char* table_name = NULL;
+ result = bundle_get_str(rec_msg, "table_name", &table_name);
-static void new_group_added_handler(bundle *rec_msg, void *data)
-{
- appdata_s *app = data;
-#if 0
- char* chat_id_str = NULL;
- result = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
- int chat_id = atoi(chat_id_str);
- // get group chat details from database.(chat info)
- // tg_chat_info_s* chat_info = get_chat_info(chat_id);
-
- load_buddy_list_data(app);
- load_group_chat_data(app);
- load_peer_data(app);
- load_main_list_data(app);
- if (app->current_app_state == TG_BUDDY_LIST_STATE) {
- //refresh_buddy_list(app);
- show_toast(app, "new group created");
- } else {
- elm_naviframe_item_pop(app->nf);
- //refresh_buddy_list(app);
- }
-#else
- if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
- refresh_main_view_list(app);
- } else {
- refresh_main_view_list(app);
- elm_naviframe_item_pop(app->nf);
- app->current_app_state = TG_USER_MAIN_VIEW_STATE;
- evas_object_show(app->panel);
- //elm_panel_hidden_set(app->panel, EINA_FALSE);
- }
-#endif
-}
+ char* phone_number = NULL;
+ result = bundle_get_str(rec_msg, "phone_number", &phone_number);
-static void contact_updated_handler(bundle *rec_msg, void *data)
-{
- appdata_s *app = data;
- int result;
+ char* type_of_chat_str = NULL;
+ result = bundle_get_str(rec_msg, "type_of_chat", &type_of_chat_str);
+ int type_of_chat = atoi(type_of_chat_str);
- char* buddy_id_str = NULL;
- result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
- //int buddy_id = atoi(buddy_id_str);
+ tg_message_s* msg = get_message_from_message_table(message_id, table_name);
- char* update_msg = NULL;
- result = bundle_get_str(rec_msg, "update_message", &update_msg);
- //show_toast(app, update_msg);
-}
+ if (msg ) {
+ 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) {
+ // update message to sent state
+ on_text_message_state_changed(app, msg, type_of_chat);
+ }
-static void buddy_status_updated_handler(bundle *rec_msg, void *data)
-{
- appdata_s *app = data;
- char *tmp;
- int buddy_id;
- int result;
+ if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
- result = bundle_get_str(rec_msg, "buddy_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ if (app->main_list) {
+ int main_list_size = eina_list_count(app->main_list);
+ for (int i = 0; i < main_list_size; i++) {
+ tg_main_list_item_s* sel_item = eina_list_nth(app->main_list, i);
+ if (sel_item->peer_id == buddy_id && sel_item->last_msg_id == message_id) {
- buddy_id = atoi(tmp);
- // update to online or last seen, if current view is conversation.
+ if (sel_item->msg_status_lbl) {
+ elm_image_file_set(sel_item->msg_status_lbl, ui_utils_get_resource(MESSAGE_READ_ICON), NULL);
+ }
- // sandeep
- 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)
- {
- on_user_presence_state_changed(app, buddy_id);
- }
-}
+ break;
+ }
+ }
+ }
+ }
-static void type_status_updated_handler(bundle *rec_msg, void *data)
-{
- appdata_s *app = data;
- char *tmp;
- char *buddy_name;
- int buddy_id;
- enum tgl_typing_status type_status;
- char *type_status_message;
- int result;
-
- result = bundle_get_str(rec_msg, "buddy_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ if(msg->message) {
+ free(msg->message);
+ msg->message = NULL;
+ }
- buddy_id = atoi(tmp);
+ if(msg->media_id) {
+ free(msg->media_id);
+ msg->media_id = NULL;
+ }
+ free(msg);
+ }
- result = bundle_get_str(rec_msg, "buddy_name", &buddy_name);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ } else if (strcmp(rec_key_val, "media_download_completed") == 0) {
- result = bundle_get_str(rec_msg, "type_status", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- type_status = atoi(tmp);
+ char* to_id_str = NULL;
+ result = bundle_get_str(rec_msg, "to_peer_id", &to_id_str);
+ int to_id = atoi(to_id_str);
- // update UI
+ char* media_id_str = NULL;
+ result = bundle_get_str(rec_msg, "media_id", &media_id_str);
+ long long media_id = atoll(media_id_str);
- switch (type_status) {
- case tgl_typing_none:
- type_status_message = strdup("doing nothing");
- break;
- case tgl_typing_typing:
- type_status_message = strdup("typing...");
- break;
- case tgl_typing_cancel:
- type_status_message = strdup("deleting typed message");
- break;
- case tgl_typing_record_video:
- type_status_message = strdup("recording video");
- break;
- case tgl_typing_upload_video:
- type_status_message = strdup("uploading video");
- break;
- case tgl_typing_record_audio:
- type_status_message = strdup("recording audio");
- break;
- case tgl_typing_upload_audio:
- type_status_message = strdup("uploading audio");
- break;
- case tgl_typing_upload_photo:
- type_status_message = strdup("uploading photo");
- break;
- case tgl_typing_upload_document:
- type_status_message = strdup("uploading document");
- break;
- case tgl_typing_geo:
- type_status_message = strdup("choosing location");
- break;
- case tgl_typing_choose_contact:
- type_status_message = strdup("choosing contact");
- break;
- default:
- type_status_message = NULL;
- break;
- }
+ char* file_name = NULL;
+ result = bundle_get_str(rec_msg, "file_name", &file_name);
- // update UI. may be contacts view or conversation view.
- if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
- Eina_List *l;
- tg_main_list_item_s *sel_item;
+ //file_name == "failed_to_load"
- EINA_LIST_FOREACH(app->main_list, l, sel_item) {
- if (sel_item->peer_id != buddy_id ) {
- continue;
- }
- // update last message
+ if (strstr(file_name, "failed_to_load") != NULL) {
+ // download failed.
+ show_toast(app, "media download failed.");
+ }
- if (sel_item->profile_pic) {
+ if (file_name && app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->peer_in_cahtting_data
+ && app->peer_in_cahtting_data->use_data->peer_id == to_id) {
+ // update media to sent state
+ on_media_download_completed(app, buddy_id, media_id, file_name);
+ }
+ } else if (strcmp(rec_key_val, "video_thumb_download_completed") == 0) {
- }
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
+
+ char* to_id_str = NULL;
+ result = bundle_get_str(rec_msg, "to_peer_id", &to_id_str);
+ int to_id = atoi(to_id_str);
- if (sel_item->user_name_lbl) {
+ char* media_id_str = NULL;
+ result = bundle_get_str(rec_msg, "media_id", &media_id_str);
+ long long media_id = atoll(media_id_str);
+ char* file_name = NULL;
+ result = bundle_get_str(rec_msg, "file_name", &file_name);
+
+ if (file_name && app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE && app->peer_in_cahtting_data
+ && app->peer_in_cahtting_data->use_data->peer_id == to_id) {
+ // update thumbnail icon
+ on_video_thumb_download_completed(app, buddy_id, media_id, file_name);
+ }
+ } else if (strcmp(rec_key_val, "add_contacts_request") == 0) {
+
+ // load contacts
+
+ if(sc_db_utils_connect())
+ {
+ Eina_List* contacts_list = get_contact_list_from_device_db();
+ sc_db_utils_disconnect();
+
+ if (!contacts_list || eina_list_count(contacts_list) <= 0) {
+ // no contacts avilable. empty contact list.
+ return result;
}
+ send_contacts_list_to_server(app->service_client, contacts_list);
- if (sel_item->status_lbl) {
- char* org_msg = NULL;
- char res[25] = {'\0'};
- char status_buf[512] = {'\0'};
- int len_org_str;
+ for (int i = 0; i < eina_list_count(contacts_list) ; i++) {
+ contact_data_s* contact_data = eina_list_nth(contacts_list, i);
+ if (contact_data->display_name) {
+ free(contact_data->display_name);
+ contact_data->display_name = NULL;
+ }
- if (type_status_message) {
- org_msg = type_status_message;
- } else {
- org_msg = "";
+ if (contact_data->first_name) {
+ free(contact_data->first_name);
+ contact_data->first_name = NULL;
}
- len_org_str = strlen(org_msg);
+ if (contact_data->last_name) {
+ free(contact_data->last_name);
+ contact_data->last_name = NULL;
+ }
- if(len_org_str > 25) {
- strncpy(res, org_msg, 25);
- snprintf(status_buf, sizeof(status_buf) - 1,
- "<font=Tizen:style=Italic color=#008000 align=left><font_size=30>%s</font_size></font>", res);
- } else {
- snprintf(status_buf, sizeof(status_buf) - 1,
- "<font=Tizen:style=Italic color=#008000 align=left><font_size=30>%s</font_size></font>", org_msg);
+ if (contact_data->phone_number) {
+ free(contact_data->phone_number);
+ contact_data->phone_number = NULL;
}
- elm_object_text_set(sel_item->status_lbl, status_buf);
+ free(contact_data);
}
+ eina_list_free(contacts_list);
+ }
+ } else if (strcmp(rec_key_val, "new_group_added") == 0) {
+
+ char* chat_id_str = NULL;
+ result = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
+
+
+#if 0
- if (sel_item->date_lbl) {
+ // get group chat details from database.(chat info)
+ // tg_chat_info_s* chat_info = get_chat_info(chat_id);
+ load_buddy_list_data(app);
+ load_group_chat_data(app);
+ load_peer_data(app);
+ load_main_list_data(app);
+ if (app->current_app_state == TG_BUDDY_LIST_STATE) {
+ //refresh_buddy_list(app);
+ show_toast(app, "new group created");
+ } else {
+ elm_naviframe_item_pop(app->nf);
+ //refresh_buddy_list(app);
+ }
+#else
+ int chat_id = atoi(chat_id_str);
+ peer_with_pic_s *peer_item = get_peer_info(chat_id);
+ if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
+ tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
+ app->main_list = eina_list_prepend(app->main_list, latest_item);
+ refresh_main_list_view(app, EINA_TRUE);
+ } else {
+ tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
+ app->main_list = eina_list_prepend(app->main_list, latest_item);
+ refresh_main_list_view(app, EINA_TRUE);
+ elm_naviframe_item_pop(app->nf);
+ app->current_app_state = TG_USER_MAIN_VIEW_STATE;
+ evas_object_show(app->panel);
+ //elm_panel_hidden_set(app->panel, EINA_FALSE);
+ }
+ app->peer_list = eina_list_prepend(app->peer_list, peer_item);
+#endif
+ } else if (strcmp(rec_key_val, "contact_updated") == 0) {
+
+
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ //int buddy_id = atoi(buddy_id_str);
+
+ char* update_msg = NULL;
+ result = bundle_get_str(rec_msg, "update_message", &update_msg);
+ //show_toast(app, update_msg);
+ } else if (strcmp(rec_key_val, "buddy_status_updated") == 0) {
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
+ // update to online or last seen, if current view is conversation.
+
+ // sandeep
+ 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) {
+ on_user_presence_state_changed(app, buddy_id);
+ }
+
+ } else if (strcmp(rec_key_val, "type_status_updated") == 0) {
+
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
+
+ char* buddy_name = NULL;
+ result = bundle_get_str(rec_msg, "buddy_name", &buddy_name);
+
+ char* type_status_str = NULL;
+ result = bundle_get_str(rec_msg, "type_status", &type_status_str);
+ enum tgl_typing_status type_status = atoi(type_status_str);
+
+ // update UI
+ char* type_status_message = NULL;
+
+ switch (type_status) {
+ case tgl_typing_none:
+ type_status_message = (char*)malloc(strlen("doing nothing") + 1);
+ strcpy(type_status_message, "doing nothing");
+ break;
+ case tgl_typing_typing:
+ type_status_message = (char*)malloc(strlen("typing...") + 1);
+ strcpy(type_status_message, "typing...");
+ break;
+ case tgl_typing_cancel:
+ type_status_message = (char*)malloc(strlen("deleting typed message") + 1);
+ strcpy(type_status_message, "deleting typed message");
+ break;
+ case tgl_typing_record_video:
+ type_status_message = (char*)malloc(strlen("recording video") + 1);
+ strcpy(type_status_message, "recording video");
+ break;
+ case tgl_typing_upload_video:
+ type_status_message = (char*)malloc(strlen("uploading video") + 1);
+ strcpy(type_status_message, "uploading video");
+ break;
+ case tgl_typing_record_audio:
+ type_status_message = (char*)malloc(strlen("recording audio") + 1);
+ strcpy(type_status_message, "recording audio");
+ break;
+ case tgl_typing_upload_audio:
+ type_status_message = (char*)malloc(strlen("uploading audio") + 1);
+ strcpy(type_status_message, "uploading audio");
+ break;
+ case tgl_typing_upload_photo:
+ type_status_message = (char*)malloc(strlen("uploading photo") + 1);
+ strcpy(type_status_message, "uploading photo");
+ break;
+ case tgl_typing_upload_document:
+ type_status_message = (char*)malloc(strlen("uploading document") + 1);
+ strcpy(type_status_message, "uploading document");
+ break;
+ case tgl_typing_geo:
+ type_status_message = (char*)malloc(strlen("choosing location") + 1);
+ strcpy(type_status_message, "choosing location");
+ break;
+ case tgl_typing_choose_contact:
+ type_status_message = (char*)malloc(strlen("choosing contact") + 1);
+ strcpy(type_status_message, "choosing contact");
+ break;
+ }
+
+ // update UI. may be contacts view or conversation view.
+ if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
+ if (app->main_list) {
+ int main_list_size = eina_list_count(app->main_list);
+ for (int i = 0; i < main_list_size; i++) {
+ tg_main_list_item_s* sel_item = eina_list_nth(app->main_list, i);
+ if (sel_item->peer_id == buddy_id ) {
+ // update last message
+
+ if (sel_item->profile_pic) {
+
+ }
+
+ if (sel_item->user_name_lbl) {
+
+ }
+
+ if (sel_item->status_lbl) {
+ char* org_msg = NULL;
+ if (type_status_message) {
+ org_msg = type_status_message;
+ } else {
+ org_msg = "";
+ }
+
+ int len_org_str = strlen(org_msg);
+
+ char res[25] = {'\0'};
+ char status_buf[512] = {'\0'};
+ if(len_org_str > 25) {
+ strncpy(res, org_msg, 25);
+ snprintf(status_buf, 512, "<font=Tizen:style=Italic color=#008000 align=left><font_size=30>%s</font_size></font>", res);
+ } else {
+ snprintf(status_buf, 512, "<font=Tizen:style=Italic color=#008000 align=left><font_size=30>%s</font_size></font>", org_msg);
+ }
+ elm_object_text_set(sel_item->status_lbl, status_buf);
+ }
+
+ if (sel_item->date_lbl) {
+
+ }
+ if (sel_item->msg_status_lbl) {
+
+ }
+ break;
+ }
+ }
}
- if (sel_item->msg_status_lbl) {
+ }
+
+ 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) {
+ on_user_status_changed(app, type_status_message);
+ }
+
+ if (type_status_message) {
+ free(type_status_message);
+ type_status_message = NULL;
+ }
+
+ } else if (strcmp(rec_key_val, "user_status_updated") == 0) {
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
+
+ char* buddy_name = NULL;
+ result = bundle_get_str(rec_msg, "buddy_name", &buddy_name);
+
+ if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
+ if (app->main_list) {
+ int main_list_size = eina_list_count(app->main_list);
+ for (int i = 0; i < main_list_size; i++) {
+ tg_main_list_item_s* sel_item = eina_list_nth(app->main_list, i);
+ if (sel_item->peer_id == buddy_id ) {
+ // update last message
+
+ if (sel_item->profile_pic) {
+
+ }
+
+ if (sel_item->user_name_lbl) {
+
+ }
+
+ if (sel_item->status_lbl) {
+ char* org_msg = NULL;
+ if (sel_item->last_message) {
+ org_msg = sel_item->last_message;
+ } else {
+ org_msg = "";
+ }
+
+ int len_org_str = strlen(org_msg);
+
+ char res[25] = {'\0'};
+ char status_buf[126] = {'\0'};
+ if(len_org_str > 25) {
+ strncpy(res, org_msg, 24);
+ sprintf(status_buf,"<font=Tizen:style=Italic color=#A4A4A4 align=left><font_size=30>%s</font_size></font>", res);
+ } else {
+ snprintf(status_buf, "<font=Tizen:style=Italic color=#A4A4A4 align=left><font_size=30>%s</font_size></font>", org_msg);
+ }
+ elm_object_text_set(sel_item->status_lbl, status_buf);
+ }
+
+ if (sel_item->date_lbl) {
+
+ }
+ if (sel_item->msg_status_lbl) {
+
+ }
+
+ break;
+ }
+ }
}
- break;
}
+ 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) {
+ on_user_presence_state_changed(app, buddy_id);
+ }
+
+ } else {
+
}
+ hide_loading_popup(app);
+ return result;
+}
- 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)
+int init_service(appdata_s *app)
+{
+ int result = SVC_RES_FAIL;
+ RETVM_IF(!app, result, "Application data is NULL");
+
+ app->service_client = service_client_create();
+ RETVM_IF(!app->service_client, result, "Failed to create service client");
+
+ result = service_client_register_port(app->service_client, TELEGRAM_CLIENT_PORT_NAME);
+ if (result != SVC_RES_OK)
{
- on_user_status_changed(app, type_status_message);
+ ERR("Failed to register service client port");
+ service_client_destroy(app->service_client);
+ app->service_client = NULL;
+ return result;
}
- free(type_status_message);
- type_status_message = NULL;
+ result = _service_client_set_remote_data(app->service_client, TELEGRAM_SERVER_APP_NAME, TELEGRAM_SERVER_PORT_NAME);
+
+ result = service_client_register_msg_receive_callback(app->service_client, _on_service_client_msg_received_cb, app);
+ if (result != SVC_RES_OK)
+ {
+ ERR("Failed to register service client on message receive callback");
+ service_client_destroy(app->service_client);
+ app->service_client = NULL;
+ return result;
+ }
+ return result;
}
-static void user_status_updated_handler(bundle *rec_msg, void *data)
+void win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
{
- appdata_s *app = data;
- char *tmp;
- int buddy_id;
- char *buddy_name = NULL;
- int result;
+ ui_app_exit();
+}
- result = bundle_get_str(rec_msg, "buddy_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- buddy_id = atoi(tmp);
+tg_main_list_item_s* get_latest_item(appdata_s *ad, peer_with_pic_s *item)
+{
+ tg_main_list_item_s* main_list_item = NULL;
+ if (item) {
+ tg_peer_info_s* peer_info = item->use_data;
+ if(peer_info) {
- result = bundle_get_str(rec_msg, "buddy_name", &buddy_name);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ // get message from message table.
- if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
- Eina_List *l;
- tg_main_list_item_s *sel_item;
- EINA_LIST_FOREACH(app->main_list, l, sel_item) {
- if (sel_item->peer_id != buddy_id) {
- continue;
- }
+ char* tablename = get_table_name_from_number(peer_info->peer_id);
+ tg_message_s* msg = get_latest_message_from_message_table(tablename);
+
+ if (msg) {
- // update last message
+ if (msg->service) {
+ if (msg->message && strlen(msg->message) > 0) {
+ item->last_message = strdup(msg->message);
+ } else {
+ item->last_message = strdup(" ");
+ }
+ } else {
- if (sel_item->profile_pic) {
+ int media_type = msg->media_type;
+ if(media_type == tgl_message_media_none) {
+ if (msg->message && strlen(msg->message) > 0) {
+ item->last_message = strdup(msg->message);
+ } else {
+ item->last_message = strdup(" ");
+ }
+ } else if(media_type == tgl_message_media_photo) {
+ item->last_message = strdup("Image");
+ } else if(media_type == tgl_message_media_document) {
+ if (msg->message && strlen(msg->message) > 0) {
+ item->last_message = strdup(msg->message);
+ } else {
+ item->last_message = strdup("Document");
+ }
+ } else if(media_type == tgl_message_media_geo) {
+ item->last_message = strdup("Geo location");
+ } else if(media_type == tgl_message_media_contact) {
+ item->last_message = strdup("Contact");
+ } else if(media_type == tgl_message_media_unsupported) {
+ item->last_message = strdup(" ");
+ } else if(media_type == tgl_message_media_photo_encr) {
+ item->last_message = strdup("Image encrypted");
+ } else if(media_type == tgl_message_media_document_encr) {
+ item->last_message = strdup("Document encrypted");
+ } else {
+ item->last_message = strdup(" ");
+ }
+ }
+
+ main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s));
+ main_list_item->peer_id = peer_info->peer_id;
+ main_list_item->peer_type = peer_info->peer_type;
+ main_list_item->peer_print_name = strdup(peer_info->print_name);
+ main_list_item->last_seen_time = msg->date;
+ main_list_item->profile_pic = NULL;
+ main_list_item->last_msg_id = msg->msg_id;
+ main_list_item->last_message = strdup(item->last_message);
+ main_list_item->last_msg_type = msg->media_type;
+ main_list_item->is_out_msg = msg->out;
+ main_list_item->last_msg_status = msg->msg_state;
+ main_list_item->last_msg_service = msg->service;
+ main_list_item->number_of_unread_msgs = get_unread_message_count(tablename);
+ if (peer_info->photo_path) {
+ main_list_item->profile_pic_path = strdup(peer_info->photo_path);
+ } else {
+ main_list_item->profile_pic_path = NULL;
+ }
+ main_list_item->user_name_lbl = NULL;
+ main_list_item->status_lbl = NULL;
+ main_list_item->date_lbl = NULL;
+ main_list_item->msg_status_lbl = NULL;
- }
- if (sel_item->user_name_lbl) {
+ // delete message object
+ if(msg->message) {
+ free(msg->message);
+ msg->message = NULL;
+ }
- }
+ if(msg->media_id) {
+ free(msg->media_id);
+ msg->media_id = NULL;
+ }
- if (sel_item->status_lbl) {
- char* org_msg;
- int len_org_str;
- char res[25] = {'\0'};
- char status_buf[126] = {'\0'};
+ free(msg);
+ msg = NULL;
- if (sel_item->last_message) {
- org_msg = sel_item->last_message;
} else {
- org_msg = "";
- }
-
- len_org_str = strlen(org_msg);
+ item->last_message = strdup(" ");
+ if (peer_info->peer_type == TGL_PEER_CHAT) {
+ main_list_item = (tg_main_list_item_s*)malloc(sizeof(tg_main_list_item_s));
+ main_list_item->peer_id = peer_info->peer_id;
+ main_list_item->peer_type = peer_info->peer_type;
+ main_list_item->peer_print_name = strdup(peer_info->print_name);
+ main_list_item->last_seen_time = peer_info->last_seen_time;
+ main_list_item->profile_pic = NULL;
+ main_list_item->last_message = strdup(item->last_message);
+ main_list_item->last_msg_type = -1;
+ main_list_item->last_msg_service = 0;
+ main_list_item->is_out_msg = -1;
+ main_list_item->last_msg_id = -1;
+ main_list_item->last_msg_status = -1;
+ main_list_item->number_of_unread_msgs = 0;
+ if (peer_info->photo_path) {
+ main_list_item->profile_pic_path = strdup(peer_info->photo_path);
+ } else {
+ main_list_item->profile_pic_path = NULL;
+ }
+ main_list_item->user_name_lbl = NULL;
+ main_list_item->status_lbl = NULL;
+ main_list_item->date_lbl = NULL;
+ main_list_item->msg_status_lbl = NULL;
- if(len_org_str > 25) {
- strncpy(res, org_msg, 24);
- snprintf(status_buf, sizeof(status_buf) - 1,
- "<font=Tizen:style=Italic color=#A4A4A4 align=left><font_size=30>%s</font_size></font>", res);
- } else {
- snprintf(status_buf, sizeof(status_buf) - 1,
- "<font=Tizen:style=Italic color=#A4A4A4 align=left><font_size=30>%s</font_size></font>", org_msg);
+ }
}
- elm_object_text_set(sel_item->status_lbl, status_buf);
- }
-
- if (sel_item->date_lbl) {
-
- }
-
- if (sel_item->msg_status_lbl) {
-
- }
-
- break;
- }
- }
-
- 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)
- {
- on_user_presence_state_changed(app, buddy_id);
- }
-}
-
-static int _on_service_client_msg_received_cb(void *data, bundle * const rec_msg)
-{
- int result = SVC_RES_FAIL;
- RETVM_IF(!data, result, "Data is NULL");
- char *rec_key_val = NULL;
- int i;
- static struct _msg_handler {
- const char *key;
- void (*handler)(bundle *b, void *data);
- } msg_handlers[] = {
- [0] = {
- .key = "registration_done",
- .handler = registration_done_handler,
- },
- [1] = {
- .key = "contacts_load_done",
- .handler = contacts_load_done_handler,
- },
- [2] = {
- .key = "contacts_and_chats_load_done",
- .handler = contacts_and_chats_load_done_handler,
- },
- [3] = {
- .key = "buddy_profile_pic_updated",
- .handler = buddy_profile_pic_updated_handler,
- },
- [4] = {
- .key = "message_received",
- .handler = message_received_handler,
- },
- [5] = {
- .key = "message_sent_to_buddy",
- .handler = message_sent_to_buddy_handler,
- },
- [6] = {
- .key = "message_read_by_buddy",
- .handler = message_read_by_buddy_handler,
- },
- [7] = {
- .key = "media_download_completed",
- .handler = media_download_completed_handler,
- },
- [8] = {
- .key = "name_registration_request",
- .handler = name_registration_request_handler,
- },
- [9] = {
- .key = "add_contacts_request",
- .handler = add_contacts_request_handler,
- },
- [10] = {
- .key = "new_group_added",
- .handler = new_group_added_handler,
- },
- [11] = {
- .key = "contact_updated",
- .handler = contact_updated_handler,
- },
- [12] = {
- .key = "buddy_status_updated",
- .handler = buddy_status_updated_handler,
- },
- [13] = {
- .key = "type_status_updated",
- .handler = type_status_updated_handler,
- },
- [14] = {
- .key = "user_status_updated",
- .handler = user_status_updated_handler,
- },
- [15] = {
- .key = NULL,
- .handler = NULL,
- },
- };
-
- result = bundle_get_str(rec_msg, "command", &rec_key_val);
- for (i = 0; msg_handlers[i].key; i++) {
- if (strcmp(msg_handlers[i].key, rec_key_val)) {
- continue;
- }
-
- if (!msg_handlers[i].handler) {
- continue;
+ if (tablename) {
+ free(tablename);
+ tablename = NULL;
+ }
}
-
- msg_handlers[i].handler(rec_msg, data);
- }
-}
-
-int init_service(appdata_s *app)
-{
- int result = SVC_RES_FAIL;
- RETVM_IF(!app, result, "Application data is NULL");
-
- app->service_client = service_client_create();
- RETVM_IF(!app->service_client, result, "Failed to create service client");
-
- result = service_client_register_port(app->service_client, TELEGRAM_CLIENT_PORT_NAME);
- if (result != SVC_RES_OK)
- {
- ERR("Failed to register service client port");
- service_client_destroy(app->service_client);
- app->service_client = NULL;
- return result;
- }
-
- result = _service_client_set_remote_data(app->service_client, TELEGRAM_SERVER_APP_NAME, TELEGRAM_SERVER_PORT_NAME);
-
- result = service_client_register_msg_receive_callback(app->service_client, _on_service_client_msg_received_cb, app);
- if (result != SVC_RES_OK)
- {
- ERR("Failed to register service client on message receive callback");
- service_client_destroy(app->service_client);
- app->service_client = NULL;
- return result;
}
- return result;
-}
-
-void win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
-{
- ui_app_exit();
+ return main_list_item;
}
void app_nf_back_cb(void *data, Evas_Object *obj, void *event_info)
elm_exit();
break;
case TG_CHAT_MESSAGING_VIEW_STATE:
- // to be handled
+ // to be handled
if (ad->is_last_msg_changed) {
// update main view.
// refresh main view
+ if (ad->main_list) {
+ if (ad->main_item_in_cahtting_data) {
+ tg_main_list_item_s* old_item = ad->main_item_in_cahtting_data;
+ if (old_item->peer_print_name) {
+ free(old_item->peer_print_name);
+ old_item->peer_print_name = NULL;
+ }
+ if (old_item->last_message) {
+ free(old_item->last_message);
+ old_item->last_message = NULL;
+ }
+ if (old_item->profile_pic_path) {
+ free(old_item->profile_pic_path);
+ old_item->profile_pic_path = NULL;
+ }
+ old_item->date_lbl = NULL;
+ old_item->msg_status_lbl = NULL;
+ old_item->profile_pic = NULL;
+ old_item->profile_pic_path = NULL;
+ old_item->status_lbl = NULL;
+ old_item->user_name_lbl = NULL;
+ ad->main_list = eina_list_remove(ad->main_list, ad->main_item_in_cahtting_data);
+
+ ad->main_item_in_cahtting_data = NULL;
+ }
+ if (ad->peer_in_cahtting_data) {
+ peer_with_pic_s *item = ad->peer_in_cahtting_data;
+ tg_main_list_item_s* latest_item = get_latest_item(ad, item);
+ if (latest_item) {
+ ad->main_list = eina_list_prepend(ad->main_list, latest_item);
+ }
+ }
+ }
} else {
}
- refresh_main_view_list(ad);
+ refresh_main_list_view(ad, EINA_FALSE);
+ eext_object_event_callback_del(ad->nf, EEXT_CALLBACK_MORE, on_messaging_menu_button_clicked);
+ ad->main_item_in_cahtting_data = NULL;
+ ad->buddy_in_cahtting_data = NULL;
+ ad->peer_in_cahtting_data = NULL;
elm_naviframe_item_pop(ad->nf);
ad->current_app_state = TG_USER_MAIN_VIEW_STATE;
break;
+ case TG_SELECT_BUDDY_VIEW:
+ elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_SET_CHAT_INFO_STATE;
+ break;
+ case TG_PEER_SEARCH_VIEW_STATE:
+ elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_USER_MAIN_VIEW_STATE;
+ break;
+ case TG_SET_USERNAME_STATE:
+ elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_SETTINGS_SCREEN_STATE;
+ break;
+ case TG_SET_CHAT_INFO_STATE:
+ case TG_SET_USER_INFO_STATE:
+ elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_CHAT_MESSAGING_VIEW_STATE;
+ break;
case TG_START_MESSAGING_VIEW_STATE:
+ case TG_SETTINGS_SCREEN_STATE:
elm_naviframe_item_pop(ad->nf);
ad->current_app_state = TG_USER_MAIN_VIEW_STATE;
+ //evas_object_show(ad->panel);
+ //elm_panel_hidden_set(ad->panel, EINA_FALSE);
break;
case TG_REGISTRATION_STATE:
elm_win_lower(ad->win);
}
elm_naviframe_item_pop(ad->nf);
ad->current_app_state = TG_BUDDY_LIST_STATE;
- evas_object_show(ad->panel);
+ //evas_object_show(ad->panel);
//elm_panel_hidden_set(ad->panel, EINA_FALSE);
//refresh_buddy_list(ad);
break;
}
elm_naviframe_item_pop(ad->nf);
ad->current_app_state = TG_BUDDY_LIST_STATE;
- evas_object_show(ad->panel);
+ //evas_object_show(ad->panel);
//elm_panel_hidden_set(ad->panel, EINA_FALSE);
//refresh_buddy_list(ad);
break;
}
}
-void layout_back_cb(void *data, Evas_Object *obj, void *event_info)
+void
+layout_back_cb(void *data, Evas_Object *obj, void *event_info)
{
appdata_s *ad = data;
/* Let window go to hide state. */
bundle_free(msg);
}
+static Eina_Bool on_load_main_view_requested(void *data)
+{
+ appdata_s *ad = data;
+ if (ad) {
+ elm_naviframe_item_pop(ad->nf);
+ launch_user_main_view_cb(ad);
+ int unread_msg_cnt = get_number_of_unread_messages();
+ int err = badge_set_count(TELEGRAM_APP_ID, unread_msg_cnt);
+ if (BADGE_ERROR_NONE != err) {
+
+ }
+ }
+ return ECORE_CALLBACK_CANCEL;
+}
+
static void create_base_gui(appdata_s *ad)
{
evas_object_show(ad->win);
-
// check for user info
+ //
+ char *chat_bg = NULL;
+ preference_get_string(TG_CHAT_BG_PREFERENCE, &chat_bg);
+ if (chat_bg) {
+ ad->chat_background = strdup(chat_bg);
+ }
+
+ if (!ad->chat_background) {
+ ad->chat_background = strdup(ui_utils_get_resource(TG_CHAT_DEFAULT_BG));
+ preference_set_string(TG_CHAT_BG_PREFERENCE, ad->chat_background);
+ }
+
Eina_List* user_info = get_registered_user_info();
if (!user_info) {
//launch_user_main_view_cb(ad);
} else {
//show_toast(ad, "user already registered");
- load_registered_user_data(ad, user_info);
+ load_registered_user_data(ad);
load_buddy_list_data(ad);
- load_group_chat_data(ad);
+ //load_group_chat_data(ad);
load_peer_data(ad);
load_main_list_data(ad);
- // Launch buddy list view
- elm_naviframe_item_pop(ad->nf);
- //launch_buddy_list_cb(ad);
- launch_user_main_view_cb(ad);
+
+ ecore_timer_add(2, on_load_main_view_requested, ad);
+
}
//eina_list_free(user_info);
}
-static bool app_create(void *data)
+static bool
+app_create(void *data)
{
/*
Hook to take necessary actions before main event loop starts
ad->phone_number = NULL;
ad->buddy_list = NULL;
ad->main_list = NULL;
+ ad->peer_list = NULL;
+ ad->search_peer_list = NULL;
ad->is_first_time_registration = EINA_FALSE;
ad->panel = NULL;
ad->loaded_msg_list = NULL;
+ ad->loading_popup = NULL;
+ ad->current_user_data = NULL;
+ ad->is_tg_initilized = EINA_FALSE;
+ ad->chat_background = NULL;
+ ad->msg_popup = NULL;
+ ad->s_notififcation = NULL;
+ ad->panel = NULL;
+ ad->is_server_ready = EINA_FALSE;
create_base_gui(ad);
+ int err = badge_new(TELEGRAM_APP_ID);
+ if (BADGE_ERROR_NONE != err) {
+
+ }
init_service(ad);
return true;
}
-static void app_control(app_control_h app_control, void *data)
+static void
+app_control(app_control_h app_control, void *data)
{
/* Handle the launch request. */
}
-static void app_pause(void *data)
+static void
+app_pause(void *data)
{
- /* Take necessary actions when application becomes invisible. */
+ appdata_s *app_data = data;
+ if (app_data) {
+ app_data->s_app_visible_state = APP_STATE_IN_BACKGROUND;
+ }
}
-static void app_resume(void *data)
+static void
+app_resume(void *data)
{
- /* Take necessary actions when application becomes visible. */
+ appdata_s *app_data = data;
+ if (app_data) {
+ app_data->s_app_visible_state = APP_STATE_IN_FOREGROUND;
+ }
}
-static void app_terminate(void *data)
+static void
+app_terminate(void *data)
{
/* Release all resources. */
- appdata_s* app_data = data;
+ appdata_s *app_data = data;
+
+ int unread_msg_cnt = get_number_of_unread_messages();
+ int err = badge_set_count(TELEGRAM_APP_ID, unread_msg_cnt);
+ if (BADGE_ERROR_NONE != err) {
+
+ }
+
+ if (app_data->panel) {
+ Evas_Object *panel_list = evas_object_data_get(app_data->panel, "panel_list");
+ if (panel_list) {
+ evas_object_del(panel_list);
+ }
+ evas_object_del(app_data->panel);
+ app_data->panel = NULL;
+ }
+
+ if (app_data->phone_number) {
+ free(app_data->phone_number);
+ app_data->phone_number = NULL;
+ }
+
+ if (app_data->sms_code) {
+ free(app_data->sms_code);
+ app_data->sms_code = NULL;
+ }
+
if(app_data->service_client) {
service_client_destroy(app_data->service_client);
app_data->service_client = NULL;
}
+ if (app_data->current_user_data) {
+ free_user_data(app_data->current_user_data);
+ }
+ if (app_data->chat_background) {
+ app_data->chat_background = NULL;
+ }
+ if (app_data && app_data->s_notififcation) {
+ notification_delete_all(NOTIFICATION_TYPE_NOTI);
+ app_data->s_notififcation = NULL;
+ }
+
+ if (app_data->peer_list) {
+ for (int i = 0; i < eina_list_count(app_data->peer_list) ; i++) {
+ peer_with_pic_s* pic_item = eina_list_nth(app_data->peer_list, i);
+ tg_peer_info_s* item = pic_item->use_data;
+ if (item) {
+ if (item->print_name) {
+ free(item->print_name);
+ item->print_name = NULL;
+ }
+ if (item->photo_path) {
+ free(item->photo_path);
+ item->photo_path = NULL;
+ }
+ pic_item->contact_icon = NULL;
+ pic_item->msg_object = NULL;
+ pic_item->name_object = NULL;
+ free(item);
+ }
+ free(pic_item);
+ }
+ eina_list_free(app_data->peer_list);
+ }
+ app_data->peer_list = NULL;
+
+ if (app_data->main_list) {
+ for (int i = 0; i < eina_list_count(app_data->main_list) ; i++) {
+ tg_main_list_item_s* main_item = eina_list_nth(app_data->main_list, i);
+
+ if (main_item->peer_print_name) {
+ free(main_item->peer_print_name);
+ main_item->peer_print_name = NULL;
+ }
+ if (main_item->last_message) {
+ free(main_item->last_message);
+ main_item->last_message = NULL;
+ }
+ if (main_item->profile_pic_path) {
+ free(main_item->profile_pic_path);
+ main_item->profile_pic_path = NULL;
+ }
+ main_item->date_lbl = NULL;
+ main_item->msg_status_lbl = NULL;
+ main_item->profile_pic = NULL;
+ main_item->profile_pic_path = NULL;
+ main_item->status_lbl = NULL;
+ main_item->user_name_lbl = NULL;
+ }
+ eina_list_free(app_data->main_list);
+ }
+ app_data->main_list = NULL;
+
+#if 0
+ if (app_data->group_chat_list) {
+ for (int i = 0; i < eina_list_count(app_data->group_chat_list) ; i++) {
+ group_chat_with_pic_s* pic_item = eina_list_nth(app_data->group_chat_list, i);
+ tg_chat_info_s* item = pic_item->use_data;
+ if (item) {
+ if (item->photo_path) {
+ free(item->photo_path);
+ item->photo_path = NULL;
+ }
+ if (item->print_title) {
+ free(item->print_title);
+ item->print_title = NULL;
+ }
+ if (item->title) {
+ free(item->title);
+ item->title = NULL;
+ }
+ free(item);
+ }
+ free(pic_item);
+ }
+ eina_list_free(app_data->group_chat_list);
+ }
+ app_data->group_chat_list = NULL;
+#endif
+ if (app_data->buddy_list) {
+
+ for (int i = 0; i < eina_list_count(app_data->buddy_list) ; i++) {
+ user_data_with_pic_s *item = eina_list_nth(app_data->buddy_list, i);
+ user_data_s* user_data = item->use_data;
+
+ if (user_data->print_name) {
+ free(user_data->print_name);
+ user_data->print_name = NULL;
+ }
+
+ if (user_data->photo_path) {
+ free(user_data->photo_path);
+ user_data->photo_path = NULL;
+ }
+
+ if (user_data->first_name) {
+ free(user_data->first_name);
+ user_data->first_name = NULL;
+ }
+
+ if (user_data->last_name) {
+ free(user_data->last_name);
+ user_data->last_name = NULL;
+ }
+
+ if (user_data->phone) {
+ free(user_data->phone);
+ user_data->phone = NULL;
+ }
+ if (user_data->real_first_name) {
+ free(user_data->real_first_name);
+ user_data->real_first_name = NULL;
+ }
+
+ if (user_data->real_last_name) {
+ free(user_data->real_last_name);
+ user_data->real_last_name = NULL;
+ }
+
+ if (user_data->username) {
+ free(user_data->username);
+ user_data->username = NULL;
+ }
+ free(user_data);
+ free(item);
+ }
+
+ eina_list_free(app_data->buddy_list);
+ app_data->buddy_list = NULL;
+ }
+
+ if (app_data->loaded_msg_list) {
+ eina_list_free(app_data->loaded_msg_list);
+ app_data->loaded_msg_list = NULL;
+ }
+
+ if (app_data->service_client) {
+ service_client_destroy(app_data->service_client);
+ app_data->service_client = NULL;
+ }
tg_db_fini();
}
-static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
+static void
+ui_app_lang_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LANGUAGE_CHANGED*/
char *locale = NULL;
return;
}
-static void ui_app_orient_changed(app_event_info_h event_info, void *user_data)
+static void
+ui_app_orient_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
+
+ //elm_object_signal_emit(layout, "change,view", "swallow.media_item");
+
return;
}
-static void ui_app_region_changed(app_event_info_h event_info, void *user_data)
+static void
+ui_app_region_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_REGION_FORMAT_CHANGED*/
}
-static void ui_app_low_battery(app_event_info_h event_info, void *user_data)
+static void
+ui_app_low_battery(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LOW_BATTERY*/
}
-static void ui_app_low_memory(app_event_info_h event_info, void *user_data)
+static void
+ui_app_low_memory(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LOW_MEMORY*/
}
-int main(int argc, char *argv[])
+int
+main(int argc, char *argv[])
{
appdata_s ad = {0,};
int ret = 0;
--- /dev/null
+/*
+ * tg_chat_info_view.c
+ *
+ * Created on: Oct 3, 2015
+ * Author: sandeep
+ */
+
+#include "tg_chat_info_view.h"
+#include "tg_db_wrapper.h"
+#include "server_requests.h"
+#include "tg_select_buddy_from_list.h"
+
+static Evas_Object* get_image_from_path(const char* path, Evas_Object* parent)
+{
+ if (!path || !parent) {
+ return NULL;
+ }
+ Evas_Object *media_image = elm_image_add(parent);
+ elm_image_aspect_fixed_set(media_image, EINA_FALSE);
+ elm_image_file_set(media_image, path, NULL);
+ evas_object_size_hint_weight_set(media_image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(media_image, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(media_image);
+ return media_image;
+}
+
+static Eina_Bool on_view_deleteion_requested(void *data)
+{
+ appdata_s *ad = data;
+ if (ad) {
+ elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_USER_MAIN_VIEW_STATE;
+ hide_loading_popup(ad);
+ }
+ return ECORE_CALLBACK_CANCEL;
+}
+
+void on_group_chat_deleted(appdata_s *ad, int chat_id)
+{
+ if (!ad) {
+ return;
+ }
+ ad->peer_in_cahtting_data = NULL;
+ ad->main_item_in_cahtting_data = NULL;
+ show_loading_popup(ad);
+ elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_SET_CHAT_INFO_STATE;
+ ecore_timer_add(2, on_view_deleteion_requested, ad);
+}
+
+Evas_Object* on_chat_info_requested(void *data, Evas_Object *obj, const char *part)
+{
+ Evas_Object *eo = NULL;
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+ if (!strcmp(part, "elm.swallow.icon")) {
+ Evas_Object *profile_pic = NULL;
+
+ if (ad->peer_in_cahtting_data->use_data->photo_path && strlen(ad->peer_in_cahtting_data->use_data->photo_path) > 0 && strstr(ad->peer_in_cahtting_data->use_data->photo_path, "_null_") == NULL) {
+ profile_pic = get_image_from_path(ad->peer_in_cahtting_data->use_data->photo_path, ad->nf);
+ } else {
+ profile_pic = get_image_from_path(ui_utils_get_resource(DEFAULT_PROFILE_PIC), ad->nf);
+ }
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* user_pic_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_pic_layout, edj_path, "circle_layout");
+ evas_object_size_hint_weight_set(user_pic_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_pic_layout);
+ elm_object_part_content_set(user_pic_layout, "content", profile_pic);
+
+ evas_object_data_set(ad->nf, "user_chat_profile_pic", profile_pic);
+
+ eo = elm_layout_add(obj);
+ elm_layout_theme_set(eo, "layout", "list/C/type.1", "default");
+ elm_layout_content_set(eo, "elm.swallow.content", user_pic_layout);
+ } else if (!strcmp(part, "elm.swallow.icon.0")) {
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* user_status_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_status_layout, edj_path, "main_list_name_status_item");
+ evas_object_size_hint_weight_set(user_status_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_status_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_status_layout);
+
+
+ char* user_name = replace(ad->peer_in_cahtting_data->use_data->print_name, '_', " ");
+ char buf[512] = {'\0'};
+ snprintf(buf, 512, "<font=Tizen:style=Bold color=#FFFFFF align=left><font_size=40>%s</font_size></font>", user_name);
+ free(user_name);
+
+ Evas_Object* name_lbl = elm_label_add(ad->nf);
+ elm_object_text_set(name_lbl, buf);
+ evas_object_size_hint_weight_set(name_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(name_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(name_lbl);
+
+ elm_object_part_content_set(user_status_layout, "swallow.name", name_lbl);
+
+ evas_object_data_set(ad->nf, "chat_info_name", name_lbl);
+
+ Evas_Object *profile_time = evas_object_data_get(ad->nf, "profile_time");
+ char *online_status = "";
+ if (profile_time) {
+ online_status = elm_entry_markup_to_utf8(elm_object_text_get(profile_time));
+ }
+
+ //char* user_status = "online";
+ char status_buf[126] = {'\0'};
+ sprintf(status_buf, "<font=Tizen:style=Italic color=#FFFFFF align=left><font_size=35>%s</font_size></font>", online_status);
+
+ Evas_Object* status_lbl = elm_label_add(ad->nf);
+ elm_object_text_set(status_lbl, status_buf);
+ evas_object_size_hint_weight_set(status_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(status_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(status_lbl);
+ evas_object_data_set(ad->nf, "chat_info_status", status_lbl);
+ elm_object_part_content_set(user_status_layout, "swallow.status", status_lbl);
+ return user_status_layout;
+ } else {
+
+ }
+ return eo;
+}
+
+
+
+char* on_chat_info_buddy_name_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ int id = (int)data;
+ Eina_List* selected_buddies = evas_object_data_get(obj, "selected_buddies");
+
+
+ int size = eina_list_count(selected_buddies);
+ if (size <= 0) {
+ if (!strcmp(part,"elm.text")){
+ char buf[512] = {'\0'};
+ snprintf(buf, 512, "<align=left><font_size=35><color=#000000>%s</color></font_size></align>", "No Items");
+ return strdup(buf);
+
+ } else if (!strcmp(part, "elm.text.sub")) {
+ return NULL;
+ }
+ }
+
+ user_data_s *user = eina_list_nth(selected_buddies, id);
+ if (!user)
+ return NULL;
+
+ if (!strcmp(part,"elm.text")){
+ char* user_name = replace(user->print_name, '_', " ");
+ char buf[512] = {'\0'};
+ snprintf(buf, 512, "<align=left><font_size=35><color=#000000>%s</color></font_size></align>", user_name);
+ free(user_name);
+ return strdup(buf);
+
+ }
+
+ return NULL;
+}
+
+Evas_Object* on_chat_info_buddy_selection_part_content_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ Evas_Object *eo = NULL;
+ if (!strcmp(part, "elm.swallow.icon")) {
+
+ int id = (int) data;
+ Eina_List* selected_buddies = evas_object_data_get(obj, "selected_buddies");
+ int size = eina_list_count(selected_buddies);
+ if (size <= 0) {
+ return eo;
+ }
+ user_data_s *user = eina_list_nth(selected_buddies, id);
+ Evas_Object *profile_pic = NULL;
+ if (user->photo_path && strcmp(user->photo_path, "") != 0) {
+ profile_pic = get_image_from_path(user->photo_path, obj);
+ } else {
+ profile_pic = get_image_from_path(ui_utils_get_resource(DEFAULT_PROFILE_PIC), obj);
+ }
+
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* user_pic_layout = elm_layout_add(obj);
+ elm_layout_file_set(user_pic_layout, edj_path, "circle_layout");
+ evas_object_size_hint_weight_set(user_pic_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_pic_layout);
+ elm_object_part_content_set(user_pic_layout, "content", profile_pic);
+
+ eo = elm_layout_add(obj);
+ elm_layout_theme_set(eo, "layout", "list/C/type.3", "default");
+ elm_layout_content_set(eo, "elm.swallow.content", user_pic_layout);
+ }
+ return eo;
+
+}
+
+
+void on_chat_image_select_result_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+{
+ if (result == APP_CONTROL_RESULT_SUCCEEDED) {
+ char* file_path = NULL;
+ char** path_arryay = NULL;
+ int array_length = 0;
+ app_control_get_extra_data_array(reply, APP_CONTROL_DATA_SELECTED, &path_arryay, &array_length);
+
+ for(int i = 0 ; i < array_length ; i++) {
+ file_path = path_arryay[i];
+ if (file_path) {
+ appdata_s *ad = (appdata_s*)user_data;
+ if (ad) {
+ Evas_Object *profile_pic = evas_object_data_get(ad->nf, "user_chat_profile_pic");
+ if (profile_pic) {
+ elm_image_file_set(profile_pic, file_path, NULL);
+ send_set_group_chat_profile_pic_request(ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id, file_path);
+ }
+ }
+ break;
+ }
+ }
+ }
+}
+
+
+void on_chat_image_request_option_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *popup = data;
+ int id = 0;
+ Elm_Object_Item *item = event_info;
+
+ id = (int)elm_object_item_data_get(item);
+ app_control_h app_control;
+ int ret = app_control_create(&app_control);
+
+
+ appdata_s *ad = evas_object_data_get(popup, "app_data");
+
+ if(ret != APP_CONTROL_ERROR_NONE) {
+ show_toast(ad, "Error: Can not load image picker");
+ return;
+ }
+
+ if (id == 0) {
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_CREATE_CONTENT);
+ app_control_set_mime(app_control, "image/jpg");
+ app_control_send_launch_request(app_control, &on_chat_image_select_result_cb, ad);
+ } else {
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_PICK);
+ app_control_set_mime(app_control,"image/*");
+ app_control_send_launch_request(app_control, &on_chat_image_select_result_cb, ad);
+ }
+
+ app_control_destroy(app_control);
+ evas_object_del(popup);
+}
+
+char* on_chat_camera_load_text_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ int id = (int) data;
+ if (id == 0) {
+ return strdup("Camera");
+ } else {
+ return strdup("Gallery");
+ }
+}
+
+void on_chat_camera_button_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object* cam_icon = data;
+ appdata_s* ad = evas_object_data_get(data, "app_data");
+ static Elm_Genlist_Item_Class itc;
+ Evas_Object *popup;
+ Evas_Object *box;
+ Evas_Object *genlist;
+ int i;
+ Evas_Object *win = ad->win;
+
+ popup = elm_popup_add(win);
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
+ elm_object_part_text_set(popup, "title,text", "Load image from");
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ evas_object_data_set(popup, "cam_icon", cam_icon);
+ evas_object_data_set(popup, "app_data", ad);
+ /* box */
+ box = elm_box_add(popup);
+ evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ /* genlist */
+ genlist = elm_genlist_add(box);
+ evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ itc.item_style = "default";
+ itc.func.text_get = on_chat_camera_load_text_get_cb;
+ itc.func.content_get = NULL;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+
+ for (i = 0; i < 2; i++) {
+ elm_genlist_item_append(genlist, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_chat_image_request_option_selected_cb, popup);
+ }
+ evas_object_show(genlist);
+ elm_box_pack_end(box, genlist);
+ evas_object_size_hint_min_set(box, -1, 230);
+ elm_object_content_set(popup, box);
+
+ evas_object_show(popup);
+}
+
+
+user_data_with_pic_s* is_present_in_buddy_list(appdata_s* ad, int buddy_id)
+{
+ if (ad->buddy_list) {
+ for (int i = 0 ; i < eina_list_count(ad->buddy_list) ; i++) {
+ user_data_with_pic_s *item = eina_list_nth(ad->buddy_list, i);
+ user_data_s* user = item->use_data;
+ if (user->user_id.id == buddy_id) {
+ return item;
+ }
+ }
+ }
+ return NULL;
+}
+
+
+/************************* menu *************************/
+
+
+/************ edit name ***************/
+
+
+void on_group_chat_info_updated(appdata_s *ad, char *type_of_change)
+{
+ if (!ad || !type_of_change) {
+ return;
+ }
+ if (strstr(type_of_change, "edit_title") != NULL) {
+ peer_with_pic_s *sel_item = ad->peer_in_cahtting_data;
+ if (sel_item) {
+ char* user_name = replace(sel_item->use_data->print_name, '_', " ");
+ char temp_name[512] = {'\0'};
+ snprintf(temp_name, 512, "<font=Tizen:style=Italic color=#000000 align=left><font_size=30>%s</font_size></font>", user_name);
+ free(user_name);
+ Evas_Object *profile_name = evas_object_data_get(ad->nf, "chat_info_name");
+ if (profile_name) {
+ elm_object_text_set(profile_name,temp_name);
+ }
+ }
+ } else if (strstr(type_of_change, "delete_photo") != NULL) {
+
+ } else if (strstr(type_of_change, "add_user") != NULL || strstr(type_of_change, "delete_user") != NULL) {
+ Evas_Object *status_lbl = evas_object_data_get(ad->nf, "chat_info_status");
+ if (status_lbl) {
+ Evas_Object *profile_time = evas_object_data_get(ad->nf, "profile_time");
+ char *online_status = "";
+ if (profile_time) {
+ online_status = elm_entry_markup_to_utf8(elm_object_text_get(profile_time));
+ }
+
+ //char* user_status = "online";
+ char status_buf[126] = {'\0'};
+ sprintf(status_buf, "<font=Tizen:style=Italic color=#FFFFFF align=left><font_size=35>%s</font_size></font>", online_status);
+ elm_object_text_set(status_lbl, status_buf);
+ }
+
+
+ Evas_Object *users_list = evas_object_data_get(ad->nf, "group_chat_user_list");
+ if (users_list) {
+
+ Eina_List* selected_buddies = evas_object_data_get(users_list, "selected_buddies");
+ if (selected_buddies) {
+ eina_list_free(selected_buddies);
+ selected_buddies = NULL;
+ }
+
+ elm_genlist_clear(users_list);
+ static Elm_Genlist_Item_Class sitc;
+ sitc.item_style = "default_style";
+ sitc.func.text_get = on_chat_info_buddy_name_get_cb;
+ sitc.func.content_get = on_chat_info_buddy_selection_part_content_get_cb;
+ sitc.func.state_get = NULL;
+ sitc.func.del = NULL;
+
+ /************** selected buddies **************/
+ tg_chat_info_s* chat_info = get_chat_info(ad->peer_in_cahtting_data->use_data->peer_id);
+ if (chat_info) {
+ int mem_cnt = 0;
+ selected_buddies = eina_list_append(selected_buddies, ad->current_user_data);
+ mem_cnt++;
+ int user_list_size = chat_info->user_list_size;
+
+ for (int i = 0; i < user_list_size; i++) {
+ user_data_with_pic_s *item = is_present_in_buddy_list(ad, chat_info->chat_users[i]);
+ if (item) {
+ selected_buddies = eina_list_append(selected_buddies, item->use_data);
+ mem_cnt++;
+ }
+ }
+
+ if(chat_info->print_title) {
+ free(chat_info->print_title);
+ chat_info->print_title = NULL;
+ }
+ if(chat_info->photo_path) {
+ free(chat_info->photo_path);
+ chat_info->photo_path = NULL;
+ }
+ if(chat_info->title) {
+ free(chat_info->title);
+ chat_info->title = NULL;
+ }
+
+
+ for (int i = 0 ; i < mem_cnt; i++) {
+ elm_genlist_item_append(users_list, &sitc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
+ }
+ }
+
+ /************** selected buddies **************/
+
+ evas_object_show(users_list);
+ evas_object_data_set(users_list, "selected_buddies", (void*)selected_buddies);
+ }
+
+ } else {
+
+ }
+}
+
+static void on_entry_pop_up_ok_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *popup = data;
+
+ appdata_s *ad = evas_object_data_get(popup, "app_data");
+ Evas_Object *entry = evas_object_data_get(popup, "title_entry");
+
+ if (entry) {
+ char *new_title = elm_entry_markup_to_utf8(elm_object_text_get(entry));
+ if (new_title) {
+ //send request to server.
+ int chat_id = ad->peer_in_cahtting_data->use_data->peer_id;
+ send_set_group_chat_new_title_request(ad->service_client, chat_id, new_title);
+ }
+ }
+ evas_object_del(popup);
+}
+
+static void on_entry_pop_up_cancel_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *popup = data;
+ evas_object_del(popup);
+}
+
+
+static void set_new_name_to_chat(appdata_s *ad)
+{
+ Evas_Object *popup, *btn;
+ Evas_Object *entry;
+ Evas_Object *layout;
+
+ /* popup */
+ popup = elm_popup_add(ad->nf);
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_object_part_text_set(popup, "title,text", "Title");
+
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_POPUP_VIEW_EDJ, edj_path, (int)PATH_MAX);
+
+ layout = elm_layout_add(popup);
+ elm_layout_file_set(layout, edj_path, "popup_input_text");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_object_content_set(popup, layout);
+
+ entry = elm_entry_add(layout);
+ elm_entry_single_line_set(entry, EINA_TRUE);
+ elm_entry_scrollable_set(entry, EINA_TRUE);
+ evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
+ elm_object_part_text_set(entry, "elm.guide", "New title");
+ elm_object_part_content_set(layout, "elm.swallow.content" , entry);
+
+ evas_object_data_set(popup, "app_data", ad);
+ evas_object_data_set(popup, "title_entry", entry);
+
+
+ /* Cancel button */
+ btn = elm_button_add(popup);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, "Cancel");
+ elm_object_part_content_set(popup, "button1", btn);
+ evas_object_smart_callback_add(btn, "clicked", on_entry_pop_up_cancel_clicked_cb, popup);
+
+ /* Set button */
+ btn = elm_button_add(popup);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, "Ok");
+ elm_object_part_content_set(popup, "button2", btn);
+ evas_object_smart_callback_add(btn, "clicked", on_entry_pop_up_ok_clicked_cb, popup);
+
+ evas_object_show(popup);
+}
+
+/************ edit name ***************/
+
+
+void on_chat_info_longpress_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = data;
+
+
+ Elm_Object_Item *it = event_info;
+ elm_genlist_item_selected_set(it, EINA_FALSE);
+ int id = (int)elm_object_item_data_get(it);
+
+
+ peer_with_pic_s *sel_item = ad->peer_in_cahtting_data;
+ tg_peer_info_s *user_data = sel_item->use_data;
+
+ if (!sel_item || !user_data) {
+ show_toast(ad, "Failed to get user info.");
+ return;
+ }
+
+ if (user_data->peer_type == TGL_PEER_USER) {
+
+ } else if (user_data->peer_type == TGL_PEER_CHAT) {
+ if (id == 0) {
+ if (ad->selected_buddy_item) {
+ user_data_s *sel_user = ad->selected_buddy_item;
+ show_loading_popup(ad);
+ send_remove_buddy_from_group_chat_request(ad->service_client, ad->selected_buddy_item->user_id.id, ad->peer_in_cahtting_data->use_data->peer_id);
+ }
+ }
+ }
+
+ if (ad->msg_popup) {
+ evas_object_del(ad->msg_popup);
+ ad->msg_popup = NULL;
+ }
+}
+
+
+char* on_chat_info_longpress_menu_group_text_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ int id = (int) data;
+ if (id == 0) {
+ return strdup("Add member");
+ } else if (id == 1) {
+ return strdup("Edit Name");
+ } else {
+ return strdup("Delete and leave group");
+ }
+}
+
+void on_chat_info_msg_popup_back_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = data;
+ if (ad->msg_popup) {
+ evas_object_del(ad->msg_popup);
+ ad->msg_popup = NULL;
+ }
+}
+
+void on_chat_info_menu_option_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = data;
+
+
+ Elm_Object_Item *it = event_info;
+ elm_genlist_item_selected_set(it, EINA_FALSE);
+ int id = (int)elm_object_item_data_get(it);
+
+
+ peer_with_pic_s *sel_item = ad->peer_in_cahtting_data;
+ tg_peer_info_s *user_data = sel_item->use_data;
+
+ if (!sel_item || !user_data) {
+ show_toast(ad, "Failed to get user info.");
+ return;
+ }
+
+ if (user_data->peer_type == TGL_PEER_USER) {
+
+
+
+ } else if (user_data->peer_type == TGL_PEER_CHAT) {
+
+ if (id == 0) {
+ launch_select_buddy_view(ad);
+ } else if (id == 1) {
+ set_new_name_to_chat(ad);
+ } else if (id == 2) {
+
+ peer_with_pic_s *sel_item = ad->peer_in_cahtting_data;
+ tg_peer_info_s *user_data = sel_item->use_data;
+ show_loading_popup(ad);
+ send_delete_group_chat_request(ad->service_client, user_data->peer_id);
+ } else {
+
+ }
+
+ }
+
+ if (ad->msg_popup) {
+ evas_object_del(ad->msg_popup);
+ ad->msg_popup = NULL;
+ }
+}
+
+void on_chat_info_menu_button_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = data;
+ if (ad->msg_popup || ad->current_app_state != TG_SET_CHAT_INFO_STATE) {
+ return;
+ }
+
+ static Elm_Genlist_Item_Class itc;
+ //Evas_Object *popup;
+ Evas_Object *box;
+ Evas_Object *genlist;
+ int i;
+ Evas_Object *win = ad->win;
+
+ ad->msg_popup = elm_popup_add(win);
+ elm_popup_align_set(ad->msg_popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(ad->msg_popup, EEXT_CALLBACK_BACK, on_chat_info_msg_popup_back_cb, ad);
+ evas_object_size_hint_weight_set(ad->msg_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ evas_object_data_set(ad->msg_popup, "app_data", ad);
+ box = elm_box_add(ad->msg_popup);
+ evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ genlist = elm_genlist_add(box);
+ evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ itc.item_style = "default";
+ itc.func.text_get = on_chat_info_longpress_menu_group_text_get_cb;
+ itc.func.content_get = NULL;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+
+ for (i = 0; i < 3; i++) {
+ elm_genlist_item_append(genlist, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_chat_info_menu_option_selected_cb, ad);
+ }
+
+ evas_object_data_set(genlist, "app_data", ad);
+
+ evas_object_show(genlist);
+ elm_box_pack_end(box, genlist);
+ evas_object_size_hint_min_set(box, -1, 345);
+ elm_object_content_set(ad->msg_popup, box);
+ evas_object_show(ad->msg_popup);
+}
+
+char* on_chat_info_longpress_menu_text_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ int id = (int) data;
+ if (id == 0) {
+ return strdup("Remove from group");
+ }
+ return NULL;
+}
+
+static void on_user_list_longpress(void *data, Evas_Object *obj, void *event_info)
+{
+ Elm_Object_Item *item = event_info;
+ int id = -1;
+ id = (int)elm_object_item_data_get(item);
+
+ if (id ==0) {
+ return;
+ }
+ appdata_s *ad = data;
+ Eina_List* selected_buddies = evas_object_data_get(obj, "selected_buddies");
+ user_data_s *user = eina_list_nth(selected_buddies, id);
+
+ ad->selected_buddy_item = user;
+
+ if (ad->msg_popup) {
+ evas_object_del(ad->msg_popup);
+ ad->msg_popup = NULL;
+ }
+
+ if (ad->current_app_state != TG_SET_CHAT_INFO_STATE) {
+ return;
+ }
+
+ static Elm_Genlist_Item_Class itc;
+ //Evas_Object *popup;
+ Evas_Object *box;
+ Evas_Object *genlist;
+ int i;
+ Evas_Object *win = ad->win;
+
+ ad->msg_popup = elm_popup_add(win);
+ elm_popup_align_set(ad->msg_popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(ad->msg_popup, EEXT_CALLBACK_BACK, on_chat_info_msg_popup_back_cb, ad);
+ evas_object_size_hint_weight_set(ad->msg_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ evas_object_data_set(ad->msg_popup, "app_data", ad);
+ box = elm_box_add(ad->msg_popup);
+ evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ genlist = elm_genlist_add(box);
+ evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ itc.item_style = "default";
+ itc.func.text_get = on_chat_info_longpress_menu_text_get_cb;
+ itc.func.content_get = NULL;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+
+ for (i = 0; i < 1; i++) {
+ elm_genlist_item_append(genlist, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_chat_info_longpress_clicked_cb, ad);
+ }
+
+ evas_object_data_set(genlist, "app_data", ad);
+
+ evas_object_show(genlist);
+ elm_box_pack_end(box, genlist);
+ evas_object_size_hint_min_set(box, -1, 115);
+ elm_object_content_set(ad->msg_popup, box);
+ evas_object_show(ad->msg_popup);
+}
+
+void on_user_list_item_selected(void *data, Evas_Object *obj, void *event_info)
+{
+ Elm_Object_Item *it = event_info;
+ elm_genlist_item_selected_set(it, EINA_FALSE);
+}
+
+/************************* menu *************************/
+
+void launch_chat_info_screen(appdata_s* ad, int chat_id)
+{
+ if (!ad) {
+ return;
+ }
+ if (ad->msg_popup) {
+ evas_object_del(ad->msg_popup);
+ ad->msg_popup = NULL;
+ }
+
+ ad->selected_buddy_item = NULL;
+ ad->current_app_state = TG_SET_CHAT_INFO_STATE;
+
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+
+ Evas_Object* scroller = elm_scroller_add(ad->nf);
+ elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
+ elm_scroller_policy_set(scroller,ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+
+ Evas_Object* layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(layout, edj_path, "chat_info_screen");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(layout);
+ elm_object_content_set(scroller, layout);
+
+
+ /**************** user info *********************/
+ Evas_Object *pic_name_list = NULL;
+
+ pic_name_list = elm_genlist_add(ad->nf);
+ elm_list_mode_set(pic_name_list, ELM_LIST_COMPRESS);
+ elm_genlist_mode_set(pic_name_list, ELM_LIST_COMPRESS);
+ elm_object_style_set(pic_name_list, "solid/default");
+ evas_object_size_hint_weight_set(pic_name_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(pic_name_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_data_set(pic_name_list, "app_data", ad);
+
+ static Elm_Genlist_Item_Class itc;
+ itc.item_style = "type1";
+ itc.func.text_get = NULL;
+ itc.func.content_get = on_chat_info_requested;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+ int i = 1;
+ elm_genlist_item_append(pic_name_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
+
+ evas_object_show(pic_name_list);
+ elm_object_part_content_set(layout, "pic_name_layout", pic_name_list);
+ /******************* user Info **********************/
+
+
+ Evas_Object* user_info_lbl = elm_label_add(ad->nf);
+ evas_object_show(user_info_lbl);
+ evas_object_size_hint_weight_set(user_info_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_info_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_object_text_set(user_info_lbl, "<font=Tizen:style=Bold color=#00FFFF align=left><font_size=45> Info</font_size></font>");
+ elm_object_part_content_set(layout, "user_info", user_info_lbl);
+
+
+ /******************** Phone num layout ********************/
+
+ Evas_Object *users_list = NULL;
+
+ users_list = elm_genlist_add(ad->nf);
+ elm_list_mode_set(users_list, ELM_LIST_COMPRESS);
+ elm_genlist_mode_set(users_list, ELM_LIST_COMPRESS);
+ evas_object_size_hint_weight_set(users_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(users_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_data_set(users_list, "app_data", ad);
+
+ static Elm_Genlist_Item_Class sitc;
+ sitc.item_style = "default_style";
+ sitc.func.text_get = on_chat_info_buddy_name_get_cb;
+ sitc.func.content_get = on_chat_info_buddy_selection_part_content_get_cb;
+ sitc.func.state_get = NULL;
+ sitc.func.del = NULL;
+
+ /************** selected buddies **************/
+ Eina_List* selected_buddies = NULL;
+ tg_chat_info_s* chat_info = get_chat_info(chat_id);
+ if (chat_info) {
+ int mem_cnt = 0;
+ selected_buddies = eina_list_append(selected_buddies, ad->current_user_data);
+ mem_cnt++;
+ int user_list_size = chat_info->user_list_size;
+
+ for (int i = 0; i < user_list_size; i++) {
+ user_data_with_pic_s *item = is_present_in_buddy_list(ad, chat_info->chat_users[i]);
+ if (item) {
+ selected_buddies = eina_list_append(selected_buddies, item->use_data);
+ mem_cnt++;
+ }
+ }
+
+ if(chat_info->print_title) {
+ free(chat_info->print_title);
+ chat_info->print_title = NULL;
+ }
+ if(chat_info->photo_path) {
+ free(chat_info->photo_path);
+ chat_info->photo_path = NULL;
+ }
+ if(chat_info->title) {
+ free(chat_info->title);
+ chat_info->title = NULL;
+ }
+
+
+ for (int i = 0 ; i < mem_cnt; i++) {
+ elm_genlist_item_append(users_list, &sitc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
+ }
+ }
+
+
+ evas_object_smart_callback_add(users_list, "longpressed", on_user_list_longpress, ad);
+ evas_object_smart_callback_add(users_list, "selected", on_user_list_item_selected, ad);
+ /************** selected buddies **************/
+
+ evas_object_show(users_list);
+ elm_object_part_content_set(layout, "phone_num_layout", users_list);
+ evas_object_data_set(users_list, "app_data", ad);
+ evas_object_data_set(users_list, "selected_buddies", (void*)selected_buddies);
+
+ evas_object_data_set(ad->nf, "group_chat_user_list", users_list);
+
+ /******************* Phone Num layout ************************/
+
+ Evas_Object *settings_info_lbl_bg = elm_object_part_content_get(layout, "settings_info,bg");
+ if (settings_info_lbl_bg) {
+ evas_object_hide(settings_info_lbl_bg);
+ }
+
+
+ Evas_Object* msg_btn = elm_button_add(ad->layout);
+ evas_object_size_hint_weight_set(msg_btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(msg_btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(msg_btn);
+
+
+ Evas_Object *msg_image = elm_image_add(ad->layout);
+ elm_image_file_set(msg_image, ui_utils_get_resource(CAMERA_ICON), NULL);
+ evas_object_size_hint_weight_set(msg_image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(msg_image, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(msg_image);
+ elm_object_content_set(msg_btn, msg_image);
+
+ elm_object_part_content_set(layout, "cam_layout", msg_btn);
+ evas_object_smart_callback_add(msg_btn, "clicked", on_chat_camera_button_clicked, msg_btn);
+ evas_object_data_set(msg_btn, "app_data", ad);
+
+ Elm_Object_Item* navi_item = elm_naviframe_item_push(ad->nf, "Chat Info", NULL, NULL, scroller, NULL);
+ eext_object_event_callback_add(ad->nf, EEXT_CALLBACK_MORE, on_chat_info_menu_button_clicked, ad);
+
+}
+
+
+
+
*/
#include "tg_db_wrapper.h"
+#include <mime_type.h>
void create_data_base_tables()
{
- char *table_name = USER_INFO_TABLE_NAME;
+ char* table_name = USER_INFO_TABLE_NAME;
Eina_List* col_names = NULL;
col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_ID);
col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME);
col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_NAME);
col_names = eina_list_append(col_names, USER_INFO_TABLE_ONLINE_STATUS);
col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_BLOCKED);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_DELETED);
Eina_List* col_types = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
Eina_Bool ret = create_table(table_name, col_names, col_types);
if (!ret) {
eina_list_free(col_names);
eina_list_free(col_types);
+
table_name = BUDDY_INFO_TABLE_NAME;
col_names = NULL;
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_BUDDY_ID);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PRINT_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_STRUCTURE_VERSION);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHOTO_PATH);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHOTO_ID);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_FIRST_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_LAST_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHONE_NO);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_ACCESS_HASH);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_REAL_FIRST_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_REAL_LAST_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_BUDDY_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_ONLINE_STATUS);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_STRUCTURE_VERSION);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHONE_NO);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ACCESS_HASH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ONLINE_STATUS);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_BLOCKED);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_DELETED);
col_types = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
ret = create_table(table_name, col_names, col_types);
if (!ret) {
// error occured
}
-
eina_list_free(col_names);
eina_list_free(col_types);
+
table_name = MEDIA_INFO_TABLE_NAME;
col_names = NULL;
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_ID);
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE4);
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA4);
-
/********************************************************************/
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHONE_NO);
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LAST_NAME);
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FILE_PATH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MIME_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_WIDTH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_HEIGHT);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DURATION);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_SIZE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DC);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE);
+
col_types = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
ret = create_table(table_name, col_names, col_types);
if (!ret) {
// error occured
col_names = eina_list_append(col_names, PEER_INFO_TABLE_STRUCT_VERSION);
col_names = eina_list_append(col_names, PEER_INFO_TABLE_NO_OF_UNREAD_MESSAGES);
col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_SEEN_TIME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHOTO_PATH);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHOTO_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
col_types = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
eina_list_free(col_names);
eina_list_free(col_types);
+ table_name = TG_SETTINGS_TABLE_NAME;
+ col_names = NULL;
+ col_names = eina_list_append(col_names, TG_SETTINGS_ROW_ID);
+ col_names = eina_list_append(col_names, TG_SETTINGS_CHAT_BG);
+
+ col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_AUTO_INC_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ ret = create_table(table_name, col_names, col_types);
+ if(!ret) {
+ // error occured
+ }
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+
+
+ /****************************************************/
+
+ table_name = MESSAGE_TRANSPORT_TABLE_NAME;
+ col_names = NULL;
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_ROW_ID);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_APP_NAME);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_COMMAND);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_BUDDY_ID);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_MESSAGE_TYPE);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_MESSAGE_DATA);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_TYPE_OF_CHAT);
+
+ col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_AUTO_INC_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ ret = create_table(table_name, col_names, col_types);
+ if(!ret) {
+ // error occured
+ }
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+
+ table_name = MEDIA_TRANSPORT_TABLE_NAME;
+ col_names = NULL;
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_ROW_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_APP_NAME);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_COMMAND);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_BUDDY_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_MEDIA_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_MESSAGE_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_FILE_PATH);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_TYPE_OF_CHAT);
+
+ col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_AUTO_INC_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ ret = create_table(table_name, col_names, col_types);
+ if(!ret) {
+ // error occured
+ }
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+}
+
+
+Eina_Bool insert_unsent_message_to_db(const char *app_name, const char *command, const char *buddy_id, const char *msg_id, const char *msg_type, const char * msg_data, const char *type_of_chat)
+{
+ Eina_Bool ret = EINA_FALSE;
+ if (!app_name || !command || !buddy_id || !msg_id || !msg_type || !msg_data || !type_of_chat) {
+ return ret;
+ }
+
+ char* table_name = MESSAGE_TRANSPORT_TABLE_NAME;
+ Eina_List* col_names = NULL;
+ col_names = NULL;
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_APP_NAME);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_COMMAND);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_BUDDY_ID);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_MESSAGE_TYPE);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_MESSAGE_DATA);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_TYPE_OF_CHAT);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, app_name);
+ col_values = eina_list_append(col_values, command);
+ col_values = eina_list_append(col_values,buddy_id);
+ col_values = eina_list_append(col_values, msg_id);
+ col_values = eina_list_append(col_values, msg_type);
+ col_values = eina_list_append(col_values, msg_data);
+ col_values = eina_list_append(col_values, type_of_chat);
+
+
+ ret = insert_table(table_name, col_names, col_types,col_values);
+ if(!ret) {
+ ret = EINA_FALSE;
+ } else {
+ ret = EINA_TRUE;
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+ return ret;
+}
+
+Eina_Bool insert_unsent_media_message_to_db(const char *app_name, const char *command, const char *buddy_id, const char *msg_id, const char *media_id, const char *msg_type, const char *file_path, const char *type_of_chat)
+{
+ Eina_Bool ret = EINA_FALSE;
+
+ if (!app_name || !command || !buddy_id || !msg_id || !media_id || !msg_type || !file_path || !type_of_chat) {
+ return ret;
+ }
+
+
+ char* table_name = MEDIA_TRANSPORT_TABLE_NAME;
+ Eina_List* col_names = NULL;
+ col_names = NULL;
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_APP_NAME);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_COMMAND);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_BUDDY_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_MEDIA_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_MESSAGE_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_FILE_PATH);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_TYPE_OF_CHAT);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, app_name);
+ col_values = eina_list_append(col_values, command);
+ col_values = eina_list_append(col_values, buddy_id);
+ col_values = eina_list_append(col_values, msg_id);
+ col_values = eina_list_append(col_values, media_id);
+ col_values = eina_list_append(col_values, msg_type);
+ col_values = eina_list_append(col_values, file_path);
+ col_values = eina_list_append(col_values, type_of_chat);
+
+ ret = insert_table(table_name, col_names, col_types,col_values);
+ if(!ret) {
+ ret = EINA_FALSE;
+ } else {
+ ret = EINA_TRUE;
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+ return ret;
}
-Eina_List* get_all_peer_details()
+
+Eina_List* get_all_peer_details(char* start_name)
{
Eina_List* peer_details = NULL;
- char *table_name = PEER_INFO_TABLE_NAME;
+ char* table_name = PEER_INFO_TABLE_NAME;
Eina_List* col_names = NULL;
col_names = eina_list_append(col_names, PEER_INFO_TABLE_CHAT_ID);
col_names = eina_list_append(col_names, PEER_INFO_TABLE_STRUCT_VERSION);
col_names = eina_list_append(col_names, PEER_INFO_TABLE_NO_OF_UNREAD_MESSAGES);
col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_SEEN_TIME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHOTO_PATH);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHOTO_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
Eina_List* col_types = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
//peer_details = get_values_from_table_sync(db, table_name, col_names, col_types, NULL);
- peer_details = get_values_from_table_sync_order_by(table_name, col_names, col_types, PEER_INFO_TABLE_LAST_MESSAGE_DATE, EINA_FALSE, NULL);
+ char *where_clause = NULL;
+ if (start_name) {
+ where_clause = (char *)malloc(strlen(PEER_INFO_TABLE_PRINT_NAME) + strlen(" LIKE '") + strlen(start_name) + strlen("%'") + 1);
+ strcpy(where_clause, PEER_INFO_TABLE_PRINT_NAME);
+ strcat(where_clause, " LIKE '");
+ strcat(where_clause, start_name);
+ strcat(where_clause, "%'");
+ }
+
+ peer_details = get_values_from_table_sync_order_by(table_name, col_names, col_types, PEER_INFO_TABLE_LAST_MESSAGE_DATE, EINA_FALSE, where_clause);
eina_list_free(col_names);
eina_list_free(col_types);
+ if (where_clause) {
+ free(where_clause);
+ where_clause = NULL;
+ }
return peer_details;
}
+peer_with_pic_s* get_peer_info(int peer_id)
+{
+ Eina_List* peer_details = NULL;
+ char* table_name = PEER_INFO_TABLE_NAME;
+ Eina_List* col_names = NULL;
+
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_CHAT_ID);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_PEER_TYPE);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_FLAGS);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_MESSAGE_ID);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_MESSAGE_DATE);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_PRINT_NAME);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_STRUCT_VERSION);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_NO_OF_UNREAD_MESSAGES);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+
+ char chat_id_str[50];
+ sprintf(chat_id_str, "%d", peer_id);
+
+ char* where_clause = (char*)malloc(strlen(PEER_INFO_TABLE_CHAT_ID) + strlen(" = ") + strlen(chat_id_str) + 1);
+ strcpy(where_clause, PEER_INFO_TABLE_CHAT_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, chat_id_str);
+
+ peer_details = get_values_from_table_sync_order_by(table_name, col_names, col_types, PEER_INFO_TABLE_LAST_MESSAGE_DATE, EINA_FALSE, where_clause);
+
+ free(where_clause);
+
+ peer_with_pic_s *item = NULL;
+
+
+ for (int i = 0; i < eina_list_count(peer_details) ; i++) {
+ Eina_List* ts_msg = eina_list_nth(peer_details, i);
+ tg_peer_info_s* peer_info = (tg_peer_info_s*)malloc(sizeof(tg_peer_info_s));
+
+ int *temp_peer_id = (int*)eina_list_nth(ts_msg, 0);
+ if (temp_peer_id) {
+ peer_info->peer_id = *temp_peer_id;
+ free(temp_peer_id);
+ }
+
+ int *temp_peer_type = (int*)eina_list_nth(ts_msg, 1);
+ if (temp_peer_type) {
+ peer_info->peer_type = *temp_peer_type;
+ free(temp_peer_type);
+ }
+
+ int *temp_flags = (int*)eina_list_nth(ts_msg, 2);
+ if (temp_flags) {
+ peer_info->flags = *temp_flags;
+ free(temp_flags);
+ }
+
+ char *temp_msg_id = (char*)eina_list_nth(ts_msg, 3);
+ if (temp_msg_id) {
+ peer_info->last_msg_id = atoll(temp_msg_id);
+ free(temp_msg_id);
+ } else {
+ peer_info->last_msg_id = 0;
+ }
+
+ int *temp_last_msg_date = (int*)eina_list_nth(ts_msg, 4);
+ if (temp_last_msg_date) {
+ peer_info->last_msg_date = *temp_last_msg_date;
+ free(temp_last_msg_date);
+ }
+
+ char *temp_print_name = (char*)eina_list_nth(ts_msg, 5);
+ if (temp_print_name) {
+ peer_info->print_name = strdup(temp_print_name);
+ free(temp_print_name);
+ } else {
+ peer_info->print_name = NULL;
+ }
+
+ int *temp_struct_ver = (int*)eina_list_nth(ts_msg, 6);
+ if (temp_struct_ver) {
+ peer_info->struct_version = *temp_struct_ver;
+ free(temp_struct_ver);
+ }
+
+ int *temp_no_unread = (int*)eina_list_nth(ts_msg, 7);
+ if (temp_no_unread) {
+ peer_info->no_of_unread_msgs = *temp_no_unread;
+ free(temp_no_unread);
+ }
+
+ int *temp_last_seen = (int*)eina_list_nth(ts_msg, 8);
+ if (temp_last_seen) {
+ peer_info->last_seen_time = *temp_last_seen;
+ free(temp_last_seen);
+ }
+
+ char *temp_pic_path = (char*)eina_list_nth(ts_msg, 9);
+ if (temp_pic_path) {
+ peer_info->photo_path = strdup(temp_pic_path);
+ free(temp_pic_path);
+ } else {
+ peer_info->photo_path = NULL;
+ }
+
+ int *temp_pic_id = (int*)eina_list_nth(ts_msg, 10);
+ if (temp_pic_id) {
+ peer_info->photo_id = *temp_pic_id;
+ free(temp_pic_id);
+ }
+
+
+ eina_list_free(ts_msg);
+
+ item = (peer_with_pic_s*) malloc(sizeof (peer_with_pic_s));
+ item->use_data = peer_info;
+ item->contact_icon = NULL;
+
+ break;
+
+ }
+ eina_list_free(peer_details);
+
+
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+ return item;
+}
+
Eina_List* get_group_chat_details()
{
Eina_List* chat_details = NULL;
- char *table_name = CHAT_INFO_TABLE_NAME;
+ char* table_name = CHAT_INFO_TABLE_NAME;
Eina_List* col_names = NULL;
col_names = eina_list_append(col_names, CHAT_INFO_TABLE_CHAT_ID);
col_names = eina_list_append(col_names, CHAT_INFO_TABLE_FLAGS);
{
Eina_List* chat_details = NULL;
- char *table_name = CHAT_INFO_TABLE_NAME;
+ char* table_name = CHAT_INFO_TABLE_NAME;
Eina_List* col_names = NULL;
col_names = eina_list_append(col_names, CHAT_INFO_TABLE_CHAT_ID);
col_names = eina_list_append(col_names, CHAT_INFO_TABLE_FLAGS);
{
Eina_List* user_details = NULL;
- char *table_name = USER_INFO_TABLE_NAME;
+ char* table_name = USER_INFO_TABLE_NAME;
Eina_List* col_names = NULL;
col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_ID);
col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME);
{
Eina_List* user_details = NULL;
- char *table_name = BUDDY_INFO_TABLE_NAME;
+ char* table_name = BUDDY_INFO_TABLE_NAME;
Eina_List* col_names = NULL;
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_BUDDY_ID);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PRINT_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_STRUCTURE_VERSION);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHOTO_PATH);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHOTO_ID);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_FIRST_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_LAST_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHONE_NO);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_ACCESS_HASH);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_REAL_FIRST_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_REAL_LAST_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_BUDDY_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_ONLINE_STATUS);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_STRUCTURE_VERSION);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHONE_NO);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ACCESS_HASH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ONLINE_STATUS);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_BLOCKED);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_DELETED);
Eina_List* col_types = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
- char* where_clause = (char*)malloc(strlen(BUDDY_INFO_TABLE_REAL_FIRST_NAME) + strlen(" <> ") + strlen("'Telegram'") + 1);
- strcpy(where_clause, BUDDY_INFO_TABLE_REAL_FIRST_NAME);
+#if 0
+ char* where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen("'Telegram'") + 1);
+ strcpy(where_clause, USER_INFO_TABLE_REAL_FIRST_NAME);
strcat(where_clause, " <> ");
strcat(where_clause, "'Telegram'");
-
+#endif
//user_details = get_values_from_table_sync(db, table_name, col_names, col_types, NULL);
- user_details = get_values_from_table_sync_order_by(table_name, col_names, col_types, BUDDY_INFO_TABLE_PRINT_NAME, EINA_TRUE, where_clause);
+ user_details = get_values_from_table_sync_order_by(table_name, col_names, col_types, USER_INFO_TABLE_PRINT_NAME, EINA_TRUE, NULL);
eina_list_free(col_names);
eina_list_free(col_types);
return user_details;
}
-
-char* get_profile_pic_path(int buddy_id)
+#if 0
+void set_chat_bg(char *file_path)
{
- Eina_List* buddy_details_array = NULL;
+ if (!file_path) {
+ return;
+ }
+ char* table_name = TG_SETTINGS_TABLE_NAME;
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, TG_SETTINGS_CHAT_BG);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, file_path);
+
+ // already exist. So update the table
+ char* where_clause = NULL;
+ char user_id_str[50];
+ sprintf(user_id_str,"%d",1);
+ where_clause = (char*)malloc(strlen(TG_SETTINGS_ROW_ID) + strlen(" = ") + strlen(user_id_str) + 1);
+ strcpy(where_clause, TG_SETTINGS_ROW_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, user_id_str);
+ Eina_Bool ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+ free(where_clause);
+
+ if(!ret) {
+ ret = insert_table(table_name, col_names, col_types,col_values);
+ } else {
+
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+}
+
+char* get_chat_bg()
+{
+ char* table_name = TG_SETTINGS_TABLE_NAME;
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, TG_SETTINGS_CHAT_BG);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ Eina_List *settings_array = NULL;
+ char *chat_bg = NULL;
+ char* where_clause = NULL;
+ char user_id_str[50];
+ sprintf(user_id_str,"%d",1);
+ where_clause = (char*)malloc(strlen(TG_SETTINGS_ROW_ID) + strlen(" = ") + strlen(user_id_str) + 1);
+ strcpy(where_clause, TG_SETTINGS_ROW_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, user_id_str);
+ settings_array = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+ free(where_clause);
+ if (settings_array && eina_list_count(settings_array) > 0) {
+ Eina_List* settings_details = eina_list_nth(settings_array, 0);
+ if (settings_details && eina_list_count(settings_details) > 0) {
+ char* pic_path = (char*)eina_list_nth(settings_details, 0);
+
+ if (pic_path && strlen(pic_path) > 0) {
+ chat_bg = strdup(pic_path);
+ }
+ free(pic_path);
+ eina_list_free(settings_details);
+ }
+ eina_list_free(settings_array);
+ }
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+ return chat_bg;
+
+}
+#endif
+char* get_profile_pic_path(int buddy_id)
+{
+ Eina_List* buddy_details_array = NULL;
char* profile_pic_path = NULL;
- char *table_name = BUDDY_INFO_TABLE_NAME;
+ char* table_name = BUDDY_INFO_TABLE_NAME;
Eina_List* col_names = NULL;
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
Eina_List* col_types = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
char buddy_id_str[50];
sprintf(buddy_id_str, "%d", buddy_id);
- char* where_clause = (char*)malloc(strlen(BUDDY_INFO_TABLE_BUDDY_ID) + strlen(" = ") + strlen(buddy_id_str) + 1);
- strcpy(where_clause, BUDDY_INFO_TABLE_BUDDY_ID);
+ char* where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(buddy_id_str) + 1);
+ strcpy(where_clause, USER_INFO_TABLE_USER_ID);
strcat(where_clause, " = ");
strcat(where_clause, buddy_id_str);
if (pic_path && strlen(pic_path) > 0) {
profile_pic_path = strdup(pic_path);
}
-
- for (int i = 0 ; i < eina_list_count(buddy_details_array); i++) {
- void* val = eina_list_nth(buddy_details, i);
- free(val);
- }
+ free(pic_path);
eina_list_free(buddy_details);
}
eina_list_free(buddy_details_array);
Eina_List* buddy_details_array = NULL;
char* profile_name = NULL;
- char *table_name = BUDDY_INFO_TABLE_NAME;
+ char* table_name = BUDDY_INFO_TABLE_NAME;
Eina_List* col_names = NULL;
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PRINT_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME);
Eina_List* col_types = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
char buddy_id_str[50];
sprintf(buddy_id_str, "%d", buddy_id);
- char* where_clause = (char*)malloc(strlen(BUDDY_INFO_TABLE_BUDDY_ID) + strlen(" = ") + strlen(buddy_id_str) + 1);
- strcpy(where_clause, BUDDY_INFO_TABLE_BUDDY_ID);
+ char* where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(buddy_id_str) + 1);
+ strcpy(where_clause, USER_INFO_TABLE_USER_ID);
strcat(where_clause, " = ");
strcat(where_clause, buddy_id_str);
if (name && strlen(name) > 0) {
profile_name = strdup(name);
}
-
- for (int i = 0 ; i < eina_list_count(buddy_details_array); i++) {
- void* val = eina_list_nth(buddy_details, i);
- free(val);
- }
+ free(name);
eina_list_free(buddy_details);
}
+
eina_list_free(buddy_details_array);
}
{
Eina_List* buddy_details_array = NULL;
- char *table_name = BUDDY_INFO_TABLE_NAME;
+ char* table_name = BUDDY_INFO_TABLE_NAME;
Eina_List* col_names = NULL;
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_ONLINE_STATUS);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ONLINE_STATUS);
Eina_List* col_types = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
char buddy_id_str[50];
sprintf(buddy_id_str, "%d", buddy_id);
- char* where_clause = (char*)malloc(strlen(BUDDY_INFO_TABLE_BUDDY_ID) + strlen(" = ") + strlen(buddy_id_str) + 1);
- strcpy(where_clause, BUDDY_INFO_TABLE_BUDDY_ID);
+ char* where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(buddy_id_str) + 1);
+ strcpy(where_clause, USER_INFO_TABLE_USER_ID);
strcat(where_clause, " = ");
strcat(where_clause, buddy_id_str);
is_online = *temp_online_status;
free(temp_online_status);
}
-
- for (int i = 0 ; i < eina_list_count(buddy_details_array); i++) {
- void* val = eina_list_nth(buddy_details, i);
- free(val);
- }
eina_list_free(buddy_details);
}
eina_list_free(buddy_details_array);
return is_online;
}
-Eina_List *get_buddy_info(int buddy_id)
+Eina_List* get_buddy_info(int buddy_id)
{
Eina_List* user_details = NULL;
- char *table_name = BUDDY_INFO_TABLE_NAME;
+ char* table_name = BUDDY_INFO_TABLE_NAME;
Eina_List* col_names = NULL;
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_BUDDY_ID);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PRINT_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_STRUCTURE_VERSION);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHOTO_PATH);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHOTO_ID);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_FIRST_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_LAST_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHONE_NO);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_ACCESS_HASH);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_REAL_FIRST_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_REAL_LAST_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_BUDDY_NAME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_ONLINE_STATUS);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_STRUCTURE_VERSION);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHONE_NO);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ACCESS_HASH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ONLINE_STATUS);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_BLOCKED);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_DELETED);
Eina_List* col_types = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
char buddy_id_str[50];
sprintf(buddy_id_str, "%d", buddy_id);
- char* where_clause = (char*)malloc(strlen(BUDDY_INFO_TABLE_BUDDY_ID) + strlen(" = ") + strlen(buddy_id_str) + 1);
- strcpy(where_clause, BUDDY_INFO_TABLE_BUDDY_ID);
+ char* where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(buddy_id_str) + 1);
+ strcpy(where_clause, USER_INFO_TABLE_USER_ID);
strcat(where_clause, " = ");
strcat(where_clause, buddy_id_str);
return user_details;
}
-int get_unread_message_count(const char *table_name)
+int get_unread_message_count(char* table_name)
{
// number of rows, having out == 1 and unread == 0
char out_str[50];
sprintf(out_str, "%d", 0);
+#if 0
char service_str[50];
sprintf(service_str, "%d", 1);
strcat(where_clause, MESSAGE_INFO_TABLE_SERVICE);
strcat(where_clause, " = ");
strcat(where_clause, service_str);
+#endif
+
+ where_clause = (char*)malloc(strlen(MESSAGE_INFO_TABLE_UNREAD) + strlen(" = ") + strlen(unread_str) + 1);
+ strcpy(where_clause, MESSAGE_INFO_TABLE_UNREAD);
+ strcat(where_clause, " = ");
+ strcat(where_clause, unread_str);
+
num_of_rows = get_number_of_rows(table_name, where_clause);
free(where_clause);
}
-tg_message_s* get_latest_message_from_message_table(const char *table_name)
+tg_message_s* get_latest_message_from_message_table(char* table_name)
{
tg_message_s* message = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
- message_details = get_values_from_table_sync_order_by(table_name, col_names, col_types, MESSAGE_INFO_TABLE_DATE, EINA_FALSE, NULL);
+
+
+ char service_str[50];
+ sprintf(service_str, "%d", 2);
+
+ char* where_clause = (char*)malloc(strlen(MESSAGE_INFO_TABLE_SERVICE) + strlen(" <> ") + strlen(service_str) + 1);
+ strcpy(where_clause, MESSAGE_INFO_TABLE_SERVICE);
+ strcat(where_clause, " <> ");
+ strcat(where_clause, service_str);
+
+
+ message_details = get_values_from_table_sync_order_by(table_name, col_names, col_types, MESSAGE_INFO_TABLE_DATE, EINA_FALSE, where_clause);
+ free(where_clause);
eina_list_free(col_names);
eina_list_free(col_types);
}
-void update_msg_into_db(tg_message_s *M, const char *table_name)
+void update_msg_into_db(tg_message_s *M, char* table_name)
{
if(!M) {
return;
} else {
}
+ free(where_clause);
eina_list_free(col_names);
eina_list_free(col_types);
eina_list_free(col_values);
}
+int insert_current_date_to_table(char* tb_name)
+{
+ tg_message_s* last_msg = get_latest_message_from_message_table(tb_name);
+ if (last_msg) {
+ int old_date = last_msg->date;
+ time_t old_t = old_date;
+
+ struct tm old_lt;
+ (void) localtime_r(&old_t, &old_lt);
+
+
+ int cur_time = time(NULL);
+ time_t new_t = cur_time;
+
+ struct tm new_lt;
+ (void) localtime_r(&new_t, &new_lt);
+
+
+ if (old_lt.tm_mday == new_lt.tm_mday && old_lt.tm_mon == new_lt.tm_mon && old_lt.tm_year == new_lt.tm_year) {
+ // no need of new date
+ return -1;
+ } else {
+ int cur_time = time(NULL);
+ time_t t = cur_time;
+
+ char *format = NULL;
+ format = "%d %B %Y";
+
+ struct tm lt;
+ char res[256];
+ (void) localtime_r(&t, <);
+
+ if (strftime(res, sizeof(res), format, <) == 0) {
+ (void) fprintf(stderr, "strftime(3): cannot format supplied "
+ "date/time into buffer of size %u "
+ "using: '%s'\n",
+ sizeof(res), format);
+ }
+
+ srand(time(NULL));
+ int r = rand();
+ tg_message_s date_msg;
+ date_msg.msg_id = 2*r;
+ date_msg.media_type = tgl_message_media_none;
+ date_msg.date = cur_time;
+ date_msg.message = res;
+ date_msg.message_len = strlen(res);
+ date_msg.service = 2;
+ date_msg.unread = 0;
+ date_msg.out = 0;
+ date_msg.media_id = "";
+ insert_msg_into_db(&date_msg, tb_name, date_msg.msg_id);
+ return date_msg.msg_id;
+ }
+
+ } else {
+ int cur_time = time(NULL);
+ time_t t = cur_time;
+
+ char *format = NULL;
+ format = "%d %B %Y";
+
+ struct tm lt;
+ char res[256];
+ (void) localtime_r(&t, <);
+
+ if (strftime(res, sizeof(res), format, <) == 0) {
+ (void) fprintf(stderr, "strftime(3): cannot format supplied "
+ "date/time into buffer of size %u "
+ "using: '%s'\n",
+ sizeof(res), format);
+ }
+ srand(time(NULL));
+ int r = rand();
+ tg_message_s date_msg;
+ date_msg.msg_id = 2*r;
+ date_msg.media_type = tgl_message_media_none;
+ date_msg.date = cur_time;
+ date_msg.message = res;
+ date_msg.message_len = strlen(res);
+ date_msg.service = 2;
+ date_msg.unread = 0;
+ date_msg.out = 0;
+ date_msg.media_id = "";
+ insert_msg_into_db(&date_msg, tb_name, date_msg.msg_id);
+ return date_msg.msg_id;
+ }
+ return -1;
+}
+
-tg_message_s* get_message_from_message_table(long long msg_id, const char *table_name)
+tg_message_s* get_message_from_message_table(long long msg_id, char* table_name)
{
tg_message_s* message = NULL;
return;
}
- char *table_name = PEER_INFO_TABLE_NAME;
+ char* table_name = PEER_INFO_TABLE_NAME;
Eina_List* col_names = NULL;
col_names = NULL;
col_names = eina_list_append(col_names, PEER_INFO_TABLE_CHAT_ID);
col_names = eina_list_append(col_names, PEER_INFO_TABLE_STRUCT_VERSION);
col_names = eina_list_append(col_names, PEER_INFO_TABLE_NO_OF_UNREAD_MESSAGES);
col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_SEEN_TIME);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHOTO_PATH);
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHOTO_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
Eina_List* col_types = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
strcat(where_clause, " = ");
strcat(where_clause, user_id_str);
ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+ free(where_clause);
} else {
}
}
-void insert_msg_into_db(tg_message_s *M, const char *table_name, int unique_id)
+void insert_msg_into_db(tg_message_s *M, char* table_name, int unique_id)
{
if(!M) {
return;
}
-void insert_media_info_to_db(tg_message_s *M, char* file_path, int width, int height, int size)
+void insert_media_info_to_db(tg_message_s *M, char *file_path, int width, int height, int size, char *latitude, char *longitude, char *first_name, char *last_name, char *phone_number)
{
- if(!M || !file_path) {
+ if (!M) {
return;
}
- char *table_name = MEDIA_INFO_TABLE_NAME;
+ char* table_name = MEDIA_INFO_TABLE_NAME;
Eina_List* col_names = NULL;
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_ID);
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_TYPE);
/********************************************************************/
-
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHONE_NO);
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FIRST_NAME);
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LAST_NAME);
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FILE_PATH);
+ /****************************NEW****************************************/
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MIME_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_WIDTH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_HEIGHT);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DURATION);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_SIZE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DC);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE);
+
+ /****************************NEW****************************************/
+
+
Eina_List* col_types = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ /****************************NEW****************************************/
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ /****************************NEW****************************************/
Eina_List* col_values = NULL;
int media_type = M->media_type;
- if (media_type == tgl_message_media_photo) {
+ col_values = eina_list_append(col_values,M->media_id);
+ col_values = eina_list_append(col_values, &(media_type));
- col_values = eina_list_append(col_values,M->media_id);
- col_values = eina_list_append(col_values, &(media_type));
+ if (media_type == tgl_message_media_photo) {
long long temp_val = 0;
char access_hash_str[50];
col_values = eina_list_append(col_values, "");
- double longitude = 0.0f;
- double latitude = 0.0f;
-
- char long_str[50];
- sprintf(long_str,"%lf",longitude);
-
- char lat_str[50];
- sprintf(lat_str,"%lf",latitude);
-
- col_values = eina_list_append(col_values, long_str);
- col_values = eina_list_append(col_values, long_str);
+ if (longitude) {
+ col_values = eina_list_append(col_values, longitude);
+ } else {
+ col_values = eina_list_append(col_values, "0.000");
+ }
+ if (latitude) {
+ col_values = eina_list_append(col_values, latitude);
+ } else {
+ col_values = eina_list_append(col_values, "0.000");
+ }
int temp_sizes = 4;
col_values = eina_list_append(col_values, &(temp_val));
col_values = eina_list_append(col_values, &(temp_val));
col_values = eina_list_append(col_values, &(temp_val));
- col_values = eina_list_append(col_values, &(temp_val));
- col_values = eina_list_append(col_values, &(temp_val));
col_values = eina_list_append(col_values, "");
- double longitude = 0.0f;
- double latitude = 0.0f;
-
- char long_str[50];
- sprintf(long_str,"%lf",longitude);
-
- char lat_str[50];
- sprintf(lat_str,"%lf",latitude);
-
- col_values = eina_list_append(col_values, long_str);
- col_values = eina_list_append(col_values, long_str);
+ if (longitude) {
+ col_values = eina_list_append(col_values, longitude);
+ } else {
+ col_values = eina_list_append(col_values, "0.000");
+ }
+ if (latitude) {
+ col_values = eina_list_append(col_values, latitude);
+ } else {
+ col_values = eina_list_append(col_values, "0.000");
+ }
col_values = eina_list_append(col_values, &(temp_val));
col_values = eina_list_append(col_values, photo_data);
}
+ } else if (media_type == tgl_message_media_geo) {
+ // To be checked
+ int dummy = 0;
+ col_values = eina_list_append(col_values, &(dummy));
+ col_values = eina_list_append(col_values, &(dummy));
+ col_values = eina_list_append(col_values, &(dummy));
+
+ col_values = eina_list_append(col_values, "");
+
+ if (longitude) {
+ col_values = eina_list_append(col_values, longitude);
+ } else {
+ col_values = eina_list_append(col_values, "0.000");
+ }
+ if (latitude) {
+ col_values = eina_list_append(col_values, latitude);
+ } else {
+ col_values = eina_list_append(col_values, "0.000");
+ }
+ col_values = eina_list_append(col_values, &(dummy));
+
+ for (int j = 0; j < 4; j++) {
+
+ char* photo_type = "";
+ col_values = eina_list_append(col_values, photo_type);
+
+ int photo_loc_dc = -1;
+ col_values = eina_list_append(col_values, &photo_loc_dc);
+
+ col_values = eina_list_append(col_values, "");
+
+ int photo_loc_id = -1;
+ col_values = eina_list_append(col_values, &photo_loc_id);
+
+
+ col_values = eina_list_append(col_values, "");
+
+ col_values = eina_list_append(col_values, &width);
+
+ col_values = eina_list_append(col_values, &height);
+
+ col_values = eina_list_append(col_values, &size);
+
+ char* photo_data = "";
+ col_values = eina_list_append(col_values, photo_data);
+ }
} else {
// To be checked
int dummy = 0;
col_values = eina_list_append(col_values, &(dummy));
- col_values = eina_list_append(col_values, &(media_type));
- col_values = eina_list_append(col_values, &(dummy));
col_values = eina_list_append(col_values, &(dummy));
col_values = eina_list_append(col_values, &(dummy));
col_values = eina_list_append(col_values, "");
- double longitude = 0.0f;
- double latitude = 0.0f;
-
- char long_str[50];
- sprintf(long_str,"%lf",longitude);
-
- char lat_str[50];
- sprintf(lat_str,"%lf",latitude);
-
- col_values = eina_list_append(col_values, long_str);
- col_values = eina_list_append(col_values, long_str);
+ if (longitude) {
+ col_values = eina_list_append(col_values, longitude);
+ } else {
+ col_values = eina_list_append(col_values, "0.000");
+ }
+ if (latitude) {
+ col_values = eina_list_append(col_values, latitude);
+ } else {
+ col_values = eina_list_append(col_values, "0.000");
+ }
col_values = eina_list_append(col_values, &(dummy));
for (int j = 0; j < 4; j++) {
}
}
- col_values = eina_list_append(col_values, "");
+ if (phone_number) {
+ col_values = eina_list_append(col_values, phone_number);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
- col_values = eina_list_append(col_values, "");
+ if (first_name) {
+ col_values = eina_list_append(col_values, first_name);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+ if (last_name) {
+ col_values = eina_list_append(col_values, last_name);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+
+
+
+ if (file_path) {
+ col_values = eina_list_append(col_values, file_path);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+
+ /*****************************************/
col_values = eina_list_append(col_values, "");
- col_values = eina_list_append(col_values, file_path);
+ char *mime_type = NULL;
+ if (file_path) {
+ char *extn = strrchr(file_path, '.');
+
+ if (extn) {
+ extn = replace(extn, '.', "");
+ }
+
+
+ if (extn) {
+ mime_type_get_mime_type(extn, &mime_type);
+ }
+ }
+ if (mime_type) {
+ col_values = eina_list_append(col_values, mime_type);
+ } else {
+ char * doc_type = "none";
+ col_values = eina_list_append(col_values, doc_type);
+ }
+
+ int doc_width = 0;
+ col_values = eina_list_append(col_values, &doc_width);
+
+ int doc_height = 0;
+ col_values = eina_list_append(col_values, &doc_height);
+
+ int doc_duration = 0;
+ col_values = eina_list_append(col_values, &doc_duration);
+
+ int doc_size = 0;
+ col_values = eina_list_append(col_values, &doc_size);
+
+ int doc_dc = 0;
+ col_values = eina_list_append(col_values, &doc_dc);
+
+ char *doc_thumb = NULL;
+ get_thumbnail_from_video_url(file_path, &doc_thumb);
+
+ if (!doc_thumb) {
+ doc_thumb = "";
+ }
+
+ col_values = eina_list_append(col_values, doc_thumb);
+
+ /*****************************************/
+
+
Eina_Bool ret = insert_table(table_name, col_names, col_types,col_values);
if(!ret) {
}
-char* get_image_path_from_db(long long media_id)
+int get_media_size_from_db(long long media_id)
{
- char* file_path = NULL;
+ int video_size = 0;
+ char* table_name = MEDIA_INFO_TABLE_NAME;
+
+ char usr_str[50];
+ sprintf(usr_str, "%lld", media_id);
+ char* where_clause = (char *)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = '") + strlen(usr_str) + strlen("'") + 1);
+ strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID);
+ strcat(where_clause, " = '");
+ strcat(where_clause, usr_str);
+ strcat(where_clause, "'");
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_SIZE);
+
+ Eina_List* vals = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+
+ if (!vals) {
+ //("DB error");
+ eina_list_free(col_names);
+ return 0;
+ } else {
+ int row_count = eina_list_count(vals);
+ for (int i = 0 ; i < row_count ; i++) {
+ Eina_List* row_vals = eina_list_nth(vals, i);
+ int *temp_video_size = (int*)eina_list_nth(row_vals, 0);
+ if (temp_video_size) {
+ video_size = *temp_video_size;
+ free(temp_video_size);
+ }
+ eina_list_free(row_vals);
+ break;
+ }
+ eina_list_free(vals);
+ }
+ eina_list_free(col_names);
+ return video_size;
+}
- char *table_name = MEDIA_INFO_TABLE_NAME;
+char* get_video_thumb_path_from_db(long long media_id)
+{
+ char* file_path = NULL;
+ char* table_name = MEDIA_INFO_TABLE_NAME;
char usr_str[50];
sprintf(usr_str, "%lld", media_id);
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
Eina_List* col_names = NULL;
- col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FILE_PATH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE);
Eina_List* vals = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
file_path = NULL;
for (int i = 0 ; i < row_count ; i++) {
Eina_List* row_vals = eina_list_nth(vals, i);
file_path = (char*)eina_list_nth(row_vals, 0);
+ eina_list_free(row_vals);
if (!file_path) {
//("DB Error");
eina_list_free(col_names);
} else {
break;
}
- eina_list_free(row_vals);
}
eina_list_free(vals);
}
- eina_list_free(col_names);
+ eina_list_free(col_names);
return file_path;
}
-Eina_List* get_image_sizes_from_db(long long media_id)
+char* get_media_path_from_db(long long media_id)
{
- Eina_List* vals = NULL;
+ char* file_path = NULL;
+
+ char* table_name = MEDIA_INFO_TABLE_NAME;
- char *table_name = MEDIA_INFO_TABLE_NAME;
char usr_str[50];
- sprintf(usr_str,"%lld",media_id);
- char* where_clause = (char*)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = ") + strlen(usr_str) + 1);
+ sprintf(usr_str, "%lld", media_id);
+ char* where_clause = (char *)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = '") + strlen(usr_str) + strlen("'") + 1);
+ strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID);
+ strcat(where_clause, " = '");
+ strcat(where_clause, usr_str);
+ strcat(where_clause, "'");
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FILE_PATH);
+
+ Eina_List* vals = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+ file_path = NULL;
+
+ if (!vals) {
+ //("DB error");
+ eina_list_free(col_names);
+ return NULL;
+ } else {
+ int row_count = eina_list_count(vals);
+
+ for (int i = 0 ; i < row_count ; i++) {
+ Eina_List* row_vals = eina_list_nth(vals, i);
+ file_path = (char*)eina_list_nth(row_vals, 0);
+ if (!file_path) {
+ //("DB Error");
+ eina_list_free(col_names);
+ return NULL;
+ } else {
+ break;
+ }
+ eina_list_free(row_vals);
+ }
+ eina_list_free(vals);
+ }
+ eina_list_free(col_names);
+
+ return file_path;
+}
+
+Eina_List* get_image_sizes_from_db(long long media_id)
+{
+ Eina_List* vals = NULL;
+
+ char* table_name = MEDIA_INFO_TABLE_NAME;
+ char usr_str[50];
+ sprintf(usr_str,"%lld",media_id);
+ char* where_clause = (char*)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = ") + strlen(usr_str) + 1);
strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID);
strcat(where_clause, " = ");
strcat(where_clause, usr_str);
Eina_List* get_image_details_from_db(long long media_id)
{
Eina_List* vals = NULL;
- char *table_name = MEDIA_INFO_TABLE_NAME;
+ char* table_name = MEDIA_INFO_TABLE_NAME;
char usr_str[50];
sprintf(usr_str,"%lld",media_id);
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
Eina_List* col_names = NULL;
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_ID);
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_TYPE);
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LAST_NAME);
col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FILE_PATH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MIME_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_WIDTH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_HEIGHT);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DURATION);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_SIZE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DC);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE);
+
vals = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
eina_list_free(col_types);
eina_list_free(col_names);
}
+Eina_List* load_peer_data_by_name(char* name)
+{
+ Eina_List* peer_list = NULL;
+ Eina_List* peer_details = get_all_peer_details(name);
+
+ for (int i = 0; i < eina_list_count(peer_details) ; i++) {
+ Eina_List* ts_msg = eina_list_nth(peer_details, i);
+ tg_peer_info_s* peer_info = (tg_peer_info_s*)malloc(sizeof(tg_peer_info_s));
+
+ int *temp_peer_id = (int*)eina_list_nth(ts_msg, 0);
+ if (temp_peer_id) {
+ peer_info->peer_id = *temp_peer_id;
+ free(temp_peer_id);
+ }
+
+ int *temp_peer_type = (int*)eina_list_nth(ts_msg, 1);
+ if (temp_peer_type) {
+ peer_info->peer_type = *temp_peer_type;
+ free(temp_peer_type);
+ }
+
+ int *temp_flags = (int*)eina_list_nth(ts_msg, 2);
+ if (temp_flags) {
+ peer_info->flags = *temp_flags;
+ free(temp_flags);
+ }
+
+ char *temp_msg_id = (char*)eina_list_nth(ts_msg, 3);
+ if (temp_msg_id) {
+ peer_info->last_msg_id = atoll(temp_msg_id);
+ free(temp_msg_id);
+ } else {
+ peer_info->last_msg_id = 0;
+ }
+
+ int *temp_last_msg_date = (int*)eina_list_nth(ts_msg, 4);
+ if (temp_last_msg_date) {
+ peer_info->last_msg_date = *temp_last_msg_date;
+ free(temp_last_msg_date);
+ }
+
+ char *temp_print_name = (char*)eina_list_nth(ts_msg, 5);
+ if (temp_print_name) {
+ peer_info->print_name = strdup(temp_print_name);
+ free(temp_print_name);
+ } else {
+ peer_info->print_name = NULL;
+ }
+
+ int *temp_struct_ver = (int*)eina_list_nth(ts_msg, 6);
+ if (temp_struct_ver) {
+ peer_info->struct_version = *temp_struct_ver;
+ free(temp_struct_ver);
+ }
+
+ int *temp_no_unread = (int*)eina_list_nth(ts_msg, 7);
+ if (temp_no_unread) {
+ peer_info->no_of_unread_msgs = *temp_no_unread;
+ free(temp_no_unread);
+ }
+
+ int *temp_last_seen = (int*)eina_list_nth(ts_msg, 8);
+ if (temp_last_seen) {
+ peer_info->last_seen_time = *temp_last_seen;
+ free(temp_last_seen);
+ }
+
+ char *temp_pic_path = (char*)eina_list_nth(ts_msg, 9);
+ if (temp_pic_path) {
+ peer_info->photo_path = strdup(temp_pic_path);
+ free(temp_pic_path);
+ } else {
+ peer_info->photo_path = NULL;
+ }
+
+ int *temp_pic_id = (int*)eina_list_nth(ts_msg, 10);
+ if (temp_pic_id) {
+ peer_info->photo_id = *temp_pic_id;
+ free(temp_pic_id);
+ }
+
+
+ eina_list_free(ts_msg);
+
+ peer_with_pic_s *item = (peer_with_pic_s*) malloc(sizeof (peer_with_pic_s));
+ item->use_data = peer_info;
+ item->contact_icon = NULL;
+
+ peer_list = eina_list_append(peer_list, item);
+
+ }
+ eina_list_free(peer_details);
+ return peer_list;
+}
+
+void free_media_details(tgl_media_s *media_msg)
+{
+ if (media_msg) {
+ if (media_msg->caption) {
+ free(media_msg->caption);
+ }
+ if (media_msg->longitude) {
+ free(media_msg->longitude);
+ }
+ if (media_msg->latitude) {
+ free(media_msg->latitude);
+ }
+ if (media_msg->phone_no) {
+ free(media_msg->phone_no);
+ }
+ if (media_msg->first_name) {
+ free(media_msg->first_name);
+ }
+ if (media_msg->last_name) {
+ free(media_msg->last_name);
+ }
+ if (media_msg->file_path) {
+ free(media_msg->file_path);
+ }
+ if (media_msg->photo_type1) {
+ free(media_msg->photo_type1);
+ }
+ if (media_msg->photo_data1) {
+ free(media_msg->photo_data1);
+ }
+ if (media_msg->photo_type2) {
+ free(media_msg->photo_type2);
+ }
+ if (media_msg->photo_data2) {
+ free(media_msg->photo_data2);
+ }
+ if (media_msg->photo_type3) {
+ free(media_msg->photo_type3);
+ }
+ if (media_msg->photo_data3) {
+ free(media_msg->photo_data3);
+ }
+ if (media_msg->photo_type4) {
+ free(media_msg->photo_type4);
+ }
+ if (media_msg->photo_data4) {
+ free(media_msg->photo_data4);
+ }
+ if (media_msg->mime_type) {
+ free(media_msg->mime_type);
+ }
+ if (media_msg->doc_type) {
+ free(media_msg->doc_type);
+ }
+ }
+}
+
+tgl_media_s *get_media_details_from_db(long long media_id)
+{
+ Eina_List* img_details = get_image_details_from_db(media_id);
+
+ if (!img_details) {
+ return NULL;
+ }
+
+ tgl_media_s* media_info = (tgl_media_s*)malloc(sizeof(tgl_media_s));
+
+ Eina_List* row_vals = eina_list_nth(img_details, 0);
+
+ char *temp_media_id = (char *)eina_list_nth(row_vals, 0);
+
+ if(temp_media_id) {
+ media_info->media_id = atoll(temp_media_id);
+ free(temp_media_id);
+ } else {
+ media_info->media_id = 0;
+ }
+
+ int* temp_media_type = (int*)eina_list_nth(row_vals, 1);
+
+ if(temp_media_type) {
+ media_info->media_type = *temp_media_type;
+ free(temp_media_type);
+ } else {
+ media_info->media_type = -1;
+ }
+
+ char *temp_access_hash = (char *)eina_list_nth(row_vals, 2);
+
+ if(temp_access_hash) {
+ media_info->access_hash = atoll(temp_access_hash);
+ free(temp_access_hash);
+ } else {
+ media_info->access_hash = 0;
+ }
+
+ int* temp_user_id = (int*)eina_list_nth(row_vals, 3);
+
+ if(temp_user_id) {
+ media_info->user_id = *temp_user_id;
+ free(temp_user_id);
+ } else {
+ media_info->user_id = 0;
+ }
+
+ int* temp_date = (int*)eina_list_nth(row_vals, 4);
+
+ if(temp_date) {
+ media_info->date = *temp_date;
+ free(temp_date);
+ } else {
+ media_info->date = 0;
+ }
+
+ char *temp_caption = (char *)eina_list_nth(row_vals, 5);
+
+ if(temp_caption) {
+ media_info->caption = strdup(temp_caption);
+ free(temp_caption);
+ }
+
+ char *temp_longitude = (char *)eina_list_nth(row_vals, 6);
+
+ if(temp_longitude) {
+ media_info->longitude = strdup(temp_longitude);
+ free(temp_longitude);
+ } else {
+ media_info->longitude = 0;
+ }
+
+ char *temp_latitude = (char *)eina_list_nth(row_vals, 7);
+
+ if(temp_latitude) {
+ media_info->latitude = strdup(temp_latitude);
+ free(temp_latitude);
+ } else {
+ media_info->latitude = 0;
+ }
+
+ int* temp_sizes = (int*)eina_list_nth(row_vals, 8);
+
+ if(temp_sizes) {
+ media_info->sizes = *temp_sizes;
+ free(temp_sizes);
+ } else {
+ media_info->sizes = 0;
+ }
+
+ /***************************************************************/
+
+ char *temp_photo_type1 = (char *)eina_list_nth(row_vals, 9);
+ if (temp_photo_type1 && strlen(temp_photo_type1) > 0) {
+ media_info->photo_type1 =strdup(temp_photo_type1);
+ free(temp_photo_type1);
+ } else {
+ media_info->photo_type1 = 0;
+ }
+
+
+ int* temp_photo_loc_dc1 = (int*)eina_list_nth(row_vals, 10);
+ if (temp_photo_loc_dc1) {
+ media_info->photo_loc_dc1 = *temp_photo_loc_dc1;
+ free(temp_photo_loc_dc1);
+ } else {
+ media_info->photo_loc_dc1 = 0;
+ }
+
+
+ char *temp_photo_loc_vol1 = (char *)eina_list_nth(row_vals, 11);
+ if(temp_photo_loc_vol1 && strlen(temp_photo_loc_vol1) > 0) {
+ media_info->photo_loc_vol1 = atoll(temp_photo_loc_vol1);
+ free(temp_photo_loc_vol1);
+ } else {
+ media_info->photo_loc_vol1 = 0;
+ }
+
+
+ int* temp_photo_loc_id1 = (int*)eina_list_nth(row_vals, 12);
+ if (temp_photo_loc_id1) {
+ media_info->photo_loc_id1 = *temp_photo_loc_id1;
+ free(temp_photo_loc_id1);
+ } else {
+ media_info->photo_loc_id1 = 0;
+ }
+
+ char *temp_photo_loc_sec1 = (char *)eina_list_nth(row_vals, 13);
+ if(temp_photo_loc_sec1 && strlen(temp_photo_loc_sec1) > 0) {
+ media_info->photo_loc_sec1 = atoll(temp_photo_loc_sec1);
+ free(temp_photo_loc_sec1);
+ } else {
+ media_info->photo_loc_sec1 = 0;
+ }
+
+
+ int* temp_photo_width1 = (int*)eina_list_nth(row_vals, 14);
+ if(temp_photo_width1) {
+ media_info->photo_width1 = *temp_photo_width1;
+ free(temp_photo_width1);
+ } else {
+ media_info->photo_width1 = 0;
+ }
+
+
+ int* temp_photo_height1 = (int*)eina_list_nth(row_vals, 15);
+ if(temp_photo_height1) {
+ media_info->photo_height1 = *temp_photo_height1;
+ free(temp_photo_height1);
+ } else {
+ media_info->photo_height1 = 0;
+ }
+
+ int* temp_photo_size1 = (int*)eina_list_nth(row_vals, 16);
+ if(temp_photo_size1) {
+ media_info->photo_size1 = *temp_photo_size1;
+ free(temp_photo_size1);
+ } else {
+ media_info->photo_size1 = 0;
+ }
+
+
+ char *temp_photo_data1 = (char *)eina_list_nth(row_vals, 17);
+ if(temp_photo_data1 && strlen(temp_photo_data1) > 0) {
+ media_info->photo_data1 = strdup(temp_photo_data1);
+ free(temp_photo_data1);
+ } else {
+ media_info->photo_data1 = 0;
+ }
+
+
+ char *temp_photo_type2 = (char *)eina_list_nth(row_vals, 18);
+ if (temp_photo_type2 && strlen(temp_photo_type2) > 0) {
+ media_info->photo_type2 =strdup(temp_photo_type2);
+ free(temp_photo_type2);
+ } else {
+ media_info->photo_type2 = 0;
+ }
+
+
+ int* temp_photo_loc_dc2 = (int*)eina_list_nth(row_vals, 19);
+ if (temp_photo_loc_dc2) {
+ media_info->photo_loc_dc2 = *temp_photo_loc_dc2;
+ free(temp_photo_loc_dc2);
+ } else {
+ media_info->photo_loc_dc2 = 0;
+ }
+
+
+ char *temp_photo_loc_vol2 = (char *)eina_list_nth(row_vals, 20);
+ if(temp_photo_loc_vol2 && strlen(temp_photo_loc_vol2) > 0) {
+ media_info->photo_loc_vol2 = atoll(temp_photo_loc_vol2);
+ free(temp_photo_loc_vol2);
+ } else {
+ media_info->photo_loc_vol2 = 0;
+ }
+
+
+ int* temp_photo_loc_id2 = (int*)eina_list_nth(row_vals, 21);
+ if (temp_photo_loc_id2) {
+ media_info->photo_loc_id2 = *temp_photo_loc_id2;
+ free(temp_photo_loc_id2);
+ } else {
+ media_info->photo_loc_id2 = 0;
+ }
+
+ char *temp_photo_loc_sec2 = (char *)eina_list_nth(row_vals, 22);
+ if(temp_photo_loc_sec2 && strlen(temp_photo_loc_sec2) > 0) {
+ media_info->photo_loc_sec2 = atoll(temp_photo_loc_sec2);
+ free(temp_photo_loc_sec2);
+ } else {
+ media_info->photo_loc_sec2 = 0;
+ }
+
+
+ int* temp_photo_width2 = (int*)eina_list_nth(row_vals, 23);
+ if(temp_photo_width2) {
+ media_info->photo_width2 = *temp_photo_width2;
+ free(temp_photo_width2);
+ } else {
+ media_info->photo_width2 = 0;
+ }
+
+
+ int* temp_photo_height2 = (int*)eina_list_nth(row_vals, 24);
+ if(temp_photo_height2) {
+ media_info->photo_height2 = *temp_photo_height2;
+ free(temp_photo_height2);
+ } else {
+ media_info->photo_height2 = 0;
+ }
+
+ int* temp_photo_size2 = (int*)eina_list_nth(row_vals, 25);
+ if(temp_photo_size2) {
+ media_info->photo_size2 = *temp_photo_size2;
+ free(temp_photo_size2);
+ } else {
+ media_info->photo_size2 = 0;
+ }
+
+
+ char *temp_photo_data2 = (char *)eina_list_nth(row_vals, 26);
+ if(temp_photo_data2 && strlen(temp_photo_data2) > 0) {
+ media_info->photo_data2 = strdup(temp_photo_data2);
+ free(temp_photo_data2);
+ } else {
+ media_info->photo_data2 = 0;
+ }
+
+ char *temp_photo_type3 = (char *)eina_list_nth(row_vals, 27);
+ if (temp_photo_type3 && strlen(temp_photo_type3) > 0) {
+ media_info->photo_type3 =strdup(temp_photo_type3);
+ free(temp_photo_type3);
+ } else {
+ media_info->photo_type3 = 0;
+ }
+
+
+ int* temp_photo_loc_dc3 = (int*)eina_list_nth(row_vals, 28);
+ if (temp_photo_loc_dc3) {
+ media_info->photo_loc_dc3 = *temp_photo_loc_dc3;
+ free(temp_photo_loc_dc3);
+ } else {
+ media_info->photo_loc_dc3 = 0;
+ }
+
+
+ char *temp_photo_loc_vol3 = (char *)eina_list_nth(row_vals, 29);
+ if(temp_photo_loc_vol3 && strlen(temp_photo_loc_vol3) > 0) {
+ media_info->photo_loc_vol3 = atoll(temp_photo_loc_vol3);
+ free(temp_photo_loc_vol3);
+ } else {
+ media_info->photo_loc_vol3 = 0;
+ }
+
+
+ int* temp_photo_loc_id3 = (int*)eina_list_nth(row_vals, 30);
+ if (temp_photo_loc_id3) {
+ media_info->photo_loc_id3 = *temp_photo_loc_id3;
+ free(temp_photo_loc_id3);
+ } else {
+ media_info->photo_loc_id3 = 0;
+ }
+
+ char *temp_photo_loc_sec3 = (char *)eina_list_nth(row_vals, 31);
+ if(temp_photo_loc_sec3 && strlen(temp_photo_loc_sec3) > 0) {
+ media_info->photo_loc_sec3 = atoll(temp_photo_loc_sec3);
+ free(temp_photo_loc_sec3);
+ } else {
+ media_info->photo_loc_sec3 = 0;
+ }
+
+
+ int* temp_photo_width3 = (int*)eina_list_nth(row_vals, 32);
+ if(temp_photo_width3) {
+ media_info->photo_width3 = *temp_photo_width3;
+ free(temp_photo_width3);
+ } else {
+ media_info->photo_width3 = 0;
+ }
+
+
+ int* temp_photo_height3 = (int*)eina_list_nth(row_vals, 33);
+ if(temp_photo_height3) {
+ media_info->photo_height3 = *temp_photo_height3;
+ free(temp_photo_height3);
+ } else {
+ media_info->photo_height3 = 0;
+ }
+
+ int* temp_photo_size3 = (int*)eina_list_nth(row_vals, 34);
+ if(temp_photo_size3) {
+ media_info->photo_size3 = *temp_photo_size3;
+ free(temp_photo_size3);
+ } else {
+ media_info->photo_size3 = 0;
+ }
+
+
+ char *temp_photo_data3 = (char *)eina_list_nth(row_vals, 35);
+ if(temp_photo_data3 && strlen(temp_photo_data3) > 0) {
+ media_info->photo_data3 = strdup(temp_photo_data3);
+ free(temp_photo_data3);
+ } else {
+ media_info->photo_data3 = 0;
+ }
+
+ char *temp_photo_type4 = (char *)eina_list_nth(row_vals, 36);
+ if (temp_photo_type4 && strlen(temp_photo_type4) > 0) {
+ media_info->photo_type4 =strdup(temp_photo_type4);
+ free(temp_photo_type4);
+ } else {
+ media_info->photo_type4 = 0;
+ }
+
+
+ int* temp_photo_loc_dc4 = (int*)eina_list_nth(row_vals, 37);
+ if (temp_photo_loc_dc4) {
+ media_info->photo_loc_dc4 = *temp_photo_loc_dc4;
+ free(temp_photo_loc_dc4);
+ } else {
+ media_info->photo_loc_dc4 = 0;
+ }
+
+
+ char *temp_photo_loc_vol4 = (char *)eina_list_nth(row_vals, 38);
+ if(temp_photo_loc_vol4 && strlen(temp_photo_loc_vol4) > 0) {
+ media_info->photo_loc_vol4 = atoll(temp_photo_loc_vol4);
+ free(temp_photo_loc_vol4);
+ } else {
+ media_info->photo_loc_vol4 = 0;
+ }
+
+
+ int* temp_photo_loc_id4 = (int*)eina_list_nth(row_vals, 39);
+ if (temp_photo_loc_id4) {
+ media_info->photo_loc_id4 = *temp_photo_loc_id4;
+ free(temp_photo_loc_id4);
+ } else {
+ media_info->photo_loc_id4 = 0;
+ }
+
+ char *temp_photo_loc_sec4 = (char *)eina_list_nth(row_vals, 40);
+ if(temp_photo_loc_sec4 && strlen(temp_photo_loc_sec4) > 0) {
+ media_info->photo_loc_sec4 = atoll(temp_photo_loc_sec4);
+ free(temp_photo_loc_sec4);
+ } else {
+ media_info->photo_loc_sec4 = 0;
+ }
+
+
+ int* temp_photo_width4 = (int*)eina_list_nth(row_vals, 41);
+ if(temp_photo_width4) {
+ media_info->photo_width4 = *temp_photo_width4;
+ free(temp_photo_width4);
+ } else {
+ media_info->photo_width4 = 0;
+ }
+
+
+ int* temp_photo_height4 = (int*)eina_list_nth(row_vals, 42);
+ if(temp_photo_height4) {
+ media_info->photo_height4 = *temp_photo_height4;
+ free(temp_photo_height4);
+ } else {
+ media_info->photo_height4 = 0;
+ }
+
+ int* temp_photo_size4 = (int*)eina_list_nth(row_vals, 43);
+ if(temp_photo_size4) {
+ media_info->photo_size4 = *temp_photo_size4;
+ free(temp_photo_size4);
+ } else {
+ media_info->photo_size4 = 0;
+ }
+
+
+ char *temp_photo_data4 = (char *)eina_list_nth(row_vals, 44);
+ if(temp_photo_data4 && strlen(temp_photo_data4) > 0) {
+ media_info->photo_data4 = strdup(temp_photo_data4);
+ free(temp_photo_data4);
+ } else {
+ media_info->photo_data4 = 0;
+ }
+
+
+ /**************************************************************/
+
+ char *temp_phone_no = (char *)eina_list_nth(row_vals, 45);
+
+ if(temp_phone_no && strlen(temp_phone_no) > 0) {
+ media_info->phone_no = strdup(temp_phone_no);
+ free(temp_phone_no);
+ } else {
+ media_info->phone_no = 0;
+ }
+
+ char *temp_first_name = (char *)eina_list_nth(row_vals, 46);
+
+ if(temp_first_name && strlen(temp_first_name) > 0) {
+ media_info->first_name = strdup(temp_first_name);
+ free(temp_first_name);
+ } else {
+ media_info->first_name = 0;
+ }
+
+ char *temp_last_name = (char *)eina_list_nth(row_vals, 47);
+
+ if(temp_last_name && strlen(temp_last_name) > 0) {
+ media_info->last_name = strdup(temp_last_name);
+ free(temp_last_name);
+ } else {
+ media_info->last_name = 0;
+ }
+
+ char *temp_file_path = (char *)eina_list_nth(row_vals, 48);
+
+ if(temp_file_path && strlen(temp_file_path) > 0) {
+ media_info->file_path = strdup(temp_file_path);
+ free(temp_file_path);
+ } else {
+ media_info->file_path = 0;
+ }
+
+ char *temp_mime_type = (char *)eina_list_nth(row_vals, 49);
+
+ if(temp_mime_type && strlen(temp_mime_type) > 0) {
+ media_info->mime_type = strdup(temp_mime_type);
+ free(temp_mime_type);
+ } else {
+ media_info->mime_type = 0;
+ }
+
+ char *temp_doc_type = (char *)eina_list_nth(row_vals, 50);
+
+ if(temp_doc_type && strlen(temp_doc_type) > 0) {
+ media_info->doc_type = strdup(temp_doc_type);
+ free(temp_doc_type);
+ } else {
+ media_info->doc_type = 0;
+ }
+
+ int* temp_doc_width = (int*)eina_list_nth(row_vals, 51);
+ if(temp_doc_width) {
+ media_info->doc_width = *temp_doc_width;
+ free(temp_doc_width);
+ } else {
+ media_info->doc_width = 0;
+ }
+
+ int* temp_doc_height = (int*)eina_list_nth(row_vals, 52);
+ if(temp_doc_height) {
+ media_info->doc_height = *temp_doc_height;
+ free(temp_doc_height);
+ } else {
+ media_info->doc_height = 0;
+ }
+
+ int* temp_doc_duration = (int*)eina_list_nth(row_vals, 53);
+ if(temp_doc_duration) {
+ media_info->doc_duration = *temp_doc_duration;
+ free(temp_doc_duration);
+ } else {
+ media_info->doc_duration = 0;
+ }
+
+ int* temp_doc_size = (int*)eina_list_nth(row_vals, 54);
+ if(temp_doc_size) {
+ media_info->doc_size = *temp_doc_size;
+ free(temp_doc_size);
+ } else {
+ media_info->doc_size = 0;
+ }
+
+ eina_list_free(row_vals);
+
+ return media_info;
+
+}
+
+Eina_List* get_all_peer_ids()
+{
+ Eina_List* peer_details = NULL;
+ char* table_name = PEER_INFO_TABLE_NAME;
+ Eina_List* col_names = NULL;
+
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_CHAT_ID);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+
+ peer_details = get_values_from_table_sync_order_by(table_name, col_names, col_types, PEER_INFO_TABLE_LAST_MESSAGE_DATE, EINA_FALSE, NULL);
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ return peer_details;
+}
+
+int get_number_of_unread_messages()
+{
+ int no_of_unread = 0;
+ Eina_List* peer_details = get_all_peer_ids();
+ for (int i = 0; i < eina_list_count(peer_details) ; i++) {
+ Eina_List* ts_msg = eina_list_nth(peer_details, i);
+ int peer_id = 0;
+ int *temp_peer_id = (int*)eina_list_nth(ts_msg, 0);
+ if (temp_peer_id) {
+ peer_id = *temp_peer_id;
+ free(temp_peer_id);
+ temp_peer_id = NULL;
+ }
+ char *msg_table = get_table_name_from_number(peer_id);
+ int count = 0;
+ if (msg_table) {
+ count = get_unread_message_count(msg_table);
+ }
+ no_of_unread = no_of_unread + count;
+ free(msg_table);
+ eina_list_free(ts_msg);
+ }
+ eina_list_free(peer_details);
+ return no_of_unread;
+}
char* first_name = trim((char*)tfirst_name);
char* last_name = trim((char*)tlast_name);
send_request_for_profile_registration(ad->service_client, first_name, last_name);
+ show_loading_popup(ad);
free(first_name);
free(last_name);
#else
return;
}
send_request_for_validation(ad->service_client, val);
+ show_loading_popup(ad);
}
#else
if (ad->timer_value > 0) {
(ad->timer_value)--;
int cur_time_in_secs = ad->timer_value;
-
Evas_Object* info_timer = evas_object_data_get(ad->nf, "info_timer");
+ if (cur_time_in_secs <= 0) {
+ char temp_txt[512] = {0,};
+ snprintf(temp_txt, sizeof(temp_txt), "<font=Tizen:style=Regular color=#666362 align=left><font_size=32>%s</font_size></font>", "Requested for code via call.");
+
+ elm_object_text_set(info_timer, temp_txt);
+ Ecore_Timer* timer = evas_object_data_get(ad->nf, "code_timer");
+ ecore_timer_del(timer);
+
+ // send request to get phone call
+ send_request_for_registration(ad->service_client, ad->phone_number, EINA_FALSE);
+ return ECORE_CALLBACK_CANCEL;
+ }
int seconds = cur_time_in_secs % 60;
int minutes = (cur_time_in_secs / 60) % 60;
char sec_str[10];
char min_str[10];
- sprintf(min_str, "%d", minutes);
- sprintf(sec_str, "%d", seconds);
+ if (minutes < 10) {
+ sprintf(min_str, "0%d", minutes);
+ } else {
+ sprintf(min_str, "%d", minutes);
+ }
+ if (seconds < 10) {
+ sprintf(sec_str, "0%d", seconds);
+ } else {
+ sprintf(sec_str, "%d", seconds);
+ }
char* timer_text = (char*)malloc(strlen(TIMER_TEXT) + strlen(min_str) + strlen(":") + strlen(sec_str) + 1);
strcpy(timer_text, TIMER_TEXT);
#include "tg_messaging_view.h"
#include "tg_db_wrapper.h"
#include "server_requests.h"
+#include <mime_type.h>
+#include "tg_user_info_view.h"
+#include "tg_chat_info_view.h"
-static Evas_Object *create_image_object_from_file(const char *icon_name, Evas_Object *parent)
-{
- Evas_Object *icon = elm_image_add(parent);
- evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
- elm_image_file_set(icon, icon_name, NULL);
- evas_object_show(icon);
- return icon;
-}
+/************************ Menu Handler ********************/
-void on_chat_media_item_clicked(void* data, Evas_Object* layout, void* event_info)
+void on_messaging_menu_option_selected_cb(void *data, Evas_Object *obj, void *event_info)
{
-/* evas_object_data_set(comp_img_layout, "chat_list", (void*)chat_list);
- evas_object_data_set(comp_img_layout, "message_id", (void*)message_id);
- evas_object_data_set(comp_img_layout, "item_media", (void*)image);*/
+ appdata_s *ad = data;
- appdata_s* ad = evas_object_data_get(layout, "app_data");
- char* temp_media_id = evas_object_data_get(layout, "media_id");
- //char* img_path = evas_object_data_get(comp_img_layout, "image_path");
- long long media_id = atoll(temp_media_id);
- char* file_path = get_image_path_from_db(media_id);
+ Elm_Object_Item *it = event_info;
+ elm_genlist_item_selected_set(it, EINA_FALSE);
+ int id = (int)elm_object_item_data_get(it);
- if( access (file_path, F_OK) != -1 ) {
- } else {
- file_path = NULL;
+ peer_with_pic_s *sel_item = ad->peer_in_cahtting_data;
+ tg_peer_info_s *user_data = sel_item->use_data;
+
+ if (!sel_item || !user_data) {
+ show_toast(ad, "There are no messages to delete.");
+ return;
}
- if (!file_path || strlen(file_path) <= 0) {
+ if (id == 0) {
+ if (user_data->peer_type == TGL_PEER_USER || user_data->peer_type == TGL_PEER_CHAT) {
+ char* tablename = get_table_name_from_number(user_data->peer_id);
+ delete_all_records(tablename);
+ free(tablename);
- // show progress bar
- Evas_Object* img_info_layout = evas_object_data_get(layout, "image_info_layout");
- Evas_Object* img_size_lbl = elm_object_part_content_get(img_info_layout, "swallow.chat_recv_image,size");
- Evas_Object* download_img = elm_object_part_content_get(img_info_layout, "swallow.chat_recv_image,download");
- //Evas_Object* progressbar = elm_object_part_content_get(img_info_layout, "swallow.chat_recv_image,progress");
+ // clear all messages
+ Evas_Object *genlist = evas_object_data_get(ad->nf, "chat_list");
+ elm_genlist_clear(genlist);
+ // remove main item from main list
+ if (ad->main_item_in_cahtting_data) {
+ tg_main_list_item_s* old_item = ad->main_item_in_cahtting_data;
+ if (old_item->peer_print_name) {
+ free(old_item->peer_print_name);
+ old_item->peer_print_name = NULL;
+ }
+ if (old_item->last_message) {
+ free(old_item->last_message);
+ old_item->last_message = NULL;
+ }
+ if (old_item->profile_pic_path) {
+ free(old_item->profile_pic_path);
+ old_item->profile_pic_path = NULL;
+ }
+ old_item->date_lbl = NULL;
+ old_item->msg_status_lbl = NULL;
+ old_item->profile_pic = NULL;
+ old_item->profile_pic_path = NULL;
+ old_item->status_lbl = NULL;
+ old_item->user_name_lbl = NULL;
+ ad->main_list = eina_list_remove(ad->main_list, ad->main_item_in_cahtting_data);
+
+ ad->main_item_in_cahtting_data = NULL;
+ }
- evas_object_del(img_size_lbl);
- evas_object_del(download_img);
+ ad->is_last_msg_changed = EINA_FALSE;
+ } else {
- Evas_Object* progressbar = elm_progressbar_add(img_info_layout);
- elm_object_style_set(progressbar, "process_small");
- evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_progressbar_pulse(progressbar, EINA_TRUE);
- elm_object_part_content_set(img_info_layout, "swallow.chat_recv_image,progress", progressbar);
- evas_object_show(progressbar);
+ }
- send_request_for_image_downloading(ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id, media_id);
- }
+ } else if (id == 1) {
+ if (user_data->peer_type == TGL_PEER_USER) {
+ char* tablename = get_table_name_from_number(user_data->peer_id);
+ delete_all_records(tablename);
+ free(tablename);
+
+ // clear all messages
+ Evas_Object *genlist = evas_object_data_get(ad->nf, "chat_list");
+ elm_genlist_clear(genlist);
+
+ // remove main item from main list
+ if (ad->main_item_in_cahtting_data) {
+ tg_main_list_item_s* old_item = ad->main_item_in_cahtting_data;
+ if (old_item->peer_print_name) {
+ free(old_item->peer_print_name);
+ old_item->peer_print_name = NULL;
+ }
+ if (old_item->last_message) {
+ free(old_item->last_message);
+ old_item->last_message = NULL;
+ }
+ if (old_item->profile_pic_path) {
+ free(old_item->profile_pic_path);
+ old_item->profile_pic_path = NULL;
+ }
+ old_item->date_lbl = NULL;
+ old_item->msg_status_lbl = NULL;
+ old_item->profile_pic = NULL;
+ old_item->profile_pic_path = NULL;
+ old_item->status_lbl = NULL;
+ old_item->user_name_lbl = NULL;
+ ad->main_list = eina_list_remove(ad->main_list, ad->main_item_in_cahtting_data);
+
+ ad->main_item_in_cahtting_data = NULL;
+ }
+
+ ad->is_last_msg_changed = EINA_FALSE;
+
+
+ app_nf_back_cb(ad, NULL, NULL);
+
+
+ } else if (user_data->peer_type == TGL_PEER_CHAT) {
+ //send group chat delete request
+ show_loading_popup(ad);
+ send_delete_group_chat_request(ad->service_client, user_data->peer_id);
+
+ } else {
+
+ }
+ } else {
+
+ }
+ if (ad->msg_popup) {
+ evas_object_del(ad->msg_popup);
+ ad->msg_popup = NULL;
+ }
}
-Evas_Object* on_message_item_content_get_cb(void *data, Evas_Object *obj, const char *part)
+char* on_messaging_menu_group_text_get_cb(void *data, Evas_Object *obj, const char *part)
{
- Evas_Object *layout;
- layout = elm_layout_add(obj);
- if (!strcmp(part, "elm.icon.entry")) {
- int message_id = (int)data;
- Evas_Object* chat_list = obj;
- appdata_s* ad = evas_object_data_get(chat_list, "app_data");
- int user_id = (int)evas_object_data_get(chat_list, "user_id");
- //Evas_Object* text_entry = evas_object_data_set(chat_list, "text_entry");
+ int id = (int) data;
+ if (id == 0) {
+ return strdup("Clear history");
+ } else {
+ return strdup("Delete and exit");
+ }
+}
- peer_with_pic_s *sel_item = eina_list_nth(ad->peer_list, user_id);
- int buddy_id = sel_item->use_data->peer_id;
+char* on_messaging_menu_text_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ int id = (int) data;
+ if (id == 0) {
+ return strdup("Clear history");
+ } else {
+ return strdup("Delete");
+ }
+}
- char* tablename = get_table_name_from_number(buddy_id);
- tg_message_s* msg = get_message_from_message_table(message_id, tablename);
- Eina_Bool is_blur_image = EINA_FALSE;
+void on_msg_popup_back_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = data;
+ if (ad->msg_popup) {
+ evas_object_del(ad->msg_popup);
+ ad->msg_popup = NULL;
+ }
+}
- if (msg) {
+void on_messaging_menu_button_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = data;
+ if (ad->msg_popup || ad->current_app_state != TG_CHAT_MESSAGING_VIEW_STATE) {
+ return;
+ }
- peer_with_pic_s* pic_peer_item = ad->peer_in_cahtting_data;
- if (pic_peer_item) {
- tg_peer_info_s* peer_item = pic_peer_item->use_data;
- // update peer table
- if (peer_item) {
- peer_item->last_msg_id = msg->msg_id;
- peer_item->last_msg_date = msg->date;
- insert_or_update_peer_into_database(peer_item);
- }
- }
+ static Elm_Genlist_Item_Class itc;
+ //Evas_Object *popup;
+ Evas_Object *box;
+ Evas_Object *genlist;
+ int i;
+ Evas_Object *win = ad->win;
+
+ ad->msg_popup = elm_popup_add(win);
+ elm_popup_align_set(ad->msg_popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(ad->msg_popup, EEXT_CALLBACK_BACK, on_msg_popup_back_cb, ad);
+ evas_object_size_hint_weight_set(ad->msg_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ evas_object_data_set(ad->msg_popup, "app_data", ad);
+ box = elm_box_add(ad->msg_popup);
+ evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ genlist = elm_genlist_add(box);
+ evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ itc.item_style = "default";
+ peer_with_pic_s *sel_item = ad->peer_in_cahtting_data;
+ if (sel_item->use_data->peer_type == TGL_PEER_USER) {
+ itc.func.text_get = on_messaging_menu_text_get_cb;
+ } else if (sel_item->use_data->peer_type == TGL_PEER_CHAT) {
+ itc.func.text_get = on_messaging_menu_group_text_get_cb;
+ } else {
- if (msg->out) {
+ }
- } else {
- // update un read
- if (msg->unread) {
- msg->unread = 0;
+ itc.func.content_get = NULL;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
- update_msg_into_db(msg, tablename);
+ for (i = 0; i < 2; i++) {
+ elm_genlist_item_append(genlist, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_messaging_menu_option_selected_cb, ad);
+ }
+ evas_object_show(genlist);
+ elm_box_pack_end(box, genlist);
+ evas_object_size_hint_min_set(box, -1, 230);
+ elm_object_content_set(ad->msg_popup, box);
+ evas_object_show(ad->msg_popup);
+}
- }
- }
- if (msg->media_type == tgl_message_media_photo) {
+/************************ Menu Handler ********************/
- char edj_path[PATH_MAX] = {0, };
- app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
- char* img_path = get_image_path_from_db(atoll(msg->media_id));
- if( access(img_path, F_OK) != -1 ) {
- } else {
- img_path = NULL;
- }
+static Evas_Object *create_image_object_from_file(const char *icon_name, Evas_Object *parent)
+{
+ Evas_Object *icon = elm_image_add(parent);
+ evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_image_file_set(icon, icon_name, NULL);
+ evas_object_show(icon);
+ return icon;
+}
+void on_chat_profile_pic_changed(appdata_s *ad, char *file_path)
+{
+ if (!ad || !file_path) {
+ return;
+ }
- if (img_path == NULL || strlen(img_path) == 0) {
- const char *tmp;
- tmp = ui_utils_get_resource(BLUR_BG);
- img_path = strdup(tmp);
- is_blur_image = EINA_TRUE;
- }
+ Evas_Object *profile_image = evas_object_data_get(ad->nf, "profile_picture");
+ if (profile_image) {
+ elm_image_file_set(profile_image, file_path, NULL);
+ }
+}
- layout = elm_layout_add(obj);
- if(msg->out) {
- elm_layout_file_set(layout, edj_path, "list_image_send_item");
- } else {
- elm_layout_file_set(layout, edj_path, "list_image_recv_item");
- }
- evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_show(layout);
+void on_group_chat_info_changed(appdata_s *ad, char *type_of_change)
+{
+ if (!ad || !type_of_change) {
+ return;
+ }
+ if (strstr(type_of_change, "edit_title") != NULL) {
+ peer_with_pic_s *sel_item = ad->peer_in_cahtting_data;
+ if (sel_item) {
+ tg_peer_info_s* user = sel_item->use_data;
+ char* user_name = replace(sel_item->use_data->print_name, '_', " ");
+ char temp_name[512] = {'\0'};
+ snprintf(temp_name, 512, "<font=Tizen:style=Italic color=#000000 align=left><font_size=30>%s</font_size></font>", user_name);
+ free(user_name);
+ Evas_Object *profile_name = evas_object_data_get(ad->nf, "profile_title");
+ elm_object_text_set(profile_name,temp_name);
+ }
+ } else if (strstr(type_of_change, "delete_photo") != NULL) {
+ } else if (strstr(type_of_change, "add_user") != NULL) {
+ peer_with_pic_s *sel_item = ad->peer_in_cahtting_data;
+ if (sel_item) {
+ on_user_presence_state_changed(ad, sel_item->use_data->peer_id);
+ }
+ } else if (strstr(type_of_change, "delete_user") != NULL) {
+ peer_with_pic_s *sel_item = ad->peer_in_cahtting_data;
+ if (sel_item) {
+ on_user_presence_state_changed(ad, sel_item->use_data->peer_id);
+ }
+ } else {
- if (img_path) {
+ }
+}
- Evas_Object* img_layout = elm_layout_add(obj);
- if(msg->out) {
- elm_layout_file_set(img_layout, edj_path, "chat_media_send_box");
- } else {
- elm_layout_file_set(img_layout, edj_path, "chat_media_recv_box");
- }
- evas_object_size_hint_weight_set(img_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(img_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_show(img_layout);
-
- Evas_Object* image = create_image_object_from_file(img_path, obj);
- //elm_image_no_scale_set(image, EINA_TRUE);
- elm_image_resizable_set(image, EINA_TRUE, EINA_TRUE);
- elm_image_smooth_set(image, EINA_FALSE);
- elm_image_aspect_fixed_set(image, EINA_TRUE);
- elm_image_fill_outside_set(image, EINA_FALSE);
- elm_image_editable_set(image, EINA_TRUE);
- int pre_scale = elm_image_prescale_get(image);
- elm_image_prescale_set(image, pre_scale/2);
-
- if(msg->out) {
- Evas_Object* comp_img_layout = elm_layout_add(obj);
-
- elm_layout_file_set(comp_img_layout, edj_path, "chat_send_image_box");
-
- evas_object_size_hint_weight_set(comp_img_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(comp_img_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_show(comp_img_layout);
-
- elm_object_part_content_set(comp_img_layout, "swallow.chat_send_image", image);
- //@TODO: need to add code here
- //elm_object_signal_emit(item_top, "set,disabled", "bg");
-
- elm_object_part_content_set(layout, "swallow.img_bg", img_layout);
-
- time_t t = msg->date;
- const char *format = "%I:%M %P";
- struct tm lt;
- char res[32];
- (void) localtime_r(&t, <);
-
- if (strftime(res, sizeof(res), format, <) == 0) {
- (void) fprintf(stderr, "strftime(3): cannot format supplied "
- "date/time into buffer of size %u "
- "using: '%s'\n",
- sizeof(res), format);
- }
+void on_sent_media_item_clicked(void* data, Evas_Object* layout, void* event_info)
+{
+ appdata_s* ad = evas_object_data_get(layout, "app_data");
+ char* media_type_str = evas_object_data_get(layout, "media_type");
+ char* media_file = evas_object_data_get(layout, "media_file");
- char time_str[20]={0,};
- snprintf(time_str, sizeof(time_str) - 1, "%s", res);
+ if( access (media_file, F_OK) != -1 ) {
- char temp_time[256] = {0,};
- snprintf(temp_time, sizeof(temp_time), "<font=Tizen:style=Regular color=#000000 align=left><font_size=30>%s</font_size></font>", time_str);
+ } else {
+ media_file = NULL;
+ }
- Evas_Object* send_time = elm_label_add(obj);
- elm_object_text_set(send_time,temp_time);
- evas_object_size_hint_align_set(send_time, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_size_hint_weight_set(send_time, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_object_style_set(send_time, "transparent");
- evas_object_show(send_time);
- elm_object_part_content_set(comp_img_layout, "swallow.chat_send_time", send_time);
- //elm_object_part_content_set(comp_img_layout, "swallow.chat_recv_time", send_time);
+ if (media_file && strlen(media_file) > 0) {
+ app_control_h app_control;
+ int ret = app_control_create(&app_control);
+ if(ret != APP_CONTROL_ERROR_NONE) {
+ show_toast(ad, "Error: Can not load image");
+ return;
+ }
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_VIEW);
+ if (strstr(media_type_str, "video") != NULL) {
+ app_control_set_mime(app_control,"video/*");
+ } else if (strstr(media_type_str, "audio") != NULL) {
+ app_control_set_mime(app_control,"audio/*");
+ } else {
+ app_control_set_mime(app_control,"image/*");
+ }
+ app_control_set_uri(app_control, media_file);
+ app_control_send_launch_request(app_control, NULL, NULL);
+ app_control_destroy(app_control);
+ }
+}
- Evas_Object *status_obj = elm_icon_add(obj);
- evas_object_size_hint_weight_set(status_obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(status_obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
+static Evas_Object* get_image_from_path(const char* path, Evas_Object* parent)
+{
+ if (!path || !parent) {
+ return NULL;
+ }
+ Evas_Object *media_image = elm_image_add(parent);
+ elm_image_aspect_fixed_set(media_image, EINA_FALSE);
+ elm_image_file_set(media_image, path, NULL);
+ evas_object_size_hint_weight_set(media_image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(media_image, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(media_image);
+ return media_image;
+}
- if(msg->msg_state == TG_MESSAGE_STATE_SENDING) {
- elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_SENDING_ICON), NULL);
- } else if(msg->msg_state == TG_MESSAGE_STATE_SENT) {
- elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_SENT_ICON), NULL);
- } else if(msg->msg_state == TG_MESSAGE_STATE_DELIVERED) {
- elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_DELIVERED_ICON), NULL);
- } else if(msg->msg_state == TG_MESSAGE_STATE_RECEIVED) {
+int get_image_size(long long media_id)
+{
+ Eina_List* media_sizes = get_image_sizes_from_db(media_id);
+ int row_count = eina_list_count(media_sizes);
+ int size1 = 0;
+ int size2 = 0;
+ int size3 = 0;
+ int size4 = 0;
+ int media_size = 0;
+ for (int i = 0 ; i < row_count ; i++) {
+ Eina_List* row_vals = eina_list_nth(media_sizes, i);
+ int* temp_size1 = (int*)eina_list_nth(row_vals, 0);
+ if(temp_size1) {
+ size1 = *temp_size1;
+ free(temp_size1);
+ }
+ int* temp_size2 = (int*)eina_list_nth(row_vals, 3);
+ if(temp_size2) {
+ size2 = *temp_size2;
+ free(temp_size2);
+ }
+ int* temp_size3 = (int*)eina_list_nth(row_vals, 6);
+ if(temp_size3) {
+ size3 = *temp_size3;
+ free(temp_size3);
+ }
+ int* temp_size4 = (int*)eina_list_nth(row_vals, 9);
+ if(temp_size4) {
+ size4 = *temp_size4;
+ free(temp_size4);
+ }
+ eina_list_free(row_vals);
+ break;
+ }
+ eina_list_free(media_sizes);
+
+ if (size1 > 0) {
+ media_size = size1;
+ } else if (size2 > 0) {
+ media_size = size2;
+ } else if (size3 > 0) {
+ media_size = size3;
+ } else if (size4 > 0) {
+ media_size = size4;
+ } else {
- } else if(msg->msg_state == TG_MESSAGE_STATE_FAILED) {
- elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_FAILED_ICON), NULL);
- } else if(msg->msg_state == TG_MESSAGE_STATE_READ) {
- elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_READ_ICON), NULL);
- } else if(msg->msg_state == TG_MESSAGE_STATE_UNKNOWN) {
+ }
+ return media_size;
+}
- }
- evas_object_show(status_obj);
- elm_object_part_content_set(comp_img_layout, "status_icon", status_obj);
- evas_object_data_set(comp_img_layout, "chat_list", (void*)chat_list);
- evas_object_data_set(comp_img_layout, "message_id", (void*)message_id);
- evas_object_data_set(comp_img_layout, "item_media", (void*)image);
+void on_media_chat_item_clicked(void* data, Evas_Object *entry, void* event_info)
+{
+ Evas_Object *button = evas_object_data_get(entry, "button_object");
+ if (button) {
+ char* img_state = evas_object_data_get(button, "image_state");
+ if (img_state && strstr(img_state, "download_in_progress") != NULL) {
+ return;
+ }
+ }
+ appdata_s* ad = evas_object_data_get(entry, "app_data");
+ char *temp_media_id = evas_object_data_get(entry, "media_id");
+ char *media_type_str = evas_object_data_get(entry, "media_type");
- ad->loaded_msg_list = eina_list_append(ad->loaded_msg_list, comp_img_layout);
+ if (strstr(media_type_str, "location") != NULL) {
+ char *url = evas_object_data_get(entry, "location_url");
+ launch_app_control(ad, media_type_str, url);
+ return;
+ }
- char *sender_name = NULL;
- if(msg->out) {
- sender_name = replace(ad->current_user_data.print_name, '_', " ");
- } else {
- if (sel_item->use_data->peer_type == TGL_PEER_USER) {
- sender_name = replace(sel_item->use_data->print_name, '_', " ");
- } else if (sel_item->use_data->peer_type == TGL_PEER_CHAT) {
- int from_id = msg->from_id;
- // get name of buddy
- char* buddy_name = get_buddy_name_from_id(from_id);
- if (buddy_name) {
- sender_name = replace(buddy_name, '_', " ");
- free(buddy_name);
- }
- } else {
- sender_name = replace(sel_item->use_data->print_name, '_', " ");
- }
- }
- char temp_name[256] = {0,};
- snprintf(temp_name, sizeof(temp_name), "<font=Tizen:style=Regular color=#f16745 align=left><font_size=30>%s</font_size></font>", sender_name);
+ long long media_id = atoll(temp_media_id);
- if (sender_name) {
- free(sender_name);
- sender_name = NULL;
- }
- Evas_Object* sender_name_lbl = elm_label_add(obj);
- elm_object_text_set(sender_name_lbl,temp_name);
- evas_object_size_hint_align_set(sender_name_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_size_hint_weight_set(sender_name_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_object_style_set(sender_name_lbl, "transparent");
- evas_object_show(sender_name_lbl);
- elm_object_part_content_set(comp_img_layout, "swallow.chat_sender_name", sender_name_lbl);
-
- elm_object_part_content_set(img_layout, "swallow.chat_send_image", comp_img_layout);
- } else {
+ char *media_file = get_media_path_from_db(media_id);
- Evas_Object* comp_img_layout = elm_layout_add(obj);
- elm_layout_file_set(comp_img_layout, edj_path, "chat_recv_image_box");
- evas_object_size_hint_weight_set(comp_img_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(comp_img_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_show(comp_img_layout);
- if (is_blur_image) {
- Eina_List* img_sizes = get_image_sizes_from_db(atoll(msg->media_id));
- int row_count = eina_list_count(img_sizes);
- int size1 = 0;
- int size2 = 0;
- int size3 = 0;
- int size4 = 0;
+ if( access (media_file, F_OK) != -1 ) {
- int width1 = 0;
- int height1 = 0;
+ } else {
+ media_file = NULL;
+ }
- int width2 = 0;
- int height2 = 0;
+ if (!media_file || strlen(media_file) <= 0) {
- int width3 = 0;
- int height3 = 0;
+ Eina_Bool ret = send_request_for_media_downloading(ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id, media_id);
+ if (!ret) {
+ show_toast(ad, "Please check your network connection.");
+ return;
+ }
- int width4 = 0;
- int height4 = 0;
+ // show progress bar
+ char temp_msg[256] = {0,};
+ snprintf(temp_msg, sizeof(temp_msg), "<font=Tizen:style=Bold color=#008000 align=center><font_size=15>%s</font_size></font>", "Downloading...");
+ elm_object_text_set(button, temp_msg);
+ Evas_Object* progressbar = elm_progressbar_add(button);
+ elm_object_style_set(progressbar, "process_small");
+ evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_color_set(progressbar, 255, 255, 255, 255);
+ elm_progressbar_pulse(progressbar, EINA_TRUE);
+ evas_object_show(progressbar);
- int img_size = 0;
- int img_width = 0;
- int img_height = 0;
+ Evas_Object* old_content = elm_object_content_get(button);
+ if (old_content) {
+ evas_object_del(old_content);
+ }
- for (int i = 0 ; i < row_count ; i++) {
- Eina_List* row_vals = eina_list_nth(img_sizes, i);
- int* temp_size1 = (int*)eina_list_nth(row_vals, 0);
- if(temp_size1) {
- size1 = *temp_size1;
- free(temp_size1);
- }
+ elm_object_content_set(button, progressbar);
+ evas_object_data_set(button, "image_state", "download_in_progress");
- int* temp_width1 = (int*)eina_list_nth(row_vals, 1);
- if(temp_width1) {
- width1 = *temp_width1;
- free(temp_width1);
- }
+ } else {
+ launch_app_control(ad, media_type_str, media_file);
+ }
+}
- int* temp_height1 = (int*)eina_list_nth(row_vals, 2);
- if(temp_height1) {
- height1 = *temp_height1;
- free(temp_height1);
- }
+static Evas_Object *get_media_layout_with_play(char *img_path, Evas_Object *parent, Eina_Bool show_play_icon)
+{
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object *rec_video_layout = elm_layout_add(parent);
+ elm_layout_file_set(rec_video_layout, edj_path, "bubble_video_item_layout");
+ evas_object_size_hint_weight_set(rec_video_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(rec_video_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(rec_video_layout);
+
+ Evas_Object *vid_thumb_icon = get_image_from_path(img_path, parent);
+ elm_object_part_content_set(rec_video_layout, "swallow.video_thumb_item", vid_thumb_icon);
+
+ if (show_play_icon) {
+ Evas_Object* play_img = get_image_from_path(ui_utils_get_resource(MEDIA_PLAY_ICON), parent);
+ elm_object_part_content_set(rec_video_layout, "swallow.play_btn", play_img);
+ }
- int* temp_size2 = (int*)eina_list_nth(row_vals, 3);
- if(temp_size2) {
- size2 = *temp_size2;
- free(temp_size2);
- }
+ return rec_video_layout;
+}
+static Evas_Object * item_provider(void *data, Evas_Object *entry, const char *item)
+{
- int* temp_width2 = (int*)eina_list_nth(row_vals, 4);
- if(temp_width2) {
- width2 = *temp_width2;
- free(temp_width2);
- }
+ Evas_Object *layout = NULL;
- int* temp_height2 = (int*)eina_list_nth(row_vals, 5);
- if(temp_height2) {
- height2 = *temp_height2;
- free(temp_height2);
- }
+ if (!strcmp(item, "itemprovider")) {
- int* temp_size3 = (int*)eina_list_nth(row_vals, 6);
- if(temp_size3) {
- size3 = *temp_size3;
- free(temp_size3);
- }
+ Evas_Object* chat_list = data;
+ appdata_s* ad = evas_object_data_get(chat_list, "app_data");
+ int user_id = (int)evas_object_data_get(chat_list, "user_id");
+ int message_id = (int)evas_object_data_get(chat_list, "message_id");
- int* temp_width3 = (int*)eina_list_nth(row_vals, 7);
- if(temp_width3) {
- width3 = *temp_width3;
- free(temp_width3);
- }
+ peer_with_pic_s *sel_item = eina_list_nth(ad->peer_list, user_id);
+ int buddy_id = sel_item->use_data->peer_id;
- int* temp_height3 = (int*)eina_list_nth(row_vals, 8);
- if(temp_height3) {
- height3 = *temp_height3;
- free(temp_height3);
- }
+ char* tablename = get_table_name_from_number(buddy_id);
+ tg_message_s* msg = get_message_from_message_table(message_id, tablename);
+ free(tablename);
+ if (!msg) {
+ return NULL;
+ }
- int* temp_size4 = (int*)eina_list_nth(row_vals, 9);
- if(temp_size4) {
- size4 = *temp_size4;
- free(temp_size4);
- }
+ Evas_Object *item_to_display = NULL;
+ tgl_media_s *media_msg = NULL;
+ if (msg->media_type == tgl_message_media_photo || msg->media_type == tgl_message_media_document) {
- int* temp_width4 = (int*)eina_list_nth(row_vals, 10);
- if(temp_width4) {
- width4 = *temp_width4;
- free(temp_width4);
- }
+ Eina_Bool is_blur_image = EINA_FALSE;
+ char* img_path = NULL;
+ img_path = get_video_thumb_path_from_db(atoll(msg->media_id));
+ if (img_path == NULL || strlen(img_path) == 0 || strstr(img_path, "_null_") != NULL) {
+ img_path = get_media_path_from_db(atoll(msg->media_id));
+ }
+ if (img_path == NULL || strlen(img_path) == 0 || strstr(img_path, "_null_") != NULL) {
+ const char *tmp;
+ tmp = ui_utils_get_resource(BLUR_BG);
+ img_path = strdup(tmp);
+ is_blur_image = EINA_TRUE;
+ }
- int* temp_height4 = (int*)eina_list_nth(row_vals, 11);
- if(temp_height4) {
- height4 = *temp_height4;
- free(temp_height4);
- }
- eina_list_free(row_vals);
- break;
- }
- eina_list_free(img_sizes);
-
- if (size1 > 0) {
- img_size = size1;
- img_width = width1;
- img_height = height1;
- } else if (size2 > 0) {
- img_size = size2;
- img_width = width2;
- img_height = height2;
- } else if (size3 > 0) {
- img_size = size3;
- img_width = width3;
- img_height = height3;
- } else if (size4 > 0) {
- img_size = size4;
- img_width = width4;
- img_height = height4;
- } else {
+ if (msg->media_type == tgl_message_media_document) {
+ media_msg = get_media_details_from_db(atoll(msg->media_id));
- }
+ if (media_msg && strstr(media_msg->doc_type, "video") != NULL) {
+ if (img_path == NULL || strlen(img_path) == 0) {
+ img_path = strdup(ui_utils_get_resource(TG_VIDEO_ICON));
+ }
+ }
+ if (media_msg && strstr(media_msg->doc_type, "audio") != NULL) {
+ if (img_path) {
+ free(img_path);
+ img_path = NULL;
+ }
+ img_path = strdup(ui_utils_get_resource(TG_AUDIO_ICON));
+ }
+ char* media_file = get_media_path_from_db(atoll(msg->media_id));
+ if (!media_file || !strcmp(media_file, "_null_") || strlen(media_file) <= 0 || access(media_file, F_OK) == -1) {
+ is_blur_image = EINA_TRUE;
+ }
+ free(media_file);
- img_size = img_size >> 10; //convert to kbs
+ }
- int max_width = 240;
- int max_height = 400;
+ if (msg->out) {
+ if (msg->media_type == tgl_message_media_photo) {
+ item_to_display = get_image_from_path(img_path, entry);
+ } else {
+ if ((media_msg && strstr(media_msg->doc_type, "video") != NULL )|| (media_msg && strstr(media_msg->doc_type, "audio") != NULL)) {
+ item_to_display = get_media_layout_with_play(img_path, entry, EINA_TRUE);
+ } else {
- while (img_width > max_width) {
- img_width = img_width / 2;
- }
+ }
+ }
+ } else {
+ if (!is_blur_image) {
- while (img_height > max_height) {
- img_height = img_height / 2;
- }
+ if (msg->media_type == tgl_message_media_photo) {
+ item_to_display = get_image_from_path(img_path, entry);
+ evas_object_data_set(entry, "image_object", (void*)item_to_display);
+ } else {
+ if ((media_msg && strstr(media_msg->doc_type, "video") != NULL )|| (media_msg && strstr(media_msg->doc_type, "audio") != NULL)) {
+ item_to_display = get_media_layout_with_play(img_path, entry, EINA_TRUE);
+ } else {
- //evas_object_resize(image, img_width, img_height);
+ }
+ }
- char img_size_str[10];
- sprintf(img_size_str, "%dkbs", img_size);
+ } else {
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object *rec_img_layout = elm_layout_add(entry);
+ elm_layout_file_set(rec_img_layout, edj_path, "bubble_received_media_layout");
+ evas_object_size_hint_weight_set(rec_img_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(rec_img_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(rec_img_layout);
+ Evas_Object *img_item = NULL;
+
+
+ if (msg->media_type == tgl_message_media_photo) {
+ img_item = get_image_from_path(img_path, entry);
+ } else {
+ if ((media_msg && strstr(media_msg->doc_type, "video") != NULL )|| (media_msg && strstr(media_msg->doc_type, "audio") != NULL)) {
+ img_item = get_media_layout_with_play(img_path, entry, EINA_FALSE);
+ } else {
+ }
+ }
+ elm_object_part_content_set(rec_img_layout, "swallow.image_item", img_item);
- Evas_Object* img_info_layout = elm_layout_add(obj);
- elm_layout_file_set(img_info_layout, edj_path, "chat_recv_image_info_box");
- evas_object_size_hint_weight_set(img_info_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(img_info_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_show(img_info_layout);
+ int media_size = 0;
+ if (msg->media_type == tgl_message_media_photo) {
+ media_size = get_image_size(atoll(msg->media_id));
+ } else {
+ if (media_msg && strstr(media_msg->doc_type, "video") != NULL) {
+ media_size = get_media_size_from_db(atoll(msg->media_id));
+ } else if (media_msg && strstr(media_msg->doc_type, "audio") != NULL) {
+ media_size = get_media_size_from_db(atoll(msg->media_id));
+ } else {
+ }
+ }
- Evas_Object* img_size_lbl = elm_label_add(obj);
- elm_object_style_set(img_size_lbl, "transparent");
+ int media_size_kbs = (media_size < (1 << 20)); //convert to kbs
+ char media_size_str[10] = { 0, };
+ if (media_size_kbs > 0) {
+ sprintf(media_size_str, "%dKiB", media_size_kbs);
+ } else {
+ sprintf(media_size_str, "%dB", media_size);
+ }
- char temp_size[256] = {0,};
- snprintf(temp_size, sizeof(temp_size), "<font=Tizen:style=Regular color=#ffffff align=left><font_size=30>%s</br></font_size></font>", img_size_str);
- Eina_Strbuf *buf = eina_strbuf_new();
- eina_strbuf_append(buf, temp_size);
- elm_object_text_set(img_size_lbl, eina_strbuf_string_get(buf));
- eina_strbuf_free(buf);
- evas_object_show(img_size_lbl);
+ Evas_Object *size_btn = elm_button_add(entry);
+ char temp_msg[256] = {0,};
+ snprintf(temp_msg, sizeof(temp_msg), "<font=Tizen:style=Bold color=#008000 align=center><font_size=30>%s</font_size></font>", media_size_str);
+ elm_object_text_set(size_btn, temp_msg);
+ evas_object_size_hint_weight_set(size_btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(size_btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(size_btn);
- Evas_Object* download_img = create_image_object_from_file(ui_utils_get_resource(MEDIA_DOWNLOAD_ICON), obj);
- elm_image_resizable_set(download_img, EINA_TRUE, EINA_TRUE);
- elm_image_smooth_set(download_img, EINA_FALSE);
- elm_image_aspect_fixed_set(download_img, EINA_TRUE);
- elm_image_fill_outside_set(download_img, EINA_TRUE);
- elm_image_editable_set(download_img, EINA_TRUE);
+ evas_object_data_set(size_btn, "image_state", "ready_to_download");
+ Evas_Object* download_img = get_image_from_path(ui_utils_get_resource(MEDIA_DOWNLOAD_ICON), entry);
+ elm_object_content_set(size_btn, download_img);
- elm_object_part_content_set(img_info_layout, "swallow.chat_recv_image,size", img_size_lbl);
- elm_object_part_content_set(img_info_layout, "swallow.chat_recv_image,download", download_img);
+ elm_object_part_content_set(rec_img_layout, "swallow.download_btn", size_btn);
- evas_object_data_set(image, "image_info_layout", (void*)(img_info_layout));
+ evas_object_data_set(entry, "image_object", (void*)img_item);
+ evas_object_data_set(entry, "button_object", (void*)size_btn);
+ evas_object_data_set(entry, "image_size", (void*)strdup(media_size_str));
+ ad->loaded_msg_list = eina_list_append(ad->loaded_msg_list, entry);
- elm_object_part_content_set(layout, "swallow.image_info", img_info_layout);
- }
+ item_to_display = rec_img_layout;
+ }
+ }
- elm_object_part_content_set(comp_img_layout, "swallow.chat_recv_image", image);
+ if (img_path) {
+ free(img_path);
+ img_path = NULL;
+ }
+ // delete media details
- elm_object_part_content_set(layout, "swallow.img_bg", img_layout);
+ }
+ evas_object_data_set(entry, "chat_list", (void*)chat_list);
+ evas_object_data_set(entry, "message_id", (void*)message_id);
+ evas_object_data_set(entry, "app_data", (void*)ad);
- time_t t = msg->date;
- const char *format = "%I:%M %P";
- struct tm lt;
- char res[32];
- (void) localtime_r(&t, <);
- if (strftime(res, sizeof(res), format, <) == 0) {
- (void) fprintf(stderr, "strftime(3): cannot format supplied "
- "date/time into buffer of size %u "
- "using: '%s'\n",
- sizeof(res), format);
- }
+ if (msg->media_type == tgl_message_media_photo) {
+ evas_object_data_set(entry, "media_type", (void*)strdup("image"));
+ } else if (msg->media_type == tgl_message_media_geo) {
+ evas_object_data_set(entry, "media_type", (void*)strdup("location"));
+ } else {
+ if (media_msg && strstr(media_msg->doc_type, "video") != NULL) {
+ evas_object_data_set(entry, "media_type", (void*)strdup("video"));
+ } else if (media_msg && strstr(media_msg->doc_type, "audio") != NULL) {
+ evas_object_data_set(entry, "media_type", (void*)strdup("audio"));
+ } else {
- char time_str[20]={0,};
- snprintf(time_str, sizeof(time_str) - 1, "%s", res);
+ }
+ }
- char temp_time[256] = {0,};
- snprintf(temp_time, sizeof(temp_time), "<font=Tizen:style=Regular color=#000000 align=left><font_size=30>%s</font_size></font>", time_str);
+ evas_object_data_set(entry, "media_id", (void*)strdup(msg->media_id));
- Evas_Object* send_time = elm_label_add(obj);
- elm_object_text_set(send_time,temp_time);
- evas_object_size_hint_align_set(send_time, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_size_hint_weight_set(send_time, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_object_style_set(send_time, "transparent");
- evas_object_show(send_time);
- elm_object_part_content_set(comp_img_layout, "swallow.chat_recv_time", send_time);
+ evas_object_smart_callback_add(entry, "clicked", on_media_chat_item_clicked, NULL);
+ if (item_to_display) {
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ layout = elm_layout_add(entry);
+ elm_layout_file_set(layout, edj_path, "bubble_media_layout");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(layout);
+ elm_object_part_content_set(layout, "swallow.media_item", item_to_display);
+ }
- evas_object_data_set(image, "chat_list", (void*)chat_list);
- evas_object_data_set(image, "message_id", (void*)message_id);
- evas_object_data_set(image, "item_media", (void*)image);
- evas_object_data_set(image, "app_data", (void*)ad);
- evas_object_data_set(image, "media_id", (void*)strdup(msg->media_id));
- evas_object_data_set(image, "image_path", (void*)(img_path));
+ if(msg->message) {
+ free(msg->message);
+ msg->message = NULL;
+ }
+ if(msg->media_id) {
+ free(msg->media_id);
+ msg->media_id = NULL;
+ }
+ free(msg);
+ free_media_details(media_msg);
+ }
+
+ return layout;
+}
- ad->loaded_msg_list = eina_list_append(ad->loaded_msg_list, image);
+Evas_Object* on_message_item_content_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ Evas_Object *layout;
+ layout = elm_layout_add(obj);
+ if (!strcmp(part, "elm.icon.entry")) {
+ int message_id = (int)data;
+ Evas_Object* chat_list = obj;
+ appdata_s* ad = evas_object_data_get(chat_list, "app_data");
+ int user_id = (int)evas_object_data_get(chat_list, "user_id");
- evas_object_smart_callback_add(image, "clicked", on_chat_media_item_clicked, (void*)(msg->media_id));
+ evas_object_data_set(chat_list, "message_id", data);
- char *sender_name = NULL;
- if(msg->out) {
- sender_name = replace(ad->current_user_data.print_name, '_', " ");
- } else {
- if (sel_item->use_data->peer_type == TGL_PEER_USER) {
- sender_name = replace(sel_item->use_data->print_name, '_', " ");
- } else if (sel_item->use_data->peer_type == TGL_PEER_CHAT) {
- int from_id = msg->from_id;
- // get name of buddy
- char* buddy_name = get_buddy_name_from_id(from_id);
- if (buddy_name) {
- sender_name = replace(buddy_name, '_', " ");
- free(buddy_name);
- }
- } else {
- sender_name = replace(sel_item->use_data->print_name, '_', " ");
- }
- }
+ peer_with_pic_s *sel_item = eina_list_nth(ad->peer_list, user_id);
+ int buddy_id = sel_item->use_data->peer_id;
- char temp_name[256] = {0,};
- snprintf(temp_name, sizeof(temp_name), "<font=Tizen:style=Regular color=#f16745 align=left><font_size=30>%s</font_size></font>", sender_name);
+ char* tablename = get_table_name_from_number(buddy_id);
+ tg_message_s* msg = get_message_from_message_table(message_id, tablename);
+ //Eina_Bool is_blur_image = EINA_FALSE;
- if (sender_name) {
- free(sender_name);
- sender_name = NULL;
- }
- Evas_Object* sender_name_lbl = elm_label_add(obj);
- elm_object_text_set(sender_name_lbl,temp_name);
- evas_object_size_hint_align_set(sender_name_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_size_hint_weight_set(sender_name_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_object_style_set(sender_name_lbl, "transparent");
- evas_object_show(sender_name_lbl);
- elm_object_part_content_set(comp_img_layout, "swallow.chat_sender_name", sender_name_lbl);
+ if (msg) {
+ if (msg->unread) {
+ msg->unread = 0;
+ update_msg_into_db(msg, tablename);
+ ad->is_last_msg_changed = EINA_TRUE;
+ }
+ if (msg->out) {
- elm_object_part_content_set(img_layout, "swallow.chat_send_image", comp_img_layout);
+ } else {
+ // update un read
- }
- }
+ }
+ if (msg->service) {
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
- if(msg->message) {
- free(msg->message);
- msg->message = NULL;
- }
+ layout = elm_layout_add(obj);
+ elm_layout_file_set(layout, edj_path, "chat_service_item_box");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(layout);
- if(msg->media_id) {
- free(msg->media_id);
- msg->media_id = NULL;
- }
+ Evas_Object* ser_lbl = elm_label_add(obj);
+ char temp_msg[4*256] = {0,};
+ snprintf(temp_msg, sizeof(temp_msg), "<font=Tizen:style=Bold color=#008000 align=center><font_size=30>%s</font_size></font>", msg->message);
+ elm_object_text_set(ser_lbl, temp_msg);
+ elm_label_ellipsis_set(ser_lbl, EINA_TRUE);
+ evas_object_resize(ser_lbl, 200, 15);
+ evas_object_show(ser_lbl);
- free(msg);
+ elm_object_part_content_set(layout, "swallow.chat_service_text", ser_lbl);
return layout;
-
}
Evas_Object* entry = elm_entry_add(obj);
elm_entry_context_menu_disabled_set(entry, EINA_TRUE);
//elm_entry_magnifier_disabled_set(entry, EINA_TRUE);
+ elm_entry_selection_handler_disabled_set(entry, EINA_TRUE);
char *sender_name = NULL;
if(msg->out) {
elm_layout_theme_set(layout, "layout", "bubble", "sentmessage1/default");
elm_object_style_set(entry, "sentmessage1");
- sender_name = replace(ad->current_user_data.print_name, '_', " ");
+ sender_name = replace(ad->current_user_data->print_name, '_', " ");
} else {
elm_layout_theme_set(layout, "layout", "bubble", "readmessage1/default");
elm_object_style_set(entry, "readmessage1");
eina_strbuf_append(buf, temp_msg);
elm_entry_entry_set(entry, eina_strbuf_string_get(buf));
eina_strbuf_free(buf);
- } else if(msg->media_type == tgl_message_media_photo) {
-
- } else if(msg->media_type == tgl_message_media_document) {
+ } else if(msg->media_type == tgl_message_media_photo || msg->media_type == tgl_message_media_document) {
+ elm_entry_item_provider_append(entry, item_provider, chat_list);
+ tgl_media_s *media_msg = get_media_details_from_db(atoll(msg->media_id));
+ if (msg->out) {
+ eina_strbuf_append(buf, "<item size=147x147 vsize=full href=itemprovider></item>");
+ } else {
+ eina_strbuf_append(buf, "<item size=100x147 vsize=full href=itemprovider></item>");
+ }
+ free_media_details(media_msg);
+ elm_entry_entry_set(entry, eina_strbuf_string_get(buf));
+ eina_strbuf_free(buf);
} else if(msg->media_type == tgl_message_media_geo) {
+ tgl_media_s *media_msg = get_media_details_from_db(atoll(msg->media_id));
+ char loc_url[4*256] = {0,};
+ if (media_msg) {
+ snprintf(loc_url, sizeof(loc_url), "https://maps.google.com/?q=%s,%s", media_msg->latitude, media_msg->longitude);
+ char temp_msg[4*256] = {0,};
+ snprintf(temp_msg, sizeof(temp_msg), "<font=Tizen:style=Italic|underline color=#0000FF align=left><font_size=12>%s</font_size></font>", loc_url);
+ eina_strbuf_append(buf, temp_msg);
+ elm_entry_entry_set(entry, eina_strbuf_string_get(buf));
+ eina_strbuf_free(buf);
+ }
+
+ free_media_details(media_msg);
+ evas_object_data_set(entry, "media_type", (void*)strdup("location"));
+ evas_object_data_set(entry, "location_url", (void*)strdup(loc_url));
+ evas_object_smart_callback_add(entry, "clicked", on_media_chat_item_clicked, NULL);
+
} else if(msg->media_type == tgl_message_media_contact) {
+ tgl_media_s *media_msg = get_media_details_from_db(atoll(msg->media_id));
+
+ if (media_msg) {
+ char temp_msg[4*256] = {0,};
+ snprintf(temp_msg, sizeof(temp_msg), "<font=Tizen:style=Italic|underline color=#000000 align=left><font_size=12>%s %s, %s</font_size></font>", media_msg->first_name, media_msg->last_name, media_msg->phone_no);
+ eina_strbuf_append(buf, temp_msg);
+ elm_entry_entry_set(entry, eina_strbuf_string_get(buf));
+ eina_strbuf_free(buf);
+ free_media_details(media_msg);
+ }
+
} else if(msg->media_type == tgl_message_media_unsupported) {
} else if(msg->media_type == tgl_message_media_photo_encr) {
free(msg);
}
+#if 0
+ if (chat_list) {
+ int size = elm_genlist_items_count(chat_list);
+ if (size > 0) {
+ Elm_Object_Item *litem = elm_genlist_nth_item_get(chat_list, size -1);
+ elm_genlist_item_show(litem, ELM_GENLIST_ITEM_SCROLLTO_TOP);
+ }
+ }
+#endif
}
-
return layout;
}
if (!ad) {
return;
}
+ peer_with_pic_s* pic_peer_item = ad->peer_in_cahtting_data;
+ tg_peer_info_s* peer_item = pic_peer_item->use_data;
+ char* tablename = get_table_name_from_number(peer_item->peer_id);
+ tg_message_s* msg = get_message_from_message_table(message_id, tablename);
+ if (msg) {
+ // update peer table
+ if (peer_item) {
+ peer_item->last_msg_id = msg->msg_id;
+ peer_item->last_msg_date = msg->date;
+ insert_or_update_peer_into_database(peer_item);
+ }
+
+ if(msg->message) {
+ free(msg->message);
+ msg->message = NULL;
+ }
+
+ if(msg->media_id) {
+ free(msg->media_id);
+ msg->media_id = NULL;
+ }
+
+ free(msg);
+ }
+ free(tablename);
Evas_Object* chat_list = evas_object_data_get(ad->nf, "chat_list");
static Elm_Genlist_Item_Class itc;
if (ad->loaded_msg_list && eina_list_count(ad->loaded_msg_list) > 0) {
for (int i = eina_list_count(ad->loaded_msg_list) - 1 ; i >= 0; i--) {
- Evas_Object* layout = eina_list_nth(ad->loaded_msg_list, i);
- if (layout) {
- char* media_id_str = evas_object_data_get(layout, "media_id");
-
- if (media_id_str) {
- long long lmedia_id = atoll(media_id_str);
- if (media_id == lmedia_id) {
- Evas_Object* img_obj = evas_object_data_get(layout, "item_media");
- if (img_obj) {
-
-#if 0
- Eina_List* img_sizes = get_image_sizes_from_db(media_id);
- int row_count = eina_list_count(img_sizes);
- int size1 = 0;
- int size2 = 0;
- int size3 = 0;
- int size4 = 0;
-
- int width1 = 0;
- int height1 = 0;
-
- int width2 = 0;
- int height2 = 0;
-
- int width3 = 0;
- int height3 = 0;
-
- int width4 = 0;
- int height4 = 0;
-
-
- int img_size = 0;
- int img_width = 0;
- int img_height = 0;
-
- for (int i = 0 ; i < row_count ; i++) {
- Eina_List* row_vals = eina_list_nth(img_sizes, i);
- int* temp_size1 = (int*)eina_list_nth(row_vals, 0);
- if(temp_size1) {
- size1 = *temp_size1;
- free(temp_size1);
- }
-
- int* temp_width1 = (int*)eina_list_nth(row_vals, 1);
- if(temp_width1) {
- width1 = *temp_width1;
- free(temp_width1);
- }
-
- int* temp_height1 = (int*)eina_list_nth(row_vals, 2);
- if(temp_height1) {
- height1 = *temp_height1;
- free(temp_height1);
- }
-
- int* temp_size2 = (int*)eina_list_nth(row_vals, 3);
- if(temp_size2) {
- size2 = *temp_size2;
- free(temp_size2);
- }
-
- int* temp_width2 = (int*)eina_list_nth(row_vals, 4);
- if(temp_width2) {
- width2 = *temp_width2;
- free(temp_width2);
- }
+ Evas_Object* entry = eina_list_nth(ad->loaded_msg_list, i);
+ if (entry) {
- int* temp_height2 = (int*)eina_list_nth(row_vals, 5);
- if(temp_height2) {
- height2 = *temp_height2;
- free(temp_height2);
- }
+ char* media_type_str = evas_object_data_get(entry, "media_type");
+ char* media_id_str = evas_object_data_get(entry, "media_id");
+ char* media_size_str = evas_object_data_get(entry, "image_size");
+ Evas_Object *img_item = evas_object_data_get(entry, "image_object");
+ Evas_Object *size_btn = evas_object_data_get(entry, "button_object");
- int* temp_size3 = (int*)eina_list_nth(row_vals, 6);
- if(temp_size3) {
- size3 = *temp_size3;
- free(temp_size3);
- }
+ if (media_id_str) {
- int* temp_width3 = (int*)eina_list_nth(row_vals, 7);
- if(temp_width3) {
- width3 = *temp_width3;
- free(temp_width3);
- }
+ long long lmedia_id = atoll(media_id_str);
- int* temp_height3 = (int*)eina_list_nth(row_vals, 8);
- if(temp_height3) {
- height3 = *temp_height3;
- free(temp_height3);
+ if (media_id == lmedia_id) {
+ if (img_item) {
+
+ if (strstr(file_path, "failed_to_load") != NULL) {
+ // download failed.
+ if (size_btn) {
+
+ Evas_Object* progress = elm_object_content_get(size_btn);
+ if (progress) {
+ evas_object_del(progress);
+ }
+ Evas_Object* download_img = get_image_from_path(ui_utils_get_resource(MEDIA_DOWNLOAD_ICON), size_btn);
+ elm_object_content_set(size_btn, download_img);
+ evas_object_data_set(size_btn, "image_state", "ready_to_download");
+ char temp_msg[256] = {0,};
+ snprintf(temp_msg, sizeof(temp_msg), "<font=Tizen:style=Bold color=#008000 align=center><font_size=30>%s</font_size></font>", media_size_str);
+ elm_object_text_set(size_btn, temp_msg);
}
- int* temp_size4 = (int*)eina_list_nth(row_vals, 9);
- if(temp_size4) {
- size4 = *temp_size4;
- free(temp_size4);
- }
- int* temp_width4 = (int*)eina_list_nth(row_vals, 10);
- if(temp_width4) {
- width4 = *temp_width4;
- free(temp_width4);
+ } else {
+ if (size_btn) {
+ evas_object_del(size_btn);
}
- int* temp_height4 = (int*)eina_list_nth(row_vals, 11);
- if(temp_height4) {
- height4 = *temp_height4;
- free(temp_height4);
+ if ((strstr(media_type_str, "video") != NULL) || (strstr(media_type_str, "audio") != NULL)) {
+ Evas_Object* play_img = get_image_from_path(ui_utils_get_resource(MEDIA_PLAY_ICON), img_item);
+ elm_object_part_content_set(img_item, "swallow.play_btn", play_img);
+ } else if (strstr(media_type_str, "image") != NULL) {
+ elm_image_file_set(img_item, file_path, NULL);
}
-
- eina_list_free(row_vals);
- break;
}
- eina_list_free(img_sizes);
-
- if (size1 > 0) {
- img_size = size1;
- img_width = width1;
- img_height = height1;
- } else if (size2 > 0) {
- img_size = size2;
- img_width = width2;
- img_height = height2;
- } else if (size3 > 0) {
- img_size = size3;
- img_width = width3;
- img_height = height3;
- } else if (size4 > 0) {
- img_size = size4;
- img_width = width4;
- img_height = height4;
- } else {
-
- }
-
- img_size = img_size >> 10; //convert to kbs
-
- int max_width = 240;
- int max_height = 100;
- while (img_width > max_width) {
- img_width = img_width / 2;
- }
-
- while (img_height > max_height) {
- img_height = img_height / 2;
- }
- evas_object_resize(img_obj, img_width, img_height);
-#endif
-
- Evas_Object* img_info_layout = evas_object_data_get(img_obj, "image_info_layout");
- Evas_Object* progressbar = elm_object_part_content_get(img_info_layout, "swallow.chat_recv_image,progress");
- evas_object_del(progressbar);
- elm_image_file_set(img_obj, file_path, NULL);
}
+ break;
}
+
}
}
}
}
}
+//elm_object_part_content_set(comp_img_layout, "swallow.chat_send_image", image);
+
+void on_video_thumb_download_completed(appdata_s* ad, int buddy_id, long long media_id, const char* file_path)
+{
+ on_media_download_completed(ad, buddy_id, media_id, file_path);
+}
void on_text_message_state_changed(appdata_s* ad, tg_message_s *msg, int type_of_chat)
{
if (!ad)
return;
-
+#if 0
peer_with_pic_s* pic_peer_item = ad->peer_in_cahtting_data;
if (pic_peer_item) {
tg_peer_info_s* peer_item = pic_peer_item->use_data;
insert_or_update_peer_into_database(peer_item);
}
}
-
+#endif
if (ad->loaded_msg_list && eina_list_count(ad->loaded_msg_list) > 0) {
for (int i = eina_list_count(ad->loaded_msg_list) - 1 ; i >= 0; i--) {
Evas_Object* entry = eina_list_nth(ad->loaded_msg_list, i);
int message_id = (int)evas_object_data_get(entry, "message_id");
if (message_id == msg->msg_id || message_id == msg->unique_id) {
+ evas_object_data_set(entry, "media_id", (void*)strdup(msg->media_id));
+ evas_object_data_set(entry, "message_id", (void*)message_id);
+
Evas_Object* status_obj = elm_object_part_content_get(entry, "status_icon");
if (status_obj) {
if(msg->msg_state == TG_MESSAGE_STATE_SENDING) {
}
}
+void add_date_item_to_chat(void *data)
+{
+ Evas_Object* chat_list = data;
+ appdata_s* ad = evas_object_data_get(chat_list, "app_data");
+ int user_id = (int)evas_object_data_get(chat_list, "user_id");
+
+ peer_with_pic_s *sel_item = eina_list_nth(ad->peer_list, user_id);
+
+ char* msg_table = get_table_name_from_number(sel_item->use_data->peer_id);
+ int msg_id = insert_current_date_to_table(msg_table);
+ free(msg_table);
+
+ if (msg_id > 0) {
+ // send request to service
+
+ static Elm_Genlist_Item_Class itc;
+ itc.item_style = "entry";
+ itc.func.text_get = NULL;
+ itc.func.content_get = on_message_item_content_get_cb;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+ Elm_Object_Item* item = elm_genlist_item_append(chat_list, &itc, (void *)msg_id, NULL, ELM_GENLIST_ITEM_NONE, on_text_message_clicked, (void*)msg_id);
+ elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
+ ad->is_last_msg_changed = EINA_TRUE;
+ }
+
+}
+
static void on_text_message_send_clicked(void *data, Evas_Object *obj, void *event_info)
{
Evas_Object* chat_list = data;
if (!text_to_send || (strlen(text_to_send) == 0))
return;
+ add_date_item_to_chat(data);
+
int unique_id = time(NULL);
tg_message_s msg;
msg.msg_id = unique_id;
- msg.from_id = ad->current_user_data.user_id.id;
+ msg.from_id = ad->current_user_data->user_id.id;
msg.date = time(NULL);
msg.flags = 0;
msg.fwd_date = 0;
msg.msg_state = TG_MESSAGE_STATE_SENDING;
char* msg_table = get_table_name_from_number(msg.to_id);
-
insert_msg_into_db(&msg, msg_table, unique_id);
free(msg_table);
+ peer_with_pic_s* pic_peer_item = ad->peer_in_cahtting_data;
+ if (pic_peer_item) {
+ tg_peer_info_s* peer_item = pic_peer_item->use_data;
+ // update peer table
+ if (peer_item) {
+ peer_item->last_msg_id = msg.msg_id;
+ peer_item->last_msg_date = msg.date;
+ insert_or_update_peer_into_database(peer_item);
+ }
+ }
+
// send request to service
- send_request_for_message_transport(ad->service_client, sel_item->use_data->peer_id, msg.msg_id, tgl_message_media_none, text_to_send, sel_item->use_data->peer_type);
+ send_request_for_message_transport(ad, ad->service_client, sel_item->use_data->peer_id, msg.msg_id, tgl_message_media_none, text_to_send, sel_item->use_data->peer_type);
static Elm_Genlist_Item_Class itc;
itc.item_style = "entry";
}
} else if (type_of_chat == TGL_PEER_CHAT) {
+
+ Evas_Object *profile_time = evas_object_data_get(ad->nf, "profile_time");
+ if (!profile_time) {
+ return;
+ }
tg_chat_info_s* chat_info = get_chat_info(buddy_id);
+ if (!chat_info) {
+ char status_str[256]={0,};
+ snprintf(status_str, sizeof(status_str) - 1, "<font=Tizen:style=Italic color=#000000 align=left><font_size=30>Unidentified.</font_size></font>");
+ elm_object_text_set(profile_time,status_str);
+ return;
+ }
- int user_list_size = chat_info->users_num;
+ int user_list_size = chat_info->user_list_size;
int online_members = 0;
for (int i = 0; i < user_list_size; i++) {
}
- Evas_Object* profile_time = evas_object_data_get(ad->nf, "profile_time");
+
if (online_members == 0) {
char status_str[256]={0,};
snprintf(status_str, sizeof(status_str) - 1, "<font=Tizen:style=Italic color=#000000 align=left><font_size=30>%d members</font_size></font>", user_list_size);
}
}
-
-
}
}
}
-
-void send_image_message_to_buddy(void *data, const char* file_path)
+void send_contact_message_to_buddy(void *data, char *first_name, char *last_name, char *phone_number)
{
Evas_Object* chat_list = data;
appdata_s* ad = evas_object_data_get(chat_list, "app_data");
int user_id = (int)evas_object_data_get(chat_list, "user_id");
-
+ add_date_item_to_chat(data);
peer_with_pic_s *sel_item = eina_list_nth(ad->peer_list, user_id);
int unique_id = time(NULL);
tg_message_s msg;
msg.msg_id = unique_id;
- msg.from_id = ad->current_user_data.user_id.id;
+ msg.from_id = ad->current_user_data->user_id.id;
msg.date = time(NULL);
msg.flags = 0;
msg.fwd_date = 0;
msg.unique_id = unique_id;
msg.message = "";
msg.message_len = 0;
- msg.media_type = tgl_message_media_photo;
+ msg.media_type = tgl_message_media_contact;
msg.media_id = strdup(unique_id_str);
msg.out = 1;
msg.service = 0;
msg.unread = 0;
msg.msg_state = TG_MESSAGE_STATE_SENDING;
+
char* msg_table = get_table_name_from_number(msg.to_id);
+ insert_msg_into_db(&msg, msg_table, unique_id);
+ int img_width = 0;
+ int img_height = 0;
+ int media_size = 0;
+ insert_media_info_to_db(&msg, NULL, img_width, img_height, media_size, NULL, NULL, first_name, last_name, phone_number);
+
+ free(msg_table);
+
+ // send request to service
+ send_request_for_media_transport(ad, ad->service_client, sel_item->use_data->peer_id, msg.msg_id, unique_id, tgl_message_media_contact, NULL, sel_item->use_data->peer_type);
+
+ static Elm_Genlist_Item_Class itc;
+ itc.item_style = "entry";
+ itc.func.text_get = NULL;
+ itc.func.content_get = on_message_item_content_get_cb;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+ Elm_Object_Item* item = elm_genlist_item_append(chat_list, &itc, (void*)unique_id, NULL, ELM_GENLIST_ITEM_NONE, on_list_media_item_clicked, (void*)unique_id);
+ elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
+ free(msg.media_id);
+}
+
+void send_location_message_to_buddy(void *data, char *latitude, char *longitude)
+{
+ Evas_Object* chat_list = data;
+ appdata_s* ad = evas_object_data_get(chat_list, "app_data");
+ int user_id = (int)evas_object_data_get(chat_list, "user_id");
+ add_date_item_to_chat(data);
+ peer_with_pic_s *sel_item = eina_list_nth(ad->peer_list, user_id);
+
+ int unique_id = time(NULL);
+ char unique_id_str[50];
+ sprintf(unique_id_str, "%d", unique_id);
+
+ tg_message_s msg;
+ msg.msg_id = unique_id;
+ msg.from_id = ad->current_user_data->user_id.id;
+ msg.date = time(NULL);
+ msg.flags = 0;
+ msg.fwd_date = 0;
+ msg.fwd_from_id= 0;
+ msg.fwd_from_id = 0;
+ msg.unique_id = unique_id;
+ msg.message = "";
+ msg.message_len = 0;
+ msg.media_type = tgl_message_media_geo;
+ msg.media_id = strdup(unique_id_str);
+ msg.out = 1;
+ msg.service = 0;
+ msg.to_id = sel_item->use_data->peer_id;
+ msg.unread = 0;
+ msg.msg_state = TG_MESSAGE_STATE_SENDING;
+
+ char* msg_table = get_table_name_from_number(msg.to_id);
insert_msg_into_db(&msg, msg_table, unique_id);
+ int img_width = 0;
+ int img_height = 0;
+ int media_size = 0;
+ insert_media_info_to_db(&msg, NULL, img_width, img_height, media_size, latitude, longitude, NULL, NULL, NULL);
+
+ free(msg_table);
+
+ // send request to service
+ send_request_for_media_transport(ad, ad->service_client, sel_item->use_data->peer_id, msg.msg_id, unique_id, tgl_message_media_geo, NULL, sel_item->use_data->peer_type);
+
+ static Elm_Genlist_Item_Class itc;
+ itc.item_style = "entry";
+ itc.func.text_get = NULL;
+ itc.func.content_get = on_message_item_content_get_cb;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+ Elm_Object_Item* item = elm_genlist_item_append(chat_list, &itc, (void*)unique_id, NULL, ELM_GENLIST_ITEM_NONE, on_list_media_item_clicked, (void*)unique_id);
+ elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
+ free(msg.media_id);
+}
+
+void send_media_message_to_buddy(void *data, const char* file_path, enum tgl_message_media_type file_type)
+{
+ Evas_Object* chat_list = data;
+ appdata_s* ad = evas_object_data_get(chat_list, "app_data");
+ int user_id = (int)evas_object_data_get(chat_list, "user_id");
+ add_date_item_to_chat(data);
+ peer_with_pic_s *sel_item = eina_list_nth(ad->peer_list, user_id);
+
+ int unique_id = time(NULL);
+
+ char unique_id_str[50];
+ sprintf(unique_id_str, "%d", unique_id);
- Evas_Object* img = create_image_object_from_file(file_path, chat_list);
+ tg_message_s msg;
+ msg.msg_id = unique_id;
+ msg.from_id = ad->current_user_data->user_id.id;
+ msg.date = time(NULL);
+ msg.flags = 0;
+ msg.fwd_date = 0;
+ msg.fwd_from_id= 0;
+ msg.fwd_from_id = 0;
+ msg.unique_id = unique_id;
+ msg.message = "";
+ msg.message_len = 0;
+ msg.media_type = file_type;
+ msg.media_id = strdup(unique_id_str);
+ msg.out = 1;
+ msg.service = 0;
+ msg.to_id = sel_item->use_data->peer_id;
+ msg.unread = 0;
+ msg.msg_state = TG_MESSAGE_STATE_SENDING;
+ char* msg_table = get_table_name_from_number(msg.to_id);
+ insert_msg_into_db(&msg, msg_table, unique_id);
int img_width = 0;
int img_height = 0;
- elm_image_object_size_get(img, &img_width, &img_height);
- struct stat st;
- stat(file_path, &st);
- int img_size = st.st_size;
- evas_object_del(img);
+ int media_size = 0;
+ if (file_type == tgl_message_media_photo) {
+ Evas_Object* img = create_image_object_from_file(file_path, chat_list);
+ elm_image_object_size_get(img, &img_width, &img_height);
+ struct stat st;
+ stat(file_path, &st);
+ media_size = st.st_size;
+ evas_object_del(img);
+ }
- insert_media_info_to_db(&msg, (char*)file_path, img_width, img_height, img_size);
+ insert_media_info_to_db(&msg, (char*)file_path, img_width, img_height, media_size, NULL, NULL , NULL, NULL, NULL);
free(msg_table);
// send request to service
- send_request_for_media_transport(ad->service_client, sel_item->use_data->peer_id, msg.msg_id, unique_id, tgl_message_media_photo, file_path, sel_item->use_data->peer_type);
+ send_request_for_media_transport(ad, ad->service_client, sel_item->use_data->peer_id, msg.msg_id, unique_id, file_type, file_path, sel_item->use_data->peer_type);
static Elm_Genlist_Item_Class itc;
itc.item_style = "entry";
Elm_Object_Item* item = elm_genlist_item_append(chat_list, &itc, (void*)unique_id, NULL, ELM_GENLIST_ITEM_NONE, on_list_media_item_clicked, (void*)unique_id);
elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
free(msg.media_id);
+ ad->is_last_msg_changed = EINA_TRUE;
}
-
+static Eina_Bool on_timer_expired(void *data)
+{
+ Elm_Object_Item* last_item = data;
+ if (last_item) {
+ elm_genlist_item_show(last_item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
+ }
+ return ECORE_CALLBACK_CANCEL;
+}
void load_chat_history(Evas_Object* chat_list)
{
col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_ID);
Eina_List* vals = get_values_from_table_sync(tablename, col_names, col_types, NULL);
-
+ Elm_Object_Item* last_item = NULL;
if(!vals) {
} else {
itc.func.state_get = NULL;
itc.func.del = NULL;
Elm_Object_Item* item = elm_genlist_item_append(chat_list, &itc, (void *)message_id, NULL, ELM_GENLIST_ITEM_NONE, on_list_media_item_clicked, (void*)message_id);
+ last_item = item;
elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_TOP);
eina_list_free(row_vals);
}
eina_list_free(vals);
}
+ Ecore_Timer *timer = NULL;
+ timer = ecore_timer_add(5, on_timer_expired, last_item);
+
free(tablename);
}
int array_length = 0;
app_control_get_extra_data_array(reply, APP_CONTROL_DATA_SELECTED, &path_arryay, &array_length);
+ char* mime_type = NULL;
+ app_control_get_mime(reply, &mime_type);
+
+ for(int i = 0 ; i < array_length ; i++) {
+ file_path = strdup(path_arryay[i]);
+ send_media_message_to_buddy(chat_list, file_path, tgl_message_media_photo);
+ free(file_path);
+ break;
+ }
+ }
+}
+
+void on_location_app_control_reply_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+{
+ Evas_Object* chat_list = user_data;
+ appdata_s* ad = evas_object_data_get(chat_list, "app_data");
+ if (result == APP_CONTROL_RESULT_SUCCEEDED) {
+ char *latitude = NULL;
+ char *longitude = NULL;
+ app_control_get_extra_data(reply, "latitude", &latitude);
+ app_control_get_extra_data(reply, "longitude", &longitude);
+
+ if (latitude && longitude) {
+ send_location_message_to_buddy(chat_list, latitude, longitude);
+ } else {
+ //send_location_message_to_buddy(chat_list, "0.00000000000", "0.00000000000");
+ show_toast(ad, "Unable to detect location values.");
+ }
+ } else {
+ show_toast(ad, "Device does not support location feature.");
+ }
+}
+
+void on_video_app_control_reply_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+{
+ if (result == APP_CONTROL_RESULT_SUCCEEDED) {
+
+ Evas_Object* chat_list = user_data;
+ char* file_path = NULL;
+ char** path_arryay = NULL;
+ int array_length = 0;
+ app_control_get_extra_data_array(reply, APP_CONTROL_DATA_SELECTED, &path_arryay, &array_length);
+
+ for(int i = 0 ; i < array_length ; i++) {
+ file_path = strdup(path_arryay[i]);
+ send_media_message_to_buddy(chat_list, file_path, tgl_message_media_document);
+ free(file_path);
+ break;
+ }
+ }
+}
+
+void on_file_app_control_reply_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+{
+ if (result == APP_CONTROL_RESULT_SUCCEEDED) {
+
+ Evas_Object* chat_list = user_data;
+ appdata_s* ad = evas_object_data_get(chat_list, "app_data");
+ char* file_path = NULL;
+ char** path_arryay = NULL;
+ int array_length = 0;
+ app_control_get_extra_data_array(reply, APP_CONTROL_DATA_SELECTED, &path_arryay, &array_length);
+
for(int i = 0 ; i < array_length ; i++) {
file_path = strdup(path_arryay[i]);
- send_image_message_to_buddy(chat_list, file_path);
+
+ // get mime type of the file
+
+ char *mime_type = NULL;
+ if (file_path) {
+ char *extn = strrchr(file_path, '.');
+ if (extn) {
+ extn = replace(extn, '.', "");
+ }
+ if (extn) {
+ mime_type_get_mime_type(extn, &mime_type);
+ }
+ }
+ if (mime_type) {
+ if (strstr(mime_type, "video") != NULL) {
+ send_media_message_to_buddy(chat_list, file_path, tgl_message_media_document);
+ } else if (strstr(mime_type, "audio") != NULL) {
+ send_media_message_to_buddy(chat_list, file_path, tgl_message_media_document);
+ } else if (strstr(mime_type, "image") != NULL) {
+ send_media_message_to_buddy(chat_list, file_path, tgl_message_media_photo);
+ } else {
+ show_toast(ad, "Unsupported file.");
+ }
+ } else {
+ show_toast(ad, "Unsupported file.");
+ }
free(file_path);
break;
}
}
}
+static void on_voice_record_reply_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+{
+ if (result == APP_CONTROL_RESULT_SUCCEEDED) {
+ Evas_Object* chat_list = user_data;
+ char *file_name = NULL;
+ app_control_get_extra_data(reply, APP_CONTROL_DATA_SELECTED, &file_name);
+ if (file_name) {
+ send_media_message_to_buddy(chat_list, file_name, tgl_message_media_document);
+ }
+ }
+}
+
+void on_contact_app_control_reply_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+{
+ if (result == APP_CONTROL_RESULT_SUCCEEDED) {
+
+ Evas_Object* chat_list = user_data;
+ char *contact_name = NULL;
+ char *phone_number = NULL;
+ app_control_get_extra_data(reply, "http://tizen.org/appcontrol/data/name", &contact_name);
+ app_control_get_extra_data(reply, "http://tizen.org/appcontrol/data/phone", &phone_number);
+
+ }
+}
void on_media_type_selected_cb(void *data, Evas_Object *obj, void *event_info)
{
Evas_Object* chat_list = data;
appdata_s* ad = evas_object_data_get(chat_list, "app_data");
const char *label = elm_object_item_text_get((Elm_Object_Item *) event_info);
- if (strcasecmp(label, POPUP_TEXT_TAKE_GALLERY) == 0 || strcasecmp(label, POPUP_TEXT_TAKE_PHOTO) == 0) {
+ if (strcasecmp(label, POPUP_TEXT_TAKE_GALLERY) == 0) {
+ app_control_h app_control;
+ int ret = app_control_create(&app_control);
+ if(ret != APP_CONTROL_ERROR_NONE) {
+ show_toast(ad, "Error: Can not load image picker");
+ return;
+ }
+
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_PICK);
+
+ app_control_set_mime(app_control,"image/*");
+ app_control_add_extra_data(app_control, APP_CONTROL_DATA_SELECTION_MODE, "single");
+ app_control_send_launch_request(app_control, &on_gallery_app_control_reply_cb, data);
+ app_control_destroy(app_control);
+ } else if (strcasecmp(label, POPUP_TEXT_TAKE_PHOTO) == 0) {
+ app_control_h app_control;
+ int ret = app_control_create(&app_control);
+ if(ret != APP_CONTROL_ERROR_NONE) {
+ show_toast(ad, "Error: Can not load image picker");
+ return;
+ }
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_CREATE_CONTENT);
+ app_control_set_mime(app_control,"image/jpg");
+ //app_control_add_extra_data(app_control, "crop", "caller_id");
+ app_control_send_launch_request(app_control, &on_gallery_app_control_reply_cb, data);
+ app_control_destroy(app_control);
+ } else if (strcasecmp(label, POPUP_TEXT_TAKE_VIDEO) == 0) {
app_control_h app_control;
int ret = app_control_create(&app_control);
if(ret != APP_CONTROL_ERROR_NONE) {
return;
}
- if (strcasecmp(label, POPUP_TEXT_TAKE_PHOTO) == 0) {
- app_control_set_operation(app_control, APP_CONTROL_OPERATION_CREATE_CONTENT);
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_CREATE_CONTENT);
+
+ int remain_byte_size = 10485760;
+ int request_KB_size = 0;
+
+ if (remain_byte_size >= 1024) {
+ request_KB_size = remain_byte_size / 1024;
} else {
- app_control_set_operation(app_control, APP_CONTROL_OPERATION_PICK);
+ // TODO: Need to check minimum size for recording
+ request_KB_size = 1;
}
+ char recording_size[128] = {0, };
+ snprintf(recording_size, sizeof(recording_size), "%d", request_KB_size);
+ app_control_set_mime(app_control,"video/3gp");
+ app_control_add_extra_data(app_control, "LIMIT", recording_size);
+ app_control_add_extra_data(app_control, "RESOLUTION", "VGA");
+ app_control_add_extra_data(app_control, "CALLER", "telegram");
- app_control_set_mime(app_control,"image/*");
- app_control_send_launch_request(app_control, &on_gallery_app_control_reply_cb, data);
+ app_control_send_launch_request(app_control, &on_video_app_control_reply_cb, data);
+ app_control_destroy(app_control);
+ } else if (strcasecmp(label, POPUP_TEXT_TAKE_AUDIO) == 0) {
+
+ app_control_h app_control;
+ int ret = app_control_create(&app_control);
+ if(ret != APP_CONTROL_ERROR_NONE) {
+ show_toast(ad, "Error: Can not load image picker");
+ return;
+ }
+
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_CREATE_CONTENT);
+
+ int size = 10485760;
+
+ int remain_byte_size = (int)size;
+ int request_KB_size = 0;
+
+ if (remain_byte_size >= 1024) {
+ request_KB_size = remain_byte_size / 1024;
+ } else {
+ // TODO: Need to check minimum size for recording
+ request_KB_size = 1;
+ }
+
+ char recording_size[128] = {0, };
+ snprintf(recording_size, sizeof(recording_size), "%d", request_KB_size);
+ app_control_add_extra_data(app_control, "SIZE", recording_size);
+ app_control_set_mime(app_control,"audio/*");
+ app_control_send_launch_request(app_control, &on_voice_record_reply_cb, data);
+ app_control_destroy(app_control);
+
+ } else if (strcasecmp(label, POPUP_TEXT_TAKE_FILE) == 0) {
+ app_control_h app_control;
+ int ret = app_control_create(&app_control);
+ if(ret != APP_CONTROL_ERROR_NONE) {
+ show_toast(ad, "Error: Can not load image picker");
+ return;
+ }
+
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_PICK);
+
+ app_control_set_mime(app_control,"*/*");
+ app_control_add_extra_data(app_control, APP_CONTROL_DATA_SELECTION_MODE, "single");
+ app_control_send_launch_request(app_control, &on_file_app_control_reply_cb, data);
+ app_control_destroy(app_control);
+
+ } else if (strcasecmp(label, POPUP_TEXT_TAKE_LOCATION) == 0) {
+ app_control_h app_control;
+ int ret = app_control_create(&app_control);
+ if(ret != APP_CONTROL_ERROR_NONE) {
+ show_toast(ad, "Error: Can not load location picker");
+ return;
+ }
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_PICK);
+ //app_control_set_app_id(app_control, "com.here.tizen.maps");
+ app_control_set_uri(app_control, "geo");
+ app_control_send_launch_request(app_control, &on_location_app_control_reply_cb, data);
+ app_control_destroy(app_control);
+ } else if (strcasecmp(label, POPUP_TEXT_TAKE_CONTACT) == 0) {
+ app_control_h app_control;
+ int ret = app_control_create(&app_control);
+ if(ret != APP_CONTROL_ERROR_NONE) {
+ show_toast(ad, "Error: Can not load location picker");
+ return;
+ }
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_PICK);
+ app_control_set_mime(app_control,"application/vnd.tizen.contact");
+ app_control_add_extra_data(app_control, APP_CONTROL_DATA_SELECTION_MODE, "single");
+ app_control_send_launch_request(app_control, &on_contact_app_control_reply_cb, data);
app_control_destroy(app_control);
}
+
evas_object_del(obj);
}
{
Evas_Coord x, y, w , h;
evas_object_geometry_get(btn, &x, &y, &w, &h);
- evas_object_move(ctxpopup, x + (w / 2), y + h);
+ evas_object_move(ctxpopup, x + (w / 2), y + h - 50);
}
void on_media_attach_dismissed_cb(void *data, Evas_Object *obj, void *event_info)
elm_ctxpopup_item_append(ctxpopup, POPUP_TEXT_TAKE_PHOTO, create_image_object_from_file(ui_utils_get_resource(FM_ICON_CAMERA), chat_list), on_media_type_selected_cb, chat_list);
elm_ctxpopup_item_append(ctxpopup, POPUP_TEXT_TAKE_GALLERY, create_image_object_from_file(ui_utils_get_resource(FM_ICON_GALLERY), chat_list), on_media_type_selected_cb, chat_list);
elm_ctxpopup_item_append(ctxpopup, POPUP_TEXT_TAKE_VIDEO, create_image_object_from_file(ui_utils_get_resource(FM_ICON_VIDEO), chat_list), on_media_type_selected_cb, chat_list);
+ elm_ctxpopup_item_append(ctxpopup, POPUP_TEXT_TAKE_AUDIO, create_image_object_from_file(ui_utils_get_resource(FM_ICON_MIC), chat_list), on_media_type_selected_cb, chat_list);
elm_ctxpopup_item_append(ctxpopup, POPUP_TEXT_TAKE_FILE, create_image_object_from_file(ui_utils_get_resource(FM_ICON_FILE), chat_list), on_media_type_selected_cb, chat_list);
elm_ctxpopup_item_append(ctxpopup, POPUP_TEXT_TAKE_LOCATION, create_image_object_from_file(ui_utils_get_resource(FM_ICON_LOCATION), chat_list), on_media_type_selected_cb, chat_list);
+ //elm_ctxpopup_item_append(ctxpopup, POPUP_TEXT_TAKE_CONTACT, create_image_object_from_file(ui_utils_get_resource(TG_MENU_CONTACTS), chat_list), on_media_type_selected_cb, chat_list);
elm_ctxpopup_direction_priority_set(ctxpopup, ELM_CTXPOPUP_DIRECTION_DOWN, ELM_CTXPOPUP_DIRECTION_UNKNOWN, ELM_CTXPOPUP_DIRECTION_UNKNOWN, ELM_CTXPOPUP_DIRECTION_UNKNOWN);
elm_image_file_set(data, ui_utils_get_resource(SMILEY_ICON_UNPRESSED), NULL);
}
+void on_user_info_button_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = data;
+
+ peer_with_pic_s *sel_item = ad->peer_in_cahtting_data;
+ tg_peer_info_s *user_data = sel_item->use_data;
+
+ if (!sel_item || !user_data) {
+ show_toast(ad, "Can not display user info");
+ return;
+ }
+
+ if (user_data->peer_type == TGL_PEER_USER) {
+ launch_user_info_screen(ad, user_data->peer_id);
+ } else if (user_data->peer_type == TGL_PEER_CHAT) {
+ launch_chat_info_screen(ad, user_data->peer_id);
+ } else {
+
+ }
+
+}
void launch_messaging_view_cb(appdata_s* ad, int user_id)
{
if (!ad)
return;
+ if (ad->msg_popup) {
+ evas_object_del(ad->msg_popup);
+ ad->msg_popup = NULL;
+ }
+
ad->current_app_state = TG_CHAT_MESSAGING_VIEW_STATE;
ad->is_last_msg_changed = EINA_FALSE;
evas_object_size_hint_align_set(msg_box_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(msg_box_layout);
-#if 0
+#if 1
Evas_Object* list_bg = elm_image_add(msg_box_layout);
evas_object_size_hint_align_set(list_bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(list_bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_image_file_set(list_bg, ui_utils_get_resource(TG_CHAT_DEFAULT_BG), NULL);
+ if (ad->chat_background) {
+ elm_image_file_set(list_bg, ad->chat_background, NULL);
+ } else {
+ elm_image_file_set(list_bg, ui_utils_get_resource(TG_CHAT_DEFAULT_BG), NULL);
+ }
elm_image_resizable_set(list_bg, EINA_TRUE, EINA_TRUE);
elm_image_fill_outside_set(list_bg, EINA_TRUE);
evas_object_show(list_bg);
- Evas_Object* chat_conv_list = create_chat_genlist(ad->win);
+ elm_object_part_content_set(msg_box_layout, "swallow.gen_list.bg", list_bg);
#endif
#if 1
Evas_Object* chat_conv_list = elm_genlist_add(ad->nf);
evas_object_show(chat_conv_list);
- //elm_object_part_content_set(msg_box_layout, "swallow.gen_list.bg", list_bg);
+
elm_object_part_content_set(msg_box_layout, "swallow.gen_list", chat_conv_list);
evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(user_pic_layout);
elm_object_part_content_set(user_pic_layout, "content", profile_pic);
+ evas_object_data_set(ad->nf, "profile_picture", (void*)profile_pic);
Evas_Object* eo = elm_layout_add(ad->nf);
elm_layout_theme_set(eo, "layout", "list/C/type.3", "default");
elm_object_style_set(profile_name, "transparent");
evas_object_show(profile_name);
elm_object_part_content_set(title_layout, "swallow.profile_name", profile_name);
+ evas_object_data_set(ad->nf, "profile_title", (void*)profile_name);
+ evas_object_smart_callback_add(profile_name, "clicked", on_user_info_button_clicked, ad);
Evas_Object* profile_time = elm_label_add(title_layout);
evas_object_size_hint_align_set(profile_time, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(profile_time);
elm_object_part_content_set(title_layout, "swallow.profile_time", profile_time);
evas_object_data_set(ad->nf, "profile_time", (void*)profile_time);
+ evas_object_smart_callback_add(profile_time, "clicked", on_user_info_button_clicked, ad);
//elm_object_content_set(title_scroller, title_layout);
evas_object_smart_callback_add(send_btn, "unpressed", on_text_message_send_unpressed, send_icon);
elm_object_part_content_set(entry_box_layout, "swallow.send_icon", send_btn);
- elm_object_part_content_set(layout, "swallow.entry_box", entry_box_layout);
+ //elm_object_part_content_set(layout, "swallow.entry_box", entry_box_layout);
/********************** entry layout*******************************/
evas_object_data_set(ad->nf, "chat_list", (void*)chat_conv_list);
evas_object_data_set(chat_conv_list, "text_entry", (void*)text_entry);
evas_object_data_set(chat_conv_list, "profile_time", (void*)profile_time);
- elm_naviframe_item_simple_push(ad->nf, scroller);
+ Elm_Object_Item *nf_it = elm_naviframe_item_simple_push(ad->nf, scroller);
+
+ elm_object_item_part_content_set(nf_it, "toolbar", entry_box_layout);
+
load_chat_history(chat_conv_list);
send_request_for_marked_as_read(ad->service_client, sel_item->use_data->peer_id, sel_item->use_data->peer_type);
+ eext_object_event_callback_add(ad->nf, EEXT_CALLBACK_MORE, on_messaging_menu_button_clicked, ad);
}
strcat(phone_number, phone_num);
ad->phone_number = strdup(phone_number);
send_request_for_registration(ad->service_client, ad->phone_number, EINA_TRUE);
+ show_loading_popup(ad);
} else {
}
static void on_naviframe_cancel_clicked(void *data, Evas_Object *obj, void *event_info)
{
appdata_s* ad = data;
-#if 0
elm_win_lower(ad->win);
elm_exit();
-#else
- elm_naviframe_item_pop(ad->nf);
- launch_login_cb(ad);
-#endif
}
static void country_name_popup_dismissed_cb(void *data, Evas_Object *obj, void *event_info)
evas_object_data_set(ad->nf, "country_name_popup", country_name_popup);
}
-void launch_registration_cb(appdata_s* ad)
+void launch_registration_cb(appdata_s *ad)
{
if (!ad) {
return;
--- /dev/null
+/*
+ * tg_search_peer_view.c
+ *
+ * Created on: Sep 18, 2015
+ * Author: sandeep
+ */
+
+#include "tg_search_peer_view.h"
+#include "tg_db_wrapper.h"
+#include "tg_messaging_view.h"
+
+static Evas_Object* create_image_object_from_file(const char *icon_name, Evas_Object *parent)
+{
+ Evas_Object *icon = elm_image_add(parent);
+ evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_image_file_set(icon, icon_name, NULL);
+ evas_object_show(icon);
+ return icon;
+}
+
+char* on_peer_list_name_requested(void *data, Evas_Object *obj, const char *part)
+{
+
+ int id = (int) data;
+
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+
+ int size = eina_list_count(ad->search_peer_list);
+
+ if (size <= 0) {
+ if (!strcmp(part,"elm.text")){
+ char buf[512] = {'\0'};
+ snprintf(buf, 512, "<align=left><font_size=35><color=#000000>%s</color></font_size></align>", "No Items");
+ return strdup(buf);
+
+ } else if (!strcmp(part, "elm.text.sub")) {
+ return NULL;
+ }
+ }
+
+ peer_with_pic_s* item = eina_list_nth(ad->search_peer_list, id);
+ tg_peer_info_s* user = item->use_data;
+
+ if (!strcmp(part,"elm.text")){
+ char* user_name = replace(user->print_name, '_', " ");
+ char buf[512] = {'\0'};
+ snprintf(buf, 512, "<align=left><font_size=35><color=#000000>%s</color></font_size></align>", user_name);
+ free(user_name);
+ return strdup(buf);
+
+ } else if (!strcmp(part, "elm.text.sub")) {
+ if (user->peer_type == TGL_PEER_USER) {
+ char* last_seen = get_budy_state(ad, user->peer_id);
+ if (last_seen) {
+ return last_seen;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+void on_peer_icon_deleted(void *data, Evas *e, Evas_Object *icon, void *event_info)
+{
+ peer_with_pic_s *item = data;
+ item->contact_icon = NULL;
+}
+
+Evas_Object* on_peer_list_image_requested(void *data, Evas_Object *obj, const char *part)
+{
+ Evas_Object *eo = NULL;
+ if (!strcmp(part, "elm.swallow.icon")) {
+
+ int id = (int) data;
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+ int size = eina_list_count(ad->search_peer_list);
+ if (size <= 0) {
+ return eo;
+ }
+ peer_with_pic_s* item = eina_list_nth(ad->search_peer_list, id);
+ tg_peer_info_s* user = item->use_data;
+ Evas_Object *profile_pic = NULL;
+ if (user->photo_path && strcmp(user->photo_path, "") != 0) {
+ profile_pic = create_image_object_from_file(user->photo_path, obj);
+ } else {
+ profile_pic = create_image_object_from_file(ui_utils_get_resource(DEFAULT_PROFILE_PIC), obj);
+ }
+
+ item->contact_icon = profile_pic;
+ evas_object_event_callback_add(item->contact_icon, EVAS_CALLBACK_DEL, on_peer_icon_deleted, item);
+
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* user_pic_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_pic_layout, edj_path, "circle_layout");
+ evas_object_size_hint_weight_set(user_pic_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_pic_layout);
+ elm_object_part_content_set(user_pic_layout, "content", profile_pic);
+
+ eo = elm_layout_add(obj);
+ elm_layout_theme_set(eo, "layout", "list/C/type.3", "default");
+ elm_layout_content_set(eo, "elm.swallow.content", user_pic_layout);
+ }
+ return eo;
+}
+
+static void clear_search_list(appdata_s *ad)
+{
+ if (ad->search_peer_list) {
+ for (int i = 0; i < eina_list_count(ad->search_peer_list) ; i++) {
+ peer_with_pic_s* pic_item = eina_list_nth(ad->search_peer_list, i);
+ tg_peer_info_s* item = pic_item->use_data;
+ if (item) {
+ if (item->print_name) {
+ free(item->print_name);
+ item->print_name = NULL;
+ }
+ if (item->photo_path) {
+ free(item->photo_path);
+ item->photo_path = NULL;
+ }
+ pic_item->contact_icon = NULL;
+ pic_item->msg_object = NULL;
+ pic_item->name_object = NULL;
+ free(item);
+ }
+ free(pic_item);
+ }
+ eina_list_free(ad->search_peer_list);
+ }
+ ad->search_peer_list = NULL;
+}
+
+static void on_peer_item_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ Elm_Object_Item *it = event_info;
+ elm_genlist_item_selected_set(it, EINA_FALSE);
+
+ int item_id = (int) data;
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+
+ peer_with_pic_s* sel_pic_item = eina_list_nth(ad->search_peer_list, item_id);
+ tg_peer_info_s* sel_item = sel_pic_item->use_data;
+
+
+ ad->buddy_in_cahtting_data = NULL;
+ ad->peer_in_cahtting_data = NULL;
+ int buddy_id = -1;
+ if (sel_item) {
+ if (sel_item->peer_type == TGL_PEER_USER) {
+ for (int i = 0; i < eina_list_count(ad->buddy_list); i++) {
+ user_data_with_pic_s *item = eina_list_nth(ad->buddy_list, i);
+ user_data_s* user_data = item->use_data;
+
+ if (user_data->user_id.id == sel_item->peer_id) {
+ ad->buddy_in_cahtting_data = item;
+ break;
+ }
+ }
+ }
+
+ for (int i = 0; i < eina_list_count(ad->peer_list); i++) {
+ peer_with_pic_s* pic_item = eina_list_nth(ad->peer_list, i);
+ tg_peer_info_s* item = pic_item->use_data;
+
+ if (item->peer_id == sel_item->peer_id) {
+ ad->peer_in_cahtting_data = pic_item;
+ buddy_id = i;
+ break;
+ }
+ }
+
+ for (int i = 0; i < eina_list_count(ad->main_list); i++) {
+ tg_main_list_item_s* item = eina_list_nth(ad->main_list, i);
+
+ if (item->peer_id == sel_item->peer_id) {
+ ad->main_item_in_cahtting_data = item;
+ break;
+ }
+ }
+
+ elm_naviframe_item_pop(ad->nf);
+ clear_search_list(ad);
+ launch_messaging_view_cb(ad, buddy_id);
+ }
+}
+
+static void on_search_content_changed(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s* ad = data;
+ char buf[256] = {'\0',};
+ snprintf(buf, sizeof(buf), "%s", elm_object_text_get(obj));
+ char *org_name = trim(buf);
+ if (strlen(org_name) > 0) {
+ Evas_Object *search_list = evas_object_data_get(ad->nf, "search_list");
+ if (search_list) {
+ elm_genlist_clear(search_list);
+ clear_search_list(ad);
+ ad->search_peer_list = load_peer_data_by_name(org_name);
+ int i = 0;
+ static Elm_Genlist_Item_Class itc1;
+ itc1.item_style = "double_label";
+ itc1.func.text_get = on_peer_list_name_requested;
+ itc1.func.content_get = on_peer_list_image_requested;
+ itc1.func.state_get = NULL;
+ itc1.func.del = NULL;
+
+ int size = eina_list_count(ad->search_peer_list);
+
+ if(size > 0) {
+ for (i = 0; i < size; i++) {
+ elm_genlist_item_append(search_list, &itc1, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_peer_item_clicked, (void*) i);
+ }
+ } else {
+ i = 1;
+ elm_genlist_item_append(search_list, &itc1, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
+ }
+ evas_object_show(search_list);
+ }
+ }
+ else {
+ Evas_Object *search_list = evas_object_data_get(ad->nf, "search_list");
+ if (search_list) {
+ elm_genlist_clear(search_list);
+ clear_search_list(ad);
+ ad->search_peer_list = load_peer_data_by_name(NULL);
+ int i = 0;
+ static Elm_Genlist_Item_Class itc1;
+ itc1.item_style = "double_label";
+ itc1.func.text_get = on_peer_list_name_requested;
+ itc1.func.content_get = on_peer_list_image_requested;
+ itc1.func.state_get = NULL;
+ itc1.func.del = NULL;
+
+ int size = eina_list_count(ad->search_peer_list);
+
+ if(size > 0) {
+ for (i = 0; i < size; i++) {
+ elm_genlist_item_append(search_list, &itc1, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_peer_item_clicked, (void*) i);
+ }
+ } else {
+ i = 1;
+ elm_genlist_item_append(search_list, &itc1, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
+ }
+ evas_object_show(search_list);
+ }
+ }
+ if (org_name) {
+ free(org_name);
+ org_name = NULL;
+ }
+}
+
+
+void launch_start_peer_search_view(appdata_s* ad)
+{
+ if (!ad)
+ return;
+
+ ad->current_app_state = TG_PEER_SEARCH_VIEW_STATE;
+
+
+ clear_search_list(ad);
+
+
+ ad->search_peer_list = load_peer_data_by_name(NULL);
+
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+
+ Evas_Object* scroller = elm_scroller_add(ad->nf);
+ elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
+ elm_scroller_policy_set(scroller,ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+
+ Evas_Object* layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(layout, edj_path, "peer_search_main_layout");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(layout);
+ elm_object_content_set(scroller, layout);
+
+ Evas_Object* search_content = elm_entry_add(layout);
+ elm_object_part_text_set(search_content, "elm.guide", "<font=Tizen:style=Regular color=#666362 align=left><font_size=36>Search contact</font_size></font>");
+ elm_entry_cursor_end_set(search_content);
+ evas_object_size_hint_weight_set(search_content, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(search_content, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_entry_single_line_set(search_content, EINA_TRUE);
+ elm_entry_scrollable_set (search_content, EINA_FALSE);
+ elm_entry_cnp_mode_set(search_content, ELM_CNP_MODE_NO_IMAGE);
+ elm_entry_context_menu_disabled_set(search_content, EINA_TRUE);
+ elm_entry_text_style_user_push(search_content, "DEFAULT='color=#000000'");
+ evas_object_show(search_content);
+
+ limit_filter_data.max_char_count = 255;
+ elm_entry_markup_filter_append(search_content, elm_entry_filter_limit_size, &limit_filter_data);
+ evas_object_smart_callback_add(search_content, "changed", on_search_content_changed, ad);
+ elm_object_part_content_set(layout, "swallow.search_area", search_content);
+
+ int i;
+ static Elm_Genlist_Item_Class itc1;
+ Evas_Object *peer_list = elm_genlist_add(ad->nf);
+ elm_list_mode_set(peer_list, ELM_LIST_COMPRESS);
+ elm_genlist_mode_set(peer_list, ELM_LIST_COMPRESS);
+ evas_object_size_hint_weight_set(peer_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(peer_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_data_set(peer_list, "app_data", ad);
+
+ itc1.item_style = "double_label";
+ itc1.func.text_get = on_peer_list_name_requested;
+ itc1.func.content_get = on_peer_list_image_requested;
+ itc1.func.state_get = NULL;
+ itc1.func.del = NULL;
+
+ int size = eina_list_count(ad->search_peer_list);
+
+ if(size > 0) {
+ for (i = 0; i < size; i++) {
+ elm_genlist_item_append(peer_list, &itc1, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_peer_item_clicked, (void*) i);
+ }
+ } else {
+ i = 1;
+ elm_genlist_item_append(peer_list, &itc1, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
+ }
+
+ evas_object_show(peer_list);
+ elm_object_part_content_set(layout, "swallow.peerlist", peer_list);
+
+ evas_object_data_set(ad->nf, "search_list", peer_list);
+
+ //Elm_Object_Item* navi_item = elm_naviframe_item_push(ad->nf, "<font=Tizen:style=Regular color=#ffffff align=left><font_size=40>Search contact</font_size></font>", NULL, NULL, scroller, NULL);
+ elm_naviframe_item_simple_push(ad->nf, scroller);
+}
--- /dev/null
+/*
+ * tg_select_buddy_from_list.c
+ *
+ * Created on: Oct 3, 2015
+ * Author: sandeep
+ */
+
+#include "tg_select_buddy_from_list.h"
+#include "tg_db_wrapper.h"
+#include "server_requests.h"
+
+static Evas_Object* create_image_object_from_file(const char *icon_name, Evas_Object *parent)
+{
+ Evas_Object *icon = elm_image_add(parent);
+ evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_image_file_set(icon, icon_name, NULL);
+ evas_object_show(icon);
+ return icon;
+}
+
+char* on_buddy_select_list_name_requested(void *data, Evas_Object *obj, const char *part)
+{
+ int id = (int) data;
+
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+
+ int size = eina_list_count(ad->buddy_list);
+
+ if (size <= 0) {
+ if (!strcmp(part,"elm.text")){
+ char buf[512] = {'\0'};
+ snprintf(buf, 512, "<align=left><font_size=35><color=#000000>%s</color></font_size></align>", "No Items");
+ return strdup(buf);
+
+ } else if (!strcmp(part, "elm.text.sub")) {
+ return NULL;
+ }
+ }
+
+ user_data_with_pic_s* item = eina_list_nth(ad->buddy_list, id);
+ user_data_s* user = item->use_data;
+
+ if (!strcmp(part,"elm.text")){
+ char* user_name = replace(user->print_name, '_', " ");
+ char buf[512] = {'\0'};
+ snprintf(buf, 512, "<align=left><font_size=35><color=#000000>%s</color></font_size></align>", user_name);
+ free(user_name);
+ return strdup(buf);
+
+ } else if (!strcmp(part, "elm.text.sub")) {
+ char* last_seen = get_budy_state(ad, user->user_id.id);
+ if (last_seen) {
+ return last_seen;
+ }
+ }
+
+ return NULL;
+}
+
+void on_buddy_selected_icon_deleted(void *data, Evas *e, Evas_Object *icon, void *event_info)
+{
+ user_data_with_pic_s *item = data;
+ item->contact_icon = NULL;
+}
+
+Evas_Object* on_buddy_select_list_image_requested(void *data, Evas_Object *obj, const char *part)
+{
+ Evas_Object *eo = NULL;
+ if (!strcmp(part, "elm.swallow.icon")) {
+
+ int id = (int) data;
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+ int size = eina_list_count(ad->buddy_list);
+ if (size <= 0) {
+ return eo;
+ }
+ user_data_with_pic_s* item = eina_list_nth(ad->buddy_list, id);
+ user_data_s* user = item->use_data;
+ Evas_Object *profile_pic = NULL;
+ if (user->photo_path && strcmp(user->photo_path, "") != 0) {
+ profile_pic = create_image_object_from_file(user->photo_path, obj);
+ } else {
+ profile_pic = create_image_object_from_file(ui_utils_get_resource(DEFAULT_PROFILE_PIC), obj);
+ }
+
+ item->contact_icon = profile_pic;
+ evas_object_event_callback_add(item->contact_icon, EVAS_CALLBACK_DEL, on_buddy_selected_icon_deleted, item);
+
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* user_pic_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_pic_layout, edj_path, "circle_layout");
+ evas_object_size_hint_weight_set(user_pic_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_pic_layout);
+ elm_object_part_content_set(user_pic_layout, "content", profile_pic);
+
+ eo = elm_layout_add(obj);
+ elm_layout_theme_set(eo, "layout", "list/C/type.3", "default");
+ elm_layout_content_set(eo, "elm.swallow.content", user_pic_layout);
+ }
+ return eo;
+}
+
+
+static void on_buddy_sel_menu_canceled(void *data, Evas_Object *obj, void *event_info)
+{
+ //appdata_s *ad = evas_object_data_get(obj, "app_data");
+ Evas_Object *popup = evas_object_data_get(obj, "popup");
+ evas_object_del(popup);
+}
+
+static void on_buddy_add_to_chat_ok_selected(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = evas_object_data_get(obj, "app_data");
+ Evas_Object *popup = evas_object_data_get(obj, "popup");
+
+ if (ad->peer_in_cahtting_data && ad->peer_in_cahtting_data->use_data) {
+ show_loading_popup(ad);
+ send_add_buddy_to_group_chat_request(ad->service_client, ad->selected_buddy_item->user_id.id, ad->peer_in_cahtting_data->use_data->peer_id);
+ elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_SET_CHAT_INFO_STATE;
+ }
+
+ evas_object_del(popup);
+}
+
+static void on_new_buddy_to_chat_selected_cb(appdata_s *ad)
+{
+
+ if (!ad->selected_buddy_item) {
+ return;
+ }
+
+ Evas_Object *popup, *btn;
+
+ /* popup */
+ popup = elm_popup_add(ad->nf);
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ char* user_name = replace(ad->selected_buddy_item->print_name, '_', " ");
+ char *msg_data = (char*)malloc(strlen("Add ") + strlen(user_name) + strlen(" to the group?") + 1);
+ strcpy(msg_data, "Add ");
+ strcat(msg_data, user_name);
+ strcat(msg_data, " to the group?");
+ elm_object_text_set(popup, msg_data);
+
+ /* ok button */
+ btn = elm_button_add(popup);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, "OK");
+ elm_object_part_content_set(popup, "button1", btn);
+ evas_object_smart_callback_add(btn, "clicked", on_buddy_add_to_chat_ok_selected, ad);
+ evas_object_data_set(btn, "app_data", ad);
+ evas_object_data_set(btn, "popup", popup);
+
+ /* cancel button */
+ btn = elm_button_add(popup);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, "Cancel");
+ elm_object_part_content_set(popup, "button2", btn);
+ evas_object_smart_callback_add(btn, "clicked", on_buddy_sel_menu_canceled, ad);
+ evas_object_data_set(btn, "app_data", ad);
+ evas_object_data_set(btn, "popup", popup);
+
+ evas_object_show(popup);
+
+ free(user_name);
+ free(msg_data);
+}
+
+static void on_buddy_item_selected(void *data, Evas_Object *obj, void *event_info)
+{
+ Elm_Object_Item *it = event_info;
+ elm_genlist_item_selected_set(it, EINA_FALSE);
+
+ int item_id = (int) data;
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+
+ user_data_with_pic_s* sel_item = eina_list_nth(ad->buddy_list, item_id);
+ if (!sel_item) {
+ show_toast(ad, "Failed to add user to chat");
+ elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_SET_CHAT_INFO_STATE;
+ return;
+ }
+
+ int chat_id = ad->peer_in_cahtting_data->use_data->peer_id;
+
+ tg_chat_info_s* chat_info = get_chat_info(chat_id);
+
+ if (!chat_info) {
+ show_toast(ad, "Failed to add user to chat");
+ elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_SET_CHAT_INFO_STATE;
+ return;
+ }
+
+
+ int user_list_size = chat_info->user_list_size;
+ int online_members = 0;
+
+ Eina_Bool is_already_present = EINA_FALSE;
+ for (int i = 0; i < user_list_size; i++) {
+ int chat_buddy_id = chat_info->chat_users[i];
+ if (sel_item->use_data->user_id.id == chat_buddy_id) {
+ is_already_present = EINA_TRUE;
+ }
+ }
+
+ if(chat_info->print_title) {
+ free(chat_info->print_title);
+ chat_info->print_title = NULL;
+ }
+ if(chat_info->photo_path) {
+ free(chat_info->photo_path);
+ chat_info->photo_path = NULL;
+ }
+ if(chat_info->title) {
+ free(chat_info->title);
+ chat_info->title = NULL;
+ }
+
+ if (is_already_present) {
+ show_toast(ad, "User already present in the chat.");
+ } else {
+ ad->selected_buddy_item = sel_item->use_data;
+ on_new_buddy_to_chat_selected_cb(ad);
+ /*elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_SET_CHAT_INFO_STATE;*/
+ return;
+ }
+
+}
+
+
+
+void launch_select_buddy_view(appdata_s* ad)
+{
+ if (!ad)
+ return;
+
+ ad->current_app_state = TG_SELECT_BUDDY_VIEW;
+
+
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+
+
+ Evas_Object* scroller = elm_scroller_add(ad->nf);
+ elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
+ elm_scroller_policy_set(scroller,ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+
+ int i;
+ static Elm_Genlist_Item_Class itc1;
+ Evas_Object *buddy_list = elm_genlist_add(ad->nf);
+ elm_list_mode_set(buddy_list, ELM_LIST_COMPRESS);
+ elm_genlist_mode_set(buddy_list, ELM_LIST_COMPRESS);
+ evas_object_size_hint_weight_set(buddy_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(buddy_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_data_set(buddy_list, "app_data", ad);
+
+ itc1.item_style = "double_label";
+ itc1.func.text_get = on_buddy_select_list_name_requested;
+ itc1.func.content_get = on_buddy_select_list_image_requested;
+ itc1.func.state_get = NULL;
+ itc1.func.del = NULL;
+
+ int size = 0;
+ if (ad->buddy_list) {
+ size = eina_list_count(ad->buddy_list);
+ }
+
+ if(size > 0) {
+ for (i = 0; i < size; i++) {
+ elm_genlist_item_append(buddy_list, &itc1, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_buddy_item_selected, (void*) i);
+ }
+ } else {
+ i = 1;
+ elm_genlist_item_append(buddy_list, &itc1, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
+ }
+ evas_object_show(buddy_list);
+ elm_object_content_set(scroller, buddy_list);
+
+ /***************** contacts list *************************/
+
+ Elm_Object_Item* navi_item = elm_naviframe_item_push(ad->nf, "<font=Tizen:style=Regular color=#ffffff align=left><font_size=40>Select Buddy</font_size></font>", NULL, NULL, scroller, NULL);
+
+}
+
+
--- /dev/null
+/*
+ * tg_set_username_view.c
+ *
+ * Created on: Sep 30, 2015
+ * Author: sandeep
+ */
+
+#include "tg_set_username_view.h"
+#include "server_requests.h"
+
+static void on_username_text_change_enable_ok_button(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s* ad = data;
+ Evas_Object *done_btn = evas_object_data_get(ad->nf, "username_done_btn");
+ Evas_Object *username_entry = evas_object_data_get(ad->nf, "username_entry");
+ char *temp_user_name = elm_entry_markup_to_utf8(elm_object_text_get(username_entry));
+
+ char *user_name = trim(temp_user_name);
+
+ if (strlen(user_name) >= MIN_USERNAME_LENGTH) {
+ elm_object_disabled_set(done_btn, EINA_FALSE);
+ } else {
+ elm_object_disabled_set(done_btn, EINA_TRUE);
+ }
+ free(user_name);
+}
+
+static void on_naviframe_username_cancel_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s* ad = data;
+ elm_naviframe_item_pop(ad->nf);
+}
+
+static void on_naviframe_username_done_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s* ad = data;
+ Evas_Object *username_entry = evas_object_data_get(ad->nf, "username_entry");
+ char *temp_user_name = elm_entry_markup_to_utf8(elm_object_text_get(username_entry));
+
+ char *user_name = trim(temp_user_name);
+ if (strlen(user_name) < MIN_USERNAME_LENGTH) {
+ show_toast(ad, "Username should not be less than 5 characters");
+ } else {
+ send_set_username_request(ad->service_client, ad->current_user_data->user_id.id, user_name);
+ show_loading_popup(ad);
+ }
+ free(user_name);
+}
+
+void launch_set_username_cb(appdata_s *ad)
+{
+ if (!ad) {
+ return;
+ }
+
+ ad->current_app_state = TG_SET_USERNAME_STATE;
+
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+
+ Evas_Object* scroller = elm_scroller_add(ad->nf);
+ elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
+ elm_scroller_policy_set(scroller,ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+
+ Evas_Object* layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(layout, edj_path, "set_user_name_layout");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(layout);
+
+
+
+ Evas_Object* username_entry = elm_entry_add(layout);
+ elm_object_part_text_set(username_entry, "elm.guide", "Enter phone number");
+ elm_entry_cursor_end_set(username_entry);
+ evas_object_size_hint_weight_set(username_entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(username_entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_entry_single_line_set(username_entry, EINA_TRUE);
+ elm_entry_scrollable_set (username_entry, EINA_FALSE);
+ elm_entry_cnp_mode_set(username_entry, ELM_CNP_MODE_NO_IMAGE);
+ elm_entry_context_menu_disabled_set(username_entry, EINA_TRUE);
+ elm_entry_text_style_user_push(username_entry, "DEFAULT='color=#000000'");
+ evas_object_show(username_entry);
+ elm_object_part_content_set(layout, "swallow.entry_box", username_entry);
+
+ evas_object_data_set(ad->nf, "username_entry", (void*)username_entry);
+
+ limit_filter_data.max_char_count = MAX_USERNAME_LENGTH;
+ elm_entry_markup_filter_append(username_entry, elm_entry_filter_limit_size, &limit_filter_data);
+ Ecore_IMF_Context *imf_context;
+ imf_context = elm_entry_imf_context_get(username_entry);
+ ecore_imf_context_input_panel_layout_set(imf_context, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL_VARIATION_PERSON_NAME);
+
+ //evas_object_smart_callback_add(username_entry, "changed", on_username_text_change_enable_ok_button, ad);
+
+ char* temp_help_text_one = "You can choose a username on Telegram, If you do, other people will be able to find you by this username and contact you without knowing your phone number.";
+ char* temp_help_text_two = "You can use a-z, 0-9 and underscores. Minimum length is 5 characters.";
+
+ char help_text_one[256*4] = {'\0'};
+ sprintf(help_text_one, "<font=Tizen:style=Italic color=#000000 align=left><font_size=30>%s</font_size></font>", temp_help_text_one);
+
+
+ char help_text_two[256*4] = {'\0'};
+ sprintf(help_text_two, "<font=Tizen:style=Italic color=#000000 align=left><font_size=30>%s</font_size></font>", temp_help_text_two);
+
+ Evas_Object* help_text1 = elm_entry_add(layout);
+ elm_object_text_set(help_text1, help_text_one);
+ evas_object_size_hint_weight_set(help_text1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(help_text1, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_entry_single_line_set(help_text1, EINA_FALSE);
+ elm_entry_editable_set(help_text1, EINA_FALSE);
+ elm_entry_line_wrap_set(help_text1, EINA_TRUE);
+ evas_object_show(help_text1);
+ elm_object_part_content_set(layout, "swallow.help_text_one", help_text1);
+
+ Evas_Object* help_text2 = elm_entry_add(layout);
+ elm_object_text_set(help_text2, help_text_two);
+ evas_object_size_hint_weight_set(help_text2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(help_text2, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_entry_single_line_set(help_text2, EINA_FALSE);
+ elm_entry_editable_set(help_text2, EINA_FALSE);
+ elm_entry_line_wrap_set(help_text2, EINA_TRUE);
+ evas_object_show(help_text2);
+ elm_object_part_content_set(layout, "swallow.help_text_two", help_text2);
+
+
+ elm_object_content_set(scroller, layout);
+ Elm_Object_Item* navi_item = elm_naviframe_item_push(ad->nf, "Username", NULL, NULL, scroller, NULL);
+
+ Evas_Object *cancel_btn = elm_button_add(ad->nf);
+ elm_object_style_set(cancel_btn, "naviframe/title_icon");
+ elm_object_text_set(cancel_btn, "Cancel");
+ evas_object_smart_callback_add(cancel_btn, "clicked", on_naviframe_username_cancel_clicked, ad);
+
+ Evas_Object *done_btn = elm_button_add(ad->nf);
+ elm_object_style_set(done_btn, "naviframe/title_icon");
+ elm_object_text_set(done_btn, "Done");
+ evas_object_smart_callback_add(done_btn, "clicked", on_naviframe_username_done_clicked, ad);
+
+
+ elm_object_item_part_content_set(navi_item, "title_left_btn", cancel_btn);
+ elm_object_item_part_content_set(navi_item, "title_right_btn", done_btn);
+
+ evas_object_data_set(ad->nf, "username_done_btn", (void*)done_btn);
+ evas_object_data_set(ad->nf, "username_cancel_btn", (void*)cancel_btn);
+ //elm_object_disabled_set(done_btn, EINA_TRUE);
+
+}
+
+
--- /dev/null
+/*
+ * tg_settings_view.c
+ *
+ * Created on: Sep 29, 2015
+ * Author: sandeep
+ */
+
+
+#include "tg_settings_view.h"
+#include "server_requests.h"
+#include "tg_set_username_view.h"
+#include "tg_db_wrapper.h"
+
+static Evas_Object* get_image_from_path(const char* path, Evas_Object* parent)
+{
+ if (!path || !parent) {
+ return NULL;
+ }
+ Evas_Object *media_image = elm_image_add(parent);
+ elm_image_aspect_fixed_set(media_image, EINA_FALSE);
+ elm_image_file_set(media_image, path, NULL);
+ evas_object_size_hint_weight_set(media_image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(media_image, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(media_image);
+ return media_image;
+}
+
+static void on_chat_bg_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = data;
+ if (ad && ad->chat_background) {
+#if 0
+ if (strstr(ad->chat_background, ui_utils_get_resource(TG_CHAT_DEFAULT_BG)) != NULL) {
+ show_toast(ad, "Default background");
+ } else {
+ launch_app_control(ad, "image", ad->chat_background);
+ }
+#endif
+ }
+}
+
+Evas_Object* on_settings_info_requested(void *data, Evas_Object *obj, const char *part)
+{
+ Evas_Object *eo = NULL;
+ int id = (int) data;
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+ if (!strcmp(part, "elm.swallow.icon.0")) {
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* user_status_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_status_layout, edj_path, "main_list_name_status_item");
+ evas_object_size_hint_weight_set(user_status_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_status_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_status_layout);
+
+
+ char* first_text = NULL;
+ char buf[512] = {'\0'};
+ if (id == 0) {
+ first_text = "Chat Background";
+ } else {
+ first_text = "";
+ }
+
+ snprintf(buf, 512, "<font=Tizen:style=Bold color=#000000 align=left><font_size=40>%s</font_size></font>", first_text);
+
+ Evas_Object* name_lbl = elm_label_add(ad->nf);
+ elm_object_text_set(name_lbl, buf);
+ evas_object_size_hint_weight_set(name_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(name_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(name_lbl);
+
+ elm_object_part_content_set(user_status_layout, "swallow.name", name_lbl);
+ return user_status_layout;
+ } else if (!strcmp(part, "elm.swallow.end")) {
+ if (ad->chat_background) {
+
+ char *doc_thumb = NULL;
+ get_thumbnail_from_video_url(ad->chat_background, &doc_thumb);
+ Evas_Object *chat_bg = NULL;
+ if (doc_thumb) {
+ chat_bg = get_image_from_path(doc_thumb, ad->nf);
+ } else {
+ chat_bg = get_image_from_path(ad->chat_background, ad->nf);
+ }
+
+ evas_object_data_set(ad->nf, "settings_chat_bg", chat_bg);
+
+ eo = elm_layout_add(obj);
+ elm_layout_theme_set(eo, "layout", "list/C/type.1", "default");
+ elm_layout_content_set(eo, "elm.swallow.content", chat_bg);
+ evas_object_smart_callback_add(chat_bg, "clicked", on_chat_bg_clicked, ad);
+ }
+ }
+ return eo;
+}
+
+
+Evas_Object* on_user_phone_info_requested(void *data, Evas_Object *obj, const char *part)
+{
+ Evas_Object *eo = NULL;
+ int id = (int) data;
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+ if (!strcmp(part, "elm.swallow.icon.0")) {
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* user_status_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_status_layout, edj_path, "main_list_name_status_item");
+ evas_object_size_hint_weight_set(user_status_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_status_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_status_layout);
+
+
+ char* first_text = NULL;
+ char buf[512] = {'\0'};
+ if (id == 0) {
+ if (ad->current_user_data->phone) {
+ first_text = ad->current_user_data->phone;
+ } else {
+ first_text = "";
+ }
+ } else {
+ if (ad->current_user_data->username && strlen(ad->current_user_data->username) > 0 && strstr(ad->current_user_data->username, "_null_") == NULL) {
+ first_text = ad->current_user_data->username;
+ } else {
+ first_text = "None";
+ }
+ }
+
+ snprintf(buf, 512, "<font=Tizen:style=Bold color=#000000 align=left><font_size=40>%s</font_size></font>", first_text);
+
+ Evas_Object* name_lbl = elm_label_add(ad->nf);
+ elm_object_text_set(name_lbl, buf);
+ evas_object_size_hint_weight_set(name_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(name_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(name_lbl);
+
+ if (id == 1) {
+ evas_object_data_set(ad->nf, "settings_user_name_label", name_lbl);
+ }
+
+ elm_object_part_content_set(user_status_layout, "swallow.name", name_lbl);
+
+ char* second_text = NULL;
+ if (id == 0) {
+ second_text = "Phone";
+ } else {
+ second_text = "Username";
+ }
+ char status_buf[126] = {'\0'};
+ sprintf(status_buf, "<font=Tizen:style=Italic color=#808080 align=left><font_size=35>%s</font_size></font>", second_text);
+
+ Evas_Object* status_lbl = elm_label_add(ad->nf);
+ elm_object_text_set(status_lbl, status_buf);
+ evas_object_size_hint_weight_set(status_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(status_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(status_lbl);
+
+ elm_object_part_content_set(user_status_layout, "swallow.status", status_lbl);
+ return user_status_layout;
+ }
+ return eo;
+}
+
+Evas_Object* on_user_info_requested(void *data, Evas_Object *obj, const char *part)
+{
+ Evas_Object *eo = NULL;
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+ if (!strcmp(part, "elm.swallow.icon")) {
+ Evas_Object *profile_pic = NULL;
+
+ if (ad->current_user_data->photo_path && strlen(ad->current_user_data->photo_path) > 0 && strstr(ad->current_user_data->photo_path, "_null_") == NULL) {
+ profile_pic = get_image_from_path(ad->current_user_data->photo_path, ad->nf);
+ } else {
+ profile_pic = get_image_from_path(ui_utils_get_resource(DEFAULT_PROFILE_PIC), ad->nf);
+ }
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* user_pic_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_pic_layout, edj_path, "circle_layout");
+ evas_object_size_hint_weight_set(user_pic_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_pic_layout);
+ elm_object_part_content_set(user_pic_layout, "content", profile_pic);
+
+ evas_object_data_set(ad->nf, "user_profile_pic", profile_pic);
+
+ eo = elm_layout_add(obj);
+ elm_layout_theme_set(eo, "layout", "list/C/type.1", "default");
+ elm_layout_content_set(eo, "elm.swallow.content", user_pic_layout);
+ } else if (!strcmp(part, "elm.swallow.icon.0")) {
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* user_status_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_status_layout, edj_path, "main_list_name_status_item");
+ evas_object_size_hint_weight_set(user_status_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_status_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_status_layout);
+
+
+ char* user_name = replace(ad->current_user_data->print_name, '_', " ");
+ char buf[512] = {'\0'};
+ snprintf(buf, 512, "<font=Tizen:style=Bold color=#FFFFFF align=left><font_size=40>%s</font_size></font>", user_name);
+ free(user_name);
+
+ Evas_Object* name_lbl = elm_label_add(ad->nf);
+ elm_object_text_set(name_lbl, buf);
+ evas_object_size_hint_weight_set(name_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(name_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(name_lbl);
+
+ elm_object_part_content_set(user_status_layout, "swallow.name", name_lbl);
+
+ char* user_status = "online";
+ char status_buf[126] = {'\0'};
+ sprintf(status_buf, "<font=Tizen:style=Italic color=#FFFFFF align=left><font_size=35>%s</font_size></font>", user_status);
+
+ Evas_Object* status_lbl = elm_label_add(ad->nf);
+ elm_object_text_set(status_lbl, status_buf);
+ evas_object_size_hint_weight_set(status_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(status_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(status_lbl);
+
+ elm_object_part_content_set(user_status_layout, "swallow.status", status_lbl);
+ return user_status_layout;
+ } else {
+
+ }
+ return eo;
+}
+
+void on_user_info_item_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ Elm_Object_Item *it = event_info;
+ elm_genlist_item_selected_set(it, EINA_FALSE);
+}
+
+void on_phone_info_item_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ Elm_Object_Item *it = event_info;
+ elm_genlist_item_selected_set(it, EINA_FALSE);
+ int id = (int)data;
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+
+ if (id == 1) {
+ launch_set_username_cb(ad);
+ }
+}
+
+void on_image_select_result_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+{
+ if (result == APP_CONTROL_RESULT_SUCCEEDED) {
+ char* file_path = NULL;
+ char** path_arryay = NULL;
+ int array_length = 0;
+ app_control_get_extra_data_array(reply, APP_CONTROL_DATA_SELECTED, &path_arryay, &array_length);
+
+ for(int i = 0 ; i < array_length ; i++) {
+ file_path = path_arryay[i];
+ if (file_path) {
+ appdata_s *ad = (appdata_s*)user_data;
+ if (ad) {
+ Evas_Object *profile_pic = evas_object_data_get(ad->nf, "user_profile_pic");
+ if (profile_pic) {
+ elm_image_file_set(profile_pic, file_path, NULL);
+ send_set_profile_pic_request(ad->service_client, ad->current_user_data->user_id.id, file_path);
+ }
+ }
+ break;
+ }
+ }
+ }
+}
+
+void on_image_request_option_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *popup = data;
+ int id = 0;
+ Elm_Object_Item *item = event_info;
+
+ id = (int)elm_object_item_data_get(item);
+ app_control_h app_control;
+ int ret = app_control_create(&app_control);
+
+
+ appdata_s *ad = evas_object_data_get(popup, "app_data");
+
+ if(ret != APP_CONTROL_ERROR_NONE) {
+ show_toast(ad, "Error: Can not load image picker");
+ return;
+ }
+
+ if (id == 0) {
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_CREATE_CONTENT);
+ app_control_set_mime(app_control, "image/jpg");
+ app_control_send_launch_request(app_control, &on_image_select_result_cb, ad);
+ } else {
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_PICK);
+ app_control_set_mime(app_control,"image/*");
+ app_control_send_launch_request(app_control, &on_image_select_result_cb, ad);
+ }
+
+ app_control_destroy(app_control);
+ evas_object_del(popup);
+}
+
+char* on_camera_load_text_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ int id = (int) data;
+ if (id == 0) {
+ return strdup("Camera");
+ } else {
+ return strdup("Gallery");
+ }
+}
+
+void on_camera_button_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object* cam_icon = data;
+ appdata_s* ad = evas_object_data_get(data, "app_data");
+ static Elm_Genlist_Item_Class itc;
+ Evas_Object *popup;
+ Evas_Object *box;
+ Evas_Object *genlist;
+ int i;
+ Evas_Object *win = ad->win;
+
+ popup = elm_popup_add(win);
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
+ elm_object_part_text_set(popup, "title,text", "Load image from");
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ evas_object_data_set(popup, "cam_icon", cam_icon);
+ evas_object_data_set(popup, "app_data", ad);
+ /* box */
+ box = elm_box_add(popup);
+ evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ /* genlist */
+ genlist = elm_genlist_add(box);
+ evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ itc.item_style = "default";
+ itc.func.text_get = on_camera_load_text_get_cb;
+ itc.func.content_get = NULL;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+
+ for (i = 0; i < 2; i++) {
+ elm_genlist_item_append(genlist, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_image_request_option_selected_cb, popup);
+ }
+ evas_object_show(genlist);
+ elm_box_pack_end(box, genlist);
+ evas_object_size_hint_min_set(box, -1, 230);
+ elm_object_content_set(popup, box);
+
+ evas_object_show(popup);
+}
+
+
+/**************************************************************************/
+
+
+void on_chat_bg_select_result_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+{
+ if (result == APP_CONTROL_RESULT_SUCCEEDED) {
+ char* file_path = NULL;
+ char** path_arryay = NULL;
+ int array_length = 0;
+ app_control_get_extra_data_array(reply, APP_CONTROL_DATA_SELECTED, &path_arryay, &array_length);
+
+ for(int i = 0 ; i < array_length ; i++) {
+ file_path = path_arryay[i];
+ if (file_path) {
+ appdata_s *ad = (appdata_s*)user_data;
+ if (ad) {
+ Evas_Object *chat_bg = evas_object_data_get(ad->nf, "settings_chat_bg");
+ if (chat_bg) {
+ elm_image_file_set(chat_bg, file_path, NULL);
+
+ preference_set_string(TG_CHAT_BG_PREFERENCE, file_path);
+
+ char *chat_bg = NULL;
+ preference_get_string(TG_CHAT_BG_PREFERENCE, &chat_bg);
+
+ if (ad->chat_background) {
+ free(ad->chat_background);
+ ad->chat_background = NULL;
+ }
+
+ if (chat_bg) {
+ ad->chat_background = strdup(chat_bg);
+ }
+
+ if (!ad->chat_background) {
+ ad->chat_background = strdup(ui_utils_get_resource(TG_CHAT_DEFAULT_BG));
+ preference_set_string(TG_CHAT_BG_PREFERENCE, ad->chat_background);
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+}
+
+
+void on_chat_bg_change_option_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *popup = data;
+ int id = 0;
+ Elm_Object_Item *item = event_info;
+
+ id = (int)elm_object_item_data_get(item);
+ app_control_h app_control;
+ int ret = app_control_create(&app_control);
+
+
+ appdata_s *ad = evas_object_data_get(popup, "app_data");
+
+ if(ret != APP_CONTROL_ERROR_NONE) {
+ show_toast(ad, "Error: Can not load image picker");
+ return;
+ }
+ if (id == 0) {
+
+
+
+ if (ad->chat_background) {
+ free(ad->chat_background);
+ ad->chat_background = NULL;
+ }
+ ad->chat_background = strdup(ui_utils_get_resource(TG_CHAT_DEFAULT_BG));
+ preference_set_string(TG_CHAT_BG_PREFERENCE, ad->chat_background);
+ Evas_Object *chat_bg = evas_object_data_get(ad->nf, "settings_chat_bg");
+ if (chat_bg) {
+ elm_image_file_set(chat_bg, ad->chat_background, NULL);
+ }
+ }else if (id == 1) {
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_CREATE_CONTENT);
+ app_control_set_mime(app_control, "image/jpg");
+ app_control_send_launch_request(app_control, &on_chat_bg_select_result_cb, ad);
+ } else {
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_PICK);
+ app_control_set_mime(app_control,"image/*");
+ app_control_send_launch_request(app_control, &on_chat_bg_select_result_cb, ad);
+ }
+
+ app_control_destroy(app_control);
+ evas_object_del(popup);
+}
+
+
+
+
+char* on_chat_bg_load_text_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ int id = (int) data;
+ if (id == 0) {
+ return strdup("Set default");
+ } else if (id == 1) {
+ return strdup("Camera");
+ } else {
+ return strdup("Gallery");
+ }
+}
+
+
+void on_settings_info_item_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ Elm_Object_Item *it = event_info;
+ elm_genlist_item_selected_set(it, EINA_FALSE);
+
+ Evas_Object* cam_icon = data;
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+ static Elm_Genlist_Item_Class itc;
+ Evas_Object *popup;
+ Evas_Object *box;
+ Evas_Object *genlist;
+ int i;
+ Evas_Object *win = ad->win;
+
+ popup = elm_popup_add(win);
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
+ elm_object_part_text_set(popup, "title,text", "Load image from");
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+
+ evas_object_data_set(popup, "app_data", ad);
+ /* box */
+ box = elm_box_add(popup);
+ evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ /* genlist */
+ genlist = elm_genlist_add(box);
+ evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ itc.item_style = "default";
+ itc.func.text_get = on_chat_bg_load_text_get_cb;
+ itc.func.content_get = NULL;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+
+ for (i = 0; i < 3; i++) {
+ elm_genlist_item_append(genlist, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_chat_bg_change_option_selected_cb, popup);
+ }
+ evas_object_show(genlist);
+ elm_box_pack_end(box, genlist);
+ evas_object_size_hint_min_set(box, -1, 350);
+ elm_object_content_set(popup, box);
+
+ evas_object_show(popup);
+}
+
+/*************************************************************************/
+
+void launch_settings_screen(appdata_s* ad)
+{
+ if (!ad) {
+ return;
+ }
+
+ ad->current_app_state = TG_SETTINGS_SCREEN_STATE;
+
+ if (!ad->current_user_data) {
+ load_registered_user_data(ad);
+ }
+
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+
+ Evas_Object* scroller = elm_scroller_add(ad->nf);
+ elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
+ elm_scroller_policy_set(scroller,ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+
+ Evas_Object* layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(layout, edj_path, "settings_screen");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(layout);
+ elm_object_content_set(scroller, layout);
+
+ /**************** user info *********************/
+ Evas_Object *pic_name_list = NULL;
+ static Elm_Genlist_Item_Class itc;
+ pic_name_list = elm_genlist_add(ad->nf);
+ elm_list_mode_set(pic_name_list, ELM_LIST_COMPRESS);
+ elm_genlist_mode_set(pic_name_list, ELM_LIST_COMPRESS);
+ elm_object_style_set(pic_name_list, "solid/default");
+ evas_object_size_hint_weight_set(pic_name_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(pic_name_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_data_set(pic_name_list, "app_data", ad);
+
+ itc.item_style = "type1";
+ itc.func.text_get = NULL;
+ itc.func.content_get = on_user_info_requested;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+ int i = 1;
+ elm_genlist_item_append(pic_name_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_user_info_item_clicked, (void*) i);
+
+ evas_object_show(pic_name_list);
+ elm_object_part_content_set(layout, "pic_name_layout", pic_name_list);
+ /******************* user Info **********************/
+
+
+ Evas_Object* user_info_lbl = elm_label_add(ad->nf);
+ evas_object_show(user_info_lbl);
+ evas_object_size_hint_weight_set(user_info_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_info_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_object_text_set(user_info_lbl, "<font=Tizen:style=Bold color=#00FFFF align=left><font_size=45> Info</font_size></font>");
+ elm_object_part_content_set(layout, "user_info", user_info_lbl);
+
+
+ /******************** Phone num layout ********************/
+
+ Evas_Object *phone_num_list = NULL;
+ static Elm_Genlist_Item_Class sitc;
+ phone_num_list = elm_genlist_add(ad->nf);
+ elm_list_mode_set(phone_num_list, ELM_LIST_COMPRESS);
+ elm_genlist_mode_set(phone_num_list, ELM_LIST_COMPRESS);
+ evas_object_size_hint_weight_set(phone_num_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(phone_num_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_data_set(phone_num_list, "app_data", ad);
+
+ sitc.item_style = "type1";
+ sitc.func.text_get = NULL;
+ sitc.func.content_get = on_user_phone_info_requested;
+ sitc.func.state_get = NULL;
+ sitc.func.del = NULL;
+ for (int i = 0 ; i < 2; i++) {
+ elm_genlist_item_append(phone_num_list, &sitc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_phone_info_item_clicked, (void*) i);
+ }
+
+ evas_object_show(phone_num_list);
+ elm_object_part_content_set(layout, "phone_num_layout", phone_num_list);
+
+ /******************* Phone Num layout ************************/
+
+ Evas_Object* settings_info_lbl = elm_label_add(ad->nf);
+ evas_object_show(settings_info_lbl);
+ evas_object_size_hint_weight_set(settings_info_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(settings_info_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_object_text_set(settings_info_lbl, "<font=Tizen:style=Bold color=#00FFFF align=left><font_size=45> Settings</font_size></font>");
+ elm_object_part_content_set(layout, "settings_info", settings_info_lbl);
+
+
+
+ /******************** Settings layout ********************/
+
+ Evas_Object *settings_list = NULL;
+ static Elm_Genlist_Item_Class titc;
+ settings_list = elm_genlist_add(ad->nf);
+ elm_list_mode_set(settings_list, ELM_LIST_COMPRESS);
+ elm_genlist_mode_set(settings_list, ELM_LIST_COMPRESS);
+ evas_object_size_hint_weight_set(settings_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(settings_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_data_set(settings_list, "app_data", ad);
+
+ titc.item_style = "type1";
+ titc.func.text_get = NULL;
+ titc.func.content_get = on_settings_info_requested;
+ titc.func.state_get = NULL;
+ titc.func.del = NULL;
+ for (int i = 0 ; i < 1; i++) {
+ elm_genlist_item_append(settings_list, &titc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_settings_info_item_clicked, (void*) i);
+ }
+
+ evas_object_show(settings_list);
+ elm_object_part_content_set(layout, "setting_option_layout", settings_list);
+
+ /******************* Settings layout ************************/
+
+
+
+ //Evas_Object *profile_pic = NULL;
+ //profile_pic = get_image_from_path(ui_utils_get_resource(CAMERA_ICON), ad->nf);
+ /*Evas_Object* user_pic_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_pic_layout, edj_path, "circle_layout");
+ evas_object_size_hint_weight_set(user_pic_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_pic_layout);
+ elm_object_part_content_set(user_pic_layout, "content", profile_pic);
+
+ Evas_Object *eo = elm_layout_add(ad->nf);
+ elm_layout_theme_set(eo, "layout", "list/C/type.3", "default");
+ elm_layout_content_set(eo, "elm.swallow.content", user_pic_layout);*/
+
+ Evas_Object* cam_btn = elm_button_add(ad->layout);
+ evas_object_size_hint_weight_set(cam_btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(cam_btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(cam_btn);
+
+
+ Evas_Object *cam_image = elm_image_add(ad->layout);
+ elm_image_file_set(cam_image, ui_utils_get_resource(CAMERA_ICON), NULL);
+ evas_object_size_hint_weight_set(cam_image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(cam_image, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(cam_image);
+ elm_object_content_set(cam_btn, cam_image);
+
+ elm_object_part_content_set(layout, "cam_layout", cam_btn);
+ evas_object_smart_callback_add(cam_btn, "clicked", on_camera_button_clicked, cam_btn);
+ evas_object_data_set(cam_btn, "app_data", ad);
+
+ Elm_Object_Item* navi_item = elm_naviframe_item_push(ad->nf, "Settings", NULL, NULL, scroller, NULL);
+}
+
app_get_resource(EDJ_CHAT_CONV_FILE, edj_path, (int)PATH_MAX);
elm_layout_file_set(layout, edj_path, "splash_screen");
Evas_Object* progressbar = elm_progressbar_add(layout);
- elm_object_style_set(progressbar, "process_large");
+ elm_object_style_set(progressbar, "process_small");
evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_progressbar_pulse(progressbar, EINA_TRUE);
}
-char* get_budy_state(appdata_s* ad, int buddy_id)
-{
- if (!ad)
- return NULL;
-
-
- char time_str[256]={0,};
- Eina_List* buddy_details_array = get_buddy_info(buddy_id);
- if (buddy_details_array && eina_list_count(buddy_details_array) > 0) {
- Eina_List* buddy_details = eina_list_nth(buddy_details_array, 0);
- if (buddy_details && eina_list_count(buddy_details) > 0) {
- int* temp_online = (int*)eina_list_nth(buddy_details, 12);
- int is_online = *temp_online;
- int* temp_last_seen = (int*)eina_list_nth(buddy_details, 13);
- int last_seen = *temp_last_seen;
-
- char *format = NULL;
- Eina_Bool is_today = compare_date_with_current_date(last_seen);
-
- if (is_online > 0) {
- strcpy(time_str,"online");
- } else {
- time_t t = last_seen;
-
- if (is_today) {
- format = "last seen Today at %I:%M %P";
- } else {
- format = "last seen %d/%b/%Y at %I:%M %P";
- }
-
- struct tm lt;
- char res[256];
- (void) localtime_r(&t, <);
-
- if (strftime(res, sizeof(res), format, <) == 0) {
- (void) fprintf(stderr, "strftime(3): cannot format supplied "
- "date/time into buffer of size %u "
- "using: '%s'\n",
- sizeof(res), format);
- }
- snprintf(time_str, sizeof(time_str), "<align=left><font_size=30><color=#808080>%s</color></font_size></align>", res);
- }
-
- for (int i = 0 ; i < eina_list_count(buddy_details_array); i++) {
- void* val = eina_list_nth(buddy_details, i);
- free(val);
- }
- eina_list_free(buddy_details);
- }
- eina_list_free(buddy_details_array);
- }
- return strdup(time_str);
-}
+
static void on_buddy_item_clicked(void *data, Evas_Object *obj, void *event_info)
{
}
}
+ if (peer_id == -1) {
+ ad->peer_in_cahtting_data = NULL;
+ ad->buddy_in_cahtting_data = NULL;
+ show_toast(ad, "Unable to retrieve buddy details");
+ return;
+ }
+
+ ad->main_item_in_cahtting_data = NULL;
+ for (int i = 0 ; i < eina_list_count(ad->main_list) ; i++) {
+ tg_main_list_item_s *item = eina_list_nth(ad->main_list, i);
+ if (item->peer_id == sel_item->use_data->user_id.id) {
+ ad->main_item_in_cahtting_data = item;
+ break;
+ }
+ }
+
elm_naviframe_item_pop(ad->nf);
launch_messaging_view_cb(ad, peer_id);
}
elm_genlist_item_selected_set(it, EINA_FALSE);
}
+static void on_search_icon_pressed(void *data, Evas_Object *obj, void *event_info)
+{
+ elm_image_file_set(data, ui_utils_get_resource(TG_SEARCH_PRESSED_ICON), NULL);
+}
+
+static void on_search_icon_unpressed(void *data, Evas_Object *obj, void *event_info)
+{
+ elm_image_file_set(data, ui_utils_get_resource(TG_SEARCH_ICON), NULL);
+}
+
void launch_start_messaging_view(appdata_s* ad)
{
if (!ad)
itc1.func.state_get = NULL;
itc1.func.del = NULL;
- int size = eina_list_count(ad->buddy_list);
+ int size = 0;
+ if (ad->buddy_list) {
+ size = eina_list_count(ad->buddy_list);
+ }
if(size > 0) {
for (i = 0; i < size; i++) {
evas_object_size_hint_weight_set(search_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(search_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(search_layout);
- Evas_Object *search_icon = elm_image_add(layout);
- elm_image_file_set(search_icon, ui_utils_get_resource(TG_SEARCH_ICON), NULL);
- evas_object_show(search_icon);
- elm_object_part_content_set(search_layout, "search_box", search_icon);
- evas_object_smart_callback_add(search_icon, "clicked", on_user_list_search_clicked, ad);
+
+ Evas_Object *search_btn = elm_button_add(layout);
+ elm_object_style_set(search_btn, "transparent");
+ evas_object_size_hint_align_set(search_btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_size_hint_weight_set(search_btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ Evas_Object *search_icon = elm_image_add(layout);
+ elm_image_file_set(search_icon, ui_utils_get_resource(TG_SEARCH_ICON), NULL);
+ evas_object_show(search_icon);
+
+ elm_object_content_set(search_btn, search_icon);
+
+ elm_object_part_content_set(search_layout, "search_box", search_btn);
+ evas_object_smart_callback_add(search_icon, "clicked", on_user_list_search_clicked, ad);
+ evas_object_smart_callback_add(search_btn, "pressed", on_search_icon_pressed, search_icon);
+ evas_object_smart_callback_add(search_btn, "unpressed", on_search_icon_unpressed, search_icon);
Elm_Object_Item* navi_item = elm_naviframe_item_push(ad->nf, "<font=Tizen:style=Regular color=#ffffff align=left><font_size=40>New Message</font_size></font>", NULL, NULL, scroller, NULL);
elm_object_item_part_content_set(navi_item, "title_right_btn", search_layout);
--- /dev/null
+/*
+ * tg_user_info_view.c
+ *
+ * Created on: Oct 2, 2015
+ * Author: sandeep
+ */
+
+#include "tg_user_info_view.h"
+#include "server_requests.h"
+#include "tg_user_main_view.h"
+
+static Evas_Object* get_image_from_path(const char* path, Evas_Object* parent)
+{
+ if (!path || !parent) {
+ return NULL;
+ }
+ Evas_Object *media_image = elm_image_add(parent);
+ elm_image_aspect_fixed_set(media_image, EINA_FALSE);
+ elm_image_file_set(media_image, path, NULL);
+ evas_object_size_hint_weight_set(media_image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(media_image, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(media_image);
+ return media_image;
+}
+#if 0
+static Eina_Bool on_view_deleteion_requested(void *data)
+{
+ appdata_s *ad = data;
+ if (ad) {
+ elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_USER_MAIN_VIEW_STATE;
+ hide_loading_popup(ad);
+ }
+ return ECORE_CALLBACK_CANCEL;
+}
+#endif
+void on_user_added_response_received(appdata_s *ad, int buddy_id, Eina_Bool is_success)
+{
+ if (is_success) {
+ if (ad->peer_in_cahtting_data->use_data->peer_id == buddy_id) {
+ if (ad->buddy_in_cahtting_data && ad->buddy_in_cahtting_data->use_data->user_id.id == buddy_id) {
+ ad->buddy_in_cahtting_data->use_data->is_deleted = 0;
+ show_toast(ad, "User added successfully");
+ }
+ }
+ } else {
+ show_toast(ad, "Failed to add user.");
+ }
+}
+
+void on_user_deleted_response_received(appdata_s *ad, int buddy_id, Eina_Bool is_success)
+{
+#if 0
+ if (is_success) {
+ if (ad->peer_in_cahtting_data->use_data->peer_id == buddy_id) {
+ if (ad->buddy_in_cahtting_data && ad->buddy_in_cahtting_data->use_data->user_id.id == buddy_id) {
+
+ show_toast(ad, "User deleted successfully");
+
+ if(ad->peer_list) {
+ int size = eina_list_count(ad->peer_list);
+ for (int i = 0 ; i < size ; i++) {
+ peer_with_pic_s *item = eina_list_nth(ad->peer_list, i);
+ if (item->use_data->peer_id == buddy_id) {
+ ad->peer_list = eina_list_remove(ad->peer_list, item);
+ break;
+ }
+ }
+ }
+
+ if(ad->main_list) {
+ int size = eina_list_count(ad->main_list);
+ for (int i = 0 ; i < size ; i++) {
+ tg_main_list_item_s *item = eina_list_nth(ad->main_list, i);
+ if (item->peer_id == buddy_id) {
+ ad->main_list = eina_list_remove(ad->main_list, item);
+ break;
+ }
+ }
+ }
+
+ if(ad->buddy_list) {
+ int size = eina_list_count(ad->buddy_list);
+ for (int i = 0 ; i < size ; i++) {
+ user_data_with_pic_s *item = eina_list_nth(ad->buddy_list, i);
+ user_data_s* user = item->use_data;
+
+ if (user->user_id.id == buddy_id) {
+ ad->buddy_list = eina_list_remove(ad->buddy_list, item);
+ break;
+ }
+ }
+ }
+
+ refresh_main_list_view(ad, EINA_FALSE);
+ ad->peer_in_cahtting_data = NULL;
+ ad->main_item_in_cahtting_data = NULL;
+
+ elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_CHAT_MESSAGING_VIEW_STATE;
+ /*
+ elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_USER_MAIN_VIEW_STATE;
+ */
+ show_loading_popup(ad);
+ ecore_timer_add(2, on_view_deleteion_requested, ad);
+ }
+ }
+ } else {
+ show_toast(ad, "Failed to delete user.");
+ }
+#else
+ if (is_success) {
+ if (ad->peer_in_cahtting_data->use_data->peer_id == buddy_id) {
+ if (ad->buddy_in_cahtting_data && ad->buddy_in_cahtting_data->use_data->user_id.id == buddy_id) {
+ ad->buddy_in_cahtting_data->use_data->is_deleted = 1;
+ show_toast(ad, "User deleted successfully");
+ }
+ }
+ } else {
+ show_toast(ad, "Failed to delete user.");
+ }
+#endif
+}
+
+void on_user_block_response_received(appdata_s *ad, int buddy_id, Eina_Bool is_success)
+{
+ if (is_success) {
+ if (ad->peer_in_cahtting_data->use_data->peer_id == buddy_id) {
+ if (ad->buddy_in_cahtting_data && ad->buddy_in_cahtting_data->use_data->user_id.id == buddy_id) {
+ ad->buddy_in_cahtting_data->use_data->is_blocked = 1;
+ show_toast(ad, "User blocked successfully");
+ }
+ }
+ } else {
+ show_toast(ad, "Failed to block user.");
+ }
+}
+
+void on_user_unblock_response_received(appdata_s *ad, int buddy_id, Eina_Bool is_success)
+{
+ if (is_success) {
+ if (ad->peer_in_cahtting_data->use_data->peer_id == buddy_id) {
+ if (ad->buddy_in_cahtting_data && ad->buddy_in_cahtting_data->use_data->user_id.id == buddy_id) {
+ ad->buddy_in_cahtting_data->use_data->is_blocked = 0;
+ show_toast(ad, "User unblocked successfully");
+ }
+ }
+ } else {
+ show_toast(ad, "Failed to unblock user.");
+ }
+}
+
+
+static void on_userinfo_menu_canceled(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = evas_object_data_get(obj, "app_data");
+ Evas_Object *popup = evas_object_data_get(obj, "popup");
+ evas_object_del(popup);
+}
+
+static void on_user_block_ok_selected(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = evas_object_data_get(obj, "app_data");
+ Evas_Object *popup = evas_object_data_get(obj, "popup");
+
+ if (ad->peer_in_cahtting_data && ad->peer_in_cahtting_data->use_data) {
+ show_loading_popup(ad);
+ if (ad->buddy_in_cahtting_data && ad->buddy_in_cahtting_data->use_data->is_blocked == 1) {
+ send_unblock_buddy_request(ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id);
+ } else {
+ send_block_buddy_request(ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id);
+ }
+ }
+
+ evas_object_del(popup);
+}
+
+static void on_block_selected_cb(appdata_s *ad)
+{
+ Evas_Object *popup, *btn;
+
+ /* popup */
+ popup = elm_popup_add(ad->nf);
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+
+ if (ad->buddy_in_cahtting_data && ad->buddy_in_cahtting_data->use_data->is_blocked == 1) {
+ elm_object_text_set(popup,"Are you sure want to unblock this contact?");
+ } else {
+ elm_object_text_set(popup,"Are you sure want to block this contact?");
+ }
+
+ /* ok button */
+ btn = elm_button_add(popup);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, "OK");
+ elm_object_part_content_set(popup, "button1", btn);
+ evas_object_smart_callback_add(btn, "clicked", on_user_block_ok_selected, ad);
+ evas_object_data_set(btn, "app_data", ad);
+ evas_object_data_set(btn, "popup", popup);
+
+ /* cancel button */
+ btn = elm_button_add(popup);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, "Cancel");
+ elm_object_part_content_set(popup, "button2", btn);
+ evas_object_smart_callback_add(btn, "clicked", on_userinfo_menu_canceled, ad);
+ evas_object_data_set(btn, "app_data", ad);
+ evas_object_data_set(btn, "popup", popup);
+
+ evas_object_show(popup);
+}
+
+/************************ delete user *****************************/
+
+static void on_user_delete_ok_selected(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = evas_object_data_get(obj, "app_data");
+ Evas_Object *popup = evas_object_data_get(obj, "popup");
+
+ if (ad->peer_in_cahtting_data && ad->peer_in_cahtting_data->use_data) {
+ show_loading_popup(ad);
+
+ if (ad->buddy_in_cahtting_data && ad->buddy_in_cahtting_data->use_data->is_deleted == 1) {
+ send_add_buddy_request(ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id);
+ } else {
+ send_delete_buddy_request(ad->service_client, ad->peer_in_cahtting_data->use_data->peer_id);
+ }
+
+ }
+ evas_object_del(popup);
+}
+
+
+
+static void on_delete_selected_cb(appdata_s *ad)
+{
+ Evas_Object *popup, *btn;
+
+ /* popup */
+ popup = elm_popup_add(ad->nf);
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+
+
+ if (ad->buddy_in_cahtting_data && ad->buddy_in_cahtting_data->use_data->is_deleted == 1) {
+ elm_object_text_set(popup,"Are you sure want to add this contact?");
+ } else {
+ elm_object_text_set(popup,"Are you sure want to delete this contact?");
+ }
+
+
+ /* ok button */
+ btn = elm_button_add(popup);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, "OK");
+ elm_object_part_content_set(popup, "button1", btn);
+ evas_object_smart_callback_add(btn, "clicked", on_user_delete_ok_selected, ad);
+ evas_object_data_set(btn, "app_data", ad);
+ evas_object_data_set(btn, "popup", popup);
+
+ /* cancel button */
+ btn = elm_button_add(popup);
+ elm_object_style_set(btn, "popup");
+ elm_object_text_set(btn, "Cancel");
+ elm_object_part_content_set(popup, "button2", btn);
+ evas_object_smart_callback_add(btn, "clicked", on_userinfo_menu_canceled, ad);
+ evas_object_data_set(btn, "app_data", ad);
+ evas_object_data_set(btn, "popup", popup);
+
+ evas_object_show(popup);
+}
+
+
+
+/************************ delete user *****************************/
+
+/************************ Menu Handler ********************/
+
+void on_user_info_menu_option_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = data;
+
+
+ Elm_Object_Item *it = event_info;
+ elm_genlist_item_selected_set(it, EINA_FALSE);
+ int id = (int)elm_object_item_data_get(it);
+
+
+ peer_with_pic_s *sel_item = ad->peer_in_cahtting_data;
+ tg_peer_info_s *user_data = sel_item->use_data;
+
+ if (!sel_item || !user_data) {
+ show_toast(ad, "Failed to get user info.");
+ return;
+ }
+
+ if (user_data->peer_type == TGL_PEER_USER) {
+
+ if (id == 0) {
+ on_block_selected_cb(ad);
+ } else if (id == 1) {
+ on_delete_selected_cb(ad);
+ } else {
+
+ }
+
+ } else if (user_data->peer_type == TGL_PEER_CHAT) {
+
+
+ }
+
+ if (ad->msg_popup) {
+ evas_object_del(ad->msg_popup);
+ ad->msg_popup = NULL;
+ }
+}
+
+
+char* on_user_info_menu_group_text_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ int id = (int) data;
+ if (id == 0) {
+ return strdup("Add member");
+ } else if (id == 1) {
+ return strdup("Edit Name");
+ } else {
+ return strdup("Delete and leave group");
+ }
+}
+
+char* on_user_info_menu_text_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ int id = (int) data;
+
+ appdata_s *ad = evas_object_data_get(obj, "app_data");
+
+ if (id == 0) {
+ if (ad && ad->buddy_in_cahtting_data && ad->buddy_in_cahtting_data->use_data->is_blocked == 1) {
+ return strdup("UnBlock");
+ } else {
+ return strdup("Block");
+ }
+
+ } else {
+ if (ad && ad->buddy_in_cahtting_data && ad->buddy_in_cahtting_data->use_data->is_deleted == 1) {
+ return strdup("Add");
+ } else {
+ return strdup("Delete");
+ }
+ }
+}
+
+void on_user_info_msg_popup_back_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = data;
+ if (ad->msg_popup) {
+ evas_object_del(ad->msg_popup);
+ ad->msg_popup = NULL;
+ }
+}
+
+void on_user_info_menu_button_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = data;
+ if (ad->msg_popup || ad->current_app_state != TG_SET_USER_INFO_STATE) {
+ return;
+ }
+
+ static Elm_Genlist_Item_Class itc;
+ //Evas_Object *popup;
+ Evas_Object *box;
+ Evas_Object *genlist;
+ int i;
+ Evas_Object *win = ad->win;
+
+ ad->msg_popup = elm_popup_add(win);
+ elm_popup_align_set(ad->msg_popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(ad->msg_popup, EEXT_CALLBACK_BACK, on_user_info_msg_popup_back_cb, ad);
+ evas_object_size_hint_weight_set(ad->msg_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ evas_object_data_set(ad->msg_popup, "app_data", ad);
+ box = elm_box_add(ad->msg_popup);
+ evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ genlist = elm_genlist_add(box);
+ evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ itc.item_style = "default";
+ peer_with_pic_s *sel_item = ad->peer_in_cahtting_data;
+ if (sel_item->use_data->peer_type == TGL_PEER_USER) {
+ itc.func.text_get = on_user_info_menu_text_get_cb;
+
+ itc.func.content_get = NULL;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+
+ for (i = 0; i < 2; i++) {
+ elm_genlist_item_append(genlist, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_user_info_menu_option_selected_cb, ad);
+ }
+
+ } else if (sel_item->use_data->peer_type == TGL_PEER_CHAT) {
+ itc.func.text_get = on_user_info_menu_group_text_get_cb;
+
+ itc.func.content_get = NULL;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+
+ for (i = 0; i < 3; i++) {
+ elm_genlist_item_append(genlist, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_user_info_menu_option_selected_cb, ad);
+ }
+
+ } else {
+
+ }
+ evas_object_data_set(genlist, "app_data", ad);
+
+ evas_object_show(genlist);
+ elm_box_pack_end(box, genlist);
+ evas_object_size_hint_min_set(box, -1, 230);
+ elm_object_content_set(ad->msg_popup, box);
+ evas_object_show(ad->msg_popup);
+}
+
+
+/************************ Menu Handler ********************/
+
+
+
+
+Evas_Object* on_buddy_info_requested(void *data, Evas_Object *obj, const char *part)
+{
+ Evas_Object *eo = NULL;
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+ if (!strcmp(part, "elm.swallow.icon")) {
+ Evas_Object *profile_pic = NULL;
+
+ if (ad->peer_in_cahtting_data->use_data->photo_path && strlen(ad->peer_in_cahtting_data->use_data->photo_path) > 0 && strstr(ad->peer_in_cahtting_data->use_data->photo_path, "_null_") == NULL) {
+ profile_pic = get_image_from_path(ad->peer_in_cahtting_data->use_data->photo_path, ad->nf);
+ } else {
+ profile_pic = get_image_from_path(ui_utils_get_resource(DEFAULT_PROFILE_PIC), ad->nf);
+ }
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* user_pic_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_pic_layout, edj_path, "circle_layout");
+ evas_object_size_hint_weight_set(user_pic_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_pic_layout);
+ elm_object_part_content_set(user_pic_layout, "content", profile_pic);
+
+ evas_object_data_set(ad->nf, "user_profile_pic", profile_pic);
+
+ eo = elm_layout_add(obj);
+ elm_layout_theme_set(eo, "layout", "list/C/type.1", "default");
+ elm_layout_content_set(eo, "elm.swallow.content", user_pic_layout);
+ } else if (!strcmp(part, "elm.swallow.icon.0")) {
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* user_status_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_status_layout, edj_path, "main_list_name_status_item");
+ evas_object_size_hint_weight_set(user_status_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_status_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_status_layout);
+
+
+ char* user_name = replace(ad->peer_in_cahtting_data->use_data->print_name, '_', " ");
+ char buf[512] = {'\0'};
+ snprintf(buf, 512, "<font=Tizen:style=Bold color=#FFFFFF align=left><font_size=40>%s</font_size></font>", user_name);
+ free(user_name);
+
+ Evas_Object* name_lbl = elm_label_add(ad->nf);
+ elm_object_text_set(name_lbl, buf);
+ evas_object_size_hint_weight_set(name_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(name_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(name_lbl);
+
+ elm_object_part_content_set(user_status_layout, "swallow.name", name_lbl);
+
+ Evas_Object *profile_time = evas_object_data_get(ad->nf, "profile_time");
+ char *online_status = "";
+ if (profile_time) {
+ online_status = elm_entry_markup_to_utf8(elm_object_text_get(profile_time));
+ }
+
+ //char* user_status = "online";
+ char status_buf[126] = {'\0'};
+ sprintf(status_buf, "<font=Tizen:style=Italic color=#FFFFFF align=left><font_size=35>%s</font_size></font>", online_status);
+
+ Evas_Object* status_lbl = elm_label_add(ad->nf);
+ elm_object_text_set(status_lbl, status_buf);
+ evas_object_size_hint_weight_set(status_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(status_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(status_lbl);
+
+ elm_object_part_content_set(user_status_layout, "swallow.status", status_lbl);
+ return user_status_layout;
+ } else {
+
+ }
+ return eo;
+}
+
+Evas_Object* on_buddy_phone_info_requested(void *data, Evas_Object *obj, const char *part)
+{
+ Evas_Object *eo = NULL;
+ int id = (int) data;
+ appdata_s* ad = evas_object_data_get(obj, "app_data");
+ if (!strcmp(part, "elm.swallow.icon.0")) {
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* user_status_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_status_layout, edj_path, "main_list_name_status_item");
+ evas_object_size_hint_weight_set(user_status_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_status_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_status_layout);
+
+
+ char* first_text = NULL;
+ char buf[512] = {'\0'};
+ if (id == 0) {
+ if (ad->buddy_in_cahtting_data->use_data->phone) {
+ first_text = ad->buddy_in_cahtting_data->use_data->phone;
+ } else {
+ first_text = "";
+ }
+ } else {
+ if (ad->buddy_in_cahtting_data->use_data->username && strlen(ad->buddy_in_cahtting_data->use_data->username) > 0 && strstr(ad->buddy_in_cahtting_data->use_data->username, "_null_") == NULL) {
+ first_text = ad->buddy_in_cahtting_data->use_data->username;
+ } else {
+ first_text = "None";
+ }
+ }
+
+ snprintf(buf, 512, "<font=Tizen:style=Bold color=#000000 align=left><font_size=40>%s</font_size></font>", first_text);
+
+ Evas_Object* name_lbl = elm_label_add(ad->nf);
+ elm_object_text_set(name_lbl, buf);
+ evas_object_size_hint_weight_set(name_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(name_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(name_lbl);
+
+ if (id == 1) {
+ evas_object_data_set(ad->nf, "settings_user_name_label", name_lbl);
+ }
+
+ elm_object_part_content_set(user_status_layout, "swallow.name", name_lbl);
+
+ char* second_text = NULL;
+ if (id == 0) {
+ second_text = "Phone";
+ } else {
+ second_text = "Username";
+ }
+ char status_buf[126] = {'\0'};
+ sprintf(status_buf, "<font=Tizen:style=Italic color=#808080 align=left><font_size=35>%s</font_size></font>", second_text);
+
+ Evas_Object* status_lbl = elm_label_add(ad->nf);
+ elm_object_text_set(status_lbl, status_buf);
+ evas_object_size_hint_weight_set(status_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(status_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(status_lbl);
+
+ elm_object_part_content_set(user_status_layout, "swallow.status", status_lbl);
+ return user_status_layout;
+ }
+ return eo;
+}
+
+void on_message_button_clicked(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = data;
+ if (ad) {
+ elm_naviframe_item_pop(ad->nf);
+ ad->current_app_state = TG_CHAT_MESSAGING_VIEW_STATE;
+ }
+}
+
+void launch_user_info_screen(appdata_s* ad, int peer_id)
+{
+ if (!ad) {
+ return;
+ }
+ if (ad->msg_popup) {
+ evas_object_del(ad->msg_popup);
+ ad->msg_popup = NULL;
+ }
+
+ ad->current_app_state = TG_SET_USER_INFO_STATE;
+
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+
+ Evas_Object* scroller = elm_scroller_add(ad->nf);
+ elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
+ elm_scroller_policy_set(scroller,ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+
+ Evas_Object* layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(layout, edj_path, "settings_screen");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(layout);
+ elm_object_content_set(scroller, layout);
+
+
+ /**************** user info *********************/
+ Evas_Object *pic_name_list = NULL;
+ static Elm_Genlist_Item_Class itc;
+ pic_name_list = elm_genlist_add(ad->nf);
+ elm_list_mode_set(pic_name_list, ELM_LIST_COMPRESS);
+ elm_genlist_mode_set(pic_name_list, ELM_LIST_COMPRESS);
+ elm_object_style_set(pic_name_list, "solid/default");
+ evas_object_size_hint_weight_set(pic_name_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(pic_name_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_data_set(pic_name_list, "app_data", ad);
+
+ itc.item_style = "type1";
+ itc.func.text_get = NULL;
+ itc.func.content_get = on_buddy_info_requested;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+ int i = 1;
+ elm_genlist_item_append(pic_name_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
+
+ evas_object_show(pic_name_list);
+ elm_object_part_content_set(layout, "pic_name_layout", pic_name_list);
+ /******************* user Info **********************/
+
+
+ Evas_Object* user_info_lbl = elm_label_add(ad->nf);
+ evas_object_show(user_info_lbl);
+ evas_object_size_hint_weight_set(user_info_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_info_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_object_text_set(user_info_lbl, "<font=Tizen:style=Bold color=#00FFFF align=left><font_size=45> Info</font_size></font>");
+ elm_object_part_content_set(layout, "user_info", user_info_lbl);
+
+
+ /******************** Phone num layout ********************/
+
+ Evas_Object *phone_num_list = NULL;
+ static Elm_Genlist_Item_Class sitc;
+ phone_num_list = elm_genlist_add(ad->nf);
+ elm_list_mode_set(phone_num_list, ELM_LIST_COMPRESS);
+ elm_genlist_mode_set(phone_num_list, ELM_LIST_COMPRESS);
+ evas_object_size_hint_weight_set(phone_num_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(phone_num_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_data_set(phone_num_list, "app_data", ad);
+
+ sitc.item_style = "type1";
+ sitc.func.text_get = NULL;
+ sitc.func.content_get = on_buddy_phone_info_requested;
+ sitc.func.state_get = NULL;
+ sitc.func.del = NULL;
+ for (int i = 0 ; i < 2; i++) {
+ elm_genlist_item_append(phone_num_list, &sitc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
+ }
+
+ evas_object_show(phone_num_list);
+ elm_object_part_content_set(layout, "phone_num_layout", phone_num_list);
+
+ /******************* Phone Num layout ************************/
+
+ Evas_Object *settings_info_lbl_bg = elm_object_part_content_get(layout, "settings_info,bg");
+ if (settings_info_lbl_bg) {
+ evas_object_hide(settings_info_lbl_bg);
+ }
+
+
+ Evas_Object* msg_btn = elm_button_add(ad->layout);
+ evas_object_size_hint_weight_set(msg_btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(msg_btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(msg_btn);
+
+
+ Evas_Object *msg_image = elm_image_add(ad->layout);
+ elm_image_file_set(msg_image, ui_utils_get_resource(FLOATING_MSG_ICON), NULL);
+ evas_object_size_hint_weight_set(msg_image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(msg_image, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(msg_image);
+ elm_object_content_set(msg_btn, msg_image);
+
+ elm_object_part_content_set(layout, "cam_layout", msg_btn);
+ evas_object_smart_callback_add(msg_btn, "clicked", on_message_button_clicked, ad);
+ evas_object_data_set(msg_btn, "app_data", ad);
+
+ Elm_Object_Item* navi_item = elm_naviframe_item_push(ad->nf, "User Info", NULL, NULL, scroller, NULL);
+ eext_object_event_callback_add(ad->nf, EEXT_CALLBACK_MORE, on_user_info_menu_button_clicked, ad);
+
+}
+
#include "tg_start_messaging_view.h"
#include "tg_messaging_view.h"
#include "contact_selection_view.h"
+#include "tg_search_peer_view.h"
+#include "tg_settings_view.h"
+#include "tg_db_manager.h"
+#include "server_requests.h"
static Evas_Object *create_image_object_from_file(const char *icon_name, Evas_Object *parent)
{
static void on_new_message_clicked(void *data, Evas_Object *obj, void *event_info)
{
appdata_s* ad = data;
+
+ if (!ad->buddy_list || eina_list_count(ad->buddy_list) <= 0) {
+ load_buddy_list_data(ad);
+ }
+#if 0
+ if (ad->panel) {
+ Evas_Object *panel_list = evas_object_data_get(ad->panel, "panel_list");
+ if (panel_list) {
+ evas_object_del(panel_list);
+ }
+ evas_object_del(ad->panel);
+ ad->panel = NULL;
+ }
+#endif
launch_start_messaging_view(ad);
}
return NULL;
}
+static void launch_contact_picker(appdata_s* ad)
+{
+ app_control_h app_control;
+ int ret = app_control_create(&app_control);
+
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_COMPOSE);
+ app_control_set_app_id(app_control, "tizen.messages");
+ //app_control_add_extra_data(app_control, APP_CONTROL_DATA_TO, recipient);
+ char *text = "Invite you to telegram! https://telegram.org/dl";
+ app_control_add_extra_data(app_control, APP_CONTROL_DATA_TEXT, text);
+ if (app_control_send_launch_request(app_control, NULL, NULL) == APP_CONTROL_ERROR_NONE) {
+ // sms view launched
+ }
+ app_control_destroy(app_control);
+}
+
static void on_menu_item_selected(void *data, Evas_Object *obj, void *event_info)
{
//int index __attribute__((unused)) = (int)data;
appdata_s* ad = evas_object_data_get(obj, "app_data");
int id = (int) data;
- if (id == 0) {
+ if (id == 0) { // new group
launch_contact_selction_view(ad);
- }
+ } else if (id == 1) { // new sec chat
+
+ } else if (id == 2) { // contacts
+ launch_start_messaging_view(ad);
+ } else if (id == 3) { // invite friends
+ launch_contact_picker(ad);
+ } else if (id == 4) { // settings
+ launch_settings_screen(ad);
+ } else {
+ }
+ elm_panel_hidden_set(ad->panel, EINA_TRUE);
}
static void on_menu_list_clicked_cb(void *data, Evas_Object *obj, void *event_info)
elm_genlist_item_selected_set(it, EINA_FALSE);
}
-Evas_Object* create_side_panel_list(appdata_s *ad, Evas_Object *parent)
+Evas_Object* create_side_panel_list(appdata_s* ad, Evas_Object *parent)
{
- char edj_path[PATH_MAX] = {0, };
- Evas_Object *scroller;
- Evas_Object *layout;
- Evas_Object *user_info_layout;
- Evas_Object *profile_pic;
- Evas_Object *user_pic_layout;
- Evas_Object *user_name;
- Evas_Object *phone_no_lbl;
- Evas_Object *menu_gen_list;
- const char *tmp;
- char *full_name;
- char *phone_no;
- int full_name_len;
- int i;
- static Elm_Genlist_Item_Class itc = {
- .item_style = "type1",
- .func.text_get = on_menu_item_name_get_cb,
- .func.content_get = on_menu_item_image_get_cb,
- .func.state_get = NULL,
- .func.del = NULL,
- };
+ char edj_path[PATH_MAX] = {0, };
app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
- scroller = elm_scroller_add(ad->nf);
+ Evas_Object* scroller = elm_scroller_add(ad->nf);
elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
elm_scroller_policy_set(scroller,ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
- layout = elm_layout_add(ad->nf);
+ Evas_Object* layout = elm_layout_add(ad->nf);
elm_layout_file_set(layout, edj_path, "user_main_screen_side_panel");
evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(layout);
elm_object_content_set(scroller, layout);
- user_info_layout = elm_layout_add(ad->nf);
+
+ Evas_Object* user_info_layout = elm_layout_add(ad->nf);
elm_layout_file_set(user_info_layout, edj_path, "menu_user_layout");
evas_object_size_hint_weight_set(user_info_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(user_info_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(user_info_layout);
elm_object_part_content_set(layout, "main_box", user_info_layout);
+ Evas_Object *profile_pic = NULL;
/*********** user info ********************/
- profile_pic = create_image_object_from_file(ui_utils_get_resource(DEFAULT_PROFILE_PIC), ad->nf);
+ if (ad->current_user_data->photo_path && strlen(ad->current_user_data->photo_path) > 0 && strstr(ad->current_user_data->photo_path, "_null_") == NULL) {
+ profile_pic = create_image_object_from_file(ad->current_user_data->photo_path, ad->nf);
+ } else {
+ profile_pic = create_image_object_from_file(ui_utils_get_resource(DEFAULT_PROFILE_PIC), ad->nf);
+ }
- user_pic_layout = elm_layout_add(ad->nf);
- elm_layout_file_set(user_pic_layout, edj_path, "circle_layout");
+ Evas_Object *user_pic_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_pic_layout, edj_path, "main_circle_layout");
evas_object_size_hint_weight_set(user_pic_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(user_pic_layout);
elm_object_part_content_set(user_info_layout, "user_photo_box", user_pic_layout);
- full_name_len = 0;
- if (ad->current_user_data.first_name) {
- full_name_len += strlen(ad->current_user_data.first_name) + 1;
- }
+ evas_object_data_set(ad->nf, "main_user_profile_pic", profile_pic);
+
+
+ char* full_name = NULL;
+ /*
+ if (ad->current_user_data.first_name && ad->current_user_data.last_name) {
+ full_name =(char*)malloc(strlen(ad->current_user_data.first_name) + strlen(" ") + strlen(ad->current_user_data.last_name) + 1);
+ strcpy(full_name, ad->current_user_data.first_name);
+ strcat(full_name, " ");
+ strcat(full_name, ad->current_user_data.last_name);
+ } else if (ad->current_user_data.first_name) {
+ full_name =(char*)malloc(strlen(ad->current_user_data.first_name) + strlen(" ") + strlen(ad->current_user_data.last_name) + 1);
+ strcpy(full_name, ad->current_user_data.first_name);
+ strcat(full_name, " ");
+ strcat(full_name, ad->current_user_data.last_name);
+ }*/
- if (ad->current_user_data.last_name) {
- full_name_len += strlen(ad->current_user_data.last_name) + 1;
+ if (ad->current_user_data->print_name) {
+ full_name = replace(ad->current_user_data->print_name, '_', " ");
+ } else {
+ full_name = strdup("");
}
- if (full_name_len) {
- full_name = malloc(full_name_len);
- if (!full_name) {
- evas_object_del(scroller);
- evas_object_del(layout);
- evas_object_del(user_info_layout);
- evas_object_del(profile_pic);
- evas_object_del(user_pic_layout);
- return NULL;
- }
- snprintf(full_name, full_name_len, "%s%s%s",
- ad->current_user_data.first_name ? ad->current_user_data.first_name : "",
- ad->current_user_data.first_name ? " " : "",
- ad->current_user_data.last_name ? ad->current_user_data.last_name : "");
+
+ char* phone_no = NULL;
+ if (ad->current_user_data->phone) {
+ phone_no = (char*)malloc(strlen(ad->current_user_data->phone) + strlen("+") + 1);
+ strcpy(phone_no, "+");
+ strcat(phone_no, ad->current_user_data->phone);
} else {
- full_name = NULL;
+ phone_no = strdup("");
}
- if (ad->current_user_data.phone) {
- int len;
- len = strlen(ad->current_user_data.phone) + strlen("+");
- phone_no = malloc(len + 1);
- if (!phone_no) {
- free(full_name);
- evas_object_del(scroller);
- evas_object_del(layout);
- evas_object_del(user_info_layout);
- evas_object_del(profile_pic);
- evas_object_del(user_pic_layout);
- return NULL;
- }
+ char temp_full_name[256];
+ sprintf(temp_full_name, "<font=Tizen:style=Bold color=#000000 align=center><font_size=30>%s</font_size></font>", full_name);
+
+
+ char temp_phone_no[256];
+ sprintf(temp_phone_no, "<font=Tizen:style=Bold color=#000000 align=center><font_size=30>%s</font_size></font>", phone_no);
- snprintf(phone_no, len, "+%s", ad->current_user_data.phone);
- }
- user_name = elm_label_add(ad->nf);
- tmp = tg_common_to_string("<font=Tizen:style=Bold color=#000000 align=center><font_size=30>%s</font_size></font>", full_name);
- elm_object_text_set(user_name, tmp);
+ Evas_Object* user_name = elm_label_add(ad->nf);
+ elm_object_text_set(user_name, temp_full_name);
elm_label_ellipsis_set(user_name, EINA_TRUE);
evas_object_show(user_name);
elm_object_part_content_set(user_info_layout, "user_name_box", user_name);
- phone_no_lbl = elm_label_add(ad->nf);
- tmp = tg_common_to_string("<font=Tizen:style=Bold color=#000000 align=center><font_size=30>%s</font_size></font>", phone_no);
- elm_object_text_set(phone_no_lbl, tmp);
+ Evas_Object* phone_no_lbl = elm_label_add(ad->nf);
+ elm_object_text_set(phone_no_lbl, temp_phone_no);
elm_label_ellipsis_set(phone_no_lbl, EINA_TRUE);
evas_object_show(phone_no_lbl);
elm_object_part_content_set(user_info_layout, "phone_number_box", phone_no_lbl);
+
free(full_name);
free(phone_no);
+
/*********** user info ********************/
- menu_gen_list = elm_genlist_add(parent);
+
+
+ Evas_Object* menu_gen_list = elm_genlist_add(parent);
elm_list_mode_set(menu_gen_list, ELM_LIST_COMPRESS);
elm_genlist_mode_set(menu_gen_list, ELM_LIST_COMPRESS);
evas_object_size_hint_weight_set(menu_gen_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_data_set(menu_gen_list, "app_data", ad);
- for (i = 0; i < NUMBER_OF_MENU_ITEMS; i++) {
+ static Elm_Genlist_Item_Class itc;
+ itc.item_style = "type1";
+ itc.func.text_get = on_menu_item_name_get_cb;
+ itc.func.content_get = on_menu_item_image_get_cb;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+
+ for (int i = 0; i < NUMBER_OF_MENU_ITEMS; i++) {
elm_genlist_item_append(menu_gen_list, &itc, (void *)i, NULL, ELM_GENLIST_ITEM_NONE, on_menu_item_selected, (void*)i);
}
-
evas_object_show(menu_gen_list);
elm_object_part_content_set(layout, "options_box", menu_gen_list);
evas_object_smart_callback_add(menu_gen_list, "selected", on_menu_list_clicked_cb, ad);
-
return scroller;
+
}
+
void on_side_panel_scroll_clicked(void *data, Evas_Object *obj, void *event_info)
{
Elm_Panel_Scroll_Info *ev = event_info;
Evas_Object *bg = data;
- int col;
-
- col = 127 * ev->rel_x;
+ int col = 127 * ev->rel_x;
evas_object_color_set(bg, 0, 0, 0, col);
}
void create_side_main_view(appdata_s *ad)
{
- if (ad->panel) {
- Evas_Object *panel_list = evas_object_data_get(ad->panel, "panel_list");
- if (panel_list) {
- evas_object_del(panel_list);
- }
- evas_object_del(ad->panel);
- ad->panel = NULL;
- }
-
ad->panel = create_side_panel(ad->layout);
elm_object_part_content_set(ad->layout, "elm.swallow.left", ad->panel);
Evas_Object *panel_list = create_side_panel_list(ad, ad->panel);
if (!ad)
return;
- if (!elm_object_disabled_get(ad->panel))
- elm_panel_toggle(ad->panel);
+ if (ad->current_app_state == TG_USER_MAIN_VIEW_STATE) {
+
+ if (ad->panel == NULL) {
+ create_side_main_view(ad);
+ }
+ if (!elm_object_disabled_get(ad->panel))
+ elm_panel_toggle(ad->panel);
+ }
return;
}
-void on_main_chat_item_clicked(void *data, Evas_Object *obj, void *event_info)
+/******************** long press menu *******************************************/
+
+
+char* on_longpress_group_menu_text_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ int id = (int) data;
+ if (id == 0) {
+ return strdup("Clear history");
+ } else {
+ return strdup("Delete and exit");
+ }
+}
+
+char* on_longpress_single_menu_text_get_cb(void *data, Evas_Object *obj, const char *part)
+{
+ int id = (int) data;
+ if (id == 0) {
+ return strdup("Clear history");
+ } else {
+ return strdup("Delete");
+ }
+}
+
+/******************** long press menu *******************************************/
+void on_chat_long_press_option_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *popup = data;
+ appdata_s *ad = (appdata_s*)evas_object_data_get(popup, "app_data");
+ tg_main_list_item_s *sel_item = (tg_main_list_item_s*)evas_object_data_get(popup, "selected_chat_item");
+ int item_id = (int)evas_object_data_get(popup, "selected_chat_item_index");
+
+
+
+ Elm_Object_Item *it = event_info;
+ elm_genlist_item_selected_set(it, EINA_FALSE);
+ int id = (int)elm_object_item_data_get(it);
+
+ if (id == 0) {
+ if (sel_item->peer_type == TGL_PEER_USER || sel_item->peer_type == TGL_PEER_CHAT) {
+ char* tablename = get_table_name_from_number(sel_item->peer_id);
+ delete_all_records(tablename);
+ free(tablename);
+
+ //change item in list
+ sel_item->last_message = strdup(" ");
+ sel_item->last_msg_id = -1;
+ sel_item->last_msg_type = -1;
+ sel_item->is_out_msg = -1;
+ sel_item->last_msg_status = -1;
+ sel_item->number_of_unread_msgs = 0;
+
+ if (sel_item->status_lbl) {
+ char *org_msg = "";
+ elm_object_text_set(sel_item->status_lbl, org_msg);
+ }
+ if (sel_item->date_lbl) {
+ Eina_Bool is_today = compare_date_with_current_date(sel_item->last_seen_time);
+
+ if (is_today) {
+ elm_object_text_set(sel_item->date_lbl, "<font=Tizen:style=Italic color=#000000 align=center><font_size=25>Today</font_size></font>");
+ } else {
+ char *format = NULL;
+ time_t t = sel_item->last_seen_time;
+ format = "%d/%b/%Y";
+ struct tm lt;
+ char res[256];
+ (void) localtime_r(&t, <);
+
+ if (strftime(res, sizeof(res), format, <) == 0) {
+ (void) fprintf(stderr, "strftime(3): cannot format supplied "
+ "date/time into buffer of size %u "
+ "using: '%s'\n",
+ sizeof(res), format);
+ }
+
+ char time_str[256]={0,};
+ snprintf(time_str, sizeof(time_str), "<font=Tizen:style=Italic color=#000000 align=center><font_size=25>%s</font_size></font>", res);
+
+ elm_object_text_set(sel_item->date_lbl,time_str);
+ }
+ }
+ if (sel_item->msg_status_lbl) {
+ Evas_Object* temp_lbl = elm_object_part_content_get(sel_item->msg_status_lbl, "swallow.status");
+ if (temp_lbl) {
+ evas_object_del(temp_lbl);
+ }
+ Evas_Object* num_lbl = elm_label_add(ad->nf);
+ elm_object_style_set(num_lbl, "transparent");
+ elm_object_text_set(num_lbl, "");
+ evas_object_size_hint_weight_set(num_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(num_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(num_lbl);
+ elm_object_part_content_set(sel_item->msg_status_lbl, "swallow.status", num_lbl);
+ }
+
+ } else {
+
+ }
+
+ } else if (id == 1) {
+ if (sel_item->peer_type == TGL_PEER_USER) {
+ char* tablename = get_table_name_from_number(sel_item->peer_id);
+ delete_all_records(tablename);
+ free(tablename);
+
+ // delete from main list
+
+ if (sel_item->peer_print_name) {
+ free(sel_item->peer_print_name);
+ sel_item->peer_print_name = NULL;
+ }
+ if (sel_item->last_message) {
+ free(sel_item->last_message);
+ sel_item->last_message = NULL;
+ }
+ if (sel_item->profile_pic_path) {
+ free(sel_item->profile_pic_path);
+ sel_item->profile_pic_path = NULL;
+ }
+ sel_item->date_lbl = NULL;
+ sel_item->msg_status_lbl = NULL;
+ sel_item->profile_pic = NULL;
+ sel_item->profile_pic_path = NULL;
+ sel_item->status_lbl = NULL;
+ sel_item->user_name_lbl = NULL;
+
+ //ad->main_list
+ ad->main_list = eina_list_remove(ad->main_list, sel_item);
+ refresh_main_list_view(ad, EINA_FALSE);
+
+ } else if (sel_item->peer_type == TGL_PEER_CHAT) {
+
+ //send group chat delete request
+ show_loading_popup(ad);
+ send_delete_group_chat_request(ad->service_client, sel_item->peer_id);
+
+ } else {
+
+ }
+ } else {
+
+ }
+ evas_object_del(popup);
+}
+
+
+static void on_buddy_list_longpress(void *data, Evas_Object *obj, void *event_info)
+{
+ appdata_s *ad = data;
+ Elm_Object_Item *it = event_info;
+ elm_genlist_item_selected_set(it, EINA_FALSE);
+
+ int item_id = (int)elm_object_item_data_get(it);
+ tg_main_list_item_s *sel_item = eina_list_nth(ad->main_list, item_id);
+
+ if (sel_item) {
+ static Elm_Genlist_Item_Class itc;
+ Evas_Object *popup;
+ Evas_Object *box;
+ Evas_Object *genlist;
+ int i;
+ Evas_Object *win = ad->win;
+
+ popup = elm_popup_add(win);
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ evas_object_data_set(popup, "app_data", ad);
+ evas_object_data_set(popup, "selected_chat_item", (void*)sel_item);
+ evas_object_data_set(popup, "selected_chat_item_index", (void*)item_id);
+ /* box */
+ box = elm_box_add(popup);
+ evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ /* genlist */
+ genlist = elm_genlist_add(box);
+ evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ itc.item_style = "default";
+
+
+ if (sel_item->peer_type == TGL_PEER_USER) {
+ itc.func.text_get = on_longpress_single_menu_text_get_cb;
+ } else if (sel_item->peer_type == TGL_PEER_CHAT) {
+ itc.func.text_get = on_longpress_group_menu_text_get_cb;
+ } else {
+
+ }
+
+ itc.func.content_get = NULL;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+
+ for (i = 0; i < 2; i++) {
+ elm_genlist_item_append(genlist, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_chat_long_press_option_selected_cb, popup);
+ }
+ evas_object_show(genlist);
+ elm_box_pack_end(box, genlist);
+ evas_object_size_hint_min_set(box, -1, 230);
+ elm_object_content_set(popup, box);
+ evas_object_show(popup);
+ }
+}
+
+void on_main_chat_item_selected(void *data, Evas_Object *obj, void *event_info)
{
Elm_Object_Item *it = event_info;
elm_genlist_item_selected_set(it, EINA_FALSE);
- int item_id = (int) data;
+ //int item_id = (int) data;
+ int item_id = (int)elm_object_item_data_get(it);
+
appdata_s* ad = evas_object_data_get(obj, "app_data");
tg_main_list_item_s* sel_item = eina_list_nth(ad->main_list, item_id);
-/* if (sel_item->peer_type == TGL_PEER_CHAT) {
- // to be handled.
- return;
- }*/
ad->buddy_in_cahtting_data = NULL;
ad->peer_in_cahtting_data = NULL;
int buddy_id = -1;
- for (int i = 0; i < eina_list_count(ad->buddy_list); i++) {
- user_data_with_pic_s *item = eina_list_nth(ad->buddy_list, i);
- user_data_s* user_data = item->use_data;
-
- if (user_data->user_id.id == sel_item->peer_id) {
- ad->buddy_in_cahtting_data = item;
- break;
+ if (sel_item) {
+ if (sel_item->peer_type == TGL_PEER_USER) {
+ for (int i = 0; i < eina_list_count(ad->buddy_list); i++) {
+ user_data_with_pic_s *item = eina_list_nth(ad->buddy_list, i);
+ user_data_s* user_data = item->use_data;
+
+ if (user_data->user_id.id == sel_item->peer_id) {
+ ad->buddy_in_cahtting_data = item;
+ break;
+ }
+ }
}
- }
- for (int i = 0; i < eina_list_count(ad->peer_list); i++) {
- peer_with_pic_s* pic_item = eina_list_nth(ad->peer_list, i);
- tg_peer_info_s* item = pic_item->use_data;
+ for (int i = 0; i < eina_list_count(ad->peer_list); i++) {
+ peer_with_pic_s* pic_item = eina_list_nth(ad->peer_list, i);
+ tg_peer_info_s* item = pic_item->use_data;
- if (item->peer_id == sel_item->peer_id) {
- ad->peer_in_cahtting_data = pic_item;
- buddy_id = i;
- break;
+ if (item->peer_id == sel_item->peer_id) {
+ ad->peer_in_cahtting_data = pic_item;
+ buddy_id = i;
+ break;
+ }
+ }
+ ad->main_item_in_cahtting_data = sel_item;
+#if 0
+ if (ad->panel) {
+ Evas_Object *panel_list = evas_object_data_get(ad->panel, "panel_list");
+ if (panel_list) {
+ evas_object_del(panel_list);
+ }
+ evas_object_del(ad->panel);
+ ad->panel = NULL;
}
+#endif
+ launch_messaging_view_cb(ad, buddy_id);
}
-
- launch_messaging_view_cb(ad, buddy_id);
-
}
void on_buddy_icon_deleted(void *data, Evas *e, Evas_Object *icon, void *event_info)
return eo;
}
- Evas_Object *profile_pic = NULL;
- if (item->profile_pic_path && strcmp(item->profile_pic_path, "") != 0) {
+ if (item->profile_pic == NULL) {
+ Evas_Object *profile_pic = NULL;
+ if (item->profile_pic_path && strcmp(item->profile_pic_path, "") != 0) {
- profile_pic = elm_image_add(obj);
- evas_object_size_hint_weight_set(profile_pic, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(profile_pic, EVAS_HINT_FILL, EVAS_HINT_FILL);
- elm_object_focus_set(profile_pic, EINA_FALSE);
+ profile_pic = elm_image_add(obj);
+ evas_object_size_hint_weight_set(profile_pic, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(profile_pic, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ elm_object_focus_set(profile_pic, EINA_FALSE);
- Eina_Bool is_success = elm_image_file_set(profile_pic, item->profile_pic_path, NULL);
+ Eina_Bool is_success = elm_image_file_set(profile_pic, item->profile_pic_path, NULL);
- if (!is_success) {
- create_image_object_from_file(ui_utils_get_resource(DEFAULT_PROFILE_PIC), obj);
- // send download request again
- }
+ if (!is_success) {
+ create_image_object_from_file(ui_utils_get_resource(DEFAULT_PROFILE_PIC), obj);
+ // send download request again
+ }
- evas_object_show(profile_pic);
+ evas_object_show(profile_pic);
- } else {
- profile_pic = create_image_object_from_file(ui_utils_get_resource(DEFAULT_PROFILE_PIC), obj);
- }
+ } else {
+ profile_pic = create_image_object_from_file(ui_utils_get_resource(DEFAULT_PROFILE_PIC), obj);
+ }
- item->profile_pic = profile_pic;
- evas_object_event_callback_add(item->profile_pic, EVAS_CALLBACK_DEL, on_buddy_icon_deleted, item);
+ item->profile_pic = profile_pic;
+ evas_object_event_callback_add(item->profile_pic, EVAS_CALLBACK_DEL, on_buddy_icon_deleted, item);
+ }
char edj_path[PATH_MAX] = {0, };
app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
evas_object_size_hint_weight_set(user_pic_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(user_pic_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(user_pic_layout);
- elm_object_part_content_set(user_pic_layout, "content", profile_pic);
+ elm_object_part_content_set(user_pic_layout, "content", item->profile_pic);
eo = elm_layout_add(obj);
elm_layout_theme_set(eo, "layout", "list/C/type.3", "default");
} else if (!strcmp(part, "elm.swallow.end")) {
- char edj_path[PATH_MAX] = {0, };
- app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
- Evas_Object* user_status_layout = elm_layout_add(ad->nf);
- elm_layout_file_set(user_status_layout, edj_path, "main_list_status_item");
- evas_object_size_hint_weight_set(user_status_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(user_status_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_show(user_status_layout);
+ if (item->msg_status_lbl == NULL) {
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ Evas_Object* user_status_layout = elm_layout_add(ad->nf);
+ elm_layout_file_set(user_status_layout, edj_path, "main_list_status_item");
+ evas_object_size_hint_weight_set(user_status_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(user_status_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(user_status_layout);
+
+ Eina_Bool is_today = compare_date_with_current_date(item->last_seen_time);
+
+ Evas_Object* time_lbl = elm_label_add(ad->nf);
+ if (is_today) {
+ elm_object_text_set(time_lbl, "<font=Tizen:style=Italic color=#000000 align=center><font_size=25>Today</font_size></font>");
+ } else {
+ char *format = NULL;
+ time_t t = item->last_seen_time;
+ format = "%d/%b/%Y";
+ struct tm lt;
+ char res[256];
+ (void) localtime_r(&t, <);
+
+ if (strftime(res, sizeof(res), format, <) == 0) {
+ (void) fprintf(stderr, "strftime(3): cannot format supplied "
+ "date/time into buffer of size %u "
+ "using: '%s'\n",
+ sizeof(res), format);
+ }
- Eina_Bool is_today = compare_date_with_current_date(item->last_seen_time);
+ char time_str[256]={0,};
+ snprintf(time_str, sizeof(time_str), "<font=Tizen:style=Italic color=#000000 align=center><font_size=25>%s</font_size></font>", res);
- Evas_Object* time_lbl = elm_label_add(ad->nf);
- if (is_today) {
- elm_object_text_set(time_lbl, "<font=Tizen:style=Italic color=#000000 align=center><font_size=25>Today</font_size></font>");
- } else {
- char *format = NULL;
- time_t t = item->last_seen_time;
- format = "%d/%b/%Y";
- struct tm lt;
- char res[256];
- (void) localtime_r(&t, <);
-
- if (strftime(res, sizeof(res), format, <) == 0) {
- (void) fprintf(stderr, "strftime(3): cannot format supplied "
- "date/time into buffer of size %u "
- "using: '%s'\n",
- sizeof(res), format);
+ elm_object_text_set(time_lbl,time_str);
}
- char time_str[256]={0,};
- snprintf(time_str, sizeof(time_str), "<font=Tizen:style=Italic color=#000000 align=center><font_size=25>%s</font_size></font>", res);
-
- elm_object_text_set(time_lbl,time_str);
- }
+ evas_object_size_hint_weight_set(time_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(time_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(time_lbl);
- evas_object_size_hint_weight_set(time_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(time_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_show(time_lbl);
+ item->date_lbl = time_lbl;
+ evas_object_event_callback_add(item->date_lbl, EVAS_CALLBACK_DEL, on_buddy_date_deleted, item);
- item->date_lbl = time_lbl;
- evas_object_event_callback_add(item->date_lbl, EVAS_CALLBACK_DEL, on_buddy_date_deleted, item);
+ elm_object_part_content_set(user_status_layout, "swallow.date", time_lbl);
- elm_object_part_content_set(user_status_layout, "swallow.date", time_lbl);
+ if (item->is_out_msg && !(item->last_msg_service)) {
+ Evas_Object *status_obj;
+ status_obj = elm_icon_add(obj);
+ evas_object_size_hint_weight_set(status_obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(status_obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
- if (item->is_out_msg && !(item->last_msg_service)) {
- Evas_Object *status_obj;
- status_obj = elm_icon_add(obj);
- evas_object_size_hint_weight_set(status_obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(status_obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
-
- if(item->last_msg_status == TG_MESSAGE_STATE_SENDING) {
- elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_SENDING_ICON), NULL);
- } else if(item->last_msg_status == TG_MESSAGE_STATE_SENT) {
- elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_SENT_ICON), NULL);
- } else if(item->last_msg_status == TG_MESSAGE_STATE_DELIVERED) {
- elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_DELIVERED_ICON), NULL);
- } else if(item->last_msg_status == TG_MESSAGE_STATE_RECEIVED) {
-
- } else if(item->last_msg_status == TG_MESSAGE_STATE_FAILED) {
- elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_FAILED_ICON), NULL);
- } else if(item->last_msg_status == TG_MESSAGE_STATE_READ) {
- elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_READ_ICON), NULL);
- } else if(item->last_msg_status == TG_MESSAGE_STATE_UNKNOWN) {
-
- }
+ if(item->last_msg_status == TG_MESSAGE_STATE_SENDING) {
+ elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_SENDING_ICON), NULL);
+ } else if(item->last_msg_status == TG_MESSAGE_STATE_SENT) {
+ elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_SENT_ICON), NULL);
+ } else if(item->last_msg_status == TG_MESSAGE_STATE_DELIVERED) {
+ elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_DELIVERED_ICON), NULL);
+ } else if(item->last_msg_status == TG_MESSAGE_STATE_RECEIVED) {
- Evas_Object* msg_status = elm_layout_add(ad->nf);
- elm_layout_file_set(msg_status, edj_path, "circle_layout");
- evas_object_size_hint_weight_set(msg_status, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(msg_status, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_show(msg_status);
- elm_object_part_content_set(msg_status, "content", status_obj);
+ } else if(item->last_msg_status == TG_MESSAGE_STATE_FAILED) {
+ elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_FAILED_ICON), NULL);
+ } else if(item->last_msg_status == TG_MESSAGE_STATE_READ) {
+ elm_image_file_set(status_obj, ui_utils_get_resource(MESSAGE_READ_ICON), NULL);
+ } else if(item->last_msg_status == TG_MESSAGE_STATE_UNKNOWN) {
- elm_object_part_content_set(user_status_layout, "swallow.status", msg_status);
-
- } else {
- if (item->number_of_unread_msgs > 0) {
- Evas_Object* num_lbl = elm_label_add(ad->nf);
- elm_object_style_set(num_lbl, "transparent");
- char unread_msgs[256];
- sprintf(unread_msgs, "<font=Tizen:style=Bold color=#ffffff align=center><font_size=25>%d</font_size></font>", item->number_of_unread_msgs);
- elm_object_text_set(num_lbl, unread_msgs);
- evas_object_size_hint_weight_set(num_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(num_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
- evas_object_show(num_lbl);
+ }
Evas_Object* msg_status = elm_layout_add(ad->nf);
- elm_layout_file_set(msg_status, edj_path, "circle_item");
+ elm_layout_file_set(msg_status, edj_path, "circle_layout");
evas_object_size_hint_weight_set(msg_status, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(msg_status, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(msg_status);
- elm_object_part_content_set(msg_status, "content", num_lbl);
+ elm_object_part_content_set(msg_status, "content", status_obj);
+
elm_object_part_content_set(user_status_layout, "swallow.status", msg_status);
+
+ } else {
+ if (item->number_of_unread_msgs > 0) {
+ Evas_Object* num_lbl = elm_label_add(ad->nf);
+ elm_object_style_set(num_lbl, "transparent");
+ char unread_msgs[256];
+ sprintf(unread_msgs, "<font=Tizen:style=Bold color=#ffffff align=center><font_size=25>%d</font_size></font>", item->number_of_unread_msgs);
+ elm_object_text_set(num_lbl, unread_msgs);
+ evas_object_size_hint_weight_set(num_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(num_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(num_lbl);
+
+ Evas_Object* msg_status = elm_layout_add(ad->nf);
+ elm_layout_file_set(msg_status, edj_path, "circle_item");
+ evas_object_size_hint_weight_set(msg_status, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(msg_status, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(msg_status);
+ elm_object_part_content_set(msg_status, "content", num_lbl);
+ elm_object_part_content_set(user_status_layout, "swallow.status", msg_status);
+ }
}
+ item->msg_status_lbl = user_status_layout;
+ evas_object_event_callback_add(item->msg_status_lbl, EVAS_CALLBACK_DEL, on_buddy_msg_status_deleted, item);
}
- item->msg_status_lbl = user_status_layout;
- evas_object_event_callback_add(item->msg_status_lbl, EVAS_CALLBACK_DEL, on_buddy_msg_status_deleted, item);
+
+
eo = elm_layout_add(obj);
elm_layout_theme_set(eo, "layout", "list/C/type.3", "default");
- elm_layout_content_set(eo, "elm.swallow.content", user_status_layout);
+ elm_layout_content_set(eo, "elm.swallow.content", item->msg_status_lbl);
} else if (!strcmp(part, "elm.swallow.icon.0")) {
evas_object_event_callback_add(item->user_name_lbl, EVAS_CALLBACK_DEL, on_buddy_user_name_deleted, item);
- char* org_msg = NULL;
- if (item->last_message) {
- org_msg = item->last_message;
- } else {
- org_msg = "Hello";
- }
-
- int len_org_str = strlen(org_msg);
-
- char res[25] = {'\0'};
- char status_buf[126] = {'\0'};
- if(len_org_str > 25) {
- strncpy(res, org_msg, 24);
- if(item->last_msg_service) {
- sprintf(status_buf,"<font=Tizen:style=Italic color=#158CB0 align=left><font_size=30>%s</font_size></font>", res);
- } else {
- sprintf(status_buf,"<font=Tizen:style=Italic color=#A4A4A4 align=left><font_size=30>%s</font_size></font>", res);
- }
- } else {
- if(item->last_msg_service) {
- sprintf(status_buf, "<font=Tizen:style=Italic color=#158CB0 align=left><font_size=30>%s</font_size></font>", org_msg);
- } else {
- sprintf(status_buf, "<font=Tizen:style=Italic color=#A4A4A4 align=left><font_size=30>%s</font_size></font>", org_msg);
- }
- }
+ char* org_msg = NULL;
+ if (item->last_message) {
+ org_msg = item->last_message;
+ } else {
+ org_msg = "";
+ }
+
+ int len_org_str = strlen(org_msg);
+
+ char res[25] = {'\0'};
+ char status_buf[126] = {'\0'};
+ if(len_org_str > 25) {
+ strncpy(res, org_msg, 24);
+ if(item->last_msg_service) {
+ sprintf(status_buf,"<font=Tizen:style=Italic color=#158CB0 align=left><font_size=30>%s</font_size></font>", res);
+ } else {
+ sprintf(status_buf,"<font=Tizen:style=Italic color=#A4A4A4 align=left><font_size=30>%s</font_size></font>", res);
+ }
+ } else {
+ if(item->last_msg_service) {
+ sprintf(status_buf, "<font=Tizen:style=Italic color=#158CB0 align=left><font_size=30>%s</font_size></font>", org_msg);
+ } else {
+ sprintf(status_buf, "<font=Tizen:style=Italic color=#A4A4A4 align=left><font_size=30>%s</font_size></font>", org_msg);
+ }
+ }
+
+
Evas_Object* status_lbl = elm_label_add(ad->nf);
elm_object_text_set(status_lbl, status_buf);
evas_object_size_hint_weight_set(status_lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(status_lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(status_lbl);
- elm_object_part_content_set(user_status_layout, "swallow.status", status_lbl);
item->status_lbl = status_lbl;
evas_object_event_callback_add(item->status_lbl, EVAS_CALLBACK_DEL, on_buddy_user_status_deleted, item);
+
+ elm_object_part_content_set(user_status_layout, "swallow.status", item->status_lbl);
return user_status_layout;
} else if (!strcmp(part, "elm.swallow.icon.1")) {
return eo;
}
-
-void refresh_main_view_list(appdata_s* ad)
+void reload_main_list_view(appdata_s* ad)
{
- load_peer_data(ad);
- load_main_list_data(ad);
Evas_Object *buddy_list = evas_object_data_get(ad->nf, "buddy_list");
if (buddy_list) {
+ elm_genlist_clear(buddy_list);
+ int i = 0;
+ static Elm_Genlist_Item_Class itc;
+ itc.item_style = "type1";
+ itc.func.text_get = NULL;
+ itc.func.content_get = on_buddy_photo_requested;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+
+ int size = eina_list_count(ad->main_list);
+ if(size > 0) {
+ for (i = 0; i < size; i++) {
+ elm_genlist_item_append(buddy_list, &itc, (void*) i, NULL, ELM_GENLIST_ITEM_NONE, on_main_chat_item_selected, (void*) i);
+ }
+ } else {
+ i = 1;
+ elm_genlist_item_append(buddy_list, &itc, (void*) i, NULL, ELM_GENLIST_ITEM_NONE, on_main_chat_item_selected, (void*) i);
+ }
+ evas_object_show(buddy_list);
+ }
+}
+
+
+void refresh_main_list_view(appdata_s* ad, Eina_Bool is_new_item)
+{
+ //load_peer_data(ad);
+ //load_main_list_data(ad);
+ Evas_Object *buddy_list = evas_object_data_get(ad->nf, "buddy_list");
+ if (buddy_list) {
+#if 0
elm_genlist_clear(buddy_list);
int i = 0;
int size = eina_list_count(ad->main_list);
if(size > 0) {
for (i = 0; i < size; i++) {
- elm_genlist_item_append(buddy_list, &itc, (void*) i, NULL, ELM_GENLIST_ITEM_NONE, on_main_chat_item_clicked, (void*) i);
+ elm_genlist_item_append(buddy_list, &itc, (void*) i, NULL, ELM_GENLIST_ITEM_NONE, on_main_chat_item_selected, (void*) i);
}
} else {
i = 1;
- elm_genlist_item_append(buddy_list, &itc, (void*) i, NULL, ELM_GENLIST_ITEM_NONE, on_main_chat_item_clicked, (void*) i);
+ elm_genlist_item_append(buddy_list, &itc, (void*) i, NULL, ELM_GENLIST_ITEM_NONE, on_main_chat_item_selected, (void*) i);
}
evas_object_show(buddy_list);
+#endif
+
+
+ if (is_new_item) {
+
+ static Elm_Genlist_Item_Class itc;
+ itc.item_style = "type1";
+ itc.func.text_get = NULL;
+ itc.func.content_get = on_buddy_photo_requested;
+ itc.func.state_get = NULL;
+ itc.func.del = NULL;
+
+ int size = eina_list_count(ad->main_list);
+ int i = size - 1;
+ elm_genlist_item_append(buddy_list, &itc, (void*) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
+
+ }
+
+
+ elm_genlist_realized_items_update(buddy_list);
} else {
int size = eina_list_count(ad->main_list);
if(size > 0) {
for (i = 0; i < size; i++) {
- elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_main_chat_item_clicked, (void*) i);
+ elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
}
} else {
i = 1;
- elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_main_chat_item_clicked, (void*) i);
+ elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
}
evas_object_show(buddy_list);
elm_box_pack_end(bg_box, buddy_list);
static void on_user_list_search_clicked(void *data, Evas_Object *obj, void *event_info)
{
appdata_s* ad = data;
- show_toast(ad, "search clicked");
+#if 0
+ if (ad->panel) {
+ Evas_Object *panel_list = evas_object_data_get(ad->panel, "panel_list");
+ if (panel_list) {
+ evas_object_del(panel_list);
+ }
+ evas_object_del(ad->panel);
+ ad->panel = NULL;
+ }
+#endif
+ launch_start_peer_search_view(ad);
+}
+
+static void on_search_icon_pressed(void *data, Evas_Object *obj, void *event_info)
+{
+ elm_image_file_set(data, ui_utils_get_resource(TG_SEARCH_PRESSED_ICON), NULL);
+}
+
+static void on_search_icon_unpressed(void *data, Evas_Object *obj, void *event_info)
+{
+ elm_image_file_set(data, ui_utils_get_resource(TG_SEARCH_ICON), NULL);
}
void launch_user_main_view_cb(appdata_s* ad)
{
if (!ad)
return;
- ad->current_app_state = TG_USER_MAIN_VIEW_STATE;
+#if 0
+ if (ad->panel) {
+ Evas_Object *panel_list = evas_object_data_get(ad->panel, "panel_list");
+ if (panel_list) {
+ evas_object_del(panel_list);
+ }
+ evas_object_del(ad->panel);
+ ad->panel = NULL;
+ }
+#endif
+ ad->current_app_state = TG_USER_MAIN_VIEW_STATE;
+ ad->is_tg_initilized = EINA_TRUE;
char edj_path[PATH_MAX] = {0, };
app_get_resource(TELEGRAM_INIT_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ send_request_for_delete_notifications(ad->service_client);
+
Evas_Object* scroller = elm_scroller_add(ad->nf);
elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
elm_scroller_policy_set(scroller,ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
elm_object_content_set(scroller, layout);
elm_layout_theme_set(ad->layout, "layout", "drawer", "panel");
+ // sandeep
create_side_main_view(ad);
/************** no chat item++ *********************/
-
+ Evas_Object *buddy_list = NULL;
Evas_Object* bg_box = elm_box_add(layout);
evas_object_size_hint_weight_set(bg_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(bg_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
} else {
int i;
static Elm_Genlist_Item_Class itc;
- Evas_Object *buddy_list = elm_genlist_add(ad->nf);
+ buddy_list = elm_genlist_add(ad->nf);
elm_list_mode_set(buddy_list, ELM_LIST_COMPRESS);
elm_genlist_mode_set(buddy_list, ELM_LIST_COMPRESS);
evas_object_size_hint_weight_set(buddy_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
int size = eina_list_count(ad->main_list);
if(size > 0) {
for (i = 0; i < size; i++) {
- elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_main_chat_item_clicked, (void*) i);
+ elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
}
} else {
i = 1;
- elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_main_chat_item_clicked, (void*) i);
+ elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void*) i);
}
evas_object_show(buddy_list);
elm_box_pack_end(bg_box, buddy_list);
evas_object_data_set(ad->nf, "buddy_list", buddy_list);
+
+ evas_object_smart_callback_add(buddy_list, "longpressed", on_buddy_list_longpress, ad);
+ evas_object_smart_callback_add(buddy_list, "selected", on_main_chat_item_selected, ad);
+
}
evas_object_data_set(ad->nf, "main_list_box", bg_box);
/************** no chat item-- *********************/
evas_object_size_hint_weight_set(search_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(search_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(search_layout);
+
+ Evas_Object *search_btn = elm_button_add(layout);
+ elm_object_style_set(search_btn, "transparent");
+ evas_object_size_hint_align_set(search_btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_size_hint_weight_set(search_btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+
Evas_Object *search_icon = elm_image_add(layout);
elm_image_file_set(search_icon, ui_utils_get_resource(TG_SEARCH_ICON), NULL);
evas_object_show(search_icon);
- elm_object_part_content_set(search_layout, "search_box", search_icon);
- evas_object_smart_callback_add(search_icon, "clicked", on_user_list_search_clicked, ad);
+
+ elm_object_content_set(search_btn, search_icon);
+
+ elm_object_part_content_set(search_layout, "search_box", search_btn);
+ evas_object_smart_callback_add(search_btn, "clicked", on_user_list_search_clicked, ad);
+ evas_object_smart_callback_add(search_btn, "pressed", on_search_icon_pressed, search_icon);
+ evas_object_smart_callback_add(search_btn, "unpressed", on_search_icon_unpressed, search_icon);
Elm_Object_Item* navi_item = elm_naviframe_item_push(ad->nf, "<font=Tizen:style=Regular color=#ffffff align=left><font_size=40>Telegram</font_size></font>", NULL, NULL, scroller, NULL);
elm_object_item_part_content_set(navi_item, "title_right_btn", search_layout);
Evas_Object *panel_btn = create_button(ad->nf, "naviframe/drawers", NULL);
evas_object_smart_callback_add(panel_btn, "clicked", on_side_panel_requested, ad);
elm_object_item_part_content_set(navi_item, "title_left_btn", panel_btn);
+ eext_object_event_callback_add(ad->nf, EEXT_CALLBACK_MORE, on_side_panel_requested, ad);
}
#include <unistd.h>
#include <app.h>
#include "tg_common.h"
+#include "tg_db_wrapper.h"
+#include <media_content.h>
+
void app_get_resource(const char *edj_file_in, char *edj_path_out, int edj_path_max)
{
return msg_table;
}
+char* get_budy_state(appdata_s* ad, int buddy_id)
+{
+ if (!ad)
+ return NULL;
+ char time_str[256]={0,};
+ Eina_List* buddy_details_array = get_buddy_info(buddy_id);
+ if (buddy_details_array && eina_list_count(buddy_details_array) > 0) {
+ Eina_List* buddy_details = eina_list_nth(buddy_details_array, 0);
+ if (buddy_details && eina_list_count(buddy_details) > 0) {
+ int* temp_online = (int*)eina_list_nth(buddy_details, 12);
+ int is_online = *temp_online;
+ int* temp_last_seen = (int*)eina_list_nth(buddy_details, 13);
+ int last_seen = *temp_last_seen;
+
+ char *format = NULL;
+ Eina_Bool is_today = compare_date_with_current_date(last_seen);
+
+ if (is_online > 0) {
+ strcpy(time_str,"online");
+ } else {
+ time_t t = last_seen;
+
+ if (is_today) {
+ format = "last seen Today at %I:%M %P";
+ } else {
+ format = "last seen %d/%b/%Y at %I:%M %P";
+ }
+
+ struct tm lt;
+ char res[256];
+ (void) localtime_r(&t, <);
+
+ if (strftime(res, sizeof(res), format, <) == 0) {
+ (void) fprintf(stderr, "strftime(3): cannot format supplied "
+ "date/time into buffer of size %u "
+ "using: '%s'\n",
+ sizeof(res), format);
+ }
+ snprintf(time_str, sizeof(time_str), "<align=left><font_size=30><color=#808080>%s</color></font_size></align>", res);
+ }
+
+ for (int i = 0 ; i < eina_list_count(buddy_details_array); i++) {
+ void* val = eina_list_nth(buddy_details, i);
+ free(val);
+ }
+ eina_list_free(buddy_details);
+ }
+ eina_list_free(buddy_details_array);
+ }
+ return strdup(time_str);
+}
+
int numbers_only(const char *s)
{
return 1;
}
-const char *tg_common_to_string(const char *fmt, ...)
+static bool mp_util_svc_iterate_for_get_video_item_cb(media_info_h item, void *user_data)
+{
+ return TRUE;
+}
+
+
+
+static bool __thumbnail_cb(media_info_h item, void *user_data)
+{
+ char **thumbnail_path = (char **) user_data;
+
+ if(thumbnail_path == NULL)
+ return FALSE;
+
+ if (media_info_get_thumbnail_path(item, thumbnail_path) != MEDIA_CONTENT_ERROR_NONE) {
+ return FALSE;
+ }
+ if (*thumbnail_path) {
+ }
+ return TRUE;
+}
+
+Eina_Bool get_thumbnail_from_video_url(const char *file_path, char **thumbnail_path)
+{
+ if (thumbnail_path == NULL) {
+ return FALSE;
+ }
+ char condition[512 + 1] = { '\0', };
+ int ret=-1;
+ //snprintf(condition, 512, "%s ", file_path);
+ snprintf(condition, 512, "%s = \'%s\'", MEDIA_PATH, (char *)file_path);
+ ret = media_content_connect();
+
+ filter_h filter = NULL;
+ ret = media_filter_create(&filter);
+ if(ret != MEDIA_CONTENT_ERROR_NONE) {
+ goto ERROR_THROW;
+ }
+
+ ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ goto ERROR_THROW;
+ }
+
+ char *temp_thumbnail_path = NULL;
+ ret = media_info_foreach_media_from_db(filter, __thumbnail_cb, &temp_thumbnail_path);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ goto ERROR_THROW;
+ }
+ *thumbnail_path = temp_thumbnail_path;
+ if (filter) {
+ media_filter_destroy(filter);
+ }
+ filter = NULL;
+ ret = media_content_disconnect();
+ return TRUE;
+
+ERROR_THROW:
+ if (filter) {
+ media_filter_destroy(filter);
+ }
+ filter = NULL;
+ ret = media_content_disconnect();
+ return FALSE;
+}
+
+void show_loading_popup(appdata_s* ad)
+{
+ if (!ad)
+ return;
+
+ if (ad->loading_popup) {
+ evas_object_del(ad->loading_popup);
+ ad->loading_popup = NULL;
+ }
+
+ Evas_Object *layout;
+ Evas_Object *progressbar;
+
+
+ ad->loading_popup = elm_popup_add(ad->win);
+ elm_popup_align_set(ad->loading_popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ evas_object_size_hint_weight_set(ad->loading_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ /* layout */
+ layout = elm_layout_add(ad->loading_popup);
+ char edj_path[PATH_MAX] = {0, };
+ app_get_resource(TELEGRAM_POPUP_VIEW_EDJ, edj_path, (int)PATH_MAX);
+ elm_layout_file_set(layout, edj_path, "processing_view_layout");
+ evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_object_part_text_set(layout, "elm.text", "<font=Tizen:style=Italic color=#666362 align=left><font_size=36>Loading...</font_size></font>");
+ progressbar = elm_progressbar_add(layout);
+ elm_object_style_set(progressbar, "process_medium");
+ evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, 0.5);
+ evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_progressbar_pulse(progressbar, EINA_TRUE);
+ elm_object_part_content_set(layout, "processing", progressbar);
+
+ elm_object_content_set(ad->loading_popup, layout);
+
+ evas_object_show(ad->loading_popup);
+
+}
+
+void hide_loading_popup(appdata_s* ad)
+{
+ if (!ad)
+ return;
+
+ if (ad->loading_popup) {
+ evas_object_del(ad->loading_popup);
+ ad->loading_popup = NULL;
+ }
+}
+
+void launch_app_control(appdata_s *ad, char *media_type, char *url)
+{
+ if (!media_type || !url) {
+ return;
+ }
+ app_control_h app_control;
+ int ret = app_control_create(&app_control);
+ if(ret != APP_CONTROL_ERROR_NONE) {
+ show_toast(ad, "Error: Can not load image");
+ return;
+ }
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_VIEW);
+ if (strstr(media_type, "video") != NULL) {
+ app_control_set_mime(app_control,"video/*");
+ app_control_set_app_id(app_control, "com.samsung.video-player-lite");
+ } else if (strstr(media_type, "audio") != NULL) {
+ app_control_set_mime(app_control,"audio/*");
+ } else if (strstr(media_type, "image") != NULL) {
+ app_control_set_mime(app_control,"image/*");
+ } else if (strstr(media_type, "location") != NULL) {
+ app_control_set_app_id(app_control, "com.samsung.browser");
+ }
+ app_control_set_uri(app_control, url);
+
+
+ int nRet = app_control_send_launch_request(app_control, NULL, NULL);
+ if(nRet != APP_CONTROL_ERROR_NONE) {
+ if(nRet == APP_CONTROL_ERROR_INVALID_PARAMETER) {
+ printf("app_control_send_launch_request is fail APP_CONTROL_ERROR_INVALID_PARAMETER [0x%x]", nRet);
+ }
+ else if(nRet == APP_CONTROL_ERROR_OUT_OF_MEMORY ) {
+ printf("app_control_send_launch_request is fail APP_CONTROL_ERROR_OUT_OF_MEMORY [0x%x]", nRet);
+ }
+ else if(nRet == APP_CONTROL_ERROR_APP_NOT_FOUND ) {
+ printf("app_control_send_launch_request is fail APP_CONTROL_ERROR_APP_NOT_FOUND [0x%x]", nRet);
+ }
+ else if(nRet == APP_CONTROL_ERROR_KEY_NOT_FOUND ) {
+ printf("app_control_send_launch_request is fail APP_CONTROL_ERROR_KEY_NOT_FOUND [0x%x]", nRet);
+ }
+ else if(nRet == APP_CONTROL_ERROR_KEY_REJECTED ) {
+ printf("app_control_send_launch_request is fail APP_CONTROL_ERROR_KEY_REJECTED [0x%x]", nRet);
+ }
+ else if(nRet == APP_CONTROL_ERROR_INVALID_DATA_TYPE ) {
+ printf("app_control_send_launch_request is fail APP_CONTROL_ERROR_INVALID_DATA_TYPE [0x%x]", nRet);
+ }
+ else if(nRet == APP_CONTROL_ERROR_LAUNCH_REJECTED ) {
+ printf("app_control_send_launch_request is fail APP_CONTROL_ERROR_LAUNCH_REJECTED [0x%x]", nRet);
+ }
+ }
+ app_control_destroy(app_control);
+
+}
+
+void free_user_data(user_data_s *user_data)
+{
+ if (!user_data) {
+ return;
+ }
+
+ if (user_data->print_name) {
+ free(user_data->print_name);
+ user_data->print_name = NULL;
+ }
+
+ if (user_data->first_name) {
+ free(user_data->first_name);
+ user_data->first_name = NULL;
+ }
+
+ if (user_data->last_name) {
+ free(user_data->last_name);
+ user_data->last_name = NULL;
+ }
+
+ if (user_data->phone) {
+ free(user_data->phone);
+ user_data->phone = NULL;
+ }
+
+ if (user_data->real_first_name) {
+ free(user_data->real_first_name);
+ user_data->real_first_name = NULL;
+ }
+ if (user_data->real_last_name) {
+ free(user_data->real_last_name);
+ user_data->real_last_name = NULL;
+ }
+ if (user_data->username) {
+ free(user_data->username);
+ user_data->username = NULL;
+ }
+
+ free(user_data);
+ user_data = NULL;
+}
+
+
+void tg_notification_create(appdata_s *app_data, char * icon_path, const char *title, char *content, char *sound_path, char *app_id)
{
- va_list vp;
- static char string_buffer[256];
- int ret;
+ int err = NOTIFICATION_ERROR_NONE;
+ if (app_data && app_data->s_notififcation) {
+ //err = notification_delete(app_data->s_notififcation);
+ notification_delete_all(NOTIFICATION_TYPE_NOTI);
+ app_data->s_notififcation = NULL;
+ }
+
+ notification_error_e ret = NOTIFICATION_ERROR_NONE;
+ app_data->s_notififcation = notification_create(NOTIFICATION_TYPE_NOTI);
+ ret = notification_set_property(app_data->s_notififcation, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
+ ret = notification_set_layout(app_data->s_notififcation, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
- va_start(vp, fmt);
- ret = vsnprintf(string_buffer, sizeof(string_buffer) - 1, fmt, vp);
- va_end(vp);
+ if (icon_path) {
+ ret = notification_set_image(app_data->s_notififcation, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
+ }
+ if (title) {
+ ret = notification_set_text(app_data->s_notififcation, NOTIFICATION_TEXT_TYPE_TITLE, title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ }
+ if (content) {
+ ret = notification_set_text(app_data->s_notififcation, NOTIFICATION_TEXT_TYPE_CONTENT, content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ }
- return ret <= 0 ? NULL : string_buffer;
+ if (sound_path) {
+ ret = notification_set_sound(app_data->s_notififcation, NOTIFICATION_SOUND_TYPE_USER_DATA, sound_path);
+ } else {
+ ret = notification_set_sound(app_data->s_notififcation, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL);
+ }
+ ret = notification_set_vibration(app_data->s_notififcation, NOTIFICATION_VIBRATION_TYPE_DEFAULT, NULL);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ //failed
+ }
+ app_control_h service = NULL;
+ app_control_create(&service);
+ app_control_set_app_id(service, app_id);
+ app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT);
+
+ //notification_update()
+
+ ret = notification_set_launch_option(app_data->s_notififcation, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, service);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ //failed
+ }
+ notification_post(app_data->s_notififcation);
+ app_control_destroy(service);
+ ret = notification_free(app_data->s_notififcation);
+ if(ret != NOTIFICATION_ERROR_NONE) {
+ }
+ return;
}
#include <system_settings.h>
#include <efl_extension.h>
#include <dlog.h>
+#include <app_preference.h>
#include "service_client.h"
+#include <notification.h>
#ifdef LOG_TAG
#undef LOG_TAG
#if !defined(PACKAGE)
#define PACKAGE "org.tizen.telegram_tizen"
#endif
-
+#define TELEGRAM_APP_ID "org.tizen.telegramtizen"
#define EDJ_REG_FILE "edje/telegram_tizen_reg.edj"
#define EDJ_LOGIN_FILE "edje/telegram_tizen_login.edj"
#define EDJ_CHAT_LIST_FILE "edje/telegram_chat_list.edj"
#define TELEGRAM_CUSTOM_WINSET_EDJ "edje/telegram_theme.edj"
#define TELEGRAM_CHAT_VIEW_EDJ "edje/telegram_chat_view.edj"
#define TELEGRAM_INIT_VIEW_EDJ "edje/telegram_init_screen.edj"
+#define TELEGRAM_POPUP_VIEW_EDJ "edje/telegram_custom_popup.edj"
#define TELEGRAM_GENLIST_THEME_EDJ "edje/telegram_genlist_theme.edj"
#define SEND_UNPRESSED_ICON FM_ICON_PATH"/ic_send_pressed.png"
#define SEND_PRESSED_ICON FM_ICON_PATH"/ic_send_unpressed.png"
#define CHAT_BG FM_ICON_PATH"/chat_bg.jpg"
-#define BLUR_BG FM_ICON_PATH"/blur_img.jpg"
+#define BLUR_BG FM_ICON_PATH"/blur_img.png"
#define CAMERA_ICON FM_ICON_PATH"/camera-icon.png"
#define MESSAGE_READ_ICON FM_ICON_PATH"/ic_message_read.png"
#define MESSAGE_SENDING_ICON FM_ICON_PATH"/ic_message_sending.png"
#define MESSAGE_SENT_ICON FM_ICON_PATH"/ic_message_sent.png"
#define MESSAGE_FAILED_ICON FM_ICON_PATH"/ic_message_failed.png"
#define MESSAGE_DELIVERED_ICON FM_ICON_PATH"/ic_message_delivered.png"
+#define FLOATING_MSG_ICON FM_ICON_PATH"/floating_message.png"
#define MEDIA_DOWNLOAD_ICON FM_ICON_PATH"/ic_attach_download.png"
#define MEDIA_MANUAL_DOWNLOAD_ICON FM_ICON_PATH"/ic_attach_manual_download.png"
+#define MEDIA_PLAY_ICON FM_ICON_PATH"/playvideo.png"
+#define DEFAULT_TELEGRAM_ICON FM_ICON_PATH"/tg_icon.png"
#define FM_ICON_CAMERA FM_ICON_PATH"floating_camera.png"
#define FM_ICON_GALLERY FM_ICON_PATH"ic_attach_gallery.png"
#define FM_ICON_VIDEO FM_ICON_PATH"ic_attach_video.png"
+#define FM_ICON_MIC FM_ICON_PATH"ic_attach_mic.png"
#define FM_ICON_FILE FM_ICON_PATH"ic_attach_doc.png"
#define FM_ICON_LOCATION FM_ICON_PATH"ic_attach_location.png"
+
+
#define TG_ICON_FLOATING_PENCIL FM_ICON_PATH"floating_pencil.png"
#define TG_ICON_FLOATING_BG FM_ICON_PATH"floating_pressed.png"
#define TG_SEARCH_ICON FM_ICON_PATH"ic_ab_search.png"
+#define TG_SEARCH_PRESSED_ICON FM_ICON_PATH"ic_ab_search_pressed.png"
#define TG_MENU_GROUP FM_ICON_PATH"menu_newgroup.png"
#define TG_MENU_INVITE FM_ICON_PATH"menu_invite.png"
#define TG_CHAT_DEFAULT_BG FM_ICON_PATH"background_hd.jpg"
+#define TG_VIDEO_ICON FM_ICON_PATH"Video-Icon.jpg"
+//#define TG_AUDIO_ICON FM_ICON_PATH"Audio-Icon.png"
+#define TG_AUDIO_ICON FM_ICON_PATH"Audio-wave.png"
+
#define INIT_SCREEN_1 FM_ICON_PATH"screenshot_1.png"
#define INIT_SCREEN_2 FM_ICON_PATH"screenshot_2.png"
#define POPUP_TEXT_TAKE_PHOTO "Take photo"
#define POPUP_TEXT_TAKE_GALLERY "Gallery"
#define POPUP_TEXT_TAKE_VIDEO "Video"
+#define POPUP_TEXT_TAKE_AUDIO "Audio"
#define POPUP_TEXT_TAKE_FILE "File"
#define POPUP_TEXT_TAKE_LOCATION "Location"
+#define POPUP_TEXT_TAKE_CONTACT "Contact"
+
+#define TG_CHAT_BG_PREFERENCE "chat_view_bg"
#define LIST_CONTACT_ROUND_MASK_ICON FM_ICON_PATH"/info_page_pic_mask.png"
#define SAFE_STRLEN(src) \
((src != NULL)? strlen(src): 0)
#define ELM_OBJ_PART_TEXT_SET(obj, part, text) elm_object_domain_translatable_part_text_set(obj, part, "telegram", text)
-
+#define EVAS_OBJECT_DELIF(p) if (p) { evas_object_del(p); p = NULL; }
#define TGL_PEER_USER 1
#define TGL_PEER_CHAT 2
#define MAX_NUM_LENGTH 10
#define MAX_CODE_LENGTH 5
+#define MAX_USERNAME_LENGTH 15
+#define MIN_USERNAME_LENGTH 5
typedef struct {
int type;
} tgl_peer_id_t;
+
+typedef enum {
+ APP_STATE_IN_BACKGROUND = 0,
+ APP_STATE_IN_FOREGROUND
+}app_visible_state;
+
typedef enum {
TELEGRAM_APP_FILE_TYPE_NONE = 0,
TELEGRAM_APP_FILE_TYPE_IMAGE, /**< Image category */
TG_BUDDY_CHAT_CONV_STATE,
TG_USER_MAIN_VIEW_STATE,
TG_START_MESSAGING_VIEW_STATE,
- TG_CHAT_MESSAGING_VIEW_STATE
+ TG_CHAT_MESSAGING_VIEW_STATE,
+ TG_PEER_SEARCH_VIEW_STATE,
+ TG_SETTINGS_SCREEN_STATE,
+ TG_SET_USERNAME_STATE,
+ TG_SET_USER_INFO_STATE,
+ TG_SET_CHAT_INFO_STATE,
+ TG_SELECT_BUDDY_VIEW
} state_of_app_s;
enum tgl_typing_status {
typedef struct user_data {
tgl_peer_id_t user_id;
- char* print_name;
+ char *print_name;
int structure_version;
- char* photo_path;
+ char *photo_path;
int photo_id;
- char* first_name;
- char* last_name;
- char* phone;
+ char *first_name;
+ char *last_name;
+ char *phone;
int access_hash;
- char* real_first_name;
- char* real_last_name;
- char* username;
+ char *real_first_name;
+ char *real_last_name;
+ char *username;
int online;
int last_seen;
Eina_Bool is_selected;
+ int is_blocked;
+ int is_deleted;
} user_data_s;
typedef struct user_data_with_pic {
} user_data_with_pic_s;
enum tgl_message_media_type {
- tgl_message_media_none,
+ tgl_message_media_none = 1001,
tgl_message_media_photo,
//tgl_message_media_video,
//tgl_message_media_audio,
int unique_id;
} tg_message_s;
+typedef struct tgl_media {
+ long long media_id;
+ int media_type;
+ long long access_hash;
+ int user_id;
+ int date;
+ char *caption;
+ char *longitude;
+ char *latitude;
+ int sizes;
+ char *phone_no;
+ char *first_name;
+ char *last_name;
+ char *file_path;
+
+ char *photo_type1;
+ int photo_loc_dc1;
+ long long photo_loc_vol1;
+ int photo_loc_id1;
+ long long photo_loc_sec1;
+ int photo_width1;
+ int photo_height1;
+ int photo_size1;
+ char *photo_data1;
+
+ char *photo_type2;
+ int photo_loc_dc2;
+ long long photo_loc_vol2;
+ int photo_loc_id2;
+ long long photo_loc_sec2;
+ int photo_width2;
+ int photo_height2;
+ int photo_size2;
+ char *photo_data2;
+
+ char *photo_type3;
+ int photo_loc_dc3;
+ long long photo_loc_vol3;
+ int photo_loc_id3;
+ long long photo_loc_sec3;
+ int photo_width3;
+ int photo_height3;
+ int photo_size3;
+ char *photo_data3;
+
+ char *photo_type4;
+ int photo_loc_dc4;
+ long long photo_loc_vol4;
+ int photo_loc_id4 ;
+ long long photo_loc_sec4;
+ int photo_width4;
+ int photo_height4;
+ int photo_size4;
+ char *photo_data4;
+
+
+ char* mime_type;
+ char* doc_type;
+ int doc_width;
+ int doc_height;
+ int doc_duration;
+ int doc_size;
+
+} tgl_media_s;
+
typedef struct tg_main_list_item {
char* peer_print_name;
int peer_id;
Evas_Object* conform;
Evas_Object* nf;
Evas_Object* panel;
- struct event_base *basic_event;
char* phone_number;
char* sms_code;
Eina_List* buddy_list;
- Eina_List* group_chat_list;
+ //Eina_List* group_chat_list;
Eina_List* peer_list;
Eina_List* main_list;
+ Eina_List* search_peer_list;
int curtimezoneoffset;
int curtimeformat;
tgl_peer_id_t user_id;
state_of_app_s current_app_state;
- user_data_s current_user_data;
+ user_data_s *current_user_data;
+ tg_main_list_item_s* main_item_in_cahtting_data;
peer_with_pic_s* peer_in_cahtting_data;
user_data_with_pic_s* buddy_in_cahtting_data;
- Eina_Bool is_network_connected;
service_client* service_client;
Eina_Bool is_first_time_registration;
Eina_List* loaded_msg_list;
int timer_value;
Eina_Bool is_last_msg_changed;
+ Evas_Object* loading_popup;
+ Eina_Bool is_tg_initilized;
+
+ char *chat_background;
+ //Eina_Bool is_long_pressed;
+ Evas_Object *msg_popup;
+
+ //user_data_with_pic_s *selected_buddy_item;
+ user_data_s *selected_buddy_item;
+
+ app_visible_state s_app_visible_state;
+ notification_h s_notififcation;
+ Eina_Bool is_server_ready;
} appdata_s;
extern void show_toast(appdata_s* ad, char* value);
extern void detail_list_nf_back_cb(void *data, Evas_Object *obj, void *event_info);
extern void create_buddy_msg_table(const char* table_name);
extern void load_buddy_list_data(appdata_s *ad);
-extern void load_group_chat_data(appdata_s *ad);
+//extern void load_group_chat_data(appdata_s *ad);
extern void load_peer_data(appdata_s *ad);
+extern void load_registered_user_data(appdata_s *ad);
extern void load_main_list_data(appdata_s *ad);
+extern void launch_app_control(appdata_s *ad, char *media_type, char *url);
#if 0
static char *trim(char *s) {
}
}
+extern tg_main_list_item_s* get_latest_item(appdata_s *ad, peer_with_pic_s *item);
//static char* get_table_name_from_number(const char* phone_no)
extern char* get_table_name_from_number(const int id);
extern Eina_Bool compare_date_with_current_date(int rtime);
int nameInfo ;
char* msisdns;
char* smsContacts;
+
} Buddy;
extern void app_get_resource(const char *edj_file_in, char *edj_path_out, int edj_path_max);
-extern const char *tg_common_to_string(const char *fmt, ...);
+extern char* get_budy_state(appdata_s* ad, int buddy_id);
+
+extern Eina_Bool get_thumbnail_from_video_url(const char *file_path, char **thumbnail_path);
+
+extern void show_loading_popup(appdata_s* ad);
+
+extern void hide_loading_popup(appdata_s* ad);
+
+extern void free_user_data(user_data_s *user_data);
+
+extern void app_nf_back_cb(void *data, Evas_Object *obj, void *event_info);
+
+extern void tg_notification_create(appdata_s *app_data, char * icon_path, const char *title, char *content, char *sound_path, char *app_id);
+
#endif /* TG_COMMON_H_ */
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<manifest xmlns="http://tizen.org/ns/packages" api-version="2.4" package="org.tizen.telegramtizen" version="1.0.0">
<profile name="mobile"/>
- <ui-application appid="org.tizen.telegramtizen" exec="telegramtizen" hw-acceleration="on" multiple="false" nodisplay="false" taskmanage="true" type="capp">
+ <ui-application appid="org.tizen.telegramtizen" auto-restart="false" exec="telegramtizen" hw-acceleration="on" multiple="false" nodisplay="false" taskmanage="true" type="capp">
<label>Telegram</label>
<icon>ic_launcher.png</icon>
</ui-application>
<privileges>
<privilege>http://tizen.org/privilege/location</privilege>
+ <privilege>http://tizen.org/privilege/datasharing</privilege>
<privilege>http://tizen.org/privilege/network.get</privilege>
<privilege>http://tizen.org/privilege/callhistory.read</privilege>
<privilege>http://tizen.org/privilege/contact.write</privilege>
+ <privilege>http://tizen.org/privilege/message.write</privilege>
<privilege>http://tizen.org/privilege/content.write</privilege>
<privilege>http://tizen.org/privilege/push</privilege>
<privilege>http://tizen.org/privilege/account.read</privilege>
<privilege>http://tizen.org/privilege/mediastorage</privilege>
<privilege>http://tizen.org/privilege/internet</privilege>
<privilege>http://tizen.org/privilege/callhistory.write</privilege>
+ <privilege>http://tizen.org/privilege/email</privilege>
<privilege>http://tizen.org/privilege/contact.read</privilege>
<privilege>http://tizen.org/privilege/keymanager</privilege>
<privilege>http://tizen.org/privilege/camera</privilege>
<privilege>http://tizen.org/privilege/appmanager.launch</privilege>
<privilege>http://tizen.org/privilege/display</privilege>
<privilege>http://tizen.org/privilege/network.profile</privilege>
- <privilege>http://tizen.org/privilege/alarm.get</privilege>
<privilege>http://tizen.org/privilege/account.write</privilege>
<privilege>http://tizen.org/privilege/bluetooth</privilege>
<privilege>http://tizen.org/privilege/network.set</privilege>
<privilege>http://tizen.org/privilege/notification</privilege>
<privilege>http://tizen.org/privilege/externalstorage.appdata</privilege>
- <privilege>http://tizen.org/privilege/telephony</privilege>
+ <privilege>http://tizen.org/privilege/mapservice</privilege>
+ <privilege>http://tizen.org/privilege/message.read</privilege>
</privileges>
- <feature name="http://tizen.org/feature/camera.front.flash">true</feature>
- <feature name="http://tizen.org/feature/camera.back.flash">true</feature>
- <feature name="http://tizen.org/feature/network.push">true</feature>
- <feature name="http://tizen.org/feature/camera">true</feature>
- <feature name="http://tizen.org/feature/camera.front">true</feature>
- <feature name="http://tizen.org/feature/network.wifi">true</feature>
- <feature name="http://tizen.org/feature/screen.size.all">true</feature>
- <feature name="http://tizen.org/feature/network.telephony">true</feature>
- <feature name="http://tizen.org/feature/camera.back">true</feature>
</manifest>
</option>
<option id="sbi.gnu.cpp.compiler.option.frameworks_inc.core.1999052704" name="Tizen-Frameworks-Include-Path" superClass="sbi.gnu.cpp.compiler.option.frameworks_inc.core" valueType="includePath">
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/libxml2""/>
- <listOptionValue builtIn="false" value=""${SDK_PATH}/library""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/appcore-agent""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/appfw""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/ethumb-client-1""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/evas-1""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/ewebkit2-0""/>
+ <listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/feedback""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/fontconfig""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/freetype2""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/geofence""/>
</option>
<option id="sbi.gnu.c.compiler.option.frameworks_inc.core.1087094675" name="Tizen-Frameworks-Include-Path" superClass="sbi.gnu.c.compiler.option.frameworks_inc.core" valueType="includePath">
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/libxml2""/>
- <listOptionValue builtIn="false" value=""${SDK_PATH}/library""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/appcore-agent""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/appfw""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/ethumb-client-1""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/evas-1""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/ewebkit2-0""/>
+ <listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/feedback""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/fontconfig""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/freetype2""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/geofence""/>
<listOptionValue builtIn="false" value="-Xlinker --version-script="${PROJ_PATH}/.exportMap""/>
<listOptionValue builtIn="false" value="-L"${SBI_SYSROOT}/usr/lib""/>
<listOptionValue builtIn="false" value="$(RS_LIBRARIES)"/>
+ <listOptionValue builtIn="false" value="-Xlinker -rpath="/opt/usr/apps/org.tizen.tg-engine-service/lib""/>
</option>
<option id="gnu.cpp.link.option.paths.1718248047" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.269893982" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
</option>
<option id="sbi.gnu.cpp.compiler.option.frameworks_inc.core.607323538" name="Tizen-Frameworks-Include-Path" superClass="sbi.gnu.cpp.compiler.option.frameworks_inc.core" valueType="includePath">
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/libxml2""/>
- <listOptionValue builtIn="false" value=""${SDK_PATH}/library""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/appcore-agent""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/appfw""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/ethumb-client-1""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/evas-1""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/ewebkit2-0""/>
+ <listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/feedback""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/fontconfig""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/freetype2""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/geofence""/>
</option>
<option id="sbi.gnu.c.compiler.option.frameworks_inc.core.1774188413" name="Tizen-Frameworks-Include-Path" superClass="sbi.gnu.c.compiler.option.frameworks_inc.core" valueType="includePath">
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/libxml2""/>
- <listOptionValue builtIn="false" value=""${SDK_PATH}/library""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/appcore-agent""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/appfw""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/ethumb-client-1""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/evas-1""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/ewebkit2-0""/>
+ <listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/feedback""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/fontconfig""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/freetype2""/>
<listOptionValue builtIn="false" value=""${SBI_SYSROOT}/usr/include/geofence""/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="inc"/>
<entry excluding="tl-parser|auto" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="mtprotocol"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="mtprotocol/auto"/>
- <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="mtprotocol/tl-parser"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="res"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="shared"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
#include <malloc.h>
#include <errno.h>
#include <string.h>
-#include <sqlite3.h>
-
-#include "tgl.h"
-#include "tgl-layout.h"
-#include "tg_common.h"
#include "tg_db_manager.h"
+#include "tg_common.h"
+#include "tg_engine.h"
int errno;
int tg_db_init(void)
{
+#if 0
int ret;
if (s_info.db) {
if(ret != SQLITE_OK) {
return EINA_FALSE;
}
-
+#endif
return EINA_TRUE;
-
}
int tg_db_fini(void)
{
+#if 0
if (!s_info.db) {
return EINA_FALSE;
}
sqlite3_close(s_info.db);
s_info.db = NULL;
+#endif
return EINA_TRUE;
}
-static inline int create_table_query_to_db(const char *ddl, const char *table_name)
+Eina_Bool create_table(const char* table_name, Eina_List* column_names, Eina_List* column_types)
{
- sqlite3_stmt *stmt;
- int ret;
-
- ret = sqlite3_prepare_v2(s_info.db, ddl, -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- return -EFAULT;
- }
-
- ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_DONE) {
- sqlite3_finalize(stmt);
- return -EIO;
+ if(!table_name || ! column_names || !column_types) {
+ return EINA_FALSE;
}
- sqlite3_finalize(stmt);
- return 0;
-}
-
-int tg_db_create_table_user_info(const char *table_name)
-{
- const char *ddl;
-
- ddl = "CREATE TABLE ? (" \
- "user_id INTEGER PRIMARY KEY NOT NULL," \
- "print_name TEXT," \
- "structure_version INTEGER," \
- "photo_path TEXT," \
- "photo_id INTEGER," \
- "first_name TEXT," \
- "last_name TEXT," \
- "phone TEXT," \
- "access_hash INTEGER," \
- "real_first_name TEXT," \
- "real_last_name TEXT," \
- "username TEXT," \
- "online INTEGER," \
- "last_seen INTEGER)";
-
- return create_table_query_to_db(ddl, table_name);
-}
-
-int tg_db_create_table_media_info(const char *table_name)
-{
- const char *ddl;
- ddl = "CREATE TABLE ? (" \
- "media_id TEXT," \
- "media_type INTEGER," \
- "access_hash TEXT," \
- "user_id INTEGER," \
- "date INTEGER," \
- "caption TEXT," \
- "longitude TEXT," \
- "latitude TEXT," \
- "sizes_num INTEGER," \
- "photo_type1 TEXT," \
- "photo_loc_dc1 INTEGER," \
- "photo_loc_vol1 TEXT," \
- "photo_loc_id1 INTEGER," \
- "photo_loc_secret1 TEXT," \
- "photo_width1 INTEGER," \
- "photo_height1 INTEGER," \
- "photo_size1 INTEGER," \
- "photo_data1 TEXT," \
- "photo_type2 TEXT," \
- "photo_loc_dc2 INTEGER," \
- "photo_loc_vol2 TEXT," \
- "photo_loc_id2 INTEGER," \
- "photo_loc_secret2 TEXT," \
- "photo_width2 INTEGER," \
- "photo_height2 INTEGER," \
- "photo_size2 INTEGER," \
- "photo_data2 TEXT," \
- "photo_type3 TEXT," \
- "photo_loc_dc3 INTEGER," \
- "photo_loc_vol3 TEXT," \
- "photo_loc_id3 INTEGER," \
- "photo_loc_secret3 TEXT," \
- "photo_width3 INTEGER," \
- "photo_height3 INTEGER," \
- "photo_size3 INTEGER," \
- "photo_data3 TEXT," \
- "photo_type4 TEXT," \
- "photo_loc_dc4 INTEGER," \
- "photo_loc_vol4 TEXT," \
- "photo_loc_id4 INTEGER," \
- "photo_loc_secret4 TEXT," \
- "photo_width4 INTEGER," \
- "photo_height4 INTEGER," \
- "photo_size4 INTEGER," \
- "photo_data4 TEXT," \
- "phone TEXT," \
- "first_name TEXT," \
- "last_name TEXT," \
- "file_path TEXT)";
- return create_table_query_to_db(ddl, table_name);
-}
-
-int tg_db_update_media_info_filepath(const char *table_name, long long media_id, const char *filepath)
-{
- const char *dml;
- const char *id_str;
- int ret;
- sqlite3_stmt *stmt;
-
- dml = "UPDATE ? SET file_path = ? WHERE media_id = ?";
-
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_text(stmt, 2, filepath, -1, SQLITE_TRANSIENT);
- id_str = tg_common_to_string("%lld", media_id);
- ret = sqlite3_bind_text(stmt, 3, id_str, -1, SQLITE_TRANSIENT);
- ret = sqlite3_step(stmt);
- sqlite3_finalize(stmt);
- return 0;
-}
-
-int tg_db_update_media_info_by_id(const char *table_name, struct tgl_message *msg, long long id)
-{
- const char *dml;
- const char *tmp;
- int ret;
- sqlite3_stmt *stmt;
- int i;
-
- dml = "UPDATE ? SET media_id = ?, "
- "media_type = ?, "
- "access_hash = ?, "
- "user_id = ?, "
- "date = ?, "
- "caption = ?, "
- "longitude = ?, "
- "latitude = ?, "
- "sizes_num = ?, "
- "photo_type1 = ?," \
- "photo_loc_dc1 = ?," \
- "photo_loc_vol1 = ?," \
- "photo_loc_id1 = ?," \
- "photo_loc_secret1 = ?," \
- "photo_width1 = ?," \
- "photo_height1 = ?," \
- "photo_size1 = ?," \
- "photo_data1 = ?," \
- "photo_type2 = ?," \
- "photo_loc_dc2 = ?," \
- "photo_loc_vol2 = ?," \
- "photo_loc_id2 = ?," \
- "photo_loc_secret2 = ?," \
- "photo_width2 = ?," \
- "photo_height2 = ?," \
- "photo_size2 = ?," \
- "photo_data2 = ?," \
- "photo_type3 = ?," \
- "photo_loc_dc3 = ?," \
- "photo_loc_vol3 = ?," \
- "photo_loc_id3 = ?," \
- "photo_loc_secret3 = ?," \
- "photo_width3 = ?," \
- "photo_height3 = ?," \
- "photo_size3 = ?," \
- "photo_data3 = ?," \
- "photo_type4 = ?," \
- "photo_loc_dc4 = ?," \
- "photo_loc_vol4 = ?," \
- "photo_loc_id4 = ?," \
- "photo_loc_secret4 = ?," \
- "photo_width4 = ?," \
- "photo_height4 = ?," \
- "photo_size4 = ?," \
- "photo_data4 = ?," \
- "phone = ?," \
- "first_name = ?," \
- "last_name = ? WHERE media_id = ?";
- /* Except filename */
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
- switch (msg->media.type) {
- case tgl_message_media_photo:
- tmp = tg_common_to_string("%lld", msg->media.photo.id);
- ret = sqlite3_bind_text(stmt, 2, tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 3, msg->media.type);
- ret = sqlite3_bind_int64(stmt, 4, msg->media.photo.access_hash);
- ret = sqlite3_bind_int(stmt, 5, msg->media.photo.user_id);
- ret = sqlite3_bind_int(stmt, 6, msg->media.photo.date);
- ret = sqlite3_bind_text(stmt, 7, msg->media.photo.caption, -1, SQLITE_TRANSIENT);
-
- tmp = tg_common_to_string("%lf", msg->media.photo.geo.longitude);
- ret = sqlite3_bind_text(stmt, 8, tmp, -1, SQLITE_TRANSIENT);
-
- tmp = tg_common_to_string("%lf", msg->media.photo.geo.latitude);
- ret = sqlite3_bind_text(stmt, 9, tmp, -1, SQLITE_TRANSIENT);
-
- ret = sqlite3_bind_int(stmt, 10, msg->media.photo.sizes_num);
- for (i = 0; i < 4; i++) {
- if (i < msg->media.photo.sizes_num) {
- ret = sqlite3_bind_text(stmt, 11 + (i * 9), msg->media.photo.sizes[i].type, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 12 + (i * 9), msg->media.photo.sizes[i].loc.dc);
- tmp = tg_common_to_string("%lld", msg->media.photo.sizes[i].loc.volume);
- ret = sqlite3_bind_text(stmt, 13 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 14 + (i * 9), msg->media.photo.sizes[i].loc.local_id);
- tmp = tg_common_to_string("%lld", msg->media.photo.sizes[i].loc.secret);
- ret = sqlite3_bind_text(stmt, 15 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 16 + (i * 9), msg->media.photo.sizes[i].w);
- ret = sqlite3_bind_int(stmt, 17 + (i * 9), msg->media.photo.sizes[i].h);
- ret = sqlite3_bind_int(stmt, 18 + (i * 9), msg->media.photo.sizes[i].size);
- ret = sqlite3_bind_text(stmt, 19 + (i * 9), msg->media.photo.sizes[i].data, -1, SQLITE_TRANSIENT);
- } else {
- ret = sqlite3_bind_text(stmt, 11 + (i * 9), " ", -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 12 + (i * 9), 0);
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 13 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 14 + (i * 9), 0);
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 15 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 16 + (i * 9), 0);
- ret = sqlite3_bind_int(stmt, 17 + (i * 9), 0);
- ret = sqlite3_bind_int(stmt, 18 + (i * 9), 0);
- ret = sqlite3_bind_text(stmt, 19 + (i * 9), " ", -1, SQLITE_TRANSIENT);
- }
+ sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
+
+ int ret = 0 ;
+ char* err_msg = 0;
+ int col_count = eina_list_count(column_names);
+
+ int str_len = strlen("CREATE TABLE IF NOT EXISTS ") + strlen(table_name) + strlen("(") + 1;
+ char* var_query = (char*)malloc(str_len);
+ strcpy(var_query,"CREATE TABLE IF NOT EXISTS ");
+ strcat(var_query, table_name);
+ strcat(var_query, "(");
+
+ for(int col = 0; col < col_count ; col++) {
+ char* col_name = eina_list_nth(column_names, col);
+ var_query = realloc(var_query, strlen(var_query)+strlen(col_name) + 1);
+ strcat(var_query, col_name);
+ var_query = realloc(var_query, strlen(var_query)+strlen(" ") + 1);
+ strcat(var_query, " ");
+ char* col_type = eina_list_nth(column_types, col);
+ var_query = realloc(var_query, strlen(var_query)+strlen(col_type) + 1);
+ strcat(var_query, col_type);
+ if(col < col_count - 1){
+ var_query = realloc(var_query, strlen(var_query) + 2);
+ strcat(var_query, ",");
+ } else {
+ var_query = realloc(var_query, strlen(var_query) + 3);
+ strcat(var_query, ");");
}
- break;
- case tgl_message_media_document:
- tmp = tg_common_to_string("%lld", msg->media.document.id);
- ret = sqlite3_bind_text(stmt, 2, tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 3, msg->media.type);
- ret = sqlite3_bind_int64(stmt, 4, msg->media.document.access_hash);
- ret = sqlite3_bind_int(stmt, 5, msg->media.document.user_id);
- ret = sqlite3_bind_int(stmt, 6, msg->media.document.date);
- ret = sqlite3_bind_text(stmt, 7, msg->media.document.caption, -1, SQLITE_TRANSIENT);
- tmp = tg_common_to_string("%lf", 0.0f);
- ret = sqlite3_bind_text(stmt, 8, tmp, -1, SQLITE_TRANSIENT);
- tmp = tg_common_to_string("%lf", 0.0f);
- ret = sqlite3_bind_text(stmt, 9, tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 10, msg->media.document.size);
- for (i = 0; i < 4; i++) {
- ret = sqlite3_bind_text(stmt, 11 + (i * 9), " ", -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 12 + (i * 9), 0);
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 13 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 14 + (i * 9), 0);
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 15 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 16 + (i * 9), 0);
- ret = sqlite3_bind_int(stmt, 17 + (i * 9), 0);
- ret = sqlite3_bind_int(stmt, 18 + (i * 9), 0);
- ret = sqlite3_bind_text(stmt, 19 + (i * 9), " ", -1, SQLITE_TRANSIENT);
- }
- break;
- default:
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 2, tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 3, msg->media.type);
- ret = sqlite3_bind_int64(stmt, 4, 0);
- ret = sqlite3_bind_int(stmt, 5, 0);
- ret = sqlite3_bind_int(stmt, 6, 0);
- ret = sqlite3_bind_text(stmt, 7, " ", -1, SQLITE_TRANSIENT);
- tmp = tg_common_to_string("%lf", 0.0f);
- ret = sqlite3_bind_text(stmt, 8, tmp, -1, SQLITE_TRANSIENT);
- tmp = tg_common_to_string("%lf", 0.0f);
- ret = sqlite3_bind_text(stmt, 9, tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 10, 0);
- for (i = 0; i < 4; i++) {
- ret = sqlite3_bind_text(stmt, 11 + (i * 9), " ", -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 12 + (i * 9), 0);
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 13 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 14 + (i * 9), 0);
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 15 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 16 + (i * 9), 0);
- ret = sqlite3_bind_int(stmt, 17 + (i * 9), 0);
- ret = sqlite3_bind_int(stmt, 18 + (i * 9), 0);
- ret = sqlite3_bind_text(stmt, 19 + (i * 9), " ", -1, SQLITE_TRANSIENT);
- }
- break;
}
- ret = sqlite3_bind_text(stmt, 46, msg->media.phone, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_text(stmt, 47, msg->media.first_name, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_text(stmt, 48, msg->media.last_name, -1, SQLITE_TRANSIENT);
- tmp = tg_common_to_string("%lld", id);
- ret = sqlite3_bind_text(stmt, 49, tmp, -1, SQLITE_TRANSIENT);
-
- ret = sqlite3_step(stmt);
- sqlite3_finalize(stmt);
- if (ret != SQLITE_DONE) {
- return -EIO;
+ ret = sqlite3_exec(db,var_query, NULL,NULL, &err_msg);
+ close_database(db);
+ if( ret != SQLITE_OK ){
+ sqlite3_free(err_msg);
+ return EINA_FALSE;
}
-
- return 0;
+ return EINA_TRUE;
}
-void *tg_db_get_media_info(const char *table_name, long long id, int *media_type)
+Eina_Bool insert_table(const char* table_name, Eina_List* column_names, Eina_List* column_types, Eina_List* column_values)
{
- void *info = NULL;
- const char *dml;
- sqlite3_stmt *stmt;
- const char *tmp;
- int ret;
- int i;
-
- if (!media_type || !table_name) {
- return NULL;
- }
-
- dml = "SELECT * FROM ? WHERE media_id = ?";
-
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
- tmp = tg_common_to_string("%lld", id);
- ret = sqlite3_bind_text(stmt, 2, tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_ROW) {
- sqlite3_finalize(stmt);
- return NULL;
+ if( !table_name || ! column_names || !column_types || !column_values) {
+ return EINA_FALSE;
}
- *media_type = sqlite3_column_int(stmt, 1);
- if (*media_type == tgl_message_media_photo) {
- struct tgl_photo *photo;
- const char *tmp;
+ sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
+ int ret = 0 ;
+ char* err_msg = 0;
+ int col_count = eina_list_count(column_names);
- photo = calloc(1, sizeof(*photo));
- if (!photo) {
- sqlite3_finalize(stmt);
- return NULL;
- }
+ int str_len = strlen("INSERT INTO ") + strlen(table_name) + strlen("(") + 1;
+ char* var_query = (char*)malloc(str_len);
+ strcpy(var_query,"INSERT INTO ");
+ strcat(var_query, table_name);
+ strcat(var_query, "(");
- tmp = (const char *)sqlite3_column_text(stmt, 0);
- if (tmp && tmp[0] != '\0') {
- if (sscanf(tmp, "%lld", &photo->id) != 1) {
+ for(int col = 0; col < col_count ; col++) {
- }
- }
+ char* col_name = eina_list_nth(column_names, col);
+ var_query = realloc(var_query, strlen(var_query)+strlen(col_name) + 1);
+ strcat(var_query, col_name);
- photo->access_hash = sqlite3_column_int(stmt, 2);
- photo->user_id = sqlite3_column_int(stmt, 3);
- photo->date = sqlite3_column_int(stmt, 4);
- tmp = (const char *)sqlite3_column_text(stmt, 5);
- if (tmp && tmp[0] != '\0') {
- photo->caption = strdup(tmp);
+ if(col < col_count - 1){
+ var_query = realloc(var_query, strlen(var_query) + 2);
+ strcat(var_query, ",");
+ } else {
+ var_query = realloc(var_query, strlen(var_query) + strlen(") VALUES (") + 1);
+ strcat(var_query, ") VALUES (");
}
+ }
- tmp = (const char *)sqlite3_column_text(stmt, 6);
- if (tmp && tmp[0] != '\0') {
- if (sscanf(tmp, "%lf", &photo->geo.longitude) != 1) {
+ int col_val_count = eina_list_count(column_values);
- }
- }
+ for(int col = 0; col < col_val_count ; col++) {
- tmp = (const char *)sqlite3_column_text(stmt, 7);
- if (tmp && tmp[0] != '\0') {
- if (sscanf(tmp, "%lf", &photo->geo.latitude) != 1) {
+ char* col_type = eina_list_nth(column_types, col);
+ char* col_value = NULL;
+ if(!strcmp(col_type, "INTEGER") || !strcmp(col_type, "INTEGER PRIMARY KEY NOT NULL")) {
+ int* tmp_value = eina_list_nth(column_values, col);
- }
- }
+#if 0
+ long long val = *tmp_value;
+ col_value = (char*)malloc(50);
+ //sprintf(col_value, "%lld", *tmp_value);
+ sprintf(col_value, "%lld", val);
+#endif
- photo->sizes_num = sqlite3_column_int(stmt, 8);
- photo->sizes = calloc(4, sizeof(*photo->sizes));
- for (i = 0; i < photo->sizes_num; i++) {
- if (i < photo->sizes_num) {
- tmp = (const char *)sqlite3_column_text(stmt, 9 + (i * 9));
- if (tmp && tmp[0] != '\0') {
- photo->sizes[i].type = strdup(tmp);
- }
- photo->sizes[i].loc.dc = sqlite3_column_int(stmt, 10 + (i * 9));
- tmp = (const char *)sqlite3_column_text(stmt, 11 + (i * 9));
- if (tmp && tmp[0] != '\0') {
- if (sscanf(tmp, "%lld", &photo->sizes[i].loc.volume) != 1) {
+ int act_val = (*tmp_value);
+ col_value = (char*)malloc(50);
+ sprintf(col_value, "%d", act_val);
- }
- }
- photo->sizes[i].loc.local_id = sqlite3_column_int(stmt, 12);
- tmp = (const char *)sqlite3_column_text(stmt, 13 + (i * 9));
- if (tmp && tmp[0] != '\0') {
- if (sscanf(tmp, "%lld", &photo->sizes[i].loc.secret) != 1) {
+ var_query = realloc(var_query, strlen(var_query)+strlen(col_value) + 1);
+ strcat(var_query, col_value);
- }
- }
- photo->sizes[i].w = sqlite3_column_int(stmt, 14 + (i * 9));
- photo->sizes[i].h = sqlite3_column_int(stmt, 15 + (i * 9));
- photo->sizes[i].size = sqlite3_column_int(stmt, 16 + (i * 9));
+ } else if(!strcmp(col_type, "TEXT") || !strcmp(col_type, "TEXT PRIMARY KEY NOT NULL")) {
+ char* tmp_value = eina_list_nth(column_values, col);
+ col_value = (char*)malloc(strlen(tmp_value) + 1);
+ strcpy(col_value,tmp_value);
- tmp = (const char *)sqlite3_column_text(stmt, 17 + (i * 9));
- if (tmp && tmp[0] != '\0') {
- photo->sizes[i].data = strdup(tmp);
- }
- }
- }
-
- // 45: phone
- // 46: first_name
- // 47: last_name
- // 48: file_path
- info = photo;
- } else if (*media_type == tgl_message_media_document) {
- struct tgl_document *document;
-
- document = calloc(1, sizeof(*document));
- if (!document) {
- sqlite3_finalize(stmt);
- return NULL;
- }
-
- tmp = (const char *)sqlite3_column_text(stmt, 0);
- if (tmp && tmp[0] != '\0') {
- if (sscanf(tmp, "%lld", &document->id) != 1) {
-
- }
- }
+ var_query = realloc(var_query, strlen(var_query)+strlen("'") + 1);
+ strcat(var_query, "'");
- tmp = (const char *)sqlite3_column_text(stmt, 2);
- if (tmp && tmp[0] != '\0') {
- if (sscanf(tmp, "%lld", &document->access_hash) != 1) {
+ var_query = realloc(var_query, strlen(var_query)+strlen(col_value) + 1);
+ strcat(var_query, col_value);
- }
+ var_query = realloc(var_query, strlen(var_query)+strlen("'") + 1);
+ strcat(var_query, "'");
}
- document->user_id = sqlite3_column_int(stmt, 3);
- document->date = sqlite3_column_int(stmt, 4);
-
- tmp = (const char *)sqlite3_column_text(stmt, 5);
- if (tmp && tmp[0] != '\0') {
- document->caption = strdup(tmp);
+ if(col < col_count - 1){
+ var_query = realloc(var_query, strlen(var_query) + 3);
+ strcat(var_query, ", ");
+ } else {
+ var_query = realloc(var_query, strlen(var_query) + 3);
+ strcat(var_query, ");");
}
-
- // 6: "longitude TEXT,"
- // 7: "latitude TEXT,"
- // 9 ~ 44: Photo informations
-
- document->size = sqlite3_column_int(stmt, 8);
-
- // 45 "phone TEXT,"
- // 46 "first_name TEXT,"
- // 47 "last_name TEXT,"
- // 48 "file_path TEXT)"
-
- info = document;
- } else {
- /**
- * @todo
- * Handles me
- */
- }
-
- sqlite3_finalize(stmt);
- return info;
-}
-
-int tg_db_insert_media_info(const char *table_name, struct tgl_message *msg, const char *filename)
-{
- const char *dml;
- const char *tmp;
- int ret;
- sqlite3_stmt *stmt;
- int i;
-
- dml = "INSERT INTO ? VALUES (" \
- "?, ?, ?, ?, ?, " \
- "?, ?, ?, ?, ?, " \
- "?, ?, ?, ?, ?, " \
- "?, ?, ?, ?, ?, " \
- "?, ?, ?, ?, ?, " \
- "?, ?, ?, ?, ?, " \
- "?, ?, ?, ?, ?, " \
- "?, ?, ?, ?, ?, " \
- "?, ?, ?, ?, ?, " \
- "?, ?, ?, ?)";
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
-
- ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
-
- switch (msg->media.type) {
- case tgl_message_media_photo:
- tmp = tg_common_to_string("%lld", msg->media.photo.id);
- ret = sqlite3_bind_text(stmt, 2, tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 3, msg->media.type);
- ret = sqlite3_bind_int64(stmt, 4, msg->media.photo.access_hash);
- ret = sqlite3_bind_int(stmt, 5, msg->media.photo.user_id);
- ret = sqlite3_bind_int(stmt, 6, msg->media.photo.date);
- ret = sqlite3_bind_text(stmt, 7, msg->media.photo.caption, -1, SQLITE_TRANSIENT);
-
- tmp = tg_common_to_string("%lf", msg->media.photo.geo.longitude);
- ret = sqlite3_bind_text(stmt, 8, tmp, -1, SQLITE_TRANSIENT);
-
- tmp = tg_common_to_string("%lf", msg->media.photo.geo.latitude);
- ret = sqlite3_bind_text(stmt, 9, tmp, -1, SQLITE_TRANSIENT);
-
- ret = sqlite3_bind_int(stmt, 10, msg->media.photo.sizes_num);
- for (i = 0; i < 4; i++) {
- if (i < msg->media.photo.sizes_num) {
- ret = sqlite3_bind_text(stmt, 11 + (i * 9), msg->media.photo.sizes[i].type, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 12 + (i * 9), msg->media.photo.sizes[i].loc.dc);
- tmp = tg_common_to_string("%lld", msg->media.photo.sizes[i].loc.volume);
- ret = sqlite3_bind_text(stmt, 13 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 14 + (i * 9), msg->media.photo.sizes[i].loc.local_id);
- tmp = tg_common_to_string("%lld", msg->media.photo.sizes[i].loc.secret);
- ret = sqlite3_bind_text(stmt, 15 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 16 + (i * 9), msg->media.photo.sizes[i].w);
- ret = sqlite3_bind_int(stmt, 17 + (i * 9), msg->media.photo.sizes[i].h);
- ret = sqlite3_bind_int(stmt, 18 + (i * 9), msg->media.photo.sizes[i].size);
- ret = sqlite3_bind_text(stmt, 19 + (i * 9), msg->media.photo.sizes[i].data, -1, SQLITE_TRANSIENT);
- } else {
- ret = sqlite3_bind_text(stmt, 11 + (i * 9), " ", -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 12 + (i * 9), 0);
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 13 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 14 + (i * 9), 0);
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 15 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 16 + (i * 9), 0);
- ret = sqlite3_bind_int(stmt, 17 + (i * 9), 0);
- ret = sqlite3_bind_int(stmt, 18 + (i * 9), 0);
- ret = sqlite3_bind_text(stmt, 19 + (i * 9), " ", -1, SQLITE_TRANSIENT);
- }
- }
- break;
- case tgl_message_media_document:
- tmp = tg_common_to_string("%lld", msg->media.document.id);
- ret = sqlite3_bind_text(stmt, 2, tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 3, msg->media.type);
- ret = sqlite3_bind_int64(stmt, 4, msg->media.document.access_hash);
- ret = sqlite3_bind_int(stmt, 5, msg->media.document.user_id);
- ret = sqlite3_bind_int(stmt, 6, msg->media.document.date);
- ret = sqlite3_bind_text(stmt, 7, msg->media.document.caption, -1, SQLITE_TRANSIENT);
- tmp = tg_common_to_string("%lf", 0.0f);
- ret = sqlite3_bind_text(stmt, 8, tmp, -1, SQLITE_TRANSIENT);
- tmp = tg_common_to_string("%lf", 0.0f);
- ret = sqlite3_bind_text(stmt, 9, tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 10, msg->media.document.size);
- for (i = 0; i < 4; i++) {
- ret = sqlite3_bind_text(stmt, 11 + (i * 9), " ", -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 12 + (i * 9), 0);
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 13 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 14 + (i * 9), 0);
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 15 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 16 + (i * 9), 0);
- ret = sqlite3_bind_int(stmt, 17 + (i * 9), 0);
- ret = sqlite3_bind_int(stmt, 18 + (i * 9), 0);
- ret = sqlite3_bind_text(stmt, 19 + (i * 9), " ", -1, SQLITE_TRANSIENT);
- }
- break;
- default:
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 2, tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 3, msg->media.type);
- ret = sqlite3_bind_int64(stmt, 4, 0);
- ret = sqlite3_bind_int(stmt, 5, 0);
- ret = sqlite3_bind_int(stmt, 6, 0);
- ret = sqlite3_bind_text(stmt, 7, " ", -1, SQLITE_TRANSIENT);
- tmp = tg_common_to_string("%lf", 0.0f);
- ret = sqlite3_bind_text(stmt, 8, tmp, -1, SQLITE_TRANSIENT);
- tmp = tg_common_to_string("%lf", 0.0f);
- ret = sqlite3_bind_text(stmt, 9, tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 10, 0);
- for (i = 0; i < 4; i++) {
- ret = sqlite3_bind_text(stmt, 11 + (i * 9), " ", -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 12 + (i * 9), 0);
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 13 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 14 + (i * 9), 0);
- tmp = tg_common_to_string("%lld", 0);
- ret = sqlite3_bind_text(stmt, 15 + (i * 9), tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 16 + (i * 9), 0);
- ret = sqlite3_bind_int(stmt, 17 + (i * 9), 0);
- ret = sqlite3_bind_int(stmt, 18 + (i * 9), 0);
- ret = sqlite3_bind_text(stmt, 19 + (i * 9), " ", -1, SQLITE_TRANSIENT);
- }
- break;
+ free(col_value);
}
- ret = sqlite3_bind_text(stmt, 46, msg->media.phone, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_text(stmt, 47, msg->media.first_name, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_text(stmt, 48, msg->media.last_name, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_text(stmt, 49, filename, -1, SQLITE_TRANSIENT);
-
- ret = sqlite3_step(stmt);
- sqlite3_finalize(stmt);
-
- if (ret != SQLITE_DONE) {
- return -EIO;
+ ret = sqlite3_exec(db,var_query, NULL, NULL, &err_msg);
+ close_database(db);
+ if( ret != SQLITE_OK ){
+ sqlite3_free(err_msg);
+ return EINA_FALSE;
}
+ return EINA_TRUE;
- return 0;
}
-int tg_db_create_table_chat_info(const char *table_name)
-{
- const char *ddl;
- ddl = "CREATE TABLE ? (" \
- "chat_id INTEGER PRIMARY KEY NOT NULL," \
- "flags INTEGER," \
- "print_title TEXT," \
- "struct_version INTEGER," \
- "photo_id TEXT," \
- "photo_path TEXT," \
- "title TEXT," \
- "users_num INTEGER," \
- "user_list_size INTEGER," \
- "user_list_version INTEGER," \
- "inviter_id INTEGER," \
- "chat_users TEXT," \
- "date INTEGER," \
- "version INTEGER," \
- "admin_id INTEGER)";
- return create_table_query_to_db(ddl, table_name);
-}
-int tg_db_count_chat_info(const char *table_name, struct tgl_chat *chat)
+Eina_Bool update_table(const char* table_name, Eina_List* column_names, Eina_List* column_types, Eina_List* column_values, const char* where_clause)
{
- const char *dml;
- sqlite3_stmt *stmt;
- int ret;
-
- dml = "SELECT COUNT(*) FROM ? WHERE chat_id = ?";
+ if( !table_name || ! column_names || !column_types || !column_values) {
+ return EINA_FALSE;
+ }
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 2, chat->id.id);
- ret = sqlite3_step(stmt);
- ret = sqlite3_column_int(stmt, 0);
- sqlite3_finalize(stmt);
- return ret;
-}
+ sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
-int tg_db_update_chat_info(const char *table_name, struct tgl_chat *chat, char *photo)
-{
- const char *dml;
- int ret;
- sqlite3_stmt *stmt;
- const char *tmp;
- char *str;
- int i;
- int str_len;
- int str_size;
-
- dml = "UPDATE ? SET " \
- "chat_id = ?, " \
- "flags = ?, " \
- "print_title = ?, " \
- "struct_version = ?, " \
- "photo_id = ?, " \
- "photo_path = ?, " \
- "title = ?, " \
- "users_num = ?, " \
- "user_list_size = ?, " \
- "user_list_version = ?, " \
- "inviter_id = ?, " \
- "chat_users = ?, " \
- "date = ?, " \
- "version = ?, " \
- "admin_id = ? " \
- "WHERE chat_id = ?";
-
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 2, chat->id.id);
- ret = sqlite3_bind_int(stmt, 3, chat->flags);
- ret = sqlite3_bind_text(stmt, 4, chat->print_title, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 5, chat->structure_version);
- tmp = tg_common_to_string("%lld", chat->photo.id);
- ret = sqlite3_bind_text(stmt, 6, tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_text(stmt, 7, photo, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_text(stmt, 8, chat->title, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 9, chat->users_num);
- ret = sqlite3_bind_int(stmt, 10, chat->user_list_size);
- ret = sqlite3_bind_int(stmt, 11, chat->user_list_version);
- ret = sqlite3_bind_int(stmt, 12, chat->user_list[0].inviter_id);
-
- str_size = 64;
- str_len = 0;
- str = malloc(str_size);
- for (i = 0; i < chat->user_list_size; i++) {
- str_len += snprintf(str + str_len, str_size - str_len - 1, "%d, ", chat->user_list[i].user_id);
- if (str_size - str_len < 32) {
- char *ptr;
- str_size <<= 1; /* doulbing current size */
- ptr = realloc(str, str_size);
- if (!ptr) {
- break;
- }
- str = ptr;
- }
- }
- /* Cut off the last colon */
- str[str_len - 2] = '\0';
- ret = sqlite3_bind_text(stmt, 13, str, str_len - 2, SQLITE_TRANSIENT);
- free(str);
- ret = sqlite3_bind_int(stmt, 14, chat->date);
- ret = sqlite3_bind_int(stmt, 15, chat->version);
- ret = sqlite3_bind_int(stmt, 16, chat->admin_id);
- ret = sqlite3_bind_int(stmt, 17, chat->id.id);
-
- ret = sqlite3_step(stmt);
- sqlite3_finalize(stmt);
- return 0;
-}
+ int ret = 0 ;
+ char* err_msg = 0;
+ int col_count = eina_list_count(column_names);
-int tg_db_insert_chat_info(const char *table_name, struct tgl_chat *chat, char *photo_path)
-{
- const char *dml;
- int ret;
- sqlite3_stmt *stmt;
- const char *tmp;
- char *str;
- int i;
- int str_len;
- int str_size;
-
- dml = "INSERT INTO ? VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 2, chat->id.id);
- ret = sqlite3_bind_text(stmt, 3, chat->print_title, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 4, chat->structure_version);
- tmp = tg_common_to_string("%lld", chat->photo.id);
- ret = sqlite3_bind_text(stmt, 5, tmp, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_text(stmt, 6, photo_path, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_text(stmt, 7, chat->title, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 8, chat->users_num);
- ret = sqlite3_bind_int(stmt, 9, chat->user_list_size);
- ret = sqlite3_bind_int(stmt, 10, chat->user_list_version);
- if (chat->user_list) {
- ret = sqlite3_bind_int(stmt, 11, chat->user_list[0].inviter_id);
- } else {
- ret = sqlite3_bind_int(stmt, 11, 0);
- }
+ int str_len = strlen("UPDATE ") + strlen(table_name) + strlen(" SET ") + 1;
+ char* var_query = (char*)malloc(str_len);
+ strcpy(var_query,"UPDATE ");
+ strcat(var_query, table_name);
+ strcat(var_query, " SET ");
- if (chat->user_list_size > 0) {
- str_size = 64;
- str_len = 0;
- str = malloc(str_size);
- for (i = 0; i < chat->user_list_size; i++) {
- str_len += snprintf(str + str_len, str_size - str_len - 1, "%d, ", chat->user_list[i].user_id);
- if (str_size - str_len < 32) {
- char *ptr;
- str_size <<= 1; /* doulbing current size */
- ptr = realloc(str, str_size);
- if (!ptr) {
- break;
- }
- str = ptr;
- }
- }
- /* Cut off the last colon */
- str[str_len - 2] = '\0';
- ret = sqlite3_bind_text(stmt, 12, str, str_len - 2, SQLITE_TRANSIENT);
- free(str);
- } else {
- ret = sqlite3_bind_text(stmt, 12, "", -1, SQLITE_TRANSIENT);
- }
- ret = sqlite3_bind_int(stmt, 13, chat->date);
- ret = sqlite3_bind_int(stmt, 14, chat->version);
- ret = sqlite3_bind_int(stmt, 15, chat->admin_id);
- ret = sqlite3_step(stmt);
+ int col_val_count = eina_list_count(column_values);
- sqlite3_finalize(stmt);
- return 0;
-}
+ for(int col = 0; col < col_val_count ; col++) {
+ char* col_name = eina_list_nth(column_names, col);
+ char* col_type = eina_list_nth(column_types, col);
-int tg_db_create_table_message(const char *table_name)
-{
- const char *ddl;
-
- ddl = "CREATE TABLE ? (" \
- "msg_id INTEGER," \
- "flags INTEGER," \
- "fwd_from_id INTEGER," \
- "fwd_date INTEGER," \
- "from_id INTEGER," \
- "to_id INTEGER," \
- "out INTEGER," \
- "unread INTEGER," \
- "date INTEGER," \
- "service INTEGER," \
- "message TEXT," \
- "message_state INTEGER," \
- "message_len INTEGER," \
- "media_type INTEGER," \
- "media_id TEXT," \
- "unique_id INTEGER)";
-
- return create_table_query_to_db(ddl, table_name);
-}
+ char* col_value = NULL;
+ if(!strcmp(col_type, "INTEGER") || !strcmp(col_type, "INTEGER PRIMARY KEY NOT NULL")) {
+ int* tmp_value = eina_list_nth(column_values, col);
-struct tgl_message *tg_db_get_message(const char *table_name, long long id)
-{
- struct tgl_message *msg;
- int ret;
- sqlite3_stmt *stmt;
- const char *dml;
- const char *tmp;
+ int act_val = (*tmp_value);
+ col_value = (char*)malloc(50);
+ sprintf(col_value, "%d", act_val);
- dml = "SELECT * FROM ? WHERE msg_id = ?";
+ var_query = realloc(var_query, strlen(var_query) + strlen(col_name) + strlen(" = ") + strlen(col_value) + 1);
+ strcat(var_query, col_name);
+ strcat(var_query, " = ");
+ strcat(var_query, col_value);
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- return NULL;
- }
+ } else if(!strcmp(col_type, "TEXT") || !strcmp(col_type, "TEXT PRIMARY KEY NOT NULL")) {
- ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return NULL;
- }
+ char* tmp_value = eina_list_nth(column_values, col);
+ col_value = (char*)malloc(strlen(tmp_value) + 1);
+ strcpy(col_value,tmp_value);
- ret = sqlite3_bind_int64(stmt, 2, id);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return NULL;
- }
+ var_query = realloc(var_query, strlen(var_query)+ strlen(col_name) + strlen(" = ")+strlen("'") + 1);
+ strcat(var_query, col_name);
+ strcat(var_query, " = ");
+ strcat(var_query, "'");
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_ROW) {
- sqlite3_finalize(stmt);
- return NULL;
- }
+ var_query = realloc(var_query, strlen(var_query)+strlen(col_value) + 1);
+ strcat(var_query, col_value);
- msg = calloc(1, sizeof(*msg));
- if (!msg) {
- sqlite3_finalize(stmt);
- return NULL;
- }
+ var_query = realloc(var_query, strlen(var_query)+strlen("'") + 1);
+ strcat(var_query, "'");
+ }
- msg->id = id;
- msg->flags = sqlite3_column_int(stmt, 1);
- msg->fwd_from_id.id = sqlite3_column_int(stmt, 2);
- msg->fwd_date = sqlite3_column_int(stmt, 3);
- msg->from_id.id = sqlite3_column_int(stmt, 4);
- msg->to_id.id = sqlite3_column_int(stmt, 5);
- msg->out = sqlite3_column_int(stmt, 6);
- msg->unread = sqlite3_column_int(stmt, 7);
- msg->date = sqlite3_column_int(stmt, 8);
- msg->service = sqlite3_column_int(stmt, 9);
- tmp = (const char *)sqlite3_column_text(stmt, 10);
- if (tmp && tmp[0] != '\0') {
- msg->message = strdup(tmp);
- if (!msg->message) {
- /*
- * @todo
- */
+ if(col < col_count - 1){
+ var_query = realloc(var_query, strlen(var_query) + 3);
+ strcat(var_query, ", ");
+ } else {
+ var_query = realloc(var_query, strlen(var_query) + 2);
+ strcat(var_query, " ");
}
+ free(col_value);
}
- msg->msg_state = sqlite3_column_int(stmt, 11);
- msg->message_len = sqlite3_column_int(stmt, 12);
- msg->media.type = sqlite3_column_int(stmt, 13);
- if (msg->media.type == tgl_message_media_photo) {
- msg->media.photo.id = sqlite3_column_int64(stmt, 14);
- } else if (msg->media.type == tgl_message_media_document) {
- msg->media.document.id = sqlite3_column_int64(stmt, 14);
- } else {
- // 14
- }
- //msg->id = sqlite3_column_int64(stmt, 15);
- sqlite3_finalize(stmt);
- return msg;
-}
-int tg_db_update_message(const char *table_name, struct tgl_message *M, long long unique_id)
-{
- int ret;
- sqlite3_stmt *stmt;
- const char *dml;
- dml = "UPDATE ? SET " \
- "msg_id = ?, " \
- "flags = ?, " \
- "fwd_from_id = ?, " \
- "fwd_date = ?, " \
- "from_id = ?, " \
- "to_id = ?, " \
- "out = ?, " \
- "unread = ?, " \
- "date = ?, " \
- "service = ?, " \
- "message = ?, " \
- "message_state = ?, " \
- "message_len = ?, " \
- "media_type = ?, " \
- "media_id = ?, " \
- "WHERE ? = ?";
-
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int64(stmt, 2, M->id);
- ret = sqlite3_bind_int(stmt, 3, M->flags);
- ret = sqlite3_bind_int(stmt, 4, M->fwd_from_id.id);
- ret = sqlite3_bind_int(stmt, 5, M->fwd_date);
- ret = sqlite3_bind_int(stmt, 6, M->from_id.id);
- ret = sqlite3_bind_int(stmt, 7, M->to_id.id);
- ret = sqlite3_bind_int(stmt, 8, M->out);
- ret = sqlite3_bind_int(stmt, 9, M->unread);
- ret = sqlite3_bind_int(stmt, 10, M->date);
- ret = sqlite3_bind_int(stmt, 11, M->service);
- ret = sqlite3_bind_text(stmt, 12, M->message, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 13, M->msg_state);
- ret = sqlite3_bind_int(stmt, 14, M->message_len);
- ret = sqlite3_bind_int(stmt, 15, M->media.type);
- if (M->media.type == tgl_message_media_photo) {
- ret = sqlite3_bind_int64(stmt, 16, M->media.photo.id);
- } else if (M->media.type == tgl_message_media_document) {
- ret = sqlite3_bind_int64(stmt, 16, M->media.document.id);
- } else {
- ret = sqlite3_bind_int64(stmt, 17, 0);
- }
- if (unique_id > 0) {
- ret = sqlite3_bind_text(stmt, 18, "unique_id", -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int64(stmt, 19, unique_id);
- } else {
- ret = sqlite3_bind_text(stmt, 18, "msg_id", -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int64(stmt, 19, M->id);
- }
- ret = sqlite3_step(stmt);
- sqlite3_finalize(stmt);
- return 0;
-}
+ var_query = realloc(var_query, strlen(var_query) + strlen(" WHERE ") + strlen(where_clause) + 2);
+ strcat(var_query, " WHERE ");
+ strcat(var_query, where_clause);
+ strcat(var_query, ";");
-int tg_db_insert_message(const char *table_name, struct tgl_message *M, long long unique_id)
-{
- int ret;
- sqlite3_stmt *stmt;
- const char *dml;
-
- dml = "INSERT INTO ? VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 2, M->id);
- ret = sqlite3_bind_int(stmt, 3, M->flags);
- ret = sqlite3_bind_int(stmt, 4, M->fwd_from_id.id);
- ret = sqlite3_bind_int(stmt, 5, M->fwd_date);
- ret = sqlite3_bind_int(stmt, 6, M->from_id.id);
- ret = sqlite3_bind_int(stmt, 7, M->to_id.id);
- ret = sqlite3_bind_int(stmt, 8, M->out);
- ret = sqlite3_bind_int(stmt, 9, M->unread);
- ret = sqlite3_bind_int(stmt, 10, M->date);
- ret = sqlite3_bind_int(stmt, 11, M->service);
- ret = sqlite3_bind_text(stmt, 12, M->message, -1, SQLITE_TRANSIENT);
- ret = sqlite3_bind_int(stmt, 13, M->msg_state);
- ret = sqlite3_bind_int(stmt, 14, M->message_len);
- ret = sqlite3_bind_int(stmt, 15, M->media.type);
- if (M->media.type == tgl_message_media_photo) {
- ret = sqlite3_bind_int64(stmt, 16, M->media.photo.id);
- } else if (M->media.type == tgl_message_media_document) {
- ret = sqlite3_bind_int64(stmt, 16, M->media.document.id);
- } else {
- ret = sqlite3_bind_int64(stmt, 16, 0);
+ ret = sqlite3_exec(db,var_query, NULL,NULL, &err_msg);
+ close_database(db);
+ if( ret != SQLITE_OK ){
+ sqlite3_free(err_msg);
+ return EINA_FALSE;
}
- ret = sqlite3_bind_int64(stmt, 17, unique_id);
-
- ret = sqlite3_step(stmt);
- sqlite3_finalize(stmt);
- return ret == SQLITE_DONE ? 0 : -EIO;
-}
+ return EINA_TRUE;
-int tg_db_create_table_peer_info(const char *table_name)
-{
- const char *ddl;
- ddl = "CREATE TABLE ? (" \
- "user_id INTEGER PRIMARY KEY NOT NULL," \
- "peer_type INTEGER," \
- "flags INTEGER," \
- "message_id TEXT," \
- "message_date INTEGER," \
- "print_name TEXT," \
- "struct_version INTEGER," \
- "unread_message_count INTEGER," \
- "last_seen INTEGER," \
- "photo_path TEXT," \
- "photo_id INTEGER)";
- return create_table_query_to_db(ddl, table_name);
}
-int tg_db_update_peer_info(const char *tablename, tgl_peer_t *UC, int last_msg_id, int unread_count)
+Eina_Bool get_values_from_table(const char* table_name, Eina_List* column_names, int (*callback)(void*,int,char**,char**), const char* where_clause, void* data_to_callback)
{
- const char *dml;
- sqlite3_stmt *stmt;
- const char *str;
- int ret;
-
- dml = "UPDATE ? SET " \
- "peer_type = ?," \
- "flags = ?," \
- "message_id = ?," \
- "message_data = ?," \
- "print_name = ?," \
- "struct_version = ?," \
- "unread_message_count = ?," \
- "last_seen = ?," \
- "photo_path = ?," \
- "photo_id = ? WHERE user_id = ?";
-
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- return -EFAULT;
- }
-
- ret = sqlite3_bind_text(stmt, 1, tablename, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_int(stmt, 2, UC->id.type);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_int(stmt, 3, UC->flags);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- str = tg_common_to_string("%d", last_msg_id);
- ret = sqlite3_bind_text(stmt, 4, str, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_int(stmt, 5, UC->last ? UC->last->date : 0);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_text(stmt, 6, UC->print_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_int(stmt, 7, UC->structure_version);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_int(stmt, 8, unread_count);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- if (UC->id.type == TGL_PEER_USER ) {
- ret = sqlite3_bind_int(stmt, 9, UC->user.status.when);
- } else if (UC->id.type == TGL_PEER_CHAT ) {
- ret = sqlite3_bind_int(stmt, 9, UC->chat.date);
- } else {
- ret = sqlite3_bind_int(stmt, 9, 0);
- }
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_text(stmt, 10, "", -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_int(stmt, 11, UC->photo.id);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
+ if (!table_name) {
+ return EINA_FALSE;
}
- ret = sqlite3_bind_int(stmt, 12, UC->id.id);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
+ /*****No rows identification*****/
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_DONE) {
- sqlite3_finalize(stmt);
- return -EIO;
- }
+ char* row_cnt_qry = (char*)malloc(strlen("SELECT COUNT(*) FROM ") + strlen(table_name) + strlen(";") +1);
+ strcpy(row_cnt_qry, "SELECT COUNT(*) FROM ");
+ strcat(row_cnt_qry, table_name);
+ strcat(row_cnt_qry, ";");
- sqlite3_finalize(stmt);
- return 0;
-}
+ int no_of_rows = 0;
+ //ret = sqlite3_exec(s_info.db,var_query, callback,(void*)s_info.db, &err_msg);
-int tg_db_insert_peer_info(const char *tablename, tgl_peer_t *UC, int last_msg_id, int unread_count)
-{
- const char *dml;
sqlite3_stmt *stmt;
- const char *str;
- int ret;
-
- dml = "INSERT INTO ? ("
- "user_id,peer_type,flags,message_id,message_date," \
- "print_name,struct_version,unread_message_count,last_seen," \
- "photo_path,photo_id) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
-
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- return -EFAULT;
- }
-
- ret = sqlite3_bind_text(stmt, 1, tablename, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_int(stmt, 2, UC->id.id);
- if (ret != SQLITE_OK) {
+ if (sqlite3_prepare_v2(db, row_cnt_qry, -1, &stmt, NULL) == SQLITE_OK) {
+ if (sqlite3_step(stmt) == SQLITE_ERROR) {
+ no_of_rows = 0;
+ } else {
+ no_of_rows = sqlite3_column_int(stmt, 0);
+ }
sqlite3_finalize(stmt);
- return -EFAULT;
}
- ret = sqlite3_bind_int(stmt, 3, UC->id.type);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
+ free(row_cnt_qry);
+ if(no_of_rows <= 0) {
+ close_database(db);
+ return EINA_FALSE;
}
+ close_database(db);
+ /********************************/
- ret = sqlite3_bind_int(stmt, 4, UC->flags);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ int ret = 0 ;
+ char* err_msg = 0;
+ //int col_count = eina_list_count(column_names);
- str = tg_common_to_string("%d", last_msg_id);
- ret = sqlite3_bind_text(stmt, 5, str, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ db = create_database(DEFAULT_TG_DATABASE_PATH);
- ret = sqlite3_bind_int(stmt, 6, UC->last ? UC->last->date : 0);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ int str_len = strlen("SELECT ") + 1;
+ char* var_query = (char*)malloc(str_len);
+ strcpy(var_query,"SELECT ");
+ if(!column_names) {
+ var_query = realloc(var_query, strlen(var_query) + 3);
+ strcat(var_query, "* ");
+ } else {
- ret = sqlite3_bind_text(stmt, 7, UC->print_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ int col_count = eina_list_count(column_names);
+ char* col_name = NULL;
+ for(int col = 0; col < col_count ; col++) {
+ col_name = eina_list_nth(column_names, col);
+ var_query = realloc(var_query, strlen(var_query)+strlen(col_name) + 1);
+ strcat(var_query, col_name);
+ col_name = NULL;
+ var_query = realloc(var_query, strlen(var_query)+strlen(" ") + 1);
+
+ if(col < col_count - 1){
+ var_query = realloc(var_query, strlen(var_query) + 3);
+ strcat(var_query, ", ");
+ } else {
+ var_query = realloc(var_query, strlen(var_query) + 2);
+ strcat(var_query, " ");
+ }
+ }
- ret = sqlite3_bind_int(stmt, 8, UC->structure_version);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
}
- ret = sqlite3_bind_int(stmt, 9, unread_count);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ var_query = realloc(var_query, strlen(var_query) + strlen("FROM ") + 2);
+ strcat(var_query, "FROM ");
+ var_query = realloc(var_query, strlen(var_query) + strlen(table_name) + 1);
+ strcat(var_query, table_name);
- if (UC->id.type == TGL_PEER_USER ) {
- ret = sqlite3_bind_int(stmt, 10, UC->user.status.when);
- } else if (UC->id.type == TGL_PEER_CHAT ) {
- ret = sqlite3_bind_int(stmt, 10, UC->chat.date);
- } else {
- ret = sqlite3_bind_int(stmt, 10, 0);
- }
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
+ if (where_clause) {
+ var_query = realloc(var_query, strlen(var_query)+strlen(" WHERE ") + 1);
+ strcat(var_query, " WHERE ");
+ var_query = realloc(var_query, strlen(var_query)+strlen(where_clause) + 1);
+ strcat(var_query, where_clause);
}
- ret = sqlite3_bind_text(stmt, 11, "", -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ var_query = realloc(var_query, strlen(var_query) + 2);
+ strcat(var_query, ";");
- ret = sqlite3_bind_int(stmt, 12, UC->photo.id);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
+ ret = sqlite3_exec(db,var_query, callback,(void*)data_to_callback, &err_msg);
+ close_database(db);
+ if( ret != SQLITE_OK ){
+ sqlite3_free(err_msg);
+ return EINA_FALSE;
}
- sqlite3_finalize(stmt);
- return 0;
+ free(var_query);
+ return EINA_TRUE;
}
-int tg_db_update_user_info(const char *tablename, struct tgl_user *U)
+Eina_List *get_values_from_table_sync(const char* table_name, Eina_List* column_names, Eina_List* column_types, const char* where_clause)
{
- const char *dml;
- sqlite3_stmt *stmt;
- int ret;
+ Eina_List* query_vals = NULL;
- dml = "UPDATE ? SET print_name = ?, structure_version = ?, first_name = ?, last_name = ?, phone = ?, access_hash = ?, real_first_name = ?, real_last_name = ?, username = ?, online = ?, last_seen = ? WHERE user_id = ?";
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- return -EFAULT;
+ if (!table_name) {
+ return (Eina_List *)NULL;
}
- ret = sqlite3_bind_text(stmt, 1, tablename, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
+ /*****No rows identification*****/
- ret = sqlite3_bind_text(stmt, 2, U->print_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ char* row_cnt_qry = (char *)malloc(strlen("SELECT COUNT(*) FROM ") + strlen(table_name) + strlen(";") +1);
+ strcpy(row_cnt_qry, "SELECT COUNT(*) FROM ");
+ strcat(row_cnt_qry, table_name);
+ strcat(row_cnt_qry, ";");
- ret = sqlite3_bind_int(stmt, 3, U->structure_version);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_text(stmt, 4, U->first_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_text(stmt, 5, U->last_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_text(stmt, 6, U->phone, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_int(stmt, 7, U->access_hash);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_text(stmt, 8, U->real_first_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_text(stmt, 9, U->real_last_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_text(stmt, 10, U->username, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
-
- ret = sqlite3_bind_int(stmt, 11, U->status.online);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ int no_of_rows = 0;
+ //ret = sqlite3_exec(s_info.db,var_query, callback,(void*)s_info.db, &err_msg);
- ret = sqlite3_bind_int(stmt, 12, U->last->date);
- if (ret != SQLITE_OK) {
+ sqlite3_stmt *stmt;
+ if (sqlite3_prepare_v2(db, row_cnt_qry, -1, &stmt, NULL) == SQLITE_OK) {
+ if (sqlite3_step(stmt) == SQLITE_ERROR) {
+ no_of_rows = 0;
+ } else {
+ no_of_rows = sqlite3_column_int(stmt, 0);
+ }
sqlite3_finalize(stmt);
- return -EFAULT;
}
-
- ret = sqlite3_bind_int(stmt, 13, U->id.id);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
+ close_database(db);
+ free(row_cnt_qry);
+ if(no_of_rows <= 0) {
+ return (Eina_List *)NULL;
}
- if (sqlite3_step(stmt) != SQLITE_DONE) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ /********************************/
+ db = create_database(DEFAULT_TG_DATABASE_PATH);
+ int ret = 0 ;
+ char* err_msg = 0;
+ //int col_count = eina_list_count(column_names);
- sqlite3_finalize(stmt);
- return 0;
-}
+ int str_len = strlen("SELECT ") + 1;
+ char* var_query = (char*)malloc(str_len);
+ strcpy(var_query,"SELECT ");
+ if(!column_names) {
+ var_query = realloc(var_query, strlen(var_query) + 3);
+ strcat(var_query, "* ");
+ } else {
-int tg_db_update_user_photo(const char *tablename, int uid, const char *photo, int photo_id)
-{
- const char *dml;
- int ret;
- sqlite3_stmt *stmt;
- int idx;
+ int col_count = eina_list_count(column_names);
+ char* col_name = NULL;
+ for(int col = 0; col < col_count ; col++) {
+ col_name = eina_list_nth(column_names, col);
+ var_query = realloc(var_query, strlen(var_query)+strlen(col_name) + 1);
+ strcat(var_query, col_name);
+ col_name = NULL;
+ var_query = realloc(var_query, strlen(var_query)+strlen(" ") + 1);
+
+ if(col < col_count - 1){
+ var_query = realloc(var_query, strlen(var_query) + 3);
+ strcat(var_query, ", ");
+ } else {
+ var_query = realloc(var_query, strlen(var_query) + 2);
+ strcat(var_query, " ");
+ }
+ }
- if (photo_id < 0) {
- dml = "UPDATE ? SET photo = ?, photo_id = ? WHERE user_id = ?";
- } else {
- dml = "UPDATE ? SET photo = ? WHERE user_id = ?";
}
- idx = 1;
+ var_query = realloc(var_query, strlen(var_query) + strlen("FROM ") + 2);
+ strcat(var_query, "FROM ");
+ var_query = realloc(var_query, strlen(var_query) + strlen(table_name) + 1);
+ strcat(var_query, table_name);
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- return -EFAULT;
+ if (where_clause) {
+ var_query = realloc(var_query, strlen(var_query)+strlen(" WHERE ") + 1);
+ strcat(var_query, " WHERE ");
+ var_query = realloc(var_query, strlen(var_query)+strlen(where_clause) + 1);
+ strcat(var_query, where_clause);
}
- ret = sqlite3_bind_text(stmt, idx++, tablename, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ var_query = realloc(var_query, strlen(var_query) + 2);
+ strcat(var_query, ";");
- ret = sqlite3_bind_text(stmt, idx++, photo, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
- if (photo_id >= 0) {
- ret = sqlite3_bind_int(stmt, idx++, photo_id);
+ ret = sqlite3_prepare_v2(db, var_query, -1, &stmt, 0);
+ close_database(db);
+ if( ret != SQLITE_OK ){
+ sqlite3_free(err_msg);
+ return NULL;
}
- ret = sqlite3_bind_int(stmt, idx++, uid);
- ret = sqlite3_step(stmt);
- sqlite3_finalize(stmt);
- if (ret != SQLITE_DONE) {
- return -EIO;
+ while(sqlite3_step(stmt) == SQLITE_ROW) {
+ int col_val_count = eina_list_count(column_names);
+ Eina_List* row_vals = NULL;
+ for(int col = 0; col < col_val_count ; col++) {
+ char* col_type = eina_list_nth(column_types, col);
+ if(!strcmp(col_type, "INTEGER") || !strcmp(col_type, "INTEGER PRIMARY KEY NOT NULL")) {
+ long long temp = sqlite3_column_int64(stmt, col);
+ int* val_int = (int *)malloc(sizeof(int));
+ *val_int = temp;
+ row_vals = eina_list_append(row_vals, val_int);
+ } else if(!strcmp(col_type, "TEXT") || !strcmp(col_type, "TEXT PRIMARY KEY NOT NULL")) {
+ const char *text = (const char *)sqlite3_column_text(stmt, col);
+ char *val_text;
+
+ val_text = strdup(text);
+ if (!val_text) {
+ /**
+ * Handling me.
+ */
+ } else {
+ row_vals = eina_list_append(row_vals, val_text);
+ }
+ }
+ }
+ query_vals = eina_list_append(query_vals, row_vals);
}
- return 0;
+ free(var_query);
+ return query_vals;
}
-int tg_db_insert_user_info(const char *tablename, struct tgl_user *U)
+Eina_List* get_values_from_table_sync_order_by(const char* table_name, Eina_List* column_names, Eina_List* column_types, const char* order_column, Eina_Bool is_asc, const char* where_clause)
{
- const char *dml;
- sqlite3_stmt *stmt;
- int ret;
-
- dml = "INSERT (user_id, print_name, structure_version, first_name, last_name, phone, access_hash, real_first_name, real_last_name, username, online, last_seen) INTO ? VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
-
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- return -EFAULT;
- }
-
- ret = sqlite3_bind_int(stmt, 1, U->id.id);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ Eina_List* query_vals = NULL;
- ret = sqlite3_bind_text(stmt, 2, U->print_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
+ if (!table_name) {
+ return NULL;
}
+ sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
+ /*****No rows identification*****/
- ret = sqlite3_bind_int(stmt, 3, U->structure_version);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ char* row_cnt_qry = (char*)malloc(strlen("SELECT COUNT(*) FROM ") + strlen(table_name) + strlen(";") +1);
+ strcpy(row_cnt_qry, "SELECT COUNT(*) FROM ");
+ strcat(row_cnt_qry, table_name);
+ strcat(row_cnt_qry, ";");
- ret = sqlite3_bind_text(stmt, 4, U->first_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ int no_of_rows = 0;
+ //ret = sqlite3_exec(s_info.db,var_query, callback,(void*)s_info.db, &err_msg);
- ret = sqlite3_bind_text(stmt, 5, U->last_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
+ sqlite3_stmt *stmt;
+ if (sqlite3_prepare_v2(db, row_cnt_qry, -1, &stmt, NULL) == SQLITE_OK) {
+ if (sqlite3_step(stmt) == SQLITE_ERROR) {
+ no_of_rows = 0;
+ } else {
+ no_of_rows = sqlite3_column_int(stmt, 0);
+ }
sqlite3_finalize(stmt);
- return -EFAULT;
}
-
- ret = sqlite3_bind_text(stmt, 6, U->phone, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
+ close_database(db);
+ free(row_cnt_qry);
+ if(no_of_rows <= 0) {
+ return NULL;
}
- ret = sqlite3_bind_int(stmt, 7, U->access_hash);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ /********************************/
+ db = create_database(DEFAULT_TG_DATABASE_PATH);
+ int ret = 0 ;
+ char* err_msg = 0;
+ //int col_count = eina_list_count(column_names);
- ret = sqlite3_bind_text(stmt, 8, U->real_first_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ int str_len = strlen("SELECT ") + 1;
+ char* var_query = (char*)malloc(str_len);
+ strcpy(var_query,"SELECT ");
+ if(!column_names) {
+ var_query = realloc(var_query, strlen(var_query) + 3);
+ strcat(var_query, "* ");
+ } else {
- ret = sqlite3_bind_text(stmt, 9, U->real_last_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ int col_count = eina_list_count(column_names);
+ char* col_name = NULL;
+ for(int col = 0; col < col_count ; col++) {
+ col_name = eina_list_nth(column_names, col);
+ var_query = realloc(var_query, strlen(var_query)+strlen(col_name) + 1);
+ strcat(var_query, col_name);
+ col_name = NULL;
+ var_query = realloc(var_query, strlen(var_query)+strlen(" ") + 1);
+
+ if(col < col_count - 1){
+ var_query = realloc(var_query, strlen(var_query) + 3);
+ strcat(var_query, ", ");
+ } else {
+ var_query = realloc(var_query, strlen(var_query) + 2);
+ strcat(var_query, " ");
+ }
+ }
- ret = sqlite3_bind_text(stmt, 10, U->username, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
}
- ret = sqlite3_bind_int(stmt, 11, U->status.online);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
- }
+ var_query = realloc(var_query, strlen(var_query) + strlen("FROM ") + 2);
+ strcat(var_query, "FROM ");
+ var_query = realloc(var_query, strlen(var_query) + strlen(table_name) + 1);
+ strcat(var_query, table_name);
- ret = sqlite3_bind_int(stmt, 12, U->last ? U->last->date : 0);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return -EFAULT;
+ if (where_clause) {
+ var_query = realloc(var_query, strlen(var_query)+strlen(" WHERE ") + 1);
+ strcat(var_query, " WHERE ");
+ var_query = realloc(var_query, strlen(var_query)+strlen(where_clause) + 1);
+ strcat(var_query, where_clause);
}
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_DONE) {
- sqlite3_finalize(stmt);
- return 0;
+ if (order_column) {
+ var_query = realloc(var_query, strlen(var_query)+strlen(" ORDER BY ") + 1);
+ strcat(var_query, " ORDER BY ");
+ var_query = realloc(var_query, strlen(var_query)+strlen(order_column) + 1);
+ strcat(var_query, order_column);
+ if (is_asc) {
+ var_query = realloc(var_query, strlen(var_query)+strlen(" ASC ") + 1);
+ strcat(var_query, " ASC ");
+ } else {
+ var_query = realloc(var_query, strlen(var_query)+strlen(" DESC ") + 1);
+ strcat(var_query, " DESC ");
+ }
}
- sqlite3_finalize(stmt);
- return 0;
-}
-struct tgl_user *tg_db_get_user_info(const char *table_name, int uid)
-{
- const char *dml;
- sqlite3_stmt *stmt;
- int ret;
- struct tgl_user *user_info;
- const char *tmp;
- dml = "SELECT * FROM ?";
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- return NULL;
- }
+ var_query = realloc(var_query, strlen(var_query) + 2);
+ strcat(var_query, ";");
- ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return NULL;
- }
- if ((ret = sqlite3_step(stmt)) != SQLITE_ROW) {
- sqlite3_finalize(stmt);
- return NULL;
- }
- user_info = calloc(1, sizeof(*user_info));
- if (!user_info) {
- /**
- * @note
- * Unable to get the record of user info
- */
- sqlite3_finalize(stmt);
+ ret = sqlite3_prepare_v2(db, var_query, -1, &stmt, 0);
+ if( ret != SQLITE_OK ){
+ sqlite3_free(err_msg);
return NULL;
}
- user_info->id.id = sqlite3_column_int(stmt, 0);
-
- tmp = (const char *)sqlite3_column_text(stmt, 1);
- if (tmp && tmp[0] != '\0') {
- user_info->print_name = strdup(tmp);
- }
-
- user_info->structure_version = sqlite3_column_int(stmt, 2);
-
- /**
- * Getting the photo_path. but how can I store this? to where?
- */
- tmp = (const char *)sqlite3_column_text(stmt, 3);
- if (tmp && tmp[0] != '\0') {
- /*
- * Where can I get this photo path?
- */
- }
-
- user_info->photo_id = sqlite3_column_int(stmt, 4);
- tmp = (const char *)sqlite3_column_text(stmt, 5);
- if (tmp && tmp[0] != '\0') {
- user_info->first_name = strdup(tmp);
+ while(sqlite3_step(stmt) == SQLITE_ROW) {
+ int col_val_count = eina_list_count(column_names);
+ Eina_List* row_vals = NULL;
+ for(int col = 0; col < col_val_count ; col++) {
+ char* col_type = eina_list_nth(column_types, col);
+ if(!strcmp(col_type, "INTEGER") || !strcmp(col_type, "INTEGER PRIMARY KEY NOT NULL")) {
+ int temp = sqlite3_column_int64(stmt, col);
+ int* val_int = (int*)malloc(sizeof(int));
+ *val_int = temp;
+ row_vals = eina_list_append(row_vals, val_int);
+ } else if(!strcmp(col_type, "TEXT") || !strcmp(col_type, "TEXT PRIMARY KEY NOT NULL")) {
+ char* val_text = strdup((const char *)sqlite3_column_text(stmt, col));
+ row_vals = eina_list_append(row_vals, val_text);
+ }
+ }
+ query_vals = eina_list_append(query_vals, row_vals);
}
+ close_database(db);
+ free(var_query);
+ return query_vals;
+}
- tmp = (const char *)sqlite3_column_text(stmt, 6);
- if (tmp && tmp[0] != '\0') {
- user_info->last_name = strdup(tmp);
+Eina_Bool delete_record(char *tablename, const char* where_clause)
+{
+ if (!tablename) {
+ return EINA_FALSE;
}
+ char *var_query = (char*)malloc(strlen("DELETE FROM ") + strlen(tablename) + 1);
+ strcpy(var_query, "DELETE FROM ");
+ strcat(var_query, tablename);
- tmp = (const char *)sqlite3_column_text(stmt, 7);
- if (tmp && tmp[0] != '\0') {
- user_info->phone = strdup(tmp);
+ if (where_clause) {
+ var_query = realloc(var_query, strlen(var_query)+strlen(" WHERE ") + 1);
+ strcat(var_query, " WHERE ");
+ var_query = realloc(var_query, strlen(var_query)+strlen(where_clause) + 1);
+ strcat(var_query, where_clause);
}
- user_info->access_hash = sqlite3_column_int(stmt, 8);
+ var_query = realloc(var_query, strlen(var_query) + 2);
+ strcat(var_query, ";");
- tmp = (const char *)sqlite3_column_text(stmt, 9);
- if (tmp && tmp[0] != '\0') {
- user_info->real_first_name = strdup(tmp);
+ int ret;
+ char* err_msg = 0;
+ sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
+ ret = sqlite3_exec(db,var_query, NULL, NULL, &err_msg);
+ close_database(db);
+ if( ret != SQLITE_OK ){
+ sqlite3_free(err_msg);
+ return EINA_FALSE;
}
+ free(var_query);
+ return EINA_TRUE;
+}
- tmp = (const char *)sqlite3_column_text(stmt, 10);
- if (tmp && tmp[0] != '\0') {
- user_info->real_last_name = strdup(tmp);
+Eina_Bool drop_table(char *tablename)
+{
+ if (!tablename) {
+ return EINA_FALSE;
}
-
- tmp = (const char *)sqlite3_column_text(stmt, 11);
- if (tmp && tmp[0] != '\0') {
- user_info->username = strdup(tmp);
+ char *var_query = (char*)malloc(strlen("DROP TABLE ") + strlen(tablename) + strlen(";") + 1);
+ strcpy(var_query, "DROP TABLE ");
+ strcat(var_query, tablename);
+ strcat(var_query, ";");
+ int ret;
+ char* err_msg = 0;
+ sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
+ ret = sqlite3_exec(db,var_query, NULL, NULL, &err_msg);
+ close_database(db);
+ if( ret != SQLITE_OK ){
+ sqlite3_free(err_msg);
+ return EINA_FALSE;
}
-
- sqlite3_finalize(stmt);
- return user_info;
+ free(var_query);
+ return EINA_TRUE;
}
-Eina_List *tg_db_get_user_list(const char *table_name)
+int get_number_of_rows(char* table_name, char* where_clause)
{
- const char *dml;
- sqlite3_stmt *stmt;
- int ret;
- Eina_List *user_list;
- struct tgl_user *user_info;
- const char *tmp;
-
- dml = "SELECT * FROM ?";
- ret = sqlite3_prepare_v2(s_info.db, dml, -1, &stmt, NULL);
- if (ret != SQLITE_OK) {
- return NULL;
+ int no_of_rows = 0;
+ if (!table_name) {
+ return no_of_rows;
}
+ sqlite3* db = create_database(DEFAULT_TG_DATABASE_PATH);
+ char* row_cnt_qry = (char*)malloc(strlen("SELECT COUNT(*) FROM ") + strlen(table_name) + 1);
+ strcpy(row_cnt_qry, "SELECT COUNT(*) FROM ");
+ strcat(row_cnt_qry, table_name);
- ret = sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT);
- if (ret != SQLITE_OK) {
- sqlite3_finalize(stmt);
- return NULL;
+ if (where_clause) {
+ row_cnt_qry = realloc(row_cnt_qry, strlen(row_cnt_qry)+strlen(" WHERE ") + 1);
+ strcat(row_cnt_qry, " WHERE ");
+ row_cnt_qry = realloc(row_cnt_qry, strlen(row_cnt_qry)+strlen(where_clause) + 1);
+ strcat(row_cnt_qry, where_clause);
}
+ row_cnt_qry = realloc(row_cnt_qry, strlen(row_cnt_qry) + 2);
+ strcat(row_cnt_qry, ";");
- user_list = NULL;
- while ((ret = sqlite3_step(stmt)) == SQLITE_ROW) {
- user_info = calloc(1, sizeof(*user_info));
- if (!user_info) {
- /**
- * @note
- * Unable to get the record of user info
- */
- continue;
- }
-
- user_info->id.id = sqlite3_column_int(stmt, 0);
-
- tmp = (const char *)sqlite3_column_text(stmt, 1);
- if (tmp && tmp[0] != '\0') {
- user_info->print_name = strdup(tmp);
- }
-
- user_info->structure_version = sqlite3_column_int(stmt, 2);
-
- /**
- * Getting the photo_path. but how can I store this? to where?
- */
- tmp = (const char *)sqlite3_column_text(stmt, 3);
- if (tmp && tmp[0] != '\0') {
- /*
- * Where can I get this photo path?
- */
- }
-
- user_info->photo_id = sqlite3_column_int(stmt, 4);
- tmp = (const char *)sqlite3_column_text(stmt, 5);
- if (tmp && tmp[0] != '\0') {
- user_info->first_name = strdup(tmp);
- }
-
- tmp = (const char *)sqlite3_column_text(stmt, 6);
- if (tmp && tmp[0] != '\0') {
- user_info->last_name = strdup(tmp);
- }
-
- tmp = (const char *)sqlite3_column_text(stmt, 7);
- if (tmp && tmp[0] != '\0') {
- user_info->phone = strdup(tmp);
- }
-
- user_info->access_hash = sqlite3_column_int(stmt, 8);
-
- tmp = (const char *)sqlite3_column_text(stmt, 9);
- if (tmp && tmp[0] != '\0') {
- user_info->real_first_name = strdup(tmp);
- }
-
- tmp = (const char *)sqlite3_column_text(stmt, 10);
- if (tmp && tmp[0] != '\0') {
- user_info->real_last_name = strdup(tmp);
- }
-
- tmp = (const char *)sqlite3_column_text(stmt, 11);
- if (tmp && tmp[0] != '\0') {
- user_info->username = strdup(tmp);
+ sqlite3_stmt *stmt;
+ if (sqlite3_prepare_v2(db, row_cnt_qry, -1, &stmt, NULL) == SQLITE_OK) {
+ if (sqlite3_step(stmt) == SQLITE_ERROR) {
+ no_of_rows = 0;
+ } else {
+ no_of_rows = sqlite3_column_int(stmt, 0);
}
-
- user_list = eina_list_append(user_list, user_info);
+ sqlite3_finalize(stmt);
}
-
- sqlite3_finalize(stmt);
- return user_list;
+ close_database(db);
+ free(row_cnt_qry);
+ return no_of_rows;
}
#ifndef TG_DB_MANAGER_H_
#define TG_DB_MANAGER_H_
+#include "tg_common.h"
+#include <sqlite3.h>
+
extern int tg_db_fini(void);
extern int tg_db_init(void);
-
-extern int tg_db_create_table_peer_info(const char *table_name);
-extern int tg_db_insert_peer_info(const char *tablename, tgl_peer_t *UC, int last_msg_id, int unread_count);
-extern int tg_db_update_peer_info(const char *tablename, tgl_peer_t *UC, int last_msg_id, int unread_count);
-
-extern int tg_db_create_table_message(const char *table_name);
-extern struct tgl_message *tg_db_get_message(const char *table_name, long long id);
-extern int tg_db_insert_message(const char *table_name, struct tgl_message *M, long long unique_id);
-extern int tg_db_update_message(const char *table_name, struct tgl_message *M, long long unique_id);
-
-extern int tg_db_create_table_buddy_info(const char *table_name);
-
-extern int tg_db_create_table_chat_info(const char *table_name);
-extern int tg_db_insert_chat_info(const char *table_name, struct tgl_chat *chat, char *photo_path);
-extern int tg_db_update_chat_info(const char *table_name, struct tgl_chat *chat, char *photo);
-extern int tg_db_count_chat_info(const char *table_name, struct tgl_chat *chat);
-
-extern int tg_db_create_table_media_info(const char *table_name);
-extern int tg_db_update_media_info_filepath(const char *table_name, long long media_id, const char *filepath);
-extern int tg_db_update_media_info_by_id(const char *table_name, struct tgl_message *msg, long long id);
-extern int tg_db_insert_media_info(const char *table_name, struct tgl_message *msg, const char *filename);
-extern void *tg_db_get_media_info(const char *table_name, long long id, int *media_type);
-
-extern int tg_db_create_table_user_info(const char *table_name);
-extern Eina_List *tg_db_get_user_list(const char *table_name);
-extern struct tgl_user *tg_db_get_user_info(const char *table_name, int uid);
-extern int tg_db_insert_user_info(const char *tablename, struct tgl_user *U);
-extern int tg_db_update_user_info(const char *tablename, struct tgl_user *U);
-extern int tg_db_update_user_photo(const char *tablename, int uid, const char *photo, int photo_id);
-
+extern Eina_Bool create_table(const char* table_name, Eina_List* column_names, Eina_List* column_types);
+extern Eina_Bool insert_table(const char* table_name, Eina_List* column_names, Eina_List* column_types, Eina_List* column_values);
+extern Eina_Bool update_table(const char* table_name, Eina_List* column_names, Eina_List* column_types, Eina_List* column_values, const char* where_clause);
+extern Eina_Bool get_values_from_table(const char* table_name, Eina_List* column_names, int (*callback)(void*,int,char**,char**), const char* where_clause, void* data_to_callback);
+extern Eina_List* get_values_from_table_sync(const char* table_name, Eina_List* column_names, Eina_List* column_types, const char* where_clause);
+extern Eina_List* get_values_from_table_sync_order_by(const char* table_name, Eina_List* column_names, Eina_List* column_types, const char* order_column, Eina_Bool is_asc, const char* where_clause);
+extern Eina_Bool delete_record(char *tablename, const char* where_clause);
+extern Eina_Bool drop_table(char *tablename);
+extern int get_number_of_rows(char* table_name, char* where_clause);
#endif /* TG_DB_MANAGER_H_ */
#ifndef SERVER_RESPONSE_H_
#define SERVER_RESPONSE_H_
+
+
extern void process_registration_command(tg_engine_data_s *tg_data, char *phone_no, Eina_Bool trough_sms);
extern void process_validation_command(tg_engine_data_s *tg_data, char *code);
extern void process_send_message_command(int buddy_id, int message_id, int msg_type, char* msg_data, int type_of_chat);
extern void process_marked_as_read_command(int buddy_id, int type_of_chat);
+extern void process_delete_group_chat_request(tg_engine_data_s* tg_data, int chat_id);
+extern void process_add_user_request(tg_engine_data_s* tg_data, int buddy_id);
+extern void process_delete_user_request(tg_engine_data_s* tg_data, int buddy_id);
+extern void process_block_user_request(tg_engine_data_s* tg_data, int buddy_id);
+extern void process_unblock_user_request(tg_engine_data_s* tg_data, int buddy_id);
extern void process_send_media_command(int buddy_id, int message_id, int media_id, int msg_type, char* file_path, int type_of_chat);
extern void process_media_download_command(tg_engine_data_s *tg_data, int buddy_id, long long media_id);
extern void process_add_contacts_command(tg_engine_data_s *tg_data, int size, Eina_List* contact_list);
extern void process_new_group_create_command(tg_engine_data_s *tg_data, Eina_List* buddy_ids, const char* group_name, const char* group_icon);
+extern void process_set_profile_pic_command(tg_engine_data_s *tg_data, int buddy_id, const char *file_path);
+extern void process_set_group_chat_new_title_command(tg_engine_data_s *tg_data, int buddy_id, const char *new_title);
+extern void process_add_new_buddy_to_chat_command(tg_engine_data_s *tg_data, int s_buddy_id, int s_chat_id);
+extern void process_remove_buddy_from_chat_command(tg_engine_data_s *tg_data, int s_buddy_id, int s_chat_id);
+extern void process_set_group_chat_profile_pic_command(tg_engine_data_s *tg_data, int buddy_id, const char *file_path);
+extern void process_set_username_command(tg_engine_data_s *tg_data, int buddy_id, const char *username);
extern void send_add_contacts_request();
extern void send_registration_response(tg_engine_data_s *tg_data, Eina_Bool is_success);
extern void send_name_registration_response();
extern void send_contacts_load_done_response(tg_engine_data_s *tg_data, Eina_Bool is_success);
+extern void send_self_profile_picture_updated_response(tg_engine_data_s *tg_data, char *file_path, Eina_Bool is_success);
+extern void send_self_user_name_updated_response(tg_engine_data_s *tg_data, char *username, Eina_Bool is_success);
extern void send_contacts_and_chats_load_done_response(tg_engine_data_s *tg_data, Eina_Bool is_success);
extern void send_buddy_profile_pic_updated_response(tg_engine_data_s *tg_data, int buddy_id, char* file_path);
extern void send_message_received_response(tg_engine_data_s *tg_data, int from_id, int to_id, long long message_id, int type_of_chat);
extern void send_message_sent_to_buddy_response(tg_engine_data_s *tg_data, int buddy_id, int message_id, char* table_name, Eina_Bool is_success, int type_of_chat);
+extern void send_group_chat_deleted_response(tg_engine_data_s *tg_data, int chat_id, Eina_Bool is_success);
extern void send_message_read_by_buddy_response(tg_engine_data_s *tg_data, int buddy_id, int message_id, char* table_name, char* phone, int type_of_chat);
extern void send_media_download_completed_response(tg_engine_data_s *tg_data, int buddy_id, int to_id, long long media_id, const char* filename);
+extern void send_video_thumb_download_completed_response(tg_engine_data_s *tg_data, int buddy_id, int to_id, long long media_id, const char* filename);
extern void send_new_group_added_response(tg_engine_data_s *tg_data, int chat_id);
+extern void send_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id, const char *type_of_change);
extern void send_chat_profile_pic_updated_response(tg_engine_data_s *tg_data, int chat_id, char* filename);
extern void send_contact_updated_response(tg_engine_data_s *tg_data, int buddy_id, char* update_message);
extern void send_buddy_status_updated_response(tg_engine_data_s *tg_data, int buddy_id);
extern void send_buddy_status_updated_response(tg_engine_data_s *tg_data, int buddy_id);
extern void send_buddy_type_notification_response(tg_engine_data_s *tg_data, int buddy_id, char* budy_name, int type_status);
extern void send_buddy_status_notification_response(tg_engine_data_s *tg_data, int buddy_id, char* budy_name, int online);
+
+extern void send_group_chat_rename_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success);
+extern void send_buddy_readded_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success);
+extern void send_buddy_deleted_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success);
+extern void send_buddy_blocked_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success);
+extern void send_buddy_unblocked_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success);
+extern void send_group_chat_new_buddy_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success);
+extern void send_group_chat_delete_buddy_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success);
+extern void send_response_for_server_connection_status(tg_engine_data_s *tg_data, Eina_Bool connection_status);
#endif /* SERVER_RESPONSE_H_ */
#include "tg_db_manager.h"
#include "tg_engine.h"
+#define MESSAGE_TRANSPORT_TABLE_NAME "message_transport_table"
+
+#define MESSAGE_TRANSPORT_TABLE_ROW_ID "row_id"
+#define MESSAGE_TRANSPORT_TABLE_APP_NAME "app_name"
+#define MESSAGE_TRANSPORT_TABLE_COMMAND "command"
+#define MESSAGE_TRANSPORT_TABLE_BUDDY_ID "buddy_id"
+#define MESSAGE_TRANSPORT_TABLE_MESSAGE_ID "message_id"
+#define MESSAGE_TRANSPORT_TABLE_MESSAGE_TYPE "message_type"
+#define MESSAGE_TRANSPORT_TABLE_MESSAGE_DATA "message_data"
+#define MESSAGE_TRANSPORT_TABLE_TYPE_OF_CHAT "type_of_chat"
+
+#define MEDIA_TRANSPORT_TABLE_NAME "media_transport_table"
+
+#define MEDIA_TRANSPORT_TABLE_ROW_ID "row_id"
+#define MEDIA_TRANSPORT_TABLE_APP_NAME "app_name"
+#define MEDIA_TRANSPORT_TABLE_COMMAND "command"
+#define MEDIA_TRANSPORT_TABLE_BUDDY_ID "buddy_id"
+#define MEDIA_TRANSPORT_TABLE_MESSAGE_ID "message_id"
+#define MEDIA_TRANSPORT_TABLE_MEDIA_ID "media_id"
+#define MEDIA_TRANSPORT_TABLE_MESSAGE_TYPE "message_type"
+#define MEDIA_TRANSPORT_TABLE_FILE_PATH "file_path"
+#define MEDIA_TRANSPORT_TABLE_TYPE_OF_CHAT "type_of_chat"
+
+
#define USER_INFO_TABLE_NAME "user_info_table"
+
+#define USER_INFO_TABLE_USER_ID "user_id"
+#define USER_INFO_TABLE_PRINT_NAME "print_name"
+#define USER_INFO_TABLE_STRUCTURE_VERSION "structure_version"
+#define USER_INFO_TABLE_PHOTO_PATH "photo_path"
+#define USER_INFO_TABLE_PHOTO_ID "photo_id"
+#define USER_INFO_TABLE_FIRST_NAME "first_name"
+#define USER_INFO_TABLE_LAST_NAME "last_name"
+#define USER_INFO_TABLE_PHONE_NO "phone"
+#define USER_INFO_TABLE_ACCESS_HASH "access_hash"
+#define USER_INFO_TABLE_REAL_FIRST_NAME "real_first_name"
+#define USER_INFO_TABLE_REAL_LAST_NAME "real_last_name"
+#define USER_INFO_TABLE_USER_NAME "username"
+#define USER_INFO_TABLE_ONLINE_STATUS "online"
+#define USER_INFO_TABLE_LAST_SEEN_TIME "last_seen"
+#define USER_INFO_TABLE_IS_BLOCKED "is_blocked"
+#define USER_INFO_TABLE_IS_DELETED "is_deleted"
+
#define BUDDY_INFO_TABLE_NAME "buddy_info_table"
+
+#if 0
+#define BUDDY_INFO_TABLE_BUDDY_ID "user_id"
+#define BUDDY_INFO_TABLE_PRINT_NAME "print_name"
+#define BUDDY_INFO_TABLE_STRUCTURE_VERSION "structure_version"
+#define BUDDY_INFO_TABLE_PHOTO_PATH "photo_path"
+#define BUDDY_INFO_TABLE_PHOTO_ID "photo_id"
+#define BUDDY_INFO_TABLE_FIRST_NAME "first_name"
+#define BUDDY_INFO_TABLE_LAST_NAME "last_name"
+#define BUDDY_INFO_TABLE_PHONE_NO "phone"
+#define BUDDY_INFO_TABLE_ACCESS_HASH "access_hash"
+#define BUDDY_INFO_TABLE_REAL_FIRST_NAME "real_first_name"
+#define BUDDY_INFO_TABLE_REAL_LAST_NAME "real_last_name"
+#define BUDDY_INFO_TABLE_BUDDY_NAME "username"
+#define BUDDY_INFO_TABLE_ONLINE_STATUS "online"
+#define BUDDY_INFO_TABLE_LAST_SEEN_TIME "last_seen"
+#endif
#define MEDIA_INFO_TABLE_NAME "media_info_table"
+#define MEDIA_INFO_TABLE_MEDIA_ID "media_id"
+#define MEDIA_INFO_TABLE_MEDIA_TYPE "media_type"
+#define MEDIA_INFO_TABLE_ACCESS_HASH "access_hash"
+#define MEDIA_INFO_TABLE_USER_ID "user_id"
+#define MEDIA_INFO_TABLE_DATE "date"
+#define MEDIA_INFO_TABLE_CAPTION "caption"
+#define MEDIA_INFO_TABLE_LONGITUDE "longitude"
+#define MEDIA_INFO_TABLE_LATITUDE "latitude"
+#define MEDIA_INFO_TABLE_SIZES_NUM "sizes_num"
+
+#define MEDIA_INFO_TABLE_PHOTO_TYPE1 "photo_type1" //text
+#define MEDIA_INFO_TABLE_PHOTO_LOC_DC1 "photo_loc_dc1" //int
+#define MEDIA_INFO_TABLE_PHOTO_LOC_VOL1 "photo_loc_vol1" //int
+#define MEDIA_INFO_TABLE_PHOTO_LOC_ID1 "photo_loc_id1" //int
+#define MEDIA_INFO_TABLE_PHOTO_LOC_SECRET1 "photo_loc_secret1" //int
+#define MEDIA_INFO_TABLE_PHOTO_WIDTH1 "photo_width1" //int
+#define MEDIA_INFO_TABLE_PHOTO_HEIGHT1 "photo_height1" //int
+#define MEDIA_INFO_TABLE_PHOTO_SIZE1 "photo_size1" //int
+#define MEDIA_INFO_TABLE_PHOTO_DATA1 "photo_data1" //text
+
+#define MEDIA_INFO_TABLE_PHOTO_TYPE2 "photo_type2" //text
+#define MEDIA_INFO_TABLE_PHOTO_LOC_DC2 "photo_loc_dc2" //int
+#define MEDIA_INFO_TABLE_PHOTO_LOC_VOL2 "photo_loc_vol2" //int
+#define MEDIA_INFO_TABLE_PHOTO_LOC_ID2 "photo_loc_id2" //int
+#define MEDIA_INFO_TABLE_PHOTO_LOC_SECRET2 "photo_loc_secret2" //int
+#define MEDIA_INFO_TABLE_PHOTO_WIDTH2 "photo_width2" //int
+#define MEDIA_INFO_TABLE_PHOTO_HEIGHT2 "photo_height2" //int
+#define MEDIA_INFO_TABLE_PHOTO_SIZE2 "photo_size2" //int
+#define MEDIA_INFO_TABLE_PHOTO_DATA2 "photo_data2" //text
+
+#define MEDIA_INFO_TABLE_PHOTO_TYPE3 "photo_type3" //text
+#define MEDIA_INFO_TABLE_PHOTO_LOC_DC3 "photo_loc_dc3" //int
+#define MEDIA_INFO_TABLE_PHOTO_LOC_VOL3 "photo_loc_vol3" //int
+#define MEDIA_INFO_TABLE_PHOTO_LOC_ID3 "photo_loc_id3" //int
+#define MEDIA_INFO_TABLE_PHOTO_LOC_SECRET3 "photo_loc_secret3" //int
+#define MEDIA_INFO_TABLE_PHOTO_WIDTH3 "photo_width3" //int
+#define MEDIA_INFO_TABLE_PHOTO_HEIGHT3 "photo_height3" //int
+#define MEDIA_INFO_TABLE_PHOTO_SIZE3 "photo_size3" //int
+#define MEDIA_INFO_TABLE_PHOTO_DATA3 "photo_data3" //text
+
+#define MEDIA_INFO_TABLE_PHOTO_TYPE4 "photo_type4" //text
+#define MEDIA_INFO_TABLE_PHOTO_LOC_DC4 "photo_loc_dc4" //int
+#define MEDIA_INFO_TABLE_PHOTO_LOC_VOL4 "photo_loc_vol4" //int
+#define MEDIA_INFO_TABLE_PHOTO_LOC_ID4 "photo_loc_id4" //int
+#define MEDIA_INFO_TABLE_PHOTO_LOC_SECRET4 "photo_loc_secret4" //int
+#define MEDIA_INFO_TABLE_PHOTO_WIDTH4 "photo_width4" //int
+#define MEDIA_INFO_TABLE_PHOTO_HEIGHT4 "photo_height4" //int
+#define MEDIA_INFO_TABLE_PHOTO_SIZE4 "photo_size4" //int
+#define MEDIA_INFO_TABLE_PHOTO_DATA4 "photo_data4" //text
+
+#define MEDIA_INFO_TABLE_MIME_TYPE "mime_type" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_TYPE "doc_type" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_WIDTH "doc_width" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_HEIGHT "doc_height" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_DURATION "doc_duration" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_SIZE "doc_size" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_DC "doc_dc" //text
+#define MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE "video_thumb" //text
+
+#define MEDIA_INFO_TABLE_PHONE_NO "phone"
+#define MEDIA_INFO_TABLE_FIRST_NAME "first_name"
+#define MEDIA_INFO_TABLE_LAST_NAME "last_name"
+#define MEDIA_INFO_TABLE_FILE_PATH "file_path"
+
+#define MESSAGE_INFO_TABLE_MESSAGE_ROW_ID "msg_row_id"
#define MESSAGE_INFO_TABLE_MESSAGE_ID "msg_id"
#define MESSAGE_INFO_TABLE_FLAGS "flags"
#define MESSAGE_INFO_TABLE_FWD_FROM_ID "fwd_from_id"
#define TG_DB_COLUMN_INTEGER "INTEGER"
#define TG_DB_COLUMN_INTEGER_PRIMARY_KEY "INTEGER PRIMARY KEY NOT NULL"
+#define TG_DB_COLUMN_INTEGER_PRIMARY_AUTO_INC_KEY "INTEGER PRIMARY KEY AUTOINCREMENT"
#define TG_DB_COLUMN_TEXT "TEXT"
void insert_buddy_into_db(char* table_name, struct tgl_user* U);
+void update_peer_info_database(tgl_peer_t* UC);
+
+void delete_chat_from_db(int peer_id);
+
+void delete_buddy_from_db(int peer_id);
+
void insert_peer_into_database(tgl_peer_t* UC, int last_msg_id, int unread_count);
void update_buddy_pic_db(char* file_path, char* table_name, int id);
+void update_buddy_block_db(char* table_name, int id, int block);
+
void create_buddy_msg_table(const char* table_name);
void insert_buddy_msg_to_db(struct tgl_message *M);
void insert_chat_info_to_db(struct tgl_chat *C, char* photo_path);
-void update_chat_info_to_db(struct tgl_chat *chat_info, char* photo_path);
+Eina_Bool update_chat_info_to_db(struct tgl_chat *chat_info, char* photo_path);
-extern struct tgl_user* get_buddy_info(int buddy_id);
+Eina_List* get_buddy_info(int buddy_id);
void insert_media_info_to_db(struct tgl_message *M, char* file_path);
+void update_video_thumb_in_db(long long media_id, char* thumb_file);
void update_sent_media_info_in_db(struct tgl_message *M, long long unique_val);
void update_receive_media_info_in_db(long long media_id, char* file_path);
+Eina_List* get_image_details_from_db(long long media_id);
+
Eina_Bool is_chat_id_already_exists(struct tgl_chat *C);
+struct tgl_message* get_latest_message_from_message_table(char* table_name);
+
+int insert_current_date_to_table(char* tb_name);
+
+struct tgl_media* get_media_details_from_db(long long media_id);
+
+char* get_video_thumb_path_from_db(long long media_id);
+
+void get_geo_location_from_db(long long media_id, char **latitude, char **longitude);
+
+void get_contact_details_from_db(long long media_id, char **first_name, char **last_name, char **phone_number);
+
+void get_buddy_contact_details_from_db(int buddy_id, char **first_name, char **last_name, char **phone_number);
+
+void update_buddy_delete_db(char* table_name, int id, int delete_item);
+
+Eina_List* get_all_peer_ids();
+int get_number_of_unread_messages();
+int get_unread_message_count(char* table_name);
+
+Eina_List* get_all_unsent_media_messages();
+Eina_List* get_all_unsent_text_messages();
+void delete_message_from_unsent_db(int message_id);
+void delete_media_from_unsent_db(int message_id);
+
#endif /* TG_DB_WRAPPER_H_ */
local_next_token ();
//#define OUT_BUF_SIZE (1 << 25)
-#define OUT_BUF_SIZE (1)
+#define OUT_BUF_SIZE (512)
char out_buf[OUT_BUF_SIZE];
int out_buf_pos;
#define CODE_input_video_empty 0x5508ec75
#define CODE_input_video 0xee579652
#define CODE_input_file_location 0x14637196
-#define CODE_input_video_file_location 0x3d0364ec
#define CODE_input_photo_crop_auto 0xade6b004
#define CODE_input_photo_crop 0xd9915325
#define CODE_input_app_event 0x770656a8
#define CODE_input_document 0x18798952
#define CODE_input_audio_file_location 0x74dc404d
#define CODE_input_document_file_location 0x4e45abe9
+#define CODE_input_video_file_location 0x3d0364ec
#define CODE_audio_empty 0x586988d8
#define CODE_audio 0xc7ac6496
#define CODE_document_empty 0x36f8c871
assert(ok >= 0);
assert(in_ptr == in_end);
- binlog_pos += (in_ptr - rptr) * 4;
+ binlog_pos +=(in_ptr - rptr) * 4;
rptr = in_ptr;
}
static void init_enc_msg(struct tgl_state *TLS, struct tgl_session *S, int useful)
{
struct tgl_dc *DC = S->dc;
+ // sandeep
+#if 0
assert(DC->state == st_authorized);
assert(DC->temp_auth_key_id);
+#else
+ if (DC->state != st_authorized) {
+ return;
+ }
+
+ if (DC->temp_auth_key_id == 0) {
+ return;
+ }
+#endif
+
vlogprintf(E_DEBUG, "temp_auth_key_id = 0x%016llx, auth_key_id = 0x%016llx\n", DC->temp_auth_key_id, DC->auth_key_id);
enc_msg.auth_key_id = DC->temp_auth_key_id;
enc_msg.server_salt = DC->server_salt;
fail_session(TLS, S);
return -1;
}
- assert(in_ptr == in_end);
+ //sandeep
+ //assert(in_ptr == in_end);
return 0;
}
in_ptr = save;
}
q->methods->on_answer(TLS, q);
- assert(in_ptr == in_end);
+ // sandeep
+ //assert(in_ptr == in_end);
}
tfree(q->data, 4 * q->data_len);
TLS->timer_methods->free(q->ev);
.type = TYPE_TO_PARAM(bool)
};
-void tgl_do_phone_call(struct tgl_state *TLS, const char *user, const char *hash,void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra)
+void tgl_do_phone_call(struct tgl_state *TLS, const char *user, const char *hash, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra)
{
vlogprintf(E_DEBUG, "calling user\n");
clear_packet();
int w;
int h;
int duration;
+ unsigned media_type;
};
static void out_peer_id(struct tgl_state *TLS, tgl_peer_id_t id)
static void send_file_unencrypted_end(struct tgl_state *TLS, struct send_file *f, void *callback, void *callback_extra)
{
+#if 0
out_int(CODE_messages_send_media);
out_peer_id(TLS, f->to_id);
if (f->flags == -1) {
tglq_send_query(TLS, TLS->DC_working, packet_ptr - packet_buffer, packet_buffer, &send_file_methods, 0, callback, callback_extra);
tfree_str(f->file_name);
tfree(f, sizeof(*f));
+#else
+ out_int (CODE_messages_send_media);
+ out_peer_id(TLS, f->to_id);
+ out_int (f->media_type);
+ if (f->size < (16 << 20)) {
+ out_int (CODE_input_file);
+ } else {
+ out_int (CODE_input_file_big);
+ }
+ out_long (f->id);
+ out_int (f->part_num);
+ char *s = f->file_name + strlen (f->file_name);
+ while (s >= f->file_name && *s != '/') { s --;}
+ out_string (s + 1);
+ if (f->size < (16 << 20)) {
+ out_string ("");
+ }
+ if (f->media_type == CODE_input_media_uploaded_thumb_video || f->media_type == CODE_input_media_uploaded_thumb_document) {
+ out_int (CODE_input_file);
+ out_long (f->thumb_id);
+ out_int (1);
+ out_string ("thumb.jpg");
+ out_string ("");
+ }
+ if (f->media_type == CODE_input_media_uploaded_video || f->media_type == CODE_input_media_uploaded_thumb_video) {
+ out_int (100);
+ out_int (100);
+ out_int (100);
+ out_string ("video");
+ }
+ if (f->media_type == CODE_input_media_uploaded_document || f->media_type == CODE_input_media_uploaded_thumb_document) {
+ out_string (s + 1);
+ out_string ("text");
+ }
+ if (f->media_type == CODE_input_media_uploaded_audio) {
+ out_int (60);
+ out_string ("audio");
+ }
+
+ long long r;
+ tglt_secure_random (&r, 8);
+ out_long (r);
+ tglq_send_query(TLS, TLS->DC_working, packet_ptr - packet_buffer, packet_buffer, &send_file_methods, 0, callback, callback_extra);
+ tfree_str(f->file_name);
+ tfree(f, sizeof(*f));
+#endif
}
static void send_file_encrypted_end(struct tgl_state *TLS, struct send_file *f, void *callback, void *callback_extra)
}
f->flags = flags;
+ if (f->flags == FLAG_DOCUMENT_VIDEO) {
+ f->media_type = CODE_input_media_uploaded_video;
+ } else if (f->flags == FLAG_DOCUMENT_AUDIO) {
+ f->media_type = CODE_input_media_uploaded_audio;
+ } else if (f->flags == FLAG_DOCUMENT_IMAGE) {
+ f->media_type = CODE_input_media_uploaded_photo;
+ } else {
+ f->media_type = CODE_input_media_uploaded_document;
+ }
+
if (f->part_size >(512 << 10)) {
close(fd);
vlogprintf(E_WARNING, "Too big file. Maximal supported size is %d.\n",(512 << 10) * 1000);
}
if (!f->encr && f->flags != -1 && thumb_len > 0) {
+ f->media_type = CODE_input_media_uploaded_thumb_video;
send_file_thumb(TLS, f, thumb_data, thumb_len, callback, callback_extra);
} else {
send_part(TLS, f, callback, callback_extra);
_tgl_do_send_photo(TLS, flags, to_id, file_name, 0, w, h, duration, thumb, thumb_len, callback, callback_extra);
}
+void tgl_do_send_video(struct tgl_state *TLS, int flags, tgl_peer_id_t to_id, char *video_name, char *thumb_file, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra)
+{
+ if (flags == -2) {
+ char *mime_type = tg_mime_by_filename(video_name);
+ if (!memcmp(mime_type, "image/", 6)) {
+ flags = -1;
+ } else if (!memcmp(mime_type, "video/", 6)) {
+ flags = FLAG_DOCUMENT_VIDEO;
+ } else if (!memcmp(mime_type, "audio/", 6)) {
+ flags = FLAG_DOCUMENT_AUDIO;
+ } else {
+ flags = 0;
+ }
+ }
+ char *buffer = NULL;
+ long numbytes = 0;
+ if (thumb_file) {
+ FILE *infile;
+ infile = fopen(thumb_file, "r");
+ fseek(infile, 0L, SEEK_END);
+ numbytes = ftell(infile);
+ fseek(infile, 0L, SEEK_SET);
+ buffer = (char*)calloc(numbytes, sizeof(char));
+ fread(buffer, sizeof(char), numbytes, infile);
+ fclose(infile);
+ }
+
+ _tgl_do_send_photo(TLS, flags, to_id, video_name, 0, 100, 100, 100, buffer, numbytes, callback, callback_extra);
+}
+
+void tgl_do_send_audio(struct tgl_state *TLS, tgl_peer_id_t to_id, char *file_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra)
+{
+ int flags = FLAG_DOCUMENT_AUDIO;
+ _tgl_do_send_photo(TLS, flags, to_id, file_name, 0, 100, 100, 100, 0, 0, callback, callback_extra);
+}
void tgl_do_send_document(struct tgl_state *TLS, int flags, tgl_peer_id_t to_id, char *file_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra)
{
if (flags == -2) {
} else {
flags = 0;
}
+ } else {
+ flags = FLAG_DOCUMENT_IMAGE;
}
_tgl_do_send_photo(TLS, flags, to_id, file_name, 0, 100, 100, 100, 0, 0, callback, callback_extra);
}
out_long(D->access_hash);
}
out_int(D->offset);
- out_int(1 << 14);
+ //out_int(1 << 14);
+ out_int (D->size ? (1 << 14) : (1 << 19));
tglq_send_query(TLS, TLS->DC_list[D->dc], packet_ptr - packet_buffer, packet_buffer, &download_methods, D, callback, callback_extra);
}
D->dc = V->dc_id;
D->name = 0;
D->fd = -1;
- D->type = CODE_input_document_file_location;
+
+ if (V->flags & FLAG_DOCUMENT_AUDIO) {
+ D->type = CODE_input_audio_file_location;
+ } else if (V->flags & FLAG_DOCUMENT_VIDEO) {
+ D->type = CODE_input_video_file_location;
+ } else {
+ D->type = CODE_input_document_file_location;
+ }
+
if (V->mime_type) {
char *r = tg_extension_by_mime(V->mime_type);
if (r) {
tglq_send_query(TLS, TLS->DC_working, packet_ptr - packet_buffer, packet_buffer, &send_broadcast_methods, 0, callback, callback_extra);
}
+/* {{{ block user */
+static int block_user_on_answer (struct tgl_state *TLS, struct query *q, void *D) {
+ if (q->callback) {
+ ((void (*)(struct tgl_state *, void *, int))q->callback)(TLS, q->callback_extra, 1);
+ }
+ return 0;
+}
+
+static struct query_methods block_user_methods = {
+ .on_answer = block_user_on_answer,
+ .on_error = q_void_on_error,
+ .type = TYPE_TO_PARAM (bool)
+};
+
+void tgl_do_block_user (struct tgl_state *TLS, tgl_peer_id_t id, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra) {
+ if (tgl_get_peer_type (id) != TGL_PEER_USER) {
+ if (callback) {
+ callback (TLS, callback_extra, 0);
+ }
+ return;
+ }
+
+ clear_packet ();
+
+ out_int (CODE_contacts_block);
+ tgl_peer_t *U = tgl_peer_get (TLS, id);
+ if (U && U->user.access_hash) {
+ out_int (CODE_input_user_foreign);
+ out_int (tgl_get_peer_id (id));
+ out_long (U->user.access_hash);
+ } else {
+ out_int (CODE_input_user_contact);
+ out_int (tgl_get_peer_id (id));
+ }
+ tglq_send_query (TLS, TLS->DC_working, packet_ptr - packet_buffer, packet_buffer, &block_user_methods, 0, callback, callback_extra);
+}
+
+void tgl_do_unblock_user (struct tgl_state *TLS, tgl_peer_id_t id, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra) {
+ if (tgl_get_peer_type (id) != TGL_PEER_USER) {
+ if (callback) {
+ callback (TLS, callback_extra, 0);
+ }
+ return;
+ }
+
+ clear_packet ();
+
+ out_int (CODE_contacts_unblock);
+ tgl_peer_t *U = tgl_peer_get (TLS, id);
+ if (U && U->user.access_hash) {
+ out_int (CODE_input_user_foreign);
+ out_int (tgl_get_peer_id (id));
+ out_long (U->user.access_hash);
+ } else {
+ out_int (CODE_input_user_contact);
+ out_int (tgl_get_peer_id (id));
+ }
+ tglq_send_query (TLS, TLS->DC_working, packet_ptr - packet_buffer, packet_buffer, &block_user_methods, 0, callback, callback_extra);
+}
+/* }}} */
+
+
static void set_flag_4(struct tgl_state *TLS, void *_D, int success)
{
struct tgl_dc *D = _D;
return;
default:
vlogprintf(E_ERROR, "type = 0x%08x\n", M->type);
- assert(0);
+ //assert(0);
}
}
};
enum tgl_message_media_type {
- tgl_message_media_none,
+ tgl_message_media_none = 1001,
tgl_message_media_photo,
//tgl_message_media_video,
//tgl_message_media_audio,
double latitude;
};
+struct tgl_media {
+ long long media_id;
+ int media_type;
+ long long access_hash;
+ int user_id;
+ int date;
+ char *caption;
+ char *longitude;
+ char *latitude;
+ int sizes;
+ char *phone_no;
+ char *first_name;
+ char *last_name;
+ char *file_path;
+
+ char *photo_type1;
+ int photo_loc_dc1;
+ long long photo_loc_vol1;
+ int photo_loc_id1;
+ long long photo_loc_sec1;
+ int photo_width1;
+ int photo_height1;
+ int photo_size1;
+ char *photo_data1;
+
+ char *photo_type2;
+ int photo_loc_dc2;
+ long long photo_loc_vol2;
+ int photo_loc_id2;
+ long long photo_loc_sec2;
+ int photo_width2;
+ int photo_height2;
+ int photo_size2;
+ char *photo_data2;
+
+ char *photo_type3;
+ int photo_loc_dc3;
+ long long photo_loc_vol3;
+ int photo_loc_id3;
+ long long photo_loc_sec3;
+ int photo_width3;
+ int photo_height3;
+ int photo_size3;
+ char *photo_data3;
+
+ char *photo_type4;
+ int photo_loc_dc4;
+ long long photo_loc_vol4;
+ int photo_loc_id4 ;
+ long long photo_loc_sec4;
+ int photo_width4;
+ int photo_height4;
+ int photo_size4;
+ char *photo_data4;
+
+
+ char* mime_type;
+ char* doc_type;
+ int doc_width;
+ int doc_height;
+ int doc_duration;
+ int doc_size;
+ int doc_dc;
+ char* doc_thumb_path;
+
+};
+
struct tgl_photo {
long long id;
long long access_hash;
long long exchange_key_fingerprint;
};
-
+typedef union tgl_peer {
+ struct {
+ tgl_peer_id_t id;
+ int flags;
+ struct tgl_message *last;
+ char *print_name;
+ int structure_version;
+ struct tgl_file_location photo_big;
+ struct tgl_file_location photo_small;
+ struct tgl_photo photo;
+ };
+ struct tgl_user user;
+ struct tgl_chat chat;
+ struct tgl_secret_chat encr_chat;
+} tgl_peer_t;
/*
struct tgl_video {
long long id;
int h;
int flags;
int duration;
+
+ int to_peer_id;
};
struct tgl_message_action {
};
};
};
-
-typedef union tgl_peer {
- struct {
- tgl_peer_id_t id;
- int flags;
- struct tgl_message *last;
- char *print_name;
- int structure_version;
- struct tgl_file_location photo_big;
- struct tgl_file_location photo_small;
- struct tgl_photo photo;
- };
- struct tgl_user user;
- struct tgl_chat chat;
- struct tgl_secret_chat encr_chat;
-} tgl_peer_t;
-
#pragma pack(pop)
#endif
static Eina_Bool write_call(void* data)
{
struct connection *c = data;
+
+ if (c->TLS == NULL || c->fd <= 0) {
+ return ECORE_CALLBACK_CANCEL;
+ }
+
fd_set writeset;
FD_ZERO(&writeset);
FD_SET(c->fd, &writeset);
select(c->fd + 1, NULL, &writeset, NULL, NULL);
-
- /**
- * conn_try_write can create write_ev timer again.
- * So we have to clear the c->write_ev before call it.
- */
- c->write_ev = NULL;
-
conn_try_write(c);
return ECORE_CALLBACK_CANCEL;
}
struct connection *c = arg;
struct tgl_state *TLS = c->TLS;
vlogprintf(E_DEBUG + 2,"ping alarm\n");
- assert(c->state == conn_ready || c->state == conn_connecting);
+ //assert(c->state == conn_ready || c->state == conn_connecting);
+ if(c->state != conn_ready || c->state != conn_connecting) {
+ return ECORE_CALLBACK_CANCEL;
+ }
+
if (tglt_get_double_time() - c->last_receive_time > 6 * PING_TIMEOUT) {
vlogprintf(E_WARNING, "fail connection: reason: ping timeout\n");
c->state = conn_failed;
} else {
start_ping_timer(c);
}
- c->ping_ev = NULL;
return ECORE_CALLBACK_CANCEL;
}
static void start_ping_timer(struct connection *c)
{
- if (c->ping_ev) {
- return;
- }
-
c->ping_ev = ecore_timer_add(PING_TIMEOUT, ping_alarm, c);
}
Eina_Bool fail_alarm(void *arg)
{
struct connection *c = arg;
-
c->in_fail_timer = 0;
restart_connection(c);
-
- c->fail_ev = NULL;
return ECORE_CALLBACK_CANCEL;
}
#else
if(c->write_ev) {
ecore_timer_del(c->write_ev);
+ c->write_ev = NULL;
}
c->write_ev = ecore_timer_add(0.000001, write_call, c);
#endif
#else
if(c->write_ev) {
ecore_timer_del(c->write_ev);
+ c->write_ev = NULL;
}
c->write_ev = ecore_timer_add(0.000001, write_call, c);
#endif
struct connection *c = arg;
if(c->read_ev) {
ecore_main_fd_handler_del(c->read_ev);
+ c->read_ev = NULL;
}
c->read_ev = ecore_main_fd_handler_add(c->fd, ECORE_FD_READ, conn_try_read, c, NULL,NULL);
return ECORE_CALLBACK_CANCEL;
struct tgl_state *TLS = c->TLS;
vlogprintf(E_DEBUG, "try read: fd = %d\n", c->fd);
+ if (c->TLS == NULL || c->fd <= 0) {
+ return;
+ }
if (!c->in_tail) {
c->in_head = c->in_tail = new_connection_buffer(1 << 20);
}
void tgl_timer_insert(struct tgl_timer *t, double p)
{
- if (p < 0) {
+ if (p <= 0) {
p = 0.000001;
}
struct timer_context *tc = (struct timer_context *)t;
// Something goes wrong, tgl_timer_delete is not called before.
// Exceptional cases.
ecore_timer_del(tc->handler);
- tc->handler = NULL;
}
free(tc->cbdata);
free(tc);
{
assert(TLS->timer_methods);
assert(TLS->net_methods);
-
if (!TLS->callback.create_print_name) {
TLS->callback.create_print_name = tgls_default_create_print_name;
}
-
if (!TLS->temp_key_expire_time) {
TLS->temp_key_expire_time = 100000;
}
extern void tgl_do_get_dialog_list(struct tgl_state *TLS, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, int size, tgl_peer_id_t peers[], int last_msg_id[], int unread_count[]), void *callback_extra);
extern void tgl_do_send_photo(struct tgl_state *TLS, enum tgl_message_media_type type, tgl_peer_id_t to_id, char *file_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
extern void tgl_do_send_document(struct tgl_state *TLS, int flags, tgl_peer_id_t to_id, char *file_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
+extern void tgl_do_send_audio(struct tgl_state *TLS, tgl_peer_id_t to_id, char *file_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
+extern void tgl_do_send_video(struct tgl_state *TLS, int flags, tgl_peer_id_t to_id, char *video_name, char *thumb_file, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
extern void tgl_do_set_chat_photo(struct tgl_state *TLS, tgl_peer_id_t chat_id, char *file_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
extern void tgl_do_set_profile_photo(struct tgl_state *TLS, char *file_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
extern void tgl_do_set_profile_name(struct tgl_state *TLS, char *first_name, char *last_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U), void *callback_extra);
extern void tgl_do_contact_search(struct tgl_state *TLS, char *name, int limit, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, int cnt, struct tgl_user *U[]), void *callback_extra);
extern void tgl_do_request_exchange(struct tgl_state *TLS, struct tgl_secret_chat *E);
extern void tgl_do_send_typing(struct tgl_state *TLS, tgl_peer_id_t id, enum tgl_typing_status status, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
+
+// blocks user
+void tgl_do_block_user (struct tgl_state *TLS, tgl_peer_id_t id, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
+
+// unblocks blocked user
+void tgl_do_unblock_user (struct tgl_state *TLS, tgl_peer_id_t id, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
+/* }}} */
+
extern void tgl_do_send_broadcast(struct tgl_state *TLS, int num, tgl_peer_id_t id[], const char *text, int text_len, void(*callback)(struct tgl_state *TLS, void *extra, int success, int num, struct tgl_message *ML[]), void *callback_extra);
extern void tgl_do_visualize_key(struct tgl_state *TLS, tgl_peer_id_t id, unsigned char buf[16]);
extern void tgl_do_send_ping(struct tgl_state *TLS, struct connection *c);
#include "logger.h"
#include "tg_engine.h"
#include "server_response.h"
+#include "tg_db_wrapper.h"
#include "tg_common.h"
-
+#include <badge.h>
void process_registration_command(tg_engine_data_s *tg_data, char* phone_no, Eina_Bool trough_sms)
{
- if (tg_data->tg_state != TG_ENGINE_STATE_REGISTRATION || !phone_no) {
+ if (trough_sms && (tg_data->tg_state != TG_ENGINE_STATE_REGISTRATION || !phone_no)) {
return;
}
tg_data->phone_number = NULL;
}
+ if (!trough_sms) {
+ request_for_code_via_call(tgl_engine_get_TLS(), phone_no, trough_sms);
+ return;
+ }
+
if (tg_data->get_string) {
tg_data->get_string(tgl_engine_get_TLS(), tg_data->phone_number, tg_data->callback_arg);
}
send_message_to_buddy(buddy_id, message_id, msg_type, msg_data, type_of_chat);
}
+void process_delete_group_chat_request(tg_engine_data_s* tg_data, int chat_id)
+{
+ if (!tgl_engine_get_TLS()) {
+ return;
+ }
+ leave_group_chat(tg_data, chat_id);
+}
+
+void process_add_user_request(tg_engine_data_s* tg_data, int buddy_id)
+{
+ if (!tgl_engine_get_TLS()) {
+ return;
+ }
+ do_add_buddy(buddy_id);
+}
+
+
+void process_delete_user_request(tg_engine_data_s* tg_data, int buddy_id)
+{
+ if (!tgl_engine_get_TLS()) {
+ return;
+ }
+ do_delete_buddy(buddy_id);
+}
+
+void process_block_user_request(tg_engine_data_s* tg_data, int buddy_id)
+{
+ if (!tgl_engine_get_TLS()) {
+ return;
+ }
+ do_block_buddy(buddy_id);
+}
+
+void process_unblock_user_request(tg_engine_data_s* tg_data, int buddy_id)
+{
+ if (!tgl_engine_get_TLS()) {
+ return;
+ }
+ do_unblock_buddy(buddy_id);
+}
+
void process_marked_as_read_command(int buddy_id, int type_of_chat)
{
if (!tgl_engine_get_TLS()) {
create_new_group(tg_data, buddy_ids, group_name, group_icon);
}
+void process_set_group_chat_new_title_command(tg_engine_data_s *tg_data, int buddy_id, const char *new_title)
+{
+ set_group_chat_new_title(tg_data, buddy_id, new_title);
+}
+
+void process_add_new_buddy_to_chat_command(tg_engine_data_s *tg_data, int s_buddy_id, int s_chat_id)
+{
+ set_group_chat_add_new_buddy(tg_data, s_buddy_id, s_chat_id);
+}
+
+void process_remove_buddy_from_chat_command(tg_engine_data_s *tg_data, int s_buddy_id, int s_chat_id)
+{
+ set_group_chat_remove_buddy(tg_data, s_buddy_id, s_chat_id);
+}
+
+void process_set_group_chat_profile_pic_command(tg_engine_data_s *tg_data, int buddy_id, const char *file_path)
+{
+ set_group_chat_profile_picture(tg_data, buddy_id, file_path);
+}
+
+void process_set_profile_pic_command(tg_engine_data_s *tg_data, int buddy_id, const char *file_path)
+{
+ set_profile_picture(tg_data, buddy_id, file_path);
+}
+
+void process_set_username_command(tg_engine_data_s *tg_data, int buddy_id, const char *username)
+{
+ set_user_name(tg_data, buddy_id, username);
+}
+
void send_registration_response(tg_engine_data_s *tg_data, Eina_Bool is_success)
{
bundle *msg;
return;
}
+ result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
- bundle_free(msg);
-
if(result != SVC_RES_OK) {
// error: cient not ready
}
+
+ bundle_free(msg);
}
void send_new_group_added_response(tg_engine_data_s *tg_data, int chat_id)
{
- int result;
- bundle *msg;
- const char *str;
-
- msg = bundle_create();
- if (!msg) {
- ERR("Unable to create the bundle");
- return;
- }
-
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "command", "new_group_added") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "new_group_added") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%d", chat_id);
- if (bundle_add_str(msg, "chat_id", str) != BUNDLE_ERROR_NONE) {
+ char chat_id_str[50];
+ sprintf(chat_id_str,"%d",chat_id);
+ if (bundle_add_str(msg, "chat_id", chat_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
-
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
- bundle_free(msg);
if(result != SVC_RES_OK) {
// error: cient not ready
}
+
+ bundle_free(msg);
}
-void send_chat_profile_pic_updated_response(tg_engine_data_s *tg_data, int chat_id, char* filename)
+void send_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id, const char *type_of_change)
{
- int result;
- bundle *msg;
- const char *str;
-
- msg = bundle_create();
- if (!msg) {
- return;
- }
-
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "command", "new_group_icon_added") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "group_chat_updated") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%d", chat_id);
- if (bundle_add_str(msg, "chat_id", str) != BUNDLE_ERROR_NONE) {
+ char chat_id_str[50];
+ sprintf(chat_id_str,"%d",chat_id);
+ if (bundle_add_str(msg, "chat_id", chat_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "chat_icon_path", filename) != BUNDLE_ERROR_NONE) {
+
+ if (bundle_add_str(msg, "type_of_change", type_of_change) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
- bundle_free(msg);
if(result != SVC_RES_OK) {
// error: cient not ready
}
+
+ bundle_free(msg);
}
-void send_name_registration_response(tg_engine_data_s *tg_data)
+void send_chat_profile_pic_updated_response(tg_engine_data_s *tg_data, int chat_id, char* filename)
{
- int result;
- bundle *msg;
-
- msg = bundle_create();
- if (!msg) {
- return;
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
}
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "new_group_icon_added") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "command", "name_registration_request") != BUNDLE_ERROR_NONE) {
+ char chat_id_str[50];
+ sprintf(chat_id_str,"%d",chat_id);
+ if (bundle_add_str(msg, "chat_id", chat_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
-
+ if (bundle_add_str(msg, "chat_icon_path", filename) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
- bundle_free(msg);
if(result != SVC_RES_OK) {
// error: cient not ready
}
+
+ bundle_free(msg);
}
-void send_add_contacts_request(tg_engine_data_s *tg_data)
+void send_name_registration_response(tg_engine_data_s *tg_data)
{
- bundle *msg;
- int result;
-
- msg = bundle_create();
- if (!msg) {
- return;
- }
-
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "command", "add_contacts_request") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "name_registration_request") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
-
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
- bundle_free(msg);
if(result != SVC_RES_OK) {
// error: cient not ready
}
+ bundle_free(msg);
}
-void send_contacts_and_chats_load_done_response(tg_engine_data_s *tg_data, Eina_Bool is_success)
+void send_add_contacts_request(tg_engine_data_s *tg_data)
{
- int result;
- bundle *msg;
-
- msg = bundle_create();
- if (!msg) {
- return;
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
}
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "add_contacts_request") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
+ bundle_free(msg);
+}
- if (bundle_add_str(msg, "command", "contacts_and_chats_load_done") != BUNDLE_ERROR_NONE) {
+void send_contacts_and_chats_load_done_response(tg_engine_data_s *tg_data, Eina_Bool is_success)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "is_success", is_success ? "true" : "false") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "contacts_and_chats_load_done") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
+ if (is_success) {
+ if (bundle_add_str(msg, "is_success", "true") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "is_success", "false") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
- bundle_free(msg);
if(result != SVC_RES_OK) {
// error: cient not ready
}
+ bundle_free(msg);
}
-void send_contacts_load_done_response(tg_engine_data_s *tg_data, Eina_Bool is_success)
+void send_self_user_name_updated_response(tg_engine_data_s *tg_data, char *username, Eina_Bool is_success)
{
- bundle *msg;
- int result;
-
- msg = bundle_create();
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "command", "contacts_load_done") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "self_username_updated") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "is_success", is_success ? "true" : "false") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "username", username) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
+ if (is_success) {
+ if (bundle_add_str(msg, "is_success", "true") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "is_success", "false") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
- bundle_free(msg);
+
if(result != SVC_RES_OK) {
// error: cient not ready
}
+ bundle_free(msg);
}
-void send_buddy_profile_pic_updated_response(tg_engine_data_s *tg_data, int buddy_id, char* file_path)
+void send_self_profile_picture_updated_response(tg_engine_data_s *tg_data, char *file_path, Eina_Bool is_success)
{
- bundle *msg;
- int result;
- const char *str;
-
- msg = bundle_create();
- if (!msg) {
- return;
- }
-
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "command", "buddy_profile_pic_updated") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "self_profile_picture_updated") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%d", buddy_id);
- if (bundle_add_str(msg, "user_id", str) != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "file_path", file_path) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "file_path", file_path) != BUNDLE_ERROR_NONE) {
- ERR("Failed to add data by key to bundle");
- bundle_free(msg);
- return;
+ if (is_success) {
+ if (bundle_add_str(msg, "is_success", "true") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "is_success", "false") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
}
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
- bundle_free(msg);
if(result != SVC_RES_OK) {
// error: cient not ready
}
+ bundle_free(msg);
}
-void send_message_received_response(tg_engine_data_s *tg_data, int from_id, int to_id, long long message_id, int type_of_chat)
+void send_contacts_load_done_response(tg_engine_data_s *tg_data, Eina_Bool is_success)
{
- int result;
- bundle *msg;
- const char *str;
-
- msg = bundle_create();
- if (!msg) {
- return;
- }
-
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "command", "message_received") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "contacts_load_done") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%d", from_id);
- if (bundle_add_str(msg, "from_id", str) != BUNDLE_ERROR_NONE) {
+ if (is_success) {
+ if (bundle_add_str(msg, "is_success", "true") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "is_success", "false") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
+ bundle_free(msg);
+}
+
+void send_buddy_profile_pic_updated_response(tg_engine_data_s *tg_data, int buddy_id, char* file_path)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%d", to_id);
- if (bundle_add_str(msg, "to_id", str) != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "buddy_profile_pic_updated") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%lld", message_id);
- if (bundle_add_str(msg, "message_id", str) != BUNDLE_ERROR_NONE) {
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",buddy_id);
+
+ if (bundle_add_str(msg, "user_id", usr_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%d", type_of_chat);
- if (bundle_add_str(msg, "type_of_chat", str) != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "file_path", file_path) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
- bundle_free(msg);
if(result != SVC_RES_OK) {
// error: cient not ready
}
+ bundle_free(msg);
}
-void send_message_read_by_buddy_response(tg_engine_data_s *tg_data, int buddy_id, int message_id, char* table_name, char* phone, int type_of_chat)
+void send_message_received_response(tg_engine_data_s *tg_data, int from_id, int to_id, long long message_id, int type_of_chat)
{
- bundle *msg;
- int result;
- const char *str;
-
- msg = bundle_create();
- if (!msg) {
- return;
- }
-
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "command", "message_read_by_buddy") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "message_received") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%d", buddy_id);
- if (bundle_add_str(msg, "buddy_id", str) != BUNDLE_ERROR_NONE) {
- ERR("Failed to add data by key to bundle");
- bundle_free(msg);
- }
+ char from_id_str[50];
+ sprintf(from_id_str,"%d",from_id);
- str = tg_common_to_string("%d", message_id);
- if (bundle_add_str(msg, "message_id", str) != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "from_id", from_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
- if (bundle_add_str(msg, "table_name", table_name) != BUNDLE_ERROR_NONE) {
+ char to_id_str[50];
+ sprintf(to_id_str,"%d",to_id);
+
+ if (bundle_add_str(msg, "to_id", to_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
- if (bundle_add_str(msg, "phone_number", phone) != BUNDLE_ERROR_NONE) {
+ char msg_id_str[50];
+ sprintf(msg_id_str,"%lld",message_id);
+
+ if (bundle_add_str(msg, "message_id", msg_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
- str = tg_common_to_string("%d", type_of_chat);
- if (bundle_add_str(msg, "type_of_chat", str) != BUNDLE_ERROR_NONE) {
+ char type_of_chat_str[50];
+ sprintf(type_of_chat_str,"%d",type_of_chat);
+
+ if (bundle_add_str(msg, "type_of_chat", type_of_chat_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
- bundle_free(msg);
if(result != SVC_RES_OK) {
// error: cient not ready
- }
-}
+ // send notification
+ char *icon_path = ui_utils_get_resource(DEFAULT_TELEGRAM_ICON);
+ char *title = "Telegram";
+ char content[512];
-void send_message_sent_to_buddy_response(tg_engine_data_s *tg_data, int buddy_id, int message_id, char* table_name, Eina_Bool is_success, int type_of_chat)
-{
- bundle *msg;
- const char *str;
- int result;
+ int unread_msg_cnt = get_number_of_unread_messages();
+ sprintf(content, "%d new messages received.", unread_msg_cnt);
- msg = bundle_create();
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ char *sound_track = NULL;
+ char *app_id = TELEGRAM_APP_ID;
+ tg_notification_create(tg_data, icon_path, title, content, sound_track, app_id);
+
+ int err = badge_set_count(TELEGRAM_APP_ID, unread_msg_cnt);
+ if (BADGE_ERROR_NONE != err) {
+
+ }
+ }
+ bundle_free(msg);
+}
+
+void send_message_read_by_buddy_response(tg_engine_data_s *tg_data, int buddy_id, int message_id, char* table_name, char* phone, int type_of_chat)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "command", "message_sent_to_buddy") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "message_read_by_buddy") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%d", buddy_id);
- if (bundle_add_str(msg, "buddy_id", str) != BUNDLE_ERROR_NONE) {
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%d", message_id);
- if (bundle_add_str(msg, "message_id", str) != BUNDLE_ERROR_NONE) {
+ char msg_id_str[50];
+ sprintf(msg_id_str,"%d", message_id);
+
+ if (bundle_add_str(msg, "message_id", msg_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "table_name", table_name) != BUNDLE_ERROR_NONE) {
+ if (table_name) {
+ if (bundle_add_str(msg, "table_name", table_name) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "table_name", "") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+
+ if (phone) {
+ if (bundle_add_str(msg, "phone_number", phone) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "phone_number", "") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ }
+
+ char type_of_chat_str[50];
+ sprintf(type_of_chat_str,"%d",type_of_chat);
+
+ if (bundle_add_str(msg, "type_of_chat", type_of_chat_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "is_success", is_success ? "true" : "false") != BUNDLE_ERROR_NONE) {
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
+ bundle_free(msg);
+}
+
+void send_group_chat_delete_buddy_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%d", type_of_chat);
- if (bundle_add_str(msg, "type_of_chat", str) != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "group_chat_buddy_deleted_response") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",peer_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
+ if (is_success) {
+ if (bundle_add_str(msg, "is_success", "true") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "is_success", "false") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
- bundle_free(msg);
+
if(result != SVC_RES_OK) {
// error: cient not ready
}
+ bundle_free(msg);
}
-void send_media_download_completed_response(tg_engine_data_s *tg_data, int buddy_id, int to_id, long long media_id, const char* filename)
+void send_group_chat_new_buddy_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success)
{
- bundle *msg;
- int result;
- const char *str;
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
- msg = bundle_create();
- if (!msg) {
- return;
+ if (bundle_add_str(msg, "command", "group_chat_new_buddy_added_response") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
}
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",peer_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "command", "media_download_completed") != BUNDLE_ERROR_NONE) {
+ if (is_success) {
+ if (bundle_add_str(msg, "is_success", "true") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "is_success", "false") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
+ bundle_free(msg);
+}
+
+void send_group_chat_rename_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%d", buddy_id);
- if (bundle_add_str(msg, "buddy_id", str) != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "group_chat_rename_response") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%d", to_id);
- if (bundle_add_str(msg, "to_peer_id", str) != BUNDLE_ERROR_NONE) {
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",peer_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%lld", media_id);
- if (bundle_add_str(msg, "media_id", str) != BUNDLE_ERROR_NONE) {
+ if (is_success) {
+ if (bundle_add_str(msg, "is_success", "true") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "is_success", "false") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
+ bundle_free(msg);
+}
+
+
+void send_buddy_readded_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "file_name", filename ? filename : "failed_to_load") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "buddy_readded") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
+ ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
+ if (is_success) {
+ if (bundle_add_str(msg, "is_success", "true") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "is_success", "false") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
- bundle_free(msg);
+
if(result != SVC_RES_OK) {
// error: cient not ready
}
+ bundle_free(msg);
}
-void send_contact_updated_response(tg_engine_data_s *tg_data, int buddy_id, char* update_message)
+void send_buddy_deleted_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
{
- int result;
- const char *str;
- bundle *msg;
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
- if (!update_message) {
- return;
+ if (bundle_add_str(msg, "command", "buddy_deleted") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
}
- msg = bundle_create();
- if (!msg) {
- return;
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
}
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ if (is_success) {
+ if (bundle_add_str(msg, "is_success", "true") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "is_success", "false") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
+ bundle_free(msg);
+}
+
+void send_buddy_blocked_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "command", "contact_updated") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "buddy_blocked") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- str = tg_common_to_string("%d", buddy_id);
- if (bundle_add_str(msg, "buddy_id", str) != BUNDLE_ERROR_NONE) {
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "update_message", update_message) != BUNDLE_ERROR_NONE) {
+ if (is_success) {
+ if (bundle_add_str(msg, "is_success", "true") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "is_success", "false") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
+ bundle_free(msg);
+}
+
+void send_buddy_unblocked_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
+ if (bundle_add_str(msg, "command", "buddy_unblocked") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (is_success) {
+ if (bundle_add_str(msg, "is_success", "true") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "is_success", "false") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
bundle_free(msg);
+
+}
+
+void send_group_chat_deleted_response(tg_engine_data_s *tg_data, int chat_id, Eina_Bool is_success)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (bundle_add_str(msg, "command", "group_chat_deleted_response") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",chat_id);
+
+ if (bundle_add_str(msg, "chat_id", usr_id_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (is_success) {
+ if (bundle_add_str(msg, "is_success", "true") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "is_success", "false") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
if(result != SVC_RES_OK) {
// error: cient not ready
}
+ bundle_free(msg);
}
-void send_buddy_status_updated_response(tg_engine_data_s *tg_data, int buddy_id)
+void send_message_sent_to_buddy_response(tg_engine_data_s *tg_data, int buddy_id, int message_id, char* table_name, Eina_Bool is_success, int type_of_chat)
{
- bundle *msg;
- int result;
- const char *str;
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
- msg = bundle_create();
- if (!msg) {
- return;
+ if (bundle_add_str(msg, "command", "message_sent_to_buddy") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
}
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
- if (bundle_add_str(msg, "command", "buddy_status_updated") != BUNDLE_ERROR_NONE) {
+ char msg_id_str[50];
+ sprintf(msg_id_str,"%d", message_id);
+
+ if (bundle_add_str(msg, "message_id", msg_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
- str = tg_common_to_string("%d", buddy_id);
- if (bundle_add_str(msg, "buddy_id", str) != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "table_name", table_name) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
}
+ if (is_success) {
+ if (bundle_add_str(msg, "is_success", "true") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "is_success", "false") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+
+ char type_of_chat_str[50];
+ sprintf(type_of_chat_str,"%d",type_of_chat);
+
+ if (bundle_add_str(msg, "type_of_chat", type_of_chat_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
bundle_free(msg);
+}
+
+void send_video_thumb_download_completed_response(tg_engine_data_s *tg_data, int buddy_id, int to_id, long long media_id, const char* filename)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (bundle_add_str(msg, "command", "video_thumb_download_completed") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char to_id_str[50];
+ sprintf(to_id_str,"%d",to_id);
+
+ if (bundle_add_str(msg, "to_peer_id", to_id_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char media_id_str[50];
+ sprintf(media_id_str,"%lld",media_id);
+
+ if (bundle_add_str(msg, "media_id", media_id_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (filename) {
+ if (bundle_add_str(msg, "file_name", filename) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "file_name", "failed_to_load") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
if(result != SVC_RES_OK) {
// error: cient not ready
}
+ bundle_free(msg);
}
-void send_buddy_status_notification_response(tg_engine_data_s *tg_data, int buddy_id, char* budy_name, int online)
+void send_media_download_completed_response(tg_engine_data_s *tg_data, int buddy_id, int to_id, long long media_id, const char* filename)
{
- bundle *msg;
- const char *tmp;
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (bundle_add_str(msg, "command", "media_download_completed") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char to_id_str[50];
+ sprintf(to_id_str,"%d",to_id);
+
+ if (bundle_add_str(msg, "to_peer_id", to_id_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char media_id_str[50];
+ sprintf(media_id_str,"%lld",media_id);
+
+ if (bundle_add_str(msg, "media_id", media_id_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (filename) {
+ if (bundle_add_str(msg, "file_name", filename) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "file_name", "failed_to_load") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ }
+
int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
- msg = bundle_create();
- if (!msg) {
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
+ bundle_free(msg);
+}
+
+void send_contact_updated_response(tg_engine_data_s *tg_data, int buddy_id, char* update_message)
+{
+ if (!update_message) {
return;
}
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "contact_updated") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "command", "user_status_updated") != BUNDLE_ERROR_NONE) {
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- tmp = tg_common_to_string("%d", buddy_id);
- if (bundle_add_str(msg, "buddy_id", tmp) != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "update_message", update_message) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "buddy_name", budy_name) != BUNDLE_ERROR_NONE) {
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
+ bundle_free(msg);
+}
+
+void send_buddy_status_updated_response(tg_engine_data_s *tg_data, int buddy_id)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "user_status", online ? "online" : "offline") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "buddy_status_updated") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
bundle_free(msg);
+}
+
+void send_buddy_status_notification_response(tg_engine_data_s *tg_data, int buddy_id, char* budy_name, int online)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (bundle_add_str(msg, "command", "user_status_updated") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (bundle_add_str(msg, "buddy_name", budy_name) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (online) {
+ if (bundle_add_str(msg, "user_status", "online") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ } else {
+ if (bundle_add_str(msg, "user_status", "offline") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ }
+
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
if(result != SVC_RES_OK) {
// error: cient not ready
}
+ bundle_free(msg);
}
-void send_buddy_type_notification_response(tg_engine_data_s *tg_data, int buddy_id, char* buddy_name, int type_status)
+void send_buddy_type_notification_response(tg_engine_data_s *tg_data, int buddy_id, char* budy_name, int type_status)
{
- bundle *msg;
- int result;
- const char *str;
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
- msg = bundle_create();
- if (!msg) {
- return;
+ if (bundle_add_str(msg, "command", "type_status_updated") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
}
- if (bundle_add_str(msg, "app_name", "Tizen Telegram") != BUNDLE_ERROR_NONE) {
+ char usr_id_str[50];
+ sprintf(usr_id_str,"%d",buddy_id);
+
+ if (bundle_add_str(msg, "buddy_id", usr_id_str) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
- return;
}
- if (bundle_add_str(msg, "command", "type_status_updated") != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "buddy_name", budy_name) != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
+ }
+
+ char type_status_str[50];
+ sprintf(type_status_str,"%d",type_status);
+
+ if (bundle_add_str(msg, "type_status", type_status_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
+ bundle_free(msg);
+}
+
+void send_response_for_server_connection_status(tg_engine_data_s *tg_data, Eina_Bool connection_status)
+{
+ bundle *msg;
+
+ msg = bundle_create();
+ if (!msg) {
+ LOGE("Failed to create a bundle");
return;
}
- str = tg_common_to_string("%d", buddy_id);
- if (bundle_add_str(msg, "buddy_id", str) != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
return;
}
- if (bundle_add_str(msg, "buddy_name", buddy_name) != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "command", "server_connection_status") != 0) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
return;
}
- str = tg_common_to_string("%d", type_status);
- if (bundle_add_str(msg, "type_status", str) != BUNDLE_ERROR_NONE) {
+ if (bundle_add_str(msg, "connection_status", connection_status ? "true" : "false") != BUNDLE_ERROR_NONE) {
ERR("Failed to add data by key to bundle");
bundle_free(msg);
+ return;
}
+ int result = SVC_RES_FAIL;
result = tg_server_send_message(tg_data->tg_server, msg);
- bundle_free(msg);
+
if(result != SVC_RES_OK) {
// error: cient not ready
}
+ bundle_free(msg);
}
#include "server_response.h"
#include <net_connection.h>
#include "tg_db_wrapper.h"
+#include <badge.h>
-static void registration_handler(bundle *rec_msg, void *data)
+static void free_connection(tg_engine_data_s* tg_data);
+static int _on_tg_server_msg_received_cb(void *data, bundle *const rec_msg)
{
tg_engine_data_s *tg_data = data;
- Eina_Bool th_sms = EINA_TRUE;
- char *ph_no_key_val = NULL;
- char *sms_key_val = NULL;
- int result;
+ int result = SVC_RES_FAIL;
+ RETVM_IF(!tg_data, result, "Data is NULL");
+ char *cmd_key_val = NULL;
- result = bundle_get_str(rec_msg, "phone_number", &ph_no_key_val);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ int res = bundle_get_str(rec_msg, "command", &cmd_key_val);
- result = bundle_get_str(rec_msg, "through_sms", &sms_key_val);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ if (strcmp(cmd_key_val, "registration") == 0) {
+ char *ph_no_key_val = NULL;
+ char *sms_key_val = NULL;
+ res = bundle_get_str(rec_msg, "phone_number", &ph_no_key_val);
+ res = bundle_get_str(rec_msg, "through_sms", &sms_key_val);
- th_sms = !strcmp(sms_key_val, "true");
+ Eina_Bool th_sms = EINA_TRUE;
- process_registration_command(tg_data, ph_no_key_val, th_sms);
-}
+ if (strcmp(sms_key_val, "true") == 0) {
+ th_sms = EINA_TRUE;
+ } else {
+ th_sms = EINA_FALSE;
+ }
-static void code_validation_handler(bundle *rec_msg, void *data)
-{
- int result;
- tg_engine_data_s *tg_data = data;
- char* sms_code_val = NULL;
+ process_registration_command(tg_data, ph_no_key_val, th_sms);
- result = bundle_get_str(rec_msg, "sms_code", &sms_code_val);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ } else if (strcmp(cmd_key_val, "code_validation") == 0) {
- process_validation_command(tg_data, sms_code_val);
-}
+ char* sms_code_val = NULL;
+ res = bundle_get_str(rec_msg, "sms_code", &sms_code_val);
+ process_validation_command(tg_data, sms_code_val);
-static void message_transport_handler(bundle *rec_msg, void *data)
-{
- char *tmp = NULL;
- char* msg_data_str = NULL;
- int message_id;
- int buddy_id;
- int result;
- int msg_type;
- int type_of_chat;
+ } else if (strcmp(cmd_key_val, "message_transport") == 0) {
- result = bundle_get_str(rec_msg, "buddy_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ char* buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- buddy_id = atoi(tmp);
+ char* message_id_str = NULL;
+ res = bundle_get_str(rec_msg, "message_id", &message_id_str);
+ int message_id = atoi(message_id_str);
- result = bundle_get_str(rec_msg, "message_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- message_id = atoi(tmp);
+ char* msg_type_str = NULL;
+ res = bundle_get_str(rec_msg, "message_type", &msg_type_str);
+ int msg_type = atoi(msg_type_str);
- result = bundle_get_str(rec_msg, "message_type", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- msg_type = atoi(tmp);
+ char* msg_data_str = NULL;
+ res = bundle_get_str(rec_msg, "message_data", &msg_data_str);
- result = bundle_get_str(rec_msg, "message_data", &msg_data_str);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ char* type_of_chat_str = NULL;
+ res = bundle_get_str(rec_msg, "type_of_chat", &type_of_chat_str);
+ int type_of_chat = atoi(type_of_chat_str);
- result = bundle_get_str(rec_msg, "type_of_chat", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ process_send_message_command(buddy_id, message_id, msg_type, msg_data_str, type_of_chat);
- type_of_chat = atoi(tmp);
+ } else if (strcmp(cmd_key_val, "marked_as_read") == 0) {
+ char* buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- process_send_message_command(buddy_id, message_id, msg_type, msg_data_str, type_of_chat);
-}
+ char* type_of_chat_str = NULL;
+ res = bundle_get_str(rec_msg, "type_of_chat", &type_of_chat_str);
+ int type_of_chat = atoi(type_of_chat_str);
+ process_marked_as_read_command(buddy_id, type_of_chat);
-static void marked_as_read_handler(bundle *rec_msg, void *data)
-{
- int result;
- int buddy_id;
- char *tmp;
- int type_of_chat;
+ } else if (strcmp(cmd_key_val, "delete_group_chat_request") == 0) {
- result = bundle_get_str(rec_msg, "buddy_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- buddy_id = atoi(tmp);
+ char* chat_id_str = NULL;
+ res = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
+ int chat_id = atoi(chat_id_str);
- result = bundle_get_str(rec_msg, "type_of_chat", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ process_delete_group_chat_request(tg_data, chat_id);
+ } else if (strcmp(cmd_key_val, "add_buddy") == 0) {
- type_of_chat = atoi(tmp);
- process_marked_as_read_command(buddy_id, type_of_chat);
-}
+ char* buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
-static void media_download_request_handler(bundle *rec_msg, void *data)
-{
- tg_engine_data_s *tg_data = data;
- int result;
- char *tmp;
- int buddy_id;
- long long media_id;
+ process_add_user_request(tg_data, buddy_id);
- result = bundle_get_str(rec_msg, "buddy_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- buddy_id = atoi(tmp);
+ } else if (strcmp(cmd_key_val, "delete_buddy") == 0) {
- result = bundle_get_str(rec_msg, "media_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- media_id = atoll(tmp);
+ char* buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- process_media_download_command(tg_data, buddy_id, media_id);
-}
+ process_delete_user_request(tg_data, buddy_id);
-static void media_transport_handler(bundle *rec_msg, void *data)
-{
- int result;
- int buddy_id;
- int message_id;
- int media_id;
- int msg_type;
- char *tmp;
- char *file_path_str = NULL;
- int type_of_chat;
-
- result = bundle_get_str(rec_msg, "buddy_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ } else if (strcmp(cmd_key_val, "block_buddy") == 0) {
- buddy_id = atoi(tmp);
+ char* buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- result = bundle_get_str(rec_msg, "message_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- message_id = atoi(tmp);
+ process_block_user_request(tg_data, buddy_id);
- result = bundle_get_str(rec_msg, "media_id", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- media_id = atoi(tmp);
+ } else if (strcmp(cmd_key_val, "unblock_buddy") == 0) {
- result = bundle_get_str(rec_msg, "message_type", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- msg_type = atoi(tmp);
+ char* buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- result = bundle_get_str(rec_msg, "file_path", &file_path_str);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ process_unblock_user_request(tg_data, buddy_id);
- result = bundle_get_str(rec_msg, "type_of_chat", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- type_of_chat = atoi(tmp);
+ } else if (strcmp(cmd_key_val, "media_download_request") == 0) {
- process_send_media_command(buddy_id, message_id, media_id, msg_type, file_path_str, type_of_chat);
-}
+ char* buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
-static void profile_registration_handler(bundle *rec_msg, void *data)
-{
- int result;
- tg_engine_data_s *tg_data = data;
- char* first_name = NULL;
- char* last_name = NULL;
+ char* media_id_str = NULL;
+ res = bundle_get_str(rec_msg, "media_id", &media_id_str);
+ long long media_id = atoll(media_id_str);
+ process_media_download_command(tg_data, buddy_id, media_id);
- result = bundle_get_str(rec_msg, "first_name", &first_name);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ } else if (strcmp(cmd_key_val, "media_transport") == 0) {
- tg_data->first_name = strdup(first_name);
+ char* buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+ int buddy_id = atoi(buddy_id_str);
- result = bundle_get_str(rec_msg, "last_name", &last_name);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- tg_data->last_name = strdup(last_name);
+ char* message_id_str = NULL;
+ res = bundle_get_str(rec_msg, "message_id", &message_id_str);
+ int message_id = atoi(message_id_str);
- if (tg_data->tg_state == TG_ENGINE_STATE_PROFILE_FIRST_NAME_REGISTRATION && tg_data->get_string) {
- tg_data->get_string(tgl_engine_get_TLS(), tg_data->first_name, tg_data->callback_arg);
- }
-}
+ char* media_id_str = NULL;
+ res = bundle_get_str(rec_msg, "media_id", &media_id_str);
+ int media_id = atoi(media_id_str);
-static void device_contact_list_handler(bundle *rec_msg, void *data)
-{
- int result;
- tg_engine_data_s *tg_data = data;
- char *tmp = NULL;
- int size;
- int count;
- Eina_List* contact_list = NULL;
- contact_data_s *contact;
-
- result = bundle_get_str(rec_msg, "count", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
+ char* msg_type_str = NULL;
+ res = bundle_get_str(rec_msg, "message_type", &msg_type_str);
+ int msg_type = atoi(msg_type_str);
+
+ char* file_path_str = NULL;
+ res = bundle_get_str(rec_msg, "file_path", &file_path_str);
+
+ char* type_of_chat_str = NULL;
+ res = bundle_get_str(rec_msg, "type_of_chat", &type_of_chat_str);
+ int type_of_chat = atoi(type_of_chat_str);
- size = atoi(tmp);
+ process_send_media_command(buddy_id, message_id, media_id, msg_type, file_path_str, type_of_chat);
- for (count = 0 ; count < size; count++) {
- contact = (contact_data_s *)malloc(sizeof(*contact));
- if (!contact) {
- break;
+ } else if (strcmp(cmd_key_val, "profile_registration") == 0) {
+
+ char* first_name = NULL;
+ char* last_name = NULL;
+
+ res = bundle_get_str(rec_msg, "first_name", &first_name);
+ if (res == BUNDLE_ERROR_NONE && first_name) {
+ tg_data->first_name = strdup(first_name);
}
- contact->first_name = NULL;
- contact->last_name = NULL;
- contact->phone_number = NULL;
+ res = bundle_get_str(rec_msg, "last_name", &last_name);
+ if (res == BUNDLE_ERROR_NONE && last_name) {
+ tg_data->last_name = strdup(last_name);
+ }
- tmp = (char *)tg_common_to_string("first_name_%d", count);
- result = bundle_get_str(rec_msg, tmp, &tmp);
- if (result == BUNDLE_ERROR_NONE) {
- contact->first_name = strdup(tmp);
+ if (tg_data->tg_state == TG_ENGINE_STATE_PROFILE_FIRST_NAME_REGISTRATION && tg_data->get_string) {
+ tg_data->get_string(tgl_engine_get_TLS(), tg_data->first_name, tg_data->callback_arg);
}
+ } else if (strcmp(cmd_key_val, "device_contact_list") == 0) {
+
+ char* count_str = NULL;
+ res = bundle_get_str(rec_msg, "count", &count_str);
+ int size = atoi(count_str);
+ Eina_List* contact_list = NULL;
+
+ for (int count = 0 ; count < size ; count++) {
+ contact_data_s* contact = (contact_data_s*)malloc(sizeof(contact_data_s));
+ contact->first_name = NULL;
+ contact->last_name = NULL;
+ contact->phone_number = NULL;
+
+ char count_str[10];
+ sprintf(count_str, "%d", count);
+
+ char first_name_key[20];
+ strcpy(first_name_key, "first_name_");
+ strcat(first_name_key, count_str);
+
+ char last_name_key[20];
+ strcpy(last_name_key, "last_name_");
+ strcat(last_name_key, count_str);
+
+ char phone_number_key[20];
+ strcpy(phone_number_key, "phone_number_");
+ strcat(phone_number_key, count_str);
+
+ char* first_name = NULL;
+ res = bundle_get_str(rec_msg, first_name_key, &first_name);
- tmp = (char *)tg_common_to_string("last_name_%d", count);
- result = bundle_get_str(rec_msg, tmp, &tmp);
- if (result == BUNDLE_ERROR_NONE) {
- contact->last_name = strdup(tmp);
+ if (first_name) {
+ contact->first_name = strdup(first_name);
+ }
+
+ char* last_name = NULL;
+ res = bundle_get_str(rec_msg, last_name_key, &last_name);
+
+ if (last_name) {
+ contact->last_name = strdup(last_name);
+ }
+
+ char* phone_number = NULL;
+ res = bundle_get_str(rec_msg, phone_number_key, &phone_number);
+
+ if (phone_number) {
+ contact->phone_number = strdup(phone_number);
+ }
+ contact_list = eina_list_append(contact_list, contact);
}
- tmp = (char *)tg_common_to_string("phone_number_%d", count);
- result = bundle_get_str(rec_msg, tmp, &tmp);
- if (result == BUNDLE_ERROR_NONE) {
- contact->phone_number = strdup(tmp);
+ process_add_contacts_command(tg_data, size, contact_list);
+
+ } else if (strcmp(cmd_key_val, "group_creation_request") == 0) {
+ char* count_str = NULL;
+ res = bundle_get_str(rec_msg, "count", &count_str);
+ int size = atoi(count_str);
+ Eina_List* buddy_ids = NULL;
+
+ for (int count = 0 ; count < size ; count++) {
+ char count_str[10];
+ sprintf(count_str, "%d", count);
+
+ char buddy_id_key[20];
+ strcpy(buddy_id_key, "buddy_id_");
+ strcat(buddy_id_key, count_str);
+
+ char* buddy_id = NULL;
+ res = bundle_get_str(rec_msg, buddy_id_key, &buddy_id);
+
+ buddy_ids = eina_list_append(buddy_ids, buddy_id);
}
- contact_list = eina_list_append(contact_list, contact);
- }
+ char* temp_group_name = NULL;
+ res = bundle_get_str(rec_msg, "group_name", &temp_group_name);
+ char* group_name = strdup(temp_group_name);
- process_add_contacts_command(tg_data, size, contact_list);
-}
+ char* temp_group_image = NULL;
+ res = bundle_get_str(rec_msg, "group_image", &temp_group_image);
+ char* group_image = strdup(temp_group_image);
-static void group_creation_request_handler(bundle *rec_msg, void *data)
-{
- int result;
- tg_engine_data_s *tg_data = data;
- char *tmp = NULL;
- int size;
- int count;
- Eina_List* buddy_ids = NULL;
- char *group_name;
- char *group_image;
-
- result = bundle_get_str(rec_msg, "count", &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- return;
- }
- size = atoi(tmp);
+ process_new_group_create_command(tg_data, buddy_ids, group_name, group_image);
+ } else if (strcmp(cmd_key_val, "remove_buddy_from_chat_request") == 0) {
+
+ char *buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
- for (count = 0 ; count < size; count++) {
- tmp = (char *)tg_common_to_string("buddy_id_%d", count);
- result = bundle_get_str(rec_msg, tmp, &tmp);
- if (result != BUNDLE_ERROR_NONE) {
- goto out;
+ int buddy_id = 0;
+ if (buddy_id_str) {
+ buddy_id = atoi(buddy_id_str);
}
- buddy_ids = eina_list_append(buddy_ids, strdup(tmp));
- }
- result = bundle_get_str(rec_msg, "group_name", &group_name);
- if (result != BUNDLE_ERROR_NONE) {
- goto out;
- }
+ char *chat_id_str = NULL;
+ res = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
- result = bundle_get_str(rec_msg, "group_image", &group_image);
- if (result != BUNDLE_ERROR_NONE) {
- goto out;
- }
+ int chat_id = 0;
+ if (chat_id_str) {
+ chat_id = atoi(chat_id_str);
+ }
+ process_remove_buddy_from_chat_command(tg_data, buddy_id, chat_id);
- process_new_group_create_command(tg_data, buddy_ids, group_name, group_image);
+ } else if (strcmp(cmd_key_val, "add_new_buddy_to_chat_request") == 0) {
-out:
- EINA_LIST_FREE(buddy_ids, tmp) {
- free(tmp);
- }
-}
+ char *buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
-static int _on_tg_server_msg_received_cb(void *data, bundle * const rec_msg)
-{
- int i;
- int result = SVC_RES_FAIL;
- RETVM_IF(!data, result, "Data is NULL");
- char *cmd_key_val = NULL;
- struct _msg_handler {
- const char *key;
- void (*handler)(bundle *, void *);
- } msg_handlers[] = {
- [0] = {
- .key = "registration",
- .handler = registration_handler,
- },
- [1] = {
- .key = "code_validation",
- .handler = code_validation_handler,
- },
- [2] = {
- .key = "message_transport",
- .handler = message_transport_handler,
- },
- [3] = {
- .key = "marked_as_read",
- .handler = marked_as_read_handler,
- },
- [4] = {
- .key = "media_download_request",
- .handler = media_download_request_handler,
- },
- [5] = {
- .key = "media_transport",
- .handler = media_transport_handler,
- },
- [6] = {
- .key = "profile_registration",
- .handler = profile_registration_handler,
- },
- [7] = {
- .key = "device_contact_list",
- .handler = device_contact_list_handler,
- },
- [8] = {
- .key = "group_creation_request",
- .handler = group_creation_request_handler,
- },
- [9] = {
- .key = NULL,
- .handler = NULL,
- },
- };
-
- result = bundle_get_str(rec_msg, "command", &cmd_key_val);
- if (result != BUNDLE_ERROR_NONE) {
- return result;
- }
+ int buddy_id = 0;
+ if (buddy_id_str) {
+ buddy_id = atoi(buddy_id_str);
+ }
+
+ char *chat_id_str = NULL;
+ res = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
+
+ int chat_id = 0;
+ if (chat_id_str) {
+ chat_id = atoi(chat_id_str);
+ }
+ process_add_new_buddy_to_chat_command(tg_data, buddy_id, chat_id);
+
+ } else if (strcmp(cmd_key_val, "set_group_chat_new_title_request") == 0) {
+
+ char *buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+
+ int buddy_id = 0;
+ if (buddy_id_str) {
+ buddy_id = atoi(buddy_id_str);
+ }
+
+ char *new_title = NULL;
+ res = bundle_get_str(rec_msg, "new_title", &new_title);
+ process_set_group_chat_new_title_command(tg_data, buddy_id, new_title);
+
+ } else if (strcmp(cmd_key_val, "set_group_chat_profile_pic_request") == 0) {
+
+ char *buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+
+ int buddy_id = 0;
+ if (buddy_id_str) {
+ buddy_id = atoi(buddy_id_str);
+ }
- for (i = 0; msg_handlers[i].key; i++) {
- if (strcmp(msg_handlers[i].key, cmd_key_val)) {
- continue;
+ char *file_path = NULL;
+ res = bundle_get_str(rec_msg, "file_path", &file_path);
+ process_set_group_chat_profile_pic_command(tg_data, buddy_id, file_path);
+
+ } else if (strcmp(cmd_key_val, "set_profile_pic_request") == 0) {
+
+ char *buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+
+ int buddy_id = 0;
+ if (buddy_id_str) {
+ buddy_id = atoi(buddy_id_str);
}
- if (!msg_handlers[i].handler) {
- break;
+ char *file_path = NULL;
+ res = bundle_get_str(rec_msg, "file_path", &file_path);
+ process_set_profile_pic_command(tg_data, buddy_id, file_path);
+ } else if (strcmp(cmd_key_val, "set_username_request") == 0) {
+
+ char *buddy_id_str = NULL;
+ res = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+
+ int buddy_id = 0;
+ if (buddy_id_str) {
+ buddy_id = atoi(buddy_id_str);
}
- msg_handlers[i].handler(rec_msg, data);
+ char *username = NULL;
+ res = bundle_get_str(rec_msg, "username", &username);
+ process_set_username_command(tg_data, buddy_id, username);
+
+ } else if (strcmp(cmd_key_val, "delete_all_notifications") == 0) {
+ if(tg_data->s_notififcation) {
+ notification_delete_all(NOTIFICATION_TYPE_NOTI);
+ tg_data->s_notififcation = NULL;
+ }
+ } else if (strcmp(cmd_key_val, "server_connection_status") == 0) {
+ send_response_for_server_connection_status(tg_data, tg_data->is_login_activated);
+ } else {
+
}
- return 0;
+ return result;
}
Eina_Bool event_idler_cb(void *data)
return ECORE_CALLBACK_CANCEL;
}
+static Eina_Bool on_start_service_requested(void *data)
+{
+ tg_engine_data_s *tg_data = data;
+
+ init_tl_engine(data);
+ tgl_login(tgl_engine_get_TLS());
+
+ tg_data->lazy_init_idler = NULL;
+ return ECORE_CALLBACK_CANCEL;
+}
+
+static Eina_Bool on_restart_service_requested(void *data)
+{
+ tg_engine_data_s *tg_data = data;
+
+
+ free_connection(tg_data);
+ tgl_engine_var_init();
+ tg_db_init();
+ tg_data->tg_state = TG_ENGINE_STATE_REGISTRATION;
+ tg_data->tg_server = tg_server_create();
+ tg_data->first_name = NULL;
+ tg_data->last_name = NULL;
+ tg_data->phone_number = NULL;
+ tg_data->sms_code = NULL;
+ tg_data->contact_list_to_add = NULL;
+ tg_data->new_group_icon = NULL;
+ tg_data->mhash = NULL;
+ tg_data->lazy_init_idler = NULL;
+
+
+ init_tl_engine(data);
+ tgl_login(tgl_engine_get_TLS());
+
+ tg_data->lazy_init_idler = NULL;
+ return ECORE_CALLBACK_CANCEL;
+}
+
void on_connection_type_changed_cb(connection_type_e type, void *user_data)
{
tg_engine_data_s *tg_data = user_data;
case CONNECTION_WIFI_STATE_DEACTIVATED:
case CONNECTION_WIFI_STATE_DISCONNECTED:
default:
+ tg_data->is_login_activated = EINA_FALSE;
tg_data->is_network_connected = EINA_FALSE;
+ send_response_for_server_connection_status(tg_data, tg_data->is_login_activated);
break;
}
}
tg_data->is_network_connected = EINA_TRUE;
}
} else {
-
+ tg_data->is_login_activated = EINA_FALSE;
+ tg_data->is_network_connected = EINA_FALSE;
+ send_response_for_server_connection_status(tg_data, tg_data->is_login_activated);
}
/**
* @note
* We should find a gorgeous way to initialize the Telegram Service.
*/
- if (tg_data->is_network_connected && !tg_data->is_login_activated) {
-
- if (!tg_data->lazy_init_idler) {
- tg_data->lazy_init_idler = ecore_idler_add(event_idler_cb, tg_data);
+ if (tg_data->is_network_connected) {
+ if (tg_data->is_login_activated) {
+ tg_data->is_login_activated = EINA_FALSE;
+ ecore_timer_add(30, on_restart_service_requested, tg_data);
+ } else {
+ ecore_timer_add(5, on_start_service_requested, tg_data);
}
}
}
tg_engine_data_s *tg_data = data;
RETVM_IF(!tg_data, SVC_RES_FAIL, "Application data is NULL");
-
+ tgl_engine_var_init();
tg_db_init();
tg_data->tg_state = TG_ENGINE_STATE_REGISTRATION;
tg_data->tg_server = tg_server_create();
+ tg_data->first_name = NULL;
+ tg_data->last_name = NULL;
+ tg_data->phone_number = NULL;
+ tg_data->sms_code = NULL;
+ tg_data->contact_list_to_add = NULL;
+ tg_data->new_group_icon = NULL;
+ tg_data->mhash = NULL;
+ tg_data->lazy_init_idler = NULL;
+ tg_data->s_notififcation = NULL;
+ //tg_data->is_loading_completed = EINA_FALSE;
RETVM_IF(!tg_data->tg_server, SVC_RES_FAIL, "Failed to create proxy client");
result = tg_server_register_port(tg_data->tg_server, TELEGRAM_SERVER_PORT_NAME);
// if wi-fi or data is on
create_data_base_tables();
+ int err = badge_new(TELEGRAM_APP_ID);
+ if (BADGE_ERROR_NONE != err) {
+
+ }
+
result = connection_create(&(tg_data->connection));
if (result == CONNECTION_ERROR_NONE) {
connection_type_e net_state;
return true;
}
-void service_app_terminate(void *data)
+void free_connection(tg_engine_data_s* tg_data)
{
- tg_engine_data_s* tg_data = data;
- struct tgl_state *TLS;
+ //struct tgl_state *TLS;
+/*
TLS = tgl_engine_get_TLS();
if (TLS) {
tgl_engine_destroy_TLS();
}
+*/
+ tg_data->is_login_activated = EINA_FALSE;
+ tg_data->is_network_connected = EINA_FALSE;
+ send_response_for_server_connection_status(tg_data, tg_data->is_login_activated);
+ if (tg_data->phone_number) {
+ free(tg_data->phone_number);
+ tg_data->phone_number = NULL;
+ }
+
+ if (tg_data->sms_code) {
+ free(tg_data->sms_code);
+ tg_data->sms_code = NULL;
+ }
+ if (tg_data->first_name) {
+ free(tg_data->first_name);
+ tg_data->first_name = NULL;
+ }
+
+ if (tg_data->last_name) {
+ free(tg_data->last_name);
+ tg_data->last_name = NULL;
+ }
+
+ if (tg_data->contact_list_to_add) {
+ free_contact_data(tg_data->contact_list_to_add);
+ tg_data->contact_list_to_add = NULL;
+ }
+ tgl_engine_var_free();
+
+ tg_db_fini();
+}
+
+void service_app_terminate(void *data)
+{
+ tg_engine_data_s* tg_data = data;
+ if (tg_data->connection) {
+ connection_destroy(tg_data->connection);
+ tg_data->connection = NULL;
+ }
if (tg_data->tg_server) {
tg_server_destroy(tg_data->tg_server);
tg_data->tg_server = NULL;
}
-
- connection_destroy(tg_data->connection);
- if (tg_data) {
- free(tg_data);
- tg_data = NULL;
+ if (tg_data && tg_data->s_notififcation) {
+ notification_delete_all(NOTIFICATION_TYPE_NOTI);
+ tg_data->s_notififcation = NULL;
}
- tg_db_fini();
+ free_connection(tg_data);
return;
}
return;
}
-static void service_app_lang_changed(app_event_info_h event_info, void *user_data)
+static void
+service_app_lang_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LANGUAGE_CHANGED*/
return;
}
-static void service_app_orient_changed(app_event_info_h event_info, void *user_data)
+static void
+service_app_orient_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
return;
}
-static void service_app_region_changed(app_event_info_h event_info, void *user_data)
+static void
+service_app_region_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_REGION_FORMAT_CHANGED*/
}
-static void service_app_low_battery(app_event_info_h event_info, void *user_data)
+static void
+service_app_low_battery(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LOW_BATTERY*/
}
-static void service_app_low_memory(app_event_info_h event_info, void *user_data)
+static void
+service_app_low_memory(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LOW_MEMORY*/
}
* @author sandeep
*/
-#include "tgl-layout.h"
-#include "tg_common.h"
#include "tg_db_wrapper.h"
+#include "tg_common.h"
+#include "tgl-layout.h"
+
+void create_data_base_tables()
+{
+ char* table_name = USER_INFO_TABLE_NAME;
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_STRUCTURE_VERSION);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHONE_NO);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ACCESS_HASH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ONLINE_STATUS);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_BLOCKED);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_DELETED);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ Eina_Bool ret = create_table(table_name, col_names, col_types);
+ if(!ret) {
+ // error occured
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+ table_name = BUDDY_INFO_TABLE_NAME;
+ col_names = NULL;
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_STRUCTURE_VERSION);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHONE_NO);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ACCESS_HASH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ONLINE_STATUS);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_BLOCKED);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_DELETED);
+
+ col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ ret = create_table(table_name, col_names, col_types);
+ if(!ret) {
+ // error occured
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+
+ table_name = MEDIA_INFO_TABLE_NAME;
+ col_names = NULL;
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_ID);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_ACCESS_HASH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_USER_ID);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DATE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_CAPTION);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LONGITUDE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LATITUDE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_SIZES_NUM);
+
+
+ /********************************************************************/
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA1);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA2);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA3);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA4);
+
+
+ /********************************************************************/
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHONE_NO);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LAST_NAME);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FILE_PATH);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MIME_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_WIDTH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_HEIGHT);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DURATION);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_SIZE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DC);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE);
+
+ col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ ret = create_table(table_name, col_names, col_types);
+ if(!ret) {
+ // error occured
+ }
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+ table_name = CHAT_INFO_TABLE_NAME;
+ col_names = NULL;
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_CHAT_ID);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_FLAGS);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_PRINT_TITLE);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_STRUCT_VERSION);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_PHOTO_ID);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_TITLE);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_NO_OF_USERS);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_USER_LIST_SIZE);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_USER_LIST_VERSION);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_INVITER_ID);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_CHAT_USERS);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_DATE);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_VERSION);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_ADMIN_ID);
+
+ col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ ret = create_table(table_name, col_names, col_types);
+ if(!ret) {
+ // error occured
+ }
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+ table_name = PEER_INFO_TABLE_NAME;
+ col_names = NULL;
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_CHAT_ID);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_PEER_TYPE);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_FLAGS);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_MESSAGE_ID);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_MESSAGE_DATE);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_PRINT_NAME);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_STRUCT_VERSION);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_NO_OF_UNREAD_MESSAGES);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
+
+ col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ ret = create_table(table_name, col_names, col_types);
+ if(!ret) {
+ // error occured
+ }
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+
+ /****************************************************/
+
+ table_name = MESSAGE_TRANSPORT_TABLE_NAME;
+ col_names = NULL;
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_ROW_ID);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_APP_NAME);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_COMMAND);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_BUDDY_ID);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_MESSAGE_TYPE);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_MESSAGE_DATA);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_TYPE_OF_CHAT);
+
+ col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_AUTO_INC_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ ret = create_table(table_name, col_names, col_types);
+ if(!ret) {
+ // error occured
+ }
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+
+ table_name = MEDIA_TRANSPORT_TABLE_NAME;
+ col_names = NULL;
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_ROW_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_APP_NAME);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_COMMAND);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_BUDDY_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_MEDIA_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_MESSAGE_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_FILE_PATH);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_TYPE_OF_CHAT);
+
+ col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_AUTO_INC_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ ret = create_table(table_name, col_names, col_types);
+ if(!ret) {
+ // error occured
+ }
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+}
+
+
+void delete_message_from_unsent_db(int message_id)
+{
+ char* where_clause = NULL;
+ char msg_id_str[50];
+ sprintf(msg_id_str,"%d", message_id);
+ where_clause = (char*)malloc(strlen(MESSAGE_TRANSPORT_TABLE_MESSAGE_ID) + strlen(" = ") + strlen(msg_id_str) + 1);
+ strcpy(where_clause, MESSAGE_TRANSPORT_TABLE_MESSAGE_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, msg_id_str);
+ Eina_Bool ret = delete_record(MESSAGE_TRANSPORT_TABLE_NAME, where_clause);
+ free(where_clause);
+ if(!ret) {
+ //("error: database creation failed");
+ } else {
+
+ }
+}
+
+Eina_List* get_all_unsent_text_messages()
+{
+ Eina_List* unsent_msg_details = NULL;
+ Eina_List* ret_msg_details = NULL;
+ char* table_name = MESSAGE_TRANSPORT_TABLE_NAME;
+ Eina_List* col_names = NULL;
+
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_APP_NAME);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_COMMAND);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_BUDDY_ID);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_MESSAGE_TYPE);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_MESSAGE_DATA);
+ col_names = eina_list_append(col_names, MESSAGE_TRANSPORT_TABLE_TYPE_OF_CHAT);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ unsent_msg_details = get_values_from_table_sync_order_by(table_name, col_names, col_types, MESSAGE_TRANSPORT_TABLE_ROW_ID, EINA_TRUE, NULL);
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+ if (unsent_msg_details) {
+ for (int i = 0; i < eina_list_count(unsent_msg_details) ; i++) {
+ Eina_List* ts_msg = eina_list_nth(unsent_msg_details, i);
+ sent_message_data_s* msg_info = (sent_message_data_s*)malloc(sizeof(sent_message_data_s));
+
+ char *temp_app_name = (char*)eina_list_nth(ts_msg, 0);
+ if (temp_app_name) {
+ msg_info->app_name = strdup(temp_app_name);
+ free(temp_app_name);
+ } else {
+ msg_info->app_name = NULL;
+ }
+
+ char *temp_command = (char*)eina_list_nth(ts_msg, 1);
+ if (temp_command) {
+ msg_info->command = strdup(temp_command);
+ free(temp_command);
+ } else {
+ msg_info->command = NULL;
+ }
+
+ char *temp_buddy_id = (char*)eina_list_nth(ts_msg, 2);
+ if (temp_buddy_id) {
+ msg_info->buddy_id = strdup(temp_buddy_id);
+ free(temp_buddy_id);
+ } else {
+ msg_info->buddy_id = NULL;
+ }
+
+ char *temp_msg_id = (char*)eina_list_nth(ts_msg, 3);
+ if (temp_msg_id) {
+ msg_info->message_id = strdup(temp_msg_id);
+ free(temp_msg_id);
+ } else {
+ msg_info->message_id = NULL;
+ }
+
+ char *temp_msg_type = (char*)eina_list_nth(ts_msg, 4);
+ if (temp_msg_type) {
+ msg_info->message_type = strdup(temp_msg_type);
+ free(temp_msg_type);
+ } else {
+ msg_info->message_type = NULL;
+ }
+
+ char *temp_msg_data = (char*)eina_list_nth(ts_msg, 5);
+ if (temp_msg_data) {
+ msg_info->message_data = strdup(temp_msg_data);
+ free(temp_msg_data);
+ } else {
+ msg_info->message_data = NULL;
+ }
+
+ char *temp_type_of_chat = (char*)eina_list_nth(ts_msg, 6);
+ if (temp_type_of_chat) {
+ msg_info->type_of_chat = strdup(temp_type_of_chat);
+ free(temp_type_of_chat);
+ } else {
+ msg_info->type_of_chat = NULL;
+ }
+ ret_msg_details = eina_list_append(ret_msg_details, msg_info);
+ eina_list_free(ts_msg);
+ }
+
+ eina_list_free(unsent_msg_details);
+ }
+ return ret_msg_details;
+}
+
+void delete_media_from_unsent_db(int message_id)
+{
+ char* where_clause = NULL;
+ char msg_id_str[50];
+ sprintf(msg_id_str,"%d", message_id);
+ where_clause = (char*)malloc(strlen(MEDIA_TRANSPORT_TABLE_MESSAGE_ID) + strlen(" = ") + strlen(msg_id_str) + 1);
+ strcpy(where_clause, MEDIA_TRANSPORT_TABLE_MESSAGE_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, msg_id_str);
+ Eina_Bool ret = delete_record(MEDIA_TRANSPORT_TABLE_NAME, where_clause);
+ free(where_clause);
+ if(!ret) {
+ //("error: database creation failed");
+ } else {
+
+ }
+}
+
+Eina_List* get_all_unsent_media_messages()
+{
+ Eina_List* unsent_msg_details = NULL;
+ Eina_List* ret_msg_details = NULL;
+ char* table_name = MEDIA_TRANSPORT_TABLE_NAME;
+ Eina_List* col_names = NULL;
+
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_APP_NAME);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_COMMAND);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_BUDDY_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_MEDIA_ID);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_MESSAGE_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_FILE_PATH);
+ col_names = eina_list_append(col_names, MEDIA_TRANSPORT_TABLE_TYPE_OF_CHAT);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ unsent_msg_details = get_values_from_table_sync_order_by(table_name, col_names, col_types, MEDIA_TRANSPORT_TABLE_ROW_ID, EINA_TRUE, NULL);
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+ if (unsent_msg_details) {
+ for (int i = 0; i < eina_list_count(unsent_msg_details) ; i++) {
+ Eina_List* ts_msg = eina_list_nth(unsent_msg_details, i);
+ sent_media_data_s* msg_info = (sent_media_data_s*)malloc(sizeof(sent_media_data_s));
+
+ char *temp_app_name = (char*)eina_list_nth(ts_msg, 0);
+ if (temp_app_name) {
+ msg_info->app_name = strdup(temp_app_name);
+ free(temp_app_name);
+ } else {
+ msg_info->app_name = NULL;
+ }
+
+ char *temp_command = (char*)eina_list_nth(ts_msg, 1);
+ if (temp_command) {
+ msg_info->command = strdup(temp_command);
+ free(temp_command);
+ } else {
+ msg_info->command = NULL;
+ }
+
+ char *temp_buddy_id = (char*)eina_list_nth(ts_msg, 2);
+ if (temp_buddy_id) {
+ msg_info->buddy_id = strdup(temp_buddy_id);
+ free(temp_buddy_id);
+ } else {
+ msg_info->buddy_id = NULL;
+ }
+
+ char *temp_msg_id = (char*)eina_list_nth(ts_msg, 3);
+ if (temp_msg_id) {
+ msg_info->message_id = strdup(temp_msg_id);
+ free(temp_msg_id);
+ } else {
+ msg_info->message_id = NULL;
+ }
+
+ char *temp_media_id = (char*)eina_list_nth(ts_msg, 4);
+ if (temp_media_id) {
+ msg_info->media_id = strdup(temp_media_id);
+ free(temp_media_id);
+ } else {
+ msg_info->media_id = NULL;
+ }
+
+ char *temp_msg_type = (char*)eina_list_nth(ts_msg, 5);
+ if (temp_msg_type) {
+ msg_info->message_type = strdup(temp_msg_type);
+ free(temp_msg_type);
+ } else {
+ msg_info->message_type = NULL;
+ }
+
+ char *temp_file_path = (char*)eina_list_nth(ts_msg, 6);
+ if (temp_file_path) {
+ msg_info->file_path = strdup(temp_file_path);
+ free(temp_file_path);
+ } else {
+ msg_info->file_path = NULL;
+ }
+
+ char *temp_type_of_chat = (char*)eina_list_nth(ts_msg, 7);
+ if (temp_type_of_chat) {
+ msg_info->type_of_chat = strdup(temp_type_of_chat);
+ free(temp_type_of_chat);
+ } else {
+ msg_info->type_of_chat = NULL;
+ }
+ ret_msg_details = eina_list_append(ret_msg_details, msg_info);
+ eina_list_free(ts_msg);
+ }
+
+ eina_list_free(unsent_msg_details);
+ }
+ return ret_msg_details;
+}
+
+
+void create_buddy_msg_table(const char* table_name)
+{
+ if(!table_name) {
+ return;
+ }
+ // create user info table
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_ROW_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FLAGS);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_FROM_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_DATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FROM_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_TO_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_OUT_MSG);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNREAD);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_DATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_SERVICE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_STATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_LENGTH);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_TYPE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNIQUE_ID);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_AUTO_INC_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ Eina_Bool ret = create_table(table_name, col_names, col_types);
+ if(!ret) {
+ //("error: database creation failed");
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+}
+
+int insert_current_date_to_table(char* tb_name)
+{
+ struct tgl_message* last_msg = get_latest_message_from_message_table(tb_name);
+ if (last_msg) {
+ int old_date = last_msg->date;
+ time_t old_t = old_date;
+
+ struct tm old_lt;
+ (void) localtime_r(&old_t, &old_lt);
+
+
+ int cur_time = time(NULL);
+ time_t new_t = cur_time;
+
+ struct tm new_lt;
+ (void) localtime_r(&new_t, &new_lt);
+
+
+ if (old_lt.tm_mday == new_lt.tm_mday && old_lt.tm_mon == new_lt.tm_mon && old_lt.tm_year == new_lt.tm_year) {
+ // no need of new date
+ return -1;
+ } else {
+ int cur_time = time(NULL);
+ time_t t = cur_time;
+
+ char *format = NULL;
+ format = "%d %B %Y";
+
+ struct tm lt;
+ char res[256];
+ (void) localtime_r(&t, <);
+
+ if (strftime(res, sizeof(res), format, <) == 0) {
+ (void) fprintf(stderr, "strftime(3): cannot format supplied "
+ "date/time into buffer of size %u "
+ "using: '%s'\n",
+ sizeof(res), format);
+ }
+
+ srand(time(NULL));
+ int r = rand();
+ struct tgl_message date_msg;
+ date_msg.id = r;
+ date_msg.media.type = tgl_message_media_none;
+ date_msg.date = cur_time;
+ date_msg.message = res;
+ date_msg.message_len = strlen(res);
+ date_msg.service = 2;
+ date_msg.unread = 0;
+ date_msg.out = 0;
+ insert_msg_into_db(&date_msg, tb_name, t);
+ return date_msg.id;
+ }
+
+ } else {
+ int cur_time = time(NULL);
+ time_t t = cur_time;
+
+ char *format = NULL;
+ format = "%d %B %Y";
+
+ struct tm lt;
+ char res[256];
+ (void) localtime_r(&t, <);
+
+ if (strftime(res, sizeof(res), format, <) == 0) {
+ (void) fprintf(stderr, "strftime(3): cannot format supplied "
+ "date/time into buffer of size %u "
+ "using: '%s'\n",
+ sizeof(res), format);
+ }
+ srand(time(NULL));
+ int r = rand();
+ struct tgl_message date_msg;
+ date_msg.id = r;
+ date_msg.media.type = tgl_message_media_none;
+ date_msg.date = cur_time;
+ date_msg.message = res;
+ date_msg.message_len = strlen(res);
+ date_msg.service = 2;
+ date_msg.unread = 0;
+ date_msg.out = 0;
+ insert_msg_into_db(&date_msg, tb_name, t);
+ return date_msg.id;
+ }
+ return -1;
+}
+
+void insert_buddy_msg_to_db(struct tgl_message *M)
+{
+ // get user name using id from buddy_info_table
+ int t = 0;
+#if 0
+ char* table_name = BUDDY_INFO_TABLE_NAME;
+
+ int user_id = M->from_id.id;
+ char usr_str[50];
+ sprintf(usr_str,"%d",user_id);
+
+ char* where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(usr_str));
+ strcpy(where_clause, USER_INFO_TABLE_USER_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, usr_str);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHONE_NO);
+
+ Eina_List* vals = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+ close_database(db);
+
+ char* phone_no = NULL;
+
+ if(!vals) {
+ //("DB error");
+ return;
+ } else {
+ int row_count = eina_list_count(vals);
+
+ for (int i = 0 ; i < row_count ; i++) {
+ Eina_List* row_vals = eina_list_nth(vals, i);
+ phone_no = (char*)eina_list_nth(row_vals, 0);
+ if(!phone_no) {
+ //("DB Error");
+ return;
+ } else {
+ break;
+ }
+ eina_list_free(row_vals);
+ }
+ eina_list_free(vals);
+ }
+
+ if(phone_no) {
+ char* tb_name = get_table_name_from_number(phone_no);
+ insert_msg_into_db(M, tb_name, t);
+ free(tb_name);
+ free(phone_no);
+ }
+#else
+ int user_id = 0;
+ if (tgl_get_peer_type(M->to_id) == TGL_PEER_USER) {
+ user_id = M->from_id.id;
+ } else if (tgl_get_peer_type(M->to_id) == TGL_PEER_CHAT) {
+ user_id = M->to_id.id;
+ }
+ char* tb_name = get_table_name_from_number(user_id);
+ insert_msg_into_db(M, tb_name, t);
+ free(tb_name);
+#endif
+}
+
+
+struct tgl_message* get_latest_message_from_message_table(char* table_name)
+{
+
+ struct tgl_message* message = NULL;
+
+ Eina_List* message_details = NULL;
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FLAGS);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_FROM_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_DATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FROM_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_TO_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_OUT_MSG);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNREAD);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_DATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_SERVICE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_STATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_LENGTH);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_TYPE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNIQUE_ID);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ message_details = get_values_from_table_sync_order_by(table_name, col_names, col_types, MESSAGE_INFO_TABLE_DATE, EINA_FALSE, NULL);
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+
+ if (message_details && eina_list_count(message_details) > 0) {
+ Eina_List* ts_msg = eina_list_nth(message_details, 0);
+
+ message = (struct tgl_message*)malloc(sizeof(struct tgl_message));
+
+
+ int *temp_msg_id = (int*)eina_list_nth(ts_msg, 0);
+ if (temp_msg_id) {
+ message->id = *temp_msg_id;
+ free(temp_msg_id);
+ }
+
+ int *temp_flags = (int*)eina_list_nth(ts_msg, 1);
+ if (temp_flags) {
+ message->flags = *temp_flags;
+ free(temp_flags);
+ }
+
+
+ int *temp_fwd_from_id = (int*)eina_list_nth(ts_msg, 2);
+ if (temp_fwd_from_id) {
+ message->fwd_from_id.id = *temp_fwd_from_id;
+ free(temp_fwd_from_id);
+ }
+
+
+ int *temp_fwd_date = (int*)eina_list_nth(ts_msg, 3);
+ if (temp_fwd_date) {
+ message->fwd_date = *temp_fwd_date;
+ free(temp_fwd_date);
+ }
+
+
+ int *temp_from_id = (int*)eina_list_nth(ts_msg, 4);
+ if (temp_from_id) {
+ message->from_id.id = *temp_from_id;
+ free(temp_from_id);
+ }
+
+ int *temp_to_id = (int*)eina_list_nth(ts_msg, 5);
+ if (temp_to_id) {
+ message->to_id.id = *temp_to_id;
+ free(temp_to_id);
+ }
+
+ int *temp_out = (int*)eina_list_nth(ts_msg, 6);
+ if (temp_out) {
+ message->out = *temp_out;
+ free(temp_out);
+ }
+
+ int *temp_unread = (int*)eina_list_nth(ts_msg, 7);
+ if (temp_unread) {
+ message->unread = *temp_unread;
+ free(temp_unread);
+ }
+
+ int *temp_date = (int*)eina_list_nth(ts_msg, 8);
+ if (temp_date) {
+ message->date = *temp_date;
+ free(temp_date);
+ }
+
+ int *temp_service = (int*)eina_list_nth(ts_msg, 9);
+ if (temp_service) {
+ message->service = *temp_service;
+ free(temp_service);
+ }
+
+ char *temp_msg = (char*)eina_list_nth(ts_msg, 10);
+ if (temp_msg) {
+ message->message = strdup(temp_msg);
+ free(temp_msg);
+ }
+
+ int *temp_message_state = (int*)eina_list_nth(ts_msg, 11);
+ if (temp_message_state) {
+ message->msg_state = *temp_message_state;
+ free(temp_message_state);
+ }
+
+ int *temp_message_len = (int*)eina_list_nth(ts_msg, 12);
+ if (temp_message_len) {
+ message->message_len = *temp_message_len;
+ free(temp_message_len);
+ }
+
+ int *temp_media_type = (int*)eina_list_nth(ts_msg, 13);
+ if (temp_media_type) {
+ message->media.type = *temp_media_type;
+ free(temp_media_type);
+ }
+ // to do, get media id based on media type
+ }
+ return message;
+
+}
+
+
+
+void update_peer_info_database(tgl_peer_t* UC)
+{
+ if (!UC) {
+ return;
+ }
+
+ char* table_name = PEER_INFO_TABLE_NAME;
+ Eina_List* col_names = NULL;
+ col_names = NULL;
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_CHAT_ID);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_PEER_TYPE);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_FLAGS);
+
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_MESSAGE_DATE);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_PRINT_NAME);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_STRUCT_VERSION);
+
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, &(UC->id.id));
+ col_values = eina_list_append(col_values, &(UC->id.type));
+ col_values = eina_list_append(col_values, &(UC->flags));
+
+
+ // last message date
+ if (UC->last) {
+ col_values = eina_list_append(col_values, &(UC->last->date));
+ } else {
+ int last_msg_date = 0;
+ col_values = eina_list_append(col_values, &(last_msg_date));
+ }
+
+ if (UC->print_name) {
+ col_values = eina_list_append(col_values, UC->print_name);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ col_values = eina_list_append(col_values, &(UC->structure_version));
+
+
+ if (UC->id.type == TGL_PEER_USER ) {
+ col_values = eina_list_append(col_values, &(UC->user.status.when));
+ } else if (UC->id.type == TGL_PEER_CHAT ) {
+ col_values = eina_list_append(col_values, &(UC->chat.date));
+ } else {
+ int last_seen = 0;
+ col_values = eina_list_append(col_values, &(last_seen));
+ }
+
+ col_values = eina_list_append(col_values, "");
+
+ struct tgl_photo* photo = &(UC->photo);
+ int photo_id = -1;
+ if (photo) {
+ photo_id = photo->id;
+ }
+ col_values = eina_list_append(col_values, &(photo_id));
+
+ Eina_Bool ret = insert_table(table_name, col_names, col_types,col_values);
+ if(!ret) {
+ // already exist. So update the table
+ char* where_clause = NULL;
+ char user_id_str[50];
+ sprintf(user_id_str,"%d",UC->id.id);
+ where_clause = (char*)malloc(strlen(PEER_INFO_TABLE_CHAT_ID) + strlen(" = ") + strlen(user_id_str) + 1);
+ strcpy(where_clause, PEER_INFO_TABLE_CHAT_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, user_id_str);
+ ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+ } else {
+
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+}
+
+void delete_chat_from_db(int peer_id)
+{
+ char* where_clause = NULL;
+ char user_id_str[50];
+ sprintf(user_id_str,"%d", peer_id);
+ where_clause = (char*)malloc(strlen(PEER_INFO_TABLE_CHAT_ID) + strlen(" = ") + strlen(user_id_str) + 1);
+ strcpy(where_clause, PEER_INFO_TABLE_CHAT_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, user_id_str);
+ Eina_Bool ret = delete_record(PEER_INFO_TABLE_NAME, where_clause);
+ free(where_clause);
+ if(!ret) {
+ //("error: database creation failed");
+ } else {
+
+ }
+}
+
+void delete_buddy_from_db(int peer_id)
+{
+ char* where_clause = NULL;
+ char user_id_str[50];
+ sprintf(user_id_str,"%d", peer_id);
+ where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(user_id_str) + 1);
+ strcpy(where_clause, USER_INFO_TABLE_USER_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, user_id_str);
+ Eina_Bool ret = delete_record(BUDDY_INFO_TABLE_NAME, where_clause);
+ free(where_clause);
+ if(!ret) {
+ //("error: database creation failed");
+ } else {
+
+ }
+}
+
+
+void insert_peer_into_database(tgl_peer_t* UC, int last_msg_id, int unread_count)
+{
+ if (!UC) {
+ return;
+ }
+
+ char* table_name = PEER_INFO_TABLE_NAME;
+ Eina_List* col_names = NULL;
+ col_names = NULL;
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_CHAT_ID);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_PEER_TYPE);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_FLAGS);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_MESSAGE_ID);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_MESSAGE_DATE);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_PRINT_NAME);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_STRUCT_VERSION);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_NO_OF_UNREAD_MESSAGES);
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, &(UC->id.id));
+ col_values = eina_list_append(col_values, &(UC->id.type));
+ col_values = eina_list_append(col_values, &(UC->flags));
+ char last_msg_id_str[50];
+ sprintf(last_msg_id_str, "%d", last_msg_id);
+ col_values = eina_list_append(col_values, last_msg_id_str);
+
+ // last message date
+ if (UC->last) {
+ col_values = eina_list_append(col_values, &(UC->last->date));
+ } else {
+ int last_msg_date = 0;
+ col_values = eina_list_append(col_values, &(last_msg_date));
+ }
+
+ if (UC->print_name) {
+ col_values = eina_list_append(col_values, UC->print_name);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ col_values = eina_list_append(col_values, &(UC->structure_version));
+
+ col_values = eina_list_append(col_values, &(unread_count));
+
+ if (UC->id.type == TGL_PEER_USER ) {
+ col_values = eina_list_append(col_values, &(UC->user.status.when));
+ } else if (UC->id.type == TGL_PEER_CHAT ) {
+ col_values = eina_list_append(col_values, &(UC->chat.date));
+ } else {
+ int last_seen = 0;
+ col_values = eina_list_append(col_values, &(last_seen));
+ }
+
+ col_values = eina_list_append(col_values, "");
+
+
+
+ struct tgl_photo* photo = &(UC->photo);
+ int photo_id = -1;
+ if (photo) {
+ photo_id = photo->id;
+ }
+ col_values = eina_list_append(col_values, &(photo_id));
+
+ Eina_Bool ret = insert_table(table_name, col_names, col_types,col_values);
+ if(!ret) {
+ // already exist. So update the table
+ char* where_clause = NULL;
+ char user_id_str[50];
+ sprintf(user_id_str,"%d",UC->id.id);
+ where_clause = (char*)malloc(strlen(PEER_INFO_TABLE_CHAT_ID) + strlen(" = ") + strlen(user_id_str) + 1);
+ strcpy(where_clause, PEER_INFO_TABLE_CHAT_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, user_id_str);
+ ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+ } else {
+
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+}
+
+struct tgl_message* get_message_from_message_table(long long msg_id, char* table_name)
+{
+ struct tgl_message* message = NULL;
+
+ Eina_List* message_details = NULL;
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FLAGS);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_FROM_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_DATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FROM_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_TO_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_OUT_MSG);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNREAD);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_DATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_SERVICE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_STATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_LENGTH);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_TYPE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNIQUE_ID);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ char *where_clause = NULL;
+ char msg_id_str[50];
+ sprintf(msg_id_str, "%lld", msg_id);
+ where_clause = (char *)malloc(strlen(MESSAGE_INFO_TABLE_MESSAGE_ID) + strlen(" = ") + strlen(msg_id_str) + 1);
+ strcpy(where_clause, MESSAGE_INFO_TABLE_MESSAGE_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, msg_id_str);
+
+ message_details = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+
+ free(where_clause);
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+ if (message_details && eina_list_count(message_details) > 0) {
+ Eina_List* ts_msg = eina_list_nth(message_details, 0);
+
+ message = (struct tgl_message*)malloc(sizeof(struct tgl_message));
+
+
+ int *temp_msg_id = (int*)eina_list_nth(ts_msg, 0);
+ if (temp_msg_id) {
+ message->id = *temp_msg_id;
+ free(temp_msg_id);
+ }
+
+ int *temp_flags = (int*)eina_list_nth(ts_msg, 1);
+ if (temp_flags) {
+ message->flags = *temp_flags;
+ free(temp_flags);
+ }
+
+
+ int *temp_fwd_from_id = (int*)eina_list_nth(ts_msg, 2);
+ if (temp_fwd_from_id) {
+ message->fwd_from_id.id = *temp_fwd_from_id;
+ free(temp_fwd_from_id);
+ }
+
+
+ int *temp_fwd_date = (int*)eina_list_nth(ts_msg, 3);
+ if (temp_fwd_date) {
+ message->fwd_date = *temp_fwd_date;
+ free(temp_fwd_date);
+ }
+
+
+ int *temp_from_id = (int*)eina_list_nth(ts_msg, 4);
+ if (temp_from_id) {
+ message->from_id.id = *temp_from_id;
+ free(temp_from_id);
+ }
+
+ int *temp_to_id = (int*)eina_list_nth(ts_msg, 5);
+ if (temp_to_id) {
+ message->to_id.id = *temp_to_id;
+ free(temp_to_id);
+ }
+
+ int *temp_out = (int*)eina_list_nth(ts_msg, 6);
+ if (temp_out) {
+ message->out = *temp_out;
+ free(temp_out);
+ }
+
+ int *temp_unread = (int*)eina_list_nth(ts_msg, 7);
+ if (temp_unread) {
+ message->unread = *temp_unread;
+ free(temp_unread);
+ }
+
+ int *temp_date = (int*)eina_list_nth(ts_msg, 8);
+ if (temp_date) {
+ message->date = *temp_date;
+ free(temp_date);
+ }
+
+ int *temp_service = (int*)eina_list_nth(ts_msg, 9);
+ if (temp_service) {
+ message->service = *temp_service;
+ free(temp_service);
+ }
+
+ char *temp_msg = (char*)eina_list_nth(ts_msg, 10);
+ if (temp_msg) {
+ message->message = strdup(temp_msg);
+ free(temp_msg);
+ }
+
+ int *temp_message_state = (int*)eina_list_nth(ts_msg, 11);
+ if (temp_message_state) {
+ message->msg_state = *temp_message_state;
+ free(temp_message_state);
+ }
+
+ int *temp_message_len = (int*)eina_list_nth(ts_msg, 12);
+ if (temp_message_len) {
+ message->message_len = *temp_message_len;
+ free(temp_message_len);
+ }
+
+ int *temp_media_type = (int*)eina_list_nth(ts_msg, 13);
+ if (temp_media_type) {
+ message->media.type = *temp_media_type;
+ free(temp_media_type);
+ }
+
+ char *temp_media_id = (char*)eina_list_nth(ts_msg, 14);
+
+ char *eptr;
+ if(message->media.type == tgl_message_media_none) {
+
+ if (temp_media_id) {
+ free(temp_media_id);
+ }
+
+ } else if(message->media.type == tgl_message_media_photo) {
+
+ if (temp_media_id) {
+ message->media.photo.id = strtoll(temp_media_id, &eptr, 10);
+ free(temp_media_id);
+ }
+
+ } else if(message->media.type == tgl_message_media_document) {
+
+ if (temp_media_id) {
+ message->media.document.id = strtoll(temp_media_id, &eptr, 10);
+ free(temp_media_id);
+ }
+
+ } else if(message->media.type == tgl_message_media_geo) {
+
+ if (temp_media_id) {
+ free(temp_media_id);
+ }
+
+ } else if(message->media.type == tgl_message_media_contact) {
+
+ if (temp_media_id) {
+ free(temp_media_id);
+ }
+
+ } else if(message->media.type == tgl_message_media_unsupported) {
+
+ if (temp_media_id) {
+ free(temp_media_id);
+ }
+
+ } else if(message->media.type == tgl_message_media_photo_encr) {
+
+ if (temp_media_id) {
+ message->media.encr_photo.id = strtoll(temp_media_id, &eptr, 10);
+ free(temp_media_id);
+ }
+
+ } else if(message->media.type == tgl_message_media_document_encr) {
+
+ if (temp_media_id) {
+ message->media.encr_document.id = strtoll(temp_media_id, &eptr, 10);
+ free(temp_media_id);
+ }
+
+ } else {
+ if (temp_media_id) {
+ free(temp_media_id);
+ }
+ }
+ int *temp_unique_id = (int*)eina_list_nth(ts_msg, 15);
+ if (temp_unique_id) {
+ free(temp_unique_id);
+ }
+ }
+ return message;
+}
+
+void insert_msg_into_db(struct tgl_message *M, char* table_name, int unique_id)
+{
+ if(!M) {
+ return;
+ }
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FLAGS);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_FROM_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_DATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FROM_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_TO_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_OUT_MSG);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNREAD);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_DATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_SERVICE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_STATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_LENGTH);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_TYPE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNIQUE_ID);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, &(M->id));
+ col_values = eina_list_append(col_values, &(M->flags));
+ col_values = eina_list_append(col_values, &(M->fwd_from_id.id));
+ col_values = eina_list_append(col_values, &(M->fwd_date));
+ col_values = eina_list_append(col_values, &(M->from_id.id));
+ col_values = eina_list_append(col_values, &(M->to_id.id));
+ col_values = eina_list_append(col_values, &(M->out));
+ col_values = eina_list_append(col_values, &(M->unread));
+ col_values = eina_list_append(col_values, &(M->date));
+ col_values = eina_list_append(col_values, &(M->service));
+
+ if(M->message)
+ col_values = eina_list_append(col_values, M->message);
+ else
+ col_values = eina_list_append(col_values, "");
+
+ col_values = eina_list_append(col_values, &(M->msg_state));
+ col_values = eina_list_append(col_values, &(M->message_len));
+ col_values = eina_list_append(col_values, &(M->media.type));
+
+ char *dummy_val = "";
+ if(M->media.type == tgl_message_media_none) {
+ col_values = eina_list_append(col_values, (dummy_val));
+ } else if(M->media.type == tgl_message_media_photo) {
+
+ char temp_media_id[50];
+ sprintf(temp_media_id, "%lld", M->media.photo.id);
+
+ col_values = eina_list_append(col_values, temp_media_id);
+ } else if(M->media.type == tgl_message_media_document) {
+
+ char temp_media_id[50];
+ sprintf(temp_media_id, "%lld", M->media.document.id);
+
+ col_values = eina_list_append(col_values, temp_media_id);
+ } else if(M->media.type == tgl_message_media_geo) {
+ char temp_media_id[50];
+ sprintf(temp_media_id, "%lld", M->media.document.id);
+ col_values = eina_list_append(col_values, temp_media_id);
+ } else if(M->media.type == tgl_message_media_contact) {
+
+ char temp_media_id[50];
+ sprintf(temp_media_id, "%d",M->media.user_id);
+
+ col_values = eina_list_append(col_values, temp_media_id);
+ } else if(M->media.type == tgl_message_media_unsupported) {
+ col_values = eina_list_append(col_values, (dummy_val));
+ } else if(M->media.type == tgl_message_media_photo_encr) {
+
+ char temp_media_id[50];
+ sprintf(temp_media_id, "%lld",M->media.encr_photo.id);
+
+ col_values = eina_list_append(col_values, temp_media_id);
+ } else if(M->media.type == tgl_message_media_document_encr) {
+
+ char temp_media_id[50];
+ sprintf(temp_media_id, "%lld",M->media.encr_document.id);
+
+ col_values = eina_list_append(col_values, temp_media_id);
+ } else {
+ col_values = eina_list_append(col_values, (dummy_val));
+ }
+
+ col_values = eina_list_append(col_values, &unique_id);
+
+ Eina_Bool ret = insert_table(table_name, col_names, col_types,col_values);
+ if(!ret) {
+ //("error: database creation failed");
+ } else {
+
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+
+}
+
+void update_msg_into_db(struct tgl_message *M, char* table_name, int unique_id)
+{
+ if(!M) {
+ return;
+ }
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FLAGS);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_FROM_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_DATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FROM_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_TO_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_OUT_MSG);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNREAD);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_DATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_SERVICE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_STATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_LENGTH);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_TYPE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_ID);
+ if (unique_id != -1) {
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNIQUE_ID);
+ }
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ if (unique_id != -1) {
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ }
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, &(M->id));
+ col_values = eina_list_append(col_values, &(M->flags));
+ col_values = eina_list_append(col_values, &(M->fwd_from_id.id));
+ col_values = eina_list_append(col_values, &(M->fwd_date));
+ col_values = eina_list_append(col_values, &(M->from_id.id));
+ col_values = eina_list_append(col_values, &(M->to_id.id));
+ col_values = eina_list_append(col_values, &(M->out));
+ col_values = eina_list_append(col_values, &(M->unread));
+ col_values = eina_list_append(col_values, &(M->date));
+ col_values = eina_list_append(col_values, &(M->service));
+
+ if(M->message)
+ col_values = eina_list_append(col_values, M->message);
+ else
+ col_values = eina_list_append(col_values, " ");
+
+ col_values = eina_list_append(col_values, &(M->msg_state));
+ col_values = eina_list_append(col_values, &(M->message_len));
+ col_values = eina_list_append(col_values, &(M->media.type));
+
+ char *dummy_val = "";
+ if(M->media.type == tgl_message_media_none) {
+ col_values = eina_list_append(col_values, (dummy_val));
+ } else if(M->media.type == tgl_message_media_photo) {
+
+ char temp_media_id[50];
+ sprintf(temp_media_id, "%lld", M->media.photo.id);
+
+ col_values = eina_list_append(col_values, temp_media_id);
+ } else if(M->media.type == tgl_message_media_document) {
+
+ char temp_media_id[50];
+ sprintf(temp_media_id, "%lld", M->media.document.id);
+ col_values = eina_list_append(col_values, temp_media_id);
+
+ } else if(M->media.type == tgl_message_media_geo) {
+ col_values = eina_list_append(col_values, (dummy_val));
+ } else if(M->media.type == tgl_message_media_contact) {
+
+ char temp_media_id[50];
+ sprintf(temp_media_id, "%d",M->media.user_id);
+
+ col_values = eina_list_append(col_values, temp_media_id);
+ } else if(M->media.type == tgl_message_media_unsupported) {
+ col_values = eina_list_append(col_values, (dummy_val));
+ } else if(M->media.type == tgl_message_media_photo_encr) {
+
+ char temp_media_id[50];
+ sprintf(temp_media_id, "%lld",M->media.encr_photo.id);
+
+ col_values = eina_list_append(col_values, temp_media_id);
+ } else if(M->media.type == tgl_message_media_document_encr) {
+
+ char temp_media_id[50];
+ sprintf(temp_media_id, "%lld",M->media.document.id);
+
+ col_values = eina_list_append(col_values, temp_media_id);
+ } else {
+ col_values = eina_list_append(col_values, (dummy_val));
+ }
+
+ if (unique_id != -1) {
+ int u_id = unique_id;
+ col_values = eina_list_append(col_values, &u_id);
+ }
+
+
+ char *where_clause = NULL;
+
+ if (unique_id > 0) {
+
+ char usr_str[50];
+ sprintf(usr_str,"%d",unique_id);
+ where_clause = (char*)malloc(strlen(MESSAGE_INFO_TABLE_UNIQUE_ID) + strlen(" = ") + strlen(usr_str) + 1);
+ strcpy(where_clause, MESSAGE_INFO_TABLE_UNIQUE_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, usr_str);
+
+ } else {
+
+ char usr_str[50];
+ sprintf(usr_str,"%lld", M->id);
+ where_clause = (char *)malloc(strlen(MESSAGE_INFO_TABLE_MESSAGE_ID) + strlen(" = ") + strlen(usr_str) + 1);
+ strcpy(where_clause, MESSAGE_INFO_TABLE_MESSAGE_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, usr_str);
+
+ }
+
+ Eina_Bool ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+
+ if(!ret) {
+ //("error: database creation failed");
+ } else {
+
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+}
+
+Eina_List* get_registered_user_info()
+{
+ Eina_List* user_details = NULL;
+
+ char* table_name = USER_INFO_TABLE_NAME;
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_STRUCTURE_VERSION);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHONE_NO);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ACCESS_HASH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ONLINE_STATUS);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_SEEN_TIME);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ user_details = get_values_from_table_sync(table_name, col_names, col_types, NULL);
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ return user_details;
+}
+
+Eina_Bool is_chat_id_already_exists(struct tgl_chat *chat_info)
+{
+ // get chat name chat id from chat_info_table
+
+ char* table_name = CHAT_INFO_TABLE_NAME;
+
+ int chat_id = chat_info->id.id;
+ char chat_str[50];
+ sprintf(chat_str,"%d",chat_id);
+
+ char* where_clause = (char*)malloc(strlen(CHAT_INFO_TABLE_CHAT_ID) + strlen(" = ") + strlen(chat_str));
+ strcpy(where_clause, CHAT_INFO_TABLE_CHAT_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, chat_str);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_TITLE);
+
+ Eina_List* vals = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+
+ char* chat_name = NULL;
+
+ if(!vals) {
+ //("DB error");
+ return EINA_FALSE;
+ } else {
+ int row_count = eina_list_count(vals);
+
+ for (int i = 0 ; i < row_count ; i++) {
+ Eina_List* row_vals = eina_list_nth(vals, i);
+ chat_name = (char*)eina_list_nth(row_vals, 0);
+ if(!chat_name) {
+ //("DB Error");
+ return EINA_FALSE;
+ } else {
+ break;
+ }
+ eina_list_free(row_vals);
+ }
+ eina_list_free(vals);
+ }
+
+ if(chat_name) {
+ free(chat_name);
+ return EINA_TRUE;
+ }
+
+ return EINA_FALSE;
+}
+
+void insert_buddy_into_db(char* table_name, struct tgl_user* U)
+{
+ if(!U) {
+ return;
+ }
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_STRUCTURE_VERSION);
+ //col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHONE_NO);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ACCESS_HASH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ONLINE_STATUS);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_SEEN_TIME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_BLOCKED);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ //col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, &(U->id.id));
+ if(U->print_name)
+ col_values = eina_list_append(col_values, U->print_name);
+ else
+ col_values = eina_list_append(col_values, "");
+
+ col_values = eina_list_append(col_values, &(U->structure_version));
+ //col_values = eina_list_append(col_values, "");
+ col_values = eina_list_append(col_values, &(U->photo_id));
+
+ if(U->first_name)
+ col_values = eina_list_append(col_values, U->first_name);
+ else
+ col_values = eina_list_append(col_values, "");
+ if(U->last_name)
+ col_values = eina_list_append(col_values, U->last_name);
+ else
+ col_values = eina_list_append(col_values, "");
+
+ if(U->phone)
+ col_values = eina_list_append(col_values, U->phone);
+ else
+ col_values = eina_list_append(col_values, "");
+
+ col_values = eina_list_append(col_values, &(U->access_hash));
+
+ if(U->real_first_name)
+ col_values = eina_list_append(col_values, U->real_first_name);
+ else
+ col_values = eina_list_append(col_values, "");
+
+ if(U->real_last_name)
+ col_values = eina_list_append(col_values, U->real_last_name);
+ else
+ col_values = eina_list_append(col_values, "");
+
+ if(U->username)
+ col_values = eina_list_append(col_values, U->username);
+ else
+ col_values = eina_list_append(col_values, "");
+
+ col_values = eina_list_append(col_values, &(U->status.online));
+ col_values = eina_list_append(col_values, &(U->status.when));
+ col_values = eina_list_append(col_values, &(U->blocked));
+
+ Eina_Bool ret = insert_table(table_name, col_names, col_types,col_values);
+ if(!ret) {
+ // already exist. So update the table
+ char* where_clause = NULL;
+ char user_id_str[50];
+ sprintf(user_id_str,"%d",U->id.id);
+ where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(user_id_str) + 1);
+ strcpy(where_clause, USER_INFO_TABLE_USER_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, user_id_str);
+ ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+ } else {
+ // successfully inserted.
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+
+}
+
+void insert_chat_info_to_db(struct tgl_chat *chat_info, char* photo_path)
+{
+ if (!chat_info) {
+ return;
+ }
+ char* table_name = CHAT_INFO_TABLE_NAME;
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_CHAT_ID);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_FLAGS);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_PRINT_TITLE);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_STRUCT_VERSION);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_PHOTO_ID);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_TITLE);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_NO_OF_USERS);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_USER_LIST_SIZE);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_USER_LIST_VERSION);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_INVITER_ID);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_CHAT_USERS);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_DATE);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_VERSION);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_ADMIN_ID);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, &(chat_info->id.id));
+ col_values = eina_list_append(col_values, &(chat_info->flags));
+
+ if(chat_info->print_title)
+ col_values = eina_list_append(col_values, chat_info->print_title);
+ else
+ col_values = eina_list_append(col_values, "");
+
+ col_values = eina_list_append(col_values, &(chat_info->structure_version));
+
+ long long photo_id = chat_info->photo.id;
+
+ char photo_id_str[50];
+ sprintf(photo_id_str, "%lld", photo_id);
+ col_values = eina_list_append(col_values, photo_id_str);
+
+ if (photo_path) {
+ col_values = eina_list_append(col_values, photo_path);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ if(chat_info->title)
+ col_values = eina_list_append(col_values, chat_info->title);
+ else
+ col_values = eina_list_append(col_values, "");
+
+ col_values = eina_list_append(col_values, &(chat_info->users_num));
+ col_values = eina_list_append(col_values, &(chat_info->user_list_size));
+ col_values = eina_list_append(col_values, &(chat_info->user_list_version));
+
+ int inventor_id = 0;
+ if (chat_info->user_list) {
+ inventor_id = chat_info->user_list[0].inviter_id;
+ }
+
+ col_values = eina_list_append(col_values, &(inventor_id));
+
+ /****** add chat users list ********/
+ char* full_ids = NULL;
+ if (chat_info->user_list) {
+ char* chat_user_ids[chat_info->user_list_size];
+ int total_len = 0;
+ for (int i = 0; i < chat_info->user_list_size; i++) {
+ char temp_user_id[15];
+ int temp_id = chat_info->user_list[i].user_id;
+ sprintf(temp_user_id,"%d",temp_id);
+ chat_user_ids[i] = (char*)malloc(strlen(temp_user_id) + 1);
+ strcpy(chat_user_ids[i], temp_user_id);
+ total_len = total_len + strlen(temp_user_id);
+ total_len = total_len + 1; // delimitor
+ }
+
+ full_ids = (char*)malloc(total_len);
+ for (int i = 0; i < chat_info->user_list_size; i++) {
+ if (i == 0) {
+ strcpy(full_ids, chat_user_ids[i]);
+ } else {
+ strcat(full_ids, chat_user_ids[i]);
+ }
+ if (i < chat_info->user_list_size - 1) {
+ strcat(full_ids, ",");
+ }
+ free(chat_user_ids[i]);
+ }
+ } else {
+ full_ids = (char*)malloc(2);
+ strcpy(full_ids, " ");
+ }
+
+ col_values = eina_list_append(col_values, full_ids);
+ /****** add chat users list ********/
+
+ col_values = eina_list_append(col_values, &(chat_info->date));
+ col_values = eina_list_append(col_values, &(chat_info->version));
+ col_values = eina_list_append(col_values, &(chat_info->admin_id));
+
+ Eina_Bool ret = insert_table(table_name, col_names, col_types,col_values);
+ if(!ret) {
+ // already exist. So update the table
+ char* where_clause = NULL;
+ char chat_id_str[50];
+ sprintf(chat_id_str,"%d", chat_info->id.id);
+ where_clause = (char*)malloc(strlen(CHAT_INFO_TABLE_CHAT_ID) + strlen(" = ") + strlen(chat_id_str) + 1);
+ strcpy(where_clause, CHAT_INFO_TABLE_CHAT_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, chat_id_str);
+ ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+ } else {
+
+ }
+ free(full_ids);
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+}
+
+Eina_Bool update_chat_info_to_db(struct tgl_chat *chat_info, char* photo_path)
+{
+ if (!chat_info || !photo_path) {
+ return EINA_FALSE;
+ }
+
+#if 0
+ char* table_name = CHAT_INFO_TABLE_NAME;
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_CHAT_ID);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_FLAGS);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_PRINT_TITLE);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_STRUCT_VERSION);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_PHOTO_ID);
+ if (photo_path) {
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_PHOTO_PATH);
+ }
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_TITLE);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_NO_OF_USERS);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_USER_LIST_SIZE);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_USER_LIST_VERSION);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_INVITER_ID);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_CHAT_USERS);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_DATE);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_VERSION);
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_ADMIN_ID);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ if (photo_path) {
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ }
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, &(chat_info->id.id));
+ col_values = eina_list_append(col_values, &(chat_info->flags));
+
+ if(chat_info->print_title)
+ col_values = eina_list_append(col_values, chat_info->print_title);
+ else
+ col_values = eina_list_append(col_values, "");
+
+ col_values = eina_list_append(col_values, &(chat_info->structure_version));
+
+ long long photo_id = chat_info->photo.id;
+
+ char photo_id_str[50];
+ sprintf(photo_id_str, "%lld", photo_id);
+ col_values = eina_list_append(col_values, photo_id_str);
+
+ if (photo_path) {
+ col_values = eina_list_append(col_values, photo_path);
+ }
+
+ if(chat_info->title)
+ col_values = eina_list_append(col_values, chat_info->title);
+ else
+ col_values = eina_list_append(col_values, "");
+
+ col_values = eina_list_append(col_values, &(chat_info->users_num));
+ col_values = eina_list_append(col_values, &(chat_info->user_list_size));
+ col_values = eina_list_append(col_values, &(chat_info->user_list_version));
+
+ int inventor_id = 0;
+ if (chat_info->user_list) {
+ inventor_id = chat_info->user_list[0].inviter_id;
+ }
+
+ col_values = eina_list_append(col_values, &(inventor_id));
+
+ /****** add chat users list ********/
+ char* full_ids = NULL;
+ if (chat_info->user_list) {
+ char* chat_user_ids[chat_info->user_list_size];
+ int total_len = 0;
+ for (int i = 0; i < chat_info->user_list_size; i++) {
+ char temp_user_id[15];
+ int temp_id = chat_info->user_list[i].user_id;
+ sprintf(temp_user_id,"%d",temp_id);
+ chat_user_ids[i] = (char*)malloc(strlen(temp_user_id) + 1);
+ strcpy(chat_user_ids[i], temp_user_id);
+ total_len = total_len + strlen(temp_user_id);
+ total_len = total_len + 1; // delimitor
+ }
+
+ full_ids = (char*)malloc(total_len);
+ for (int i = 0; i < chat_info->user_list_size; i++) {
+ if (i == 0) {
+ strcpy(full_ids, chat_user_ids[i]);
+ } else {
+ strcat(full_ids, chat_user_ids[i]);
+ }
+ if (i < chat_info->user_list_size - 1) {
+ strcat(full_ids, ",");
+ }
+ }
+ } else {
+ full_ids = (char*)malloc(2);
+ strcpy(full_ids, " ");
+ }
+
+ col_values = eina_list_append(col_values, full_ids);
+ /****** add chat users list ********/
+
+ col_values = eina_list_append(col_values, &(chat_info->date));
+ col_values = eina_list_append(col_values, &(chat_info->version));
+ col_values = eina_list_append(col_values, &(chat_info->admin_id));
+
+ char* where_clause = NULL;
+
+ char chat_id_str[50];
+ sprintf(chat_id_str,"%d",chat_info->id.id);
+ where_clause = (char*)malloc(strlen(CHAT_INFO_TABLE_CHAT_ID) + strlen(" = ") + strlen(chat_id_str) + 1);
+ strcpy(where_clause, CHAT_INFO_TABLE_CHAT_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, chat_id_str);
+
+ Eina_Bool ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+
+ if(!ret) {
+ // error handling
+ } else {
+
+ }
+
+ free(full_ids);
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+#else
+ char* table_name = CHAT_INFO_TABLE_NAME;
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_PHOTO_PATH);
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, photo_path);
+
+
+ char chat_id_str[50];
+ sprintf(chat_id_str,"%d",chat_info->id.id);
+ char* where_clause = (char*)malloc(strlen(CHAT_INFO_TABLE_CHAT_ID) + strlen(" = ") + strlen(chat_id_str) + 1);
+ strcpy(where_clause, CHAT_INFO_TABLE_CHAT_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, chat_id_str);
+
+ Eina_Bool ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+ free(where_clause);
+ if(!ret) {
+ return EINA_FALSE;
+ }
+ return EINA_TRUE;
+
+#endif
+}
+
+void update_buddy_pic_db(char* file_path, char* table_name, int id)
+{
+ if (!file_path || !table_name) {
+ return;
+ }
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, file_path);
+
+ char* where_clause = NULL;
+
+ char usr_str[50];
+ sprintf(usr_str,"%d",id);
+ where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(usr_str) + 1);
+ strcpy(where_clause, USER_INFO_TABLE_USER_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, usr_str);
+
+ Eina_Bool ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+
+ if(!ret) {
+ // error handling
+ } else {
+
+ }
+ free(where_clause);
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+}
+
+void update_buddy_block_db(char* table_name, int id, int block)
+{
+ if (!table_name) {
+ return;
+ }
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_BLOCKED);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, &block);
+
+ char* where_clause = NULL;
+
+ char usr_str[50];
+ sprintf(usr_str,"%d",id);
+ where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(usr_str) + 1);
+ strcpy(where_clause, USER_INFO_TABLE_USER_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, usr_str);
+
+ Eina_Bool ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+
+ if(!ret) {
+ // error handling
+ } else {
+
+ }
+ free(where_clause);
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+}
+
+void update_buddy_delete_db(char* table_name, int id, int delete_item)
+{
+ if (!table_name) {
+ return;
+ }
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_IS_DELETED);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, &delete_item);
+
+ char* where_clause = NULL;
+
+ char usr_str[50];
+ sprintf(usr_str,"%d",id);
+ where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(usr_str) + 1);
+ strcpy(where_clause, USER_INFO_TABLE_USER_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, usr_str);
+
+ Eina_Bool ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+
+ if(!ret) {
+ // error handling
+ } else {
+
+ }
+ free(where_clause);
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+}
+
+
+Eina_List* get_buddy_info(int buddy_id)
+{
+ Eina_List* user_details = NULL;
+
+ char* table_name = BUDDY_INFO_TABLE_NAME;
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_STRUCTURE_VERSION);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_PATH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHOTO_ID);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHONE_NO);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ACCESS_HASH);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_REAL_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_USER_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_ONLINE_STATUS);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_SEEN_TIME);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ char buddy_id_str[50];
+ sprintf(buddy_id_str, "%d", buddy_id);
+
+ char* where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(buddy_id_str) + 1);
+ strcpy(where_clause, USER_INFO_TABLE_USER_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, buddy_id_str);
+
+ user_details = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+ free(where_clause);
+
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+
+ return user_details;
+}
+
+void update_receive_media_info_in_db(long long media_id, char* file_path)
+{
+ if(!file_path) {
+ return;
+ }
+ char* table_name = MEDIA_INFO_TABLE_NAME;
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FILE_PATH);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, file_path);
+
+ char media_id_str[50];
+ sprintf(media_id_str, "%lld", media_id);
+
+ char* where_clause = (char*)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = '") + strlen(media_id_str) + strlen("'") + 1);
+ strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID);
+ strcat(where_clause, " = '");
+ strcat(where_clause, media_id_str);
+ strcat(where_clause, "'");
+
+ Eina_Bool ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+
+ if(!ret) {
+ // error handling
+ } else {
+
+ }
+ free(where_clause);
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+
+}
+
+void insert_media_info_to_db(struct tgl_message *M, char* file_path)
+{
+ if(!M) {
+ return;
+ }
+
+ char* table_name = MEDIA_INFO_TABLE_NAME;
+
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_ID);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_ACCESS_HASH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_USER_ID);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DATE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_CAPTION);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LONGITUDE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LATITUDE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_SIZES_NUM);
+
+
+ /********************************************************************/
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA1);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA2);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA3);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA4);
+
+
+ /********************************************************************/
+
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHONE_NO);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LAST_NAME);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FILE_PATH);
+
+ /****************************NEW****************************************/
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MIME_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_WIDTH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_HEIGHT);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DURATION);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_SIZE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DC);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE);
+
+ /****************************NEW****************************************/
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ /****************************NEW****************************************/
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ /****************************NEW****************************************/
+
+ Eina_List* col_values = NULL;
+
+ int media_type = M->media.type;
+ char access_hash_str[256] = {'\0'};
+ char photo_id_str[256] = {'\0'};
+ char doc_id_str[256] = {'\0'};
+ if (media_type == tgl_message_media_photo) {
+
+ sprintf(photo_id_str, "%lld", M->media.photo.id);
+
+ col_values = eina_list_append(col_values, photo_id_str);
+ col_values = eina_list_append(col_values, &(media_type));
+
+
+
+ sprintf(access_hash_str, "%lld", M->media.photo.access_hash);
+
+ col_values = eina_list_append(col_values, access_hash_str);
+ col_values = eina_list_append(col_values, &(M->media.photo.user_id));
+ col_values = eina_list_append(col_values, &(M->media.photo.date));
+
+ if(M->media.photo.caption)
+ col_values = eina_list_append(col_values, M->media.photo.caption);
+ else
+ col_values = eina_list_append(col_values, "");
+
+ double longitude = M->media.photo.geo.longitude;
+ double latitude = M->media.photo.geo.latitude;
+
+ char long_str[50];
+ sprintf(long_str,"%lf",longitude);
+
+ char lat_str[50];
+ sprintf(lat_str,"%lf",latitude);
+
+ col_values = eina_list_append(col_values, long_str);
+ col_values = eina_list_append(col_values, long_str);
+ col_values = eina_list_append(col_values, &(M->media.photo.sizes_num));
+
+
+ int i = 0;
+ for (i = 0; i < M->media.photo.sizes_num; i++) {
+ //struct tgl_photo_size photo_size = M->media.photo->sizes[i];
+
+ char* photo_type = M->media.photo.sizes[i].type;
+ if(photo_type) {
+ col_values = eina_list_append(col_values, photo_type);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ int photo_loc_dc = M->media.photo.sizes[i].loc.dc;
+ col_values = eina_list_append(col_values, &photo_loc_dc);
+
+
+
+ char photo_loc_vol_str[50];
+ sprintf(photo_loc_vol_str, "%lld", M->media.photo.sizes[i].loc.volume);
+
+ col_values = eina_list_append(col_values, photo_loc_vol_str);
+
+ int photo_loc_id = M->media.photo.sizes[i].loc.local_id;
+ col_values = eina_list_append(col_values, &photo_loc_id);
+
+
+ char photo_loc_sec_str[50];
+ sprintf(photo_loc_sec_str, "%lld", M->media.photo.sizes[i].loc.secret);
+
+ col_values = eina_list_append(col_values, photo_loc_sec_str);
+
+ int photo_width = M->media.photo.sizes[i].w;
+ col_values = eina_list_append(col_values, &photo_width);
+
+ int photo_height = M->media.photo.sizes[i].h;
+ col_values = eina_list_append(col_values, &photo_height);
+
+ int pic_size = M->media.photo.sizes[i].size;
+ col_values = eina_list_append(col_values, &pic_size);
+
+ char* photo_data = M->media.photo.sizes[i].data;
+ if (photo_data) {
+ col_values = eina_list_append(col_values, photo_data);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+ }
+
+ int j = i;
+ for (j = i; j < 4; j++) {
+
+ char* photo_type = "";
+ col_values = eina_list_append(col_values, photo_type);
+
+ int photo_loc_dc = -1;
+ col_values = eina_list_append(col_values, &photo_loc_dc);
+
+ col_values = eina_list_append(col_values, "");
+
+ int photo_loc_id = -1;
+ col_values = eina_list_append(col_values, &photo_loc_id);
+
+
+ col_values = eina_list_append(col_values, "");
+
+ int photo_width = -1;
+ col_values = eina_list_append(col_values, &photo_width);
+
+ int photo_height = -1;
+ col_values = eina_list_append(col_values, &photo_height);
+
+ int photo_size = -1;
+ col_values = eina_list_append(col_values, &photo_size);
+
+ char* photo_data = "";
+ col_values = eina_list_append(col_values, photo_data);
+
+ }
+
+
+ } else if (media_type == tgl_message_media_document) {
+
+
+ sprintf(doc_id_str, "%lld", M->media.document.id);
+
+ col_values = eina_list_append(col_values, doc_id_str);
+ col_values = eina_list_append(col_values, &(media_type));
+
+
+
+ sprintf(access_hash_str, "%lld", M->media.document.access_hash);
+
+ col_values = eina_list_append(col_values, access_hash_str);
+
+ col_values = eina_list_append(col_values, &(M->media.document.user_id));
+ col_values = eina_list_append(col_values, &(M->media.document.date));
+
+ if(M->media.document.caption)
+ col_values = eina_list_append(col_values, M->media.document.caption);
+ else
+ col_values = eina_list_append(col_values, "");
+
+
+ double longitude = M->media.geo.longitude;
+ double latitude = M->media.geo.latitude;
+
+ char long_str[50];
+ sprintf(long_str,"%lf",longitude);
+
+ char lat_str[50];
+ sprintf(lat_str,"%lf",latitude);
+
+ col_values = eina_list_append(col_values, long_str);
+ col_values = eina_list_append(col_values, long_str);
+ col_values = eina_list_append(col_values, &(M->media.document.size));
+
+ char* photo_type = M->media.document.thumb.type;
+ if(photo_type) {
+ col_values = eina_list_append(col_values, photo_type);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ int photo_loc_dc = M->media.document.thumb.loc.dc;
+ col_values = eina_list_append(col_values, &photo_loc_dc);
+
+
+
+ char photo_loc_vol_str[50];
+ sprintf(photo_loc_vol_str, "%lld", M->media.document.thumb.loc.volume);
+
+ col_values = eina_list_append(col_values, photo_loc_vol_str);
+
+ int photo_loc_id = M->media.document.thumb.loc.local_id;
+ col_values = eina_list_append(col_values, &photo_loc_id);
+
+
+ char photo_loc_sec_str[50];
+ sprintf(photo_loc_sec_str, "%lld", M->media.document.thumb.loc.secret);
+
+ col_values = eina_list_append(col_values, photo_loc_sec_str);
+
+ int photo_width = M->media.document.thumb.w;
+ col_values = eina_list_append(col_values, &photo_width);
+
+ int photo_height = M->media.document.thumb.h;
+ col_values = eina_list_append(col_values, &photo_height);
+
+ int pic_size = M->media.document.thumb.size;
+ col_values = eina_list_append(col_values, &pic_size);
+
+ char* photo_data = M->media.document.thumb.data;
+ if (photo_data) {
+ col_values = eina_list_append(col_values, photo_data);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+
+ for (int j = 1; j < 4; j++) {
+
+ char* photo_type = "";
+ col_values = eina_list_append(col_values, photo_type);
+
+ int photo_loc_dc = -1;
+ col_values = eina_list_append(col_values, &photo_loc_dc);
+
+ col_values = eina_list_append(col_values, "");
+
+ int photo_loc_id = -1;
+ col_values = eina_list_append(col_values, &photo_loc_id);
+
+
+ col_values = eina_list_append(col_values, "");
+
+ int photo_width = -1;
+ col_values = eina_list_append(col_values, &photo_width);
+
+ int photo_height = -1;
+ col_values = eina_list_append(col_values, &photo_height);
+
+ int photo_size = -1;
+ col_values = eina_list_append(col_values, &photo_size);
+
+ char* photo_data = "";
+ col_values = eina_list_append(col_values, photo_data);
+
+ }
+ } else if (media_type == tgl_message_media_geo) {
+ // To be checked
+ int dummy = 0;
+ //col_values = eina_list_append(col_values, &(dummy));
+ char doc_id_str[256];
+ snprintf(doc_id_str, sizeof(doc_id_str), "%lld", M->media.document.id);
+ col_values = eina_list_append(col_values, doc_id_str);
+ col_values = eina_list_append(col_values, &(media_type));
+ col_values = eina_list_append(col_values, &(dummy));
+ col_values = eina_list_append(col_values, &(dummy));
+ col_values = eina_list_append(col_values, &(dummy));
+
+ col_values = eina_list_append(col_values, "");
+
+
+ char long_str[50];
+ sprintf(long_str,"%2.15f",M->media.geo.longitude);
+
+ char lat_str[50];
+ sprintf(lat_str,"%2.15f",M->media.geo.latitude);
+
+ col_values = eina_list_append(col_values, long_str);
+ col_values = eina_list_append(col_values, long_str);
+ col_values = eina_list_append(col_values, &(dummy));
+
+ for (int j = 0; j < 4; j++) {
+
+ char* photo_type = strdup(" ");
+ int *photo_loc_dc = malloc(sizeof(*photo_loc_dc));
+ int *photo_loc_vol = malloc(sizeof(*photo_loc_vol));
+ int *photo_loc_id = malloc(sizeof(*photo_loc_id));
+ int *photo_width = malloc(sizeof(*photo_width));
+ int *photo_height = malloc(sizeof(*photo_height));
+ int *photo_size = malloc(sizeof(*photo_size));
+ char* photo_data = strdup(" ");
+
+ *photo_loc_dc = -1;
+ *photo_loc_vol = -1;
+ *photo_loc_id = -1;
+ *photo_width = -1;
+ *photo_height = -1;
+ *photo_size = -1;
+
+ col_values = eina_list_append(col_values, photo_type);
+ col_values = eina_list_append(col_values, photo_loc_dc);
+ col_values = eina_list_append(col_values, strdup(" "));
+ col_values = eina_list_append(col_values, photo_loc_id);
+ col_values = eina_list_append(col_values, strdup(" "));
+ col_values = eina_list_append(col_values, photo_width);
+ col_values = eina_list_append(col_values, photo_height);
+ col_values = eina_list_append(col_values, photo_size);
+ col_values = eina_list_append(col_values, photo_data);
+ }
+ } else {
+ // To be checked
+ int dummy = 0;
+ //col_values = eina_list_append(col_values, &(dummy));
+ char default_id_str[256];
+ int default_id = time(NULL);
+ snprintf(default_id_str, sizeof(default_id_str), "%d", default_id);
+ col_values = eina_list_append(col_values, &(media_type));
+ col_values = eina_list_append(col_values, &(dummy));
+ col_values = eina_list_append(col_values, &(dummy));
+ col_values = eina_list_append(col_values, &(dummy));
+
+ col_values = eina_list_append(col_values, "");
+
+ double longitude = 0.0f;
+ double latitude = 0.0f;
+
+ char long_str[50];
+ sprintf(long_str,"%lf",longitude);
+
+ char lat_str[50];
+ sprintf(lat_str,"%lf",latitude);
+
+ col_values = eina_list_append(col_values, long_str);
+ col_values = eina_list_append(col_values, long_str);
+ col_values = eina_list_append(col_values, &(dummy));
+
+ for (int j = 0; j < 4; j++) {
+
+ char* photo_type = strdup(" ");
+ int *photo_loc_dc = malloc(sizeof(*photo_loc_dc));
+ int *photo_loc_vol = malloc(sizeof(*photo_loc_vol));
+ int *photo_loc_id = malloc(sizeof(*photo_loc_id));
+ int *photo_width = malloc(sizeof(*photo_width));
+ int *photo_height = malloc(sizeof(*photo_height));
+ int *photo_size = malloc(sizeof(*photo_size));
+ char* photo_data = strdup(" ");
+
+ *photo_loc_dc = -1;
+ *photo_loc_vol = -1;
+ *photo_loc_id = -1;
+ *photo_width = -1;
+ *photo_height = -1;
+ *photo_size = -1;
+
+ col_values = eina_list_append(col_values, photo_type);
+ col_values = eina_list_append(col_values, photo_loc_dc);
+ col_values = eina_list_append(col_values, strdup(" "));
+ col_values = eina_list_append(col_values, photo_loc_id);
+ col_values = eina_list_append(col_values, strdup(" "));
+ col_values = eina_list_append(col_values, photo_width);
+ col_values = eina_list_append(col_values, photo_height);
+ col_values = eina_list_append(col_values, photo_size);
+ col_values = eina_list_append(col_values, photo_data);
+ }
+ }
+
+ if(M->media.phone) {
+ //col_values = eina_list_append(col_values, M->media.phone);
+ col_values = eina_list_append(col_values, "");
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ if(M->media.first_name) {
+ //col_values = eina_list_append(col_values, M->media.first_name);
+ col_values = eina_list_append(col_values, "");
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ if(M->media.last_name) {
+ //col_values = eina_list_append(col_values, M->media.last_name);
+ col_values = eina_list_append(col_values, "");
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ if(file_path) {
+ col_values = eina_list_append(col_values, file_path);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ if (M->media.type == tgl_message_media_document) {
+ if (M->media.document.mime_type) {
+ col_values = eina_list_append(col_values, M->media.document.mime_type);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ char * doc_type = NULL;
+ if (M->media.document.flags & FLAG_DOCUMENT_IMAGE) {
+ doc_type = "image";
+ } else if (M->media.document.flags & FLAG_DOCUMENT_AUDIO) {
+ doc_type = "audio";
+ } else if (M->media.document.flags & FLAG_DOCUMENT_VIDEO) {
+ doc_type = "video";
+ } else if (M->media.document.flags & FLAG_DOCUMENT_STICKER) {
+ doc_type = "sticker";
+ } else {
+ doc_type = "document";
+ }
+ col_values = eina_list_append(col_values, doc_type);
+
+ int doc_width = M->media.document.w;
+ col_values = eina_list_append(col_values, &doc_width);
+
+ int doc_height = M->media.document.h;
+ col_values = eina_list_append(col_values, &doc_height);
+
+ int doc_duration = M->media.document.duration;
+ col_values = eina_list_append(col_values, &doc_duration);
+
+ int doc_size = M->media.document.size;
+ col_values = eina_list_append(col_values, &doc_size);
+
+ int doc_dc = M->media.document.dc_id;
+ col_values = eina_list_append(col_values, &doc_dc);
+
+ } else if (M->media.type == tgl_message_media_document_encr) {
+ if (M->media.encr_document.mime_type) {
+ col_values = eina_list_append(col_values, M->media.encr_document.mime_type);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ char * doc_type = NULL;
+ if (M->media.encr_document.flags & FLAG_DOCUMENT_IMAGE) {
+ doc_type = "image";
+ } else if (M->media.encr_document.flags & FLAG_DOCUMENT_AUDIO) {
+ doc_type = "audio";
+ } else if (M->media.encr_document.flags & FLAG_DOCUMENT_VIDEO) {
+ doc_type = "video";
+ } else if (M->media.encr_document.flags & FLAG_DOCUMENT_STICKER) {
+ doc_type = "sticker";
+ } else {
+ doc_type = "document";
+ }
+ col_values = eina_list_append(col_values, doc_type);
+
+ int doc_width = M->media.encr_document.w;
+ col_values = eina_list_append(col_values, &doc_width);
+
+ int doc_height = M->media.encr_document.h;
+ col_values = eina_list_append(col_values, &doc_height);
+
+ int doc_duration = M->media.encr_document.duration;
+ col_values = eina_list_append(col_values, &doc_duration);
+
+ int doc_size = M->media.encr_document.size;
+ col_values = eina_list_append(col_values, &doc_size);
+
+ int doc_dc = M->media.encr_document.dc_id;
+ col_values = eina_list_append(col_values, &doc_dc);
+
+ } else {
+
+ col_values = eina_list_append(col_values, "");
+
+ if (M->media.type == tgl_message_media_photo) {
+ char * doc_type = "image";
+ col_values = eina_list_append(col_values, doc_type);
+ } else {
+ char * doc_type = "none";
+ col_values = eina_list_append(col_values, doc_type);
+ }
+
+ int doc_width = 0;
+ col_values = eina_list_append(col_values, &doc_width);
+
+ int doc_height = 0;
+ col_values = eina_list_append(col_values, &doc_height);
+
+ int doc_duration = 0;
+ col_values = eina_list_append(col_values, &doc_duration);
+
+ int doc_size = 0;
+ col_values = eina_list_append(col_values, &doc_size);
+
+ int doc_dc = 0;
+ col_values = eina_list_append(col_values, &doc_dc);
+ }
+
+ col_values = eina_list_append(col_values, "");
+
+ Eina_Bool ret = insert_table(table_name, col_names, col_types,col_values);
+ if(!ret) {
+ //("error: database creation failed");
+ } else {
+
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+
+}
+
+void update_video_thumb_in_db(long long media_id, char* thumb_file)
+{
+ if (!thumb_file) {
+ return;
+ }
+ char* table_name = MEDIA_INFO_TABLE_NAME;
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ Eina_List* col_values = NULL;
+ col_values = eina_list_append(col_values, thumb_file);
+
+ char usr_str[50];
+ sprintf(usr_str,"%lld",media_id);
+ char *where_clause = (char*)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = '") + strlen(usr_str) + strlen("'") + 1);
+ strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID);
+ strcat(where_clause, " = '");
+ strcat(where_clause, usr_str);
+ strcat(where_clause, "'");
+
+ Eina_Bool ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+
+ if(!ret) {
+ //("error: database creation failed");
+ } else {
+
+ }
+ free(where_clause);
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+}
+
+void update_sent_media_info_in_db(struct tgl_message *M, long long unique_val)
+{
+ if(!M) {
+ return;
+ }
+
+ char* table_name = MEDIA_INFO_TABLE_NAME;
+
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_ID);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_ACCESS_HASH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_USER_ID);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DATE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_CAPTION);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LONGITUDE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LATITUDE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_SIZES_NUM);
+
+
+ /********************************************************************/
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA1);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA2);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA3);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA4);
+
+
+ /********************************************************************/
+
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHONE_NO);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LAST_NAME);
+
+ /****************************NEW****************************************/
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MIME_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_WIDTH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_HEIGHT);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DURATION);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_SIZE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DC);
+ //col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE);
+
+ /****************************NEW****************************************/
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ /****************************NEW****************************************/
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ //col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ /****************************NEW****************************************/
+
+
+ Eina_List* col_values = NULL;
+
+ int media_type = M->media.type;
+
+ if (media_type == tgl_message_media_photo) {
+
+ char photo_id_str[256];
+ sprintf(photo_id_str, "%lld", M->media.photo.id);
+
+ col_values = eina_list_append(col_values, photo_id_str);
+ col_values = eina_list_append(col_values, &(media_type));
+
+
+ char access_hash_str[256];
+ sprintf(access_hash_str, "%lld", M->media.photo.access_hash);
+
+ col_values = eina_list_append(col_values, access_hash_str);
+ col_values = eina_list_append(col_values, &(M->media.photo.user_id));
+ col_values = eina_list_append(col_values, &(M->media.photo.date));
+
+ if(M->media.photo.caption)
+ col_values = eina_list_append(col_values, M->media.photo.caption);
+ else
+ col_values = eina_list_append(col_values, "");
+
+ double longitude = M->media.photo.geo.longitude;
+ double latitude = M->media.photo.geo.latitude;
+
+ char long_str[50];
+ sprintf(long_str,"%lf",longitude);
+
+ char lat_str[50];
+ sprintf(lat_str,"%lf",latitude);
+
+ col_values = eina_list_append(col_values, long_str);
+ col_values = eina_list_append(col_values, long_str);
+
+ if (M->media.photo.sizes_num > 4) {
+ M->media.photo.sizes_num = 4;
+ }
+
+ col_values = eina_list_append(col_values, &(M->media.photo.sizes_num));
+
+
+ int i = 0;
+ for (i = 0; i < M->media.photo.sizes_num; i++) {
+ //struct tgl_photo_size photo_size = M->media.photo->sizes[i];
+
+ char* photo_type = M->media.photo.sizes[i].type;
+ if(photo_type) {
+ col_values = eina_list_append(col_values, photo_type);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ int photo_loc_dc = M->media.photo.sizes[i].loc.dc;
+ col_values = eina_list_append(col_values, &photo_loc_dc);
+
+
+
+ char photo_loc_vol_str[50];
+ sprintf(photo_loc_vol_str, "%lld", M->media.photo.sizes[i].loc.volume);
+
+ col_values = eina_list_append(col_values, photo_loc_vol_str);
+
+ int photo_loc_id = M->media.photo.sizes[i].loc.local_id;
+ col_values = eina_list_append(col_values, &photo_loc_id);
+
+
+ char photo_loc_sec_str[50];
+ sprintf(photo_loc_sec_str, "%lld", M->media.photo.sizes[i].loc.secret);
+
+ col_values = eina_list_append(col_values, photo_loc_sec_str);
+
+ int photo_width = M->media.photo.sizes[i].w;
+ col_values = eina_list_append(col_values, &photo_width);
+
+ int photo_height = M->media.photo.sizes[i].h;
+ col_values = eina_list_append(col_values, &photo_height);
+
+ int pic_size = M->media.photo.sizes[i].size;
+ col_values = eina_list_append(col_values, &pic_size);
+
+ char* photo_data = M->media.photo.sizes[i].data;
+ if (photo_data) {
+ col_values = eina_list_append(col_values, photo_data);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+ }
+
+ int j = i;
+ for (j = i; j < 4; j++) {
+
+ char* photo_type = "";
+ col_values = eina_list_append(col_values, photo_type);
+
+ int photo_loc_dc = -1;
+ col_values = eina_list_append(col_values, &photo_loc_dc);
+
+ col_values = eina_list_append(col_values, "");
+
+ int photo_loc_id = -1;
+ col_values = eina_list_append(col_values, &photo_loc_id);
+
+
+ col_values = eina_list_append(col_values, "");
+
+ int photo_width = -1;
+ col_values = eina_list_append(col_values, &photo_width);
+
+ int photo_height = -1;
+ col_values = eina_list_append(col_values, &photo_height);
+
+ int photo_size = -1;
+ col_values = eina_list_append(col_values, &photo_size);
+
+ char* photo_data = "";
+ col_values = eina_list_append(col_values, photo_data);
+
+ }
+
+
+ } else if (media_type == tgl_message_media_document) {
+
+ char doc_id_str[256];
+ sprintf(doc_id_str, "%lld", M->media.document.id);
+
+ col_values = eina_list_append(col_values, doc_id_str);
+ col_values = eina_list_append(col_values, &(media_type));
+
+ char access_hash_str[256];
+ sprintf(access_hash_str, "%lld", M->media.document.access_hash);
+
+ col_values = eina_list_append(col_values, access_hash_str);
+ col_values = eina_list_append(col_values, &(M->media.document.user_id));
+ col_values = eina_list_append(col_values, &(M->media.document.date));
+
+ if(M->media.document.caption)
+ col_values = eina_list_append(col_values, M->media.document.caption);
+ else
+ col_values = eina_list_append(col_values, "");
+
+
+ double longitude = M->media.geo.longitude;
+ double latitude = M->media.geo.latitude;
+
+ char long_str[50];
+ sprintf(long_str,"%lf",longitude);
+
+ char lat_str[50];
+ sprintf(lat_str,"%lf",latitude);
+
+ col_values = eina_list_append(col_values, long_str);
+ col_values = eina_list_append(col_values, long_str);
+ col_values = eina_list_append(col_values, &(M->media.document.size));
+
+ char* photo_type = M->media.document.thumb.type;
+ if(photo_type) {
+ col_values = eina_list_append(col_values, photo_type);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ int photo_loc_dc = M->media.document.thumb.loc.dc;
+ col_values = eina_list_append(col_values, &photo_loc_dc);
+
+
+
+ char photo_loc_vol_str[50];
+ sprintf(photo_loc_vol_str, "%lld", M->media.document.thumb.loc.volume);
+
+ col_values = eina_list_append(col_values, photo_loc_vol_str);
+
+ int photo_loc_id = M->media.document.thumb.loc.local_id;
+ col_values = eina_list_append(col_values, &photo_loc_id);
+
+
+ char photo_loc_sec_str[50];
+ sprintf(photo_loc_sec_str, "%lld", M->media.document.thumb.loc.secret);
+
+ col_values = eina_list_append(col_values, photo_loc_sec_str);
+
+ int photo_width = M->media.document.thumb.w;
+ col_values = eina_list_append(col_values, &photo_width);
+
+ int photo_height = M->media.document.thumb.h;
+ col_values = eina_list_append(col_values, &photo_height);
+
+ int pic_size = M->media.document.thumb.size;
+ col_values = eina_list_append(col_values, &pic_size);
+
+ char* photo_data = M->media.document.thumb.data;
+ if (photo_data) {
+ col_values = eina_list_append(col_values, photo_data);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+
+ for (int j = 1; j < 4; j++) {
+
+ char* photo_type = "";
+ col_values = eina_list_append(col_values, photo_type);
+
+ int photo_loc_dc = -1;
+ col_values = eina_list_append(col_values, &photo_loc_dc);
+
+ col_values = eina_list_append(col_values, "");
+
+ int photo_loc_id = -1;
+ col_values = eina_list_append(col_values, &photo_loc_id);
+
+
+ col_values = eina_list_append(col_values, "");
+
+ int photo_width = -1;
+ col_values = eina_list_append(col_values, &photo_width);
+
+ int photo_height = -1;
+ col_values = eina_list_append(col_values, &photo_height);
+
+ int photo_size = -1;
+ col_values = eina_list_append(col_values, &photo_size);
+
+ char* photo_data = "";
+ col_values = eina_list_append(col_values, photo_data);
+
+ }
+
+ } else {
+ // To be checked
+ int dummy = 0;
+ col_values = eina_list_append(col_values, &(dummy));
+ col_values = eina_list_append(col_values, &(media_type));
+ col_values = eina_list_append(col_values, &(dummy));
+ col_values = eina_list_append(col_values, &(dummy));
+ col_values = eina_list_append(col_values, &(dummy));
+
+ col_values = eina_list_append(col_values, "");
+
+ double longitude = 0.0f;
+ double latitude = 0.0f;
+
+ char long_str[50];
+ sprintf(long_str,"%lf",longitude);
+
+ char lat_str[50];
+ sprintf(lat_str,"%lf",latitude);
+
+ col_values = eina_list_append(col_values, long_str);
+ col_values = eina_list_append(col_values, long_str);
+ col_values = eina_list_append(col_values, &(dummy));
+
+ for (int j = 0; j < 4; j++) {
+
+ char* photo_type = strdup(" ");
+ int *photo_loc_dc = malloc(sizeof(*photo_loc_dc));
+ int *photo_loc_vol = malloc(sizeof(*photo_loc_vol));
+ int *photo_loc_id = malloc(sizeof(*photo_loc_id));
+ int *photo_width = malloc(sizeof(*photo_width));
+ int *photo_height = malloc(sizeof(*photo_height));
+ int *photo_size = malloc(sizeof(*photo_size));
+ char* photo_data = strdup(" ");
+
+ *photo_loc_dc = -1;
+ *photo_loc_vol = -1;
+ *photo_loc_id = -1;
+ *photo_width = -1;
+ *photo_height = -1;
+ *photo_size = -1;
+
+ col_values = eina_list_append(col_values, photo_type);
+ col_values = eina_list_append(col_values, photo_loc_dc);
+ col_values = eina_list_append(col_values, strdup(" "));
+ col_values = eina_list_append(col_values, photo_loc_id);
+ col_values = eina_list_append(col_values, strdup(" "));
+ col_values = eina_list_append(col_values, photo_width);
+ col_values = eina_list_append(col_values, photo_height);
+ col_values = eina_list_append(col_values, photo_size);
+ col_values = eina_list_append(col_values, photo_data);
+ }
+ }
+
+ if(M->media.phone) {
+ //col_values = eina_list_append(col_values, M->media.phone);
+ col_values = eina_list_append(col_values, "");
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ if(M->media.first_name) {
+ //col_values = eina_list_append(col_values, M->media.first_name);
+ col_values = eina_list_append(col_values, "");
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ if(M->media.last_name) {
+ //col_values = eina_list_append(col_values, M->media.last_name);
+ col_values = eina_list_append(col_values, "");
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+
+ if (M->media.type == tgl_message_media_document) {
+ if (M->media.document.mime_type) {
+ col_values = eina_list_append(col_values, M->media.document.mime_type);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ char * doc_type = NULL;
+ if (M->media.document.flags & FLAG_DOCUMENT_IMAGE) {
+ doc_type = "image";
+ } else if (M->media.document.flags & FLAG_DOCUMENT_AUDIO) {
+ doc_type = "audio";
+ } else if (M->media.document.flags & FLAG_DOCUMENT_VIDEO) {
+ doc_type = "video";
+ } else if (M->media.document.flags & FLAG_DOCUMENT_STICKER) {
+ doc_type = "sticker";
+ } else {
+ doc_type = "document";
+ }
+ col_values = eina_list_append(col_values, doc_type);
+
+ int doc_width = M->media.document.w;
+ col_values = eina_list_append(col_values, &doc_width);
+
+ int doc_height = M->media.document.h;
+ col_values = eina_list_append(col_values, &doc_height);
+
+ int doc_duration = M->media.document.duration;
+ col_values = eina_list_append(col_values, &doc_duration);
+
+ int doc_size = M->media.document.size;
+ col_values = eina_list_append(col_values, &doc_size);
+
+ int doc_dc = M->media.document.dc_id;
+ col_values = eina_list_append(col_values, &doc_dc);
+
+ } else if (M->media.type == tgl_message_media_document_encr) {
+ if (M->media.encr_document.mime_type) {
+ col_values = eina_list_append(col_values, M->media.encr_document.mime_type);
+ } else {
+ col_values = eina_list_append(col_values, "");
+ }
+
+ char * doc_type = NULL;
+ if (M->media.encr_document.flags & FLAG_DOCUMENT_IMAGE) {
+ doc_type = "image";
+ } else if (M->media.encr_document.flags & FLAG_DOCUMENT_AUDIO) {
+ doc_type = "audio";
+ } else if (M->media.encr_document.flags & FLAG_DOCUMENT_VIDEO) {
+ doc_type = "video";
+ } else if (M->media.encr_document.flags & FLAG_DOCUMENT_STICKER) {
+ doc_type = "sticker";
+ } else {
+ doc_type = "document";
+ }
+ col_values = eina_list_append(col_values, doc_type);
+
+ int doc_width = M->media.encr_document.w;
+ col_values = eina_list_append(col_values, &doc_width);
+
+ int doc_height = M->media.encr_document.h;
+ col_values = eina_list_append(col_values, &doc_height);
+
+ int doc_duration = M->media.encr_document.duration;
+ col_values = eina_list_append(col_values, &doc_duration);
+
+ int doc_size = M->media.encr_document.size;
+ col_values = eina_list_append(col_values, &doc_size);
+
+ int doc_dc = M->media.encr_document.dc_id;
+ col_values = eina_list_append(col_values, &doc_dc);
+
+ } else {
+
+ col_values = eina_list_append(col_values, "");
+
+ if (M->media.type == tgl_message_media_photo) {
+ char * doc_type = "image";
+ col_values = eina_list_append(col_values, doc_type);
+ } else {
+ char * doc_type = "none";
+ col_values = eina_list_append(col_values, doc_type);
+ }
+
+ int doc_width = 0;
+ col_values = eina_list_append(col_values, &doc_width);
+
+ int doc_height = 0;
+ col_values = eina_list_append(col_values, &doc_height);
+
+ int doc_duration = 0;
+ col_values = eina_list_append(col_values, &doc_duration);
+
+ int doc_size = 0;
+ col_values = eina_list_append(col_values, &doc_size);
+
+ int doc_dc = M->media.encr_document.dc_id;
+ col_values = eina_list_append(col_values, &doc_dc);
+ }
+
+ //col_values = eina_list_append(col_values, "");
+
+ char* where_clause = NULL;
+ if(unique_val != 0 ) {
+ char usr_str[50];
+ sprintf(usr_str,"%lld",unique_val);
+ where_clause = (char*)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = '") + strlen(usr_str) + strlen("'") + 1);
+ strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID);
+ strcat(where_clause, " = '");
+ strcat(where_clause, usr_str);
+ strcat(where_clause, "'");
+ } else {
+ char usr_str[50];
+ sprintf(usr_str,"%lld",M->media.photo.id);
+ where_clause = (char*)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = '") + strlen(usr_str) + strlen("'") + 1);
+ strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID);
+ strcat(where_clause, " = '");
+ strcat(where_clause, usr_str);
+ strcat(where_clause, "'");
+ }
+
+ Eina_Bool ret = update_table(table_name, col_names, col_types, col_values, where_clause);
+
+ if(!ret) {
+ //("error: database creation failed");
+ } else {
+
+ }
+ free(where_clause);
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ eina_list_free(col_values);
+
+}
+
+struct tgl_media* get_media_details_from_db(long long media_id)
+{
+ Eina_List* img_details = get_image_details_from_db(media_id);
+
+ if (!img_details) {
+ return NULL;
+ }
+
+ struct tgl_media* media_info = (struct tgl_media*)malloc(sizeof(struct tgl_media));
+
+ Eina_List* row_vals = eina_list_nth(img_details, 0);
+
+ char *temp_media_id = (char *)eina_list_nth(row_vals, 0);
+
+ if(temp_media_id) {
+ media_info->media_id = atoll(temp_media_id);
+ free(temp_media_id);
+ } else {
+ media_info->media_id = 0;
+ }
+
+ int* temp_media_type = (int*)eina_list_nth(row_vals, 1);
+
+ if(temp_media_type) {
+ media_info->media_type = *temp_media_type;
+ free(temp_media_type);
+ } else {
+ media_info->media_type = -1;
+ }
+
+ char *temp_access_hash = (char *)eina_list_nth(row_vals, 2);
+
+ if(temp_access_hash) {
+ media_info->access_hash = atoll(temp_access_hash);
+ free(temp_access_hash);
+ } else {
+ media_info->access_hash = 0;
+ }
+
+ int* temp_user_id = (int*)eina_list_nth(row_vals, 3);
+
+ if(temp_user_id) {
+ media_info->user_id = *temp_user_id;
+ free(temp_user_id);
+ } else {
+ media_info->user_id = 0;
+ }
+
+ int* temp_date = (int*)eina_list_nth(row_vals, 4);
+
+ if(temp_date) {
+ media_info->date = *temp_date;
+ free(temp_date);
+ } else {
+ media_info->date = 0;
+ }
+
+ char *temp_caption = (char *)eina_list_nth(row_vals, 5);
+
+ if(temp_caption) {
+ media_info->caption = strdup(temp_caption);
+ free(temp_caption);
+ }
+
+ char *temp_longitude = (char *)eina_list_nth(row_vals, 6);
+
+ if(temp_longitude) {
+ media_info->longitude = strdup(temp_longitude);
+ free(temp_longitude);
+ } else {
+ media_info->longitude = 0;
+ }
+
+ char *temp_latitude = (char *)eina_list_nth(row_vals, 7);
+
+ if(temp_latitude) {
+ media_info->latitude = strdup(temp_latitude);
+ free(temp_latitude);
+ } else {
+ media_info->latitude = 0;
+ }
+
+ int* temp_sizes = (int*)eina_list_nth(row_vals, 8);
+
+ if(temp_sizes) {
+ media_info->sizes = *temp_sizes;
+ free(temp_sizes);
+ } else {
+ media_info->sizes = 0;
+ }
+
+ /***************************************************************/
+
+ char *temp_photo_type1 = (char *)eina_list_nth(row_vals, 9);
+ if (temp_photo_type1 && strlen(temp_photo_type1) > 0) {
+ media_info->photo_type1 =strdup(temp_photo_type1);
+ free(temp_photo_type1);
+ } else {
+ media_info->photo_type1 = 0;
+ }
+
+
+ int* temp_photo_loc_dc1 = (int*)eina_list_nth(row_vals, 10);
+ if (temp_photo_loc_dc1) {
+ media_info->photo_loc_dc1 = *temp_photo_loc_dc1;
+ free(temp_photo_loc_dc1);
+ } else {
+ media_info->photo_loc_dc1 = 0;
+ }
+
+
+ char *temp_photo_loc_vol1 = (char *)eina_list_nth(row_vals, 11);
+ if(temp_photo_loc_vol1 && strlen(temp_photo_loc_vol1) > 0) {
+ media_info->photo_loc_vol1 = atoll(temp_photo_loc_vol1);
+ free(temp_photo_loc_vol1);
+ } else {
+ media_info->photo_loc_vol1 = 0;
+ }
+
+
+ int* temp_photo_loc_id1 = (int*)eina_list_nth(row_vals, 12);
+ if (temp_photo_loc_id1) {
+ media_info->photo_loc_id1 = *temp_photo_loc_id1;
+ free(temp_photo_loc_id1);
+ } else {
+ media_info->photo_loc_id1 = 0;
+ }
+
+ char *temp_photo_loc_sec1 = (char *)eina_list_nth(row_vals, 13);
+ if(temp_photo_loc_sec1 && strlen(temp_photo_loc_sec1) > 0) {
+ media_info->photo_loc_sec1 = atoll(temp_photo_loc_sec1);
+ free(temp_photo_loc_sec1);
+ } else {
+ media_info->photo_loc_sec1 = 0;
+ }
+
+
+ int* temp_photo_width1 = (int*)eina_list_nth(row_vals, 14);
+ if(temp_photo_width1) {
+ media_info->photo_width1 = *temp_photo_width1;
+ free(temp_photo_width1);
+ } else {
+ media_info->photo_width1 = 0;
+ }
+
+
+ int* temp_photo_height1 = (int*)eina_list_nth(row_vals, 15);
+ if(temp_photo_height1) {
+ media_info->photo_height1 = *temp_photo_height1;
+ free(temp_photo_height1);
+ } else {
+ media_info->photo_height1 = 0;
+ }
+
+ int* temp_photo_size1 = (int*)eina_list_nth(row_vals, 16);
+ if(temp_photo_size1) {
+ media_info->photo_size1 = *temp_photo_size1;
+ free(temp_photo_size1);
+ } else {
+ media_info->photo_size1 = 0;
+ }
+
+
+ char *temp_photo_data1 = (char *)eina_list_nth(row_vals, 17);
+ if(temp_photo_data1 && strlen(temp_photo_data1) > 0) {
+ media_info->photo_data1 = strdup(temp_photo_data1);
+ free(temp_photo_data1);
+ } else {
+ media_info->photo_data1 = 0;
+ }
+
+
+ char *temp_photo_type2 = (char *)eina_list_nth(row_vals, 18);
+ if (temp_photo_type2 && strlen(temp_photo_type2) > 0) {
+ media_info->photo_type2 =strdup(temp_photo_type2);
+ free(temp_photo_type2);
+ } else {
+ media_info->photo_type2 = 0;
+ }
+
+
+ int* temp_photo_loc_dc2 = (int*)eina_list_nth(row_vals, 19);
+ if (temp_photo_loc_dc2) {
+ media_info->photo_loc_dc2 = *temp_photo_loc_dc2;
+ free(temp_photo_loc_dc2);
+ } else {
+ media_info->photo_loc_dc2 = 0;
+ }
+
+
+ char *temp_photo_loc_vol2 = (char *)eina_list_nth(row_vals, 20);
+ if(temp_photo_loc_vol2 && strlen(temp_photo_loc_vol2) > 0) {
+ media_info->photo_loc_vol2 = atoll(temp_photo_loc_vol2);
+ free(temp_photo_loc_vol2);
+ } else {
+ media_info->photo_loc_vol2 = 0;
+ }
+
+
+ int* temp_photo_loc_id2 = (int*)eina_list_nth(row_vals, 21);
+ if (temp_photo_loc_id2) {
+ media_info->photo_loc_id2 = *temp_photo_loc_id2;
+ free(temp_photo_loc_id2);
+ } else {
+ media_info->photo_loc_id2 = 0;
+ }
+
+ char *temp_photo_loc_sec2 = (char *)eina_list_nth(row_vals, 22);
+ if(temp_photo_loc_sec2 && strlen(temp_photo_loc_sec2) > 0) {
+ media_info->photo_loc_sec2 = atoll(temp_photo_loc_sec2);
+ free(temp_photo_loc_sec2);
+ } else {
+ media_info->photo_loc_sec2 = 0;
+ }
+
+
+ int* temp_photo_width2 = (int*)eina_list_nth(row_vals, 23);
+ if(temp_photo_width2) {
+ media_info->photo_width2 = *temp_photo_width2;
+ free(temp_photo_width2);
+ } else {
+ media_info->photo_width2 = 0;
+ }
+
+
+ int* temp_photo_height2 = (int*)eina_list_nth(row_vals, 24);
+ if(temp_photo_height2) {
+ media_info->photo_height2 = *temp_photo_height2;
+ free(temp_photo_height2);
+ } else {
+ media_info->photo_height2 = 0;
+ }
+
+ int* temp_photo_size2 = (int*)eina_list_nth(row_vals, 25);
+ if(temp_photo_size2) {
+ media_info->photo_size2 = *temp_photo_size2;
+ free(temp_photo_size2);
+ } else {
+ media_info->photo_size2 = 0;
+ }
+
+
+ char *temp_photo_data2 = (char *)eina_list_nth(row_vals, 26);
+ if(temp_photo_data2 && strlen(temp_photo_data2) > 0) {
+ media_info->photo_data2 = strdup(temp_photo_data2);
+ free(temp_photo_data2);
+ } else {
+ media_info->photo_data2 = 0;
+ }
+
+ char *temp_photo_type3 = (char *)eina_list_nth(row_vals, 27);
+ if (temp_photo_type3 && strlen(temp_photo_type3) > 0) {
+ media_info->photo_type3 =strdup(temp_photo_type3);
+ free(temp_photo_type3);
+ } else {
+ media_info->photo_type3 = 0;
+ }
+
+
+ int* temp_photo_loc_dc3 = (int*)eina_list_nth(row_vals, 28);
+ if (temp_photo_loc_dc3) {
+ media_info->photo_loc_dc3 = *temp_photo_loc_dc3;
+ free(temp_photo_loc_dc3);
+ } else {
+ media_info->photo_loc_dc3 = 0;
+ }
+
+
+ char *temp_photo_loc_vol3 = (char *)eina_list_nth(row_vals, 29);
+ if(temp_photo_loc_vol3 && strlen(temp_photo_loc_vol3) > 0) {
+ media_info->photo_loc_vol3 = atoll(temp_photo_loc_vol3);
+ free(temp_photo_loc_vol3);
+ } else {
+ media_info->photo_loc_vol3 = 0;
+ }
+
+
+ int* temp_photo_loc_id3 = (int*)eina_list_nth(row_vals, 30);
+ if (temp_photo_loc_id3) {
+ media_info->photo_loc_id3 = *temp_photo_loc_id3;
+ free(temp_photo_loc_id3);
+ } else {
+ media_info->photo_loc_id3 = 0;
+ }
+
+ char *temp_photo_loc_sec3 = (char *)eina_list_nth(row_vals, 31);
+ if(temp_photo_loc_sec3 && strlen(temp_photo_loc_sec3) > 0) {
+ media_info->photo_loc_sec3 = atoll(temp_photo_loc_sec3);
+ free(temp_photo_loc_sec3);
+ } else {
+ media_info->photo_loc_sec3 = 0;
+ }
+
+
+ int* temp_photo_width3 = (int*)eina_list_nth(row_vals, 32);
+ if(temp_photo_width3) {
+ media_info->photo_width3 = *temp_photo_width3;
+ free(temp_photo_width3);
+ } else {
+ media_info->photo_width3 = 0;
+ }
+
+
+ int* temp_photo_height3 = (int*)eina_list_nth(row_vals, 33);
+ if(temp_photo_height3) {
+ media_info->photo_height3 = *temp_photo_height3;
+ free(temp_photo_height3);
+ } else {
+ media_info->photo_height3 = 0;
+ }
+
+ int* temp_photo_size3 = (int*)eina_list_nth(row_vals, 34);
+ if(temp_photo_size3) {
+ media_info->photo_size3 = *temp_photo_size3;
+ free(temp_photo_size3);
+ } else {
+ media_info->photo_size3 = 0;
+ }
+
+
+ char *temp_photo_data3 = (char *)eina_list_nth(row_vals, 35);
+ if(temp_photo_data3 && strlen(temp_photo_data3) > 0) {
+ media_info->photo_data3 = strdup(temp_photo_data3);
+ free(temp_photo_data3);
+ } else {
+ media_info->photo_data3 = 0;
+ }
+
+ char *temp_photo_type4 = (char *)eina_list_nth(row_vals, 36);
+ if (temp_photo_type4 && strlen(temp_photo_type4) > 0) {
+ media_info->photo_type4 =strdup(temp_photo_type4);
+ free(temp_photo_type4);
+ } else {
+ media_info->photo_type4 = 0;
+ }
+
+
+ int* temp_photo_loc_dc4 = (int*)eina_list_nth(row_vals, 37);
+ if (temp_photo_loc_dc4) {
+ media_info->photo_loc_dc4 = *temp_photo_loc_dc4;
+ free(temp_photo_loc_dc4);
+ } else {
+ media_info->photo_loc_dc4 = 0;
+ }
+
+
+ char *temp_photo_loc_vol4 = (char *)eina_list_nth(row_vals, 38);
+ if(temp_photo_loc_vol4 && strlen(temp_photo_loc_vol4) > 0) {
+ media_info->photo_loc_vol4 = atoll(temp_photo_loc_vol4);
+ free(temp_photo_loc_vol4);
+ } else {
+ media_info->photo_loc_vol4 = 0;
+ }
+
+
+ int* temp_photo_loc_id4 = (int*)eina_list_nth(row_vals, 39);
+ if (temp_photo_loc_id4) {
+ media_info->photo_loc_id4 = *temp_photo_loc_id4;
+ free(temp_photo_loc_id4);
+ } else {
+ media_info->photo_loc_id4 = 0;
+ }
+
+ char *temp_photo_loc_sec4 = (char *)eina_list_nth(row_vals, 40);
+ if(temp_photo_loc_sec4 && strlen(temp_photo_loc_sec4) > 0) {
+ media_info->photo_loc_sec4 = atoll(temp_photo_loc_sec4);
+ free(temp_photo_loc_sec4);
+ } else {
+ media_info->photo_loc_sec4 = 0;
+ }
+
+
+ int* temp_photo_width4 = (int*)eina_list_nth(row_vals, 41);
+ if(temp_photo_width4) {
+ media_info->photo_width4 = *temp_photo_width4;
+ free(temp_photo_width4);
+ } else {
+ media_info->photo_width4 = 0;
+ }
+
+
+ int* temp_photo_height4 = (int*)eina_list_nth(row_vals, 42);
+ if(temp_photo_height4) {
+ media_info->photo_height4 = *temp_photo_height4;
+ free(temp_photo_height4);
+ } else {
+ media_info->photo_height4 = 0;
+ }
+
+ int* temp_photo_size4 = (int*)eina_list_nth(row_vals, 43);
+ if(temp_photo_size4) {
+ media_info->photo_size4 = *temp_photo_size4;
+ free(temp_photo_size4);
+ } else {
+ media_info->photo_size4 = 0;
+ }
+
+
+ char *temp_photo_data4 = (char *)eina_list_nth(row_vals, 44);
+ if(temp_photo_data4 && strlen(temp_photo_data4) > 0) {
+ media_info->photo_data4 = strdup(temp_photo_data4);
+ free(temp_photo_data4);
+ } else {
+ media_info->photo_data4 = 0;
+ }
+
+
+ /**************************************************************/
+
+ char *temp_phone_no = (char *)eina_list_nth(row_vals, 45);
+
+ if(temp_phone_no && strlen(temp_phone_no) > 0) {
+ media_info->phone_no = strdup(temp_phone_no);
+ free(temp_phone_no);
+ } else {
+ media_info->phone_no = 0;
+ }
+
+ char *temp_first_name = (char *)eina_list_nth(row_vals, 46);
+
+ if(temp_first_name && strlen(temp_first_name) > 0) {
+ media_info->first_name = strdup(temp_first_name);
+ free(temp_first_name);
+ } else {
+ media_info->first_name = 0;
+ }
+
+ char *temp_last_name = (char *)eina_list_nth(row_vals, 47);
+
+ if(temp_last_name && strlen(temp_last_name) > 0) {
+ media_info->last_name = strdup(temp_last_name);
+ free(temp_last_name);
+ } else {
+ media_info->last_name = 0;
+ }
+
+ char *temp_file_path = (char *)eina_list_nth(row_vals, 48);
+
+ if(temp_file_path && strlen(temp_file_path) > 0) {
+ media_info->file_path = strdup(temp_file_path);
+ free(temp_file_path);
+ } else {
+ media_info->file_path = 0;
+ }
+
+ char *temp_mime_type = (char *)eina_list_nth(row_vals, 49);
+
+ if(temp_mime_type && strlen(temp_mime_type) > 0) {
+ media_info->mime_type = strdup(temp_mime_type);
+ free(temp_mime_type);
+ } else {
+ media_info->mime_type = 0;
+ }
+
+ char *temp_doc_type = (char *)eina_list_nth(row_vals, 50);
+
+ if(temp_doc_type && strlen(temp_doc_type) > 0) {
+ media_info->doc_type = strdup(temp_doc_type);
+ free(temp_doc_type);
+ } else {
+ media_info->doc_type = 0;
+ }
+
+ int* temp_doc_width = (int*)eina_list_nth(row_vals, 51);
+ if(temp_doc_width) {
+ media_info->doc_width = *temp_doc_width;
+ free(temp_doc_width);
+ } else {
+ media_info->doc_width = 0;
+ }
+
+ int* temp_doc_height = (int*)eina_list_nth(row_vals, 52);
+ if(temp_doc_height) {
+ media_info->doc_height = *temp_doc_height;
+ free(temp_doc_height);
+ } else {
+ media_info->doc_height = 0;
+ }
+
+ int* temp_doc_duration = (int*)eina_list_nth(row_vals, 53);
+ if(temp_doc_duration) {
+ media_info->doc_duration = *temp_doc_duration;
+ free(temp_doc_duration);
+ } else {
+ media_info->doc_duration = 0;
+ }
+
+ int* temp_doc_size = (int*)eina_list_nth(row_vals, 54);
+ if(temp_doc_size) {
+ media_info->doc_size = *temp_doc_size;
+ free(temp_doc_size);
+ } else {
+ media_info->doc_size = 0;
+ }
+
+ int* temp_doc_dc = (int*)eina_list_nth(row_vals, 55);
+ if(temp_doc_size) {
+ media_info->doc_dc = *temp_doc_dc;
+ free(temp_doc_dc);
+ } else {
+ media_info->doc_dc = 0;
+ }
+
+ char* temp_doc_thumb_path = (int*)eina_list_nth(row_vals, 56);
+ if(temp_doc_thumb_path) {
+ media_info->doc_thumb_path = strdup(temp_doc_thumb_path);
+ free(temp_doc_thumb_path);
+ } else {
+ media_info->doc_thumb_path = 0;
+ }
+
+ eina_list_free(row_vals);
+
+ return media_info;
-void create_data_base_tables()
-{
- tg_db_create_table_user_info(USER_INFO_TABLE_NAME);
- tg_db_create_table_user_info(BUDDY_INFO_TABLE_NAME);
- tg_db_create_table_media_info(MEDIA_INFO_TABLE_NAME);
- tg_db_create_table_chat_info(CHAT_INFO_TABLE_NAME);
- tg_db_create_table_peer_info(PEER_INFO_TABLE_NAME);
}
-void create_buddy_msg_table(const char* table_name)
+Eina_List* get_image_details_from_db(long long media_id)
{
- tg_db_create_table_message(table_name);
+ Eina_List* vals = NULL;
+
+ char* table_name = MEDIA_INFO_TABLE_NAME;
+
+ char usr_str[50];
+ sprintf(usr_str,"%lld",media_id);
+ char* where_clause = (char*)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = ") + strlen(usr_str) + 1);
+ strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, usr_str);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_ID);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MEDIA_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_ACCESS_HASH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_USER_ID);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DATE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_CAPTION);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LONGITUDE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LATITUDE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_SIZES_NUM);
+
+ /********************************************************************/
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE1);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA1);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE2);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA2);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE3);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA3);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_TYPE4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_DC4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_VOL4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_ID4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_LOC_SECRET4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_WIDTH4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_HEIGHT4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_SIZE4);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHOTO_DATA4);
+
+ /********************************************************************/
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHONE_NO);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LAST_NAME);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FILE_PATH);
+
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_MIME_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_TYPE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_WIDTH);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_HEIGHT);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DURATION);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_SIZE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_DC);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE);
+
+ vals = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+
+ eina_list_free(col_types);
+ eina_list_free(col_names);
+
+ return vals;
}
-void insert_buddy_msg_to_db(struct tgl_message *M)
+void get_contact_details_from_db(long long media_id, char **first_name, char **last_name, char **phone_number)
{
- // get user name using id from buddy_info_table
- int t = 0;
-#if 0
- char* table_name = BUDDY_INFO_TABLE_NAME;
+ char* file_path = NULL;
+ char* table_name = MEDIA_INFO_TABLE_NAME;
- int user_id = M->from_id.id;
char usr_str[50];
- sprintf(usr_str,"%d",user_id);
-
- char* where_clause = (char*)malloc(strlen(BUDDY_INFO_TABLE_BUDDY_ID) + strlen(" = ") + strlen(usr_str));
- strcpy(where_clause, BUDDY_INFO_TABLE_BUDDY_ID);
- strcat(where_clause, " = ");
+ sprintf(usr_str, "%lld", media_id);
+ char* where_clause = (char *)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = '") + strlen(usr_str) + strlen("'") + 1);
+ strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID);
+ strcat(where_clause, " = '");
strcat(where_clause, usr_str);
+ strcat(where_clause, "'");
Eina_List* col_types = NULL;
col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
Eina_List* col_names = NULL;
- col_names = eina_list_append(col_names, BUDDY_INFO_TABLE_PHONE_NO);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LAST_NAME);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_PHONE_NO);
Eina_List* vals = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
- close_database(db);
-
- char* phone_no = NULL;
+ file_path = NULL;
- if(!vals) {
+ if (!vals) {
//("DB error");
+ eina_list_free(col_names);
return;
} else {
int row_count = eina_list_count(vals);
for (int i = 0 ; i < row_count ; i++) {
Eina_List* row_vals = eina_list_nth(vals, i);
- phone_no = (char*)eina_list_nth(row_vals, 0);
- if(!phone_no) {
- //("DB Error");
- return;
- } else {
- break;
- }
+ char *temp_fname = (char*)eina_list_nth(row_vals, 0);
+ *first_name = temp_fname;
+ char *temp_lname = (char*)eina_list_nth(row_vals, 1);
+ *last_name = temp_lname;
+ char *temp_pnumber = (char*)eina_list_nth(row_vals, 2);
+ *phone_number = temp_pnumber;
eina_list_free(row_vals);
+ break;
}
eina_list_free(vals);
}
-
- if(phone_no) {
- char* tb_name = get_table_name_from_number(phone_no);
- insert_msg_into_db(M, tb_name, t);
- free(tb_name);
- free(phone_no);
- }
-#else
- int user_id = 0;
- if (tgl_get_peer_type(M->to_id) == TGL_PEER_USER) {
- user_id = M->from_id.id;
- } else if (tgl_get_peer_type(M->to_id) == TGL_PEER_CHAT) {
- user_id = M->to_id.id;
- }
- char* tb_name = get_table_name_from_number(user_id);
- insert_msg_into_db(M, tb_name, t);
- free(tb_name);
-#endif
+ eina_list_free(col_names);
+ return;
}
-void insert_peer_into_database(tgl_peer_t* UC, int last_msg_id, int unread_count)
+void get_geo_location_from_db(long long media_id, char **latitude, char **longitude)
{
- int ret;
+ char* file_path = NULL;
+ char* table_name = MEDIA_INFO_TABLE_NAME;
- if (!UC) {
- return;
- }
+ char usr_str[50];
+ sprintf(usr_str, "%lld", media_id);
+ char* where_clause = (char *)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = '") + strlen(usr_str) + strlen("'") + 1);
+ strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID);
+ strcat(where_clause, " = '");
+ strcat(where_clause, usr_str);
+ strcat(where_clause, "'");
- ret = tg_db_insert_peer_info(PEER_INFO_TABLE_NAME, UC, last_msg_id, unread_count);
- if (ret != 0) {
- ret = tg_db_update_peer_info(PEER_INFO_TABLE_NAME, UC, last_msg_id, unread_count);
- }
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
- return;
-}
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LATITUDE);
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_LONGITUDE);
-struct tgl_message* get_message_from_message_table(long long msg_id, char* table_name)
-{
- struct tgl_message* message;
- message = tg_db_get_message(table_name, msg_id);
- return message;
-}
+ Eina_List* vals = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+ file_path = NULL;
-void insert_msg_into_db(struct tgl_message *M, char* table_name, int unique_id)
-{
- if(!M) {
+ if (!vals) {
+ //("DB error");
+ eina_list_free(col_names);
return;
- }
-
- tg_db_insert_message(table_name, M, (long long)unique_id);
-}
+ } else {
+ int row_count = eina_list_count(vals);
-void update_msg_into_db(struct tgl_message *M, char* table_name, int unique_id)
-{
- if(!M) {
- return;
+ for (int i = 0 ; i < row_count ; i++) {
+ Eina_List* row_vals = eina_list_nth(vals, i);
+ char *temp_lat = (char*)eina_list_nth(row_vals, 0);
+ *latitude = temp_lat;
+ char *temp_long = (char*)eina_list_nth(row_vals, 1);
+ *longitude = temp_long;
+ eina_list_free(row_vals);
+ break;
+ }
+ eina_list_free(vals);
}
-
- tg_db_update_message(table_name, M, unique_id);
+ eina_list_free(col_names);
+ return;
}
-Eina_Bool is_chat_id_already_exists(struct tgl_chat *chat_info)
+char* get_video_thumb_path_from_db(long long media_id)
{
- // get chat name chat id from chat_info_table
+ char* file_path = NULL;
+ char* table_name = MEDIA_INFO_TABLE_NAME;
- int ret;
- ret = tg_db_count_chat_info(CHAT_INFO_TABLE_NAME, chat_info);
- return ret > 0 ? EINA_TRUE : EINA_FALSE;
-}
+ char usr_str[50];
+ sprintf(usr_str, "%lld", media_id);
+ char* where_clause = (char *)malloc(strlen(MEDIA_INFO_TABLE_MEDIA_ID) + strlen(" = '") + strlen(usr_str) + strlen("'") + 1);
+ strcpy(where_clause, MEDIA_INFO_TABLE_MEDIA_ID);
+ strcat(where_clause, " = '");
+ strcat(where_clause, usr_str);
+ strcat(where_clause, "'");
-void insert_buddy_into_db(char* table_name, struct tgl_user* U)
-{
- int ret;
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
- if(!U) {
- return;
- }
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE);
+
+ Eina_List* vals = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+ file_path = NULL;
- ret = tg_db_insert_user_info(table_name, U);
- if (ret != 0) {
- ret = tg_db_update_user_info(table_name, U);
- if (ret != 0) {
+ if (!vals) {
+ //("DB error");
+ eina_list_free(col_names);
+ return NULL;
+ } else {
+ int row_count = eina_list_count(vals);
+ for (int i = 0 ; i < row_count ; i++) {
+ Eina_List* row_vals = eina_list_nth(vals, i);
+ file_path = (char*)eina_list_nth(row_vals, 0);
+ eina_list_free(row_vals);
+ if (!file_path) {
+ //("DB Error");
+ eina_list_free(col_names);
+ return NULL;
+ } else {
+ break;
+ }
}
+ eina_list_free(vals);
}
+
+ eina_list_free(col_names);
+ return file_path;
}
-void insert_chat_info_to_db(struct tgl_chat *chat_info, char* photo_path)
-{
- if (!chat_info) {
- return;
- }
- tg_db_insert_chat_info(CHAT_INFO_TABLE_NAME, chat_info, photo_path);
-}
-void update_chat_info_to_db(struct tgl_chat *chat_info, char *photo_path)
+void get_buddy_contact_details_from_db(int buddy_id, char **first_name, char **last_name, char **phone_number)
{
- if (!chat_info) {
+ char* file_path = NULL;
+ char* table_name = BUDDY_INFO_TABLE_NAME;
+
+ char usr_str[50];
+ sprintf(usr_str, "%d", buddy_id);
+ char* where_clause = (char *)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = '") + strlen(usr_str) + strlen("'") + 1);
+ strcpy(where_clause, USER_INFO_TABLE_USER_ID);
+ strcat(where_clause, " = '");
+ strcat(where_clause, usr_str);
+ strcat(where_clause, "'");
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_FIRST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_LAST_NAME);
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PHONE_NO);
+
+ Eina_List* vals = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+ file_path = NULL;
+
+ if (!vals) {
+ //("DB error");
+ eina_list_free(col_names);
return;
- }
+ } else {
+ int row_count = eina_list_count(vals);
- tg_db_update_chat_info(CHAT_INFO_TABLE_NAME, chat_info, photo_path);
+ for (int i = 0 ; i < row_count ; i++) {
+ Eina_List* row_vals = eina_list_nth(vals, i);
+ char *temp_fname = (char*)eina_list_nth(row_vals, 0);
+ *first_name = temp_fname;
+ char *temp_lname = (char*)eina_list_nth(row_vals, 1);
+ *last_name = temp_lname;
+ char *temp_pnumber = (char*)eina_list_nth(row_vals, 2);
+ *phone_number = temp_pnumber;
+ eina_list_free(row_vals);
+ break;
+ }
+ eina_list_free(vals);
+ }
+ eina_list_free(col_names);
+ return;
}
-void update_buddy_pic_db(char* file_path, char* table_name, int id)
+
+int get_unread_message_count(char* table_name)
{
- if (!file_path || !table_name) {
- return;
+ // number of rows, having out == 1 and unread == 0
+ if (!table_name) {
+ return 0;
}
+ int num_of_rows = 0;
- tg_db_update_user_photo(table_name, id, file_path, -1);
-}
+ char* where_clause = NULL;
+ char unread_str[50];
+ sprintf(unread_str, "%d", 1);
-/**
- * @note
- * This function is not used by tgl-service.
- * Do we have to keep this from here??
- */
-struct tgl_user* get_buddy_info(int buddy_id)
-{
- struct tgl_user *user_info;
+ char out_str[50];
+ sprintf(out_str, "%d", 0);
- user_info = tg_db_get_user_info(BUDDY_INFO_TABLE_NAME, buddy_id);
+ where_clause = (char*)malloc(strlen(MESSAGE_INFO_TABLE_UNREAD) + strlen(" = ") + strlen(unread_str) + 1);
+ strcpy(where_clause, MESSAGE_INFO_TABLE_UNREAD);
+ strcat(where_clause, " = ");
+ strcat(where_clause, unread_str);
- return user_info;
+ num_of_rows = get_number_of_rows(table_name, where_clause);
+ free(where_clause);
+ return num_of_rows;
}
-void update_receive_media_info_in_db(long long media_id, char* file_path)
+Eina_List* get_all_peer_ids()
{
- tg_db_update_media_info_filepath(MEDIA_INFO_TABLE_NAME, media_id, file_path);
-}
+ Eina_List* peer_details = NULL;
+ char* table_name = PEER_INFO_TABLE_NAME;
+ Eina_List* col_names = NULL;
-void insert_media_info_to_db(struct tgl_message *M, char* file_path)
-{
- if(!M) {
- return;
- }
+ col_names = eina_list_append(col_names, PEER_INFO_TABLE_CHAT_ID);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_KEY);
+
+ peer_details = get_values_from_table_sync_order_by(table_name, col_names, col_types, PEER_INFO_TABLE_LAST_MESSAGE_DATE, EINA_FALSE, NULL);
- tg_db_insert_media_info(MEDIA_INFO_TABLE_NAME, M, file_path);
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ return peer_details;
}
-void update_sent_media_info_in_db(struct tgl_message *M, long long unique_val)
+int get_number_of_unread_messages()
{
- long long id;
- if(!M) {
- return;
- }
-
- if (unique_val == 0) {
- switch (M->media.type) {
- case tgl_message_media_photo:
- id = M->media.photo.id;
- break;
- case tgl_message_media_document:
- id = M->media.document.id;
- break;
- default:
- /**
- * @note
- * To be handled.
- */
- id = 0;
- break;
+ int no_of_unread = 0;
+ Eina_List* peer_details = get_all_peer_ids();
+ for (int i = 0; i < eina_list_count(peer_details) ; i++) {
+ Eina_List* ts_msg = eina_list_nth(peer_details, i);
+ int peer_id = 0;
+ int *temp_peer_id = (int*)eina_list_nth(ts_msg, 0);
+ if (temp_peer_id) {
+ peer_id = *temp_peer_id;
+ free(temp_peer_id);
+ temp_peer_id = NULL;
}
- } else {
- id = unique_val;
+ char *msg_table = get_table_name_from_number(peer_id);
+ int count = 0;
+ if (msg_table) {
+ count = get_unread_message_count(msg_table);
+ }
+ no_of_unread = no_of_unread + count;
+ free(msg_table);
+ eina_list_free(ts_msg);
}
-
- tg_db_update_media_info_by_id(MEDIA_INFO_TABLE_NAME, M, id);
+ eina_list_free(peer_details);
+ return no_of_unread;
}
+
void tg_server_destroy(tg_server *proxy_cl)
{
- if (proxy_cl) {
+ if (proxy_cl)
+ {
message_port_unregister_local_port(proxy_cl->local_port_id);
free(proxy_cl->remote_port_name);
free(proxy_cl->remote_app_name);
RETVM_IF(!port_name, result, "Message port name is NULL");
int temp_id = message_port_register_local_port(port_name, _on_message_received_cb, proxy_cl);
- if (temp_id < 0) {
+ if (temp_id < 0)
+ {
_tg_server_convert_msg_port_result(temp_id);
ERR("Failed to register local message port");
proxy_cl->local_port_id = 0;
char *temp_rem_app_name = NULL;
char *temp_rem_port_name = NULL;
- if (!proxy_cl->remote_app_name && rem_app_name) {
+ if (!proxy_cl->remote_app_name && rem_app_name)
+ {
temp_rem_app_name = strdup(rem_app_name);
RETVM_IF(!temp_rem_app_name, SVC_RES_FAIL,
"Failed to set remote application name. Strdup failed");
}
- if (!proxy_cl->remote_port_name && rem_port_name) {
+ if (!proxy_cl->remote_port_name && rem_port_name)
+ {
temp_rem_port_name = strdup(rem_port_name);
- if (!temp_rem_port_name) {
+ if (!temp_rem_port_name)
+ {
ERR("Failed to set remote port name. Strdup failed");
free(temp_rem_app_name);
return SVC_RES_FAIL;
}
}
- if (temp_rem_app_name) {
+ if (temp_rem_app_name)
+ {
proxy_cl->remote_app_name = temp_rem_app_name;
}
- if (temp_rem_port_name) {
+ if (temp_rem_port_name)
+ {
proxy_cl->remote_port_name = temp_rem_port_name;
}
int res = _tg_server_set_remote_data(proxy_cl, rem_app_name, rem_port_name);
RETM_IF(res != SVC_RES_OK ,"Failed to set remote data to message port");
- if (proxy_cl->cb_func) {
+ if (proxy_cl->cb_func)
+ {
res = proxy_cl->cb_func(proxy_cl->cb_data, rec_msg);
RETM_IF(res != SVC_RES_OK ,"Message port callback function failed");
- } else {
+ }
+ else
+ {
DBG("Message port callback function not set");
}
}
#include <Ecore.h>
#include "tg_db_wrapper.h"
#include "tgl-fetch.h"
-#include "tg_common.h"
+#include <mime_type.h>
#define DC_SERIALIZED_MAGIC 0x868aa81d
#define STATE_FILE_MAGIC 0x28949a93
static void on_chat_info_received(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_chat *chat_info);
static void on_buddy_info_loaded(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U);
static void on_chat_pic_loaded(struct tgl_state *TLS, void *callback_extra, int success, char *filename);
+static void on_document_download_completed(struct tgl_state *TLS, void *callback_extra, int success, char *filename);
+
+void tgl_engine_var_init(void)
+{
+ s_info.default_username = NULL;
+ s_info.config_filename = NULL;
+ s_info.auth_file_name = NULL;
+ s_info.state_file_name = NULL;
+ s_info.secret_chat_file_name = NULL;
+ s_info.downloads_directory = NULL;
+ s_info.config_directory = NULL;
+ s_info.binlog_file_name = NULL;
+ s_info.lua_file = NULL;
+}
+
+void tgl_engine_var_free(void)
+{
+ if (s_info.default_username) {
+ free(s_info.default_username);
+ s_info.default_username = NULL;
+ }
+ if (s_info.config_filename) {
+ free(s_info.config_filename);
+ s_info.config_filename = NULL;
+ }
+ if (s_info.auth_file_name) {
+ free(s_info.auth_file_name);
+ s_info.auth_file_name = NULL;
+ }
+ if (s_info.state_file_name) {
+ free(s_info.state_file_name);
+ s_info.state_file_name = NULL;
+ }
+ if (s_info.secret_chat_file_name) {
+ free(s_info.secret_chat_file_name);
+ s_info.secret_chat_file_name = NULL;
+ }
+ if (s_info.downloads_directory) {
+ free(s_info.downloads_directory);
+ s_info.downloads_directory = NULL;
+ }
+ if (s_info.config_directory) {
+ free(s_info.config_directory);
+ s_info.config_directory = NULL;
+ }
+ if (s_info.binlog_file_name) {
+ free(s_info.binlog_file_name);
+ s_info.binlog_file_name = NULL;
+ }
+ if (s_info.lua_file) {
+ free(s_info.lua_file);
+ s_info.lua_file = NULL;
+ }
+ if (s_info.TLS) {
+ tgl_state_free(s_info.TLS);
+ tgl_free_all(s_info.TLS);
+ s_info.TLS = NULL;
+ }
+}
char *tgl_engine_get_auth_key_filename(void)
{
struct tgl_user* buddy;
buddy = &(UC->user);
char *phone = NULL;
- if (buddy) {
+ if (buddy && buddy->phone && strlen(buddy->phone) > 0) {
phone = buddy->phone;
}
}
+void on_code_via_phone_result(struct tgl_state *TLS, void *callback_extra, int success)
+{
+ if (success) {
+ printf("success");
+ }
+}
+
+void request_for_code_via_call(struct tgl_state *TLS, char* phone_no, Eina_Bool trough_sms)
+{
+ tg_engine_data_s *tg_data;
+ tg_data = TLS->callback_data;
+ tgl_do_phone_call(TLS, tg_data->phone_number, tg_data->mhash, on_code_via_phone_result, TLS);
+}
+
void tg_get_string(struct tgl_state *TLS, const char *prompt, int flags, void(*callback)(struct tgl_state *TLS, char *string, void *arg), void *arg)
{
tg_engine_data_s *tg_data;
}
} else if (strcmp (prompt, "code('call' for phone call):") == 0) {
+ void **T = arg;
+ tg_data->mhash = T[1];
tg_data->tg_state = TG_ENGINE_STATE_CODE_REQUEST;
send_registration_response(tg_data, EINA_TRUE);
tgl_do_get_user_info(TLS, t_id, offline_mode, &on_user_info_loaded, NULL);
}
+static Eina_Bool on_send_media_message_requested(void *data)
+{
+ sent_media_data_s *media_info = (sent_media_data_s*)data;
+ if (media_info) {
+ int buddy_id = atoi(media_info->buddy_id);
+ int message_id = atoi(media_info->message_id);
+ int media_id = atoi(media_info->media_id);
+ int msg_type = atoi(media_info->message_type);
+ int type_of_chat = atoi(media_info->type_of_chat);
+
+ process_send_media_command(buddy_id, message_id, media_id, msg_type, media_info->file_path, type_of_chat);
+
+ if (media_info->app_name) {
+ free(media_info->app_name);
+ media_info->app_name = NULL;
+ }
+ if (media_info->command) {
+ free(media_info->command);
+ media_info->command = NULL;
+ }
+ if (media_info->buddy_id) {
+ free(media_info->buddy_id);
+ media_info->buddy_id = NULL;
+ }
+ if (media_info->message_id) {
+ free(media_info->message_id);
+ media_info->message_id = NULL;
+ }
+ if (media_info->media_id) {
+ free(media_info->media_id);
+ media_info->media_id = NULL;
+ }
+
+ if (media_info->message_type) {
+ free(media_info->message_type);
+ media_info->message_type = NULL;
+ }
+ if (media_info->file_path) {
+ free(media_info->file_path);
+ media_info->file_path = NULL;
+ }
+ if (media_info->type_of_chat) {
+ free(media_info->type_of_chat);
+ media_info->type_of_chat = NULL;
+ }
+ free(media_info);
+ }
+ return ECORE_CALLBACK_CANCEL;
+}
+
+static Eina_Bool on_send_unsent_messages_requested(void *data)
+{
+ struct tgl_state *TLS = data;
+ if (TLS) {
+ //tg_engine_data_s *tg_data = TLS->callback_data;
+
+ Eina_List *unset_text_msgs = get_all_unsent_text_messages();
+ if (unset_text_msgs && eina_list_count(unset_text_msgs) > 0 ) {
+ for (int i = 0 ; i < eina_list_count(unset_text_msgs) ; i++) {
+ sent_message_data_s* msg_info = eina_list_nth(unset_text_msgs, i);
+ if (msg_info) {
+ int buddy_id = atoi(msg_info->buddy_id);
+ int message_id = atoi(msg_info->message_id);
+ int msg_type = atoi(msg_info->message_type);
+ int type_of_chat = atoi(msg_info->type_of_chat);
+ process_send_message_command(buddy_id, message_id, msg_type, msg_info->message_data, type_of_chat);
+
+ if (msg_info->app_name) {
+ free(msg_info->app_name);
+ msg_info->app_name = NULL;
+ }
+ if (msg_info->command) {
+ free(msg_info->command);
+ msg_info->command = NULL;
+ }
+ if (msg_info->buddy_id) {
+ free(msg_info->buddy_id);
+ msg_info->buddy_id = NULL;
+ }
+ if (msg_info->message_id) {
+ free(msg_info->message_id);
+ msg_info->message_id = NULL;
+ }
+
+ if (msg_info->message_type) {
+ free(msg_info->message_type);
+ msg_info->message_type = NULL;
+ }
+ if (msg_info->message_data) {
+ free(msg_info->message_data);
+ msg_info->message_data = NULL;
+ }
+ if (msg_info->type_of_chat) {
+ free(msg_info->type_of_chat);
+ msg_info->type_of_chat = NULL;
+ }
+ free(msg_info);
+ }
+
+ }
+ eina_list_free(unset_text_msgs);
+ }
+
+ Eina_List *unset_media_msgs = get_all_unsent_media_messages();
+ int init_time = 10;
+ if (unset_media_msgs && eina_list_count(unset_media_msgs) > 0 ) {
+ for (int i = 0 ; i < eina_list_count(unset_media_msgs) ; i++) {
+ sent_media_data_s* media_info = eina_list_nth(unset_media_msgs, i);
+ if (media_info) {
+/* int buddy_id = atoi(media_info->buddy_id);
+ int message_id = atoi(media_info->message_id);
+ int media_id = atoi(media_info->media_id);
+ int msg_type = atoi(media_info->message_type);
+ int type_of_chat = atoi(media_info->type_of_chat);*/
+
+ sent_media_data_s* new_media_info = (sent_media_data_s*)malloc(sizeof(sent_media_data_s));
+ new_media_info->app_name = strdup(media_info->app_name);
+ new_media_info->command = strdup(media_info->command);
+ new_media_info->buddy_id = strdup(media_info->buddy_id);
+ new_media_info->message_id = strdup(media_info->message_id);
+ new_media_info->media_id = strdup(media_info->media_id);
+ new_media_info->message_type = strdup(media_info->message_type);
+ new_media_info->file_path = strdup(media_info->file_path);
+ new_media_info->type_of_chat = strdup(media_info->type_of_chat);
+
+ ecore_timer_add(init_time, on_send_media_message_requested, new_media_info);
+
+ //process_send_media_command(buddy_id, message_id, media_id, msg_type, media_info->file_path, type_of_chat);
+
+ if (media_info->app_name) {
+ free(media_info->app_name);
+ media_info->app_name = NULL;
+ }
+ if (media_info->command) {
+ free(media_info->command);
+ media_info->command = NULL;
+ }
+ if (media_info->buddy_id) {
+ free(media_info->buddy_id);
+ media_info->buddy_id = NULL;
+ }
+ if (media_info->message_id) {
+ free(media_info->message_id);
+ media_info->message_id = NULL;
+ }
+ if (media_info->media_id) {
+ free(media_info->media_id);
+ media_info->media_id = NULL;
+ }
+
+ if (media_info->message_type) {
+ free(media_info->message_type);
+ media_info->message_type = NULL;
+ }
+ if (media_info->file_path) {
+ free(media_info->file_path);
+ media_info->file_path = NULL;
+ }
+ if (media_info->type_of_chat) {
+ free(media_info->type_of_chat);
+ media_info->type_of_chat = NULL;
+ }
+ free(media_info);
+ }
+
+ }
+ eina_list_free(unset_media_msgs);
+ }
+
+ }
+ return ECORE_CALLBACK_CANCEL;
+}
+
void tg_started(struct tgl_state *TLS)
{
tg_engine_data_s *tg_data = TLS->callback_data;
tg_data = TLS->callback_data;
if (flags == TGL_GROUP_CHAT_CREATED) {
+#if 0
insert_chat_info_to_db(chat_info, NULL);
tgl_peer_t* UC = tgl_peer_get(TLS, chat_info->id);
insert_peer_into_database(UC, 0, 0);
+#endif
+ //if (tg_data->is_loading_completed) {
+ tgl_do_get_chat_info(TLS, chat_info->id, 0, &on_chat_info_received, NULL);
+ //}
}
if (!(flags & TGL_UPDATE_CREATED)) {
}
+void on_new_chat_info_received(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_chat *chat_info)
+{
+ tg_engine_data_s *tg_data;
+
+ struct tgl_message *M = callback_extra;
+
+ if (!chat_info) {
+ return;
+ }
+
+ tg_data = TLS->callback_data;
+
+ tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
+ int msg_len = strlen(UC->user.first_name) + strlen(" created the group") + 1;
+ char* creator_name = (char*)malloc(msg_len);
+ strcpy(creator_name, UC->user.first_name);
+ strcat(creator_name, " created the group");
+
+ int cur_time = time(NULL);
+ M->id = cur_time;
+ M->message = creator_name;
+ M->message_len = msg_len;
+ M->unread = 1;
+ M->date = cur_time;
+ insert_buddy_msg_to_db(M);
+ free(creator_name);
+
+ tgl_peer_t* chat_UC = tgl_peer_get(TLS, chat_info->id);
+ insert_chat_info_to_db(chat_info, NULL);
+ chat_UC->last = M;
+ insert_peer_into_database(chat_UC, 0, 0);
+
+ send_new_group_added_response(tg_data, chat_info->id.id);
+
+}
+
+void on_group_chat_info_updated(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_chat *chat_info)
+{
+ tg_engine_data_s *tg_data;
+
+
+ if (!chat_info) {
+ return;
+ }
+
+ tg_data = TLS->callback_data;
+ char *type_of_change = callback_extra;
+
+ if (!type_of_change) {
+ type_of_change = strdup("");
+ }
+
+ tgl_peer_t* chat_UC = tgl_peer_get(TLS, chat_info->id);
+ insert_chat_info_to_db(chat_info, NULL);
+ insert_peer_into_database(chat_UC, 0, 0);
+ send_group_chat_updated_response(tg_data, chat_info->id.id, type_of_change);
+ free(type_of_change);
+}
+
+void on_new_chat_pic_loaded(struct tgl_state *TLS, void *callback_extra, int success, char *filename)
+{
+ struct tgl_message *M = callback_extra;
+
+
+ if (filename) {
+
+ tgl_peer_t* peer = tgl_peer_get(TLS, M->from_id);
+ int msg_len = strlen(peer->user.first_name) + strlen(" changed group icon") + 1;
+ char* creator_name = (char*)malloc(msg_len);
+ strcpy(creator_name, peer->user.first_name);
+ strcat(creator_name, " changed group icon");
+
+ int cur_time = time(NULL);
+ M->id = cur_time;
+ M->message = creator_name;
+ M->message_len = msg_len;
+ M->date = cur_time;
+ M->unread = 1;
+ insert_buddy_msg_to_db(M);
+ free(creator_name);
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
+
+
+ tgl_peer_t* UC = tgl_peer_get(TLS, M->to_id);
+ struct tgl_chat *chat_info = &(UC->chat);
+ update_chat_info_to_db(chat_info, filename);
+ update_peer_info_database(UC);
+ update_buddy_pic_db(filename, PEER_INFO_TABLE_NAME, chat_info->id.id);
+ send_buddy_profile_pic_updated_response(TLS->callback_data, chat_info->id.id, filename);
+ }
+}
+
+void on_video_thumb_loaded(struct tgl_state *TLS, void *callback_extra, int success, char *filename)
+{
+ struct tgl_message *M = (struct tgl_message*)callback_extra;
+ if (success && filename) {
+ // update in db and send info to app...
+ long long media_id = M->media.document.id;
+ update_video_thumb_in_db(media_id, filename);
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ if (M->from_id.id == tg_data->id.id) {
+ send_video_thumb_download_completed_response(tg_data, M->from_id.id, M->to_id.id, media_id, filename);
+ } else {
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
+ }
+ }
+}
+
+struct tg_temp_msg_data {
+ Ecore_Timer* send_timer;
+ struct tgl_state *TLS;
+ struct tgl_message *M;
+};
+
+static Eina_Bool on_msg_received_cb(void *data)
+{
+ struct tg_temp_msg_data *msg_data = data;
+ insert_buddy_msg_to_db(msg_data->M);
+ if(msg_data->M->media.type != tgl_message_media_none) {
+ insert_media_info_to_db(msg_data->M, "");
+ if (msg_data->M->media.type != tgl_message_media_none && (msg_data->M->media.document.flags & FLAG_DOCUMENT_VIDEO)) {
+ tgl_do_load_document_thumb(msg_data->TLS, &(msg_data->M->media.document), on_video_thumb_loaded, msg_data->M);
+ if (msg_data->send_timer) {
+ ecore_timer_del(msg_data->send_timer);
+ }
+ free(msg_data);
+ return ECORE_CALLBACK_CANCEL;
+ }
+ }
+ // inform to application
+ send_message_received_response(msg_data->TLS->callback_data, msg_data->M->from_id.id, msg_data->M->to_id.id, msg_data->M->id, tgl_get_peer_type(msg_data->M->to_id));
+ if (msg_data->send_timer) {
+ ecore_timer_del(msg_data->send_timer);
+ }
+ free(msg_data);
+ return ECORE_CALLBACK_CANCEL;
+}
+
+
+
void tg_msg_receive(struct tgl_state *TLS, struct tgl_message *M)
{
if (M && TLS->started) {
if (M->service) {
// this is service message. to be handled in telegram.
if (tgl_get_peer_id (M->from_id) != TLS->our_id) {
+ char *type_of_change = NULL;
if (M->action.type == tgl_message_action_chat_create) {
char* msg_table = get_table_name_from_number(M->to_id.id);
create_buddy_msg_table(msg_table);
+ int msg_id = insert_current_date_to_table(msg_table);
free(msg_table);
- tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
+ tgl_do_get_chat_info(TLS, M->to_id, 0, &on_new_chat_info_received, M);
- int msg_len = strlen(UC->user.first_name) + strlen(" created the group") + 1;
+ } else if (M->action.type == tgl_message_action_chat_edit_title) {
+ type_of_change = strdup("edit_title");
+ tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
+ int msg_len = strlen(UC->user.first_name) + strlen(" changed the chat title") + 1;
char* creator_name = (char*)malloc(msg_len);
strcpy(creator_name, UC->user.first_name);
- strcat(creator_name, " created the group");
+ strcat(creator_name, " changed the chat title");
+
+ int cur_time = time(NULL);
+ M->id = cur_time;
M->message = creator_name;
M->message_len = msg_len;
M->unread = 1;
- M->date = time(NULL);
+ M->date = cur_time;
insert_buddy_msg_to_db(M);
free(creator_name);
-
- tgl_peer_t* chat_UC = tgl_peer_get(TLS, M->to_id);
- chat_UC->chat.date = M->date;
- insert_chat_info_to_db(&(chat_UC->chat), NULL);
- chat_UC->last = M;
- insert_peer_into_database(chat_UC, 0, 0);
-
-
-
- //send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
- tg_engine_data_s *tg_data = TLS->callback_data;
- send_new_group_added_response(tg_data, M->to_id.id);
-
- } else if (M->action.type == tgl_message_action_chat_edit_title) {
-
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
+ tgl_do_get_chat_info(TLS, M->to_id, 0, &on_group_chat_info_updated, type_of_change);
} else if (M->action.type == tgl_message_action_chat_edit_photo) {
char* msg_table = get_table_name_from_number(M->to_id.id);
create_buddy_msg_table(msg_table);
+ int msg_id = insert_current_date_to_table(msg_table);
free(msg_table);
+ struct tgl_photo *pic = &(M->action.photo);
+ if(pic) {
+ tgl_do_load_photo(TLS, pic ,&on_new_chat_pic_loaded, M);
+ }
- tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
- int msg_len = strlen(UC->user.first_name) + strlen(" changed profile photo") + 1;
+ } else if (M->action.type == tgl_message_action_chat_delete_photo) {
+ type_of_change = strdup("delete_photo");
+ tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
+ int msg_len = strlen(UC->user.first_name) + strlen(" deleted the profile photo") + 1;
char* creator_name = (char*)malloc(msg_len);
strcpy(creator_name, UC->user.first_name);
- strcat(creator_name, " changed profile photo");
+ strcat(creator_name, " deleted the profile photo");
+
+ int cur_time = time(NULL);
+ M->id = cur_time;
M->message = creator_name;
M->message_len = msg_len;
M->unread = 1;
+ M->date = cur_time;
insert_buddy_msg_to_db(M);
free(creator_name);
send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
- struct tgl_photo *pic = &(M->action.photo);
- if(pic) {
- tgl_peer_t* UC = tgl_peer_get(TLS, M->to_id);
- struct tgl_chat *chat_info = &(UC->chat);
- tgl_do_load_photo(TLS, pic ,&on_chat_pic_loaded, chat_info);
- }
- } else if (M->action.type == tgl_message_action_chat_delete_photo) {
+
+ char *filename = "";
+ tgl_peer_t* lUC = tgl_peer_get(TLS, M->to_id);
+ struct tgl_chat *chat_info = &(lUC->chat);
+ update_chat_info_to_db(chat_info, filename);
+ update_peer_info_database(lUC);
+ update_buddy_pic_db(filename, PEER_INFO_TABLE_NAME, chat_info->id.id);
+ send_buddy_profile_pic_updated_response(TLS->callback_data, chat_info->id.id, filename);
+
} else if (M->action.type == tgl_message_action_chat_add_user) {
+ type_of_change = strdup("add_user");
+ tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
+ int msg_len = strlen(UC->user.first_name) + strlen(" added to the group") + 1;
+ char* creator_name = (char*)malloc(msg_len);
+ strcpy(creator_name, UC->user.first_name);
+ strcat(creator_name, " added to the group");
+ int cur_time = time(NULL);
+ M->id = cur_time;
+ M->message = creator_name;
+ M->message_len = msg_len;
+ M->unread = 1;
+ M->date = cur_time;
+ insert_buddy_msg_to_db(M);
+ free(creator_name);
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
+ tgl_do_get_chat_info(TLS, M->to_id, 0, &on_group_chat_info_updated, type_of_change);
} else if (M->action.type == tgl_message_action_chat_delete_user) {
+ type_of_change = strdup("delete_user");
+ tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
+ int msg_len = strlen(UC->user.first_name) + strlen(" left the group") + 1;
+ char* creator_name = (char*)malloc(msg_len);
+ strcpy(creator_name, UC->user.first_name);
+ strcat(creator_name, " left the group");
+ int cur_time = time(NULL);
+ M->id = cur_time;
+ M->message = creator_name;
+ M->message_len = msg_len;
+ M->unread = 1;
+ M->date = cur_time;
+ insert_buddy_msg_to_db(M);
+ free(creator_name);
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
+ tgl_do_get_chat_info(TLS, M->to_id, 0, &on_group_chat_info_updated, type_of_change);
}
}
return;
if (tgl_get_peer_type(M->to_id) == TGL_PEER_USER) {
if (M->out) {
-
if (M->unread) {
} else {
}
-
} else {
if (M->media.type != tgl_message_media_none) {
M->message = NULL;
M->message_len = 0;
}
- insert_buddy_msg_to_db(M);
- if(M->media.type != tgl_message_media_none) {
- insert_media_info_to_db(M, "");
+ int user_id = 0;
+ if (tgl_get_peer_type(M->to_id) == TGL_PEER_USER) {
+ user_id = M->from_id.id;
+ } else if (tgl_get_peer_type(M->to_id) == TGL_PEER_CHAT) {
+ user_id = M->to_id.id;
+ }
+ char* tb_name = get_table_name_from_number(user_id);
+
+ int msg_id = insert_current_date_to_table(tb_name);
+ free(tb_name);
+ if (msg_id > 0) {
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, msg_id, tgl_get_peer_type(M->to_id));
+
+ struct tg_temp_msg_data *msg_data = (struct tg_temp_msg_data*)malloc(sizeof(struct tg_temp_msg_data));
+ msg_data->M = M;
+ msg_data->TLS = TLS;
+ msg_data->send_timer = ecore_timer_add(3, on_msg_received_cb, msg_data);
+ } else {
+ if (M->media.type != tgl_message_media_none && (M->media.document.flags & FLAG_DOCUMENT_AUDIO)) {
+ M->message = strdup("Audio");
+ M->message_len = strlen("Audio");
+ } else if (M->media.type != tgl_message_media_none && (M->media.document.flags & FLAG_DOCUMENT_VIDEO)) {
+ M->message = strdup("Video");
+ M->message_len = strlen("Video");
+ }
+ insert_buddy_msg_to_db(M);
+ if(M->media.type != tgl_message_media_none) {
+ insert_media_info_to_db(M, "");
+ if (M->media.type != tgl_message_media_none && (M->media.document.flags & FLAG_DOCUMENT_VIDEO)) {
+ tgl_do_load_document_thumb(TLS, &(M->media.document), on_video_thumb_loaded, M);
+ return;
+ } else if (M->media.type != tgl_message_media_none && (M->media.document.flags & FLAG_DOCUMENT_AUDIO)) {
+
+ }
+ }
+ // inform to application
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
}
- // inform to application
- send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
+
}
} else if (tgl_get_peer_type(M->to_id) == TGL_PEER_ENCR_CHAT) {
M->message = NULL;
M->message_len = 0;
}
-
- insert_buddy_msg_to_db(M);
- if(M->media.type != tgl_message_media_none) {
- insert_media_info_to_db(M, "");
+ int user_id = 0;
+ if (tgl_get_peer_type(M->to_id) == TGL_PEER_USER) {
+ user_id = M->from_id.id;
+ } else if (tgl_get_peer_type(M->to_id) == TGL_PEER_CHAT) {
+ user_id = M->to_id.id;
+ }
+ char* tb_name = get_table_name_from_number(user_id);
+ int msg_id = insert_current_date_to_table(tb_name);
+ free(tb_name);
+ if (msg_id > 0) {
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, msg_id, tgl_get_peer_type(M->to_id));
+ struct tg_temp_msg_data *msg_data = (struct tg_temp_msg_data*)malloc(sizeof(struct tg_temp_msg_data));
+ msg_data->M = M;
+ msg_data->TLS = TLS;
+ msg_data->send_timer = ecore_timer_add(3, on_msg_received_cb, msg_data);
+ } else {
+ if (M->media.type != tgl_message_media_none && (M->media.document.flags & FLAG_DOCUMENT_AUDIO)) {
+ M->message = strdup("Audio");
+ M->message_len = strlen("Audio");
+ } else if (M->media.type != tgl_message_media_none && (M->media.document.flags & FLAG_DOCUMENT_VIDEO)) {
+ M->message = strdup("Video");
+ M->message_len = strlen("Video");
+ }
+ insert_buddy_msg_to_db(M);
+ if(M->media.type != tgl_message_media_none) {
+ insert_media_info_to_db(M, "");
+ if (M->media.type != tgl_message_media_none && (M->media.document.flags & FLAG_DOCUMENT_VIDEO)) {
+ tgl_do_load_document_thumb(TLS, &(M->media.document), on_video_thumb_loaded, M);
+ return;
+ }
+ }
+ // inform to application
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
}
- // inform to application
- send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
}
}
}
void tg_user_status_update(struct tgl_state *TLS, struct tgl_user *U)
{
+
if (tgl_get_peer_type (U->id) != TGL_PEER_USER) {
return;
}
// newly created user
} else {
// existing user
+
}
if (U->flags & FLAG_USER_SELF) {
{
struct tgl_chat *chat_info = callback_extra;
- if (!filename) {
- return;
+ if (filename) {
+ update_chat_info_to_db(chat_info, filename);
+ tgl_peer_t* UC = tgl_peer_get(TLS, chat_info->id);
+ update_peer_info_database(UC);
+ update_buddy_pic_db(filename, PEER_INFO_TABLE_NAME, chat_info->id.id);
+ send_buddy_profile_pic_updated_response(TLS->callback_data, chat_info->id.id, filename);
}
-
- update_chat_info_to_db(chat_info, filename);
- update_buddy_pic_db(filename, PEER_INFO_TABLE_NAME, chat_info->id.id);
- send_buddy_profile_pic_updated_response(TLS->callback_data, chat_info->id.id, filename);
}
void on_buddy_pic_loaded(struct tgl_state *TLS, void *callback_extra, int success, char *filename)
if (buddy && buddy->id.id == tg_data->id.id) {
if(filename) {
update_buddy_pic_db(filename, USER_INFO_TABLE_NAME, buddy->id.id);
+ update_buddy_pic_db(filename, BUDDY_INFO_TABLE_NAME, buddy->id.id);
send_buddy_profile_pic_updated_response(TLS->callback_data, buddy->id.id, filename);
}
-
return;
}
- if (!filename) {
- return;
+ if (filename) {
+ update_buddy_pic_db(filename, BUDDY_INFO_TABLE_NAME, buddy->id.id);
+ update_buddy_pic_db(filename, PEER_INFO_TABLE_NAME, buddy->id.id);
+ send_buddy_profile_pic_updated_response(TLS->callback_data, buddy->id.id, filename);
}
-
- update_buddy_pic_db(filename, BUDDY_INFO_TABLE_NAME, buddy->id.id);
- update_buddy_pic_db(filename, PEER_INFO_TABLE_NAME, buddy->id.id);
- send_buddy_profile_pic_updated_response(TLS->callback_data, buddy->id.id, filename);
}
#if 0
if (!chat_info) {
return;
}
+ if (!chat_info->user_list) {
+ tgl_do_get_chat_info(TLS, chat_info->id, 0, &on_chat_info_received, NULL);
+ return;
+ }
tg_data = TLS->callback_data;
tgl_do_load_photo(TLS, pic ,&on_chat_pic_loaded,chat_info);
}
free(msg_table);
-#if 0
- if (tg_data->is_group_creation_requested) {
- tgl_peer_t* UC;
- UC = tgl_peer_get(TLS, chat_info->id);
- // insert into peer table
- insert_peer_into_database(UC, 0, 0);
- tg_data->is_group_creation_requested = EINA_FALSE;
-
- /*************** insert service message ********************/
-
- char* msg_data = "new group created.";
- struct tgl_message msg;
- msg.from_id.id = 0;
- msg.from_id.type = 0;
- msg.date = 0;
- msg.flags = 0;
- msg.fwd_date = 0;
- msg.fwd_from_id.id = 0;
- msg.fwd_from_id.type = 0;
- msg.id = 0;
- msg.message = msg_data;
- msg.message_len = strlen (msg_data);
- msg.out = 0;
- msg.service = 0;
- msg.to_id.id = 0;
- msg.to_id.type = tg_data->id.type;
- msg.unread = 0;
- msg.media.type = -1;
- int t = time(NULL);
- insert_msg_into_db(&msg, msg_table, t);
- /***********************************************************/
- send_new_group_added_response(tg_data, chat_info->id.id);
-
- if (tg_data->new_group_icon) {
- tgl_do_set_chat_photo(TLS, chat_info->id, tg_data->new_group_icon, on_new_group_icon_loaded, chat_info);
- }
- }
-#endif
}
void on_buddy_info_loaded(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U)
if(!U) {
return;
}
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ if (U->id.id == tg_data->id.id) {
+ return;
+ }
+
//insert_buddy_into_db(BUDDY_INFO_TABLE_NAME, U);
struct tgl_photo* pic = &(U->photo);
if(pic) {
{
for (int i = size - 1; i >= 0; i--) {
struct tgl_user *buddy = contacts[i];
+
+ if (buddy->id.id == 777000 || buddy->id.id == 333000) {
+ continue;
+ }
+
+
char* msg_table = get_table_name_from_number(buddy->id.id);
create_buddy_msg_table(msg_table);
free(msg_table);
- tgl_do_get_user_info(TLS, buddy->id, 0, &on_buddy_info_loaded, NULL);
+ //tgl_do_get_user_info(TLS, buddy->id, 0, &on_buddy_info_loaded, NULL);
insert_buddy_into_db(BUDDY_INFO_TABLE_NAME, buddy);
}
// inform client that contact loading is done.
//send_contacts_load_done_response(EINA_TRUE);
+ send_contacts_and_chats_load_done_response(TLS->callback_data, EINA_TRUE);
+
+ for (int i = size - 1; i >= 0; i--) {
+ struct tgl_user *buddy = contacts[i];
+ tgl_do_get_user_info(TLS, buddy->id, 0, on_buddy_info_loaded, NULL);
+ }
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ //tg_data->is_loading_completed = EINA_TRUE;
+
+ send_response_for_server_connection_status(tg_data, tg_data->is_login_activated);
+ ecore_timer_add(5, on_send_unsent_messages_requested, TLS);
}
void on_contacts_and_chats_loaded(struct tgl_state *TLS, void *callback_extra, int success, int size, tgl_peer_id_t peers[], int last_msg_id[], int unread_count[])
// insert into peer table
insert_peer_into_database(UC, last_msg_id[i], unread_count[i]);
//struct tgl_user* buddy;
- struct tgl_chat* chat_info;
+ //struct tgl_chat* chat_info;
switch (tgl_get_peer_type(peers[i])) {
case TGL_PEER_USER:
-#if 0
- buddy = &(UC->user);
- if (buddy) {
- char* msg_table = get_table_name_from_number(buddy->id.id);
- create_buddy_msg_table(msg_table);
- free(msg_table);
- insert_buddy_into_db(BUDDY_INFO_TABLE_NAME, buddy);
- tgl_do_get_user_info(TLS, buddy->id, 0, &on_buddy_info_loaded, NULL);
- }
-#endif
+ // To-Do
break;
case TGL_PEER_CHAT:
- chat_info = &(UC->chat);
- tgl_do_get_chat_info(TLS, chat_info->id, 0, &on_chat_info_received, NULL);
+ // To-Do
+ //tgl_do_get_chat_info(TLS, peers[i], 0, &on_chat_info_received, NULL);
break;
case TGL_PEER_ENCR_CHAT:
+ // To-Do
+ break;
+ default:
break;
}
}
- send_contacts_and_chats_load_done_response(TLS->callback_data, EINA_TRUE);
+ tgl_do_update_contact_list(TLS, on_contacts_received, NULL);
}
void on_user_info_loaded(struct tgl_state *TLS, void *extra, int success, struct tgl_user *buddy)
// send contact list to add friends.
send_add_contacts_request();
} else {
- tgl_do_update_contact_list(TLS, on_contacts_received, NULL);
tgl_do_get_dialog_list(TLS, on_contacts_and_chats_loaded, NULL);
}
}
message->msg_state = TG_MESSAGE_STATE_SENT;
char* tb_name = get_table_name_from_number(message->to_id.id);
update_msg_into_db(message, tb_name, org_msg->id);
- if (message->media.type == tgl_message_media_photo) {
+
+ // delete message from unsent db
+ delete_message_from_unsent_db(org_msg->id);
+ delete_media_from_unsent_db(org_msg->id);
+
+ if (message->media.type == tgl_message_media_photo || message->media.type == tgl_message_media_document || message->media.type == tgl_message_media_geo) {
update_sent_media_info_in_db(message, (long long)org_msg->id);
}
send_message_sent_to_buddy_response(tg_data, message->to_id.id, message->id, tb_name, EINA_TRUE, tgl_get_peer_type(message->to_id));
free(tb_name);
+
+ if (message->media.type != tgl_message_media_none && (message->media.document.flags & FLAG_DOCUMENT_VIDEO)) {
+ //tgl_do_load_document_thumb(TLS, &(message->media.document), on_video_thumb_loaded, message);
+ }
+
}
} else {
if (org_msg) {
org_msg->msg_state = TG_MESSAGE_STATE_FAILED;
char* tb_name = get_table_name_from_number(org_msg->to_id.id);
update_msg_into_db(org_msg, tb_name, org_msg->id);
- if (org_msg->media.type == tgl_message_media_photo) {
+ if (org_msg->media.type == tgl_message_media_photo || org_msg->media.type == tgl_message_media_document || message->media.type == tgl_message_media_geo) {
update_sent_media_info_in_db(org_msg, (long long)org_msg->id);
}
send_message_sent_to_buddy_response(tg_data, org_msg->to_id.id, org_msg->id, tb_name, EINA_FALSE, tgl_get_peer_type(org_msg->to_id));
}
}
+void on_document_download_completed(struct tgl_state *TLS, void *callback_extra, int success, char *filename)
+{
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ struct tgl_document* doc_prop = (struct tgl_document*)callback_extra;
+ long long media_id = doc_prop->id;
+ int buddy_id = doc_prop->user_id;
+ int to_id = doc_prop->to_peer_id;
+ if (success) {
+ if(doc_prop && filename) {
+ update_receive_media_info_in_db(media_id, filename);
+ //send response to application
+ send_media_download_completed_response(tg_data, buddy_id, to_id, media_id, filename);
+ }
+ } else {
+ send_media_download_completed_response(tg_data, buddy_id, to_id, media_id, NULL);
+ }
+
+ if (doc_prop) {
+ if (doc_prop->caption) {
+ free(doc_prop->caption);
+ }
+ free(doc_prop);
+ }
+
+}
+
+void free_contact_data(Eina_List *contact_data)
+{
+ if (contact_data) {
+ for (int i = 0; i < eina_list_count(contact_data); i++) {
+ contact_data_s* contact = eina_list_nth(contact_data, i);
+ if (contact) {
+ if (contact->display_name) {
+ free(contact->display_name);
+ contact->display_name = NULL;
+ }
+ if (contact->first_name) {
+ free(contact->first_name);
+ contact->first_name = NULL;
+ }
+ if (contact->last_name) {
+ free(contact->last_name);
+ contact->last_name = NULL;
+ }
+ if (contact->phone_number) {
+ free(contact->phone_number);
+ contact->phone_number = NULL;
+ }
+ }
+ free(contact);
+ }
+ eina_list_free(contact_data);
+ }
+}
+
void on_contact_added(struct tgl_state *TLS,void *callback_extra, int success, int size, struct tgl_user *users[])
{
tg_engine_data_s* data = callback_extra;
} else {
tgl_do_get_dialog_list(TLS, on_contacts_and_chats_loaded, NULL);
+ free_contact_data(data->contact_list_to_add);
+ data->contact_list_to_add = NULL;
}
}
char* msg_table = get_table_name_from_number(M->to_id.id);
create_buddy_msg_table(msg_table);
- free(msg_table);
+ int msg_id = insert_current_date_to_table(msg_table);
tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
int msg_len = strlen(UC->user.first_name) + strlen(" changed profile photo") + 1;
char* creator_name = (char*)malloc(msg_len);
strcpy(creator_name, UC->user.first_name);
strcat(creator_name, " changed profile photo");
+
+
+ //send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id,msg_id, tgl_get_peer_type(M->to_id));
+ int cur_time = time(NULL);
+ M->id = cur_time;
M->message = creator_name;
M->message_len = msg_len;
M->unread = 1;
+ M->date = cur_time;
insert_buddy_msg_to_db(M);
free(creator_name);
-
+ free(msg_table);
struct tgl_photo *pic = &(M->action.photo);
if(pic) {
tgl_peer_t* UC = tgl_peer_get(TLS, M->to_id);
if (M->action.type == tgl_message_action_chat_create) {
char* msg_table = get_table_name_from_number(M->to_id.id);
create_buddy_msg_table(msg_table);
- free(msg_table);
+
+
+ int msg_id = insert_current_date_to_table(msg_table);
+ //send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id,msg_id, tgl_get_peer_type(M->to_id));
+
tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
int msg_len = strlen(UC->user.first_name) + strlen(" created the group") + 1;
char* creator_name = (char*)malloc(msg_len);
strcpy(creator_name, UC->user.first_name);
strcat(creator_name, " created the group");
+
+
+
+ int cur_time = time(NULL);
+ M->id = cur_time;
M->message = creator_name;
M->message_len = msg_len;
M->unread = 1;
- M->date = time(NULL);
+ M->date = cur_time;
+
insert_buddy_msg_to_db(M);
free(creator_name);
-
+ free(msg_table);
tgl_peer_t* chat_UC = tgl_peer_get(TLS, M->to_id);
chat_UC->chat.date = M->date;
insert_chat_info_to_db(&(chat_UC->chat), NULL);
}
}
+void on_set_profile_picture_response_received(struct tgl_state *TLS, void *callback_extra, int success)
+{
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ char *file_path = callback_extra;
+ if (success) {
+ // update db
+ update_buddy_pic_db(file_path, USER_INFO_TABLE_NAME, tg_data->id.id);
+ update_buddy_pic_db(file_path, BUDDY_INFO_TABLE_NAME, tg_data->id.id);
+ send_self_profile_picture_updated_response(tg_data, file_path, EINA_TRUE);
+ } else {
+ send_self_profile_picture_updated_response(tg_data, file_path, EINA_FALSE);
+ }
+ if (file_path) {
+ free(file_path);
+ }
+}
+void set_profile_picture(tg_engine_data_s *tg_data, int buddy_id, const char *file_path)
+{
+ if (file_path) {
+ char *org_path = strdup(file_path);
+ tgl_do_set_profile_photo(tgl_engine_get_TLS(), (char*)file_path, on_set_profile_picture_response_received, org_path);
+ }
+}
+
+void on_set_new_chat_title_response_received(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M)
+{
+ if (success) {
+ char *type_of_change = NULL;
+ if (M && M->action.type == tgl_message_action_chat_edit_title) {
+ type_of_change = strdup("edit_title");
+ tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
+ int msg_len = strlen(UC->user.first_name) + strlen(" changed the chat title") + 1;
+ char* creator_name = (char*)malloc(msg_len);
+ strcpy(creator_name, UC->user.first_name);
+ strcat(creator_name, " changed the chat title");
+
+ int cur_time = time(NULL);
+ M->id = cur_time;
+ M->message = creator_name;
+ M->message_len = msg_len;
+ M->unread = 1;
+ M->date = cur_time;
+ insert_buddy_msg_to_db(M);
+ free(creator_name);
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
+ tgl_do_get_chat_info(TLS, M->to_id, 0, &on_group_chat_info_updated, type_of_change);
+ }
+ } else {
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ struct tgl_chat *chat_info = (struct tgl_chat*)callback_extra;
+ send_group_chat_rename_response(tg_data, chat_info->id.id, EINA_FALSE);
+ }
+}
+
+void set_group_chat_new_title(tg_engine_data_s *tg_data, int buddy_id, const char *new_title)
+{
+ if (new_title) {
+ tgl_peer_id_t peer_id;
+ peer_id.id = buddy_id;
+ peer_id.type = TGL_PEER_CHAT;
+
+ tgl_peer_t* UC = tgl_peer_get(tgl_engine_get_TLS(), peer_id);
+ struct tgl_chat *chat_info = &(UC->chat);
+ tgl_do_rename_chat(tgl_engine_get_TLS(), chat_info->id, (char*)new_title, on_set_new_chat_title_response_received, chat_info);
+ }
+}
+
+void on_new_buddy_added_to_chat_response_received(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M)
+{
+ if (success) {
+ char *type_of_change = NULL;
+ if (M && M->action.type == tgl_message_action_chat_add_user) {
+ type_of_change = strdup("add_user");
+ tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
+
+ tgl_peer_id_t added_id;
+ added_id.id = M->action.user;
+ added_id.type = TGL_PEER_USER;
+
+ tgl_peer_t* added_UC = tgl_peer_get(TLS, added_id);
+ char* new_user_name = replace(added_UC->print_name, '_', " ");
+ int msg_len = strlen(UC->user.first_name) + strlen(" added ") + strlen(new_user_name) + 1;
+ char* creator_name = (char*)malloc(msg_len);
+ strcpy(creator_name, UC->user.first_name);
+ strcat(creator_name, " added ");
+ strcat(creator_name, new_user_name);
+ free(new_user_name);
+
+ int cur_time = time(NULL);
+ M->id = cur_time;
+ M->message = creator_name;
+ M->message_len = msg_len;
+ M->unread = 1;
+ M->date = cur_time;
+ insert_buddy_msg_to_db(M);
+ free(creator_name);
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
+ tgl_do_get_chat_info(TLS, M->to_id, 0, &on_group_chat_info_updated, type_of_change);
+ }
+ } else {
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ struct tgl_chat *chat_info = (struct tgl_chat*)callback_extra;
+ send_group_chat_new_buddy_response(tg_data, chat_info->id.id, EINA_FALSE);
+ }
+}
+
+void set_group_chat_add_new_buddy(tg_engine_data_s *tg_data, int s_buddy_id, int s_chat_id)
+{
+ tgl_peer_id_t chat_id;
+ chat_id.id = s_chat_id;
+ chat_id.type = TGL_PEER_CHAT;
+
+ tgl_peer_id_t buddy_id;
+ buddy_id.id = s_buddy_id;
+ buddy_id.type = TGL_PEER_USER;
+
+ tgl_peer_t* UC = tgl_peer_get(tgl_engine_get_TLS(), chat_id);
+ struct tgl_chat *chat_info = &(UC->chat);
+ tgl_do_add_user_to_chat(tgl_engine_get_TLS(), chat_id, buddy_id, 100, on_new_buddy_added_to_chat_response_received, chat_info);
+}
+
+
+void on_buddy_removed_from_chat_response_received(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M)
+{
+ if (success) {
+ char *type_of_change = NULL;
+ if (M && M->action.type == tgl_message_action_chat_delete_user) {
+ type_of_change = strdup("delete_user");
+ tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
+ tgl_peer_id_t added_id;
+ added_id.id = M->action.user;
+ added_id.type = TGL_PEER_USER;
+
+ tgl_peer_t* added_UC = tgl_peer_get(TLS, added_id);
+ char* new_user_name = replace(added_UC->print_name, '_', " ");
+ int msg_len = strlen(UC->user.first_name) + strlen(" removed ") + strlen(new_user_name) + 1;
+ char* creator_name = (char*)malloc(msg_len);
+ strcpy(creator_name, UC->user.first_name);
+ strcat(creator_name, " removed ");
+ strcat(creator_name, new_user_name);
+ free(new_user_name);
+ int cur_time = time(NULL);
+ M->id = cur_time;
+ M->message = creator_name;
+ M->message_len = msg_len;
+ M->unread = 1;
+ M->date = cur_time;
+ insert_buddy_msg_to_db(M);
+ free(creator_name);
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
+ tgl_do_get_chat_info(TLS, M->to_id, 0, &on_group_chat_info_updated, type_of_change);
+ }
+ } else {
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ struct tgl_chat *chat_info = (struct tgl_chat*)callback_extra;
+ send_group_chat_delete_buddy_response(tg_data, chat_info->id.id, EINA_FALSE);
+ }
+}
+
+void set_group_chat_remove_buddy(tg_engine_data_s *tg_data, int s_buddy_id, int s_chat_id)
+{
+ tgl_peer_id_t chat_id;
+ chat_id.id = s_chat_id;
+ chat_id.type = TGL_PEER_CHAT;
+
+ tgl_peer_id_t buddy_id;
+ buddy_id.id = s_buddy_id;
+ buddy_id.type = TGL_PEER_USER;
+
+ tgl_peer_t* UC = tgl_peer_get(tgl_engine_get_TLS(), chat_id);
+ struct tgl_chat *chat_info = &(UC->chat);
+ tgl_do_del_user_from_chat(tgl_engine_get_TLS(), chat_id, buddy_id, on_buddy_removed_from_chat_response_received, chat_info);
+}
+
+void set_group_chat_profile_picture(tg_engine_data_s *tg_data, int buddy_id, const char *file_path)
+{
+ if (file_path) {
+ tgl_peer_id_t peer_id;
+ peer_id.id = buddy_id;
+ peer_id.type = TGL_PEER_CHAT;
+
+ tgl_peer_t* UC = tgl_peer_get(tgl_engine_get_TLS(), peer_id);
+ struct tgl_chat *chat_info = &(UC->chat);
+ tgl_do_set_chat_photo(tgl_engine_get_TLS(), chat_info->id, (char*)file_path, on_new_group_icon_loaded, chat_info);
+ }
+}
+
+void on_set_username_response_received(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *buddy)
+{
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ char *org_username = callback_extra;
+ if (success) {
+ // update db
+ insert_buddy_into_db(USER_INFO_TABLE_NAME, buddy);
+ insert_buddy_into_db(BUDDY_INFO_TABLE_NAME, buddy);
+ send_self_user_name_updated_response(tg_data, org_username, EINA_TRUE);
+ } else {
+ send_self_user_name_updated_response(tg_data, org_username, EINA_FALSE);
+ }
+ if (org_username) {
+ free(org_username);
+ }
+}
+
+void set_user_name(tg_engine_data_s *tg_data, int buddy_id, const char *username)
+{
+ if (username) {
+ char *org_username = strdup(username);
+ tgl_do_set_username(tgl_engine_get_TLS(), username, on_set_username_response_received, org_username);
+ }
+}
+
+
void create_new_group(tg_engine_data_s *tg_data, Eina_List* buddy_ids, const char *group_name, const char *group_icon)
{
if (!buddy_ids || ! group_name) {
void media_download_request(tg_engine_data_s *tg_data, int buddy_id, long long media_id)
{
// get media details by mediaid
- int media_type;
- void *media;
+ struct tgl_media* img_details = get_media_details_from_db(media_id);
- media = tg_db_get_media_info(MEDIA_INFO_TABLE_NAME, media_id, &media_type);
- if (!media) {
+ if(!img_details) {
send_media_download_completed_response(tg_data, -1, buddy_id, media_id, NULL);
return;
- }
-
- if (media_type == tgl_message_media_photo) {
- struct tgl_photo *photo = media;
- tgl_do_load_photo(s_info.TLS, photo, &on_image_download_completed, photo);
- /**
- * @note
- * After this, what happens to "photo"?
- * Is it released automatically?
- */
- } else if (media_type == tgl_message_media_document) {
- /**
- * @todo
- * implements me
- */
} else {
+ if (img_details->media_type == tgl_message_media_none) {
+
+ } else if (img_details->media_type == tgl_message_media_photo) {
+
+ struct tgl_photo* photo_prop = (struct tgl_photo*)malloc(sizeof(struct tgl_photo));
+ photo_prop->id = img_details->media_id;
+ photo_prop->access_hash = img_details->access_hash;
+ photo_prop->user_id = img_details->user_id;
+ photo_prop->date = img_details->date;
+ photo_prop->caption = img_details->caption;
+ photo_prop->geo.latitude = atof(img_details->latitude);
+ photo_prop->geo.longitude = atof(img_details->longitude);
+ photo_prop->sizes_num = img_details->sizes;
+
+ photo_prop->sizes = talloc(sizeof(struct tgl_photo_size) * photo_prop->sizes_num);
+ int i;
+ for (i = 0; i < photo_prop->sizes_num; i++) {
+
+ if (i == 0) {
+ photo_prop->sizes[i].w = img_details->photo_width1;
+ photo_prop->sizes[i].h = img_details->photo_height1;
+ photo_prop->sizes[i].size = img_details->photo_size1;
+ if(img_details->photo_data1) {
+ photo_prop->sizes[i].data = strdup(img_details->photo_data1);
+ }
+ if(img_details->photo_type1) {
+ photo_prop->sizes[i].type = strdup(img_details->photo_type1);
+ }
+ photo_prop->sizes[i].loc.dc = img_details->photo_loc_dc1;
+ photo_prop->sizes[i].loc.local_id = img_details->photo_loc_id1;
+ photo_prop->sizes[i].loc.secret = img_details->photo_loc_sec1;
+ photo_prop->sizes[i].loc.volume = img_details->photo_loc_vol1;
+ } else if (i == 1) {
+
+ photo_prop->sizes[i].w = img_details->photo_width2;
+ photo_prop->sizes[i].h = img_details->photo_height2;
+ photo_prop->sizes[i].size = img_details->photo_size2;
+ if(img_details->photo_data2) {
+ photo_prop->sizes[i].data = strdup(img_details->photo_data2);
+ }
+ if(img_details->photo_type2) {
+ photo_prop->sizes[i].type = strdup(img_details->photo_type2);
+ }
+ photo_prop->sizes[i].loc.dc = img_details->photo_loc_dc2;
+ photo_prop->sizes[i].loc.local_id = img_details->photo_loc_id2;
+ photo_prop->sizes[i].loc.secret = img_details->photo_loc_sec2;
+ photo_prop->sizes[i].loc.volume = img_details->photo_loc_vol2;
+
+ } else if (i == 2) {
+
+ photo_prop->sizes[i].w = img_details->photo_width3;
+ photo_prop->sizes[i].h = img_details->photo_height3;
+ photo_prop->sizes[i].size = img_details->photo_size3;
+ if(img_details->photo_data3) {
+ photo_prop->sizes[i].data = strdup(img_details->photo_data3);
+ }
+ if(img_details->photo_type3) {
+ photo_prop->sizes[i].type = strdup(img_details->photo_type3);
+ }
+ photo_prop->sizes[i].loc.dc = img_details->photo_loc_dc3;
+ photo_prop->sizes[i].loc.local_id = img_details->photo_loc_id3;
+ photo_prop->sizes[i].loc.secret = img_details->photo_loc_sec3;
+ photo_prop->sizes[i].loc.volume = img_details->photo_loc_vol3;
+
+ } else if (i == 3) {
+
+ photo_prop->sizes[i].w = img_details->photo_width4;
+ photo_prop->sizes[i].h = img_details->photo_height4;
+ photo_prop->sizes[i].size = img_details->photo_size4;
+ if(img_details->photo_data4) {
+ photo_prop->sizes[i].data = strdup(img_details->photo_data4);
+ }
+ if(img_details->photo_type4) {
+ photo_prop->sizes[i].type = strdup(img_details->photo_type4);
+ }
+ photo_prop->sizes[i].loc.dc = img_details->photo_loc_dc4;
+ photo_prop->sizes[i].loc.local_id = img_details->photo_loc_id4;
+ photo_prop->sizes[i].loc.secret = img_details->photo_loc_sec4;
+ photo_prop->sizes[i].loc.volume = img_details->photo_loc_vol4;
+
+ } else {
+
+ }
+ }
+ photo_prop->to_peer_id = buddy_id;
+ tgl_do_load_photo(s_info.TLS, photo_prop ,&on_image_download_completed, photo_prop);
+
+ } else if (img_details->media_type == tgl_message_media_document) {
+ struct tgl_document* doc_prop = (struct tgl_document*)malloc(sizeof(struct tgl_document));
+ doc_prop->id = img_details->media_id;;
+ doc_prop->access_hash = img_details->access_hash;
+ doc_prop->user_id = img_details->user_id;
+ doc_prop->date = img_details->date;
+ doc_prop->size = img_details->sizes;
+ doc_prop->mime_type = NULL;
+ doc_prop->dc_id = img_details->doc_dc;
+ doc_prop->to_peer_id = buddy_id;
+
+ if (img_details->caption) {
+ doc_prop->caption = strdup(img_details->caption);
+ } else {
+ doc_prop->caption = NULL;
+ }
+
+
+ if (!(img_details->mime_type) || strlen(img_details->mime_type) <= 0) {
+
+ if (img_details->doc_type && strlen(img_details->doc_type) > 0) {
+ if (strstr(img_details->doc_type, "video") != NULL) {
+ doc_prop->mime_type = strdup("video/mp4");
+ } else if (strstr(img_details->doc_type, "audio") != NULL) {
+ doc_prop->mime_type = strdup("audio/wav");
+ }
+ }
+ } else {
+ doc_prop->mime_type = img_details->mime_type;
+ }
+
+ if (strstr(img_details->doc_type, "video") != NULL) {
+ doc_prop->flags = FLAG_DOCUMENT_VIDEO;
+ } else if (strstr(img_details->doc_type, "audio") != NULL) {
+ doc_prop->flags = FLAG_DOCUMENT_AUDIO;
+ }
+
+ tgl_do_load_document(s_info.TLS, doc_prop ,on_document_download_completed, doc_prop);
+
+
+ } else {
+
+ }
+
+ // delete image details
+
+ if (img_details->caption) {
+ free(img_details->caption);
+ }
+ if (img_details->longitude) {
+ free(img_details->longitude);
+ }
+ if (img_details->latitude) {
+ free(img_details->latitude);
+ }
+ if (img_details->phone_no) {
+ free(img_details->phone_no);
+ }
+ if (img_details->first_name) {
+ free(img_details->first_name);
+ }
+ if (img_details->last_name) {
+ free(img_details->last_name);
+ }
+ if (img_details->file_path) {
+ free(img_details->file_path);
+ }
+ if (img_details->photo_type1) {
+ free(img_details->photo_type1);
+ }
+ if (img_details->photo_data1) {
+ free(img_details->photo_data1);
+ }
+ if (img_details->photo_type2) {
+ free(img_details->photo_type2);
+ }
+ if (img_details->photo_data2) {
+ free(img_details->photo_data2);
+ }
+ if (img_details->photo_type3) {
+ free(img_details->photo_type3);
+ }
+ if (img_details->photo_data3) {
+ free(img_details->photo_data3);
+ }
+ if (img_details->photo_type4) {
+ free(img_details->photo_type4);
+ }
+ if (img_details->photo_data4) {
+ free(img_details->photo_data4);
+ }
+ if (img_details->mime_type) {
+ free(img_details->mime_type);
+ }
+ if (img_details->doc_type) {
+ free(img_details->doc_type);
+ }
+ if (img_details->doc_thumb_path) {
+ free(img_details->doc_thumb_path);
+ }
+
}
}
tgl_do_mark_read(s_info.TLS, chat_id, &on_mark_read_callback , (void*)(&chat_id));
}
+
+void on_user_block_response(struct tgl_state *TLS, void *callback_extra, int success)
+{
+ int buddy_id = (int)callback_extra;
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ if (success) {
+ // update database
+ int blocked = 1;
+ update_buddy_block_db(BUDDY_INFO_TABLE_NAME, buddy_id, blocked);
+ send_buddy_blocked_response(tg_data, buddy_id, EINA_TRUE);
+ } else {
+ send_buddy_blocked_response(tg_data, buddy_id, EINA_FALSE);
+ }
+}
+
+void on_user_unblock_response(struct tgl_state *TLS, void *callback_extra, int success)
+{
+ int buddy_id = (int)callback_extra;
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ if (success) {
+ int blocked = 0;
+ update_buddy_block_db(BUDDY_INFO_TABLE_NAME, buddy_id, blocked);
+ send_buddy_unblocked_response(tg_data, buddy_id, EINA_TRUE);
+ } else {
+ send_buddy_unblocked_response(tg_data, buddy_id, EINA_FALSE);
+ }
+}
+
+void on_user_delete_response(struct tgl_state *TLS, void *callback_extra, int success)
+{
+ int buddy_id = (int)callback_extra;
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ if (success) {
+ // update database
+ // delete from peer table
+ // delete from buddy table
+ // delete chat items
+#if 0
+ //delete_chat_from_db(buddy_id);
+ //delete_buddy_from_db(buddy_id);
+ //char* msg_table = get_table_name_from_number(buddy_id);
+ //drop_table(msg_table);
+ //free(msg_table);
+#endif
+ int deleted = 1;
+ update_buddy_delete_db(BUDDY_INFO_TABLE_NAME, buddy_id, deleted);
+ send_buddy_deleted_response(tg_data, buddy_id, EINA_TRUE);
+ } else {
+ send_buddy_deleted_response(tg_data, buddy_id, EINA_FALSE);
+ }
+}
+
+
+void on_buddy_readded(struct tgl_state *TLS,void *callback_extra, int success, int size, struct tgl_user *users[])
+{
+ int buddy_id = (int)callback_extra;
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ if (success) {
+ int deleted = 0;
+ update_buddy_delete_db(BUDDY_INFO_TABLE_NAME, buddy_id, deleted);
+ send_buddy_readded_response(tg_data, buddy_id, EINA_TRUE);
+ } else {
+ send_buddy_readded_response(tg_data, buddy_id, EINA_FALSE);
+ }
+}
+
+void do_add_buddy(int buddy_id)
+{
+ char *first_name = NULL;
+ char *last_name = NULL;
+ char *phone_num = NULL;
+ get_buddy_contact_details_from_db(buddy_id, &first_name, &last_name, &phone_num);
+ if (!last_name) {
+ last_name = "";
+ }
+
+ if (first_name && last_name && phone_num) {
+ tgl_do_add_contact(s_info.TLS, phone_num, first_name, last_name, 0, on_buddy_readded, (void*)(buddy_id));
+ }
+}
+
+
+void do_delete_buddy(int buddy_id)
+{
+ tgl_peer_id_t peer_id;
+ peer_id.id = buddy_id;
+ peer_id.type = TGL_PEER_USER;
+ tgl_do_del_contact(s_info.TLS, peer_id, &on_user_delete_response , (void*)(buddy_id));
+}
+
+void do_block_buddy(int buddy_id)
+{
+ tgl_peer_id_t peer_id;
+ peer_id.id = buddy_id;
+ peer_id.type = TGL_PEER_USER;
+ tgl_do_block_user(s_info.TLS, peer_id, &on_user_block_response , (void*)(buddy_id));
+}
+
+void do_unblock_buddy(int buddy_id)
+{
+ tgl_peer_id_t peer_id;
+ peer_id.id = buddy_id;
+ peer_id.type = TGL_PEER_USER;
+ tgl_do_unblock_user(s_info.TLS, peer_id, &on_user_unblock_response , (void*)(buddy_id));
+}
+
+void on_group_chat_delete_reponse(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M)
+{
+ int chat_id = (int)callback_extra;
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ if (success) {
+ // update database
+ // delete from peer table
+ delete_chat_from_db(chat_id);
+ char* msg_table = get_table_name_from_number(chat_id);
+ drop_table(msg_table);
+ free(msg_table);
+ send_group_chat_deleted_response(tg_data, chat_id, EINA_TRUE);
+ } else {
+ send_group_chat_deleted_response(tg_data, chat_id, EINA_FALSE);
+ }
+}
+
+void leave_group_chat(tg_engine_data_s *tg_data, int group_chat_id)
+{
+ tgl_peer_id_t chat_id;
+ chat_id.id = group_chat_id;
+ chat_id.type = TGL_PEER_CHAT;
+
+ tgl_peer_id_t self_id = tg_data->id;
+
+ tgl_do_del_user_from_chat(s_info.TLS, chat_id, self_id, on_group_chat_delete_reponse, (void*)(group_chat_id));
+}
+
void send_message_to_buddy(int buddy_id, int message_id, int msg_type, char *msg_data, int type_of_chat)
{
// get type of chat from buddy_id.
-
char *msg_table = get_table_name_from_number(buddy_id);
struct tgl_message* msg = get_message_from_message_table(message_id, msg_table);
void send_media_to_buddy(int buddy_id, int message_id, int media_id, int msg_type, char *file_path, int type_of_chat)
{
-#if 0
- int t = time(NULL);
- struct tgl_message msg;
- msg.from_id.id = s_info.tg_data->id.id;
- msg.from_id.type = s_info.tg_data->id.type;
- msg.date = 0;
- msg.flags = 0;
- msg.fwd_date = 0;
- msg.fwd_from_id.id = 0;
- msg.fwd_from_id.type = 0;
- msg.id = 0;
- msg.message = "";
- msg.message_len = 0;
- msg.out = 0;
- msg.service = 0;
- msg.to_id.id = buddy_id;
- msg.to_id.type = s_info.tg_data->id.type;
- msg.unread = 0;
- msg.media.type = msg_type;
- msg.media.photo.id = (long long)t;
-
- char *msg_table = get_table_name_from_number(buddy_id);
- insert_msg_into_db(&msg, msg_table, t);
- insert_media_info_to_db(&msg, file_path);
- tgl_do_send_document(TLS, -1, msg.to_id, file_path, &on_message_sent_to_buddy, (void*) (t));
- free(msg_table);
-#else
-
char *msg_table = get_table_name_from_number(buddy_id);
struct tgl_message* msg = get_message_from_message_table(message_id, msg_table);
msg->from_id.type = TGL_PEER_USER;
msg->to_id.type = TGL_PEER_USER;
-
if (msg->media.type == tgl_message_media_photo) {
tgl_do_send_document(s_info.TLS, -1, msg->to_id, file_path, &on_message_sent_to_buddy, (void*) (msg));
- }
+ } else if (msg->media.type == tgl_message_media_document) {
+ char *extn = strrchr(file_path, '.');
+ if (extn) {
+ extn = replace(extn, '.', "");
+ }
+ char *mime_type = NULL;;
+ if (extn) {
+ mime_type_get_mime_type(extn, &mime_type);
+ }
+ if (strstr(mime_type, "video") != NULL) {
+
+ char* thumb_path = get_video_thumb_path_from_db(media_id);
+ tgl_do_send_video(s_info.TLS, -2, msg->to_id, file_path, thumb_path, &on_message_sent_to_buddy, (void*) (msg));
+ if (thumb_path) {
+ free(thumb_path);
+ thumb_path = NULL;
+ }
+ } else if (strstr(mime_type, "audio") != NULL) {
+ tgl_do_send_audio(s_info.TLS, msg->to_id, file_path, &on_message_sent_to_buddy, (void*) (msg));
+ } else {
+
+ }
+ } else if (msg->media.type == tgl_message_media_geo) {
+ char *latitude = NULL;
+ char *longitude = NULL;
+ get_geo_location_from_db(media_id, &latitude, &longitude);
+ if (latitude && longitude) {
+ tgl_do_send_location(s_info.TLS, msg->to_id, strtod(latitude, NULL), strtod(longitude, NULL), &on_message_sent_to_buddy, (void*) (msg));
+ }
+ } else if (msg->media.type == tgl_message_media_contact) {
+ char *first_name = NULL;
+ char *last_name = NULL;
+ char *phone_num = NULL;
+ get_contact_details_from_db(media_id, &first_name, &last_name, &phone_num);
+ if (first_name && last_name && phone_num) {
+ tgl_do_send_contact(s_info.TLS, msg->to_id, first_name, strlen(first_name), last_name, strlen(last_name), phone_num, strlen(phone_num), &on_message_sent_to_buddy, (void*) (msg));
+ }
+ }
} else if (type_of_chat == TGL_PEER_CHAT) {
msg->from_id.type = TGL_PEER_CHAT;
if (msg->media.type == tgl_message_media_photo) {
tgl_do_send_document(s_info.TLS, -1, msg->to_id, file_path, &on_message_sent_to_buddy, (void*) (msg));
+ } else if (msg->media.type == tgl_message_media_document) {
+
+
+ char *extn = strrchr(file_path, '.');
+ if (extn) {
+ extn = replace(extn, '.', "");
+ }
+ char *mime_type = NULL;;
+ if (extn) {
+ mime_type_get_mime_type(extn, &mime_type);
+ }
+
+ if (strstr(mime_type, "video") != NULL) {
+
+ char* thumb_path = get_video_thumb_path_from_db(media_id);
+ tgl_do_send_video(s_info.TLS, -2, msg->to_id, file_path, thumb_path, &on_message_sent_to_buddy, (void*) (msg));
+ if (thumb_path) {
+ free(thumb_path);
+ thumb_path = NULL;
+ }
+ } else if (strstr(mime_type, "audio") != NULL) {
+ tgl_do_send_audio(s_info.TLS, msg->to_id, file_path, &on_message_sent_to_buddy, (void*) (msg));
+ } else {
+
+ }
+ } else if (msg->media.type == tgl_message_media_geo) {
+ char *latitude = NULL;
+ char *longitude = NULL;
+ get_geo_location_from_db(media_id, &latitude, &longitude);
+ if (latitude && longitude) {
+ tgl_do_send_location(s_info.TLS, msg->to_id, strtod(latitude, NULL), strtod(longitude, NULL), &on_message_sent_to_buddy, (void*) (msg));
+ }
}
}
free(msg_table);
-#endif
-}
-
-static char *ui_utils_get_resource(const char *res_name)
-{
- static char res_path[PATH_MAX] = {'\0'};
- char *path;
-
- path = app_get_resource_path();
- if (!path) {
- return NULL;
- }
-
- snprintf(res_path, PATH_MAX, "%s%s", path, res_name);
- free(path);
-
- return res_path;
}
void check_type_sizes(void)
}
if (str_empty(s_info.config_directory)) {
- s_info.config_directory = DEFAULT_TELEGRAM_PATH; // specific path for tizen application.
+ s_info.config_directory = strdup(DEFAULT_TELEGRAM_PATH); // specific path for tizen application.
}
struct stat st = {0};
#include <Elementary.h>
#include <efl_extension.h>
#include <net_connection.h>
+#include <notification.h>
#define PROGNAME "telegram-tizen"
#define VERSION "0.01"
#define TELEGRAM_CLI_VERSION "1.0.0"
#define CONFIG_DIRECTORY_MODE 0700
#define DEFAULT_RSA_FILE_NAME "server.pub"
+#define DEFAULT_TELEGRAM_ICON "tg_icon.png"
#define TELEGRAM_CLI_APP_HASH "8b5082937b2eb8814559291b93caa8a5"
#define TELEGRAM_CLI_APP_ID 26793
extern void init_tl_engine();
extern void write_auth_file(void);
+extern void tgl_engine_var_init(void);
+extern void tgl_engine_var_free(void);
extern char *tgl_engine_get_auth_key_filename(void);
extern char *tgl_engine_get_state_filename(void);
extern char *tgl_engine_get_secret_chat_filename(void);
TG_ENGINE_STATE_CODE_REQUEST
} tg_engine_state;
+typedef struct sent_message_data {
+ char *app_name;
+ char *command;
+ char *buddy_id;
+ char *message_id;
+ char *message_type;
+ char *message_data;
+ char *type_of_chat;
+} sent_message_data_s;
+
+typedef struct sent_media_data {
+ char *app_name;
+ char *command;
+ char *buddy_id;
+ char *message_id;
+ char *media_id;
+ char *message_type;
+ char *file_path;
+ char *type_of_chat;
+} sent_media_data_s;
+
typedef struct tg_engine_data {
tgl_peer_id_t id;
char *phone_number;
Eina_Bool is_group_creation_requested;
char *new_group_icon;
Ecore_Idler *lazy_init_idler;
+ char* mhash;
+ //Eina_Bool is_loading_completed;
+ notification_h s_notififcation;
} tg_engine_data_s;
typedef struct contact_data {
extern void media_download_request(tg_engine_data_s *tg_data, int buddy_id, long long media_id);
extern void add_contacts_to_user(tg_engine_data_s *tg_data, int size, Eina_List* contact_list);
extern void create_new_group(tg_engine_data_s *tg_data, Eina_List* buddy_ids, const char* group_name, const char* group_icon);
+extern void set_profile_picture(tg_engine_data_s *tg_data, int buddy_id, const char *file_path);
+extern void set_user_name(tg_engine_data_s *tg_data, int buddy_id, const char *username);
+extern void request_for_code_via_call(struct tgl_state *TLS, char* phone_no, Eina_Bool trough_sms);
+extern void free_contact_data(Eina_List *contact_data);
+extern void leave_group_chat(tg_engine_data_s *tg_data, int group_chat_id);
+extern void do_delete_buddy(int buddy_id);
+extern void do_add_buddy(int buddy_id);
+extern void do_unblock_buddy(int buddy_id);
+extern void do_block_buddy(int buddy_id);
+extern void set_group_chat_profile_picture(tg_engine_data_s *tg_data, int buddy_id, const char *file_path);
+extern void set_group_chat_new_title(tg_engine_data_s *tg_data, int buddy_id, const char *new_title);
+extern void set_group_chat_add_new_buddy(tg_engine_data_s *tg_data, int s_buddy_id, int s_chat_id);
+extern void set_group_chat_remove_buddy(tg_engine_data_s *tg_data, int s_buddy_id, int s_chat_id);
#endif /* TG_ENGINE_H_ */
-#include <stdio.h>
-#include <stdarg.h>
+/*
+ * tg_common.c
+ *
+ * Created on: Oct 6, 2015
+ * Author: sandeep
+ */
+
#include "tg_common.h"
-const char *tg_common_to_string(const char *fmt, ...)
+void tg_notification_create(tg_engine_data_s* tg_data, char * icon_path, const char *title, char *content, char *sound_path, char *app_id)
{
- va_list vp;
- static char string_buffer[256];
- int ret;
+ int err = NOTIFICATION_ERROR_NONE;
+ if (tg_data && tg_data->s_notififcation) {
+ //err = notification_delete(tg_data->s_notififcation);
+ err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
+ tg_data->s_notififcation = NULL;
+ }
+
+ bundle *b = NULL;
+ notification_error_e ret = NOTIFICATION_ERROR_NONE;
+ tg_data->s_notififcation = notification_create(NOTIFICATION_TYPE_NOTI);
+ ret = notification_set_property(tg_data->s_notififcation, NOTIFICATION_PROP_DISABLE_TICKERNOTI);
+ ret = notification_set_layout(tg_data->s_notififcation, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
+
+ if (icon_path) {
+ ret = notification_set_image(tg_data->s_notififcation, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
+ }
+ if (title) {
+ ret = notification_set_text(tg_data->s_notififcation, NOTIFICATION_TEXT_TYPE_TITLE, title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ }
+ if (content) {
+ ret = notification_set_text(tg_data->s_notififcation, NOTIFICATION_TEXT_TYPE_CONTENT, content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ }
- va_start(vp, fmt);
- ret = vsnprintf(string_buffer, sizeof(string_buffer) - 1, fmt, vp);
- va_end(vp);
+ if (sound_path) {
+ ret = notification_set_sound(tg_data->s_notififcation, NOTIFICATION_SOUND_TYPE_USER_DATA, sound_path);
+ } else {
+ ret = notification_set_sound(tg_data->s_notififcation, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL);
+ }
+ ret = notification_set_vibration(tg_data->s_notififcation, NOTIFICATION_VIBRATION_TYPE_DEFAULT, NULL);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ //failed
+ }
+ app_control_h service = NULL;
+ app_control_create(&service);
+ app_control_set_app_id(service, app_id);
+ app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT);
- return ret <= 0 ? NULL : string_buffer;
+ ret = notification_set_launch_option(tg_data->s_notififcation, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, service);
+ if (ret != NOTIFICATION_ERROR_NONE) {
+ //failed
+ }
+ notification_post(tg_data->s_notififcation);
+ app_control_destroy(service);
+ bundle_free(b);
+ ret = notification_free(tg_data->s_notififcation);
+ if(ret != NOTIFICATION_ERROR_NONE) {
+ }
+ return;
}
-/* End of a file */
+char *replace(const char *s, char ch, const char *repl)
+{
+ int count = 0;
+ const char *t;
+
+ for(t = s; *t; t++) {
+ count += (*t == ch);
+ }
+
+ size_t rlen = strlen(repl);
+ char *res = malloc(strlen(s) + (rlen - 1) * count + 1);
+ char *ptr = res;
+
+ for(t = s; *t; t++) {
+ if(*t == ch) {
+ memcpy(ptr, repl, rlen);
+ ptr += rlen;
+ } else {
+ *ptr++ = *t;
+ }
+ }
+
+ *ptr = 0;
+ return res;
+}
+
+char *get_table_name_from_number(const int id)
+{
+ char *msg_table;
+
+ msg_table = (char *)malloc(32);
+ if (!msg_table) {
+ return NULL;
+ }
+
+ snprintf(msg_table, 32, "tg_%d_msg", id);
+
+ return msg_table;
+}
+
+char *ui_utils_get_resource(const char *res_name)
+{
+ static char res_path[PATH_MAX] = {'\0'};
+ char *path;
+
+ path = app_get_resource_path();
+ if (!path) {
+ return NULL;
+ }
+
+ snprintf(res_path, PATH_MAX, "%s%s", path, res_name);
+ free(path);
+
+ return res_path;
+}
#ifndef TG_COMMON_H_
#define TG_COMMON_H_
-
#include <Elementary.h>
+#include <app_control.h>
+#include <notification.h>
+#include "tg_engine.h"
-#define DEFAULT_TELEGRAM_PATH "/opt/usr/media/telegram/"
-#define DEFAULT_TG_DATABASE_PATH "/opt/usr/media/telegram/tg_data_base.db"
+#define TELEGRAM_APP_ID "org.tizen.telegramtizen"
typedef enum MESSAGE_STATE {
TG_MESSAGE_STATE_SENDING = 1,
TG_MESSAGE_STATE_UNKNOWN
} TG_MESSAGE_STATE;
-extern const char *tg_common_to_string(const char *fmt, ...);
-
-//static char* get_table_name_from_number(const char* phone_no)
-static inline char *get_table_name_from_number(const int id)
-{
- char *msg_table;
-
- msg_table = (char *)malloc(32);
- if (!msg_table) {
- return NULL;
- }
-
- snprintf(msg_table, 32, "tg_%d_msg", id);
-
- return msg_table;
-}
-
-static inline char *replace(const char *s, char ch, const char *repl)
-{
- int count = 0;
- const char *t;
-
- for(t = s; *t; t++) {
- count += (*t == ch);
- }
+extern char *ui_utils_get_resource(const char *res_name);
- size_t rlen = strlen(repl);
- char *res = malloc(strlen(s) + (rlen - 1) * count + 1);
- char *ptr = res;
+extern char *get_table_name_from_number(const int id);
- for(t = s; *t; t++) {
- if(*t == ch) {
- memcpy(ptr, repl, rlen);
- ptr += rlen;
- } else {
- *ptr++ = *t;
- }
- }
+extern char *replace(const char *s, char ch, const char *repl);
- *ptr = 0;
- return res;
-}
+extern void tg_notification_create(tg_engine_data_s* tg_data, char * icon_path, const char *title, char *content, char *sound_path, char *app_id);
#endif /* TG_COMMON_H_ */
<profile name="mobile"/>
<service-application appid="org.tizen.tg-engine-service" exec="tg-engine-service" multiple="false" nodisplay="true" type="capp">
<label>tg-engine-service</label>
- <icon>tg-engine-service.png</icon>
+ <icon>ic_launcher.png</icon>
<background-category value="background-network"/>
<background-category value="download"/>
<background-category value="iot-communication"/>
<privilege>http://tizen.org/privilege/appmanager.launch</privilege>
<privilege>http://tizen.org/privilege/content.write</privilege>
<privilege>http://tizen.org/privilege/push</privilege>
- <privilege>http://tizen.org/privilege/alarm.get</privilege>
<privilege>http://tizen.org/privilege/network.profile</privilege>
<privilege>http://tizen.org/privilege/display</privilege>
<privilege>http://tizen.org/privilege/account.read</privilege>
<privilege>http://tizen.org/privilege/notification</privilege>
<privilege>http://tizen.org/privilege/network.set</privilege>
<privilege>http://tizen.org/privilege/externalstorage.appdata</privilege>
+ <privilege>http://tizen.org/privilege/apphistory.read</privilege>
<privilege>http://tizen.org/privilege/contact.read</privilege>
</privileges>
- <feature name="http://tizen.org/feature/camera.front.flash">true</feature>
- <feature name="http://tizen.org/feature/camera.back.flash">true</feature>
- <feature name="http://tizen.org/feature/network.push">true</feature>
- <feature name="http://tizen.org/feature/camera">true</feature>
- <feature name="http://tizen.org/feature/network.wifi">true</feature>
- <feature name="http://tizen.org/feature/camera.front">true</feature>
- <feature name="http://tizen.org/feature/screen.size.all">true</feature>
- <feature name="http://tizen.org/feature/network.telephony">true</feature>
- <feature name="http://tizen.org/feature/camera.back">true</feature>
</manifest>