2 This file is part of Telegram application for tizen
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "tg_engine.h"
22 #include "server_response.h"
23 #include "tg_db_wrapper.h"
24 #include "tg_common.h"
25 #include "tg-engine-service.h"
29 Eina_Bool init_response(bundle *msg, tg_engine_data_s *tg_data, const char* command)
34 if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
35 ERR("Failed to add data by key to bundle");
39 if (bundle_add_str(msg, "command", command) != 0) {
40 ERR("Failed to add data by key to bundle");
46 Eina_Bool send_response(bundle *msg, tg_engine_data_s *tg_data)
48 int result = SVC_RES_FAIL;
52 result = tg_server_send_message(tg_data->tg_server, msg);
53 if (result != SVC_RES_OK) {
54 ERR("Cient not ready");
63 void make_base_response(tg_engine_data_s *tg_data, const char* command)
65 bundle *msg = bundle_create();
66 if (!init_response(msg, tg_data, command)) {
71 if (!send_response(msg, tg_data))
75 void make_arg1_response(tg_engine_data_s *tg_data, const char* command,
76 const char* arg1_name, const char* arg1_value)
78 bundle *msg = bundle_create();
79 if (!init_response(msg, tg_data, command)) {
84 if (bundle_add_str(msg, arg1_name, arg1_value) != 0) {
85 ERR("Failed to add data by key to bundle1");
89 if (!send_response(msg, tg_data))
93 void make_arg2_response(tg_engine_data_s *tg_data, const char* command,
94 const char* arg1_name, const char* arg1_value,
95 const char* arg2_name, const char* arg2_value)
97 bundle *msg = bundle_create();
98 if (!init_response(msg, tg_data, command)) {
103 if (bundle_add_str(msg, arg1_name, arg1_value) != 0) {
104 ERR("Failed to add data by key to bundle1");
108 if (bundle_add_str(msg, arg2_name, arg2_value) != 0) {
109 ERR("Failed to add data by key to bundle2");
113 if (!send_response(msg, tg_data))
117 void make_arg3_response(tg_engine_data_s *tg_data, const char* command,
118 const char* arg1_name, const char* arg1_value,
119 const char* arg2_name, const char* arg2_value,
120 const char* arg3_name, const char* arg3_value)
122 bundle *msg = bundle_create();
123 if (!init_response(msg, tg_data, command)) {
128 if (bundle_add_str(msg, arg1_name, arg1_value) != 0) {
129 ERR("Failed to add data by key to bundle1");
133 if (bundle_add_str(msg, arg2_name, arg2_value) != 0) {
134 ERR("Failed to add data by key to bundle2");
138 if (bundle_add_str(msg, arg3_name, arg3_value) != 0) {
139 ERR("Failed to add data by key to bundle3");
143 if (!send_response(msg, tg_data))
147 void make_arg4_response(tg_engine_data_s *tg_data, const char* command,
148 const char* arg1_name, const char* arg1_value,
149 const char* arg2_name, const char* arg2_value,
150 const char* arg3_name, const char* arg3_value,
151 const char* arg4_name, const char* arg4_value)
153 bundle *msg = bundle_create();
154 if (!init_response(msg, tg_data, command)) {
159 if (bundle_add_str(msg, arg1_name, arg1_value) != 0) {
160 ERR("Failed to add data by key to bundle1");
164 if (bundle_add_str(msg, arg2_name, arg2_value) != 0) {
165 ERR("Failed to add data by key to bundle2");
169 if (bundle_add_str(msg, arg3_name, arg3_value) != 0) {
170 ERR("Failed to add data by key to bundle3");
174 if (bundle_add_str(msg, arg4_name, arg4_value) != 0) {
175 ERR("Failed to add data by key to bundle4");
179 if (!send_response(msg, tg_data))
183 void make_arg5_response(tg_engine_data_s *tg_data, const char* command,
184 const char* arg1_name, const char* arg1_value,
185 const char* arg2_name, const char* arg2_value,
186 const char* arg3_name, const char* arg3_value,
187 const char* arg4_name, const char* arg4_value,
188 const char* arg5_name, const char* arg5_value)
190 bundle *msg = bundle_create();
191 if (!init_response(msg, tg_data, command)) {
196 if (bundle_add_str(msg, arg1_name, arg1_value) != 0) {
197 ERR("Failed to add data by key to bundle1");
201 if (bundle_add_str(msg, arg2_name, arg2_value) != 0) {
202 ERR("Failed to add data by key to bundle2");
206 if (bundle_add_str(msg, arg3_name, arg3_value) != 0) {
207 ERR("Failed to add data by key to bundle3");
211 if (bundle_add_str(msg, arg4_name, arg4_value) != 0) {
212 ERR("Failed to add data by key to bundle4");
216 if (bundle_add_str(msg, arg5_name, arg5_value) != 0) {
217 ERR("Failed to add data by key to bundle5");
221 if (!send_response(msg, tg_data))
225 void make_chat_response(tg_engine_data_s *tg_data, int chat_id, const char* command)
228 snprintf(id_str, sizeof(id_str), "%d", chat_id);
229 make_arg1_response(tg_data, command, "chat_id", id_str);
232 void make_buddy_response(tg_engine_data_s *tg_data, int buddy_id, const char* command)
235 snprintf(id_str, sizeof(id_str), "%d", buddy_id);
236 make_arg1_response(tg_data, command, "buddy_id", id_str);
239 void make_boolean_response(tg_engine_data_s *tg_data, Eina_Bool is_success, const char* command)
241 make_arg1_response(tg_data, command, "is_success", is_success ? "true" : "false");
244 void process_registration_command(tg_engine_data_s *tg_data, char* phone_no, Eina_Bool trough_sms)
247 if (trough_sms && (tg_data->tg_state != TG_ENGINE_STATE_REGISTRATION || !phone_no))
250 if (!tg_data || !tgl_engine_get_TLS())
253 if (tg_data->phone_number)
254 free(tg_data->phone_number);
257 tg_data->phone_number = strdup(phone_no);
259 tg_data->phone_number = NULL;
262 request_for_code_via_call(tgl_engine_get_TLS(), phone_no, trough_sms);
266 if (tg_data->get_string)
267 tg_data->get_string(tgl_engine_get_TLS(), tg_data->phone_number, tg_data->callback_arg);
270 void process_validation_command(tg_engine_data_s *tg_data, char* code)
272 if (tg_data->tg_state != TG_ENGINE_STATE_CODE_REQUEST ||
276 if (!tg_data || !tgl_engine_get_TLS())
279 tg_data->get_string(tgl_engine_get_TLS(), code, tg_data->callback_arg);
282 void process_logout_command(tg_engine_data_s *tg_data)
287 logout_telegram(tg_data);
290 void process_forward_message_command(int to_id, int type_of_chat, int from_id, int message_id, int temp_message_id)
292 if (!tgl_engine_get_TLS())
295 forward_message_to_buddy(to_id, type_of_chat, from_id, message_id, temp_message_id);
298 void process_typing_status_to_buddy_command(int buddy_id, int type_of_chat, int typing_status)
300 if (!tgl_engine_get_TLS())
303 send_typing_status_to_buddy(buddy_id, type_of_chat, typing_status);
306 void process_send_message_command(int buddy_id, int message_id, int msg_type, char* msg_data, int type_of_chat)
308 if (!msg_data || !tgl_engine_get_TLS())
311 send_message_to_buddy(buddy_id, message_id, msg_type, msg_data, type_of_chat);
314 void process_delete_selected_group_chats_request(tg_engine_data_s* tg_data, Eina_List *sel_grp_chats)
316 if (!tgl_engine_get_TLS())
319 delete_selected_group_chat(tg_data, sel_grp_chats);
322 void process_delete_group_chat_request(tg_engine_data_s* tg_data, int chat_id)
324 if (!tgl_engine_get_TLS())
327 leave_group_chat(tg_data, chat_id);
330 void process_add_user_request(tg_engine_data_s* tg_data, int buddy_id, char *first_name, char *last_name, char *phone_num)
332 if (!tgl_engine_get_TLS())
335 do_add_buddy(buddy_id, first_name, last_name, phone_num);
338 void process_update_chat_request(tg_engine_data_s* tg_data, int chat_id)
340 if (!tgl_engine_get_TLS())
343 do_update_chat_info(chat_id);
346 void process_send_secret_chat_request(tg_engine_data_s* tg_data, int buddy_id)
348 if (!tgl_engine_get_TLS())
350 request_for_secret_chat(buddy_id);
353 void process_delete_user_request(tg_engine_data_s* tg_data, int buddy_id)
355 if (!tgl_engine_get_TLS())
358 do_delete_buddy(buddy_id);
361 void process_delete_message_request(tg_engine_data_s* tg_data, int buddy_id, int message_id)
363 if (!tgl_engine_get_TLS())
366 do_delete_message(buddy_id, message_id);
369 void process_block_user_request(tg_engine_data_s* tg_data, int buddy_id)
371 if (!tgl_engine_get_TLS())
374 do_block_buddy(buddy_id);
377 void process_unblock_user_request(tg_engine_data_s* tg_data, int buddy_id)
379 if (!tgl_engine_get_TLS())
382 do_unblock_buddy(buddy_id);
385 void process_delete_all_msgs_from_table_command(int buddy_id, int type_of_chat)
387 if (!tgl_engine_get_TLS())
390 delete_all_messages_from_chat(buddy_id, type_of_chat);
393 void process_marked_as_read_command(int buddy_id, int type_of_chat)
395 if (!tgl_engine_get_TLS())
398 send_do_mark_read_messages(buddy_id, type_of_chat);
401 void process_send_media_command(int buddy_id, int message_id, int media_id, int msg_type, char* file_path, int type_of_chat)
403 if (!file_path || !tgl_engine_get_TLS())
406 send_media_to_buddy(buddy_id, message_id, media_id, msg_type, file_path, type_of_chat);
410 void process_media_download_command(tg_engine_data_s *tg_data, int buddy_id, long long media_id)
412 media_download_request(tg_data, buddy_id, media_id);
415 void process_add_contacts_command(tg_engine_data_s *tg_data, int size, Eina_List* contact_list)
417 add_contacts_to_user(tg_data, size, contact_list);
420 void process_new_group_create_command(tg_engine_data_s *tg_data, Eina_List* buddy_ids, const char* group_name, const char* group_icon)
422 create_new_group(tg_data, buddy_ids, group_name, group_icon);
425 void process_set_group_chat_new_title_command(tg_engine_data_s *tg_data, int buddy_id, const char *new_title)
427 set_group_chat_new_title(tg_data, buddy_id, new_title);
430 void process_add_new_buddy_to_chat_command(tg_engine_data_s *tg_data, int s_buddy_id, int s_chat_id)
432 set_group_chat_add_new_buddy(tg_data, s_buddy_id, s_chat_id);
435 void process_remove_buddy_from_chat_command(tg_engine_data_s *tg_data, int s_buddy_id, int s_chat_id)
437 set_group_chat_remove_buddy(tg_data, s_buddy_id, s_chat_id);
440 void process_set_group_chat_profile_pic_command(tg_engine_data_s *tg_data, int buddy_id, const char *file_path)
442 set_group_chat_profile_picture(tg_data, buddy_id, file_path);
445 void process_set_profile_pic_command(tg_engine_data_s *tg_data, int buddy_id, const char *file_path)
447 set_profile_picture(tg_data, buddy_id, file_path);
450 void process_update_display_name_command(tg_engine_data_s *tg_data, int buddy_id, const char *first_name, const char *last_name)
452 update_user_display_name(tg_data, buddy_id, first_name, last_name);
455 void process_set_username_command(tg_engine_data_s *tg_data, int buddy_id, const char *username)
457 set_user_name(tg_data, buddy_id, username);
460 void send_request_phone_num_again(tg_engine_data_s *tg_data)
462 make_arg1_response(tg_data, "request_phone_num_again", "phone_number", tg_data->phone_number);
465 void send_request_phone_new_num(tg_engine_data_s *tg_data)
467 make_base_response(tg_data, "request_phone_new_num");
470 void send_request_code_again(tg_engine_data_s *tg_data)
472 make_arg1_response(tg_data, "request_reg_code_again", "phone_number", tg_data->phone_number);
475 void send_registration_response(tg_engine_data_s *tg_data, Eina_Bool is_success)
477 make_arg2_response(tg_data, "registration_done", "phone_number", tg_data->phone_number, "is_success", is_success ? "true" : "false");
480 void send_new_group_added_response(tg_engine_data_s *tg_data, int chat_id)
482 make_chat_response(tg_data, chat_id, "new_group_added");
485 void send_new_buddy_added_response(tg_engine_data_s *tg_data, int buddy_id)
487 make_buddy_response(tg_data, buddy_id, "new_buddy_added");
490 void send_response_to_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id)
492 make_chat_response(tg_data, chat_id, "response_group_chat_updated");
495 void send_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id, const char *type_of_change)
497 char chat_id_str[50];
498 snprintf(chat_id_str, sizeof(chat_id_str), "%d", chat_id);
499 make_arg2_response(tg_data, "group_chat_updated", "chat_id", chat_id_str, "type_of_change", type_of_change);
502 void send_chat_profile_pic_updated_response(tg_engine_data_s *tg_data, int chat_id, char* filename)
504 char chat_id_str[50];
505 snprintf(chat_id_str, sizeof(chat_id_str), "%d", chat_id);
506 make_arg2_response(tg_data, "new_group_icon_added", "chat_id", chat_id_str, "chat_icon_path", filename);
509 void send_name_registration_response(tg_engine_data_s *tg_data)
511 make_base_response(tg_data, "name_registration_request");
514 void send_add_contacts_request(tg_engine_data_s *tg_data)
516 make_base_response(tg_data, "add_contacts_request");
519 void send_server_not_initialized_response(tg_engine_data_s *tg_data)
521 make_base_response(tg_data, "server_not_initialized");
524 void send_contacts_and_chats_load_done_response(tg_engine_data_s *tg_data, Eina_Bool is_success)
526 make_boolean_response(tg_data, is_success, "contacts_and_chats_load_done");
529 void send_self_profile_name_updated_response(tg_engine_data_s *tg_data, char *first_name, char *last_name, Eina_Bool is_success)
531 make_arg3_response(tg_data, "self_profile_name_updated", "first_name", first_name, "last_name", last_name, "is_success", is_success ? "true" : "false");
534 void send_self_user_name_updated_response(tg_engine_data_s *tg_data, char *username, Eina_Bool is_success)
536 make_arg2_response(tg_data, "self_username_updated", "username", username, "is_success", is_success ? "true" : "false");
539 void send_self_profile_picture_updated_response(tg_engine_data_s *tg_data, char *file_path, Eina_Bool is_success)
541 make_arg2_response(tg_data, "self_profile_picture_updated", "file_path", file_path, "is_success", is_success ? "true" : "false");
544 void send_contacts_load_done_response(tg_engine_data_s *tg_data, Eina_Bool is_success)
546 make_boolean_response(tg_data, is_success, "contacts_load_done");
549 void send_buddy_profile_pic_updated_response(tg_engine_data_s *tg_data, int buddy_id, char* file_path)
552 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
553 make_arg2_response(tg_data, "buddy_profile_pic_updated", "user_id", usr_id_str, "file_path", file_path);
557 void send_message_with_date_received_response(tg_engine_data_s *tg_data, int from_id, int to_id, long long message_id, int date_id, int type_of_chat)
559 bundle *msg = bundle_create();
560 if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
561 ERR("Failed to add data by key to bundle");
565 if (bundle_add_str(msg, "command", "message_received_with_date") != 0) {
566 ERR("Failed to add data by key to bundle");
570 char from_id_str[50];
571 snprintf(from_id_str, sizeof(from_id_str), "%d", from_id);
573 if (bundle_add_str(msg, "from_id", from_id_str) != 0) {
574 ERR("Failed to add data by key to bundle");
579 snprintf(to_id_str, sizeof(to_id_str), "%d", to_id);
581 if (bundle_add_str(msg, "to_id", to_id_str) != 0) {
582 ERR("Failed to add data by key to bundle");
587 snprintf(msg_id_str, sizeof(msg_id_str), "%lld", message_id);
589 if (bundle_add_str(msg, "message_id", msg_id_str) != 0) {
590 ERR("Failed to add data by key to bundle");
594 char date_id_str[50];
595 snprintf(date_id_str, sizeof(date_id_str), "%d", date_id);
597 if (bundle_add_str(msg, "date_id", date_id_str) != 0) {
598 ERR("Failed to add data by key to bundle");
602 char type_of_chat_str[50];
603 snprintf(type_of_chat_str, sizeof(type_of_chat_str), "%d", type_of_chat);
605 if (bundle_add_str(msg, "type_of_chat", type_of_chat_str) != 0) {
606 ERR("Failed to add data by key to bundle");
610 if (SVC_RES_OK != tg_server_send_message(tg_data->tg_server, msg))
611 display_new_message_badge(get_number_of_unread_messages(), tg_data);
616 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)
618 bundle *msg = bundle_create();
619 if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
620 ERR("Failed to add data by key to bundle");
624 if (bundle_add_str(msg, "command", "message_received") != 0) {
625 ERR("Failed to add data by key to bundle");
629 char from_id_str[64];
630 snprintf(from_id_str, sizeof(from_id_str), "%d", from_id);
632 if (bundle_add_str(msg, "from_id", from_id_str) != 0) {
633 ERR("Failed to add data by key to bundle");
638 snprintf(to_id_str, sizeof(to_id_str), "%d", to_id);
640 if (bundle_add_str(msg, "to_id", to_id_str) != 0) {
641 ERR("Failed to add data by key to bundle");
646 snprintf(msg_id_str, sizeof(msg_id_str), "%lld", message_id);
648 if (bundle_add_str(msg, "message_id", msg_id_str) != 0) {
649 ERR("Failed to add data by key to bundle");
653 char type_of_chat_str[64];
654 snprintf(type_of_chat_str, sizeof(type_of_chat_str), "%d", type_of_chat);
656 if (bundle_add_str(msg, "type_of_chat", type_of_chat_str) != 0) {
657 ERR("Failed to add data by key to bundle");
661 if (SVC_RES_OK != tg_server_send_message(tg_data->tg_server, msg))
662 display_new_message_badge(get_number_of_unread_messages(), tg_data);
667 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)
671 char type_of_chat_str[64];
673 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
674 snprintf(msg_id_str, sizeof(msg_id_str), "%d", message_id);
675 snprintf(type_of_chat_str, sizeof(type_of_chat_str), "%d", type_of_chat);
677 make_arg5_response(tg_data, "message_read_by_buddy", "buddy_id", usr_id_str, "message_id", msg_id_str,
678 "table_name", table_name ? table_name : "", "phone_number", phone ? phone : "", "type_of_chat", type_of_chat_str);
681 void send_group_chat_delete_buddy_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success)
684 snprintf(usr_id_str, sizeof(usr_id_str), "%d", peer_id);
685 make_arg2_response(tg_data, "group_chat_buddy_deleted_response", "buddy_id", usr_id_str, "is_success", is_success ? "true" : "false");
688 void send_group_chat_new_buddy_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success)
691 snprintf(usr_id_str, sizeof(usr_id_str), "%d", peer_id);
692 make_arg2_response(tg_data, "group_chat_new_buddy_added_response", "buddy_id", usr_id_str, "is_success", is_success ? "true" : "false");
695 void send_group_chat_rename_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success)
698 snprintf(usr_id_str, sizeof(usr_id_str), "%d", peer_id);
699 make_arg2_response(tg_data, "group_chat_rename_response", "buddy_id", usr_id_str, "is_success", is_success ? "true" : "false");
702 void send_new_contact_added_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
705 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
706 make_arg2_response(tg_data, "new_contact_added", "buddy_id", usr_id_str, "is_success", is_success ? "true" : "false");
709 void send_buddy_readded_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
712 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
713 make_arg2_response(tg_data, "buddy_readded", "buddy_id", usr_id_str, "is_success", is_success ? "true" : "false");
716 void send_buddy_deleted_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
719 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
720 make_arg2_response(tg_data, "buddy_deleted", "buddy_id", usr_id_str, "is_success", is_success ? "true" : "false");
723 void send_message_deleted_response(tg_engine_data_s *tg_data, int buddy_id, int message_id, Eina_Bool is_success)
727 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
728 snprintf(msg_id_str, sizeof(msg_id_str), "%d", message_id);
729 make_arg3_response(tg_data, "message_deleted", "buddy_id", usr_id_str, "message_id", msg_id_str, "is_success", is_success ? "true" : "false");
733 void send_buddy_blocked_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
736 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
737 make_arg2_response(tg_data, "buddy_blocked", "buddy_id", usr_id_str, "is_success", is_success ? "true" : "false");
740 void send_buddy_unblocked_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
743 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
744 make_arg2_response(tg_data, "buddy_unblocked", "buddy_id", usr_id_str, "is_success", is_success ? "true" : "false");
747 void send_selected_group_chats_deleted_response(tg_engine_data_s *tg_data)
749 make_base_response(tg_data, "selected_group_chats_deleted_response");
752 void send_group_chat_deleted_response(tg_engine_data_s *tg_data, int chat_id, Eina_Bool is_success)
754 char chat_id_str[64];
755 snprintf(chat_id_str, sizeof(chat_id_str), "%d", chat_id);
756 make_arg2_response(tg_data, "group_chat_deleted_response", "chat_id", chat_id_str, "is_success", is_success ? "true" : "false");
759 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)
763 char type_of_chat_str[64];
765 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
766 snprintf(msg_id_str, sizeof(msg_id_str), "%d", message_id);
767 snprintf(type_of_chat_str, sizeof(type_of_chat_str), "%d", type_of_chat);
769 make_arg5_response(tg_data, "message_sent_to_buddy", "buddy_id", usr_id_str, "message_id", msg_id_str,
770 "table_name", table_name, "is_success", is_success ? "true" : "false", "type_of_chat", type_of_chat_str);
773 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, const char* caption)
777 char media_id_str[64];
779 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
780 snprintf(to_id_str, sizeof(to_id_str), "%d", to_id);
781 snprintf(media_id_str, sizeof(media_id_str), "%lld", media_id);
783 make_arg5_response(tg_data, "video_thumb_download_completed", "buddy_id", usr_id_str,
784 "to_peer_id", to_id_str, "media_id", media_id_str, "file_name", filename ? filename : "failed_to_load", "caption", caption ? caption : "");
787 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, const char *caption)
791 char media_id_str[64];
793 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
794 snprintf(to_id_str, sizeof(to_id_str), "%d", to_id);
795 snprintf(media_id_str, sizeof(media_id_str), "%lld", media_id);
797 make_arg5_response(tg_data, "media_download_completed", "buddy_id", usr_id_str,
798 "to_peer_id", to_id_str, "media_id", media_id_str, "file_name", filename ? filename : "failed_to_load", "caption", caption ? caption : "");
801 void send_contact_updated_response(tg_engine_data_s *tg_data, int buddy_id, char* update_message)
806 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
807 make_arg2_response(tg_data, "contact_updated", "buddy_id", usr_id_str, "update_message", update_message);
810 void send_buddy_status_updated_response(tg_engine_data_s *tg_data, int buddy_id)
813 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
814 make_arg1_response(tg_data, "buddy_status_updated", "buddy_id", usr_id_str);
817 void send_buddy_status_notification_response(tg_engine_data_s *tg_data, int buddy_id, char* budy_name, int online)
820 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
821 make_arg3_response(tg_data, "user_status_updated", "buddy_id", usr_id_str, "buddy_name", budy_name, "user_status", online ? "online" : "offline");
824 void send_buddy_type_notification_response(tg_engine_data_s *tg_data, int buddy_id, char* budy_name, int type_status)
827 char type_status_str[64];
828 snprintf(usr_id_str, sizeof(usr_id_str), "%d", buddy_id);
829 snprintf(type_status_str, sizeof(type_status_str), "%d", type_status);
830 make_arg3_response(tg_data, "type_status_updated", "buddy_id", usr_id_str, "buddy_name", budy_name, "type_status", type_status_str);
833 void send_response_for_logout(tg_engine_data_s *tg_data)
835 make_base_response(tg_data, "logout_completed");
838 void send_server_restart_notification(tg_engine_data_s *tg_data)
840 make_base_response(tg_data, "server_restart_notification");
843 void send_response_for_server_connection_status(tg_engine_data_s *tg_data, Eina_Bool connection_status)
845 make_arg1_response(tg_data, "server_connection_status", "connection_status", connection_status ? "true" : "false");
848 void send_server_connection_failed_response(tg_engine_data_s *tg_data)
850 make_base_response(tg_data, "server_connection_failed");