1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-06-26 20:47:45 +02:00

Remove ability to set note with status command

This commit is contained in:
jfreegman 2018-10-08 13:47:08 -04:00
parent 56e03a3f8b
commit 258736995d
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
4 changed files with 18 additions and 33 deletions

View File

@ -99,7 +99,11 @@ int complete_line(ToxWindow *self, const void *list, size_t n_items, size_t size
{
ChatContext *ctx = self->chatwin;
if (ctx->pos <= 0 || ctx->len <= 0 || ctx->pos > ctx->len || ctx->len >= MAX_STR_SIZE || size > MAX_STR_SIZE) {
if (ctx->pos <= 0 || ctx->len <= 0 || ctx->pos > ctx->len) {
return -1;
}
if (ctx->len >= MAX_STR_SIZE || size > MAX_STR_SIZE) {
return -1;
}

View File

@ -181,11 +181,10 @@ static int parse_command(WINDOW *w, ToxWindow *self, const char *input, char (*a
}
int num_args = 0;
int i = 0; // index of last char in an argument
/* characters wrapped in double quotes count as one arg */
while (num_args < MAX_NUM_ARGS) {
i = char_find(0, cmd, ' ');
int i = char_find(0, cmd, ' '); // index of last char in an argument
memcpy(args[num_args], cmd, i);
args[num_args++][i] = '\0';

View File

@ -592,14 +592,11 @@ void cmd_requests(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
bool have_note = false;
const char *errmsg;
lock_status();
if (argc >= 2) {
have_note = true;
} else if (argc < 1) {
if (argc < 1) {
errmsg = "Require a status. Statuses are: online, busy and away.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
goto finish;
@ -622,24 +619,8 @@ void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
tox_self_set_status(m, status);
prompt_update_status(prompt, status);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Your status has been changed to %s.", status_str);
if (have_note) {
if (argv[2][0] != '\"') {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Note must be enclosed in quotes.");
goto finish;
}
/* remove opening and closing quotes */
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "%s", &argv[2][1]);
int len = strlen(msg) - 1;
msg[len] = '\0';
prompt_update_statusmessage(prompt, m, msg);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Your status has been changed to %s: \"%s\".", status_str, msg);
} else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Your status has been changed to %s.", status_str);
}
finish:
unlock_status();

View File

@ -33,7 +33,7 @@
#include <tox/tox.h>
#include "global_commands.h"
#include "execute.h"
#include "windows.h"
#include "term_mplex.h"
#include "toxic.h"
@ -390,15 +390,16 @@ static void mplex_timer_handler(Tox *m)
return;
}
char argv[3][MAX_STR_SIZE];
strcpy(argv[0], "/status");
strcpy(argv[1], (new_status == TOX_USER_STATUS_AWAY ? "away" :
new_status == TOX_USER_STATUS_BUSY ? "busy" : "online"));
argv[2][0] = '\"';
strcpy(argv[2] + 1, new_note);
strcat(argv[2], "\"");
char status_str[MAX_STR_SIZE];
char note_str[MAX_STR_SIZE];
const char *status = new_status == TOX_USER_STATUS_AWAY ? "away" :
new_status == TOX_USER_STATUS_BUSY ? "busy" : "online";
snprintf(status_str, sizeof(status_str), "/status %s", status);
snprintf(note_str, sizeof(status_str), "/note %s", new_note);
pthread_mutex_lock(&Winthread.lock);
cmd_status(prompt->chatwin->history, prompt, m, 2, argv);
execute(prompt->chatwin->history, prompt, m, status_str, GLOBAL_COMMAND_MODE);
execute(prompt->chatwin->history, prompt, m, note_str, GLOBAL_COMMAND_MODE);
pthread_mutex_unlock(&Winthread.lock);
}