mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 01:53:02 +01:00
Remove ability to set note with status command
This commit is contained in:
parent
56e03a3f8b
commit
258736995d
@ -99,7 +99,11 @@ int complete_line(ToxWindow *self, const void *list, size_t n_items, size_t size
|
|||||||
{
|
{
|
||||||
ChatContext *ctx = self->chatwin;
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,11 +181,10 @@ static int parse_command(WINDOW *w, ToxWindow *self, const char *input, char (*a
|
|||||||
}
|
}
|
||||||
|
|
||||||
int num_args = 0;
|
int num_args = 0;
|
||||||
int i = 0; // index of last char in an argument
|
|
||||||
|
|
||||||
/* characters wrapped in double quotes count as one arg */
|
/* characters wrapped in double quotes count as one arg */
|
||||||
while (num_args < MAX_NUM_ARGS) {
|
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);
|
memcpy(args[num_args], cmd, i);
|
||||||
args[num_args++][i] = '\0';
|
args[num_args++][i] = '\0';
|
||||||
|
|
||||||
|
@ -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])
|
void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||||
{
|
{
|
||||||
bool have_note = false;
|
|
||||||
const char *errmsg;
|
const char *errmsg;
|
||||||
|
|
||||||
lock_status();
|
lock_status();
|
||||||
|
|
||||||
if (argc >= 2) {
|
if (argc < 1) {
|
||||||
have_note = true;
|
|
||||||
} else if (argc < 1) {
|
|
||||||
errmsg = "Require a status. Statuses are: online, busy and away.";
|
errmsg = "Require a status. Statuses are: online, busy and away.";
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
|
||||||
goto finish;
|
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);
|
tox_self_set_status(m, status);
|
||||||
prompt_update_status(prompt, 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:
|
finish:
|
||||||
unlock_status();
|
unlock_status();
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include <tox/tox.h>
|
#include <tox/tox.h>
|
||||||
|
|
||||||
#include "global_commands.h"
|
#include "execute.h"
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
#include "term_mplex.h"
|
#include "term_mplex.h"
|
||||||
#include "toxic.h"
|
#include "toxic.h"
|
||||||
@ -390,15 +390,16 @@ static void mplex_timer_handler(Tox *m)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char argv[3][MAX_STR_SIZE];
|
char status_str[MAX_STR_SIZE];
|
||||||
strcpy(argv[0], "/status");
|
char note_str[MAX_STR_SIZE];
|
||||||
strcpy(argv[1], (new_status == TOX_USER_STATUS_AWAY ? "away" :
|
const char *status = new_status == TOX_USER_STATUS_AWAY ? "away" :
|
||||||
new_status == TOX_USER_STATUS_BUSY ? "busy" : "online"));
|
new_status == TOX_USER_STATUS_BUSY ? "busy" : "online";
|
||||||
argv[2][0] = '\"';
|
snprintf(status_str, sizeof(status_str), "/status %s", status);
|
||||||
strcpy(argv[2] + 1, new_note);
|
snprintf(note_str, sizeof(status_str), "/note %s", new_note);
|
||||||
strcat(argv[2], "\"");
|
|
||||||
pthread_mutex_lock(&Winthread.lock);
|
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);
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user