Commit c4e3052d authored by vysheng's avatar vysheng

Fixed inerface

parent 3be908e7
...@@ -40,11 +40,136 @@ char *default_prompt = "> "; ...@@ -40,11 +40,136 @@ char *default_prompt = "> ";
int unread_messages; int unread_messages;
int msg_num_mode; int msg_num_mode;
int in_readline;
long long cur_uploading_bytes; long long cur_uploading_bytes;
long long cur_uploaded_bytes; long long cur_uploaded_bytes;
long long cur_downloading_bytes; long long cur_downloading_bytes;
long long cur_downloaded_bytes; long long cur_downloaded_bytes;
char *line_ptr;
extern int user_num;
extern int chat_num;
extern union user_chat *Peers[];
int is_same_word (const char *s, size_t l, const char *word) {
return s && word && strlen (word) == l && !memcmp (s, word, l);
}
char *next_token (int *l) {
while (*line_ptr == ' ') { line_ptr ++; }
if (!*line_ptr) {
*l = 0;
return 0;
}
int neg = 0;
char *s = line_ptr;
while (*line_ptr && (*line_ptr != ' ' || neg)) {
if (*line_ptr == '\\') {
neg = 1 - neg;
} else {
neg = 0;
}
line_ptr++;
}
*l = line_ptr - s;
return s;
}
#define NOT_FOUND (int)0x80000000
int next_token_int (void) {
int l;
char *s = next_token (&l);
if (!s) { return NOT_FOUND; }
char *r;
int x = strtod (s, &r);
if (r == s + l) {
return x;
} else {
return NOT_FOUND;
}
}
int next_token_user (void) {
int l;
char *s = next_token (&l);
if (!s) { return NOT_FOUND; }
if (*s == '#') {
s ++;
l --;
if (l > 0) {
int r = atoi (s);
if (r < 0) { return r; }
else { return NOT_FOUND; }
} else {
return NOT_FOUND;
}
}
int index = 0;
while (index < user_num + chat_num && (!is_same_word (s, l, Peers[index]->print_name) || Peers[index]->id < 0)) {
index ++;
}
if (index < user_num + chat_num) {
return Peers[index]->id;
} else {
return NOT_FOUND;
}
}
int next_token_chat (void) {
int l;
char *s = next_token (&l);
if (!s) { return NOT_FOUND; }
if (*s == '#') {
s ++;
l --;
if (l > 0) {
int r = atoi (s);
if (r < 0) { return r; }
else { return NOT_FOUND; }
} else {
return NOT_FOUND;
}
}
int index = 0;
while (index < user_num + chat_num && (!is_same_word (s, l, Peers[index]->print_name) || Peers[index]->id > 0)) {
index ++;
}
if (index < user_num + chat_num) {
return Peers[index]->id;
} else {
return NOT_FOUND;
}
}
int next_token_user_chat (void) {
int l;
char *s = next_token (&l);
if (!s) { return NOT_FOUND; }
if (*s == '#') {
s ++;
l --;
if (l > 0) {
int r = atoi (s);
if (r != 0) { return r; }
else { return NOT_FOUND; }
} else {
return NOT_FOUND;
}
}
int index = 0;
while (index < user_num + chat_num && (!is_same_word (s, l, Peers[index]->print_name) || !Peers[index]->id)) {
index ++;
}
if (index < user_num + chat_num) {
return Peers[index]->id;
} else {
return NOT_FOUND;
}
}
char *get_default_prompt (void) { char *get_default_prompt (void) {
static char buf[100]; static char buf[100];
...@@ -129,54 +254,22 @@ int commands_flags[] = { ...@@ -129,54 +254,22 @@ int commands_flags[] = {
07, 07,
}; };
char *a = 0;
char *user_list[MAX_USER_NUM + 1];
char **chat_list = &a;
int init_token (char **q) {
char *r = *q;
while (*r == ' ') { r ++; }
if (!*r) { return 0; }
*q = r;
return 1;
}
char *get_token (char **q, int *l) {
char *r = *q;
while (*r == ' ') { r ++; }
if (!*r) {
*q = r;
*l = 0;
return 0;
}
int neg = 0;
char *s = r;
while (*r && (*r != ' ' || neg)) {
if (*r == '\\') {
neg = 1 - neg;
} else {
neg = 0;
}
r++;
}
*q = r;
*l = r - s;
return s;
}
int get_complete_mode (void) { int get_complete_mode (void) {
char *q = rl_line_buffer; line_ptr = rl_line_buffer;
if (!init_token (&q)) { return 0; }
int l = 0; int l = 0;
char *r = get_token (&q, &l); char *r = next_token (&l);
if (!*q) { return 0; } if (!r) { return 0; }
while (r && r[0] == '[' && r[l - 1] == ']') {
r = next_token (&l);
if (!r) { return 0; }
}
if (!*line_ptr) { return 0; }
char **command = commands; char **command = commands;
int n = 0; int n = 0;
int flags = -1; int flags = -1;
while (*command) { while (*command) {
if (!strncmp (r, *command, l)) { if (is_same_word (r, l, *command)) {
flags = commands_flags[n]; flags = commands_flags[n];
break; break;
} }
...@@ -184,20 +277,18 @@ int get_complete_mode (void) { ...@@ -184,20 +277,18 @@ int get_complete_mode (void) {
command ++; command ++;
} }
if (flags == -1) { if (flags == -1) {
return -1; return 7;
} }
int s = 0; int s = 0;
while (1) { while (1) {
get_token (&q, &l); if (!next_token (&l) || !*line_ptr) {
if (!*q) { return flags ? flags & 7 : 7; } return flags ? flags & 7 : 7;
}
s ++; s ++;
if (s <= 4) { flags >>= 3; } if (s <= 4) { flags >>= 3; }
} }
} }
extern int user_num;
extern int chat_num;
extern union user_chat *Peers[];
int complete_user_list (int index, const char *text, int len, char **R) { int complete_user_list (int index, const char *text, int len, char **R) {
index ++; index ++;
while (index < user_num + chat_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len) || Peers[index]->id < 0)) { while (index < user_num + chat_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len) || Peers[index]->id < 0)) {
...@@ -302,228 +393,221 @@ char **complete_text (char *text, int start UU, int end UU) { ...@@ -302,228 +393,221 @@ char **complete_text (char *text, int start UU, int end UU) {
return (char **) rl_completion_matches (text, command_generator); return (char **) rl_completion_matches (text, command_generator);
} }
void work_modifier (const char *s UU) {
}
void interpreter (char *line UU) { void interpreter (char *line UU) {
if (!line) { return; } line_ptr = line;
assert (!in_readline);
in_readline = 1;
if (!line) {
in_readline = 0;
return;
}
if (line && *line) { if (line && *line) {
add_history (line); add_history (line);
} }
if (!memcmp (line, "contact_list", 12)) {
int l;
char *command;
while (1) {
command = next_token (&l);
if (!command) { return; }
if (*command == '[' && command[l - 1] == ']') {
work_modifier (command);
} else {
break;
}
}
#define IS_WORD(s) is_same_word (command, l, (s))
#define RET in_readline = 0; return;
if (IS_WORD ("contact_list")) {
do_update_contact_list (); do_update_contact_list ();
} else if (!memcmp (line, "dialog_list", 11)) { } else if (IS_WORD ("dialog_list")) {
do_get_dialog_list (); do_get_dialog_list ();
} else if (!memcmp (line, "stats", 5)) { } else if (IS_WORD ("stats")) {
static char stat_buf[1 << 15]; static char stat_buf[1 << 15];
print_stat (stat_buf, (1 << 15) - 1); print_stat (stat_buf, (1 << 15) - 1);
printf ("%s\n", stat_buf); printf ("%s\n", stat_buf);
} else if (!memcmp (line, "msg ", 4)) { } else if (IS_WORD ("msg")) {
char *q = line + 4; int id = next_token_user_chat ();
int len; if (id == NOT_FOUND) {
char *text = get_token (&q, &len); printf ("Bad user/chat id\n");
int index = 0; RET;
while (index < user_num + chat_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len))) { }
index ++; int t;
} char *s = next_token (&t);
while (*q && (*q == ' ' || *q == '\t')) { q ++; } if (!s) {
if (*q && index < user_num + chat_num) { printf ("Empty message\n");
do_send_message (Peers[index], q, strlen (q)); RET;
} }
} else if (!memcmp (line, "rename_chat", 11)) { do_send_message (id, s, strlen (s));
char *q = line + 11; } else if (IS_WORD ("rename_chat")) {
int len; int id = next_token_chat ();
char *text = get_token (&q, &len); if (id == NOT_FOUND) {
int index = 0; printf ("Bad chat id\n");
while (index < user_num + chat_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len) || Peers[index]->id >= 0)) { RET;
index ++; }
} int t;
while (*q && (*q == ' ' || *q == '\t')) { q ++; } char *s = next_token (&t);
if (*q && index < user_num + chat_num) { if (!s) {
do_rename_chat (Peers[index], q); printf ("Empty new name\n");
} RET;
} else if (!memcmp (line, "send_photo", 10)) { }
char *q = line + 10; do_rename_chat (id, s);
int len; } else if (IS_WORD ("send_photo")) {
char *text = get_token (&q, &len); int id = next_token_user_chat ();
int index = 0; if (id == NOT_FOUND) {
while (index < user_num + chat_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len))) { printf ("Bad user/chat id\n");
index ++; RET;
} }
if (index < user_num + chat_num) { int t;
int len = 0; char *s = next_token (&t);
char *f = get_token (&q, &len); if (!s) {
if (len > 0) { printf ("Empty file name\n");
do_send_photo (CODE_input_media_uploaded_photo, RET;
Peers[index]->id, strndup (f, len)); }
} do_send_photo (CODE_input_media_uploaded_photo, id, strndup (s, t));
} } else if (IS_WORD("send_video")) {
} else if (!memcmp (line, "send_video", 10)) { int id = next_token_user_chat ();
char *q = line + 10; if (id == NOT_FOUND) {
int len; printf ("Bad user/chat id\n");
char *text = get_token (&q, &len); RET;
int index = 0; }
while (index < user_num + chat_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len))) { int t;
index ++; char *s = next_token (&t);
} if (!s) {
if (index < user_num + chat_num) { printf ("Empty file name\n");
int len = 0; RET;
char *f = get_token (&q, &len); }
if (len > 0) { do_send_photo (CODE_input_media_uploaded_video, id, strndup (s, t));
do_send_photo (CODE_input_media_uploaded_video, } else if (IS_WORD ("send_text")) {
Peers[index]->id, strndup (f, len)); int id = next_token_user_chat ();
} if (id == NOT_FOUND) {
} printf ("Bad user/chat id\n");
} else if (!memcmp (line, "send_text", 9)) { RET;
char *q = line + 10; }
int len; int t;
char *text = get_token (&q, &len); char *s = next_token (&t);
int index = 0; if (!s) {
while (index < user_num + chat_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len))) { printf ("Empty file name\n");
index ++; RET;
} }
if (index < user_num + chat_num) { do_send_text (id, strndup (s, t));
int len = 0; } else if (IS_WORD ("fwd")) {
char *f = get_token (&q, &len); int id = next_token_user_chat ();
if (len > 0) { if (id == NOT_FOUND) {
do_send_text (Peers[index], strndup (f, len)); printf ("Bad user/chat id\n");
} RET;
} }
} else if (!memcmp (line, "fwd ", 4)) { int num = next_token_int ();
char *q = line + 4; if (num == NOT_FOUND || num <= 0) {
int len; printf ("Bad msg id\n");
char *text = get_token (&q, &len); RET;
int index = 0; }
while (index < user_num + chat_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len))) { do_forward_message (id, num);
index ++; } else if (IS_WORD ("load_photo")) {
} int num = next_token_int ();
if (index < user_num + chat_num) { if (num == NOT_FOUND || num <= 0) {
int len = 0; printf ("Bad msg id\n");
char *f = get_token (&q, &len); RET;
if (f) { }
int num = atoi (f); struct message *M = message_get (num);
if (num > 0) { if (M && !M->service && M->media.type == (int)CODE_message_media_photo) {
do_forward_message (Peers[index], num); do_load_photo (&M->media.photo, 1);
} } else {
} printf ("Bad msg id\n");
} RET;
} else if (!memcmp (line, "load_photo ", 10)) { }
char *q = line + 10; } else if (IS_WORD ("view_photo")) {
int len = 0; int num = next_token_int ();
char *f = get_token (&q, &len); if (num == NOT_FOUND || num <= 0) {
if (f) { printf ("Bad msg id\n");
int num = atoi (f); RET;
if (num > 0) { }
struct message *M = message_get (num); struct message *M = message_get (num);
if (M && !M->service && M->media.type == (int)CODE_message_media_photo) { if (M && !M->service && M->media.type == (int)CODE_message_media_photo) {
do_load_photo (&M->media.photo, 1); do_load_photo (&M->media.photo, 2);
} } else {
} printf ("Bad msg id\n");
} RET;
} else if (!memcmp (line, "view_photo ", 10)) { }
char *q = line + 10; } else if (IS_WORD ("load_video_thumb")) {
int len = 0; int num = next_token_int ();
char *f = get_token (&q, &len); if (num == NOT_FOUND || num <= 0) {
if (f) { printf ("Bad msg id\n");
int num = atoi (f); RET;
if (num > 0) { }
struct message *M = message_get (num); struct message *M = message_get (num);
if (M && !M->service && M->media.type == (int)CODE_message_media_photo) { if (M && !M->service && M->media.type == (int)CODE_message_media_video) {
do_load_photo (&M->media.photo, 2); do_load_video_thumb (&M->media.video, 1);
} } else {
} printf ("Bad msg id\n");
} RET;
} else if (!memcmp (line, "load_video_thumb ", 16)) { }
char *q = line + 16; } else if (IS_WORD ("view_video_thumb")) {
int len = 0; int num = next_token_int ();
char *f = get_token (&q, &len); if (num == NOT_FOUND || num <= 0) {
if (f) { printf ("Bad msg id\n");
int num = atoi (f); RET;
if (num > 0) { }
struct message *M = message_get (num); struct message *M = message_get (num);
if (M && !M->service && M->media.type == (int)CODE_message_media_video) { if (M && !M->service && M->media.type == (int)CODE_message_media_video) {
do_load_video_thumb (&M->media.video, 1); do_load_video_thumb (&M->media.video, 2);
} } else {
} printf ("Bad msg id\n");
} RET;
} else if (!memcmp (line, "view_video_thumb ", 16)) { }
char *q = line + 16; } else if (IS_WORD ("load_video")) {
int len = 0; int num = next_token_int ();
char *f = get_token (&q, &len); if (num == NOT_FOUND || num <= 0) {
if (f) { printf ("Bad msg id\n");
int num = atoi (f); RET;
if (num > 0) { }
struct message *M = message_get (num); struct message *M = message_get (num);
if (M && !M->service && M->media.type == (int)CODE_message_media_video) { if (M && !M->service && M->media.type == (int)CODE_message_media_video) {
do_load_video_thumb (&M->media.video, 2); do_load_video (&M->media.video, 1);
} } else {
} printf ("Bad msg id\n");
} RET;
} else if (!memcmp (line, "load_video ", 10)) { }
char *q = line + 10; } else if (IS_WORD ("view_video")) {
int len = 0; int num = next_token_int ();
char *f = get_token (&q, &len); if (num == NOT_FOUND || num <= 0) {
if (f) { printf ("Bad msg id\n");
int num = atoi (f); RET;
if (num > 0) { }
struct message *M = message_get (num); struct message *M = message_get (num);
if (M && !M->service && M->media.type == (int)CODE_message_media_video) { if (M && !M->service && M->media.type == (int)CODE_message_media_video) {
do_load_video (&M->media.video, 1); do_load_video (&M->media.video, 2);
} } else {
} printf ("Bad msg id\n");
} RET;
} else if (!memcmp (line, "view_video ", 10)) { }
char *q = line + 10; } else if (IS_WORD ("chat_info")) {
int len = 0; int id = next_token_chat ();
char *f = get_token (&q, &len); if (id == NOT_FOUND) {
if (f) { printf ("Bad chat id\n");
int num = atoi (f); RET;
if (num > 0) { }
struct message *M = message_get (num); do_get_chat_info (id);
if (M && !M->service && M->media.type == (int)CODE_message_media_video) { } else if (IS_WORD ("user_info")) {
do_load_video (&M->media.video, 2); int id = next_token_user ();
} if (id == NOT_FOUND) {
} printf ("Bad user id\n");
} RET;
} else if (!memcmp (line, "chat_info", 9)) { }
char *q = line + 10; do_get_user_info (id);
int len; } else if (IS_WORD ("history")) {
char *text = get_token (&q, &len); int id = next_token_user_chat ();
int index = 0; if (id == NOT_FOUND) {
while (index < user_num + chat_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len))) { printf ("Bad user/chat id\n");
index ++; RET;
} }
if (index < user_num + chat_num && Peers[index]->id < 0) { int limit = next_token_int ();
do_get_chat_info (Peers[index]); do_get_history (id, limit > 0 ? limit : 40);
} } else if (IS_WORD ("help")) {
} else if (!memcmp (line, "user_info", 9)) {
char *q = line + 10;
int len;
char *text = get_token (&q, &len);
int index = 0;
while (index < user_num + chat_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len))) {
index ++;
}
if (index < user_num + chat_num && Peers[index]->id > 0) {
do_get_user_info (Peers[index]);
}
} else if (!memcmp (line, "history", 7)) {
char *q = line + 7;
int len;
char *text = get_token (&q, &len);
int index = 0;
while (index < user_num + chat_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len))) {
index ++;
}
if (index < user_num + chat_num) {
char *text = get_token (&q, &len);
int limit = 40;
if (text) {
limit = atoi (text);
if (limit <= 0 || limit >= 1000000) {
limit = 40;
}
}
do_get_history (Peers[index], limit);
}
} else if (!memcmp (line, "help", 4)) {
//print_start (); //print_start ();
push_color (COLOR_YELLOW); push_color (COLOR_YELLOW);
printf ( printf (
...@@ -548,12 +632,15 @@ void interpreter (char *line UU) { ...@@ -548,12 +632,15 @@ void interpreter (char *line UU) {
rl_on_new_line (); rl_on_new_line ();
//print_end (); //print_end ();
printf ("\033[1K\033H"); printf ("\033[1K\033H");
} else if (!memcmp (line, "show_license", 12)) { } else if (IS_WORD ("show_license")) {
char *b = char *b =
#include "LICENSE.h" #include "LICENSE.h"
; ;
printf ("%s", b); printf ("%s", b);
} }
#undef IS_WORD
#undef RET
in_readline = 0;
} }
int readline_active; int readline_active;
...@@ -586,6 +673,7 @@ int saved_point; ...@@ -586,6 +673,7 @@ int saved_point;
char *saved_line; char *saved_line;
int prompt_was; int prompt_was;
void print_start (void) { void print_start (void) {
if (in_readline) { return; }
assert (!prompt_was); assert (!prompt_was);
if (readline_active) { if (readline_active) {
saved_point = rl_point; saved_point = rl_point;
...@@ -597,6 +685,7 @@ void print_start (void) { ...@@ -597,6 +685,7 @@ void print_start (void) {
prompt_was = 1; prompt_was = 1;
} }
void print_end (void) { void print_end (void) {
if (in_readline) { return; }
assert (prompt_was); assert (prompt_was);
if (readline_active) { if (readline_active) {
rl_set_prompt (get_default_prompt ()); rl_set_prompt (get_default_prompt ());
......
...@@ -63,14 +63,6 @@ void net_loop (int flags, int (*is_end)(void)) { ...@@ -63,14 +63,6 @@ void net_loop (int flags, int (*is_end)(void)) {
double timer = next_timer_in (); double timer = next_timer_in ();
if (timer > 1000) { timer = 1000; } if (timer > 1000) { timer = 1000; }
if (poll (fds, x, timer) < 0) { if (poll (fds, x, timer) < 0) {
/* resuming from interrupt, so not an error situation,
this generally happens when you suspend your
messenger with "C-z" and then "fg". This is allowed "
*/
if (flags & 1) {
rl_reset_line_state ();
rl_forced_update_display ();
}
work_timers (); work_timers ();
continue; continue;
} }
...@@ -102,6 +94,7 @@ int is_got_it (void) { ...@@ -102,6 +94,7 @@ int is_got_it (void) {
} }
int net_getline (char **s, size_t *l) { int net_getline (char **s, size_t *l) {
rl_already_prompted = 1;
got_it_ok = 0; got_it_ok = 0;
_s = s; _s = s;
_l = l; _l = l;
......
...@@ -622,7 +622,8 @@ struct query_methods msg_send_methods = { ...@@ -622,7 +622,8 @@ struct query_methods msg_send_methods = {
int out_message_num; int out_message_num;
int our_id; int our_id;
void do_send_message (union user_chat *U, const char *msg, int len) { void out_peer_id (int id);
void do_send_message (int id, const char *msg, int len) {
if (!out_message_num) { if (!out_message_num) {
out_message_num = -lrand48 (); out_message_num = -lrand48 ();
} }
...@@ -631,21 +632,9 @@ void do_send_message (union user_chat *U, const char *msg, int len) { ...@@ -631,21 +632,9 @@ void do_send_message (union user_chat *U, const char *msg, int len) {
struct message *M = malloc (sizeof (*M)); struct message *M = malloc (sizeof (*M));
memset (M, 0, sizeof (*M)); memset (M, 0, sizeof (*M));
M->from_id = our_id; M->from_id = our_id;
M->to_id = U->id; M->to_id = id;
M->unread = 1; M->unread = 1;
if (U->id < 0) { out_peer_id (id);
out_int (CODE_input_peer_chat);
out_int (-U->id);
} else {
if (U->user.access_hash) {
out_int (CODE_input_peer_foreign);
out_int (U->id);
out_long (U->user.access_hash);
} else {
out_int (CODE_input_peer_contact);
out_int (U->id);
}
}
M->message = malloc (len + 1); M->message = malloc (len + 1);
memcpy (M->message, msg, len); memcpy (M->message, msg, len);
M->message[len] = 0; M->message[len] = 0;
...@@ -660,7 +649,7 @@ void do_send_message (union user_chat *U, const char *msg, int len) { ...@@ -660,7 +649,7 @@ void do_send_message (union user_chat *U, const char *msg, int len) {
print_message (M); print_message (M);
} }
void do_send_text (union user_chat *U, char *file_name) { void do_send_text (int id, char *file_name) {
int fd = open (file_name, O_RDONLY); int fd = open (file_name, O_RDONLY);
if (fd < 0) { if (fd < 0) {
rprintf ("No such file '%s'\n", file_name); rprintf ("No such file '%s'\n", file_name);
...@@ -676,7 +665,7 @@ void do_send_text (union user_chat *U, char *file_name) { ...@@ -676,7 +665,7 @@ void do_send_text (union user_chat *U, char *file_name) {
close (fd); close (fd);
} else { } else {
buf[x] = 0; buf[x] = 0;
do_send_message (U, buf, x); do_send_message (id, buf, x);
free (file_name); free (file_name);
close (fd); close (fd);
} }
...@@ -694,22 +683,10 @@ struct query_methods mark_read_methods = { ...@@ -694,22 +683,10 @@ struct query_methods mark_read_methods = {
.on_answer = mark_read_on_receive .on_answer = mark_read_on_receive
}; };
void do_messages_mark_read (union user_chat *U, int max_id) { void do_messages_mark_read (int id, int max_id) {
clear_packet (); clear_packet ();
out_int (CODE_messages_read_history); out_int (CODE_messages_read_history);
if (U->id < 0) { out_peer_id (id);
out_int (CODE_input_peer_chat);
out_int (-U->id);
} else {
if (U->user.access_hash) {
out_int (CODE_input_peer_foreign);
out_int (U->id);
out_long (U->user.access_hash);
} else {
out_int (CODE_input_peer_contact);
out_int (U->id);
}
}
out_int (max_id); out_int (max_id);
out_int (0); out_int (0);
send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &mark_read_methods, 0); send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &mark_read_methods, 0);
...@@ -749,7 +726,7 @@ int get_history_on_answer (struct query *q UU) { ...@@ -749,7 +726,7 @@ int get_history_on_answer (struct query *q UU) {
fetch_alloc_user (); fetch_alloc_user ();
} }
if (sn > 0) { if (sn > 0) {
do_messages_mark_read (q->extra, ML[0]->id); do_messages_mark_read ((long)(q->extra), ML[0]->id);
} }
return 0; return 0;
} }
...@@ -759,26 +736,14 @@ struct query_methods get_history_methods = { ...@@ -759,26 +736,14 @@ struct query_methods get_history_methods = {
}; };
void do_get_history (union user_chat *U, int limit) { void do_get_history (int id, int limit) {
clear_packet (); clear_packet ();
out_int (CODE_messages_get_history); out_int (CODE_messages_get_history);
if (U->id < 0) { out_peer_id (id);
out_int (CODE_input_peer_chat);
out_int (-U->id);
} else {
if (U->user.access_hash) {
out_int (CODE_input_peer_foreign);
out_int (U->id);
out_long (U->user.access_hash);
} else {
out_int (CODE_input_peer_contact);
out_int (U->id);
}
}
out_int (0); out_int (0);
out_int (0); out_int (0);
out_int (limit); out_int (limit);
send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &get_history_methods, U); send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &get_history_methods, (void *)(long)id);
} }
int get_dialogs_on_answer (struct query *q UU) { int get_dialogs_on_answer (struct query *q UU) {
...@@ -1023,11 +988,11 @@ struct query_methods fwd_msg_methods = { ...@@ -1023,11 +988,11 @@ struct query_methods fwd_msg_methods = {
.on_answer = fwd_msg_on_answer .on_answer = fwd_msg_on_answer
}; };
void do_forward_message (union user_chat *U, int n) { void do_forward_message (int id, int n) {
clear_packet (); clear_packet ();
out_int (CODE_invoke_with_layer3); out_int (CODE_invoke_with_layer3);
out_int (CODE_messages_forward_message); out_int (CODE_messages_forward_message);
out_peer_id (U->id); out_peer_id (id);
out_int (n); out_int (n);
out_long (lrand48 () * (1ll << 32) + lrand48 ()); out_long (lrand48 () * (1ll << 32) + lrand48 ());
send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &fwd_msg_methods, 0); send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &fwd_msg_methods, 0);
...@@ -1057,10 +1022,10 @@ struct query_methods rename_chat_methods = { ...@@ -1057,10 +1022,10 @@ struct query_methods rename_chat_methods = {
.on_answer = rename_chat_on_answer .on_answer = rename_chat_on_answer
}; };
void do_rename_chat (union user_chat *U, char *name) { void do_rename_chat (int id, char *name) {
clear_packet (); clear_packet ();
out_int (CODE_messages_edit_chat_title); out_int (CODE_messages_edit_chat_title);
out_int (-U->id); out_int (-id);
out_string (name); out_string (name);
send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &rename_chat_methods, 0); send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &rename_chat_methods, 0);
} }
...@@ -1095,10 +1060,10 @@ struct query_methods chat_info_methods = { ...@@ -1095,10 +1060,10 @@ struct query_methods chat_info_methods = {
.on_answer = chat_info_on_answer .on_answer = chat_info_on_answer
}; };
void do_get_chat_info (union user_chat *chat) { void do_get_chat_info (int id) {
clear_packet (); clear_packet ();
out_int (CODE_messages_get_full_chat); out_int (CODE_messages_get_full_chat);
out_int (-chat->id); out_int (-id);
send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &chat_info_methods, 0); send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &chat_info_methods, 0);
} }
...@@ -1128,16 +1093,17 @@ struct query_methods user_info_methods = { ...@@ -1128,16 +1093,17 @@ struct query_methods user_info_methods = {
.on_answer = user_info_on_answer .on_answer = user_info_on_answer
}; };
void do_get_user_info (union user_chat *U) { void do_get_user_info (int id) {
clear_packet (); clear_packet ();
out_int (CODE_users_get_full_user); out_int (CODE_users_get_full_user);
if (U->user.access_hash) { union user_chat *U = user_chat_get (id);
if (U && U->user.access_hash) {
out_int (CODE_input_user_foreign); out_int (CODE_input_user_foreign);
out_int (U->id); out_int (id);
out_long (U->user.access_hash); out_long (U->user.access_hash);
} else { } else {
out_int (CODE_input_user_contact); out_int (CODE_input_user_contact);
out_int (U->id); out_int (id);
} }
send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &user_info_methods, 0); send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &user_info_methods, 0);
} }
......
...@@ -68,16 +68,16 @@ double get_double_time (void); ...@@ -68,16 +68,16 @@ double get_double_time (void);
void do_update_contact_list (void); void do_update_contact_list (void);
union user_chat; union user_chat;
void do_send_message (union user_chat *U, const char *msg, int len); void do_send_message (int id, const char *msg, int len);
void do_send_text (union user_chat *U, char *file); void do_send_text (int id, char *file);
void do_get_history (union user_chat *U, int limit); void do_get_history (int id, int limit);
void do_get_dialog_list (void); void do_get_dialog_list (void);
void do_send_photo (int type, int to_id, char *file_name); void do_send_photo (int type, int to_id, char *file_name);
void do_get_chat_info (union user_chat *chat); void do_get_chat_info (int id);
void do_get_user_list_info_silent (int num, int *list); void do_get_user_list_info_silent (int num, int *list);
void do_get_user_info (union user_chat *user); void do_get_user_info (int id);
void do_forward_message (union user_chat *U, int n); void do_forward_message (int id, int n);
void do_rename_chat (union user_chat *U, char *name); void do_rename_chat (int id, char *name);
struct photo; struct photo;
struct video; struct video;
......
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