Commit 598b4414 authored by V V's avatar V V

some fixes. Added some debug output. Added channel_info query

parent 17fc871f
This diff is collapsed.
...@@ -84,4 +84,7 @@ void print_date (struct in_ev *ev, long t); ...@@ -84,4 +84,7 @@ void print_date (struct in_ev *ev, long t);
void play_sound (void); void play_sound (void);
void update_prompt (void); void update_prompt (void);
void set_interface_callbacks (void); void set_interface_callbacks (void);
char *print_permanent_msg_id (tgl_message_id_t id);
char *print_permanent_peer_id (tgl_peer_id_t id);
#endif #endif
...@@ -73,6 +73,15 @@ void lua_add_string_field (const char *name, const char *value) { ...@@ -73,6 +73,15 @@ void lua_add_string_field (const char *name, const char *value) {
lua_settable (luaState, -3); lua_settable (luaState, -3);
} }
void lua_add_lstring_field (const char *name, const char *value, int len) {
assert (name && strlen (name));
if (!value || !len) { return; }
my_lua_checkstack (luaState, 3);
lua_pushstring (luaState, name);
lua_pushlstring (luaState, len, value);
lua_settable (luaState, -3);
}
void lua_add_string_field_arr (int num, const char *value) { void lua_add_string_field_arr (int num, const char *value) {
if (!value || !strlen (value)) { return; } if (!value || !strlen (value)) { return; }
my_lua_checkstack (luaState, 3); my_lua_checkstack (luaState, 3);
...@@ -100,6 +109,9 @@ void push_tgl_peer_type (int x) { ...@@ -100,6 +109,9 @@ void push_tgl_peer_type (int x) {
case TGL_PEER_ENCR_CHAT: case TGL_PEER_ENCR_CHAT:
lua_pushstring (luaState, "encr_chat"); lua_pushstring (luaState, "encr_chat");
break; break;
case TGL_PEER_CHANNEL:
lua_pushstring (luaState, "channel");
break;
default: default:
assert (0); assert (0);
} }
...@@ -144,6 +156,15 @@ void push_encr_chat (tgl_peer_t *P) { ...@@ -144,6 +156,15 @@ void push_encr_chat (tgl_peer_t *P) {
lua_settable (luaState, -3); lua_settable (luaState, -3);
} }
void push_channel (tgl_peer_t *P) {
my_lua_checkstack (luaState, 4);
lua_add_string_field (luaState, "title", P->channel.title);
lua_add_string_field (luaState, "about", P->channel.about);
lua_add_num_field (luaState, "participants_count", P->channel.participants_count);
lua_add_num_field (luaState, "admins_count", P->channel.admins_count);
lua_add_num_field (luaState, "kicked_count", P->channel.kicked_count);
}
void push_update_types (unsigned flags) { void push_update_types (unsigned flags) {
my_lua_checkstack (luaState, 4); my_lua_checkstack (luaState, 4);
lua_newtable (luaState); lua_newtable (luaState);
...@@ -204,11 +225,8 @@ void push_update_types (unsigned flags) { ...@@ -204,11 +225,8 @@ void push_update_types (unsigned flags) {
void push_peer (tgl_peer_id_t id, tgl_peer_t *P) { void push_peer (tgl_peer_id_t id, tgl_peer_t *P) {
lua_newtable (luaState); lua_newtable (luaState);
lua_add_num_field ("id", tgl_get_peer_id (id)); lua_add_lstring_field ("id", print_permanent_peer_id (P->id));
lua_pushstring (luaState, "type"); lua_add_string_field (luaState, "type", tgl_get_peer_type (id));
push_tgl_peer_type (tgl_get_peer_type (id));
lua_settable (luaState, -3);
if (!P || !(P->flags & TGLPF_CREATED)) { if (!P || !(P->flags & TGLPF_CREATED)) {
lua_pushstring (luaState, "print_name"); lua_pushstring (luaState, "print_name");
...@@ -223,6 +241,9 @@ void push_peer (tgl_peer_id_t id, tgl_peer_t *P) { ...@@ -223,6 +241,9 @@ void push_peer (tgl_peer_id_t id, tgl_peer_t *P) {
case TGL_PEER_ENCR_CHAT: case TGL_PEER_ENCR_CHAT:
sprintf (s, "encr_chat#%d", tgl_get_peer_id (id)); sprintf (s, "encr_chat#%d", tgl_get_peer_id (id));
break; break;
case TGL_PEER_CHANNEL:
sprintf (s, "channel#%d", tgl_get_peer_id (id));
break;
default: default:
assert (0); assert (0);
} }
...@@ -420,9 +441,9 @@ void push_service (struct tgl_message *M) { ...@@ -420,9 +441,9 @@ void push_service (struct tgl_message *M) {
lua_add_string_field ("type", "channel_created"); lua_add_string_field ("type", "channel_created");
lua_add_string_field ("title", M->action.title); lua_add_string_field ("title", M->action.title);
break; break;
default: /*default:
lua_pushstring (luaState, "???"); lua_pushstring (luaState, "???");
break; break;*/
} }
} }
...@@ -431,15 +452,7 @@ void push_message (struct tgl_message *M) { ...@@ -431,15 +452,7 @@ void push_message (struct tgl_message *M) {
my_lua_checkstack (luaState, 10); my_lua_checkstack (luaState, 10);
lua_newtable (luaState); lua_newtable (luaState);
static char s[256]; lua_add_string_field ("id", print_permanent_msg_id (M->permanent_id));
unsigned char *mid = (void *)&M->permanent_id;
int i;
for (i = 0; i < (int)sizeof (struct tgl_message_permanent_id); i++) {
sprintf (s + 2 * i, "%02u", (unsigned) mid[i]);
}
lua_add_string_field ("id", s);
if (!(M->flags & TGLMF_CREATED)) { return; } if (!(M->flags & TGLMF_CREATED)) { return; }
lua_add_num_field ("flags", M->flags); lua_add_num_field ("flags", M->flags);
...@@ -1619,6 +1632,7 @@ enum command_argument { ...@@ -1619,6 +1632,7 @@ enum command_argument {
ca_user, ca_user,
ca_chat, ca_chat,
ca_secret_chat, ca_secret_chat,
ca_channel,
ca_peer, ca_peer,
ca_file_name, ca_file_name,
ca_file_name_end, ca_file_name_end,
......
...@@ -21,4 +21,4 @@ ...@@ -21,4 +21,4 @@
#define PROG_NAME "telegram-cli" #define PROG_NAME "telegram-cli"
#endif #endif
#define TELEGRAM_CLI_VERSION "1.3.3" #define TELEGRAM_CLI_VERSION "1.4.0"
Subproject commit 119bced18153472c67a674f141960d4e75a4a76b Subproject commit b16c44c727f1eec561c2c69eb7373b72ee08a52d
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment