fixed nextwork failed issue while login.
[apps/native/telegram-tizen.git] / tg-engine-service / src / server_response.c
1 /*
2     This file is part of Telegram application for tizen
3
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.
8
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.
13
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
17  */
18
19 #include <bundle.h>
20 #include "logger.h"
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"
26
27
28
29 Eina_Bool init_response(bundle *msg, tg_engine_data_s *tg_data, const char* command)
30 {
31         if (!msg || !tg_data)
32                 return EINA_FALSE;
33
34         if (bundle_add_str(msg, "app_name", "Tizen Telegram") != 0) {
35                 ERR("Failed to add data by key to bundle");
36                 return EINA_FALSE;
37         }
38
39         if (bundle_add_str(msg, "command", command) != 0) {
40                 ERR("Failed to add data by key to bundle");
41                 return EINA_FALSE;
42         }
43         return EINA_TRUE;
44 }
45
46 Eina_Bool send_response(bundle *msg, tg_engine_data_s *tg_data)
47 {
48         int result = SVC_RES_FAIL;
49         if (!msg || !tg_data)
50                 return EINA_FALSE;
51
52         result = tg_server_send_message(tg_data->tg_server, msg);
53         if (result != SVC_RES_OK) {
54                 ERR("Cient not ready");
55                 bundle_free(msg);
56                 return EINA_FALSE;
57         }
58
59         bundle_free(msg);
60         return EINA_TRUE;
61 }
62
63 void make_base_response(tg_engine_data_s *tg_data, const char* command)
64 {
65         bundle *msg = bundle_create();
66         if (!init_response(msg, tg_data, command)) {
67                 bundle_free(msg);
68                 return;
69         }
70
71         if (!send_response(msg, tg_data))
72                 return;
73 }
74
75 void make_arg1_response(tg_engine_data_s *tg_data, const char* command,
76                 const char* arg1_name, const char* arg1_value)
77 {
78         bundle *msg = bundle_create();
79         if (!init_response(msg, tg_data, command)) {
80                 bundle_free(msg);
81                 return;
82         }
83
84         if (bundle_add_str(msg, arg1_name, arg1_value) != 0) {
85                 ERR("Failed to add data by key to bundle1");
86                 bundle_free(msg);
87         }
88
89         if (!send_response(msg, tg_data))
90                 return;
91 }
92
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)
96 {
97         bundle *msg = bundle_create();
98         if (!init_response(msg, tg_data, command)) {
99                 bundle_free(msg);
100                 return;
101         }
102
103         if (bundle_add_str(msg, arg1_name, arg1_value) != 0) {
104                 ERR("Failed to add data by key to bundle1");
105                 bundle_free(msg);
106         }
107
108         if (bundle_add_str(msg, arg2_name, arg2_value) != 0) {
109                 ERR("Failed to add data by key to bundle2");
110                 bundle_free(msg);
111         }
112
113         if (!send_response(msg, tg_data))
114                 return;
115 }
116
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)
121 {
122         bundle *msg = bundle_create();
123         if (!init_response(msg, tg_data, command)) {
124                 bundle_free(msg);
125                 return;
126         }
127
128         if (bundle_add_str(msg, arg1_name, arg1_value) != 0) {
129                 ERR("Failed to add data by key to bundle1");
130                 bundle_free(msg);
131         }
132
133         if (bundle_add_str(msg, arg2_name, arg2_value) != 0) {
134                 ERR("Failed to add data by key to bundle2");
135                 bundle_free(msg);
136         }
137
138         if (bundle_add_str(msg, arg3_name, arg3_value) != 0) {
139                 ERR("Failed to add data by key to bundle3");
140                 bundle_free(msg);
141         }
142
143         if (!send_response(msg, tg_data))
144                 return;
145 }
146
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)
152 {
153         bundle *msg = bundle_create();
154         if (!init_response(msg, tg_data, command)) {
155                 bundle_free(msg);
156                 return;
157         }
158
159         if (bundle_add_str(msg, arg1_name, arg1_value) != 0) {
160                 ERR("Failed to add data by key to bundle1");
161                 bundle_free(msg);
162         }
163
164         if (bundle_add_str(msg, arg2_name, arg2_value) != 0) {
165                 ERR("Failed to add data by key to bundle2");
166                 bundle_free(msg);
167         }
168
169         if (bundle_add_str(msg, arg3_name, arg3_value) != 0) {
170                 ERR("Failed to add data by key to bundle3");
171                 bundle_free(msg);
172         }
173
174         if (bundle_add_str(msg, arg4_name, arg4_value) != 0) {
175                 ERR("Failed to add data by key to bundle4");
176                 bundle_free(msg);
177         }
178
179         if (!send_response(msg, tg_data))
180                 return;
181 }
182
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)
189 {
190         bundle *msg = bundle_create();
191         if (!init_response(msg, tg_data, command)) {
192                 bundle_free(msg);
193                 return;
194         }
195
196         if (bundle_add_str(msg, arg1_name, arg1_value) != 0) {
197                 ERR("Failed to add data by key to bundle1");
198                 bundle_free(msg);
199         }
200
201         if (bundle_add_str(msg, arg2_name, arg2_value) != 0) {
202                 ERR("Failed to add data by key to bundle2");
203                 bundle_free(msg);
204         }
205
206         if (bundle_add_str(msg, arg3_name, arg3_value) != 0) {
207                 ERR("Failed to add data by key to bundle3");
208                 bundle_free(msg);
209         }
210
211         if (bundle_add_str(msg, arg4_name, arg4_value) != 0) {
212                 ERR("Failed to add data by key to bundle4");
213                 bundle_free(msg);
214         }
215
216         if (bundle_add_str(msg, arg5_name, arg5_value) != 0) {
217                 ERR("Failed to add data by key to bundle5");
218                 bundle_free(msg);
219         }
220
221         if (!send_response(msg, tg_data))
222                 return;
223 }
224
225 void make_chat_response(tg_engine_data_s *tg_data, int chat_id, const char* command)
226 {
227         char id_str[64];
228         snprintf(id_str, sizeof(id_str), "%d", chat_id);
229         make_arg1_response(tg_data, command, "chat_id", id_str);
230 }
231
232 void make_buddy_response(tg_engine_data_s *tg_data, int buddy_id, const char* command)
233 {
234         char id_str[64];
235         snprintf(id_str, sizeof(id_str), "%d", buddy_id);
236         make_arg1_response(tg_data, command, "buddy_id", id_str);
237 }
238
239 void make_boolean_response(tg_engine_data_s *tg_data, Eina_Bool is_success, const char* command)
240 {
241         make_arg1_response(tg_data, command, "is_success", is_success ? "true" : "false");
242 }
243
244 void process_registration_command(tg_engine_data_s *tg_data, char* phone_no, Eina_Bool trough_sms)
245 {
246 #if 0
247         if (trough_sms && (tg_data->tg_state != TG_ENGINE_STATE_REGISTRATION || !phone_no))
248                 return;
249 #endif
250         if (!tg_data || !tgl_engine_get_TLS())
251                 return;
252
253         if (tg_data->phone_number)
254                 free(tg_data->phone_number);
255
256         if (phone_no)
257                 tg_data->phone_number = strdup(phone_no);
258         else
259                 tg_data->phone_number = NULL;
260
261         if (!trough_sms) {
262                 request_for_code_via_call(tgl_engine_get_TLS(), phone_no, trough_sms);
263                 return;
264         }
265
266         if (tg_data->get_string)
267                 tg_data->get_string(tgl_engine_get_TLS(), tg_data->phone_number, tg_data->callback_arg);
268 }
269
270 void process_validation_command(tg_engine_data_s *tg_data, char* code)
271 {
272         if (tg_data->tg_state != TG_ENGINE_STATE_CODE_REQUEST ||
273                         !code)
274                 return;
275
276         if (!tg_data || !tgl_engine_get_TLS())
277                 return;
278
279         tg_data->get_string(tgl_engine_get_TLS(), code, tg_data->callback_arg);
280 }
281
282 void process_logout_command(tg_engine_data_s *tg_data)
283 {
284         if (!tg_data)
285                 return;
286
287         logout_telegram(tg_data);
288 }
289
290 void process_forward_message_command(int to_id, int type_of_chat, int from_id, int message_id, int temp_message_id)
291 {
292         if (!tgl_engine_get_TLS())
293                 return;
294
295         forward_message_to_buddy(to_id, type_of_chat, from_id, message_id, temp_message_id);
296 }
297
298 void process_typing_status_to_buddy_command(int buddy_id, int type_of_chat, int typing_status)
299 {
300         if (!tgl_engine_get_TLS())
301                 return;
302
303         send_typing_status_to_buddy(buddy_id, type_of_chat, typing_status);
304 }
305
306 void process_send_message_command(int buddy_id, int message_id, int msg_type, char* msg_data, int type_of_chat)
307 {
308         if (!msg_data || !tgl_engine_get_TLS())
309                 return;
310
311         send_message_to_buddy(buddy_id, message_id, msg_type, msg_data, type_of_chat);
312 }
313
314 void process_delete_selected_group_chats_request(tg_engine_data_s* tg_data, Eina_List *sel_grp_chats)
315 {
316         if (!tgl_engine_get_TLS())
317                 return;
318
319         delete_selected_group_chat(tg_data, sel_grp_chats);
320 }
321
322 void process_delete_group_chat_request(tg_engine_data_s* tg_data, int chat_id)
323 {
324         if (!tgl_engine_get_TLS())
325                 return;
326
327         leave_group_chat(tg_data, chat_id);
328 }
329
330 void process_add_user_request(tg_engine_data_s* tg_data, int buddy_id, char *first_name, char *last_name, char *phone_num)
331 {
332         if (!tgl_engine_get_TLS())
333                 return;
334
335         do_add_buddy(buddy_id, first_name, last_name, phone_num);
336 }
337
338 void process_update_chat_request(tg_engine_data_s* tg_data, int chat_id)
339 {
340         if (!tgl_engine_get_TLS())
341                 return;
342
343         do_update_chat_info(chat_id);
344 }
345
346 void process_send_secret_chat_request(tg_engine_data_s* tg_data, int buddy_id)
347 {
348         if (!tgl_engine_get_TLS())
349                 return;
350         request_for_secret_chat(buddy_id);
351 }
352
353 void process_delete_user_request(tg_engine_data_s* tg_data, int buddy_id)
354 {
355         if (!tgl_engine_get_TLS())
356                 return;
357
358         do_delete_buddy(buddy_id);
359 }
360
361 void process_delete_message_request(tg_engine_data_s* tg_data, int buddy_id, int message_id)
362 {
363         if (!tgl_engine_get_TLS())
364                 return;
365
366         do_delete_message(buddy_id, message_id);
367 }
368
369 void process_block_user_request(tg_engine_data_s* tg_data, int buddy_id)
370 {
371         if (!tgl_engine_get_TLS())
372                 return;
373
374         do_block_buddy(buddy_id);
375 }
376
377 void process_unblock_user_request(tg_engine_data_s* tg_data, int buddy_id)
378 {
379         if (!tgl_engine_get_TLS())
380                 return;
381
382         do_unblock_buddy(buddy_id);
383 }
384
385 void process_delete_all_msgs_from_table_command(int buddy_id, int type_of_chat)
386 {
387         if (!tgl_engine_get_TLS())
388                 return;
389
390         delete_all_messages_from_chat(buddy_id, type_of_chat);
391 }
392
393 void process_marked_as_read_command(int buddy_id, int type_of_chat)
394 {
395         if (!tgl_engine_get_TLS())
396                 return;
397
398         send_do_mark_read_messages(buddy_id, type_of_chat);
399 }
400
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)
402 {
403         if (!file_path || !tgl_engine_get_TLS())
404                 return;
405
406         send_media_to_buddy(buddy_id, message_id, media_id, msg_type, file_path, type_of_chat);
407 }
408
409
410 void process_media_download_command(tg_engine_data_s *tg_data, int buddy_id, long long media_id)
411 {
412         media_download_request(tg_data, buddy_id, media_id);
413 }
414
415 void process_add_contacts_command(tg_engine_data_s *tg_data, int size, Eina_List* contact_list)
416 {
417         add_contacts_to_user(tg_data, size, contact_list);
418 }
419
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)
421 {
422         create_new_group(tg_data, buddy_ids, group_name, group_icon);
423 }
424
425 void process_set_group_chat_new_title_command(tg_engine_data_s *tg_data, int buddy_id, const char *new_title)
426 {
427         set_group_chat_new_title(tg_data, buddy_id, new_title);
428 }
429
430 void process_add_new_buddy_to_chat_command(tg_engine_data_s *tg_data, int s_buddy_id, int s_chat_id)
431 {
432         set_group_chat_add_new_buddy(tg_data, s_buddy_id, s_chat_id);
433 }
434
435 void process_remove_buddy_from_chat_command(tg_engine_data_s *tg_data, int s_buddy_id, int s_chat_id)
436 {
437         set_group_chat_remove_buddy(tg_data, s_buddy_id, s_chat_id);
438 }
439
440 void process_set_group_chat_profile_pic_command(tg_engine_data_s *tg_data, int buddy_id, const char *file_path)
441 {
442         set_group_chat_profile_picture(tg_data, buddy_id, file_path);
443 }
444
445 void process_set_profile_pic_command(tg_engine_data_s *tg_data, int buddy_id, const char *file_path)
446 {
447         set_profile_picture(tg_data, buddy_id, file_path);
448 }
449
450 void process_update_display_name_command(tg_engine_data_s *tg_data, int buddy_id, const char *first_name, const char *last_name)
451 {
452         update_user_display_name(tg_data, buddy_id, first_name, last_name);
453 }
454
455 void process_set_username_command(tg_engine_data_s *tg_data, int buddy_id, const char *username)
456 {
457         set_user_name(tg_data, buddy_id, username);
458 }
459
460 void send_request_phone_num_again(tg_engine_data_s *tg_data)
461 {
462         make_arg1_response(tg_data, "request_phone_num_again", "phone_number", tg_data->phone_number);
463 }
464
465 void send_request_phone_new_num(tg_engine_data_s *tg_data)
466 {
467         make_base_response(tg_data, "request_phone_new_num");
468 }
469
470 void send_request_code_again(tg_engine_data_s *tg_data)
471 {
472         make_arg1_response(tg_data, "request_reg_code_again", "phone_number", tg_data->phone_number);
473 }
474
475 void send_registration_response(tg_engine_data_s *tg_data, Eina_Bool is_success)
476 {
477         make_arg2_response(tg_data, "registration_done", "phone_number", tg_data->phone_number, "is_success", is_success ? "true" : "false");
478 }
479
480 void send_new_group_added_response(tg_engine_data_s *tg_data, int chat_id)
481 {
482         make_chat_response(tg_data, chat_id, "new_group_added");
483 }
484
485 void send_new_buddy_added_response(tg_engine_data_s *tg_data, int buddy_id)
486 {
487         make_buddy_response(tg_data, buddy_id, "new_buddy_added");
488 }
489
490 void send_response_to_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id)
491 {
492         make_chat_response(tg_data, chat_id, "response_group_chat_updated");
493 }
494
495 void send_group_chat_updated_response(tg_engine_data_s *tg_data, int chat_id, const char *type_of_change)
496 {
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);
500 }
501
502 void send_chat_profile_pic_updated_response(tg_engine_data_s *tg_data, int chat_id, char* filename)
503 {
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);
507 }
508
509 void send_name_registration_response(tg_engine_data_s *tg_data)
510 {
511         make_base_response(tg_data, "name_registration_request");
512 }
513
514 void send_add_contacts_request(tg_engine_data_s *tg_data)
515 {
516         make_base_response(tg_data, "add_contacts_request");
517 }
518
519 void send_server_not_initialized_response(tg_engine_data_s *tg_data)
520 {
521         make_base_response(tg_data, "server_not_initialized");
522 }
523
524 void send_contacts_and_chats_load_done_response(tg_engine_data_s *tg_data, Eina_Bool is_success)
525 {
526         make_boolean_response(tg_data, is_success, "contacts_and_chats_load_done");
527 }
528
529 void send_self_profile_name_updated_response(tg_engine_data_s *tg_data, char *first_name, char *last_name, Eina_Bool is_success)
530 {
531         make_arg3_response(tg_data, "self_profile_name_updated", "first_name", first_name, "last_name", last_name, "is_success", is_success ? "true" : "false");
532 }
533
534 void send_self_user_name_updated_response(tg_engine_data_s *tg_data, char *username, Eina_Bool is_success)
535 {
536         make_arg2_response(tg_data, "self_username_updated", "username", username, "is_success", is_success ? "true" : "false");
537 }
538
539 void send_self_profile_picture_updated_response(tg_engine_data_s *tg_data, char *file_path, Eina_Bool is_success)
540 {
541         make_arg2_response(tg_data, "self_profile_picture_updated", "file_path", file_path, "is_success", is_success ? "true" : "false");
542 }
543
544 void send_contacts_load_done_response(tg_engine_data_s *tg_data, Eina_Bool is_success)
545 {
546         make_boolean_response(tg_data, is_success, "contacts_load_done");
547 }
548
549 void send_buddy_profile_pic_updated_response(tg_engine_data_s *tg_data, int buddy_id, char* file_path)
550 {
551         char usr_id_str[64];
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);
554 }
555
556
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)
558 {
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");
562                 bundle_free(msg);
563         }
564
565         if (bundle_add_str(msg, "command", "message_received_with_date") != 0) {
566                 ERR("Failed to add data by key to bundle");
567                 bundle_free(msg);
568         }
569
570         char from_id_str[50];
571         snprintf(from_id_str, sizeof(from_id_str), "%d", from_id);
572
573         if (bundle_add_str(msg, "from_id", from_id_str) != 0) {
574                 ERR("Failed to add data by key to bundle");
575                 bundle_free(msg);
576         }
577
578         char to_id_str[50];
579         snprintf(to_id_str, sizeof(to_id_str), "%d", to_id);
580
581         if (bundle_add_str(msg, "to_id", to_id_str) != 0) {
582                 ERR("Failed to add data by key to bundle");
583                 bundle_free(msg);
584         }
585
586         char msg_id_str[50];
587         snprintf(msg_id_str, sizeof(msg_id_str), "%lld", message_id);
588
589         if (bundle_add_str(msg, "message_id", msg_id_str) != 0) {
590                 ERR("Failed to add data by key to bundle");
591                 bundle_free(msg);
592         }
593
594         char date_id_str[50];
595         snprintf(date_id_str, sizeof(date_id_str), "%d", date_id);
596
597         if (bundle_add_str(msg, "date_id", date_id_str) != 0) {
598                 ERR("Failed to add data by key to bundle");
599                 bundle_free(msg);
600         }
601
602         char type_of_chat_str[50];
603         snprintf(type_of_chat_str, sizeof(type_of_chat_str), "%d", type_of_chat);
604
605         if (bundle_add_str(msg, "type_of_chat", type_of_chat_str) != 0) {
606                 ERR("Failed to add data by key to bundle");
607                 bundle_free(msg);
608         }
609
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);
612
613         bundle_free(msg);
614 }
615
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)
617 {
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");
621                 bundle_free(msg);
622         }
623
624         if (bundle_add_str(msg, "command", "message_received") != 0) {
625                 ERR("Failed to add data by key to bundle");
626                 bundle_free(msg);
627         }
628
629         char from_id_str[64];
630         snprintf(from_id_str, sizeof(from_id_str), "%d", from_id);
631
632         if (bundle_add_str(msg, "from_id", from_id_str) != 0) {
633                 ERR("Failed to add data by key to bundle");
634                 bundle_free(msg);
635         }
636
637         char to_id_str[64];
638         snprintf(to_id_str, sizeof(to_id_str), "%d", to_id);
639
640         if (bundle_add_str(msg, "to_id", to_id_str) != 0) {
641                 ERR("Failed to add data by key to bundle");
642                 bundle_free(msg);
643         }
644
645         char msg_id_str[64];
646         snprintf(msg_id_str, sizeof(msg_id_str), "%lld", message_id);
647
648         if (bundle_add_str(msg, "message_id", msg_id_str) != 0) {
649                 ERR("Failed to add data by key to bundle");
650                 bundle_free(msg);
651         }
652
653         char type_of_chat_str[64];
654         snprintf(type_of_chat_str, sizeof(type_of_chat_str), "%d", type_of_chat);
655
656         if (bundle_add_str(msg, "type_of_chat", type_of_chat_str) != 0) {
657                 ERR("Failed to add data by key to bundle");
658                 bundle_free(msg);
659         }
660
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);
663
664         bundle_free(msg);
665 }
666
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)
668 {
669         char usr_id_str[64];
670         char msg_id_str[64];
671         char type_of_chat_str[64];
672
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);
676
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);
679 }
680
681 void send_group_chat_delete_buddy_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success)
682 {
683         char usr_id_str[64];
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");
686 }
687
688 void send_group_chat_new_buddy_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success)
689 {
690         char usr_id_str[64];
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");
693 }
694
695 void send_group_chat_rename_response(tg_engine_data_s *tg_data, int peer_id, Eina_Bool is_success)
696 {
697         char usr_id_str[64];
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");
700 }
701
702 void send_new_contact_added_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
703 {
704         char usr_id_str[64];
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");
707 }
708
709 void send_buddy_readded_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
710 {
711         char usr_id_str[64];
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");
714 }
715
716 void send_buddy_deleted_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
717 {
718         char usr_id_str[64];
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");
721 }
722
723 void send_message_deleted_response(tg_engine_data_s *tg_data, int buddy_id, int message_id, Eina_Bool is_success)
724 {
725         char usr_id_str[64];
726         char msg_id_str[64];
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");
730 }
731
732
733 void send_buddy_blocked_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
734 {
735         char usr_id_str[64];
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");
738 }
739
740 void send_buddy_unblocked_response(tg_engine_data_s *tg_data, int buddy_id, Eina_Bool is_success)
741 {
742         char usr_id_str[64];
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");
745 }
746
747 void send_selected_group_chats_deleted_response(tg_engine_data_s *tg_data)
748 {
749         make_base_response(tg_data, "selected_group_chats_deleted_response");
750 }
751
752 void send_group_chat_deleted_response(tg_engine_data_s *tg_data, int chat_id, Eina_Bool is_success)
753 {
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");
757 }
758
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)
760 {
761         char usr_id_str[64];
762         char msg_id_str[64];
763         char type_of_chat_str[64];
764
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);
768
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);
771 }
772
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)
774 {
775         char usr_id_str[64];
776         char to_id_str[64];
777         char media_id_str[64];
778
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);
782
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 : "");
785 }
786
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)
788 {
789         char usr_id_str[64];
790                 char to_id_str[64];
791                 char media_id_str[64];
792
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);
796
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 : "");
799 }
800
801 void send_contact_updated_response(tg_engine_data_s *tg_data, int buddy_id, char* update_message)
802 {
803         if (!update_message)
804                 return;
805         char usr_id_str[64];
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);
808 }
809
810 void send_buddy_status_updated_response(tg_engine_data_s *tg_data, int buddy_id)
811 {
812         char usr_id_str[64];
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);
815 }
816
817 void send_buddy_status_notification_response(tg_engine_data_s *tg_data, int buddy_id, char* budy_name, int online)
818 {
819         char usr_id_str[64];
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");
822 }
823
824 void send_buddy_type_notification_response(tg_engine_data_s *tg_data, int buddy_id, char* budy_name, int type_status)
825 {
826         char usr_id_str[64];
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);
831 }
832
833 void send_response_for_logout(tg_engine_data_s *tg_data)
834 {
835         make_base_response(tg_data, "logout_completed");
836 }
837
838 void send_server_restart_notification(tg_engine_data_s *tg_data)
839 {
840         make_base_response(tg_data, "server_restart_notification");
841 }
842
843 void send_response_for_server_connection_status(tg_engine_data_s *tg_data, Eina_Bool connection_status)
844 {
845         make_arg1_response(tg_data, "server_connection_status", "connection_status", connection_status ? "true" : "false");
846 }
847
848 void send_server_connection_failed_response(tg_engine_data_s *tg_data)
849 {
850         make_base_response(tg_data, "server_connection_failed");
851 }
852