added delete/restore messages queries

This commit is contained in:
Vysheng 2014-01-24 19:05:41 +04:00
parent bc8e97cdba
commit 8f63825890
3 changed files with 78 additions and 4 deletions

View File

@ -46,7 +46,7 @@
#include "mtproto-common.h"
//#define ALLOW_MULT 1
#define ALLOW_MULT 1
char *default_prompt = "> ";
int unread_messages;
@ -86,14 +86,14 @@ char *next_token (int *l) {
char *s = line_ptr;
int in_str = 0;
while (*line_ptr && (*line_ptr != ' ' || neg || in_str)) {
if (*line_ptr == '\\') {
/* if (*line_ptr == '\\') {
neg = 1 - neg;
} else {
if (*line_ptr == '"' && !neg) {
in_str = !in_str;
}
neg = 0;
}
}*/
line_ptr++;
}
*l = line_ptr - s;
@ -320,6 +320,8 @@ char *commands[] = {
"view_document",
"set",
"chat_with_peer",
"delete_msg",
"restore_msg",
0 };
int commands_flags[] = {
@ -368,6 +370,8 @@ int commands_flags[] = {
07,
07,
072,
07,
07
};
@ -1067,6 +1071,28 @@ void interpreter (char *line UU) {
GET_PEER;
in_chat_mode = 1;
chat_mode_id = id;
} else if (IS_WORD ("delete_msg")) {
long long num = next_token_int ();
if (num == NOT_FOUND) {
printf ("Bad msg id\n");
RET;
}
do_delete_msg (num);
} else if (IS_WORD ("restore_msg")) {
long long num = next_token_int ();
if (num == NOT_FOUND) {
printf ("Bad msg id\n");
RET;
}
do_restore_msg (num);
} else if (IS_WORD ("delete_restore_msg")) {
long long num = next_token_int ();
if (num == NOT_FOUND) {
printf ("Bad msg id\n");
RET;
}
do_delete_msg (num);
do_restore_msg (num);
} else if (IS_WORD ("quit")) {
exit (0);
} else if (IS_WORD ("safe_quit")) {

View File

@ -2746,6 +2746,53 @@ void do_create_secret_chat (peer_id_t id) {
}
/* }}} */
/* {{{ Delete msg */
int delete_msg_on_answer (struct query *q UU) {
assert (fetch_int () == CODE_vector);
int n = fetch_int ();
fetch_skip (n);
logprintf ("Deleted %d messages\n", n);
return 0;
}
struct query_methods delete_msg_methods = {
.on_answer = delete_msg_on_answer
};
void do_delete_msg (long long id) {
clear_packet ();
out_int (CODE_messages_delete_messages);
out_int (CODE_vector);
out_int (1);
out_int (id);
send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &delete_msg_methods, 0);
}
/* }}} */
/* {{{ Restore msg */
int restore_msg_on_answer (struct query *q UU) {
assert (fetch_int () == CODE_vector);
int n = fetch_int ();
fetch_skip (n);
logprintf ("Restored %d messages\n", n);
return 0;
}
struct query_methods restore_msg_methods = {
.on_answer = restore_msg_on_answer
};
void do_restore_msg (long long id) {
clear_packet ();
out_int (CODE_messages_restore_messages);
out_int (CODE_vector);
out_int (1);
out_int (id);
send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &restore_msg_methods, 0);
}
/* }}} */
int update_status_on_answer (struct query *q UU) {
fetch_bool ();
return 0;

View File

@ -111,7 +111,8 @@ void do_del_user_from_chat (peer_id_t chat_id, peer_id_t id);
void do_update_status (int online);
void do_contacts_search (int limit, const char *s);
void do_send_msg (struct message *M);
void do_delete_msg (long long id);
void do_restore_msg (long long id);
// For binlog