LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
__func__, __LINE__, ##arg)
+#define LOGI(fmt, arg...) dlog_print(DLOG_INFO, \
+ LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
+ __func__, __LINE__, ##arg)
+
#define DBG(fmt, arg...) dlog_print(DLOG_DEBUG, \
LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
__func__, __LINE__, ##arg)
+#define LOGD(fmt, arg...) dlog_print(DLOG_DEBUG, \
+ LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
+ __func__, __LINE__, ##arg)
+
#define WARN(fmt, arg...) dlog_print(DLOG_WARN, \
LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
__func__, __LINE__, ##arg)
LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
__func__, __LINE__, ##arg)
+#define LOGE(fmt, arg...) dlog_print(DLOG_ERROR, \
+ LOG_TAG, "%s: %s(%d) > " fmt, MODULE_INFO, \
+ __func__, __LINE__, ##arg)
+
#define RETM_IF(expr, fmt, arg...) \
{ \
if (expr) { \
void send_remove_buddy_from_group_chat_request(service_client* service_client, int user_id, int chat_id);
void send_request_for_delete_notifications(service_client* service_client);
void send_request_for_server_connection_status(service_client* service_client);
+void send_update_chat_request(service_client* service_client, const int chat_id);
#endif /* SERVER_REQUESTS_H_ */
#define MEDIA_INFO_TABLE_DOCUMENT_DC "doc_dc" //text
#define MEDIA_INFO_TABLE_DOCUMENT_THUMB_FILE "video_thumb" //text
+#define MESSAGE_INFO_TABLE_MESSAGE_ROW_ID "msg_row_id"
#define MESSAGE_INFO_TABLE_MESSAGE_ID "msg_id"
#define MESSAGE_INFO_TABLE_FLAGS "flags"
#define MESSAGE_INFO_TABLE_FWD_FROM_ID "fwd_from_id"
int get_number_of_unread_messages();
+void create_buddy_msg_table(const char* table_name);
+
Eina_Bool insert_unsent_message_to_db(const char *app_name, const char *command, const char *buddy_id, const char *msg_id, const char *msg_type, const char * msg_data, const char *type_of_chat);
Eina_Bool insert_unsent_media_message_to_db(const char *app_name, const char *command, const char *buddy_id, const char *msg_id, const char *media_id, const char *msg_type, const char *file_path, const char *type_of_chat);
#if 0
Evas_Object* buddy_gen_list = elm_genlist_add(ad->nf);
elm_list_mode_set(buddy_gen_list, ELM_LIST_COMPRESS);
- elm_genlist_decorate_mode_set(buddy_gen_list, ELM_LIST_COMPRESS);
+
+ // FIXME: Deprecated API
+ // elm_genlist_decorate_mode_set(buddy_gen_list, ELM_LIST_COMPRESS);
evas_object_size_hint_weight_set(buddy_gen_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(buddy_gen_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
Evas_Object* buddy_gen_list = elm_genlist_add(ad->nf);
elm_list_mode_set(buddy_gen_list, ELM_LIST_COMPRESS);
- elm_genlist_decorate_mode_set(buddy_gen_list, ELM_LIST_COMPRESS);
+ // FIXME: Deprecated API
+ //elm_genlist_decorate_mode_set(buddy_gen_list, ELM_LIST_COMPRESS);
evas_object_size_hint_weight_set(buddy_gen_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(buddy_gen_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
bundle_free(msg);
}
+void send_update_chat_request(service_client* service_client, const int chat_id)
+{
+ if (!service_client) {
+ // error
+ return;
+ }
+ bundle *msg;
+ char tmp[50];
+ int result;
+ msg = bundle_create();
+ if (!msg) {
+ return;
+ }
+
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ if (bundle_add_str(msg, "command", "update_chat_info") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+ snprintf(tmp, sizeof(tmp) - 1, "%d", chat_id);
+
+ if (bundle_add_str(msg, "chat_id", tmp) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ return;
+ }
+
+ result = service_client_send_message(service_client, msg);
+ if(result != SVC_RES_OK) {
+ // error
+ }
+ bundle_free(msg);
+}
+
+
void send_delete_buddy_request(service_client* service_client, const int buddy_id)
{
if (!service_client) {
// error handling
show_toast(app, "Error: loading contacts");
}
+ } else if (strcmp(rec_key_val, "reponse_group_chat_updated") == 0) {
+
+ char *chat_id_str = NULL;
+ result = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
+ int chat_id = atoi(chat_id_str);
+
+ int buddy_id = -1;
+ app->main_item_in_cahtting_data = NULL;
+ app->peer_in_cahtting_data = NULL;
+ for (int i = 0 ; i < eina_list_count(app->main_list) ; i++) {
+ tg_main_list_item_s *item = eina_list_nth(app->main_list, i);
+ if (item->peer_id == chat_id) {
+ app->main_item_in_cahtting_data = item;
+ break;
+ }
+ }
+
+ for (int i = 0; i < eina_list_count(app->peer_list); i++) {
+ peer_with_pic_s* pic_item = eina_list_nth(app->peer_list, i);
+ tg_peer_info_s* item = pic_item->use_data;
+
+ if (item->peer_id == chat_id) {
+ app->peer_in_cahtting_data = pic_item;
+ buddy_id = i;
+ break;
+ }
+ }
+
+ launch_messaging_view_cb(app, buddy_id);
+ hide_loading_popup(app);
+
} else if (strcmp(rec_key_val, "group_chat_updated") == 0) {
char *chat_id_str = NULL;
//load message from the received info.
// get phone number using buddy id.
-
+ Eina_Bool is_user_present_in_main_list = EINA_FALSE;
+ int id_to_check;
+ if (type_of_chat == TGL_PEER_USER) {
+ id_to_check = from_id;
+ } else {
+ id_to_check = to_id;
+ }
if (app->main_list) {
int main_list_size = eina_list_count(app->main_list);
for (int i = 0; i < main_list_size; i++) {
tg_main_list_item_s* sel_item = eina_list_nth(app->main_list, i);
- int id_to_check;
- if (type_of_chat == TGL_PEER_USER) {
- id_to_check = from_id;
- } else {
- id_to_check = to_id;
- }
-
-
if (sel_item->peer_id == id_to_check ) {
// update last message
}
free(tablename);
+ is_user_present_in_main_list = EINA_TRUE;
+
+ app->main_list = eina_list_remove(app->main_list, sel_item);
+ app->main_list = eina_list_prepend(app->main_list, sel_item);
+ refresh_main_list_view(app, EINA_FALSE);
break;
}
}
}
+ if (!is_user_present_in_main_list) {
+ peer_with_pic_s *peer_item = get_peer_info(id_to_check);
+ if (peer_item) {
+ tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
+ if (latest_item) {
+ app->main_list = eina_list_prepend(app->main_list, latest_item);
+ refresh_main_list_view(app, EINA_TRUE);
+ }
+ }
+ }
+
if (type_of_chat == TGL_PEER_USER) {
if ((app->current_app_state == TG_CHAT_MESSAGING_VIEW_STATE || app->current_app_state == TG_SET_USER_INFO_STATE) && app->peer_in_cahtting_data
&& app->peer_in_cahtting_data->use_data->peer_id == from_id) {
}
eina_list_free(contacts_list);
}
+ } else if (strcmp(rec_key_val, "new_buddy_added") == 0) {
+ char* buddy_id_str = NULL;
+ result = bundle_get_str(rec_msg, "buddy_id", &buddy_id_str);
+
+ int buddy_id = atoi(buddy_id_str);
+ peer_with_pic_s *peer_item = get_peer_info(buddy_id);
+ tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
+ if (latest_item) {
+ app->main_list = eina_list_prepend(app->main_list, latest_item);
+ refresh_main_list_view(app, EINA_TRUE);
+ }
+
} else if (strcmp(rec_key_val, "new_group_added") == 0) {
char* chat_id_str = NULL;
result = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
-
-#if 0
-
- // get group chat details from database.(chat info)
- // tg_chat_info_s* chat_info = get_chat_info(chat_id);
-
- load_buddy_list_data(app);
- load_group_chat_data(app);
- load_peer_data(app);
- load_main_list_data(app);
- if (app->current_app_state == TG_BUDDY_LIST_STATE) {
- //refresh_buddy_list(app);
- show_toast(app, "new group created");
- } else {
- elm_naviframe_item_pop(app->nf);
- //refresh_buddy_list(app);
- }
-#else
int chat_id = atoi(chat_id_str);
peer_with_pic_s *peer_item = get_peer_info(chat_id);
if (app->current_app_state == TG_USER_MAIN_VIEW_STATE) {
tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
- app->main_list = eina_list_prepend(app->main_list, latest_item);
- refresh_main_list_view(app, EINA_TRUE);
+ if (latest_item) {
+ app->main_list = eina_list_prepend(app->main_list, latest_item);
+ refresh_main_list_view(app, EINA_TRUE);
+ }
} else {
tg_main_list_item_s* latest_item = get_latest_item(app, peer_item);
- app->main_list = eina_list_prepend(app->main_list, latest_item);
- refresh_main_list_view(app, EINA_TRUE);
+ if (latest_item) {
+ app->main_list = eina_list_prepend(app->main_list, latest_item);
+ refresh_main_list_view(app, EINA_TRUE);
+ }
elm_naviframe_item_pop(app->nf);
app->current_app_state = TG_USER_MAIN_VIEW_STATE;
evas_object_show(app->panel);
//elm_panel_hidden_set(app->panel, EINA_FALSE);
}
app->peer_list = eina_list_prepend(app->peer_list, peer_item);
-#endif
+
} else if (strcmp(rec_key_val, "contact_updated") == 0) {
eina_list_free(peer_details);
return no_of_unread;
}
+
+void create_buddy_msg_table(const char* table_name)
+{
+ if(!table_name) {
+ return;
+ }
+ // create user info table
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_ROW_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FLAGS);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_FROM_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FWD_DATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_FROM_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_TO_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_OUT_MSG);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNREAD);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_DATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_SERVICE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_STATE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MESSAGE_LENGTH);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_TYPE);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_MEDIA_ID);
+ col_names = eina_list_append(col_names, MESSAGE_INFO_TABLE_UNIQUE_ID);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER_PRIMARY_AUTO_INC_KEY);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_INTEGER);
+
+ Eina_Bool ret = create_table(table_name, col_names, col_types);
+ if(!ret) {
+ //("error: database creation failed");
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+}
elm_entry_context_menu_disabled_set(entry, EINA_TRUE);
//elm_entry_magnifier_disabled_set(entry, EINA_TRUE);
- elm_entry_selection_handler_disabled_set(entry, EINA_TRUE);
+ // FIXME: Deprecated API
+ //elm_entry_selection_handler_disabled_set(entry, EINA_TRUE);
char *sender_name = NULL;
if(msg->out) {
elm_object_style_set(chat_conv_list, "solid/default");
evas_object_size_hint_weight_set(chat_conv_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(chat_conv_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
- elm_genlist_realization_mode_set(chat_conv_list, EINA_TRUE);
+ // FIXME: Deprecated API
+ //elm_genlist_realization_mode_set(chat_conv_list, EINA_TRUE);
//evas_object_color_set(chat_conv_list, 255 , 255, 255, 255);
#endif
#include "tg_settings_view.h"
#include "tg_db_manager.h"
#include "server_requests.h"
+#include "tg_db_wrapper.h"
static Evas_Object *create_image_object_from_file(const char *icon_name, Evas_Object *parent)
{
ad->peer_in_cahtting_data = NULL;
int buddy_id = -1;
if (sel_item) {
+
+ if (sel_item->peer_type == TGL_PEER_CHAT) {
+
+ tg_chat_info_s* chat_info = get_chat_info(sel_item->peer_id);
+ if (!chat_info) {
+ // request chat info
+ //show_toast(ad, "Loading chat info. Please wait.");
+ show_loading_popup(ad);
+ send_update_chat_request(ad->service_client, sel_item->peer_id);
+ return;
+ }
+ }
+
if (sel_item->peer_type == TGL_PEER_USER) {
for (int i = 0; i < eina_list_count(ad->buddy_list); i++) {
user_data_with_pic_s *item = eina_list_nth(ad->buddy_list, i);
int id = (int) data;
appdata_s* ad = evas_object_data_get(obj, "app_data");
tg_main_list_item_s* item = eina_list_nth(ad->main_list, id);
+ if (!item) {
+ return eo;
+ }
if (!strcmp(part, "elm.swallow.icon")) {
int size = eina_list_count(ad->main_list);
#define TELEGRAM_POPUP_VIEW_EDJ "edje/telegram_custom_popup.edj"
#define TELEGRAM_GENLIST_THEME_EDJ "edje/telegram_genlist_theme.edj"
+#define TELEGRAM_START_SCREEN_EDJ "edje/telegram_start_screen.edj"
+
+
#define GRP_MAIN "main"
#define DEFAULT_TELEGRAM_PATH "/opt/usr/media/telegram/"
extern void process_marked_as_read_command(int buddy_id, int type_of_chat);
extern void process_delete_group_chat_request(tg_engine_data_s* tg_data, int chat_id);
extern void process_add_user_request(tg_engine_data_s* tg_data, int buddy_id);
+extern void process_update_chat_request(tg_engine_data_s* tg_data, int chat_id);
extern void process_delete_user_request(tg_engine_data_s* tg_data, int buddy_id);
extern void process_block_user_request(tg_engine_data_s* tg_data, int buddy_id);
extern void process_unblock_user_request(tg_engine_data_s* tg_data, int buddy_id);
extern void send_media_download_completed_response(tg_engine_data_s *tg_data, int buddy_id, int to_id, long long media_id, const char* filename);
extern void send_video_thumb_download_completed_response(tg_engine_data_s *tg_data, int buddy_id, int to_id, long long media_id, const char* filename);
extern void send_new_group_added_response(tg_engine_data_s *tg_data, int chat_id);
+extern void send_new_buddy_added_response(tg_engine_data_s *tg_data, int buddy_id);
extern void send_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id, const char *type_of_change);
extern void send_chat_profile_pic_updated_response(tg_engine_data_s *tg_data, int chat_id, char* filename);
extern void send_contact_updated_response(tg_engine_data_s *tg_data, int buddy_id, char* update_message);
extern void send_group_chat_new_buddy_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success);
extern void send_group_chat_delete_buddy_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success);
extern void send_response_for_server_connection_status(tg_engine_data_s *tg_data, Eina_Bool connection_status);
+
+extern void send_response_to_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id);
#endif /* SERVER_RESPONSE_H_ */
Eina_List* get_all_unsent_text_messages();
void delete_message_from_unsent_db(int message_id);
void delete_media_from_unsent_db(int message_id);
+Eina_Bool is_user_present_peer_table(int id);
+Eina_Bool is_user_present_chat_table(int id);
#endif /* TG_DB_WRAPPER_H_ */
void tgls_free_message_action(struct tgl_state *TLS, struct tgl_message_action *M)
{
+ if (!M) {
+ return;
+ }
switch (M->type) {
case tgl_message_action_none:
return;
vlogprintf(E_ERROR, "type = 0x%08x\n", M->type);
assert(0);*/
}
+ // sandeep
+ /*
vlogprintf(E_ERROR, "type = 0x%08x\n", M->type);
assert(0);
+ */
}
void tgls_clear_message(struct tgl_state *TLS, struct tgl_message *M)
do_add_buddy(buddy_id);
}
+void process_update_chat_request(tg_engine_data_s* tg_data, int chat_id)
+{
+ if (!tgl_engine_get_TLS()) {
+ return;
+ }
+ do_update_chat_info(chat_id);
+}
+
void process_delete_user_request(tg_engine_data_s* tg_data, int buddy_id)
{
bundle_free(msg);
}
+void send_new_buddy_added_response(tg_engine_data_s *tg_data, int buddy_id)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (bundle_add_str(msg, "command", "new_buddy_added") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char buddy_id_str[50];
+ sprintf(buddy_id_str,"%d",buddy_id);
+ if (bundle_add_str(msg, "buddy_id", buddy_id_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
+
+ bundle_free(msg);
+}
+
+void send_response_to_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id)
+{
+ bundle *msg = bundle_create();
+ if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ if (bundle_add_str(msg, "command", "reponse_group_chat_updated") != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ char chat_id_str[50];
+ sprintf(chat_id_str,"%d",chat_id);
+ if (bundle_add_str(msg, "chat_id", chat_id_str) != 0) {
+ ERR("Failed to add data by key to bundle");
+ bundle_free(msg);
+ }
+
+ int result = SVC_RES_FAIL;
+ result = tg_server_send_message(tg_data->tg_server, msg);
+
+ if(result != SVC_RES_OK) {
+ // error: cient not ready
+ }
+
+ bundle_free(msg);
+}
+
void send_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id, const char *type_of_change)
{
bundle *msg = bundle_create();
int buddy_id = atoi(buddy_id_str);
process_add_user_request(tg_data, buddy_id);
+ } else if (strcmp(cmd_key_val, "update_chat_info") == 0) {
+
+ char* chat_id_str = NULL;
+ res = bundle_get_str(rec_msg, "chat_id", &chat_id_str);
+ int chat_id = atoi(chat_id_str);
+
+ process_update_chat_request(tg_data, chat_id);
} else if (strcmp(cmd_key_val, "delete_buddy") == 0) {
return no_of_unread;
}
+Eina_Bool is_user_present_peer_table(int peer_id)
+{
+ Eina_Bool ret = EINA_FALSE;
+
+ Eina_List* peer_details = NULL;
+ char* table_name = BUDDY_INFO_TABLE_NAME;
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, USER_INFO_TABLE_PRINT_NAME);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ char chat_id_str[50];
+ sprintf(chat_id_str, "%d", peer_id);
+
+ char* where_clause = (char*)malloc(strlen(USER_INFO_TABLE_USER_ID) + strlen(" = ") + strlen(chat_id_str) + 1);
+ strcpy(where_clause, USER_INFO_TABLE_USER_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, chat_id_str);
+
+ peer_details = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+ free(where_clause);
+ if (peer_details) {
+ for (int i = 0; i < eina_list_count(peer_details) ; i++) {
+ Eina_List* ts_msg = eina_list_nth(peer_details, i);
+ ret = EINA_TRUE;
+ eina_list_free(ts_msg);
+ break;
+ }
+ eina_list_free(peer_details);
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ return ret;
+}
+
+Eina_Bool is_user_present_chat_table(int peer_id)
+{
+ Eina_Bool ret = EINA_FALSE;
+
+ Eina_List* peer_details = NULL;
+ char* table_name = CHAT_INFO_TABLE_NAME;
+
+ Eina_List* col_names = NULL;
+ col_names = eina_list_append(col_names, CHAT_INFO_TABLE_PRINT_TITLE);
+
+ Eina_List* col_types = NULL;
+ col_types = eina_list_append(col_types, TG_DB_COLUMN_TEXT);
+
+ char chat_id_str[50];
+ sprintf(chat_id_str, "%d", peer_id);
+
+ char* where_clause = (char*)malloc(strlen(CHAT_INFO_TABLE_CHAT_ID) + strlen(" = ") + strlen(chat_id_str) + 1);
+ strcpy(where_clause, CHAT_INFO_TABLE_CHAT_ID);
+ strcat(where_clause, " = ");
+ strcat(where_clause, chat_id_str);
+
+ peer_details = get_values_from_table_sync(table_name, col_names, col_types, where_clause);
+ free(where_clause);
+ if (peer_details) {
+ for (int i = 0; i < eina_list_count(peer_details) ; i++) {
+ Eina_List* ts_msg = eina_list_nth(peer_details, i);
+ ret = EINA_TRUE;
+ eina_list_free(ts_msg);
+ break;
+ }
+ eina_list_free(peer_details);
+ }
+ eina_list_free(col_names);
+ eina_list_free(col_types);
+ return ret;
+}
static void on_buddy_info_loaded(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U);
static void on_chat_pic_loaded(struct tgl_state *TLS, void *callback_extra, int success, char *filename);
static void on_document_download_completed(struct tgl_state *TLS, void *callback_extra, int success, char *filename);
-
+static void on_buddy_pic_loaded(struct tgl_state *TLS, void *callback_extra, int success, char *filename);
+static void on_new_buddy_info_loaded(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U);
void tgl_engine_var_init(void)
{
s_info.default_username = NULL;
return;
}
+ if (chat_info->user_list) {
+ for (int i = 0; i < chat_info->user_list_size; i++) {
+ int user_id = chat_info->user_list[i].user_id;
+ Eina_Bool is_present_in_db = is_user_present_peer_table(user_id);
+ char* tb_name = get_table_name_from_number(user_id);
+ create_buddy_msg_table(tb_name);
+ if (!is_present_in_db) {
+ // add to buddy table
+ tgl_peer_id_t from_id;
+ from_id.id = user_id;
+ from_id.type = TGL_PEER_USER;
+ tgl_do_get_user_info(TLS, from_id, 0, on_new_buddy_info_loaded, NULL);
+ }
+ free(tb_name);
+ }
+ }
+
tg_data = TLS->callback_data;
tgl_peer_t* UC = tgl_peer_get(TLS, M->from_id);
return ECORE_CALLBACK_CANCEL;
}
+void on_requested_chat_info_received(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_chat *chat_info)
+{
+ tg_engine_data_s *tg_data;
+
+ struct tgl_message *M = callback_extra;
+ char *msg_table;
+
+
+ if (!chat_info) {
+ return;
+ }
+ if (!chat_info->user_list) {
+ tgl_do_get_chat_info(TLS, chat_info->id, 0, &on_requested_chat_info_received, callback_extra);
+ return;
+ }
+
+ tg_data = TLS->callback_data;
+
+ msg_table = get_table_name_from_number(chat_info->id.id);
+
+ create_buddy_msg_table(msg_table);
+
+ insert_chat_info_to_db(chat_info, NULL);
+ struct tgl_photo *pic = &(chat_info->photo);
+ if(pic) {
+ tgl_do_load_photo(TLS, pic ,&on_chat_pic_loaded,chat_info);
+ }
+
+ // send message
+ int msg_id = insert_current_date_to_table(msg_table);
+ if (msg_id > 0) {
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, msg_id, tgl_get_peer_type(M->to_id));
+ struct tg_temp_msg_data *msg_data = (struct tg_temp_msg_data*)malloc(sizeof(struct tg_temp_msg_data));
+ msg_data->M = M;
+ msg_data->TLS = TLS;
+ msg_data->send_timer = ecore_timer_add(3, on_msg_received_cb, msg_data);
+ } else {
+ if (M->media.type != tgl_message_media_none && (M->media.document.flags & FLAG_DOCUMENT_AUDIO)) {
+ M->message = strdup("Audio");
+ M->message_len = strlen("Audio");
+ } else if (M->media.type != tgl_message_media_none && (M->media.document.flags & FLAG_DOCUMENT_VIDEO)) {
+ M->message = strdup("Video");
+ M->message_len = strlen("Video");
+ }
+ insert_buddy_msg_to_db(M);
+ if(M->media.type != tgl_message_media_none) {
+ insert_media_info_to_db(M, "");
+ if (M->media.type != tgl_message_media_none && (M->media.document.flags & FLAG_DOCUMENT_VIDEO)) {
+ tgl_do_load_document_thumb(TLS, &(M->media.document), on_video_thumb_loaded, M);
+ return;
+ }
+ }
+ // inform to application
+ send_message_received_response(TLS->callback_data, M->from_id.id, M->to_id.id, M->id, tgl_get_peer_type(M->to_id));
+ }
+
+ free(msg_table);
+}
+
+
+void on_requested_update_chat_received(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_chat *chat_info)
+{
+ tg_engine_data_s *tg_data;
+ char *msg_table;
+ msg_table = get_table_name_from_number(chat_info->id.id);
+ create_buddy_msg_table(msg_table);
+ free(msg_table);
+ if (!chat_info) {
+ return;
+ }
+ if (!chat_info->user_list) {
+ tgl_do_get_chat_info(TLS, chat_info->id, 0, &on_chat_info_received, NULL);
+ return;
+ }
+
+ tg_data = TLS->callback_data;
+
+ insert_chat_info_to_db(chat_info, NULL);
+ struct tgl_photo *pic = &(chat_info->photo);
+ if(pic) {
+ tgl_do_load_photo(TLS, pic ,&on_chat_pic_loaded,chat_info);
+ }
+ //char *type_of_change = strdup("add_user");
+ tgl_peer_t* chat_UC = tgl_peer_get(TLS, chat_info->id);
+ insert_chat_info_to_db(chat_info, NULL);
+ insert_peer_into_database(chat_UC, 0, 0);
+ send_response_to_group_chat_updated_response(tg_data, chat_info->id.id);
+ //free(type_of_change);
+}
+
+void do_update_chat_info(int chat_id)
+{
+ tgl_peer_id_t to_id;
+ to_id.id = chat_id;
+ to_id.type = TGL_PEER_CHAT;
+ tgl_do_get_chat_info(s_info.TLS, to_id, 0, &on_requested_update_chat_received, NULL);
+}
+
+void on_new_buddy_info_loaded(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U)
+{
+ if(!U) {
+ return;
+ }
+ tg_engine_data_s *tg_data = TLS->callback_data;
+ if (U->id.id == tg_data->id.id) {
+ return;
+ }
+ tgl_peer_t* UC = tgl_peer_get(TLS, U->id);
+ insert_peer_into_database(UC, 0, 0);
+ insert_buddy_into_db(BUDDY_INFO_TABLE_NAME, U);
+ struct tgl_photo* pic = &(U->photo);
+ if(pic) {
+ tgl_do_load_photo(TLS, pic ,&on_buddy_pic_loaded,U);
+ }
+
+ send_new_buddy_added_response(tg_data, U->id.id);
+}
void tg_msg_receive(struct tgl_state *TLS, struct tgl_message *M)
{
} else if (tgl_get_peer_type(M->to_id) == TGL_PEER_CHAT) {
user_id = M->to_id.id;
}
+
+ Eina_Bool is_present_in_db = is_user_present_peer_table(user_id);
char* tb_name = get_table_name_from_number(user_id);
+ create_buddy_msg_table(tb_name);
+ if (!is_present_in_db) {
+ // add to buddy table
+ tgl_do_get_user_info(TLS, M->from_id, 0, on_new_buddy_info_loaded, NULL);
+ }
int msg_id = insert_current_date_to_table(tb_name);
free(tb_name);
} else if (tgl_get_peer_type(M->to_id) == TGL_PEER_CHAT) {
user_id = M->to_id.id;
}
+
+ // check whether user is present or not
+
+ Eina_Bool is_present_in_peer_db = is_user_present_peer_table(user_id);
+
+ if (!is_present_in_peer_db) {
+ tgl_do_get_chat_info(TLS, M->to_id, 0, &on_requested_chat_info_received, M);
+ return;
+ }
+
+ Eina_Bool is_present_in_chat_db = is_user_present_chat_table(user_id);
+ if (!is_present_in_chat_db) {
+ //sandeep
+ tgl_do_get_chat_info(TLS, M->to_id, 0, &on_requested_chat_info_received, M);
+ return;
+ }
+
char* tb_name = get_table_name_from_number(user_id);
int msg_id = insert_current_date_to_table(tb_name);
free(tb_name);
if (!chat_info) {
return;
}
+ msg_table = get_table_name_from_number(chat_info->id.id);
+ create_buddy_msg_table(msg_table);
+ free(msg_table);
if (!chat_info->user_list) {
tgl_do_get_chat_info(TLS, chat_info->id, 0, &on_chat_info_received, NULL);
return;
tg_data = TLS->callback_data;
- msg_table = get_table_name_from_number(chat_info->id.id);
-
- create_buddy_msg_table(msg_table);
-
insert_chat_info_to_db(chat_info, NULL);
struct tgl_photo *pic = &(chat_info->photo);
if(pic) {
tgl_do_load_photo(TLS, pic ,&on_chat_pic_loaded,chat_info);
}
- free(msg_table);
-
}
void on_buddy_info_loaded(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U)
extern void leave_group_chat(tg_engine_data_s *tg_data, int group_chat_id);
extern void do_delete_buddy(int buddy_id);
extern void do_add_buddy(int buddy_id);
+extern void do_update_chat_info(int chat_id);
extern void do_unblock_buddy(int buddy_id);
extern void do_block_buddy(int buddy_id);
extern void set_group_chat_profile_picture(tg_engine_data_s *tg_data, int buddy_id, const char *file_path);