Commit 41fc7c22 authored by Vysheng's avatar Vysheng

added /read and /history in chat_with_peer mode

parent 47174fe7
...@@ -264,6 +264,8 @@ char *modifiers[] = { ...@@ -264,6 +264,8 @@ char *modifiers[] = {
char *in_chat_commands[] = { char *in_chat_commands[] = {
"/exit", "/exit",
"/quit", "/quit",
"/history",
"/read",
0 0
}; };
...@@ -552,6 +554,17 @@ void interpreter_chat_mode (char *line) { ...@@ -552,6 +554,17 @@ void interpreter_chat_mode (char *line) {
update_prompt (); update_prompt ();
return; return;
} }
if (!strncmp (line, "/history", 8)) {
int limit = 40;
sscanf (line, "/history %d", &limit);
if (limit < 0 || limit > 1000) { limit = 40; }
do_get_history (chat_mode_id, limit);
return;
}
if (!strncmp (line, "/read", 5)) {
do_mark_read (chat_mode_id);
return;
}
do_send_message (chat_mode_id, line, strlen (line)); do_send_message (chat_mode_id, line, strlen (line));
} }
...@@ -1153,6 +1166,7 @@ void pop_color (void) { ...@@ -1153,6 +1166,7 @@ void pop_color (void) {
} }
void print_media (struct message_media *M) { void print_media (struct message_media *M) {
assert (M);
switch (M->type) { switch (M->type) {
case CODE_message_media_empty: case CODE_message_media_empty:
case CODE_decrypted_message_media_empty: case CODE_decrypted_message_media_empty:
...@@ -1250,6 +1264,7 @@ void print_user_name (peer_id_t id, peer_t *U) { ...@@ -1250,6 +1264,7 @@ void print_user_name (peer_id_t id, peer_t *U) {
} }
void print_chat_name (peer_id_t id, peer_t *C) { void print_chat_name (peer_id_t id, peer_t *C) {
assert (get_peer_type (id) == PEER_CHAT);
push_color (COLOR_MAGENTA); push_color (COLOR_MAGENTA);
if (!C) { if (!C) {
printf ("chat#%d", get_peer_id (id)); printf ("chat#%d", get_peer_id (id));
...@@ -1260,6 +1275,7 @@ void print_chat_name (peer_id_t id, peer_t *C) { ...@@ -1260,6 +1275,7 @@ void print_chat_name (peer_id_t id, peer_t *C) {
} }
void print_encr_chat_name (peer_id_t id, peer_t *C) { void print_encr_chat_name (peer_id_t id, peer_t *C) {
assert (get_peer_type (id) == PEER_ENCR_CHAT);
push_color (COLOR_MAGENTA); push_color (COLOR_MAGENTA);
if (!C) { if (!C) {
printf ("encr_chat#%d", get_peer_id (id)); printf ("encr_chat#%d", get_peer_id (id));
...@@ -1270,6 +1286,7 @@ void print_encr_chat_name (peer_id_t id, peer_t *C) { ...@@ -1270,6 +1286,7 @@ void print_encr_chat_name (peer_id_t id, peer_t *C) {
} }
void print_encr_chat_name_full (peer_id_t id, peer_t *C) { void print_encr_chat_name_full (peer_id_t id, peer_t *C) {
assert (get_peer_type (id) == PEER_ENCR_CHAT);
push_color (COLOR_MAGENTA); push_color (COLOR_MAGENTA);
if (!C) { if (!C) {
printf ("encr_chat#%d", get_peer_id (id)); printf ("encr_chat#%d", get_peer_id (id));
...@@ -1297,6 +1314,7 @@ void print_date_full (long t) { ...@@ -1297,6 +1314,7 @@ void print_date_full (long t) {
int our_id; int our_id;
void print_service_message (struct message *M) { void print_service_message (struct message *M) {
assert (M);
print_start (); print_start ();
push_color (COLOR_GREY); push_color (COLOR_GREY);
...@@ -1310,6 +1328,7 @@ void print_service_message (struct message *M) { ...@@ -1310,6 +1328,7 @@ void print_service_message (struct message *M) {
if (get_peer_type (M->to_id) == PEER_CHAT) { if (get_peer_type (M->to_id) == PEER_CHAT) {
print_chat_name (M->to_id, user_chat_get (M->to_id)); print_chat_name (M->to_id, user_chat_get (M->to_id));
} else { } else {
assert (get_peer_type (M->to_id) == PEER_ENCR_CHAT);
print_encr_chat_name (M->to_id, user_chat_get (M->to_id)); print_encr_chat_name (M->to_id, user_chat_get (M->to_id));
} }
printf (" "); printf (" ");
...@@ -1362,9 +1381,11 @@ peer_id_t last_from_id; ...@@ -1362,9 +1381,11 @@ peer_id_t last_from_id;
peer_id_t last_to_id; peer_id_t last_to_id;
void print_message (struct message *M) { void print_message (struct message *M) {
assert (M);
if (M->flags & (FLAG_MESSAGE_EMPTY | FLAG_DELETED)) { if (M->flags & (FLAG_MESSAGE_EMPTY | FLAG_DELETED)) {
return; return;
} }
if (!(M->flags & FLAG_CREATED)) { return; }
if (M->service) { if (M->service) {
print_service_message (M); print_service_message (M);
return; return;
......
...@@ -205,7 +205,7 @@ int rpc_send_message (struct connection *c, void *data, int len) { ...@@ -205,7 +205,7 @@ int rpc_send_message (struct connection *c, void *data, int len) {
assert (write_out (c, &total_len, 4) == 4); assert (write_out (c, &total_len, 4) == 4);
} }
c->out_packet_num ++; c->out_packet_num ++;
write_out (c, data, len); assert (write_out (c, data, len) == len);
flush_out (c); flush_out (c);
total_packets_sent ++; total_packets_sent ++;
...@@ -726,11 +726,8 @@ void work_update_binlog (void) { ...@@ -726,11 +726,8 @@ void work_update_binlog (void) {
U->last_name = fetch_str_dup (); U->last_name = fetch_str_dup ();
U->print_name = create_print_name (U->id, U->first_name, U->last_name, 0, 0); U->print_name = create_print_name (U->id, U->first_name, U->last_name, 0, 0);
} else { } else {
int l; fetch_skip_str ();
l = prefetch_strlen (); fetch_skip_str ();
fetch_str (l);
l = prefetch_strlen ();
fetch_str (l);
} }
} }
break; break;
...@@ -778,6 +775,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { ...@@ -778,6 +775,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
case CODE_update_new_message: case CODE_update_new_message:
{ {
struct message *M = fetch_alloc_message (); struct message *M = fetch_alloc_message ();
assert (M);
fetch_pts (); fetch_pts ();
unread_messages ++; unread_messages ++;
print_message (M); print_message (M);
...@@ -898,11 +896,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { ...@@ -898,11 +896,8 @@ void work_update (struct connection *c UU, long long msg_id UU) {
pop_color (); pop_color ();
print_end (); print_end ();
} else { } else {
int l; fetch_skip_str ();
l = prefetch_strlen (); fetch_skip_str ();
fetch_str (l);
l = prefetch_strlen ();
fetch_str (l);
} }
} }
break; break;
......
...@@ -304,6 +304,7 @@ static inline char *fetch_str (int len) { ...@@ -304,6 +304,7 @@ static inline char *fetch_str (int len) {
static inline char *fetch_str_dup (void) { static inline char *fetch_str_dup (void) {
int l = prefetch_strlen (); int l = prefetch_strlen ();
assert (l >= 0);
char *s = malloc (l + 1); char *s = malloc (l + 1);
memcpy (s, fetch_str (l), l); memcpy (s, fetch_str (l), l);
s[l] = 0; s[l] = 0;
...@@ -361,6 +362,12 @@ static inline void fetch_skip (int n) { ...@@ -361,6 +362,12 @@ static inline void fetch_skip (int n) {
in_ptr += n; in_ptr += n;
} }
static inline void fetch_skip_str (void) {
int l = prefetch_strlen ();
assert (l >= 0);
fetch_str (l);
}
static __inline__ unsigned long long rdtsc(void) { static __inline__ unsigned long long rdtsc(void) {
unsigned hi, lo; unsigned hi, lo;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
......
...@@ -1592,7 +1592,7 @@ struct query_methods rename_chat_methods = { ...@@ -1592,7 +1592,7 @@ struct query_methods rename_chat_methods = {
.on_answer = rename_chat_on_answer .on_answer = rename_chat_on_answer
}; };
void do_rename_chat (peer_id_t id, char *name) { void do_rename_chat (peer_id_t id, char *name UU) {
clear_packet (); clear_packet ();
out_int (CODE_messages_edit_chat_title); out_int (CODE_messages_edit_chat_title);
assert (get_peer_type (id) == PEER_CHAT); assert (get_peer_type (id) == PEER_CHAT);
...@@ -2316,7 +2316,8 @@ void do_create_keys_end (struct secret_chat *U) { ...@@ -2316,7 +2316,8 @@ void do_create_keys_end (struct secret_chat *U) {
hexdump ((void *)U->g_key, (void *)(U->g_key + 256)); hexdump ((void *)U->g_key, (void *)(U->g_key + 256));
hexdump ((void *)U->key, (void *)(U->key + 64)); hexdump ((void *)U->key, (void *)(U->key + 64));
hexdump ((void *)t, (void *)(t + 256)); hexdump ((void *)t, (void *)(t + 256));
logprintf ("!!Key fingerprint mismatch\n"); hexdump ((void *)sha_buffer, (void *)(sha_buffer + 20));
logprintf ("!!Key fingerprint mismatch (my 0x%llx 0x%llx)\n", (unsigned long long)k, (unsigned long long)U->key_fingerprint);
U->state = sc_deleted; U->state = sc_deleted;
} }
......
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