Skip to content

Commit 3abec73

Browse files
committed
Merge pull request #875 from yagop/test
Fixes in lua-tg.c and functions channel_invite_user and channel_info
2 parents c61c8ba + e0f5f16 commit 3abec73

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

README-LUA

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Function_list (arguments are listed aside from cb_function and cb_extra, :
5151
load_document_thumb(msg)
5252

5353
chat_info (chat)
54+
channel_info (channel)
5455
user_info (user)
5556

5657
get_history (peer, limit)

lua-tg.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ enum lua_query_type {
683683
lq_load_video_thumb,
684684
lq_load_video,
685685
lq_chat_info,
686+
lq_channel_info,
686687
lq_user_info,
687688
lq_history,
688689
lq_chat_add_user,
@@ -710,7 +711,8 @@ enum lua_query_type {
710711
lq_send_location,
711712
lq_extf,
712713
lq_import_chat_link,
713-
lq_export_chat_link
714+
lq_export_chat_link,
715+
lq_channel_invite_user
714716
};
715717

716718
struct lua_query_extra {
@@ -1034,6 +1036,38 @@ void lua_secret_chat_cb (struct tgl_state *TLSR, void *cb_extra, int success, st
10341036
free (cb);
10351037
}
10361038

1039+
void lua_channel_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_channel *C) {
1040+
assert (TLSR == TLS);
1041+
struct lua_query_extra *cb = cb_extra;
1042+
lua_settop (luaState, 0);
1043+
//lua_checkstack (luaState, 20);
1044+
my_lua_checkstack (luaState, 20);
1045+
1046+
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
1047+
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
1048+
1049+
lua_pushnumber (luaState, success);
1050+
1051+
if (success) {
1052+
push_peer (C->id, (void *)C);
1053+
} else {
1054+
lua_pushboolean (luaState, 0);
1055+
}
1056+
1057+
assert (lua_gettop (luaState) == 4);
1058+
1059+
int r = ps_lua_pcall (luaState, 3, 0, 0);
1060+
1061+
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
1062+
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
1063+
1064+
if (r) {
1065+
logprintf ("lua: %s\n", lua_tostring (luaState, -1));
1066+
}
1067+
1068+
free (cb);
1069+
}
1070+
10371071
void lua_user_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_user *C) {
10381072
assert (TLSR == TLS);
10391073
struct lua_query_extra *cb = cb_extra;
@@ -1211,6 +1245,10 @@ void lua_do_all (void) {
12111245
tgl_do_get_chat_info (TLS, lua_ptr[p + 1].peer_id, 0, lua_chat_cb, lua_ptr[p].ptr);
12121246
p += 2;
12131247
break;
1248+
case lq_channel_info:
1249+
tgl_do_get_channel_info (TLS, lua_ptr[p + 1].peer_id, 0, lua_channel_cb, lua_ptr[p].ptr);
1250+
p += 2;
1251+
break;
12141252
case lq_user_info:
12151253
tgl_do_get_user_info (TLS, lua_ptr[p + 1].peer_id, 0, lua_user_cb, lua_ptr[p].ptr);
12161254
p += 2;
@@ -1220,11 +1258,11 @@ void lua_do_all (void) {
12201258
p += 3;
12211259
break;
12221260
case lq_chat_add_user:
1223-
tgl_do_add_user_to_chat (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 1].peer_id, 10, lua_empty_cb, lua_ptr[p].ptr);
1261+
tgl_do_add_user_to_chat (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 2].peer_id, 10, lua_empty_cb, lua_ptr[p].ptr);
12241262
p += 3;
12251263
break;
12261264
case lq_chat_del_user:
1227-
tgl_do_del_user_from_chat (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 1].peer_id, lua_empty_cb, lua_ptr[p].ptr);
1265+
tgl_do_del_user_from_chat (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 2].peer_id, lua_empty_cb, lua_ptr[p].ptr);
12281266
p += 3;
12291267
break;
12301268
case lq_add_contact:
@@ -1303,6 +1341,10 @@ void lua_do_all (void) {
13031341
tgl_do_send_location (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 2].dnum, lua_ptr[p + 3].dnum, 0, lua_msg_cb, lua_ptr[p].ptr);
13041342
p += 4;
13051343
break;
1344+
case lq_channel_invite_user:
1345+
tgl_do_channel_invite_user (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 2].peer_id, lua_empty_cb, lua_ptr[p].ptr);
1346+
p += 3;
1347+
break;
13061348
/*
13071349
lq_delete_msg,
13081350
lq_restore_msg,
@@ -1379,6 +1421,7 @@ struct lua_function functions[] = {
13791421
{"fwd_msg", lq_fwd, { lfp_peer, lfp_msg, lfp_none }},
13801422
{"fwd_media", lq_fwd_media, { lfp_peer, lfp_msg, lfp_none }},
13811423
{"chat_info", lq_chat_info, { lfp_chat, lfp_none }},
1424+
{"channel_info", lq_channel_info, { lfp_channel, lfp_none }},
13821425
{"user_info", lq_user_info, { lfp_user, lfp_none }},
13831426
{"get_history", lq_history, { lfp_peer, lfp_nonnegative_number, lfp_none }},
13841427
{"chat_add_user", lq_chat_add_user, { lfp_chat, lfp_user, lfp_none }},
@@ -1403,6 +1446,7 @@ struct lua_function functions[] = {
14031446
{"ext_function", lq_extf, { lfp_string, lfp_none }},
14041447
{"import_chat_link", lq_import_chat_link, { lfp_string, lfp_none }},
14051448
{"export_chat_link", lq_export_chat_link, { lfp_chat, lfp_none }},
1449+
{"channel_invite_user", lq_channel_invite_user, { lfp_channel, lfp_user, lfp_none }},
14061450
{ 0, 0, { lfp_none}}
14071451
};
14081452

0 commit comments

Comments
 (0)