try to add partial channel support
This commit is contained in:
parent
2052f4b381
commit
4c27091706
76
interface.c
76
interface.c
@ -69,6 +69,7 @@
|
||||
//#include "mtproto-common.h"
|
||||
|
||||
#include <tgl/tgl.h>
|
||||
#include <tgl/tgl-queries.h>
|
||||
#include "loop.h"
|
||||
|
||||
#ifndef PATH_MAX
|
||||
@ -757,6 +758,13 @@ void do_msg (struct command *command, int arg_num, struct arg args[], struct in_
|
||||
tgl_do_send_message (TLS, args[0].P->id, ARG2STR(1), TGL_SEND_MSG_FLAG_REPLY(reply_id) | disable_msg_preview, NULL, print_msg_success_gw, ev);
|
||||
}
|
||||
|
||||
void do_post (struct command *command, int arg_num, struct arg args[], struct in_ev *ev) {
|
||||
assert (arg_num == 2);
|
||||
if (ev) { ev->refcnt ++; }
|
||||
vlogprintf (E_DEBUG, "reply_id=%d, disable=%d\n", reply_id, disable_msg_preview);
|
||||
tgl_do_send_message (TLS, args[0].P->id, ARG2STR(1), TGL_SEND_MSG_FLAG_REPLY(reply_id) | disable_msg_preview | TGLMF_POST_AS_CHANNEL, NULL, print_msg_success_gw, ev);
|
||||
}
|
||||
|
||||
void do_msg_kbd (struct command *command, int arg_num, struct arg args[], struct in_ev *ev) {
|
||||
assert (arg_num == 3);
|
||||
if (ev) { ev->refcnt ++; }
|
||||
@ -1172,6 +1180,12 @@ void do_dialog_list (struct command *command, int arg_num, struct arg args[], st
|
||||
tgl_do_get_dialog_list (TLS, args[0].num != NOT_FOUND ? args[0].num : 100, args[1].num != NOT_FOUND ? args[1].num : 0, print_dialog_list_gw, ev);
|
||||
}
|
||||
|
||||
void do_channel_list (struct command *command, int arg_num, struct arg args[], struct in_ev *ev) {
|
||||
assert (arg_num <= 2);
|
||||
if (ev) { ev->refcnt ++; }
|
||||
tgl_do_get_channels_dialog_list (TLS, args[0].num != NOT_FOUND ? args[0].num : 100, args[1].num != NOT_FOUND ? args[1].num : 0, print_dialog_list_gw, ev);
|
||||
}
|
||||
|
||||
void do_resolve_username (struct command *command, int arg_num, struct arg args[], struct in_ev *ev) {
|
||||
assert (arg_num == 1);
|
||||
if (ev) { ev->refcnt ++; }
|
||||
@ -1393,6 +1407,7 @@ struct command commands[MAX_COMMANDS_SIZE] = {
|
||||
{"add_contact", {ca_string, ca_string, ca_string, ca_none}, do_add_contact, "add_contact <phone> <first name> <last name>\tTries to add user to contact list", NULL},
|
||||
{"block_user", {ca_user, ca_none}, do_block_user, "block_user <user>\tBlocks user", NULL},
|
||||
{"broadcast", {ca_user, ca_period, ca_string_end, ca_none}, do_broadcast, "broadcast <user>+ <text>\tSends text to several users at once", NULL},
|
||||
{"channel_list", {ca_number | ca_optional, ca_number | ca_optional, ca_none}, do_channel_list, "channel_list [limit=100] [offset=0]\tList of last channels", NULL},
|
||||
{"chat_add_user", {ca_chat, ca_user, ca_number | ca_optional, ca_none}, do_chat_add_user, "chat_add_user <chat> <user> [msgs-to-forward]\tAdds user to chat. Sends him last msgs-to-forward message from this chat. Default 100", NULL},
|
||||
{"chat_del_user", {ca_chat, ca_user, ca_none}, do_chat_del_user, "chat_del_user <chat> <user>\tDeletes user from chat", NULL},
|
||||
{"chat_info", {ca_chat, ca_none}, do_chat_info, "chat_info <chat>\tPrints info about chat (id, members, admin, etc.)", NULL},
|
||||
@ -1430,6 +1445,7 @@ struct command commands[MAX_COMMANDS_SIZE] = {
|
||||
{"mark_read", {ca_peer, ca_none}, do_mark_read, "mark_read <peer>\tMarks messages with peer as read", NULL},
|
||||
{"msg", {ca_peer, ca_msg_string_end, ca_none}, do_msg, "msg <peer> <text>\tSends text message to peer", NULL},
|
||||
{"msg_kbd", {ca_peer, ca_string, ca_msg_string_end, ca_none}, do_msg_kbd, "msg <peer> <kbd> <text>\tSends text message to peer with custom kbd", NULL},
|
||||
{"post", {ca_peer, ca_msg_string_end, ca_none}, do_post, "post <peer> <text>\tSends text message to peer as admin", NULL},
|
||||
{"quit", {ca_none}, do_quit, "quit\tQuits immediately", NULL},
|
||||
{"rename_chat", {ca_chat, ca_string_end, ca_none}, do_rename_chat, "rename_chat <chat> <new name>\tRenames chat", NULL},
|
||||
{"rename_contact", {ca_user, ca_string, ca_string, ca_none}, do_rename_contact, "rename_contact <user> <first name> <last name>\tRenames contact", NULL},
|
||||
@ -2337,6 +2353,12 @@ void print_dialog_list_gw (struct tgl_state *TLSR, void *extra, int success, int
|
||||
print_chat_name (ev, peers[i], UC);
|
||||
mprintf (ev, ": %d unread\n", unread_count[i]);
|
||||
break;
|
||||
case TGL_PEER_CHANNEL:
|
||||
UC = tgl_peer_get (TLS, peers[i]);
|
||||
mprintf (ev, "Channel ");
|
||||
print_channel_name (ev, peers[i], UC);
|
||||
mprintf (ev, ": %d unread\n", unread_count[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
mpop_color (ev);
|
||||
@ -3502,6 +3524,17 @@ void print_chat_name (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *C) {
|
||||
mpop_color (ev);
|
||||
}
|
||||
|
||||
void print_channel_name (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *C) {
|
||||
assert (tgl_get_peer_type (id) == TGL_PEER_CHANNEL);
|
||||
mpush_color (ev, COLOR_CYAN);
|
||||
if (!C || use_ids) {
|
||||
mprintf (ev, "channel#%d", tgl_get_peer_id (id));
|
||||
} else {
|
||||
mprintf (ev, "%s", C->channel.title);
|
||||
}
|
||||
mpop_color (ev);
|
||||
}
|
||||
|
||||
void print_encr_chat_name (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *C) {
|
||||
assert (tgl_get_peer_type (id) == TGL_PEER_ENCR_CHAT);
|
||||
mpush_color (ev, COLOR_MAGENTA);
|
||||
@ -3546,7 +3579,11 @@ void print_service_message (struct in_ev *ev, struct tgl_message *M) {
|
||||
//print_start ();
|
||||
mpush_color (ev, COLOR_GREY);
|
||||
|
||||
if (tgl_get_peer_type (M->to_id) == TGL_PEER_CHANNEL) {
|
||||
mpush_color (ev, COLOR_CYAN);
|
||||
} else {
|
||||
mpush_color (ev, COLOR_MAGENTA);
|
||||
}
|
||||
if (msg_num_mode) {
|
||||
mprintf (ev, "%lld ", M->id);
|
||||
}
|
||||
@ -3555,12 +3592,17 @@ void print_service_message (struct in_ev *ev, struct tgl_message *M) {
|
||||
mprintf (ev, " ");
|
||||
if (tgl_get_peer_type (M->to_id) == TGL_PEER_CHAT) {
|
||||
print_chat_name (ev, M->to_id, tgl_peer_get (TLS, M->to_id));
|
||||
} else if (tgl_get_peer_type (M->to_id) == TGL_PEER_CHANNEL) {
|
||||
print_channel_name (ev, M->to_id, tgl_peer_get (TLS, M->to_id));
|
||||
} else {
|
||||
assert (tgl_get_peer_type (M->to_id) == TGL_PEER_ENCR_CHAT);
|
||||
print_encr_chat_name (ev, M->to_id, tgl_peer_get (TLS, M->to_id));
|
||||
}
|
||||
|
||||
if (tgl_get_peer_type (M->from_id) == TGL_PEER_USER) {
|
||||
mprintf (ev, " ");
|
||||
print_user_name (ev, M->from_id, tgl_peer_get (TLS, M->from_id));
|
||||
}
|
||||
|
||||
switch (M->action.type) {
|
||||
case tgl_message_action_none:
|
||||
@ -3640,6 +3682,9 @@ void print_service_message (struct in_ev *ev, struct tgl_message *M) {
|
||||
case tgl_message_action_abort_key:
|
||||
mprintf (ev, " abort rekey #%016llx\n", M->action.exchange_id);
|
||||
break;
|
||||
case tgl_message_action_channel_create:
|
||||
mprintf (ev, " created channel %s\n", M->action.title);
|
||||
break;
|
||||
}
|
||||
mpop_color (ev);
|
||||
//print_end ();
|
||||
@ -3732,8 +3777,7 @@ void print_message (struct in_ev *ev, struct tgl_message *M) {
|
||||
mprintf (ev, " »»» ");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
assert (tgl_get_peer_type (M->to_id) == TGL_PEER_CHAT);
|
||||
} else if (tgl_get_peer_type (M->to_id) == TGL_PEER_CHAT) {
|
||||
mpush_color (ev, COLOR_MAGENTA);
|
||||
if (msg_num_mode) {
|
||||
mprintf (ev, "%lld ", M->id);
|
||||
@ -3754,6 +3798,34 @@ void print_message (struct in_ev *ev, struct tgl_message *M) {
|
||||
} else {
|
||||
mprintf (ev, " »»» ");
|
||||
}
|
||||
} else {
|
||||
assert (tgl_get_peer_type (M->to_id) == TGL_PEER_CHANNEL);
|
||||
|
||||
mpush_color (ev, COLOR_CYAN);
|
||||
if (msg_num_mode) {
|
||||
mprintf (ev, "%lld ", M->id);
|
||||
}
|
||||
print_date (ev, M->date);
|
||||
mpop_color (ev);
|
||||
mprintf (ev, " ");
|
||||
print_channel_name (ev, M->to_id, tgl_peer_get (TLS, M->to_id));
|
||||
|
||||
if (tgl_get_peer_type (M->from_id) == TGL_PEER_USER) {
|
||||
mprintf (ev, " ");
|
||||
print_user_name (ev, M->from_id, tgl_peer_get (TLS, M->from_id));
|
||||
if ((tgl_get_peer_type (M->from_id) == TGL_PEER_USER) && (tgl_get_peer_id (M->from_id) == TLS->our_id)) {
|
||||
mpush_color (ev, COLOR_GREEN);
|
||||
} else {
|
||||
mpush_color (ev, COLOR_BLUE);
|
||||
}
|
||||
} else {
|
||||
mpush_color (ev, COLOR_BLUE);
|
||||
}
|
||||
if (M->flags & TGLMF_UNREAD) {
|
||||
mprintf (ev, " >>> ");
|
||||
} else {
|
||||
mprintf (ev, " »»» ");
|
||||
}
|
||||
}
|
||||
if (tgl_get_peer_type (M->fwd_from_id) == TGL_PEER_USER) {
|
||||
mprintf (ev, "[fwd from ");
|
||||
|
@ -68,6 +68,7 @@ struct tgl_message;
|
||||
struct in_ev;
|
||||
void print_message (struct in_ev *ev, struct tgl_message *M);
|
||||
void print_chat_name (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *C);
|
||||
void print_channel_name (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *C);
|
||||
void print_user_name (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *U);
|
||||
void print_encr_chat_name_full (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *C);
|
||||
void print_encr_chat_name (struct in_ev *ev, tgl_peer_id_t id, tgl_peer_t *C);
|
||||
|
26
loop.c
26
loop.c
@ -554,23 +554,23 @@ void read_dc (int auth_file_fd, int id, unsigned ver) {
|
||||
assert (read (auth_file_fd, auth_key, 256) == 256);
|
||||
|
||||
//bl_do_add_dc (id, ip, l, port, auth_key_id, auth_key);
|
||||
bl_do_dc_option (TLS, id, "DC", 2, ip, l, port);
|
||||
bl_do_dc_option (TLS, 0, id, "DC", 2, ip, l, port);
|
||||
bl_do_set_auth_key (TLS, id, auth_key);
|
||||
bl_do_dc_signed (TLS, id);
|
||||
}
|
||||
|
||||
void empty_auth_file (void) {
|
||||
if (TLS->test_mode) {
|
||||
bl_do_dc_option (TLS, 1, "", 0, TG_SERVER_TEST_1, strlen (TG_SERVER_TEST_1), 443);
|
||||
bl_do_dc_option (TLS, 2, "", 0, TG_SERVER_TEST_2, strlen (TG_SERVER_TEST_2), 443);
|
||||
bl_do_dc_option (TLS, 3, "", 0, TG_SERVER_TEST_3, strlen (TG_SERVER_TEST_3), 443);
|
||||
bl_do_dc_option (TLS, 0, 1, "", 0, TG_SERVER_TEST_1, strlen (TG_SERVER_TEST_1), 443);
|
||||
bl_do_dc_option (TLS, 0, 2, "", 0, TG_SERVER_TEST_2, strlen (TG_SERVER_TEST_2), 443);
|
||||
bl_do_dc_option (TLS, 0, 3, "", 0, TG_SERVER_TEST_3, strlen (TG_SERVER_TEST_3), 443);
|
||||
bl_do_set_working_dc (TLS, TG_SERVER_TEST_DEFAULT);
|
||||
} else {
|
||||
bl_do_dc_option (TLS, 1, "", 0, TG_SERVER_1, strlen (TG_SERVER_1), 443);
|
||||
bl_do_dc_option (TLS, 2, "", 0, TG_SERVER_2, strlen (TG_SERVER_2), 443);
|
||||
bl_do_dc_option (TLS, 3, "", 0, TG_SERVER_3, strlen (TG_SERVER_3), 443);
|
||||
bl_do_dc_option (TLS, 4, "", 0, TG_SERVER_4, strlen (TG_SERVER_4), 443);
|
||||
bl_do_dc_option (TLS, 5, "", 0, TG_SERVER_5, strlen (TG_SERVER_5), 443);
|
||||
bl_do_dc_option (TLS, 0, 1, "", 0, TG_SERVER_1, strlen (TG_SERVER_1), 443);
|
||||
bl_do_dc_option (TLS, 0, 2, "", 0, TG_SERVER_2, strlen (TG_SERVER_2), 443);
|
||||
bl_do_dc_option (TLS, 0, 3, "", 0, TG_SERVER_3, strlen (TG_SERVER_3), 443);
|
||||
bl_do_dc_option (TLS, 0, 4, "", 0, TG_SERVER_4, strlen (TG_SERVER_4), 443);
|
||||
bl_do_dc_option (TLS, 0, 5, "", 0, TG_SERVER_5, strlen (TG_SERVER_5), 443);
|
||||
bl_do_set_working_dc (TLS, TG_SERVER_DEFAULT);
|
||||
}
|
||||
}
|
||||
@ -648,7 +648,7 @@ void read_secret_chat (int fd, int v) {
|
||||
assert (read (fd, &out_seq_no, 4) == 4);
|
||||
}
|
||||
|
||||
bl_do_encr_chat_new (TLS, id,
|
||||
bl_do_encr_chat (TLS, id,
|
||||
&access_hash,
|
||||
&date,
|
||||
&admin_id,
|
||||
@ -814,7 +814,7 @@ int loop (void) {
|
||||
}
|
||||
tgl_init (TLS);
|
||||
|
||||
if (binlog_enabled) {
|
||||
/*if (binlog_enabled) {
|
||||
double t = tglt_get_double_time ();
|
||||
if (verbosity >= E_DEBUG) {
|
||||
logprintf ("replay log start\n");
|
||||
@ -824,11 +824,11 @@ int loop (void) {
|
||||
logprintf ("replay log end in %lf seconds\n", tglt_get_double_time () - t);
|
||||
}
|
||||
tgl_reopen_binlog_for_writing (TLS);
|
||||
} else {
|
||||
} else {*/
|
||||
read_auth_file ();
|
||||
read_state_file ();
|
||||
read_secret_chat_file ();
|
||||
}
|
||||
//}
|
||||
|
||||
binlog_read = 1;
|
||||
#ifdef USE_LUA
|
||||
|
5
lua-tg.c
5
lua-tg.c
@ -415,6 +415,11 @@ void push_service (struct tgl_message *M) {
|
||||
lua_newtable (luaState);
|
||||
lua_add_string_field ("type", "abort_rekey");
|
||||
break;
|
||||
case tgl_message_action_channel_create:
|
||||
lua_newtable (luaState);
|
||||
lua_add_string_field ("type", "channel_created");
|
||||
lua_add_string_field ("title", M->action.title);
|
||||
break;
|
||||
default:
|
||||
lua_pushstring (luaState, "???");
|
||||
break;
|
||||
|
24
main.c
24
main.c
@ -37,19 +37,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#if (READLINE == GNU)
|
||||
#include <readline/readline.h>
|
||||
#else
|
||||
#include <editline/readline.h>
|
||||
#endif
|
||||
#ifdef EVENT_V2
|
||||
#include <event2/event.h>
|
||||
#include <event2/bufferevent.h>
|
||||
#include <event2/buffer.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#include "event-old.h"
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
@ -297,18 +285,6 @@ void running_for_first_time (void) {
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
close (config_file_fd);
|
||||
/*int auth_file_fd = open (get_auth_key_filename (), O_CREAT | O_RDWR, 0600);
|
||||
int x = -1;
|
||||
assert (write (auth_file_fd, &x, 4) == 4);
|
||||
close (auth_file_fd);
|
||||
|
||||
printf ("[%s] created\n", config_filename);*/
|
||||
|
||||
/* create downloads directory */
|
||||
/*if (mkdir (downloads_directory, 0755) !=0) {
|
||||
perror ("creating download directory");
|
||||
exit (EXIT_FAILURE);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
2
tgl
2
tgl
@ -1 +1 @@
|
||||
Subproject commit 418f81be448fdebb04c3809795f8c160ee13280c
|
||||
Subproject commit e5a9d0521aee36611bd2f51d50c6609902aa0094
|
Loading…
Reference in New Issue
Block a user