mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-24 21:33:01 +01:00
Compare commits
No commits in common. "30d01127e75730ad39d671895416732287571e8b" and "ff669be8d1e9221f605ddd773c3ffca4885a792f" have entirely different histories.
30d01127e7
...
ff669be8d1
@ -157,7 +157,7 @@ CMP_FILENAME="cmp-$CMP_VERSION.tar.gz"
|
||||
wget --timeout=10 -O "$CMP_FILENAME" "https://github.com/TokTok/cmp/archive/$CMP_VERSION.tar.gz"
|
||||
tar -o -xf "$CMP_FILENAME"
|
||||
|
||||
mv cmp-*/* 'cmp/'
|
||||
mv cmp\-*/* "cmp/"
|
||||
cd ..
|
||||
|
||||
cmake -B_build -H. \
|
||||
|
@ -142,6 +142,10 @@ static struct cmd_func groupchat_commands[] = {
|
||||
{ "/unsilence", cmd_unsilence },
|
||||
{ "/voice", cmd_set_voice },
|
||||
{ "/whois", cmd_whois },
|
||||
#ifdef AUDIO
|
||||
{ "/mute", cmd_mute },
|
||||
{ "/sense", cmd_sense },
|
||||
#endif /* AUDIO */
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
|
@ -173,16 +173,10 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
|
||||
char id_bin[TOX_ADDRESS_SIZE] = {0};
|
||||
|
||||
const bool is_domain = char_find(0, id, '@') != arg_length;
|
||||
const bool valid_id_size = arg_length >= TOX_ADDRESS_SIZE * 2; // arg_length may include invite message
|
||||
const bool is_tox_id = (char_find(0, id, '@') == arg_length) && (arg_length >= TOX_ADDRESS_SIZE * 2);
|
||||
|
||||
if (is_domain) {
|
||||
if (!name_lookup(self, m, id_bin, id, msg)) {
|
||||
return;
|
||||
}
|
||||
} else if (!valid_id_size) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid Tox ID.");
|
||||
return;
|
||||
if (!is_tox_id) {
|
||||
name_lookup(self, m, id_bin, id, msg);
|
||||
}
|
||||
|
||||
char xx[3];
|
||||
|
@ -141,8 +141,6 @@ void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
|
||||
}
|
||||
|
||||
line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- Ignoring %s", nick);
|
||||
|
||||
group_toggle_peer_ignore(self->num, peer_id, true);
|
||||
}
|
||||
|
||||
void cmd_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
@ -844,8 +842,6 @@ void cmd_unignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
|
||||
}
|
||||
|
||||
line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- You are no longer ignoring %s", nick);
|
||||
|
||||
group_toggle_peer_ignore(self->num, peer_id, false);
|
||||
}
|
||||
|
||||
void cmd_whois(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
|
154
src/groupchats.c
154
src/groupchats.c
@ -117,6 +117,12 @@ static const char *group_cmd_list[] = {
|
||||
"/voice",
|
||||
"/whisper",
|
||||
"/whois",
|
||||
#ifdef AUDIO
|
||||
"/lsdev",
|
||||
"/sdev",
|
||||
"/mute",
|
||||
"/sense",
|
||||
#endif /* AUDIO */
|
||||
};
|
||||
|
||||
GroupChat groupchats[MAX_GROUPCHAT_NUM];
|
||||
@ -132,7 +138,6 @@ static void groupchat_onGroupStatusChange(ToxWindow *self, Tox *m, uint32_t grou
|
||||
TOX_USER_STATUS status);
|
||||
static void groupchat_onGroupSelfNickChange(ToxWindow *self, Tox *m, uint32_t groupnumber, const char *old_nick,
|
||||
size_t old_length, const char *new_nick, size_t length);
|
||||
static void ignore_list_cleanup(GroupChat *chat);
|
||||
|
||||
/*
|
||||
* Return a GroupChat pointer associated with groupnumber.
|
||||
@ -235,8 +240,6 @@ static void close_groupchat(ToxWindow *self, Tox *m, uint32_t groupnumber)
|
||||
return;
|
||||
}
|
||||
|
||||
ignore_list_cleanup(chat);
|
||||
|
||||
realloc_peer_list(groupnumber, 0);
|
||||
|
||||
free_ptr_array((void **) chat->name_list);
|
||||
@ -658,131 +661,6 @@ int get_peer_index(uint32_t groupnumber, uint32_t peer_id)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if `key` is in the ignored list.
|
||||
*/
|
||||
static bool peer_is_ignored(const GroupChat *chat, const uint8_t *key)
|
||||
{
|
||||
for (uint16_t i = 0; i < chat->num_ignored; ++i) {
|
||||
if (memcmp(chat->ignored_list[i], key, TOX_GROUP_PEER_PUBLIC_KEY_SIZE) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool ignore_list_add_key(GroupChat *chat, const uint8_t *key)
|
||||
{
|
||||
uint8_t **tmp_list = (uint8_t **)realloc(chat->ignored_list, (chat->num_ignored + 1) * sizeof(uint8_t *));
|
||||
|
||||
if (tmp_list == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
chat->ignored_list = tmp_list;
|
||||
|
||||
tmp_list[chat->num_ignored] = (uint8_t *)malloc(sizeof(uint8_t) * TOX_GROUP_PEER_PUBLIC_KEY_SIZE);
|
||||
|
||||
if (tmp_list[chat->num_ignored] == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(tmp_list[chat->num_ignored], key, TOX_GROUP_PEER_PUBLIC_KEY_SIZE);
|
||||
++chat->num_ignored;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ignore_list_cleanup(GroupChat *chat)
|
||||
{
|
||||
for (uint16_t i = 0; i < chat->num_ignored; ++i) {
|
||||
if (chat->ignored_list[i] != NULL) {
|
||||
free(chat->ignored_list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
free(chat->ignored_list);
|
||||
chat->ignored_list = NULL;
|
||||
chat->num_ignored = 0;
|
||||
}
|
||||
|
||||
static bool ignore_list_rm_key(GroupChat *chat, const uint8_t *key)
|
||||
{
|
||||
if (chat->num_ignored == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t idx = -1;
|
||||
|
||||
for (uint16_t i = 0; i < chat->num_ignored; ++i) {
|
||||
if (memcmp(chat->ignored_list[i], key, TOX_GROUP_PEER_PUBLIC_KEY_SIZE) == 0) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (idx == -1) {
|
||||
fprintf(stderr, "Key not found in ignore list\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((chat->num_ignored - 1) == 0) {
|
||||
ignore_list_cleanup(chat);
|
||||
return true;
|
||||
}
|
||||
|
||||
--chat->num_ignored;
|
||||
|
||||
if (idx != chat->num_ignored) {
|
||||
memcpy(chat->ignored_list[idx], chat->ignored_list[chat->num_ignored], TOX_GROUP_PEER_PUBLIC_KEY_SIZE);
|
||||
}
|
||||
|
||||
free(chat->ignored_list[chat->num_ignored]);
|
||||
|
||||
uint8_t **tmp_list = realloc(chat->ignored_list, chat->num_ignored * sizeof(uint8_t *));
|
||||
|
||||
if (tmp_list == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
chat->ignored_list = tmp_list;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void group_toggle_peer_ignore(uint32_t groupnumber, int peer_id, bool ignore)
|
||||
{
|
||||
int peer_index = get_peer_index(groupnumber, peer_id);
|
||||
|
||||
if (peer_index < 0) {
|
||||
fprintf(stderr, "Failed to find peer index (group_toggle_peer_ignore())\n");
|
||||
return;
|
||||
}
|
||||
|
||||
GroupChat *chat = get_groupchat(groupnumber);
|
||||
|
||||
if (!chat) {
|
||||
return;
|
||||
}
|
||||
|
||||
GroupPeer *peer = &chat->peer_list[peer_index];
|
||||
|
||||
peer->is_ignored = ignore;
|
||||
|
||||
bool ret;
|
||||
|
||||
if (ignore) {
|
||||
ret = ignore_list_add_key(chat, peer->public_key);
|
||||
} else {
|
||||
ret = ignore_list_rm_key(chat, peer->public_key);
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
fprintf(stderr, "Client failed to modify ignore list\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void group_update_name_list(uint32_t groupnumber)
|
||||
{
|
||||
GroupChat *chat = get_groupchat(groupnumber);
|
||||
@ -1149,12 +1027,7 @@ static void groupchat_onGroupPeerJoin(ToxWindow *self, Tox *m, uint32_t groupnum
|
||||
peer->status = tox_group_peer_get_status(m, groupnumber, peer_id, NULL);
|
||||
peer->role = tox_group_peer_get_role(m, groupnumber, peer_id, NULL);
|
||||
peer->last_active = get_unix_time();
|
||||
tox_group_peer_get_public_key(m, groupnumber, peer_id, (uint8_t *)peer->public_key, NULL);
|
||||
peer->is_ignored = peer_is_ignored(chat, peer->public_key);
|
||||
|
||||
if (peer->is_ignored) {
|
||||
tox_group_set_ignore(m, groupnumber, peer_id, true, NULL);
|
||||
}
|
||||
tox_group_peer_get_public_key(m, groupnumber, peer_id, (uint8_t *) peer->public_key, NULL);
|
||||
|
||||
if (i == chat->max_idx) {
|
||||
++chat->max_idx;
|
||||
@ -1877,12 +1750,7 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
||||
|
||||
wmove(ctx->sidebar, offset + 2, 1);
|
||||
|
||||
const bool is_ignored = chat->peer_list[i].is_ignored;
|
||||
uint16_t maxlen_offset = chat->peer_list[i].role == TOX_GROUP_ROLE_USER ? 2 : 3;
|
||||
|
||||
if (is_ignored) {
|
||||
++maxlen_offset;
|
||||
}
|
||||
const int maxlen_offset = chat->peer_list[i].role == TOX_GROUP_ROLE_USER ? 2 : 3;
|
||||
|
||||
/* truncate nick to fit in side panel without modifying list */
|
||||
char tmpnck[TOX_MAX_NAME_LENGTH];
|
||||
@ -1917,12 +1785,6 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
||||
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
if (is_ignored) {
|
||||
wattron(ctx->sidebar, COLOR_PAIR(RED) | A_BOLD);
|
||||
wprintw(ctx->sidebar, "#");
|
||||
wattroff(ctx->sidebar, COLOR_PAIR(RED) | A_BOLD);
|
||||
}
|
||||
|
||||
wattron(ctx->sidebar, COLOR_PAIR(rolecolour) | A_BOLD);
|
||||
wprintw(ctx->sidebar, "%s", rolesig);
|
||||
wattroff(ctx->sidebar, COLOR_PAIR(rolecolour) | A_BOLD);
|
||||
|
@ -47,7 +47,6 @@ typedef struct GroupPeer {
|
||||
uint8_t public_key[TOX_GROUP_PEER_PUBLIC_KEY_SIZE];
|
||||
TOX_USER_STATUS status;
|
||||
Tox_Group_Role role;
|
||||
bool is_ignored;
|
||||
uint64_t last_active;
|
||||
} GroupPeer;
|
||||
|
||||
@ -57,9 +56,6 @@ typedef struct {
|
||||
uint32_t num_peers; /* Number of peers in the chat/name_list array */
|
||||
uint32_t max_idx; /* Maximum peer list index - 1 */
|
||||
|
||||
uint8_t **ignored_list; /* List of keys of peers that we're ignoring */
|
||||
uint16_t num_ignored;
|
||||
|
||||
char group_name[TOX_GROUP_MAX_GROUP_NAME_LENGTH + 1];
|
||||
size_t group_name_length;
|
||||
uint32_t groupnumber;
|
||||
@ -112,9 +108,4 @@ void redraw_groupchat_win(ToxWindow *self);
|
||||
*/
|
||||
GroupChat *get_groupchat(uint32_t groupnumber);
|
||||
|
||||
/**
|
||||
* Toggles the ignore status of the peer associated with `peer_id`.
|
||||
*/
|
||||
void group_toggle_peer_ignore(uint32_t groupnumber, int peer_id, bool ignore);
|
||||
|
||||
#endif /* #define GROUPCHATS_H */
|
||||
|
@ -362,20 +362,16 @@ on_exit:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Attempts to do a tox name lookup.
|
||||
*
|
||||
* Returns true on success.
|
||||
*/
|
||||
bool name_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr, const char *message)
|
||||
void name_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr, const char *message)
|
||||
{
|
||||
if (t_data.disabled) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "nameservers list is empty or does not exist.");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (t_data.busy) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Please wait for previous name lookup to finish.");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(t_data.id_bin, sizeof(t_data.id_bin), "%s", id_bin);
|
||||
@ -388,24 +384,22 @@ bool name_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr,
|
||||
if (pthread_attr_init(&lookup_thread.attr) != 0) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, "Error: lookup thread attr failed to init");
|
||||
clear_thread_data();
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (pthread_attr_setdetachstate(&lookup_thread.attr, PTHREAD_CREATE_DETACHED) != 0) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, "Error: lookup thread attr failed to set");
|
||||
pthread_attr_destroy(&lookup_thread.attr);
|
||||
clear_thread_data();
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (pthread_create(&lookup_thread.tid, &lookup_thread.attr, lookup_thread_func, NULL) != 0) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, "Error: lookup thread failed to init");
|
||||
pthread_attr_destroy(&lookup_thread.attr);
|
||||
clear_thread_data();
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Initializes http based name lookups. Note: This function must be called only once before additional
|
||||
|
@ -23,19 +23,14 @@
|
||||
#ifndef NAME_LOOKUP
|
||||
#define NAME_LOOKUP
|
||||
|
||||
/* Initializes http based name lookups.
|
||||
*
|
||||
* Note: This function must be called only once before additional threads are spawned.
|
||||
/* Initializes http based name lookups. Note: This function must be called only once before additional
|
||||
* threads are spawned.
|
||||
*
|
||||
* Returns 0 on success.
|
||||
* Returns -1 on failure.
|
||||
*/
|
||||
int name_lookup_init(int curl_init_status);
|
||||
|
||||
/* Attempts to do a tox name lookup.
|
||||
*
|
||||
* Returns true on success.
|
||||
*/
|
||||
bool name_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr, const char *message);
|
||||
int name_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr, const char *message);
|
||||
|
||||
#endif /* NAME_LOOKUP */
|
||||
|
@ -114,8 +114,8 @@ void flag_interface_refresh(void);
|
||||
/* Sets ncurses refresh rate. Lower values make it refresh more often. */
|
||||
void set_window_refresh_rate(size_t refresh_rate);
|
||||
|
||||
void exit_toxic_success(Tox *m) __attribute__((__noreturn__));
|
||||
void exit_toxic_err(const char *errmsg, int errcode) __attribute__((__noreturn__));
|
||||
void exit_toxic_success(Tox *m);
|
||||
void exit_toxic_err(const char *errmsg, int errcode);
|
||||
|
||||
int store_data(Tox *m, const char *path);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user