Added chat_with_peer command

This commit is contained in:
Vysheng 2013-12-06 21:14:41 +04:00
parent 2c9e51b4af
commit 9ebb3f7370
4 changed files with 85 additions and 8 deletions

View File

@ -1046,6 +1046,22 @@ void replay_log_event (void) {
}
}
break;
case CODE_binlog_delete_msg:
rptr ++;
{
struct message *M = message_get (*(long long *)rptr);
rptr += 2;
assert (M);
if (M->flags & FLAG_PENDING) {
message_remove_unsent (M);
M->flags &= ~FLAG_PENDING;
}
message_remove_tree (M);
message_del_peer (M);
free_message (M);
free (M);
}
break;
case CODE_update_user_photo:
case CODE_update_user_name:
work_update_binlog ();
@ -1751,3 +1767,10 @@ void bl_do_set_msg_id (struct message *M, int id) {
out_int (id);
add_log_event (packet_buffer, 4 * (packet_ptr - packet_buffer));
}
void bl_do_delete_msg (struct message *M) {
clear_packet ();
out_int (CODE_binlog_delete_msg);
out_long (M->id);
add_log_event (packet_buffer, 4 * (packet_ptr - packet_buffer));
}

View File

@ -81,6 +81,7 @@
#define CODE_binlog_set_msg_id 0xf3285b6a
#define CODE_binlog_create_message_media_encr 0x19cd7c9d
#define CODE_binlog_create_message_service_encr 0x8b4b9395
#define CODE_binlog_delete_msg 0xa1d6ab6d
void *alloc_log_event (int l);
void replay_log (void);
@ -145,4 +146,5 @@ void bl_do_send_message_text (long long msg_id, int from_id, int to_type, int to
void bl_do_set_unread (struct message *M, int unread);
void bl_do_set_message_sent (struct message *M);
void bl_do_set_msg_id (struct message *M, int id);
void bl_do_delete_msg (struct message *M);
#endif

View File

@ -63,6 +63,9 @@ char *line_ptr;
extern peer_t *Peers[];
extern int peer_num;
int in_chat_mode;
peer_id_t chat_mode_id;
int is_same_word (const char *s, size_t l, const char *word) {
return s && word && strlen (word) == l && !memcmp (s, word, l);
@ -204,9 +207,15 @@ peer_id_t next_token_peer (void) {
}
char *get_default_prompt (void) {
static char buf[100];
static char buf[1000];
int l = 0;
if (in_chat_mode) {
peer_t *U = user_chat_get (chat_mode_id);
assert (U && U->print_name);
l += sprintf (buf + l, COLOR_RED "%.*s " COLOR_NORMAL, 100, U->print_name);
}
if (unread_messages || cur_uploading_bytes || cur_downloading_bytes) {
int l = sprintf (buf, COLOR_RED "[");
l += sprintf (buf + l, COLOR_RED "[");
int ok = 0;
if (unread_messages) {
l += sprintf (buf + l, "%d unread", unread_messages);
@ -222,11 +231,11 @@ char *get_default_prompt (void) {
ok = 1;
l += sprintf (buf + l, "%lld%%Down", 100 * cur_downloaded_bytes / cur_downloading_bytes);
}
sprintf (buf + l, "]" COLOR_NORMAL "%s", default_prompt);
l += sprintf (buf + l, "]" COLOR_NORMAL);
return buf;
} else {
return default_prompt;
}
l += sprintf (buf + l, "%s", default_prompt);
return buf;
}
char *complete_none (const char *text UU, int state UU) {
@ -252,6 +261,12 @@ char *modifiers[] = {
0
};
char *in_chat_commands[] = {
"/exit",
"/quit",
0
};
char *commands[] = {
"help",
"msg",
@ -296,6 +311,7 @@ char *commands[] = {
"load_document",
"view_document",
"set",
"chat_with_peer",
0 };
int commands_flags[] = {
@ -342,6 +358,7 @@ int commands_flags[] = {
07,
07,
07,
072,
};
@ -452,6 +469,12 @@ int complete_string_list (char **list, int index, const char *text, int len, cha
char *command_generator (const char *text, int state) {
static int len, index, mode;
if (in_chat_mode) {
char *R = 0;
index = complete_string_list (in_chat_commands, index, text, rl_point, &R);
return R;
}
char c = 0;
if (!state) {
len = strlen (text);
@ -521,10 +544,27 @@ void work_modifier (const char *s, int l) {
#endif
}
void interpreter_chat_mode (char *line) {
if (!strncmp (line, "/exit", 5) || !strncmp (line, "/quit", 5)) {
in_chat_mode = 0;
update_prompt ();
return;
}
do_send_message (chat_mode_id, line, strlen (line));
}
void interpreter (char *line UU) {
line_ptr = line;
assert (!in_readline);
in_readline = 1;
if (in_chat_mode) {
interpreter_chat_mode (line);
in_readline = 0;
return;
}
line_ptr = line;
offline_mode = 0;
count = 1;
if (!line) {
@ -1002,6 +1042,10 @@ void interpreter (char *line UU) {
} else if (IS_WORD ("msg_num")) {
msg_num_mode = num;
}
} else if (IS_WORD ("chat_with_peer")) {
GET_PEER;
in_chat_mode = 1;
chat_mode_id = id;
} else if (IS_WORD ("quit")) {
exit (0);
}

View File

@ -845,8 +845,16 @@ int msg_send_on_answer (struct query *q UU) {
return 0;
}
int msg_send_on_error (struct query *q, int error_code, int error_len, char *error) {
logprintf ( "error for query #%lld: #%d :%.*s\n", q->msg_id, error_code, error_len, error);
struct message *M = q->extra;
bl_do_delete_msg (M);
return 0;
}
struct query_methods msg_send_methods = {
.on_answer = msg_send_on_answer
.on_answer = msg_send_on_answer,
.on_error = msg_send_on_error
};
struct query_methods msg_send_encr_methods = {