From 7da6dd082710c2527e0cfd0a4fe04f4350bb5a9d Mon Sep 17 00:00:00 2001 From: ~/Saleh Date: Sun, 28 Feb 2016 00:54:45 +0300 Subject: [PATCH 01/11] channel set_about --- lua-tg.c | 146 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 76 insertions(+), 70 deletions(-) diff --git a/lua-tg.c b/lua-tg.c index 454a0a66..6084d152 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -170,14 +170,14 @@ void push_update_types (unsigned flags) { my_lua_checkstack (luaState, 4); lua_newtable (luaState); int cc = 0; - - + + if (flags & TGL_UPDATE_CREATED) { lua_add_string_field_arr (cc++, "created"); - } + } if (flags & TGL_UPDATE_DELETED) { lua_add_string_field_arr (cc++, "deleted"); - } + } if (flags & TGL_UPDATE_PHONE) { lua_add_string_field_arr (cc++, "phone"); } @@ -225,7 +225,7 @@ void push_update_types (unsigned flags) { void push_peer (tgl_peer_id_t id, tgl_peer_t *P) { lua_newtable (luaState); - + lua_add_string_field ("id", print_permanent_peer_id (P ? P->id : id)); lua_pushstring (luaState, "peer_type"); push_tgl_peer_type (tgl_get_peer_type (id)); @@ -233,7 +233,7 @@ void push_peer (tgl_peer_id_t id, tgl_peer_t *P) { lua_add_num_field ("peer_id", tgl_get_peer_id (id)); if (!P || !(P->flags & TGLPF_CREATED)) { - lua_pushstring (luaState, "print_name"); + lua_pushstring (luaState, "print_name"); static char s[100]; switch (tgl_get_peer_type (id)) { case TGL_PEER_USER: @@ -251,15 +251,15 @@ void push_peer (tgl_peer_id_t id, tgl_peer_t *P) { default: assert (0); } - lua_pushstring (luaState, s); + lua_pushstring (luaState, s); lua_settable (luaState, -3); // flags - + return; } - + lua_add_string_field ("print_name", P->print_name); lua_add_num_field ("flags", P->flags); - + switch (tgl_get_peer_type (id)) { case TGL_PEER_USER: push_user (P); @@ -367,7 +367,7 @@ void push_service (struct tgl_message *M) { case tgl_message_action_chat_add_users: lua_newtable (luaState); lua_add_string_field ("type", "chat_add_user"); - + lua_pushstring (luaState, "user"); push_peer (tgl_set_peer_id (TGL_PEER_USER, M->action.users[0]), tgl_peer_get (TLS, tgl_set_peer_id (TGL_PEER_USER, M->action.users[0]))); lua_settable (luaState, -3); @@ -375,7 +375,7 @@ void push_service (struct tgl_message *M) { case tgl_message_action_chat_add_user_by_link: lua_newtable (luaState); lua_add_string_field ("type", "chat_add_user_link"); - + lua_pushstring (luaState, "link_issuer"); push_peer (tgl_set_peer_id (TGL_PEER_USER, M->action.user), tgl_peer_get (TLS, tgl_set_peer_id (TGL_PEER_USER, M->action.user))); lua_settable (luaState, -3); @@ -383,7 +383,7 @@ void push_service (struct tgl_message *M) { case tgl_message_action_chat_delete_user: lua_newtable (luaState); lua_add_string_field ("type", "chat_del_user"); - + lua_pushstring (luaState, "user"); push_peer (tgl_set_peer_id (TGL_PEER_USER, M->action.user), tgl_peer_get (TLS, tgl_set_peer_id (TGL_PEER_USER, M->action.user))); lua_settable (luaState, -3); @@ -421,7 +421,7 @@ void push_service (struct tgl_message *M) { lua_add_string_field ("type", "set_layer"); lua_add_num_field ("layer", M->action.layer); break; - case tgl_message_action_typing: + case tgl_message_action_typing: lua_newtable (luaState); lua_add_string_field ("type", "typing"); break; @@ -464,7 +464,7 @@ void push_service (struct tgl_message *M) { } } -void push_message (struct tgl_message *M) { +void push_message (struct tgl_message *M) { assert (M); my_lua_checkstack (luaState, 10); lua_newtable (luaState); @@ -472,7 +472,7 @@ void push_message (struct tgl_message *M) { lua_add_string_field ("id", print_permanent_msg_id (M->permanent_id)); if (!(M->flags & TGLMF_CREATED)) { return; } lua_add_num_field ("flags", M->flags); - + if (tgl_get_peer_type (M->fwd_from_id)) { lua_pushstring (luaState, "fwd_from"); push_peer (M->fwd_from_id, tgl_peer_get (TLS, M->fwd_from_id)); @@ -484,55 +484,55 @@ void push_message (struct tgl_message *M) { if (M->reply_id) { tgl_message_id_t msg_id = M->permanent_id; msg_id.id = M->reply_id; - + lua_add_string_field ("reply_id", print_permanent_msg_id (msg_id)); } if (M->flags & TGLMF_MENTION) { lua_pushstring (luaState, "mention"); lua_pushboolean (luaState, 1); - lua_settable (luaState, -3); + lua_settable (luaState, -3); } - + lua_pushstring (luaState, "from"); push_peer (M->from_id, tgl_peer_get (TLS, M->from_id)); - lua_settable (luaState, -3); - + lua_settable (luaState, -3); + lua_pushstring (luaState, "to"); push_peer (M->to_id, tgl_peer_get (TLS, M->to_id)); - lua_settable (luaState, -3); - + lua_settable (luaState, -3); + lua_pushstring (luaState, "out"); lua_pushboolean (luaState, (M->flags & TGLMF_OUT) != 0); - lua_settable (luaState, -3); - + lua_settable (luaState, -3); + lua_pushstring (luaState, "unread"); lua_pushboolean (luaState, (M->flags & TGLMF_UNREAD) != 0); - lua_settable (luaState, -3); - + lua_settable (luaState, -3); + lua_pushstring (luaState, "date"); lua_pushnumber (luaState, M->date); - lua_settable (luaState, -3); - + lua_settable (luaState, -3); + lua_pushstring (luaState, "service"); lua_pushboolean (luaState, (M->flags & TGLMF_SERVICE) != 0); - lua_settable (luaState, -3); + lua_settable (luaState, -3); - if (!(M->flags & TGLMF_SERVICE)) { + if (!(M->flags & TGLMF_SERVICE)) { if (M->message_len && M->message) { lua_pushstring (luaState, "text"); lua_pushlstring (luaState, M->message, M->message_len); - lua_settable (luaState, -3); + lua_settable (luaState, -3); } if (M->media.type && M->media.type != tgl_message_media_none) { lua_pushstring (luaState, "media"); push_media (&M->media); - lua_settable (luaState, -3); + lua_settable (luaState, -3); } } else { lua_pushstring (luaState, "action"); push_service (M); - lua_settable (luaState, -3); + lua_settable (luaState, -3); } } @@ -661,10 +661,10 @@ struct lua_arg { struct lua_arg lua_ptr[MAX_LUA_COMMANDS]; static int pos; -static inline tgl_peer_t *get_peer (const char *s) { +static inline tgl_peer_t *get_peer (const char *s) { return tgl_peer_get_by_name (TLS, s); } - + enum lua_query_type { lq_contact_list, lq_dialog_list, @@ -718,7 +718,8 @@ enum lua_query_type { lq_channel_invite_user, lq_channel_kick_user, lq_channel_get_admins, - lq_channel_get_users + lq_channel_get_users, + lq_channel_set_about }; struct lua_query_extra { @@ -1363,6 +1364,10 @@ void lua_do_all (void) { tgl_do_channel_get_members (TLS, lua_ptr[p + 1].peer_id, 100, 0, 0, lua_contact_list_cb, lua_ptr[p].ptr); p += 2; break; + case lq_channel_set_about: + tgl_do_channel_set_about (TLS, lua_ptr[p + 1].peer_id, LUA_STR_ARG (p + 2), lua_empty_cb, lua_ptr[p].ptr); + p += 3; + break; /* lq_delete_msg, lq_restore_msg, @@ -1460,7 +1465,7 @@ struct lua_function functions[] = { {"send_contact", lq_send_contact, { lfp_peer, lfp_string, lfp_string, lfp_string, lfp_none }}, {"status_online", lq_status_online, { lfp_none }}, {"status_offline", lq_status_offline, { lfp_none }}, - {"send_location", lq_send_location, { lfp_peer, lfp_double, lfp_double, lfp_none }}, + {"send_location", lq_send_location, { lfp_peer, lfp_double, lfp_double, lfp_none }}, {"ext_function", lq_extf, { lfp_string, lfp_none }}, {"import_chat_link", lq_import_chat_link, { lfp_string, lfp_none }}, {"export_chat_link", lq_export_chat_link, { lfp_chat, lfp_none }}, @@ -1468,6 +1473,7 @@ struct lua_function functions[] = { {"channel_kick_user", lq_channel_kick_user, { lfp_channel, lfp_user, lfp_none }}, {"channel_get_admins", lq_channel_get_admins, { lfp_channel, lfp_none }}, {"channel_get_users", lq_channel_get_users, { lfp_channel, lfp_none }}, + {"channel_set_about", lq_channel_set_about, { lfp_channel, lfp_string, lfp_none }}, { 0, 0, { lfp_none}} }; @@ -1478,10 +1484,10 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) { lua_pushboolean (L, 0); return 1; } - + int a1 = luaL_ref (L, LUA_REGISTRYINDEX); int a2 = luaL_ref (L, LUA_REGISTRYINDEX); - + struct lua_query_extra *e = malloc (sizeof (*e)); assert (e); e->func = a2; @@ -1518,7 +1524,7 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) { ok = 0; break; } - + if (F->params[p] == lfp_user) { peer_id = parse_input_peer_id (s, strlen (s), TGL_PEER_USER); } else if (F->params[p] == lfp_chat) { @@ -1530,12 +1536,12 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) { } else { peer_id = parse_input_peer_id (s, strlen (s), 0); } - + if (!peer_id.peer_type) { ok = 0; break; } - + lua_ptr[pos + p].peer_id = peer_id; break; @@ -1551,10 +1557,10 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) { case lfp_number: num = lua_tonumber (L, -cc); - + lua_ptr[pos + p].num = num; break; - + case lfp_double: dval = lua_tonumber (L, -cc); lua_ptr[pos + p].dnum = dval; @@ -1572,27 +1578,27 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) { break; } break; - + case lfp_positive_number: num = lua_tonumber (L, -cc); if (num <= 0) { ok = 0; break; } - + lua_ptr[pos + p].num = num; break; - + case lfp_nonnegative_number: num = lua_tonumber (L, -cc); if (num < 0) { ok = 0; break; } - + lua_ptr[pos + p].num = num; break; - + default: assert (0); } @@ -1605,7 +1611,7 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) { lua_pushboolean (L, 0); return 1; } - + for (p = 0; p < sp; p++) { if (F->params[p] == lfp_string) { lua_ptr[pos + p].str = tstrdup (lua_ptr[pos + p].str); @@ -1620,7 +1626,7 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) { static void lua_postpone_alarm (evutil_socket_t fd, short what, void *arg) { int *t = arg; - + lua_settop (luaState, 0); //lua_checkstack (luaState, 20); my_lua_checkstack (luaState, 20); @@ -1628,7 +1634,7 @@ static void lua_postpone_alarm (evutil_socket_t fd, short what, void *arg) { lua_rawgeti (luaState, LUA_REGISTRYINDEX, t[1]); lua_rawgeti (luaState, LUA_REGISTRYINDEX, t[0]); assert (lua_gettop (luaState) == 2); - + int r = ps_lua_pcall (luaState, 1, 0, 0); luaL_unref (luaState, LUA_REGISTRYINDEX, t[0]); @@ -1664,13 +1670,13 @@ static int postpone_from_lua (lua_State *L) { t[0] = a1; t[1] = a2; *(void **)(t + 2) = ev; - + struct timeval ts= { .tv_sec = (long)timeout, .tv_usec = (timeout - ((long)timeout)) * 1000000 }; event_add (ev, &ts); - + lua_pushboolean (L, 1); return 1; } @@ -1683,7 +1689,7 @@ static int safe_quit_from_lua (lua_State *L) { return 1; } safe_quit = 1; - + lua_pushboolean (L, 1); return 1; } @@ -1760,11 +1766,11 @@ struct command { static void do_interface_from_lua (struct command *command, int arg_num, struct arg args[], struct in_ev *ev) { lua_settop (luaState, 0); my_lua_checkstack (luaState, 20); - - struct lua_query_extra *e = command->arg; + + struct lua_query_extra *e = command->arg; lua_rawgeti (luaState, LUA_REGISTRYINDEX, e->func); lua_rawgeti (luaState, LUA_REGISTRYINDEX, e->param); - + int i; for (i = 0; i < arg_num; i ++) { int j = i; @@ -1779,7 +1785,7 @@ static void do_interface_from_lua (struct command *command, int arg_num, struct switch (command->args[j] & 0xff) { case ca_none: case ca_period: - assert (0); + assert (0); break; case ca_user: case ca_chat: @@ -1817,9 +1823,9 @@ static void do_interface_from_lua (struct command *command, int arg_num, struct break; } } - - + + int r = ps_lua_pcall (luaState, 1 + arg_num, 0, 0); if (r) { @@ -1842,7 +1848,7 @@ static int register_interface_from_lua (lua_State *L) { for (i = 0; i < n - 4; i++) { const char *s = lua_tostring (L, -1); lua_pop (L, 1); - + if (!s || !strlen (s)) { lua_pushboolean (L, 0); return 1; @@ -1873,7 +1879,7 @@ static int register_interface_from_lua (lua_State *L) { VARIANT (double) VARIANT (string_end) VARIANT (string) - + #undef VARTIANT if (!ok) { @@ -1881,12 +1887,12 @@ static int register_interface_from_lua (lua_State *L) { return 1; } } - + const char *s = lua_tostring (L, -1); lua_pop (L, 1); - + cmd.desc = s ? tstrdup (s) : tstrdup ("no help provided"); - + int a1 = luaL_ref (L, LUA_REGISTRYINDEX); int a2 = luaL_ref (L, LUA_REGISTRYINDEX); @@ -1896,9 +1902,9 @@ static int register_interface_from_lua (lua_State *L) { e->param = a1; cmd.arg = e; - + cmd.fun = do_interface_from_lua; - + s = lua_tostring (L, -1); lua_pop (L, 1); @@ -1922,7 +1928,7 @@ void lua_init (const char *file) { my_lua_register (luaState, functions[i].name, universal_from_lua); i ++; } - + lua_register (luaState, "postpone", postpone_from_lua); lua_register (luaState, "safe_quit", safe_quit_from_lua); lua_register (luaState, "register_interface_function", register_interface_from_lua); From b260a1cf1e9146a0497a26bd2a0c17172cfb3828 Mon Sep 17 00:00:00 2001 From: ~/Saleh Date: Sun, 28 Feb 2016 00:57:21 +0300 Subject: [PATCH 02/11] export_channel_link --- lua-tg.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua-tg.c b/lua-tg.c index 6084d152..27890848 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -719,7 +719,8 @@ enum lua_query_type { lq_channel_kick_user, lq_channel_get_admins, lq_channel_get_users, - lq_channel_set_about + lq_channel_set_about, + lq_export_channel_link }; struct lua_query_extra { @@ -1368,6 +1369,10 @@ void lua_do_all (void) { tgl_do_channel_set_about (TLS, lua_ptr[p + 1].peer_id, LUA_STR_ARG (p + 2), lua_empty_cb, lua_ptr[p].ptr); p += 3; break; + case lq_export_channel_link: + tgl_do_export_channel_link (TLS, lua_ptr[p + 1].peer_id, lua_str_cb, lua_ptr[p].ptr); + p += 2; + break; /* lq_delete_msg, lq_restore_msg, @@ -1474,6 +1479,7 @@ struct lua_function functions[] = { {"channel_get_admins", lq_channel_get_admins, { lfp_channel, lfp_none }}, {"channel_get_users", lq_channel_get_users, { lfp_channel, lfp_none }}, {"channel_set_about", lq_channel_set_about, { lfp_channel, lfp_string, lfp_none }}, + {"export_channel_link", lq_export_channel_link, { lfp_channel, lfp_none }}, { 0, 0, { lfp_none}} }; From 77194cebfb7f7c5b5f8277eda5c8e5176133ddee Mon Sep 17 00:00:00 2001 From: ~/Saleh Date: Sun, 28 Feb 2016 01:00:29 +0300 Subject: [PATCH 03/11] channel_set_admin --- lua-tg.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua-tg.c b/lua-tg.c index 27890848..5523ef3d 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -720,7 +720,8 @@ enum lua_query_type { lq_channel_get_admins, lq_channel_get_users, lq_channel_set_about, - lq_export_channel_link + lq_export_channel_link, + lq_channel_set_admin }; struct lua_query_extra { @@ -1373,6 +1374,10 @@ void lua_do_all (void) { tgl_do_export_channel_link (TLS, lua_ptr[p + 1].peer_id, lua_str_cb, lua_ptr[p].ptr); p += 2; break; + case lq_channel_set_admin: + tgl_do_channel_set_admin (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 2].peer_id, 2, lua_empty_cb, lua_ptr[p].ptr); + p += 3; + break; /* lq_delete_msg, lq_restore_msg, @@ -1480,6 +1485,7 @@ struct lua_function functions[] = { {"channel_get_users", lq_channel_get_users, { lfp_channel, lfp_none }}, {"channel_set_about", lq_channel_set_about, { lfp_channel, lfp_string, lfp_none }}, {"export_channel_link", lq_export_channel_link, { lfp_channel, lfp_none }}, + {"channel_set_admin", lq_channel_set_admin, { lfp_channel, lfp_user,lfp_none }}, { 0, 0, { lfp_none}} }; From 4c7a69b4f54b1e36bf45d334c883816f2e83af55 Mon Sep 17 00:00:00 2001 From: ~/Saleh Date: Sun, 28 Feb 2016 01:01:56 +0300 Subject: [PATCH 04/11] channel_leave --- lua-tg.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua-tg.c b/lua-tg.c index 5523ef3d..bd3b0719 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -721,7 +721,8 @@ enum lua_query_type { lq_channel_get_users, lq_channel_set_about, lq_export_channel_link, - lq_channel_set_admin + lq_channel_set_admin, + lq_channel_leave }; struct lua_query_extra { @@ -1378,6 +1379,10 @@ void lua_do_all (void) { tgl_do_channel_set_admin (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 2].peer_id, 2, lua_empty_cb, lua_ptr[p].ptr); p += 3; break; + case lq_channel_leave: + tgl_do_leave_channel (TLS, lua_ptr[p + 1].peer_id, lua_empty_cb, lua_ptr[p].ptr); + p += 2; + break; /* lq_delete_msg, lq_restore_msg, @@ -1486,6 +1491,7 @@ struct lua_function functions[] = { {"channel_set_about", lq_channel_set_about, { lfp_channel, lfp_string, lfp_none }}, {"export_channel_link", lq_export_channel_link, { lfp_channel, lfp_none }}, {"channel_set_admin", lq_channel_set_admin, { lfp_channel, lfp_user,lfp_none }}, + {"channel_leave", lq_channel_leave, { lfp_channel, lfp_none }}, { 0, 0, { lfp_none}} }; From 9ab2dde3e78c68e6036def12ccba36804a3a46aa Mon Sep 17 00:00:00 2001 From: ~/Saleh Date: Sun, 28 Feb 2016 01:06:54 +0300 Subject: [PATCH 05/11] resolve_username --- lua-tg.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/lua-tg.c b/lua-tg.c index bd3b0719..5197dfc0 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -722,7 +722,8 @@ enum lua_query_type { lq_channel_set_about, lq_export_channel_link, lq_channel_set_admin, - lq_channel_leave + lq_channel_leave, + lq_contact_search }; struct lua_query_extra { @@ -1142,6 +1143,38 @@ void lua_str_cb (struct tgl_state *TLSR, void *cb_extra, int success, const char free (cb); } +void lua_contact_search_cb (struct tgl_state *TLSR, void *cb_extra, int success, tgl_peer_t *C) { + assert (TLSR == TLS); + struct lua_query_extra *cb = cb_extra; + lua_settop (luaState, 0); + //lua_checkstack (luaState, 20); + my_lua_checkstack (luaState, 20); + + lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); + lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); + + lua_pushnumber (luaState, success); + + if (success) { + push_peer (C->id, (void *)C); + } else { + lua_pushboolean (luaState, 0); + } + + assert (lua_gettop (luaState) == 4); + + int r = ps_lua_pcall (luaState, 3, 0, 0); + + luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); + luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); + + if (r) { + logprintf ("lua: %s\n", lua_tostring (luaState, -1)); + } + + free (cb); +} + #define LUA_STR_ARG(n) lua_ptr[n].str, strlen (lua_ptr[n].str) void lua_do_all (void) { @@ -1383,6 +1416,10 @@ void lua_do_all (void) { tgl_do_leave_channel (TLS, lua_ptr[p + 1].peer_id, lua_empty_cb, lua_ptr[p].ptr); p += 2; break; + case lq_contact_search: + tgl_do_contact_search (TLS, LUA_STR_ARG (p + 1), lua_contact_search_cb, lua_ptr[p].ptr); + p += 2; + break; /* lq_delete_msg, lq_restore_msg, @@ -1492,6 +1529,7 @@ struct lua_function functions[] = { {"export_channel_link", lq_export_channel_link, { lfp_channel, lfp_none }}, {"channel_set_admin", lq_channel_set_admin, { lfp_channel, lfp_user,lfp_none }}, {"channel_leave", lq_channel_leave, { lfp_channel, lfp_none }}, + {"resolve_username", lq_contact_search, { lfp_string, lfp_none }}, { 0, 0, { lfp_none}} }; From 255392446a581eb0755ac460227c98969b8048b5 Mon Sep 17 00:00:00 2001 From: ~/Saleh Date: Sun, 28 Feb 2016 01:08:29 +0300 Subject: [PATCH 06/11] channel_join --- lua-tg.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua-tg.c b/lua-tg.c index 5197dfc0..bb07f87e 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -723,7 +723,8 @@ enum lua_query_type { lq_export_channel_link, lq_channel_set_admin, lq_channel_leave, - lq_contact_search + lq_contact_search, + lq_channel_join }; struct lua_query_extra { @@ -1420,6 +1421,10 @@ void lua_do_all (void) { tgl_do_contact_search (TLS, LUA_STR_ARG (p + 1), lua_contact_search_cb, lua_ptr[p].ptr); p += 2; break; + case lq_channel_join: + tgl_do_join_channel (TLS, lua_ptr[p + 1].peer_id, lua_empty_cb, lua_ptr[p].ptr); + p += 2; + break; /* lq_delete_msg, lq_restore_msg, @@ -1530,6 +1535,7 @@ struct lua_function functions[] = { {"channel_set_admin", lq_channel_set_admin, { lfp_channel, lfp_user,lfp_none }}, {"channel_leave", lq_channel_leave, { lfp_channel, lfp_none }}, {"resolve_username", lq_contact_search, { lfp_string, lfp_none }}, + {"channel_join", lq_channel_join, { lfp_channel, lfp_none }}, { 0, 0, { lfp_none}} }; From fd1a5971c1351de774da09337c44696229392fa2 Mon Sep 17 00:00:00 2001 From: ~/Saleh Date: Sun, 28 Feb 2016 01:10:19 +0300 Subject: [PATCH 07/11] get_message --- lua-tg.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua-tg.c b/lua-tg.c index bb07f87e..11a4f0a5 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -724,7 +724,8 @@ enum lua_query_type { lq_channel_set_admin, lq_channel_leave, lq_contact_search, - lq_channel_join + lq_channel_join, + lq_get_message }; struct lua_query_extra { @@ -1425,6 +1426,10 @@ void lua_do_all (void) { tgl_do_join_channel (TLS, lua_ptr[p + 1].peer_id, lua_empty_cb, lua_ptr[p].ptr); p += 2; break; + case lq_get_message: + tgl_do_get_message (TLS, &lua_ptr[p + 1].msg_id, lua_msg_cb, lua_ptr[p].ptr); + p += 2; + break; /* lq_delete_msg, lq_restore_msg, @@ -1536,6 +1541,7 @@ struct lua_function functions[] = { {"channel_leave", lq_channel_leave, { lfp_channel, lfp_none }}, {"resolve_username", lq_contact_search, { lfp_string, lfp_none }}, {"channel_join", lq_channel_join, { lfp_channel, lfp_none }}, + {"get_message", lq_get_message, { lfp_msg, lfp_none }}, { 0, 0, { lfp_none}} }; From 0b5b7f8ebca2447717d0d7b55aac0cc547f2dc0a Mon Sep 17 00:00:00 2001 From: ~/Saleh Date: Sun, 28 Feb 2016 01:15:02 +0300 Subject: [PATCH 08/11] rename_channel --- lua-tg.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua-tg.c b/lua-tg.c index 11a4f0a5..8629c2ae 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -725,7 +725,8 @@ enum lua_query_type { lq_channel_leave, lq_contact_search, lq_channel_join, - lq_get_message + lq_get_message, + lq_rename_channel }; struct lua_query_extra { @@ -1430,6 +1431,10 @@ void lua_do_all (void) { tgl_do_get_message (TLS, &lua_ptr[p + 1].msg_id, lua_msg_cb, lua_ptr[p].ptr); p += 2; break; + case lq_rename_channel: + tgl_do_rename_channel (TLS, lua_ptr[p + 1].peer_id, LUA_STR_ARG (p + 2), lua_empty_cb, lua_ptr[p].ptr); + p += 3; + break; /* lq_delete_msg, lq_restore_msg, @@ -1542,6 +1547,7 @@ struct lua_function functions[] = { {"resolve_username", lq_contact_search, { lfp_string, lfp_none }}, {"channel_join", lq_channel_join, { lfp_channel, lfp_none }}, {"get_message", lq_get_message, { lfp_msg, lfp_none }}, + {"rename_channel", lq_rename_channel, { lfp_peer, lfp_string, lfp_none }}, { 0, 0, { lfp_none}} }; From fa5afb9d10cba7a7d8f0c6ed84c031f822338673 Mon Sep 17 00:00:00 2001 From: ~/Saleh Date: Sun, 28 Feb 2016 01:16:28 +0300 Subject: [PATCH 09/11] channel_set_photo --- lua-tg.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua-tg.c b/lua-tg.c index 8629c2ae..b057595b 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -726,7 +726,8 @@ enum lua_query_type { lq_contact_search, lq_channel_join, lq_get_message, - lq_rename_channel + lq_rename_channel, + lq_channel_set_photo }; struct lua_query_extra { @@ -1435,6 +1436,10 @@ void lua_do_all (void) { tgl_do_rename_channel (TLS, lua_ptr[p + 1].peer_id, LUA_STR_ARG (p + 2), lua_empty_cb, lua_ptr[p].ptr); p += 3; break; + case lq_channel_set_photo: + tgl_do_set_channel_photo (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 2].str, lua_empty_cb, lua_ptr[p].ptr); + p += 3; + break; /* lq_delete_msg, lq_restore_msg, @@ -1548,6 +1553,7 @@ struct lua_function functions[] = { {"channel_join", lq_channel_join, { lfp_channel, lfp_none }}, {"get_message", lq_get_message, { lfp_msg, lfp_none }}, {"rename_channel", lq_rename_channel, { lfp_peer, lfp_string, lfp_none }}, + {"channel_set_photo", lq_channel_set_photo, { lfp_peer, lfp_string, lfp_none }}, { 0, 0, { lfp_none}} }; From 720d8a06176aaa65b23eaf77520a9a9f5e900665 Mon Sep 17 00:00:00 2001 From: ~/Saleh Date: Sun, 28 Feb 2016 01:29:52 +0300 Subject: [PATCH 10/11] push_channel add - user_channel --- lua-tg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lua-tg.c b/lua-tg.c index b057595b..a98ac91d 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -164,6 +164,7 @@ void push_channel (tgl_peer_t *P) { lua_add_num_field ("participants_count", P->channel.participants_count); lua_add_num_field ("admins_count", P->channel.admins_count); lua_add_num_field ("kicked_count", P->channel.kicked_count); + lua_add_string_field ("user_channel", P->channel.username); } void push_update_types (unsigned flags) { From 263c1034ede0fc50126b19e20ac9ff74eefe0f06 Mon Sep 17 00:00:00 2001 From: ~/Saleh Date: Sun, 28 Feb 2016 01:48:11 +0300 Subject: [PATCH 11/11] get_channel_list --- lua-tg.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lua-tg.c b/lua-tg.c index a98ac91d..45c53375 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -728,7 +728,8 @@ enum lua_query_type { lq_channel_join, lq_get_message, lq_rename_channel, - lq_channel_set_photo + lq_channel_set_photo, + lq_channel_list }; struct lua_query_extra { @@ -1441,6 +1442,9 @@ void lua_do_all (void) { tgl_do_set_channel_photo (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 2].str, lua_empty_cb, lua_ptr[p].ptr); p += 3; break; + case lq_channel_list: + tgl_do_get_channels_dialog_list (TLS, 100, 0, lua_dialog_list_cb, lua_ptr[p ++].ptr); + break; /* lq_delete_msg, lq_restore_msg, @@ -1555,6 +1559,7 @@ struct lua_function functions[] = { {"get_message", lq_get_message, { lfp_msg, lfp_none }}, {"rename_channel", lq_rename_channel, { lfp_peer, lfp_string, lfp_none }}, {"channel_set_photo", lq_channel_set_photo, { lfp_peer, lfp_string, lfp_none }}, + {"get_channel_list", lq_channel_list, { lfp_none }}, { 0, 0, { lfp_none}} };