2014-02-25 08:28:24 +01:00
|
|
|
/* friendlist.c
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Toxic All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This file is part of Toxic.
|
|
|
|
*
|
|
|
|
* Toxic is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Toxic is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Toxic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2013-07-30 21:47:40 +02:00
|
|
|
*/
|
|
|
|
|
2020-04-18 02:00:00 +02:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <assert.h>
|
2013-07-30 21:47:40 +02:00
|
|
|
#include <stdint.h>
|
2013-08-28 20:47:47 +02:00
|
|
|
#include <stdlib.h>
|
2020-04-18 02:00:00 +02:00
|
|
|
#include <string.h>
|
2014-03-14 22:48:52 +01:00
|
|
|
#include <time.h>
|
2013-07-30 21:47:40 +02:00
|
|
|
|
2013-08-24 04:15:15 +02:00
|
|
|
#include <tox/tox.h>
|
2013-07-30 21:47:40 +02:00
|
|
|
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "avatars.h"
|
2013-11-19 21:32:35 +01:00
|
|
|
#include "chat.h"
|
2013-08-13 00:50:43 +02:00
|
|
|
#include "friendlist.h"
|
2014-07-31 19:49:15 +02:00
|
|
|
#include "help.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "line_info.h"
|
2014-09-27 08:28:11 +02:00
|
|
|
#include "log.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "misc_tools.h"
|
|
|
|
#include "notify.h"
|
2021-12-11 23:35:51 +01:00
|
|
|
#include "prompt.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "settings.h"
|
|
|
|
#include "toxic.h"
|
|
|
|
#include "windows.h"
|
2014-03-16 20:28:46 +01:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2014-03-07 03:14:04 +01:00
|
|
|
#include "audio_call.h"
|
2014-03-16 20:28:46 +01:00
|
|
|
#endif
|
2013-07-30 21:47:40 +02:00
|
|
|
|
2014-07-21 03:25:21 +02:00
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
static uint8_t blocklist_view = 0; /* 0 if we're in friendlist view, 1 if we're in blocklist view */
|
2013-07-30 21:47:40 +02:00
|
|
|
|
2014-09-28 23:49:48 +02:00
|
|
|
FriendsList Friends;
|
2013-11-24 23:12:24 +01:00
|
|
|
|
2014-09-28 23:49:48 +02:00
|
|
|
static struct Blocked {
|
2014-07-31 18:48:49 +02:00
|
|
|
int num_selected;
|
2014-08-07 19:05:42 +02:00
|
|
|
int max_idx;
|
2014-07-31 18:48:49 +02:00
|
|
|
int num_blocked;
|
2015-03-26 03:56:45 +01:00
|
|
|
uint32_t *index;
|
2014-08-07 19:05:42 +02:00
|
|
|
BlockedFriend *list;
|
2014-08-08 01:24:56 +02:00
|
|
|
} Blocked;
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
static struct PendingDel {
|
|
|
|
uint32_t num;
|
2014-03-15 22:18:23 +01:00
|
|
|
bool active;
|
2014-06-24 00:54:23 +02:00
|
|
|
WINDOW *popup;
|
2015-03-26 03:56:45 +01:00
|
|
|
} PendingDelete;
|
2014-03-09 05:57:21 +01:00
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
static void realloc_friends(int n)
|
|
|
|
{
|
|
|
|
if (n <= 0) {
|
|
|
|
free(Friends.list);
|
|
|
|
free(Friends.index);
|
|
|
|
Friends.list = NULL;
|
|
|
|
Friends.index = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ToxicFriend *f = realloc(Friends.list, n * sizeof(ToxicFriend));
|
2015-03-26 03:56:45 +01:00
|
|
|
uint32_t *f_idx = realloc(Friends.index, n * sizeof(uint32_t));
|
2014-08-07 19:05:42 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (f == NULL || f_idx == NULL) {
|
2015-07-04 07:19:16 +02:00
|
|
|
exit_toxic_err("failed in realloc_friends", FATALERR_MEMORY);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-08-07 19:05:42 +02:00
|
|
|
|
|
|
|
Friends.list = f;
|
|
|
|
Friends.index = f_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void realloc_blocklist(int n)
|
|
|
|
{
|
|
|
|
if (n <= 0) {
|
2014-08-08 01:24:56 +02:00
|
|
|
free(Blocked.list);
|
|
|
|
free(Blocked.index);
|
|
|
|
Blocked.list = NULL;
|
|
|
|
Blocked.index = NULL;
|
2014-08-07 19:05:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
BlockedFriend *b = realloc(Blocked.list, n * sizeof(BlockedFriend));
|
2015-03-26 03:56:45 +01:00
|
|
|
uint32_t *b_idx = realloc(Blocked.index, n * sizeof(uint32_t));
|
2014-08-07 19:05:42 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (b == NULL || b_idx == NULL) {
|
2015-07-04 07:19:16 +02:00
|
|
|
exit_toxic_err("failed in realloc_blocklist", FATALERR_MEMORY);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-08-07 19:05:42 +02:00
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
Blocked.list = b;
|
|
|
|
Blocked.index = b_idx;
|
2014-08-07 19:05:42 +02:00
|
|
|
}
|
|
|
|
|
2018-10-09 20:21:33 +02:00
|
|
|
void kill_friendlist(ToxWindow *self)
|
2014-08-07 19:05:42 +02:00
|
|
|
{
|
2018-10-10 00:59:25 +02:00
|
|
|
for (size_t i = 0; i < Friends.max_idx; ++i) {
|
2021-01-17 19:29:13 +01:00
|
|
|
if (Friends.list[i].active) {
|
2020-11-08 16:08:24 +01:00
|
|
|
free(Friends.list[i].conference_invite.key);
|
2021-01-19 04:37:14 +01:00
|
|
|
#ifdef GAMES
|
2021-01-17 19:29:13 +01:00
|
|
|
free(Friends.list[i].game_invite.data);
|
2021-01-19 04:37:14 +01:00
|
|
|
#endif
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2020-11-13 03:30:48 +01:00
|
|
|
|
|
|
|
if (Friends.list[i].group_invite.data != NULL) {
|
|
|
|
free(Friends.list[i].group_invite.data);
|
|
|
|
}
|
2014-09-28 04:50:20 +02:00
|
|
|
}
|
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
realloc_blocklist(0);
|
|
|
|
realloc_friends(0);
|
2018-10-09 20:21:33 +02:00
|
|
|
free(self->help);
|
|
|
|
del_window(self);
|
2014-08-07 19:05:42 +02:00
|
|
|
}
|
|
|
|
|
2020-11-11 03:25:27 +01:00
|
|
|
static void clear_blocklist_index(size_t idx)
|
|
|
|
{
|
|
|
|
Blocked.list[idx] = (BlockedFriend) {
|
|
|
|
0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clear_friendlist_index(size_t idx)
|
|
|
|
{
|
|
|
|
Friends.list[idx] = (ToxicFriend) {
|
|
|
|
0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-11-08 03:38:32 +01:00
|
|
|
/* Saves the blocklist to path. If there are no items in the blocklist the
|
|
|
|
* empty file will be removed.
|
|
|
|
*
|
|
|
|
* Returns 0 if stored successfully.
|
|
|
|
* Returns -1 on failure.
|
|
|
|
*/
|
|
|
|
#define TEMP_BLOCKLIST_EXT ".tmp"
|
2014-07-31 18:48:49 +02:00
|
|
|
static int save_blocklist(char *path)
|
|
|
|
{
|
2016-05-03 20:13:16 +02:00
|
|
|
if (path == NULL) {
|
2014-07-31 18:48:49 +02:00
|
|
|
return -1;
|
2016-05-03 20:13:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
int len = sizeof(BlockedFriend) * Blocked.num_blocked;
|
2016-05-03 20:13:16 +02:00
|
|
|
char *data = malloc(len * sizeof(char));
|
|
|
|
|
|
|
|
if (data == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2015-11-05 23:46:00 +01:00
|
|
|
int i, count = 0;
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
for (i = 0; i < Blocked.max_idx; ++i) {
|
2016-05-03 20:13:16 +02:00
|
|
|
if (count > Blocked.num_blocked) {
|
|
|
|
free(data);
|
2015-08-27 09:38:08 +02:00
|
|
|
return -1;
|
2016-05-03 20:13:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
if (Blocked.list[i].active) {
|
2017-08-29 01:37:19 +02:00
|
|
|
if (Blocked.list[i].namelength > TOXIC_MAX_NAME_LENGTH) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-11 03:25:27 +01:00
|
|
|
BlockedFriend tmp = {0};
|
2014-08-08 01:24:56 +02:00
|
|
|
tmp.namelength = htons(Blocked.list[i].namelength);
|
2017-08-29 01:37:19 +02:00
|
|
|
memcpy(tmp.name, Blocked.list[i].name, Blocked.list[i].namelength + 1); // Include null byte
|
2015-02-01 21:09:48 +01:00
|
|
|
memcpy(tmp.pub_key, Blocked.list[i].pub_key, TOX_PUBLIC_KEY_SIZE);
|
2014-07-31 20:53:02 +02:00
|
|
|
|
|
|
|
uint8_t lastonline[sizeof(uint64_t)];
|
2014-08-08 01:24:56 +02:00
|
|
|
memcpy(lastonline, &Blocked.list[i].last_on, sizeof(uint64_t));
|
2014-08-15 18:22:39 +02:00
|
|
|
hst_to_net(lastonline, sizeof(uint64_t));
|
2014-07-31 20:53:02 +02:00
|
|
|
memcpy(&tmp.last_on, lastonline, sizeof(uint64_t));
|
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
memcpy(data + count * sizeof(BlockedFriend), &tmp, sizeof(BlockedFriend));
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 23:46:00 +01:00
|
|
|
/* Blocklist is empty, we can remove the empty file */
|
|
|
|
if (count == 0) {
|
2016-05-03 20:13:16 +02:00
|
|
|
free(data);
|
|
|
|
|
|
|
|
if (remove(path) != 0) {
|
2015-11-05 23:46:00 +01:00
|
|
|
return -1;
|
2016-05-03 20:13:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2015-11-05 23:46:00 +01:00
|
|
|
return 0;
|
2015-08-27 09:38:08 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2020-10-28 05:54:06 +01:00
|
|
|
size_t temp_buf_size = strlen(path) + strlen(TEMP_BLOCKLIST_EXT) + 1;
|
|
|
|
char *temp_path = malloc(temp_buf_size);
|
|
|
|
|
|
|
|
if (temp_path == NULL) {
|
|
|
|
free(data);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(temp_path, temp_buf_size, "%s%s", path, TEMP_BLOCKLIST_EXT);
|
2015-11-08 03:38:32 +01:00
|
|
|
|
|
|
|
FILE *fp = fopen(temp_path, "wb");
|
2015-11-05 23:46:00 +01:00
|
|
|
|
2016-05-03 20:13:16 +02:00
|
|
|
if (fp == NULL) {
|
|
|
|
free(data);
|
2020-10-28 05:54:06 +01:00
|
|
|
free(temp_path);
|
2015-11-05 23:46:00 +01:00
|
|
|
return -1;
|
2016-05-03 20:13:16 +02:00
|
|
|
}
|
2015-11-05 23:46:00 +01:00
|
|
|
|
2015-08-27 09:38:08 +02:00
|
|
|
if (fwrite(data, len, 1, fp) != 1) {
|
2015-11-08 03:38:32 +01:00
|
|
|
fprintf(stderr, "Failed to write blocklist data.\n");
|
2015-08-27 09:38:08 +02:00
|
|
|
fclose(fp);
|
2016-05-03 20:13:16 +02:00
|
|
|
free(data);
|
2020-10-28 05:54:06 +01:00
|
|
|
free(temp_path);
|
2015-08-27 09:38:08 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
|
|
|
fclose(fp);
|
2016-05-03 20:13:16 +02:00
|
|
|
free(data);
|
2015-11-05 23:46:00 +01:00
|
|
|
|
2016-05-03 20:13:16 +02:00
|
|
|
if (rename(temp_path, path) != 0) {
|
2020-10-28 05:54:06 +01:00
|
|
|
free(temp_path);
|
2015-11-05 23:46:00 +01:00
|
|
|
return -1;
|
2016-05-03 20:13:16 +02:00
|
|
|
}
|
2015-11-05 23:46:00 +01:00
|
|
|
|
2020-10-28 05:54:06 +01:00
|
|
|
free(temp_path);
|
|
|
|
|
2014-10-03 04:25:21 +02:00
|
|
|
return 0;
|
2014-07-31 18:48:49 +02:00
|
|
|
}
|
2013-12-14 02:57:32 +01:00
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
static void sort_blocklist_index(void);
|
|
|
|
|
|
|
|
int load_blocklist(char *path)
|
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (path == NULL) {
|
2014-07-31 18:48:49 +02:00
|
|
|
return -1;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-12-14 02:57:32 +01:00
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
FILE *fp = fopen(path, "rb");
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (fp == NULL) {
|
2014-07-31 18:48:49 +02:00
|
|
|
return -1;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2014-09-24 20:23:08 +02:00
|
|
|
off_t len = file_size(path);
|
2014-09-24 04:51:56 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
if (len == 0) {
|
2014-09-24 04:51:56 +02:00
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-10-28 05:54:06 +01:00
|
|
|
char *data = malloc(len);
|
|
|
|
|
|
|
|
if (data == NULL) {
|
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
|
|
|
if (fread(data, len, 1, fp) != 1) {
|
|
|
|
fclose(fp);
|
2020-10-28 05:54:06 +01:00
|
|
|
free(data);
|
2014-07-31 18:48:49 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len % sizeof(BlockedFriend) != 0) {
|
|
|
|
fclose(fp);
|
2020-10-28 05:54:06 +01:00
|
|
|
free(data);
|
2014-07-31 18:48:49 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int num = len / sizeof(BlockedFriend);
|
2014-08-08 01:24:56 +02:00
|
|
|
Blocked.max_idx = num;
|
2014-08-07 19:05:42 +02:00
|
|
|
realloc_blocklist(num);
|
|
|
|
|
2020-10-28 05:54:06 +01:00
|
|
|
for (int i = 0; i < num; ++i) {
|
2020-11-11 03:25:27 +01:00
|
|
|
BlockedFriend tmp = {0};
|
|
|
|
clear_blocklist_index(i);
|
2014-08-07 19:05:42 +02:00
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
memcpy(&tmp, data + i * sizeof(BlockedFriend), sizeof(BlockedFriend));
|
2017-08-29 01:37:19 +02:00
|
|
|
Blocked.list[i].namelength = ntohs(tmp.namelength);
|
|
|
|
|
|
|
|
if (Blocked.list[i].namelength > TOXIC_MAX_NAME_LENGTH) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
Blocked.list[i].active = true;
|
|
|
|
Blocked.list[i].num = i;
|
2017-08-29 01:37:19 +02:00
|
|
|
memcpy(Blocked.list[i].name, tmp.name, Blocked.list[i].namelength + 1); // copy null byte
|
2015-02-01 21:09:48 +01:00
|
|
|
memcpy(Blocked.list[i].pub_key, tmp.pub_key, TOX_PUBLIC_KEY_SIZE);
|
2014-07-31 20:53:02 +02:00
|
|
|
|
|
|
|
uint8_t lastonline[sizeof(uint64_t)];
|
|
|
|
memcpy(lastonline, &tmp.last_on, sizeof(uint64_t));
|
|
|
|
net_to_host(lastonline, sizeof(uint64_t));
|
2014-08-08 01:24:56 +02:00
|
|
|
memcpy(&Blocked.list[i].last_on, lastonline, sizeof(uint64_t));
|
2014-07-31 20:53:02 +02:00
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
++Blocked.num_blocked;
|
2014-07-31 18:48:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
2020-10-28 05:54:06 +01:00
|
|
|
free(data);
|
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
sort_blocklist_index();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define S_WEIGHT 100000
|
2013-11-26 00:49:31 +01:00
|
|
|
static int index_name_cmp(const void *n1, const void *n2)
|
2013-11-24 23:12:24 +01:00
|
|
|
{
|
2021-12-11 23:18:43 +01:00
|
|
|
int res = qsort_strcasecmp_hlpr(Friends.list[*(const int *) n1].name, Friends.list[*(const int *) n2].name);
|
2013-11-25 00:22:48 +01:00
|
|
|
|
|
|
|
/* Use weight to make qsort always put online friends before offline */
|
2021-12-11 23:18:43 +01:00
|
|
|
res = Friends.list[*(const int *) n1].connection_status ? (res - S_WEIGHT) : (res + S_WEIGHT);
|
|
|
|
res = Friends.list[*(const int *) n2].connection_status ? (res + S_WEIGHT) : (res - S_WEIGHT);
|
2013-11-25 00:22:48 +01:00
|
|
|
|
|
|
|
return res;
|
2013-11-24 23:12:24 +01:00
|
|
|
}
|
2013-11-09 08:50:32 +01:00
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
/* sorts Friends.index first by connection status then alphabetically */
|
2014-03-14 04:30:44 +01:00
|
|
|
void sort_friendlist_index(void)
|
2013-11-09 08:50:32 +01:00
|
|
|
{
|
2015-03-28 07:56:54 +01:00
|
|
|
size_t i;
|
|
|
|
uint32_t n = 0;
|
2013-11-09 08:50:32 +01:00
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
for (i = 0; i < Friends.max_idx; ++i) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Friends.list[i].active) {
|
2014-08-07 19:05:42 +02:00
|
|
|
Friends.index[n++] = Friends.list[i].num;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-11-09 08:50:32 +01:00
|
|
|
}
|
|
|
|
|
2020-05-20 03:44:35 +02:00
|
|
|
if (Friends.num_friends > 0) {
|
|
|
|
qsort(Friends.index, Friends.num_friends, sizeof(uint32_t), index_name_cmp);
|
|
|
|
}
|
2013-11-09 08:50:32 +01:00
|
|
|
}
|
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
static int index_name_cmp_block(const void *n1, const void *n2)
|
|
|
|
{
|
2021-12-11 23:18:43 +01:00
|
|
|
return qsort_strcasecmp_hlpr(Blocked.list[*(const int *) n1].name, Blocked.list[*(const int *) n2].name);
|
2014-07-31 18:48:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sort_blocklist_index(void)
|
|
|
|
{
|
2015-03-28 07:56:54 +01:00
|
|
|
size_t i;
|
|
|
|
uint32_t n = 0;
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
for (i = 0; i < Blocked.max_idx; ++i) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Blocked.list[i].active) {
|
2014-08-08 01:24:56 +02:00
|
|
|
Blocked.index[n++] = Blocked.list[i].num;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
qsort(Blocked.index, Blocked.num_blocked, sizeof(uint32_t), index_name_cmp_block);
|
2014-07-31 18:48:49 +02:00
|
|
|
}
|
|
|
|
|
2016-09-23 00:31:52 +02:00
|
|
|
static void update_friend_last_online(uint32_t num, time_t timestamp)
|
2014-03-15 22:18:23 +01:00
|
|
|
{
|
2014-08-07 19:05:42 +02:00
|
|
|
Friends.list[num].last_online.last_on = timestamp;
|
2016-09-25 03:07:04 +02:00
|
|
|
Friends.list[num].last_online.tm = *localtime((const time_t *)×tamp);
|
2014-03-19 08:14:08 +01:00
|
|
|
|
|
|
|
/* if the format changes make sure TIME_STR_SIZE is the correct size */
|
2015-02-20 00:20:38 +01:00
|
|
|
const char *t = user_settings->timestamp_format;
|
2014-08-07 19:05:42 +02:00
|
|
|
strftime(Friends.list[num].last_online.hour_min_str, TIME_STR_SIZE, t,
|
|
|
|
&Friends.list[num].last_online.tm);
|
2014-03-15 22:18:23 +01:00
|
|
|
}
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
static void friendlist_onMessage(ToxWindow *self, Tox *m, uint32_t num, Tox_Message_Type type, const char *str,
|
2015-03-26 03:56:45 +01:00
|
|
|
size_t length)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(self);
|
|
|
|
UNUSED_VAR(type);
|
|
|
|
UNUSED_VAR(length);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (num >= Friends.max_idx) {
|
2013-08-16 19:11:09 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-08-16 19:11:09 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Friends.list[num].chatwin != -1) {
|
2015-03-26 03:56:45 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-11-30 11:35:25 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
|
|
|
Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num));
|
|
|
|
return;
|
|
|
|
}
|
2013-11-30 11:35:25 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
|
|
|
get_nick_truncate(m, nick, num);
|
2014-03-25 13:21:50 +01:00
|
|
|
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(prompt, true, nick, NULL, IN_MSG, 0, 0, "%s", str);
|
|
|
|
line_info_add(prompt, false, NULL, NULL, SYS_MSG, 0, RED, "* Warning: Too many windows are open.");
|
2015-03-26 03:56:45 +01:00
|
|
|
sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
|
2013-07-31 20:20:16 +02:00
|
|
|
}
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
static void friendlist_onConnectionChange(ToxWindow *self, Tox *m, uint32_t num, Tox_Connection connection_status)
|
2013-09-05 03:25:59 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(self);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (num >= Friends.max_idx) {
|
2013-09-05 03:25:59 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-05 03:25:59 +02:00
|
|
|
|
2015-04-04 09:26:38 +02:00
|
|
|
if (connection_status == TOX_CONNECTION_NONE) {
|
2015-03-26 03:56:45 +01:00
|
|
|
--Friends.num_online;
|
2015-04-04 09:26:38 +02:00
|
|
|
} else if (Friends.list[num].connection_status == TOX_CONNECTION_NONE) {
|
2015-03-26 03:56:45 +01:00
|
|
|
++Friends.num_online;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (avatar_send(m, num) == -1) {
|
2020-11-03 00:08:54 +01:00
|
|
|
fprintf(stderr, "avatar_send failed for friend %u\n", num);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-04-04 09:26:38 +02:00
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
Friends.list[num].connection_status = connection_status;
|
2014-03-15 22:18:23 +01:00
|
|
|
update_friend_last_online(num, get_unix_time());
|
2014-03-14 22:48:52 +01:00
|
|
|
store_data(m, DATA_FILE);
|
2014-03-14 04:30:44 +01:00
|
|
|
sort_friendlist_index();
|
2013-09-05 03:25:59 +02:00
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
static void friendlist_onNickChange(ToxWindow *self, Tox *m, uint32_t num, const char *nick, size_t length)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(self);
|
|
|
|
UNUSED_VAR(length);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (num >= Friends.max_idx) {
|
2013-08-16 19:11:09 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-07-30 21:47:40 +02:00
|
|
|
|
2014-09-27 08:28:11 +02:00
|
|
|
/* save old name for log renaming */
|
2014-10-03 23:53:50 +02:00
|
|
|
char oldname[TOXIC_MAX_NAME_LENGTH + 1];
|
2014-09-27 08:28:11 +02:00
|
|
|
snprintf(oldname, sizeof(oldname), "%s", Friends.list[num].name);
|
|
|
|
|
|
|
|
/* update name */
|
2014-10-03 23:53:50 +02:00
|
|
|
snprintf(Friends.list[num].name, sizeof(Friends.list[num].name), "%s", nick);
|
|
|
|
Friends.list[num].namelength = strlen(Friends.list[num].name);
|
2014-09-27 08:28:11 +02:00
|
|
|
|
|
|
|
/* get data for chatlog renaming */
|
2014-10-03 23:53:50 +02:00
|
|
|
char newnamecpy[TOXIC_MAX_NAME_LENGTH + 1];
|
2015-03-26 03:56:45 +01:00
|
|
|
char myid[TOX_ADDRESS_SIZE];
|
2014-10-03 23:53:50 +02:00
|
|
|
strcpy(newnamecpy, Friends.list[num].name);
|
2015-03-26 03:56:45 +01:00
|
|
|
tox_self_get_address(m, (uint8_t *) myid);
|
2014-09-27 08:28:11 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (strcmp(oldname, newnamecpy) != 0) {
|
2020-11-17 22:05:20 +01:00
|
|
|
if (rename_logfile(oldname, newnamecpy, myid, Friends.list[num].pub_key, Friends.list[num].chatwin) != 0) {
|
|
|
|
fprintf(stderr, "Failed to rename friend chat log from `%s` to `%s`\n", oldname, newnamecpy);
|
|
|
|
}
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-27 08:28:11 +02:00
|
|
|
|
2014-03-14 04:30:44 +01:00
|
|
|
sort_friendlist_index();
|
2013-07-30 21:47:40 +02:00
|
|
|
}
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
static void friendlist_onStatusChange(ToxWindow *self, Tox *m, uint32_t num, Tox_User_Status status)
|
2013-09-05 03:25:59 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(self);
|
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (num >= Friends.max_idx) {
|
2013-09-05 03:25:59 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-05 03:25:59 +02:00
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
Friends.list[num].status = status;
|
2013-09-05 03:25:59 +02:00
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
static void friendlist_onStatusMessageChange(ToxWindow *self, uint32_t num, const char *note, size_t length)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(self);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (length > TOX_MAX_STATUS_MESSAGE_LENGTH || num >= Friends.max_idx) {
|
2013-08-16 19:11:09 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-07-30 21:47:40 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
snprintf(Friends.list[num].statusmsg, sizeof(Friends.list[num].statusmsg), "%s", note);
|
2014-08-07 19:05:42 +02:00
|
|
|
Friends.list[num].statusmsg_len = strlen(Friends.list[num].statusmsg);
|
2013-07-30 21:47:40 +02:00
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, uint32_t num, bool sort)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(self);
|
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
realloc_friends(Friends.max_idx + 1);
|
2020-11-11 03:25:27 +01:00
|
|
|
clear_friendlist_index(Friends.max_idx);
|
2014-08-07 19:05:42 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
uint32_t i;
|
2013-08-28 11:46:09 +02:00
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
for (i = 0; i <= Friends.max_idx; ++i) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Friends.list[i].active) {
|
2014-08-07 19:05:42 +02:00
|
|
|
continue;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-04 03:31:50 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
++Friends.num_friends;
|
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
Friends.list[i].num = num;
|
|
|
|
Friends.list[i].active = true;
|
|
|
|
Friends.list[i].chatwin = -1;
|
2015-03-26 03:56:45 +01:00
|
|
|
Friends.list[i].connection_status = TOX_CONNECTION_NONE;
|
|
|
|
Friends.list[i].status = TOX_USER_STATUS_NONE;
|
2014-09-23 03:24:45 +02:00
|
|
|
Friends.list[i].logging_on = (bool) user_settings->autolog == AUTOLOG_ON;
|
2015-03-26 03:56:45 +01:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_Friend_Get_Public_Key pkerr;
|
2015-04-04 09:26:38 +02:00
|
|
|
tox_friend_get_public_key(m, num, (uint8_t *) Friends.list[i].pub_key, &pkerr);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (pkerr != TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK) {
|
2015-07-04 07:19:16 +02:00
|
|
|
fprintf(stderr, "tox_friend_get_public_key failed (error %d)\n", pkerr);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-04-04 09:26:38 +02:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_Friend_Get_Last_Online loerr;
|
2016-09-23 00:31:52 +02:00
|
|
|
time_t t = tox_friend_get_last_online(m, num, &loerr);
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (loerr != TOX_ERR_FRIEND_GET_LAST_ONLINE_OK) {
|
2015-04-04 09:26:38 +02:00
|
|
|
t = 0;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2015-04-04 09:26:38 +02:00
|
|
|
update_friend_last_online(i, t);
|
2014-08-07 19:05:42 +02:00
|
|
|
|
2020-10-24 20:44:41 +02:00
|
|
|
char tempname[TOX_MAX_NAME_LENGTH + 1];
|
|
|
|
int name_len = get_nick_truncate(m, tempname, num);
|
|
|
|
memcpy(Friends.list[i].name, tempname, name_len);
|
|
|
|
Friends.list[i].name[name_len] = 0;
|
|
|
|
Friends.list[i].namelength = name_len;
|
2014-02-08 05:28:17 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (i == Friends.max_idx) {
|
2014-08-07 19:05:42 +02:00
|
|
|
++Friends.max_idx;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-11-09 08:50:32 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (sort) {
|
2014-08-07 19:05:42 +02:00
|
|
|
sort_friendlist_index();
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-12-04 07:08:26 +01:00
|
|
|
|
2017-11-20 13:02:56 +01:00
|
|
|
#ifdef AUDIO
|
|
|
|
init_friend_AV(i);
|
|
|
|
#endif
|
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
return;
|
2013-08-28 11:46:09 +02:00
|
|
|
}
|
2013-07-30 21:47:40 +02:00
|
|
|
}
|
|
|
|
|
2018-10-20 08:56:37 +02:00
|
|
|
/* Puts blocked friend back in friendlist. fnum is new friend number, bnum is blocked number. */
|
2020-03-15 19:57:00 +01:00
|
|
|
static void friendlist_add_blocked(uint32_t fnum, uint32_t bnum)
|
2014-07-31 18:48:49 +02:00
|
|
|
{
|
2014-08-07 19:05:42 +02:00
|
|
|
realloc_friends(Friends.max_idx + 1);
|
2020-11-11 03:25:27 +01:00
|
|
|
clear_friendlist_index(Friends.max_idx);
|
2014-07-31 18:48:49 +02:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
for (i = 0; i <= Friends.max_idx; ++i) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Friends.list[i].active) {
|
2014-07-31 18:48:49 +02:00
|
|
|
continue;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
++Friends.num_friends;
|
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
Friends.list[i].num = fnum;
|
|
|
|
Friends.list[i].active = true;
|
|
|
|
Friends.list[i].chatwin = -1;
|
2015-03-26 03:56:45 +01:00
|
|
|
Friends.list[i].status = TOX_USER_STATUS_NONE;
|
2014-09-23 03:24:45 +02:00
|
|
|
Friends.list[i].logging_on = (bool) user_settings->autolog == AUTOLOG_ON;
|
2014-08-08 01:24:56 +02:00
|
|
|
Friends.list[i].namelength = Blocked.list[bnum].namelength;
|
|
|
|
update_friend_last_online(i, Blocked.list[bnum].last_on);
|
|
|
|
memcpy(Friends.list[i].name, Blocked.list[bnum].name, Friends.list[i].namelength + 1);
|
2015-02-01 21:09:48 +01:00
|
|
|
memcpy(Friends.list[i].pub_key, Blocked.list[bnum].pub_key, TOX_PUBLIC_KEY_SIZE);
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (i == Friends.max_idx) {
|
2014-08-07 19:05:42 +02:00
|
|
|
++Friends.max_idx;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
|
|
|
sort_blocklist_index();
|
|
|
|
sort_friendlist_index();
|
2014-08-07 19:05:42 +02:00
|
|
|
|
2018-10-20 08:56:37 +02:00
|
|
|
#ifdef AUDIO
|
|
|
|
init_friend_AV(i);
|
|
|
|
#endif
|
2014-07-31 18:48:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-19 04:37:14 +01:00
|
|
|
#ifdef GAMES
|
|
|
|
|
2021-01-17 19:29:13 +01:00
|
|
|
static void friendlist_onGameInvite(ToxWindow *self, Tox *m, uint32_t friend_number, const uint8_t *data, size_t length)
|
|
|
|
{
|
|
|
|
UNUSED_VAR(self);
|
|
|
|
UNUSED_VAR(data);
|
|
|
|
UNUSED_VAR(length);
|
|
|
|
|
|
|
|
if (friend_number >= Friends.max_idx) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Friends.list[friend_number].chatwin != -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
|
|
|
Friends.list[friend_number].chatwin = add_window(m, new_chat(m, Friends.list[friend_number].num));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
|
|
|
get_nick_truncate(m, nick, friend_number);
|
|
|
|
|
|
|
|
line_info_add(prompt, false, NULL, NULL, SYS_MSG, 0, RED,
|
|
|
|
"* Game invite from %s failed: Too many windows are open.", nick);
|
|
|
|
|
|
|
|
sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
|
|
|
|
}
|
|
|
|
|
2021-01-19 04:37:14 +01:00
|
|
|
#endif // GAMES
|
|
|
|
|
2015-03-30 00:33:51 +02:00
|
|
|
static void friendlist_onFileRecv(ToxWindow *self, Tox *m, uint32_t num, uint32_t filenum,
|
2015-03-28 07:56:54 +01:00
|
|
|
uint64_t file_size, const char *filename, size_t name_length)
|
2013-10-11 06:23:39 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(self);
|
|
|
|
UNUSED_VAR(file_size);
|
|
|
|
UNUSED_VAR(filename);
|
|
|
|
UNUSED_VAR(name_length);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (num >= Friends.max_idx) {
|
2013-10-11 06:23:39 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-10-11 06:23:39 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Friends.list[num].chatwin != -1) {
|
2015-03-26 03:56:45 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-11-30 11:35:25 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
|
|
|
Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num));
|
|
|
|
return;
|
|
|
|
}
|
2013-11-30 11:35:25 +01:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
tox_file_control(m, num, filenum, TOX_FILE_CONTROL_CANCEL, NULL);
|
2015-01-01 18:50:51 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
|
|
|
get_nick_truncate(m, nick, num);
|
|
|
|
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(prompt, false, NULL, NULL, SYS_MSG, 0, RED,
|
2015-07-04 07:19:16 +02:00
|
|
|
"* File transfer from %s failed: too many windows are open.", nick);
|
2015-03-26 03:56:45 +01:00
|
|
|
|
|
|
|
sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
|
2013-10-11 06:23:39 +02:00
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static void friendlist_onConferenceInvite(ToxWindow *self, Tox *m, int32_t num, uint8_t type,
|
|
|
|
const char *conference_pub_key,
|
|
|
|
uint16_t length)
|
2013-11-10 03:43:56 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(self);
|
|
|
|
UNUSED_VAR(type);
|
2020-11-08 16:08:24 +01:00
|
|
|
UNUSED_VAR(conference_pub_key);
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(length);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (num >= Friends.max_idx) {
|
2013-11-10 03:43:56 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-11-10 03:43:56 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Friends.list[num].chatwin != -1) {
|
2015-03-26 03:56:45 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-03-26 03:56:45 +01:00
|
|
|
|
|
|
|
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
|
|
|
Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num));
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
2013-11-30 11:35:25 +01:00
|
|
|
}
|
2015-03-26 03:56:45 +01:00
|
|
|
|
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
|
|
|
get_nick_truncate(m, nick, num);
|
|
|
|
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(prompt, false, NULL, NULL, SYS_MSG, 0, RED,
|
2020-11-08 16:08:24 +01:00
|
|
|
"* Conference chat invite from %s failed: too many windows are open.", nick);
|
2015-03-26 03:56:45 +01:00
|
|
|
|
|
|
|
sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 03:30:48 +01:00
|
|
|
static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, uint32_t num, const char *data, size_t length,
|
|
|
|
const char *group_name, size_t group_name_length)
|
|
|
|
{
|
|
|
|
UNUSED_VAR(self);
|
|
|
|
UNUSED_VAR(data);
|
|
|
|
UNUSED_VAR(length);
|
|
|
|
|
|
|
|
if (num >= Friends.max_idx) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Friends.list[num].chatwin != -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
|
|
|
Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
|
|
|
get_nick_truncate(m, nick, num);
|
|
|
|
|
|
|
|
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED,
|
|
|
|
"* Group chat invite from %s failed: too many windows are open.", nick);
|
|
|
|
|
|
|
|
sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
|
|
|
|
}
|
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
/* move friendlist/blocklist cursor up and down */
|
2020-03-15 19:57:00 +01:00
|
|
|
static void select_friend(wint_t key, int *selected, int num)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (num <= 0) {
|
2014-07-31 18:48:49 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2013-08-16 19:11:09 +02:00
|
|
|
if (key == KEY_UP) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (--(*selected) < 0) {
|
2014-07-31 19:49:15 +02:00
|
|
|
*selected = num - 1;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-08-16 19:11:09 +02:00
|
|
|
} else if (key == KEY_DOWN) {
|
2014-07-31 19:49:15 +02:00
|
|
|
*selected = (*selected + 1) % num;
|
2013-11-09 08:50:32 +01:00
|
|
|
}
|
2013-08-28 11:46:09 +02:00
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
static void delete_friend(Tox *m, uint32_t f_num)
|
2013-08-28 11:46:09 +02:00
|
|
|
{
|
2021-12-22 20:53:09 +01:00
|
|
|
kill_all_file_transfers_friend(m, f_num);
|
|
|
|
kill_avatar_file_transfers_friend(m, f_num);
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_Friend_Delete err;
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
if (tox_friend_delete(m, f_num, &err) != true) {
|
2015-07-04 07:19:16 +02:00
|
|
|
fprintf(stderr, "tox_friend_delete failed with error %d\n", err);
|
2015-03-28 07:56:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
--Friends.num_friends;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Friends.list[f_num].connection_status != TOX_CONNECTION_NONE) {
|
2015-03-28 07:56:54 +01:00
|
|
|
--Friends.num_online;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
|
|
|
/* close friend's chatwindow if it's currently open */
|
2014-08-07 19:05:42 +02:00
|
|
|
if (Friends.list[f_num].chatwin >= 0) {
|
|
|
|
ToxWindow *toxwin = get_window_ptr(Friends.list[f_num].chatwin);
|
2014-08-01 03:59:53 +02:00
|
|
|
|
|
|
|
if (toxwin != NULL) {
|
2014-08-05 23:38:33 +02:00
|
|
|
kill_chat_window(toxwin, m);
|
2018-10-10 00:59:25 +02:00
|
|
|
set_active_window_index(1); /* keep friendlist focused */
|
2014-08-01 03:59:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
if (Friends.list[f_num].conference_invite.key != NULL) {
|
|
|
|
free(Friends.list[f_num].conference_invite.key);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-28 04:50:20 +02:00
|
|
|
|
2020-11-11 03:25:27 +01:00
|
|
|
clear_friendlist_index(f_num);
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2013-08-28 11:46:09 +02:00
|
|
|
int i;
|
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
for (i = Friends.max_idx; i > 0; --i) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Friends.list[i - 1].active) {
|
2013-08-28 11:46:09 +02:00
|
|
|
break;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-08-28 11:46:09 +02:00
|
|
|
}
|
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
Friends.max_idx = i;
|
|
|
|
realloc_friends(i);
|
2013-09-05 07:34:23 +02:00
|
|
|
|
2017-11-20 13:02:56 +01:00
|
|
|
#ifdef AUDIO
|
|
|
|
del_friend_AV(i);
|
|
|
|
#endif
|
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
/* make sure num_selected stays within Friends.num_friends range */
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Friends.num_friends && Friends.num_selected == Friends.num_friends) {
|
2014-08-07 19:05:42 +02:00
|
|
|
--Friends.num_selected;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-11-18 04:28:22 +01:00
|
|
|
|
2013-09-05 07:34:23 +02:00
|
|
|
store_data(m, DATA_FILE);
|
2013-08-28 11:46:09 +02:00
|
|
|
}
|
|
|
|
|
2014-03-09 05:57:21 +01:00
|
|
|
/* activates delete friend popup */
|
2020-03-15 19:57:00 +01:00
|
|
|
static void del_friend_activate(uint32_t f_num)
|
2014-03-09 05:57:21 +01:00
|
|
|
{
|
2015-03-26 03:56:45 +01:00
|
|
|
PendingDelete.popup = newwin(3, 22 + TOXIC_MAX_NAME_LENGTH, 8, 8);
|
|
|
|
PendingDelete.active = true;
|
|
|
|
PendingDelete.num = f_num;
|
2014-03-09 05:57:21 +01:00
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
static void delete_blocked_friend(uint32_t bnum);
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2014-03-09 05:57:21 +01:00
|
|
|
/* deactivates delete friend popup and deletes friend if instructed */
|
2020-03-15 19:57:00 +01:00
|
|
|
static void del_friend_deactivate(Tox *m, wint_t key)
|
2014-03-09 05:57:21 +01:00
|
|
|
{
|
2020-11-03 06:59:28 +01:00
|
|
|
if (key == L'y') {
|
2014-07-31 18:48:49 +02:00
|
|
|
if (blocklist_view == 0) {
|
2015-03-26 03:56:45 +01:00
|
|
|
delete_friend(m, PendingDelete.num);
|
2014-07-31 18:48:49 +02:00
|
|
|
sort_friendlist_index();
|
|
|
|
} else {
|
2015-03-26 03:56:45 +01:00
|
|
|
delete_blocked_friend(PendingDelete.num);
|
2014-07-31 18:48:49 +02:00
|
|
|
sort_blocklist_index();
|
|
|
|
}
|
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
delwin(PendingDelete.popup);
|
2020-11-11 03:25:27 +01:00
|
|
|
|
|
|
|
PendingDelete = (struct PendingDel) {
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2014-03-09 05:57:21 +01:00
|
|
|
clear();
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2014-07-31 19:49:15 +02:00
|
|
|
static void draw_del_popup(void)
|
2014-03-09 05:57:21 +01:00
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!PendingDelete.active) {
|
2014-03-09 05:57:21 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-09 05:57:21 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
wattron(PendingDelete.popup, A_BOLD);
|
|
|
|
box(PendingDelete.popup, ACS_VLINE, ACS_HLINE);
|
|
|
|
wattroff(PendingDelete.popup, A_BOLD);
|
2014-03-09 07:02:54 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
wmove(PendingDelete.popup, 1, 1);
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(PendingDelete.popup, "Delete contact ");
|
2015-03-26 03:56:45 +01:00
|
|
|
wattron(PendingDelete.popup, A_BOLD);
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (blocklist_view == 0) {
|
2015-03-26 03:56:45 +01:00
|
|
|
wprintw(PendingDelete.popup, "%s", Friends.list[PendingDelete.num].name);
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2015-03-26 03:56:45 +01:00
|
|
|
wprintw(PendingDelete.popup, "%s", Blocked.list[PendingDelete.num].name);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
wattroff(PendingDelete.popup, A_BOLD);
|
|
|
|
wprintw(PendingDelete.popup, "? y/n");
|
2014-03-09 07:02:54 +01:00
|
|
|
|
2017-10-29 16:50:42 +01:00
|
|
|
wnoutrefresh(PendingDelete.popup);
|
2014-03-09 05:57:21 +01:00
|
|
|
}
|
|
|
|
|
2014-07-31 19:49:15 +02:00
|
|
|
/* deletes contact from blocked list */
|
2015-03-26 03:56:45 +01:00
|
|
|
static void delete_blocked_friend(uint32_t bnum)
|
2014-07-31 19:49:15 +02:00
|
|
|
{
|
2020-11-11 03:25:27 +01:00
|
|
|
clear_blocklist_index(bnum);
|
2014-07-31 19:49:15 +02:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
for (i = Blocked.max_idx; i > 0; --i) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Blocked.list[i - 1].active) {
|
2014-07-31 19:49:15 +02:00
|
|
|
break;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 19:49:15 +02:00
|
|
|
}
|
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
--Blocked.num_blocked;
|
|
|
|
Blocked.max_idx = i;
|
2014-08-07 19:05:42 +02:00
|
|
|
realloc_blocklist(i);
|
2014-07-31 19:49:15 +02:00
|
|
|
save_blocklist(BLOCK_FILE);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Blocked.num_blocked && Blocked.num_selected == Blocked.num_blocked) {
|
2014-08-08 01:24:56 +02:00
|
|
|
--Blocked.num_selected;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 19:49:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* deletes contact from friendlist and puts in blocklist */
|
2015-03-26 03:56:45 +01:00
|
|
|
void block_friend(Tox *m, uint32_t fnum)
|
2014-07-31 18:48:49 +02:00
|
|
|
{
|
2020-11-19 20:21:45 +01:00
|
|
|
if (Friends.num_friends == 0) {
|
2014-07-31 18:48:49 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2015-01-01 18:50:51 +01:00
|
|
|
realloc_blocklist(Blocked.max_idx + 1);
|
2020-11-11 03:25:27 +01:00
|
|
|
clear_blocklist_index(Blocked.max_idx);
|
2014-08-07 19:05:42 +02:00
|
|
|
|
2021-12-22 20:53:09 +01:00
|
|
|
for (int i = 0; i <= Blocked.max_idx; ++i) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Blocked.list[i].active) {
|
2014-07-31 18:48:49 +02:00
|
|
|
continue;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
Blocked.list[i].active = true;
|
|
|
|
Blocked.list[i].num = i;
|
|
|
|
Blocked.list[i].namelength = Friends.list[fnum].namelength;
|
|
|
|
Blocked.list[i].last_on = Friends.list[fnum].last_online.last_on;
|
2015-02-01 21:09:48 +01:00
|
|
|
memcpy(Blocked.list[i].pub_key, Friends.list[fnum].pub_key, TOX_PUBLIC_KEY_SIZE);
|
2015-03-26 03:56:45 +01:00
|
|
|
memcpy(Blocked.list[i].name, Friends.list[fnum].name, Friends.list[fnum].namelength + 1);
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
++Blocked.num_blocked;
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (i == Blocked.max_idx) {
|
2014-08-08 01:24:56 +02:00
|
|
|
++Blocked.max_idx;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
|
|
|
delete_friend(m, fnum);
|
|
|
|
save_blocklist(BLOCK_FILE);
|
|
|
|
sort_blocklist_index();
|
|
|
|
sort_friendlist_index();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* removes friend from blocklist, puts back in friendlist */
|
2015-03-26 03:56:45 +01:00
|
|
|
static void unblock_friend(Tox *m, uint32_t bnum)
|
2014-07-31 18:48:49 +02:00
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Blocked.num_blocked <= 0) {
|
2014-07-31 18:48:49 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_Friend_Add err;
|
2015-03-26 03:56:45 +01:00
|
|
|
uint32_t friendnum = tox_friend_add_norequest(m, (uint8_t *) Blocked.list[bnum].pub_key, &err);
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
if (err != TOX_ERR_FRIEND_ADD_OK) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(prompt, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to unblock friend (error %d)", err);
|
2014-07-31 18:48:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-15 19:57:00 +01:00
|
|
|
friendlist_add_blocked(friendnum, bnum);
|
2014-07-31 19:49:15 +02:00
|
|
|
delete_blocked_friend(bnum);
|
2014-07-31 18:48:49 +02:00
|
|
|
sort_blocklist_index();
|
|
|
|
sort_friendlist_index();
|
|
|
|
}
|
|
|
|
|
2020-10-13 22:12:55 +02:00
|
|
|
/*
|
|
|
|
* Return true if input is recognized by handler
|
|
|
|
*/
|
|
|
|
static bool friendlist_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
2013-08-28 11:46:09 +02:00
|
|
|
{
|
2014-07-31 19:49:15 +02:00
|
|
|
|
|
|
|
if (self->help->active) {
|
|
|
|
help_onKey(self, key);
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2014-07-31 19:49:15 +02:00
|
|
|
}
|
|
|
|
|
2020-11-08 06:07:28 +01:00
|
|
|
if (key == L'h') {
|
2014-07-31 19:49:15 +02:00
|
|
|
help_init_menu(self);
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2014-07-31 19:49:15 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!blocklist_view && !Friends.num_friends && (key != KEY_RIGHT && key != KEY_LEFT)) {
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (blocklist_view && !Blocked.num_blocked && (key != KEY_RIGHT && key != KEY_LEFT)) {
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-11-18 04:28:22 +01:00
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
int f = 0;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (blocklist_view == 1 && Blocked.num_blocked) {
|
2014-08-08 01:24:56 +02:00
|
|
|
f = Blocked.index[Blocked.num_selected];
|
2018-07-18 17:33:16 +02:00
|
|
|
} else if (Friends.num_friends) {
|
2014-08-07 19:05:42 +02:00
|
|
|
f = Friends.index[Friends.num_selected];
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-11-09 08:50:32 +01:00
|
|
|
|
2014-03-09 05:57:21 +01:00
|
|
|
/* lock screen and force decision on deletion popup */
|
2015-03-26 03:56:45 +01:00
|
|
|
if (PendingDelete.active) {
|
2020-11-08 06:07:28 +01:00
|
|
|
if (key == L'y' || key == L'n') {
|
2020-03-15 19:57:00 +01:00
|
|
|
del_friend_deactivate(m, key);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-09 05:57:21 +01:00
|
|
|
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2014-03-09 05:57:21 +01:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (key == ltr) {
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
|
|
|
switch (key) {
|
2020-11-08 06:07:28 +01:00
|
|
|
case L'\r':
|
2018-07-18 17:33:16 +02:00
|
|
|
if (blocklist_view) {
|
2014-07-31 18:48:49 +02:00
|
|
|
break;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2014-03-30 22:40:13 +02:00
|
|
|
/* Jump to chat window if already open */
|
2014-08-07 19:05:42 +02:00
|
|
|
if (Friends.list[f].chatwin != -1) {
|
2018-10-10 00:59:25 +02:00
|
|
|
set_active_window_index(Friends.list[f].chatwin);
|
2014-03-30 22:40:13 +02:00
|
|
|
} else if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
2014-08-07 19:05:42 +02:00
|
|
|
Friends.list[f].chatwin = add_window(m, new_chat(m, Friends.list[f].num));
|
2018-10-10 00:59:25 +02:00
|
|
|
set_active_window_index(Friends.list[f].chatwin);
|
2014-03-30 22:40:13 +02:00
|
|
|
} else {
|
2015-07-04 07:19:16 +02:00
|
|
|
const char *msg = "* Warning: Too many windows are open.";
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(prompt, false, NULL, NULL, SYS_MSG, 0, RED, msg);
|
2015-03-26 03:56:45 +01:00
|
|
|
sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
|
2014-03-30 22:40:13 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_DC:
|
2020-03-15 19:57:00 +01:00
|
|
|
del_friend_activate(f);
|
2014-07-31 18:48:49 +02:00
|
|
|
break;
|
|
|
|
|
2020-11-08 06:07:28 +01:00
|
|
|
case L'b':
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!blocklist_view) {
|
2014-07-31 18:48:49 +02:00
|
|
|
block_friend(m, f);
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2014-07-31 18:48:49 +02:00
|
|
|
unblock_friend(m, f);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_RIGHT:
|
|
|
|
case KEY_LEFT:
|
|
|
|
blocklist_view ^= 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-07-18 17:33:16 +02:00
|
|
|
if (blocklist_view == 0) {
|
2020-03-15 19:57:00 +01:00
|
|
|
select_friend(key, &Friends.num_selected, Friends.num_friends);
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2020-03-15 19:57:00 +01:00
|
|
|
select_friend(key, &Blocked.num_selected, Blocked.num_blocked);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
break;
|
2013-11-18 04:28:22 +01:00
|
|
|
}
|
2020-10-13 22:12:55 +02:00
|
|
|
|
|
|
|
return true;
|
2013-07-30 21:47:40 +02:00
|
|
|
}
|
|
|
|
|
2014-04-25 05:25:38 +02:00
|
|
|
#define FLIST_OFST 6 /* Accounts for space at top and bottom */
|
2013-12-03 00:23:04 +01:00
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
static void blocklist_onDraw(ToxWindow *self, Tox *m, int y2, int x2)
|
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
wattron(self->window, A_BOLD);
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(self->window, " Blocked: ");
|
2014-07-31 18:48:49 +02:00
|
|
|
wattroff(self->window, A_BOLD);
|
2014-08-08 01:24:56 +02:00
|
|
|
wprintw(self->window, "%d\n\n", Blocked.num_blocked);
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if ((y2 - FLIST_OFST) <= 0) {
|
2014-07-31 18:48:49 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
uint32_t selected_num = 0;
|
2014-07-31 18:48:49 +02:00
|
|
|
|
|
|
|
/* Determine which portion of friendlist to draw based on current position */
|
2014-08-08 01:24:56 +02:00
|
|
|
int page = Blocked.num_selected / (y2 - FLIST_OFST);
|
2014-07-31 18:48:49 +02:00
|
|
|
int start = (y2 - FLIST_OFST) * page;
|
|
|
|
int end = y2 - FLIST_OFST + start;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
for (i = start; i < Blocked.num_blocked && i < end; ++i) {
|
2015-03-26 03:56:45 +01:00
|
|
|
uint32_t f = Blocked.index[i];
|
2014-07-31 18:48:49 +02:00
|
|
|
bool f_selected = false;
|
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
if (i == Blocked.num_selected) {
|
2014-07-31 18:48:49 +02:00
|
|
|
wattron(self->window, A_BOLD);
|
|
|
|
wprintw(self->window, " > ");
|
|
|
|
wattroff(self->window, A_BOLD);
|
|
|
|
selected_num = f;
|
|
|
|
f_selected = true;
|
|
|
|
} else {
|
|
|
|
wprintw(self->window, " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
wattron(self->window, COLOR_PAIR(RED));
|
|
|
|
wprintw(self->window, "x");
|
|
|
|
wattroff(self->window, COLOR_PAIR(RED));
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (f_selected) {
|
2014-07-31 18:48:49 +02:00
|
|
|
wattron(self->window, COLOR_PAIR(BLUE));
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
|
|
|
|
wattron(self->window, A_BOLD);
|
2014-08-08 01:24:56 +02:00
|
|
|
wprintw(self->window, " %s\n", Blocked.list[f].name);
|
2014-07-31 18:48:49 +02:00
|
|
|
wattroff(self->window, A_BOLD);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (f_selected) {
|
2014-07-31 18:48:49 +02:00
|
|
|
wattroff(self->window, COLOR_PAIR(BLUE));
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
wprintw(self->window, "\n");
|
|
|
|
self->x = x2;
|
|
|
|
|
2014-08-08 01:24:56 +02:00
|
|
|
if (Blocked.num_blocked) {
|
2014-07-31 18:48:49 +02:00
|
|
|
wmove(self->window, y2 - 1, 1);
|
|
|
|
|
|
|
|
wattron(self->window, A_BOLD);
|
2020-11-30 05:26:51 +01:00
|
|
|
wprintw(self->window, "Public key: ");
|
2014-07-31 18:48:49 +02:00
|
|
|
wattroff(self->window, A_BOLD);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
for (i = 0; i < TOX_PUBLIC_KEY_SIZE; ++i) {
|
2014-08-08 01:24:56 +02:00
|
|
|
wprintw(self->window, "%02X", Blocked.list[selected_num].pub_key[i] & 0xff);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
}
|
|
|
|
|
2017-10-29 16:50:42 +01:00
|
|
|
wnoutrefresh(self->window);
|
2014-07-31 19:49:15 +02:00
|
|
|
draw_del_popup();
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->help->active) {
|
2014-07-31 19:49:15 +02:00
|
|
|
help_onDraw(self);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-07-31 18:48:49 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 23:03:44 +02:00
|
|
|
static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2013-08-16 19:11:09 +02:00
|
|
|
curs_set(0);
|
|
|
|
werase(self->window);
|
2013-12-03 00:23:04 +01:00
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2013-11-15 23:03:24 +01:00
|
|
|
|
2014-07-04 09:24:29 +02:00
|
|
|
bool fix_statuses = x2 != self->x; /* true if window max x value has changed */
|
2013-08-16 19:11:09 +02:00
|
|
|
|
2013-12-15 01:29:45 +01:00
|
|
|
wattron(self->window, COLOR_PAIR(CYAN));
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(self->window, " Press the");
|
2013-12-15 01:29:45 +01:00
|
|
|
wattron(self->window, A_BOLD);
|
2014-08-14 11:02:57 +02:00
|
|
|
wprintw(self->window, " h ");
|
2013-12-15 01:29:45 +01:00
|
|
|
wattroff(self->window, A_BOLD);
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(self->window, "key for help\n\n");
|
2013-12-15 01:29:45 +01:00
|
|
|
wattroff(self->window, COLOR_PAIR(CYAN));
|
|
|
|
|
2020-11-30 05:26:51 +01:00
|
|
|
draw_window_bar(self);
|
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
if (blocklist_view == 1) {
|
|
|
|
blocklist_onDraw(self, m, y2, x2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-23 00:31:52 +02:00
|
|
|
time_t cur_time = get_unix_time();
|
2015-08-28 03:29:34 +02:00
|
|
|
struct tm cur_loc_tm = *localtime((const time_t *) &cur_time);
|
2014-07-31 18:48:49 +02:00
|
|
|
|
2013-12-15 01:29:45 +01:00
|
|
|
wattron(self->window, A_BOLD);
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(self->window, " Online: ");
|
2013-12-15 01:29:45 +01:00
|
|
|
wattroff(self->window, A_BOLD);
|
2015-08-28 03:29:34 +02:00
|
|
|
|
2020-11-01 17:15:41 +01:00
|
|
|
wprintw(self->window, "%zu/%zu \n\n", Friends.num_online, Friends.num_friends);
|
2013-08-16 19:11:09 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if ((y2 - FLIST_OFST) <= 0) {
|
2013-12-03 00:34:14 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-12-03 00:34:14 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
uint32_t selected_num = 0;
|
2014-04-25 05:25:38 +02:00
|
|
|
|
2013-12-03 00:23:04 +01:00
|
|
|
/* Determine which portion of friendlist to draw based on current position */
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2021-12-22 20:26:07 +01:00
|
|
|
const int page = Friends.num_selected / (y2 - FLIST_OFST);
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
2021-12-22 20:26:07 +01:00
|
|
|
const int start = (y2 - FLIST_OFST) * page;
|
|
|
|
const int end = y2 - FLIST_OFST + start;
|
2013-12-03 00:23:04 +01:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2021-12-22 20:26:07 +01:00
|
|
|
const size_t num_friends = Friends.num_friends;
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
2013-08-16 19:11:09 +02:00
|
|
|
int i;
|
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
for (i = start; i < num_friends && i < end; ++i) {
|
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2015-03-26 03:56:45 +01:00
|
|
|
uint32_t f = Friends.index[i];
|
2015-08-28 03:29:34 +02:00
|
|
|
bool is_active = Friends.list[f].active;
|
|
|
|
int num_selected = Friends.num_selected;
|
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
|
|
|
if (is_active) {
|
2020-11-30 18:06:13 +01:00
|
|
|
bool f_selected = false;
|
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
if (i == num_selected) {
|
2013-11-18 01:45:53 +01:00
|
|
|
wattron(self->window, A_BOLD);
|
2013-09-02 04:11:47 +02:00
|
|
|
wprintw(self->window, " > ");
|
2013-11-18 01:45:53 +01:00
|
|
|
wattroff(self->window, A_BOLD);
|
2014-04-25 05:25:38 +02:00
|
|
|
selected_num = f;
|
2013-11-18 01:45:53 +01:00
|
|
|
f_selected = true;
|
|
|
|
} else {
|
2013-09-02 04:11:47 +02:00
|
|
|
wprintw(self->window, " ");
|
2013-11-18 01:45:53 +01:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Connection connection_status = Friends.list[f].connection_status;
|
|
|
|
Tox_User_Status status = Friends.list[f].status;
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
|
|
|
if (connection_status != TOX_CONNECTION_NONE) {
|
2015-03-26 03:56:45 +01:00
|
|
|
int colour = MAGENTA;
|
2013-09-02 04:11:47 +02:00
|
|
|
|
2013-11-12 07:50:04 +01:00
|
|
|
switch (status) {
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_USER_STATUS_NONE:
|
2014-04-19 23:58:13 +02:00
|
|
|
colour = GREEN;
|
|
|
|
break;
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_USER_STATUS_AWAY:
|
2014-04-19 23:58:13 +02:00
|
|
|
colour = YELLOW;
|
|
|
|
break;
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
case TOX_USER_STATUS_BUSY:
|
2014-04-19 23:58:13 +02:00
|
|
|
colour = RED;
|
|
|
|
break;
|
2013-09-02 04:11:47 +02:00
|
|
|
}
|
|
|
|
|
2013-09-05 07:34:23 +02:00
|
|
|
wattron(self->window, COLOR_PAIR(colour) | A_BOLD);
|
2014-07-27 01:16:07 +02:00
|
|
|
wprintw(self->window, "%s ", ONLINE_CHAR);
|
2013-09-05 07:34:23 +02:00
|
|
|
wattroff(self->window, COLOR_PAIR(colour) | A_BOLD);
|
2013-11-18 01:45:53 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (f_selected) {
|
2014-03-15 09:14:46 +01:00
|
|
|
wattron(self->window, COLOR_PAIR(BLUE));
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-11-18 01:45:53 +01:00
|
|
|
|
2014-03-15 09:14:46 +01:00
|
|
|
wattron(self->window, A_BOLD);
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2014-08-07 19:05:42 +02:00
|
|
|
wprintw(self->window, "%s", Friends.list[f].name);
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2014-03-15 09:14:46 +01:00
|
|
|
wattroff(self->window, A_BOLD);
|
2013-11-18 01:45:53 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (f_selected) {
|
2014-03-15 09:14:46 +01:00
|
|
|
wattroff(self->window, COLOR_PAIR(BLUE));
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-10 10:04:13 +02:00
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
/* Reset Friends.list[f].statusmsg on window resize */
|
2013-11-15 23:03:24 +01:00
|
|
|
if (fix_statuses) {
|
2015-03-26 03:56:45 +01:00
|
|
|
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH];
|
2014-03-14 04:30:44 +01:00
|
|
|
|
2014-03-13 11:06:53 +01:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2015-03-28 07:56:54 +01:00
|
|
|
tox_friend_get_status_message(m, Friends.list[f].num, (uint8_t *) statusmsg, NULL);
|
|
|
|
size_t s_len = tox_friend_get_status_message_size(m, Friends.list[f].num, NULL);
|
2014-03-13 11:06:53 +01:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2014-03-14 04:30:44 +01:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
statusmsg[s_len] = '\0';
|
|
|
|
|
2014-10-07 22:18:06 +02:00
|
|
|
filter_str(statusmsg, s_len);
|
2015-08-28 03:29:34 +02:00
|
|
|
|
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2014-08-07 19:05:42 +02:00
|
|
|
snprintf(Friends.list[f].statusmsg, sizeof(Friends.list[f].statusmsg), "%s", statusmsg);
|
|
|
|
Friends.list[f].statusmsg_len = strlen(Friends.list[f].statusmsg);
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2013-09-13 08:02:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Truncate note if it doesn't fit on one line */
|
2015-03-26 03:56:45 +01:00
|
|
|
size_t maxlen = x2 - getcurx(self->window) - 2;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
|
|
|
|
2014-08-07 19:05:42 +02:00
|
|
|
if (Friends.list[f].statusmsg_len > maxlen) {
|
|
|
|
Friends.list[f].statusmsg[maxlen - 3] = '\0';
|
|
|
|
strcat(Friends.list[f].statusmsg, "...");
|
|
|
|
Friends.list[f].statusmsg[maxlen] = '\0';
|
|
|
|
Friends.list[f].statusmsg_len = maxlen;
|
2013-09-10 10:04:13 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (Friends.list[f].statusmsg_len > 0) {
|
2014-08-07 19:05:42 +02:00
|
|
|
wprintw(self->window, " %s", Friends.list[f].statusmsg);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-14 22:48:52 +01:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
2014-03-14 22:48:52 +01:00
|
|
|
wprintw(self->window, "\n");
|
2013-09-02 04:11:47 +02:00
|
|
|
} else {
|
2014-07-27 01:16:07 +02:00
|
|
|
wprintw(self->window, "%s ", OFFLINE_CHAR);
|
2013-11-18 01:45:53 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (f_selected) {
|
2014-03-15 09:14:46 +01:00
|
|
|
wattron(self->window, COLOR_PAIR(BLUE));
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-11-18 01:45:53 +01:00
|
|
|
|
2014-03-15 09:14:46 +01:00
|
|
|
wattron(self->window, A_BOLD);
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2014-08-07 19:05:42 +02:00
|
|
|
wprintw(self->window, "%s", Friends.list[f].name);
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2014-03-15 09:14:46 +01:00
|
|
|
wattroff(self->window, A_BOLD);
|
2013-11-18 01:45:53 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (f_selected) {
|
2014-05-01 10:00:19 +02:00
|
|
|
wattroff(self->window, COLOR_PAIR(BLUE));
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2016-09-23 00:31:52 +02:00
|
|
|
time_t last_seen = Friends.list[f].last_online.last_on;
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2015-04-03 04:19:09 +02:00
|
|
|
|
|
|
|
if (last_seen != 0) {
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
|
|
|
|
2015-04-03 04:19:09 +02:00
|
|
|
int day_dist = (
|
2016-09-25 03:07:04 +02:00
|
|
|
cur_loc_tm.tm_yday - Friends.list[f].last_online.tm.tm_yday
|
|
|
|
+ ((cur_loc_tm.tm_year - Friends.list[f].last_online.tm.tm_year) * 365)
|
|
|
|
);
|
2015-04-03 04:19:09 +02:00
|
|
|
const char *hourmin = Friends.list[f].last_online.hour_min_str;
|
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
2015-04-03 04:19:09 +02:00
|
|
|
switch (day_dist) {
|
|
|
|
case 0:
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(self->window, " Last seen: Today %s\n", hourmin);
|
2015-04-03 04:19:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(self->window, " Last seen: Yesterday %s\n", hourmin);
|
2015-04-03 04:19:09 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(self->window, " Last seen: %d days ago\n", day_dist);
|
2015-04-03 04:19:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(self->window, " Last seen: Never\n");
|
2015-04-03 04:19:09 +02:00
|
|
|
}
|
2013-09-02 04:11:47 +02:00
|
|
|
}
|
2013-11-10 03:43:56 +01:00
|
|
|
}
|
2013-08-16 19:11:09 +02:00
|
|
|
}
|
2013-09-05 03:25:59 +02:00
|
|
|
|
2013-12-03 00:23:04 +01:00
|
|
|
self->x = x2;
|
2014-04-25 05:25:38 +02:00
|
|
|
|
2015-08-28 03:29:34 +02:00
|
|
|
if (num_friends) {
|
2014-04-25 05:25:38 +02:00
|
|
|
wmove(self->window, y2 - 1, 1);
|
|
|
|
|
|
|
|
wattron(self->window, A_BOLD);
|
2020-11-30 05:26:51 +01:00
|
|
|
wprintw(self->window, "Public key: ");
|
2014-04-25 05:25:38 +02:00
|
|
|
wattroff(self->window, A_BOLD);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
for (i = 0; i < TOX_PUBLIC_KEY_SIZE; ++i) {
|
2014-08-07 19:05:42 +02:00
|
|
|
wprintw(self->window, "%02X", Friends.list[selected_num].pub_key[i] & 0xff);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-25 05:25:38 +02:00
|
|
|
}
|
2014-07-05 20:46:16 +02:00
|
|
|
|
2017-10-29 16:50:42 +01:00
|
|
|
wnoutrefresh(self->window);
|
2014-07-31 19:49:15 +02:00
|
|
|
draw_del_popup();
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->help->active) {
|
2014-07-31 19:49:15 +02:00
|
|
|
help_onDraw(self);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-07-30 21:47:40 +02:00
|
|
|
}
|
|
|
|
|
2020-11-30 05:26:51 +01:00
|
|
|
void friendlist_onInit(ToxWindow *self, Tox *m)
|
|
|
|
{
|
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
|
|
|
int x2;
|
|
|
|
int y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
|
|
|
|
|
|
|
if (y2 <= 0 || x2 <= 0) {
|
|
|
|
exit_toxic_err("failed in friendlist_onInit", FATALERR_CURSES);
|
|
|
|
}
|
|
|
|
|
|
|
|
self->window_bar = subwin(self->window, WINDOW_BAR_HEIGHT, x2, y2 - 2, 0);
|
|
|
|
}
|
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
void disable_chatwin(uint32_t f_num)
|
2013-08-07 00:27:51 +02:00
|
|
|
{
|
2014-08-07 19:05:42 +02:00
|
|
|
Friends.list[f_num].chatwin = -1;
|
2013-08-05 07:57:29 +02:00
|
|
|
}
|
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2015-06-12 17:50:26 +02:00
|
|
|
static void friendlist_onAV(ToxWindow *self, ToxAV *av, uint32_t friend_number, int state)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(self);
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (friend_number >= Friends.max_idx) {
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
|
|
|
Tox *m = toxav_get_tox(av);
|
2015-11-05 23:46:00 +01:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if (Friends.list[friend_number].chatwin == -1) {
|
2014-03-11 01:04:53 +01:00
|
|
|
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
2016-09-25 03:07:04 +02:00
|
|
|
if (state != TOXAV_FRIEND_CALL_STATE_FINISHED) {
|
2015-06-12 17:50:26 +02:00
|
|
|
Friends.list[friend_number].chatwin = add_window(m, new_chat(m, Friends.list[friend_number].num));
|
2018-10-10 00:59:25 +02:00
|
|
|
set_active_window_index(Friends.list[friend_number].chatwin);
|
2015-01-01 18:50:51 +01:00
|
|
|
}
|
2014-03-07 03:14:04 +01:00
|
|
|
} else {
|
2014-07-07 04:15:35 +02:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
2015-06-12 17:50:26 +02:00
|
|
|
get_nick_truncate(m, nick, Friends.list[friend_number].num);
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(prompt, false, NULL, NULL, SYS_MSG, 0, 0, "Audio action from: %s!", nick);
|
2014-03-25 13:21:50 +01:00
|
|
|
|
2015-07-04 07:19:16 +02:00
|
|
|
const char *errmsg = "* Warning: Too many windows are open.";
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(prompt, false, NULL, NULL, SYS_MSG, 0, RED, errmsg);
|
2015-01-01 18:50:51 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* AUDIO */
|
2014-03-07 03:14:04 +01:00
|
|
|
|
2018-02-25 06:00:06 +01:00
|
|
|
/* Returns a friend's status */
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_User_Status get_friend_status(uint32_t friendnumber)
|
2018-02-25 06:00:06 +01:00
|
|
|
{
|
|
|
|
return Friends.list[friendnumber].status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns a friend's connection status */
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Connection get_friend_connection_status(uint32_t friendnumber)
|
2018-02-25 06:00:06 +01:00
|
|
|
{
|
|
|
|
return Friends.list[friendnumber].connection_status;
|
|
|
|
}
|
|
|
|
|
2019-11-16 07:55:47 +01:00
|
|
|
/*
|
|
|
|
* Returns true if friend associated with `public_key` is in the block list.
|
|
|
|
*
|
|
|
|
* `public_key` must be at least TOX_PUBLIC_KEY_SIZE bytes.
|
|
|
|
*/
|
|
|
|
bool friend_is_blocked(const char *public_key)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < Blocked.max_idx; ++i) {
|
|
|
|
if (!Blocked.list[i].active) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(public_key, Blocked.list[i].pub_key, TOX_PUBLIC_KEY_SIZE) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
ToxWindow *new_friendlist(void)
|
2013-08-16 19:11:09 +02:00
|
|
|
{
|
2018-10-10 00:59:25 +02:00
|
|
|
ToxWindow *ret = calloc(1, sizeof(ToxWindow));
|
|
|
|
|
|
|
|
if (ret == NULL) {
|
|
|
|
exit_toxic_err("failed in new_friendlist", FATALERR_MEMORY);
|
|
|
|
}
|
|
|
|
|
2020-11-09 23:01:22 +01:00
|
|
|
ret->type = WINDOW_TYPE_FRIEND_LIST;
|
2018-10-10 00:59:25 +02:00
|
|
|
|
2020-11-30 05:26:51 +01:00
|
|
|
ret->onInit = &friendlist_onInit;
|
2018-10-10 00:59:25 +02:00
|
|
|
ret->onKey = &friendlist_onKey;
|
|
|
|
ret->onDraw = &friendlist_onDraw;
|
|
|
|
ret->onFriendAdded = &friendlist_onFriendAdded;
|
|
|
|
ret->onMessage = &friendlist_onMessage;
|
|
|
|
ret->onConnectionChange = &friendlist_onConnectionChange;
|
|
|
|
ret->onNickChange = &friendlist_onNickChange;
|
|
|
|
ret->onStatusChange = &friendlist_onStatusChange;
|
|
|
|
ret->onStatusMessageChange = &friendlist_onStatusMessageChange;
|
|
|
|
ret->onFileRecv = &friendlist_onFileRecv;
|
2020-11-08 16:08:24 +01:00
|
|
|
ret->onConferenceInvite = &friendlist_onConferenceInvite;
|
2020-11-13 03:30:48 +01:00
|
|
|
ret->onGroupInvite = &friendlist_onGroupInvite;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2018-10-10 00:59:25 +02:00
|
|
|
ret->onInvite = &friendlist_onAV;
|
|
|
|
ret->onRinging = &friendlist_onAV;
|
|
|
|
ret->onStarting = &friendlist_onAV;
|
|
|
|
ret->onEnding = &friendlist_onAV;
|
|
|
|
ret->onError = &friendlist_onAV;
|
|
|
|
ret->onStart = &friendlist_onAV;
|
|
|
|
ret->onCancel = &friendlist_onAV;
|
|
|
|
ret->onReject = &friendlist_onAV;
|
|
|
|
ret->onEnd = &friendlist_onAV;
|
|
|
|
|
|
|
|
ret->is_call = false;
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* AUDIO */
|
2015-01-01 18:50:51 +01:00
|
|
|
|
2021-01-19 04:37:14 +01:00
|
|
|
#ifdef GAMES
|
|
|
|
ret->onGameInvite = &friendlist_onGameInvite;
|
|
|
|
#endif
|
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
ret->num = -1;
|
|
|
|
ret->active_box = -1;
|
2014-07-31 19:49:15 +02:00
|
|
|
|
|
|
|
Help *help = calloc(1, sizeof(Help));
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (help == NULL) {
|
2015-07-04 07:19:16 +02:00
|
|
|
exit_toxic_err("failed in new_friendlist", FATALERR_MEMORY);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-01-01 18:50:51 +01:00
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
ret->help = help;
|
2020-11-19 07:30:30 +01:00
|
|
|
strcpy(ret->name, "Contacts");
|
2013-08-16 19:11:09 +02:00
|
|
|
return ret;
|
2013-07-30 21:47:40 +02:00
|
|
|
}
|