2020-11-08 16:08:24 +01:00
|
|
|
/* conference.c
|
2014-02-25 08:28:24 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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-09-15 22:38:38 +02:00
|
|
|
*/
|
|
|
|
|
2014-06-24 17:35:23 +02:00
|
|
|
#ifndef _GNU_SOURCE
|
2014-07-14 20:32:38 +02:00
|
|
|
#define _GNU_SOURCE /* needed for strcasestr() and wcswidth() */
|
2014-06-24 17:35:23 +02:00
|
|
|
#endif
|
2014-06-22 03:41:38 +02:00
|
|
|
|
2013-09-15 22:38:38 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-08-02 00:37:02 +02:00
|
|
|
#include <assert.h>
|
2013-09-15 22:38:38 +02:00
|
|
|
#include <time.h>
|
2014-06-22 03:41:38 +02:00
|
|
|
#include <wchar.h>
|
2014-10-09 07:39:22 +02:00
|
|
|
#include <unistd.h>
|
2019-03-27 06:38:15 +01:00
|
|
|
#include <inttypes.h>
|
2020-05-07 02:00:00 +02:00
|
|
|
#include <math.h>
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2014-11-29 15:36:31 +01:00
|
|
|
#ifdef AUDIO
|
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <OpenAL/al.h>
|
|
|
|
#include <OpenAL/alc.h>
|
|
|
|
#else
|
|
|
|
#include <AL/al.h>
|
|
|
|
#include <AL/alc.h>
|
|
|
|
/* compatibility with older versions of OpenAL */
|
|
|
|
#ifndef ALC_ALL_DEVICES_SPECIFIER
|
|
|
|
#include <AL/alext.h>
|
2018-10-08 19:39:04 +02:00
|
|
|
#endif /* ALC_ALL_DEVICES_SPECIFIER */
|
|
|
|
#endif /* __APPLE__ */
|
|
|
|
#endif /* AUDIO */
|
2014-11-29 15:36:31 +01:00
|
|
|
|
2014-06-12 00:06:55 +02:00
|
|
|
#include "windows.h"
|
|
|
|
#include "toxic.h"
|
2013-11-10 03:43:56 +01:00
|
|
|
#include "execute.h"
|
2013-09-21 02:35:03 +02:00
|
|
|
#include "misc_tools.h"
|
2020-11-08 16:08:24 +01:00
|
|
|
#include "conference.h"
|
2013-12-09 23:56:20 +01:00
|
|
|
#include "prompt.h"
|
2013-12-11 06:10:09 +01:00
|
|
|
#include "toxic_strings.h"
|
2014-03-01 13:10:44 +01:00
|
|
|
#include "log.h"
|
2014-03-25 13:21:50 +01:00
|
|
|
#include "line_info.h"
|
2014-04-07 10:42:10 +02:00
|
|
|
#include "settings.h"
|
2014-06-26 08:33:09 +02:00
|
|
|
#include "input.h"
|
2014-07-04 09:24:29 +02:00
|
|
|
#include "help.h"
|
2014-07-21 01:12:13 +02:00
|
|
|
#include "notify.h"
|
2014-07-18 07:29:46 +02:00
|
|
|
#include "autocomplete.h"
|
2015-05-25 23:59:06 +02:00
|
|
|
#include "audio_device.h"
|
2013-09-15 22:38:38 +02:00
|
|
|
|
|
|
|
extern char *DATA_FILE;
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static ConferenceChat conferences[MAX_CONFERENCE_NUM];
|
|
|
|
static int max_conference_index = 0;
|
2013-11-30 00:52:21 +01:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
extern struct user_settings *user_settings;
|
2014-10-09 07:39:22 +02:00
|
|
|
extern struct Winthread Winthread;
|
2014-04-07 10:42:10 +02:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
/* Array of conference command names used for tab completion. */
|
|
|
|
static const char *conference_cmd_list[] = {
|
2020-10-30 01:28:09 +01:00
|
|
|
"/accept",
|
|
|
|
"/add",
|
2020-05-07 02:00:00 +02:00
|
|
|
#ifdef AUDIO
|
|
|
|
"/audio",
|
|
|
|
#endif
|
2020-10-30 01:28:09 +01:00
|
|
|
"/avatar",
|
|
|
|
"/clear",
|
|
|
|
"/close",
|
|
|
|
"/connect",
|
|
|
|
"/decline",
|
|
|
|
"/exit",
|
2020-11-08 16:08:24 +01:00
|
|
|
"/conference",
|
2020-10-30 01:28:09 +01:00
|
|
|
"/help",
|
|
|
|
"/log",
|
2020-05-07 02:00:00 +02:00
|
|
|
#ifdef AUDIO
|
|
|
|
"/mute",
|
|
|
|
#endif
|
2020-10-30 01:28:09 +01:00
|
|
|
"/myid",
|
2018-06-16 05:07:16 +02:00
|
|
|
#ifdef QRCODE
|
2020-10-30 01:28:09 +01:00
|
|
|
"/myqr",
|
2018-06-16 05:07:16 +02:00
|
|
|
#endif /* QRCODE */
|
2020-10-30 01:28:09 +01:00
|
|
|
"/nick",
|
|
|
|
"/note",
|
|
|
|
"/nospam",
|
|
|
|
"/quit",
|
|
|
|
"/requests",
|
2020-05-07 02:00:00 +02:00
|
|
|
#ifdef AUDIO
|
|
|
|
"/sense",
|
|
|
|
#endif
|
2020-10-30 01:28:09 +01:00
|
|
|
"/status",
|
|
|
|
"/title",
|
2017-05-23 02:47:56 +02:00
|
|
|
|
|
|
|
#ifdef PYTHON
|
|
|
|
|
2020-10-30 01:28:09 +01:00
|
|
|
"/run",
|
2017-05-23 02:47:56 +02:00
|
|
|
|
|
|
|
#endif /* PYTHON */
|
2014-11-15 02:13:08 +01:00
|
|
|
};
|
2013-12-09 00:14:57 +01:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static ToxWindow *new_conference_chat(uint32_t conferencenum);
|
2020-03-15 19:57:00 +01:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static void kill_conference_window(ToxWindow *self)
|
2018-10-09 20:21:33 +02:00
|
|
|
{
|
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
|
|
|
|
log_disable(ctx->log);
|
|
|
|
line_info_cleanup(ctx->hst);
|
|
|
|
delwin(ctx->linewin);
|
|
|
|
delwin(ctx->history);
|
|
|
|
delwin(ctx->sidebar);
|
|
|
|
free(ctx->log);
|
|
|
|
free(ctx);
|
|
|
|
free(self->help);
|
2020-11-10 23:20:40 +01:00
|
|
|
kill_notifs(self->active_box);
|
2018-10-09 20:21:33 +02:00
|
|
|
del_window(self);
|
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
int init_conference_win(Tox *m, uint32_t conferencenum, uint8_t type, const char *title,
|
|
|
|
size_t title_length)
|
2013-09-15 22:38:38 +02:00
|
|
|
{
|
2020-11-08 16:08:24 +01:00
|
|
|
if (conferencenum > MAX_CONFERENCE_NUM) {
|
2014-06-18 18:10:00 +02:00
|
|
|
return -1;
|
2016-12-18 06:01:51 +01:00
|
|
|
}
|
2014-06-18 18:10:00 +02:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
ToxWindow *self = new_conference_chat(conferencenum);
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
for (int i = 0; i <= max_conference_index; ++i) {
|
|
|
|
if (!conferences[i].active) {
|
2020-05-07 02:00:00 +02:00
|
|
|
// FIXME: it is assumed at various points in the code that
|
|
|
|
// toxcore's conferencenums agree with toxic's indices to conferences;
|
|
|
|
// probably it so happens that this will (at least typically) be
|
|
|
|
// the case, because toxic and tox maintain the indices in
|
|
|
|
// parallel ways. But it isn't guaranteed by the API.
|
2020-11-08 16:08:24 +01:00
|
|
|
conferences[i].chatwin = add_window(m, self);
|
|
|
|
conferences[i].active = true;
|
|
|
|
conferences[i].num_peers = 0;
|
|
|
|
conferences[i].type = type;
|
|
|
|
conferences[i].start_time = get_unix_time();
|
2020-05-07 02:00:00 +02:00
|
|
|
conferences[i].audio_enabled = false;
|
|
|
|
conferences[i].last_sent_audio = 0;
|
2014-09-24 04:51:56 +02:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
set_active_window_index(conferences[i].chatwin);
|
2019-06-30 20:51:13 +02:00
|
|
|
set_window_title(self, title, title_length);
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
if (i == max_conference_index) {
|
|
|
|
++max_conference_index;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-11-17 22:09:14 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
return conferences[i].chatwin;
|
2013-09-15 22:38:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
kill_conference_window(self);
|
2014-02-26 11:23:11 +01:00
|
|
|
|
2018-10-09 20:21:33 +02:00
|
|
|
return -1;
|
2014-02-26 11:23:11 +01:00
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
static void free_peer(ConferencePeer *peer)
|
|
|
|
{
|
|
|
|
#ifdef AUDIO
|
|
|
|
|
|
|
|
if (peer->sending_audio) {
|
|
|
|
close_device(output, peer->audio_out_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
void free_conference(ToxWindow *self, uint32_t conferencenum)
|
2014-02-26 11:23:11 +01:00
|
|
|
{
|
2020-05-07 02:00:00 +02:00
|
|
|
ConferenceChat *chat = &conferences[conferencenum];
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < chat->num_peers; ++i) {
|
|
|
|
ConferencePeer *peer = &chat->peer_list[i];
|
|
|
|
|
|
|
|
if (peer->active) {
|
|
|
|
free_peer(peer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef AUDIO
|
|
|
|
|
|
|
|
if (chat->audio_enabled) {
|
|
|
|
close_device(input, chat->audio_in_idx);
|
|
|
|
}
|
2020-11-11 03:25:27 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
free(chat->name_list);
|
|
|
|
free(chat->peer_list);
|
2020-11-11 03:25:27 +01:00
|
|
|
conferences[conferencenum] = (ConferenceChat) {
|
|
|
|
0
|
|
|
|
};
|
2013-09-15 22:38:38 +02:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
for (i = max_conference_index; i > 0; --i) {
|
|
|
|
if (conferences[i - 1].active) {
|
2013-09-15 22:38:38 +02:00
|
|
|
break;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-15 22:38:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
max_conference_index = i;
|
|
|
|
kill_conference_window(self);
|
2013-09-15 22:38:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static void delete_conference(ToxWindow *self, Tox *m, uint32_t conferencenum)
|
2018-02-25 06:00:06 +01:00
|
|
|
{
|
2020-11-08 16:08:24 +01:00
|
|
|
tox_conference_delete(m, conferencenum, NULL);
|
|
|
|
free_conference(self, conferencenum);
|
2018-02-25 06:00:06 +01:00
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
/* destroys and re-creates conference window with or without the peerlist */
|
|
|
|
void redraw_conference_win(ToxWindow *self)
|
2014-10-08 08:45:08 +02:00
|
|
|
{
|
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
|
|
|
|
endwin();
|
|
|
|
refresh();
|
|
|
|
clear();
|
|
|
|
|
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(stdscr, y2, x2);
|
|
|
|
y2 -= 2;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (y2 <= 0 || x2 <= 0) {
|
2015-11-08 09:57:01 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-11-08 09:57:01 +01:00
|
|
|
|
2014-10-08 08:45:08 +02:00
|
|
|
if (ctx->sidebar) {
|
|
|
|
delwin(ctx->sidebar);
|
|
|
|
ctx->sidebar = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
delwin(ctx->linewin);
|
|
|
|
delwin(ctx->history);
|
|
|
|
delwin(self->window);
|
|
|
|
|
|
|
|
self->window = newwin(y2, x2, 0, 0);
|
|
|
|
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);
|
|
|
|
|
|
|
|
if (self->show_peerlist) {
|
|
|
|
ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2 - SIDEBAR_WIDTH - 1, 0, 0);
|
|
|
|
ctx->sidebar = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, SIDEBAR_WIDTH, 0, x2 - SIDEBAR_WIDTH);
|
|
|
|
} else {
|
|
|
|
ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
scrollok(ctx->history, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static void conference_onConferenceMessage(ToxWindow *self, Tox *m, uint32_t conferencenum, uint32_t peernum,
|
|
|
|
Tox_Message_Type type, const char *msg, size_t len)
|
2013-09-15 22:38:38 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(len);
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
if (self->num != conferencenum) {
|
2013-09-15 22:38:38 +02:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
2020-11-08 16:08:24 +01:00
|
|
|
get_conference_nick_truncate(m, nick, peernum, conferencenum);
|
2014-02-10 04:55:42 +01:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char selfnick[TOX_MAX_NAME_LENGTH];
|
2015-03-26 03:56:45 +01:00
|
|
|
tox_self_get_name(m, (uint8_t *) selfnick);
|
|
|
|
|
|
|
|
size_t sn_len = tox_self_get_name_size(m);
|
2014-04-01 09:53:12 +02:00
|
|
|
selfnick[sn_len] = '\0';
|
2014-04-01 04:00:17 +02:00
|
|
|
|
2014-02-17 05:15:27 +01:00
|
|
|
int nick_clr = strcmp(nick, selfnick) == 0 ? GREEN : CYAN;
|
2013-12-07 01:41:53 +01:00
|
|
|
|
2014-10-04 03:08:33 +02:00
|
|
|
/* Only play sound if mentioned by someone else */
|
|
|
|
if (strcasestr(msg, selfnick) && strcmp(selfnick, nick)) {
|
2016-07-21 11:25:40 +02:00
|
|
|
sound_notify(self, generic_message, NT_WNDALERT_0 | user_settings->bell_on_message, NULL);
|
2015-03-26 03:56:45 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->active_box != -1) {
|
2014-10-03 23:53:50 +02:00
|
|
|
box_silent_notify2(self, NT_NOFOCUS, self->active_box, "%s %s", nick, msg);
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2014-10-03 23:53:50 +02:00
|
|
|
box_silent_notify(self, NT_NOFOCUS, &self->active_box, self->name, "%s %s", nick, msg);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-08-02 00:37:02 +02:00
|
|
|
|
2013-12-08 11:45:23 +01:00
|
|
|
nick_clr = RED;
|
2016-09-25 03:07:04 +02:00
|
|
|
} else {
|
2014-10-03 05:22:37 +02:00
|
|
|
sound_notify(self, silent, NT_WNDALERT_1, NULL);
|
|
|
|
}
|
2013-12-07 01:41:53 +01:00
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
char timefrmt[TIME_STR_SIZE];
|
2014-06-24 00:54:23 +02:00
|
|
|
get_time_str(timefrmt, sizeof(timefrmt));
|
2014-02-26 09:51:26 +01:00
|
|
|
|
2016-12-18 06:01:51 +01:00
|
|
|
line_info_add(self, timefrmt, nick, NULL, type == TOX_MESSAGE_TYPE_NORMAL ? IN_MSG : IN_ACTION, 0, nick_clr, "%s", msg);
|
2014-10-03 23:53:50 +02:00
|
|
|
write_to_log(msg, nick, ctx->log, false);
|
2013-09-15 22:38:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static void conference_onConferenceTitleChange(ToxWindow *self, Tox *m, uint32_t conferencenum, uint32_t peernum,
|
2017-06-01 22:46:12 +02:00
|
|
|
const char *title,
|
2016-12-18 06:01:51 +01:00
|
|
|
size_t length)
|
2014-11-15 04:15:59 +01:00
|
|
|
{
|
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
if (self->num != conferencenum) {
|
2014-11-15 04:15:59 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-11-15 04:15:59 +01:00
|
|
|
|
|
|
|
set_window_title(self, title, length);
|
|
|
|
|
|
|
|
char timefrmt[TIME_STR_SIZE];
|
|
|
|
get_time_str(timefrmt, sizeof(timefrmt));
|
|
|
|
|
2014-11-16 04:39:24 +01:00
|
|
|
/* don't announce title when we join the room */
|
2020-11-08 16:08:24 +01:00
|
|
|
if (!timed_out(conferences[self->num].start_time, CONFERENCE_EVENT_WAIT)) {
|
2014-11-15 04:15:59 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-11-15 04:15:59 +01:00
|
|
|
|
|
|
|
char nick[TOX_MAX_NAME_LENGTH];
|
2020-11-08 16:08:24 +01:00
|
|
|
get_conference_nick_truncate(m, nick, peernum, conferencenum);
|
|
|
|
line_info_add(self, timefrmt, nick, NULL, NAME_CHANGE, 0, 0, " set the conference title to: %s", title);
|
2014-11-15 04:15:59 +01:00
|
|
|
|
|
|
|
char tmp_event[MAX_STR_SIZE];
|
2015-07-04 07:19:16 +02:00
|
|
|
snprintf(tmp_event, sizeof(tmp_event), "set title to %s", title);
|
2014-11-15 04:15:59 +01:00
|
|
|
write_to_log(tmp_event, nick, ctx->log, true);
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
/* Puts `(NameListEntry *)`s in `entries` for each matched peer, up to a
|
|
|
|
* maximum of `maxpeers`.
|
|
|
|
* Maches each peer whose name or pubkey begins with `prefix`.
|
|
|
|
* If `prefix` is exactly the pubkey of a peer, matches only that peer.
|
|
|
|
* return number of entries placed in `entries`.
|
|
|
|
*/
|
|
|
|
uint32_t get_name_list_entries_by_prefix(uint32_t conferencenum, const char *prefix, NameListEntry **entries,
|
|
|
|
uint32_t maxpeers)
|
|
|
|
{
|
|
|
|
ConferenceChat *chat = &conferences[conferencenum];
|
|
|
|
|
|
|
|
if (!chat->active) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
const size_t len = strlen(prefix);
|
2020-05-07 02:00:00 +02:00
|
|
|
|
|
|
|
if (len == 2 * TOX_PUBLIC_KEY_SIZE) {
|
|
|
|
for (uint32_t i = 0; i < chat->num_peers; ++i) {
|
2020-05-07 02:00:00 +02:00
|
|
|
NameListEntry *entry = &chat->name_list[i];
|
|
|
|
|
|
|
|
if (strcasecmp(prefix, entry->pubkey_str) == 0) {
|
|
|
|
entries[0] = entry;
|
2020-05-07 02:00:00 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t n = 0;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < chat->num_peers; ++i) {
|
2020-05-07 02:00:00 +02:00
|
|
|
NameListEntry *entry = &chat->name_list[i];
|
|
|
|
|
|
|
|
if (strncmp(prefix, entry->name, len) == 0
|
|
|
|
|| strncasecmp(prefix, entry->pubkey_str, len) == 0) {
|
|
|
|
entries[n] = entry;
|
2020-05-07 02:00:00 +02:00
|
|
|
++n;
|
|
|
|
|
|
|
|
if (n == maxpeers) {
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int compare_name_list_entries(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const int cmp1 = qsort_strcasecmp_hlpr(
|
|
|
|
((const NameListEntry *)a)->name,
|
|
|
|
((const NameListEntry *)b)->name);
|
|
|
|
|
|
|
|
if (cmp1 == 0) {
|
|
|
|
return qsort_strcasecmp_hlpr(
|
|
|
|
((const NameListEntry *)a)->pubkey_str,
|
|
|
|
((const NameListEntry *)b)->pubkey_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmp1;
|
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static void conference_update_name_list(uint32_t conferencenum)
|
2013-11-27 02:45:08 +01:00
|
|
|
{
|
2020-11-08 16:08:24 +01:00
|
|
|
ConferenceChat *chat = &conferences[conferencenum];
|
2018-02-25 06:00:06 +01:00
|
|
|
|
2020-02-29 20:14:56 +01:00
|
|
|
if (!chat->active) {
|
2018-02-25 06:00:06 +01:00
|
|
|
return;
|
2013-11-27 02:45:08 +01:00
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
if (chat->name_list) {
|
|
|
|
free(chat->name_list);
|
2018-02-25 06:00:06 +01:00
|
|
|
}
|
2016-12-18 06:01:51 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
chat->name_list = malloc(chat->num_peers * sizeof(NameListEntry));
|
2016-12-18 06:01:51 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
if (chat->name_list == NULL) {
|
|
|
|
exit_toxic_err("failed in conference_update_name_list", FATALERR_MEMORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t count = 0;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < chat->max_idx; ++i) {
|
2020-05-07 02:00:00 +02:00
|
|
|
const ConferencePeer *peer = &chat->peer_list[i];
|
|
|
|
NameListEntry *entry = &chat->name_list[count];
|
|
|
|
|
|
|
|
if (peer->active) {
|
|
|
|
memcpy(entry->name, peer->name, peer->name_length + 1);
|
|
|
|
bin_pubkey_to_string(peer->pubkey, sizeof(peer->pubkey),
|
|
|
|
entry->pubkey_str, sizeof(entry->pubkey_str));
|
|
|
|
entry->peernum = i;
|
2018-02-25 06:00:06 +01:00
|
|
|
++count;
|
2015-03-26 03:56:45 +01:00
|
|
|
}
|
2013-11-27 02:45:08 +01:00
|
|
|
}
|
2013-11-28 01:29:58 +01:00
|
|
|
|
2020-10-30 01:28:09 +01:00
|
|
|
if (count != chat->num_peers) {
|
|
|
|
fprintf(stderr, "WARNING: count != chat->num_peers\n");
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
qsort(chat->name_list, count, sizeof(NameListEntry), compare_name_list_entries);
|
2013-11-27 02:45:08 +01:00
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
/* Reallocates conferencenum's peer list.
|
2018-02-25 06:00:06 +01:00
|
|
|
*
|
|
|
|
* Returns 0 on success.
|
|
|
|
* Returns -1 on failure.
|
|
|
|
*/
|
2020-11-08 16:08:24 +01:00
|
|
|
static int realloc_peer_list(ConferenceChat *chat, uint32_t num_peers)
|
2014-10-09 07:39:22 +02:00
|
|
|
{
|
2018-02-25 06:00:06 +01:00
|
|
|
if (!chat) {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-10-09 07:39:22 +02:00
|
|
|
|
2018-02-25 06:00:06 +01:00
|
|
|
if (num_peers == 0) {
|
|
|
|
free(chat->peer_list);
|
|
|
|
chat->peer_list = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
2014-10-09 07:39:22 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
ConferencePeer *tmp_list = realloc(chat->peer_list, num_peers * sizeof(ConferencePeer));
|
2014-10-09 07:39:22 +02:00
|
|
|
|
2018-02-25 06:00:06 +01:00
|
|
|
if (!tmp_list) {
|
|
|
|
return -1;
|
2014-10-09 07:39:22 +02:00
|
|
|
}
|
|
|
|
|
2018-02-25 06:00:06 +01:00
|
|
|
chat->peer_list = tmp_list;
|
2014-10-09 07:39:22 +02:00
|
|
|
|
2018-02-25 06:00:06 +01:00
|
|
|
return 0;
|
2014-10-09 07:39:22 +02:00
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
/* return NULL if peer or conference doesn't exist */
|
|
|
|
static ConferencePeer *peer_in_conference(uint32_t conferencenum, uint32_t peernum)
|
|
|
|
{
|
|
|
|
if (conferencenum >= MAX_CONFERENCE_NUM) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConferenceChat *chat = &conferences[conferencenum];
|
|
|
|
|
|
|
|
if (!chat->active || peernum > chat->max_idx) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConferencePeer *peer = &chat->peer_list[peernum];
|
|
|
|
|
|
|
|
if (!peer->active) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return peer;
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
#ifdef AUDIO
|
|
|
|
static void set_peer_audio_position(Tox *m, uint32_t conferencenum, uint32_t peernum)
|
|
|
|
{
|
|
|
|
ConferenceChat *chat = &conferences[conferencenum];
|
|
|
|
ConferencePeer *peer = &chat->peer_list[peernum];
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
if (peer == NULL || !peer->sending_audio) {
|
2020-05-07 02:00:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Position peers at distance 1 in front of listener,
|
|
|
|
// ordered left to right by order in peerlist excluding self.
|
|
|
|
uint32_t num_posns = chat->num_peers;
|
|
|
|
uint32_t peer_posn = peernum;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < chat->num_peers; ++i) {
|
|
|
|
if (tox_conference_peer_number_is_ours(m, conferencenum, peernum, NULL)) {
|
|
|
|
if (i == peernum) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
--num_posns;
|
|
|
|
|
|
|
|
if (i < peernum) {
|
|
|
|
--peer_posn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const float angle = asinf(peer_posn - (float)(num_posns - 1) / 2);
|
|
|
|
set_source_position(peer->audio_out_idx, sinf(angle), cosf(angle), 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
static bool find_peer_by_pubkey(const ConferencePeer *list, uint32_t num_peers, uint8_t *pubkey, uint32_t *idx)
|
2020-05-07 02:00:00 +02:00
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < num_peers; ++i) {
|
2020-05-07 02:00:00 +02:00
|
|
|
const ConferencePeer *peer = &list[i];
|
2020-05-07 02:00:00 +02:00
|
|
|
|
|
|
|
if (peer->active && memcmp(peer->pubkey, pubkey, TOX_PUBLIC_KEY_SIZE) == 0) {
|
|
|
|
*idx = i;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_peer_list(Tox *m, uint32_t conferencenum, uint32_t num_peers, uint32_t old_num_peers)
|
2013-11-24 03:19:59 +01:00
|
|
|
{
|
2020-11-08 16:08:24 +01:00
|
|
|
ConferenceChat *chat = &conferences[conferencenum];
|
2013-11-24 03:19:59 +01:00
|
|
|
|
2020-02-29 20:14:56 +01:00
|
|
|
if (!chat->active) {
|
2014-06-18 18:10:00 +02:00
|
|
|
return;
|
2016-12-18 06:01:51 +01:00
|
|
|
}
|
2013-11-26 00:49:31 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
ConferencePeer *old_peer_list = malloc(old_num_peers * sizeof(ConferencePeer));
|
|
|
|
|
|
|
|
if (!old_peer_list) {
|
|
|
|
exit_toxic_err("failed in update_peer_list", FATALERR_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chat->peer_list != NULL) {
|
|
|
|
memcpy(old_peer_list, chat->peer_list, old_num_peers * sizeof(ConferencePeer));
|
|
|
|
}
|
|
|
|
|
2018-02-25 06:00:06 +01:00
|
|
|
realloc_peer_list(chat, num_peers);
|
2020-05-07 02:00:00 +02:00
|
|
|
memset(chat->peer_list, 0, num_peers * sizeof(ConferencePeer));
|
2014-06-18 18:10:00 +02:00
|
|
|
|
2020-10-30 01:28:09 +01:00
|
|
|
for (uint32_t i = 0; i < num_peers; ++i) {
|
2020-11-08 16:08:24 +01:00
|
|
|
ConferencePeer *peer = &chat->peer_list[i];
|
2013-11-26 00:49:31 +01:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_Conference_Peer_Query err;
|
2020-05-07 02:00:00 +02:00
|
|
|
tox_conference_peer_get_public_key(m, conferencenum, i, peer->pubkey, &err);
|
|
|
|
|
|
|
|
if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t j;
|
|
|
|
|
|
|
|
if (find_peer_by_pubkey(old_peer_list, old_num_peers, peer->pubkey, &j)) {
|
|
|
|
ConferencePeer *old_peer = &old_peer_list[j];
|
|
|
|
memcpy(peer, old_peer, sizeof(ConferencePeer));
|
|
|
|
old_peer->active = false;
|
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
size_t length = tox_conference_peer_get_name_size(m, conferencenum, i, &err);
|
2014-02-26 12:35:19 +01:00
|
|
|
|
2018-02-25 06:00:06 +01:00
|
|
|
if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK || length >= TOX_MAX_NAME_LENGTH) {
|
2020-05-07 02:00:00 +02:00
|
|
|
// FIXME: length == TOX_MAX_NAME_LENGTH should not be an error!
|
2018-02-25 06:00:06 +01:00
|
|
|
continue;
|
|
|
|
}
|
2014-10-09 22:39:01 +02:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
tox_conference_peer_get_name(m, conferencenum, i, (uint8_t *) peer->name, &err);
|
2018-02-25 06:00:06 +01:00
|
|
|
peer->name[length] = 0;
|
2014-10-09 22:39:01 +02:00
|
|
|
|
2018-02-25 06:00:06 +01:00
|
|
|
if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2018-02-25 06:00:06 +01:00
|
|
|
peer->active = true;
|
|
|
|
peer->name_length = length;
|
2020-05-07 02:00:00 +02:00
|
|
|
peer->peernum = i;
|
2020-05-07 02:00:00 +02:00
|
|
|
|
|
|
|
#ifdef AUDIO
|
|
|
|
set_peer_audio_position(m, conferencenum, i);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < old_num_peers; ++i) {
|
|
|
|
ConferencePeer *old_peer = &old_peer_list[i];
|
|
|
|
|
|
|
|
if (old_peer->active) {
|
|
|
|
free_peer(old_peer);
|
|
|
|
}
|
2018-02-25 06:00:06 +01:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
free(old_peer_list);
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
conference_update_name_list(conferencenum);
|
2018-02-25 06:00:06 +01:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static void conference_onConferenceNameListChange(ToxWindow *self, Tox *m, uint32_t conferencenum)
|
2018-02-25 06:00:06 +01:00
|
|
|
{
|
2020-11-08 16:08:24 +01:00
|
|
|
if (self->num != conferencenum) {
|
2018-02-25 06:00:06 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
if (conferencenum > max_conference_index) {
|
2018-02-25 06:00:06 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-10-09 07:39:22 +02:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
ConferenceChat *chat = &conferences[conferencenum];
|
2020-02-29 20:14:56 +01:00
|
|
|
|
|
|
|
if (!chat->active) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_Conference_Peer_Query err;
|
2014-10-09 07:39:22 +02:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
uint32_t num_peers = tox_conference_peer_count(m, conferencenum, &err);
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2020-10-30 01:28:09 +01:00
|
|
|
if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
|
2020-11-08 16:08:24 +01:00
|
|
|
fprintf(stderr, "conference_onConferenceNameListChange() failed with error: %d\n", err);
|
2020-10-30 01:28:09 +01:00
|
|
|
return;
|
2013-11-26 00:49:31 +01:00
|
|
|
}
|
2013-11-29 01:45:28 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
const uint32_t old_num = chat->num_peers;
|
2020-10-30 01:28:09 +01:00
|
|
|
|
|
|
|
chat->num_peers = num_peers;
|
2018-02-25 06:00:06 +01:00
|
|
|
chat->max_idx = num_peers;
|
2020-05-07 02:00:00 +02:00
|
|
|
update_peer_list(m, conferencenum, num_peers, old_num);
|
2018-02-25 06:00:06 +01:00
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static void conference_onConferencePeerNameChange(ToxWindow *self, Tox *m, uint32_t conferencenum, uint32_t peernum,
|
2018-03-04 05:54:12 +01:00
|
|
|
const char *name, size_t length)
|
2018-02-25 06:00:06 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(length);
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
if (self->num != conferencenum) {
|
2018-02-25 09:43:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
const ConferencePeer *peer = peer_in_conference(conferencenum, peernum);
|
2018-02-25 09:43:19 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
if (peer != NULL && peer->name_length > 0) {
|
|
|
|
ChatContext *ctx = self->chatwin;
|
|
|
|
char timefrmt[TIME_STR_SIZE];
|
|
|
|
get_time_str(timefrmt, sizeof(timefrmt));
|
2018-02-25 09:43:19 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
char tmp_event[TOXIC_MAX_NAME_LENGTH * 2 + 32];
|
|
|
|
snprintf(tmp_event, sizeof(tmp_event), "is now known as %s", (const char *) name);
|
2018-02-25 09:43:19 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
write_to_log(tmp_event, peer->name, ctx->log, true);
|
|
|
|
line_info_add(self, timefrmt, peer->name, (const char *) name, NAME_CHANGE, 0, 0, " is now known as ");
|
2018-02-25 09:43:19 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
conference_onConferenceNameListChange(self, m, conferencenum);
|
2013-11-24 03:19:59 +01:00
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static void send_conference_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *action)
|
2014-04-19 23:58:13 +02:00
|
|
|
{
|
2013-12-14 02:57:32 +01:00
|
|
|
if (action == NULL) {
|
2015-07-04 07:19:16 +02:00
|
|
|
wprintw(ctx->history, "Invalid syntax.\n");
|
2013-12-14 02:57:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_Conference_Send_Message err;
|
2016-12-18 06:01:51 +01:00
|
|
|
|
|
|
|
if (!tox_conference_send_message(m, self->num, TOX_MESSAGE_TYPE_ACTION, (uint8_t *) action, strlen(action), &err)) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send action (error %d)", err);
|
2013-12-14 02:57:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
/* Offset for the peer number box at the top of the statusbar */
|
|
|
|
static int sidebar_offset(uint32_t conferencenum)
|
|
|
|
{
|
|
|
|
return 2 + conferences[conferencenum].audio_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-13 22:12:55 +02:00
|
|
|
/*
|
|
|
|
* Return true if input is recognized by handler
|
|
|
|
*/
|
2020-11-08 16:08:24 +01:00
|
|
|
static bool conference_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
2013-09-15 22:38:38 +02:00
|
|
|
{
|
2013-11-29 23:48:08 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2013-09-15 22:38:38 +02:00
|
|
|
|
|
|
|
int x, y, y2, x2;
|
|
|
|
getyx(self->window, y, x);
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2014-06-21 07:26:33 +02:00
|
|
|
|
2020-03-30 18:56:42 +02:00
|
|
|
UNUSED_VAR(y);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (x2 <= 0 || y2 <= 0) {
|
2020-10-13 22:12:55 +02:00
|
|
|
return false;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-06-21 07:26:33 +02:00
|
|
|
|
2014-07-04 09:24:29 +02:00
|
|
|
if (self->help->active) {
|
|
|
|
help_onKey(self, key);
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2014-07-04 09:24:29 +02:00
|
|
|
}
|
|
|
|
|
2020-11-08 06:07:28 +01:00
|
|
|
if (ctx->pastemode && key == L'\r') {
|
|
|
|
key = L'\n';
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2016-01-17 15:10:46 +01:00
|
|
|
|
2020-11-08 06:07:28 +01:00
|
|
|
if (ltr || key == L'\n') { /* char is printable */
|
2020-03-15 19:57:00 +01:00
|
|
|
input_new_char(self, key, x, x2);
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2014-06-26 08:33:09 +02:00
|
|
|
}
|
2013-12-01 22:59:46 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (line_info_onKey(self, key)) {
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-30 22:40:13 +02:00
|
|
|
|
2020-03-15 19:57:00 +01:00
|
|
|
if (input_handle(self, key, x, x2)) {
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-12-06 04:55:14 +01:00
|
|
|
|
2020-10-13 22:12:55 +02:00
|
|
|
bool input_ret = false;
|
2020-05-07 02:00:00 +02:00
|
|
|
ConferenceChat *chat = &conferences[self->num];
|
2020-10-13 22:12:55 +02:00
|
|
|
|
2020-11-08 06:07:28 +01:00
|
|
|
if (key == L'\t') { /* TAB key: auto-completes peer name or command */
|
2020-10-13 22:12:55 +02:00
|
|
|
input_ret = true;
|
|
|
|
|
2014-06-26 08:33:09 +02:00
|
|
|
if (ctx->len > 0) {
|
2020-05-07 02:00:00 +02:00
|
|
|
int diff = -1;
|
2013-12-06 04:55:14 +01:00
|
|
|
|
2014-09-26 09:10:44 +02:00
|
|
|
/* TODO: make this not suck */
|
|
|
|
if (ctx->line[0] != L'/' || wcscmp(ctx->line, L"/me") == 0) {
|
2020-05-07 02:00:00 +02:00
|
|
|
const char **complete_strs = calloc(chat->num_peers, sizeof(const char *));
|
2020-05-07 02:00:00 +02:00
|
|
|
|
|
|
|
if (complete_strs) {
|
2020-05-07 02:00:00 +02:00
|
|
|
for (uint32_t i = 0; i < chat->num_peers; ++i) {
|
|
|
|
complete_strs[i] = (const char *) chat->name_list[i].name;
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
diff = complete_line(self, complete_strs, chat->num_peers);
|
2020-05-07 02:00:00 +02:00
|
|
|
free(complete_strs);
|
|
|
|
}
|
2018-10-08 06:47:51 +02:00
|
|
|
} else if (wcsncmp(ctx->line, L"/avatar ", wcslen(L"/avatar ")) == 0) {
|
2014-09-26 09:10:44 +02:00
|
|
|
diff = dir_match(self, m, ctx->line, L"/avatar");
|
2017-05-23 02:47:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef PYTHON
|
2018-10-09 04:28:36 +02:00
|
|
|
else if (wcsncmp(ctx->line, L"/run ", wcslen(L"/run ")) == 0) {
|
2017-05-23 02:47:56 +02:00
|
|
|
diff = dir_match(self, m, ctx->line, L"/run");
|
|
|
|
}
|
2017-06-01 22:46:12 +02:00
|
|
|
|
2017-05-23 02:47:56 +02:00
|
|
|
#endif
|
2020-05-07 02:00:00 +02:00
|
|
|
else if (wcsncmp(ctx->line, L"/mute ", wcslen(L"/mute ")) == 0) {
|
2020-05-07 02:00:00 +02:00
|
|
|
const char **complete_strs = calloc(chat->num_peers, sizeof(const char *));
|
2020-05-07 02:00:00 +02:00
|
|
|
|
|
|
|
if (complete_strs) {
|
2020-05-07 02:00:00 +02:00
|
|
|
for (uint32_t i = 0; i < chat->num_peers; ++i) {
|
|
|
|
complete_strs[i] = (const char *) chat->name_list[i].name;
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
diff = complete_line(self, complete_strs, chat->num_peers);
|
2020-05-07 02:00:00 +02:00
|
|
|
|
|
|
|
if (diff == -1) {
|
2020-05-07 02:00:00 +02:00
|
|
|
for (uint32_t i = 0; i < chat->num_peers; ++i) {
|
|
|
|
complete_strs[i] = (const char *) chat->name_list[i].pubkey_str;
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
2020-05-07 02:00:00 +02:00
|
|
|
diff = complete_line(self, complete_strs, chat->num_peers);
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
free(complete_strs);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2020-11-08 16:08:24 +01:00
|
|
|
diff = complete_line(self, conference_cmd_list, sizeof(conference_cmd_list) / sizeof(char *));
|
2014-09-26 09:10:44 +02:00
|
|
|
}
|
2013-12-01 22:59:46 +01:00
|
|
|
|
2014-06-26 08:33:09 +02:00
|
|
|
if (diff != -1) {
|
|
|
|
if (x + diff > x2 - 1) {
|
2015-08-27 09:38:08 +02:00
|
|
|
int wlen = MAX(0, wcswidth(ctx->line, sizeof(ctx->line) / sizeof(wchar_t)));
|
2014-07-18 18:42:53 +02:00
|
|
|
ctx->start = wlen < x2 ? 0 : wlen - x2 + 1;
|
2014-06-21 05:08:13 +02:00
|
|
|
}
|
2014-07-01 05:56:47 +02:00
|
|
|
} else {
|
2015-03-26 03:56:45 +01:00
|
|
|
sound_notify(self, notif_error, 0, NULL);
|
2014-07-01 05:56:47 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-03-26 03:56:45 +01:00
|
|
|
sound_notify(self, notif_error, 0, NULL);
|
2014-07-01 05:56:47 +02:00
|
|
|
}
|
2020-10-14 01:52:43 +02:00
|
|
|
} else if (key == T_KEY_C_DOWN) { /* Scroll peerlist up and down one position */
|
2020-10-13 22:12:55 +02:00
|
|
|
input_ret = true;
|
2020-05-07 02:00:00 +02:00
|
|
|
const int L = y2 - CHATBOX_HEIGHT - sidebar_offset(self->num);
|
2014-06-26 08:33:09 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
if (chat->side_pos < (int64_t) chat->num_peers - L) {
|
|
|
|
++chat->side_pos;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2020-10-14 01:52:43 +02:00
|
|
|
} else if (key == T_KEY_C_UP) {
|
2020-10-13 22:12:55 +02:00
|
|
|
input_ret = true;
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
if (chat->side_pos > 0) {
|
|
|
|
--chat->side_pos;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2020-11-08 06:07:28 +01:00
|
|
|
} else if (key == L'\r') {
|
2020-10-13 22:12:55 +02:00
|
|
|
input_ret = true;
|
2014-06-26 08:33:09 +02:00
|
|
|
rm_trailing_spaces_buf(ctx);
|
2013-12-03 09:44:02 +01:00
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
if (!wstring_is_empty(ctx->line)) {
|
2015-12-04 20:15:31 +01:00
|
|
|
add_line_to_hist(ctx);
|
2013-12-11 06:10:09 +01:00
|
|
|
|
2015-12-04 20:15:31 +01:00
|
|
|
wstrsubst(ctx->line, L'¶', L'\n');
|
2013-12-19 02:18:02 +01:00
|
|
|
|
2015-12-04 20:15:31 +01:00
|
|
|
char line[MAX_STR_SIZE];
|
2014-03-30 22:40:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1) {
|
2020-11-11 03:25:27 +01:00
|
|
|
memset(line, 0, sizeof(line));
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-12-04 20:15:31 +01:00
|
|
|
|
|
|
|
if (line[0] == '/') {
|
|
|
|
if (strcmp(line, "/close") == 0) {
|
2020-11-08 16:08:24 +01:00
|
|
|
delete_conference(self, m, self->num);
|
2020-10-13 22:12:55 +02:00
|
|
|
return true;
|
2015-12-04 20:15:31 +01:00
|
|
|
} else if (strncmp(line, "/me ", strlen("/me ")) == 0) {
|
2020-11-08 16:08:24 +01:00
|
|
|
send_conference_action(self, ctx, m, line + strlen("/me "));
|
2015-12-04 20:15:31 +01:00
|
|
|
} else {
|
2020-11-08 16:08:24 +01:00
|
|
|
execute(ctx->history, self, m, line, CONFERENCE_COMMAND_MODE);
|
2015-12-04 20:15:31 +01:00
|
|
|
}
|
2013-12-16 02:52:10 +01:00
|
|
|
} else {
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_Err_Conference_Send_Message err;
|
2016-12-18 06:01:51 +01:00
|
|
|
|
|
|
|
if (!tox_conference_send_message(m, self->num, TOX_MESSAGE_TYPE_NORMAL, (uint8_t *) line, strlen(line), &err)) {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send message (error %d)", err);
|
2015-12-04 20:15:31 +01:00
|
|
|
}
|
2013-09-15 22:38:38 +02:00
|
|
|
}
|
2014-03-30 22:40:13 +02:00
|
|
|
}
|
2014-06-26 08:33:09 +02:00
|
|
|
|
|
|
|
wclear(ctx->linewin);
|
|
|
|
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
|
|
|
reset_buf(ctx);
|
2013-09-15 22:38:38 +02:00
|
|
|
}
|
2020-10-13 22:12:55 +02:00
|
|
|
|
|
|
|
return input_ret;
|
2013-09-15 22:38:38 +02:00
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
static void draw_peer(ToxWindow *self, Tox *m, ChatContext *ctx, uint32_t i)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
|
|
|
const uint32_t peer_idx = i + conferences[self->num].side_pos;
|
|
|
|
const uint32_t peernum = conferences[self->num].name_list[peer_idx].peernum;
|
|
|
|
const bool is_self = tox_conference_peer_number_is_ours(m, self->num, peernum, NULL);
|
|
|
|
const bool audio = conferences[self->num].audio_enabled;
|
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
|
|
|
/* truncate nick to fit in side panel without modifying list */
|
|
|
|
char tmpnick[TOX_MAX_NAME_LENGTH];
|
|
|
|
int maxlen = SIDEBAR_WIDTH - 2 - 2 * audio;
|
|
|
|
|
|
|
|
if (audio) {
|
|
|
|
#ifdef AUDIO
|
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2020-05-07 02:00:00 +02:00
|
|
|
const ConferencePeer *peer = peer_in_conference(self->num, peernum);
|
2020-05-07 02:00:00 +02:00
|
|
|
const bool audio_active = is_self
|
|
|
|
? !timed_out(conferences[self->num].last_sent_audio, 2)
|
2020-05-07 02:00:00 +02:00
|
|
|
: peer != NULL && peer->sending_audio && !timed_out(peer->last_audio_time, 2);
|
2020-05-07 02:00:00 +02:00
|
|
|
const bool mute = audio_active &&
|
|
|
|
(is_self
|
|
|
|
? device_is_muted(input, conferences[self->num].audio_in_idx)
|
2020-05-07 02:00:00 +02:00
|
|
|
: peer != NULL && device_is_muted(output, peer->audio_out_idx));
|
2020-05-07 02:00:00 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
|
|
|
const int aud_attr = A_BOLD | COLOR_PAIR(audio_active && !mute ? GREEN : RED);
|
|
|
|
wattron(ctx->sidebar, aud_attr);
|
|
|
|
waddch(ctx->sidebar, audio_active ? (mute ? 'M' : '*') : '-');
|
|
|
|
wattroff(ctx->sidebar, aud_attr);
|
|
|
|
waddch(ctx->sidebar, ' ');
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
|
|
|
memcpy(tmpnick, &conferences[self->num].name_list[peer_idx].name, maxlen);
|
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
|
|
|
tmpnick[maxlen] = '\0';
|
|
|
|
|
|
|
|
if (is_self) {
|
|
|
|
wattron(ctx->sidebar, COLOR_PAIR(GREEN));
|
|
|
|
}
|
|
|
|
|
|
|
|
wprintw(ctx->sidebar, "%s\n", tmpnick);
|
|
|
|
|
|
|
|
if (is_self) {
|
|
|
|
wattroff(ctx->sidebar, COLOR_PAIR(GREEN));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static void conference_onDraw(ToxWindow *self, Tox *m)
|
2013-09-15 22:38:38 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
2013-12-03 09:44:02 +01:00
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2013-11-24 03:19:59 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (x2 <= 0 || y2 <= 0) {
|
2015-11-08 09:57:01 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-11-08 09:57:01 +01:00
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2013-12-01 04:12:43 +01:00
|
|
|
|
2015-07-01 04:40:45 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2014-03-25 13:21:50 +01:00
|
|
|
line_info_print(self);
|
2015-07-01 04:40:45 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
|
|
|
|
2014-03-27 10:08:48 +01:00
|
|
|
wclear(ctx->linewin);
|
2013-12-08 10:16:49 +01:00
|
|
|
|
2014-06-13 07:42:20 +02:00
|
|
|
curs_set(1);
|
2013-12-08 10:16:49 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ctx->len > 0) {
|
2014-06-26 08:33:09 +02:00
|
|
|
mvwprintw(ctx->linewin, 1, 0, "%ls", &ctx->line[ctx->start]);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-12-01 04:12:43 +01:00
|
|
|
|
2013-12-03 09:44:02 +01:00
|
|
|
wclear(ctx->sidebar);
|
2014-07-01 05:56:47 +02:00
|
|
|
mvwhline(self->window, y2 - CHATBOX_HEIGHT, 0, ACS_HLINE, x2);
|
2013-11-24 03:19:59 +01:00
|
|
|
|
2014-10-08 08:45:08 +02:00
|
|
|
if (self->show_peerlist) {
|
|
|
|
mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y2 - CHATBOX_HEIGHT);
|
|
|
|
mvwaddch(ctx->sidebar, y2 - CHATBOX_HEIGHT, 0, ACS_BTEE);
|
2013-11-29 07:30:10 +01:00
|
|
|
|
2016-09-23 00:00:14 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2020-05-07 02:00:00 +02:00
|
|
|
const uint32_t num_peers = conferences[self->num].num_peers;
|
|
|
|
const bool audio = conferences[self->num].audio_enabled;
|
|
|
|
const int header_lines = sidebar_offset(self->num);
|
2016-09-23 00:00:14 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2013-11-29 07:30:10 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
int line = 0;
|
2016-09-23 00:00:14 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
if (audio) {
|
|
|
|
#ifdef AUDIO
|
2016-09-23 00:00:14 +02:00
|
|
|
pthread_mutex_lock(&Winthread.lock);
|
2020-05-07 02:00:00 +02:00
|
|
|
const bool mic_on = !device_is_muted(input, conferences[self->num].audio_in_idx);
|
2020-05-07 02:00:00 +02:00
|
|
|
const float volume = get_input_volume();
|
|
|
|
const float threshold = device_get_VAD_threshold(conferences[self->num].audio_in_idx);
|
2016-09-23 00:00:14 +02:00
|
|
|
pthread_mutex_unlock(&Winthread.lock);
|
2014-01-31 04:01:08 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
wmove(ctx->sidebar, line, 1);
|
|
|
|
wattron(ctx->sidebar, A_BOLD);
|
|
|
|
wprintw(ctx->sidebar, "Mic: ");
|
2020-05-07 02:00:00 +02:00
|
|
|
const int color = mic_on && volume > threshold ? GREEN : RED;
|
2020-05-07 02:00:00 +02:00
|
|
|
wattron(ctx->sidebar, COLOR_PAIR(color));
|
2020-05-07 02:00:00 +02:00
|
|
|
|
|
|
|
if (mic_on) {
|
|
|
|
float v = volume;
|
|
|
|
|
|
|
|
while (v > 0.0f) {
|
|
|
|
wprintw(ctx->sidebar, v > 10.0f ? (v > 15.0f ? "*" : "+") : (v > 5.0f ? "-" : "."));
|
|
|
|
v -= 20.0f;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
wprintw(ctx->sidebar, "OFF");
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
wattroff(ctx->sidebar, COLOR_PAIR(color));
|
|
|
|
wattroff(ctx->sidebar, A_BOLD);
|
|
|
|
++line;
|
|
|
|
#endif
|
|
|
|
}
|
2016-09-23 00:00:14 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
wmove(ctx->sidebar, line, 1);
|
|
|
|
wattron(ctx->sidebar, A_BOLD);
|
|
|
|
wprintw(ctx->sidebar, "Peers: %"PRIu32"\n", num_peers);
|
|
|
|
wattroff(ctx->sidebar, A_BOLD);
|
|
|
|
++line;
|
2016-09-23 00:00:14 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
mvwaddch(ctx->sidebar, line, 0, ACS_LTEE);
|
|
|
|
mvwhline(ctx->sidebar, line, 1, ACS_HLINE, SIDEBAR_WIDTH - 1);
|
|
|
|
++line;
|
2014-01-31 04:01:08 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
for (uint32_t i = 0;
|
|
|
|
i < num_peers && i < y2 - header_lines - CHATBOX_HEIGHT;
|
|
|
|
++i) {
|
2020-05-07 02:00:00 +02:00
|
|
|
wmove(ctx->sidebar, i + header_lines, 1);
|
|
|
|
draw_peer(self, m, ctx, i);
|
2014-10-08 08:45:08 +02:00
|
|
|
}
|
2013-11-24 03:19:59 +01:00
|
|
|
}
|
2014-07-01 05:56:47 +02:00
|
|
|
|
|
|
|
int y, x;
|
|
|
|
getyx(self->window, y, x);
|
2020-03-30 18:56:42 +02:00
|
|
|
|
|
|
|
UNUSED_VAR(x);
|
|
|
|
|
2015-08-27 09:38:08 +02:00
|
|
|
int new_x = ctx->start ? x2 - 1 : MAX(0, wcswidth(ctx->line, ctx->pos));
|
2014-07-01 05:56:47 +02:00
|
|
|
wmove(self->window, y + 1, new_x);
|
2014-07-04 09:24:29 +02:00
|
|
|
|
2017-10-29 16:50:42 +01:00
|
|
|
wnoutrefresh(self->window);
|
2014-07-05 20:46:16 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->help->active) {
|
2014-07-04 09:24:29 +02:00
|
|
|
help_onDraw(self);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-15 22:38:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static void conference_onInit(ToxWindow *self, Tox *m)
|
2013-09-15 22:38:38 +02:00
|
|
|
{
|
2014-07-01 05:56:47 +02:00
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2013-11-24 03:19:59 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (x2 <= 0 || y2 <= 0) {
|
2020-11-08 16:08:24 +01:00
|
|
|
exit_toxic_err("failed in conference_onInit", FATALERR_CURSES);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-11-08 09:57:01 +01:00
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
ChatContext *ctx = self->chatwin;
|
2014-03-25 13:21:50 +01:00
|
|
|
|
2014-07-01 05:56:47 +02:00
|
|
|
ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2 - SIDEBAR_WIDTH - 1, 0, 0);
|
|
|
|
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);
|
|
|
|
ctx->sidebar = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, SIDEBAR_WIDTH, 0, x2 - SIDEBAR_WIDTH);
|
2013-11-24 03:19:59 +01:00
|
|
|
|
2014-07-04 19:24:18 +02:00
|
|
|
ctx->hst = calloc(1, sizeof(struct history));
|
|
|
|
ctx->log = calloc(1, sizeof(struct chatlog));
|
2014-03-01 13:10:44 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (ctx->log == NULL || ctx->hst == NULL) {
|
2020-11-08 16:08:24 +01:00
|
|
|
exit_toxic_err("failed in conference_onInit", FATALERR_MEMORY);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-01 13:10:44 +01:00
|
|
|
|
2014-03-25 13:21:50 +01:00
|
|
|
line_info_init(ctx->hst);
|
2014-04-07 10:42:10 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
if (user_settings->autolog == AUTOLOG_ON) {
|
2015-03-26 03:56:45 +01:00
|
|
|
char myid[TOX_ADDRESS_SIZE];
|
|
|
|
tox_self_get_address(m, (uint8_t *) myid);
|
2015-08-19 06:42:28 +02:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
if (log_enable(self->name, myid, NULL, ctx->log, LOG_CONFERENCE) == -1) {
|
2015-08-19 06:42:28 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Warning: Log failed to initialize.");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-09-22 23:09:39 +02:00
|
|
|
}
|
2014-04-07 10:42:10 +02:00
|
|
|
|
2014-02-27 01:00:13 +01:00
|
|
|
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);
|
2014-02-26 09:51:26 +01:00
|
|
|
|
2014-07-01 05:56:47 +02:00
|
|
|
scrollok(ctx->history, 0);
|
|
|
|
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
2013-09-15 22:38:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
static ToxWindow *new_conference_chat(uint32_t conferencenum)
|
2013-09-15 22:38:38 +02:00
|
|
|
{
|
2018-10-10 00:59:25 +02:00
|
|
|
ToxWindow *ret = calloc(1, sizeof(ToxWindow));
|
|
|
|
|
|
|
|
if (ret == NULL) {
|
2020-11-08 16:08:24 +01:00
|
|
|
exit_toxic_err("failed in new_conference_chat", FATALERR_MEMORY);
|
2018-10-10 00:59:25 +02:00
|
|
|
}
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2020-11-09 23:01:22 +01:00
|
|
|
ret->type = WINDOW_TYPE_CONFERENCE;
|
2013-11-30 11:35:25 +01:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
ret->onKey = &conference_onKey;
|
|
|
|
ret->onDraw = &conference_onDraw;
|
|
|
|
ret->onInit = &conference_onInit;
|
|
|
|
ret->onConferenceMessage = &conference_onConferenceMessage;
|
|
|
|
ret->onConferenceNameListChange = &conference_onConferenceNameListChange;
|
|
|
|
ret->onConferencePeerNameChange = &conference_onConferencePeerNameChange;
|
|
|
|
ret->onConferenceTitleChange = &conference_onConferenceTitleChange;
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
snprintf(ret->name, sizeof(ret->name), "Conference %u", conferencenum);
|
2013-09-15 22:38:38 +02:00
|
|
|
|
|
|
|
ChatContext *chatwin = calloc(1, sizeof(ChatContext));
|
2014-07-04 09:24:29 +02:00
|
|
|
Help *help = calloc(1, sizeof(Help));
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (chatwin == NULL || help == NULL) {
|
2020-11-08 16:08:24 +01:00
|
|
|
exit_toxic_err("failed in new_conference_chat", FATALERR_MEMORY);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
ret->chatwin = chatwin;
|
|
|
|
ret->help = help;
|
2014-07-04 09:24:29 +02:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
ret->num = conferencenum;
|
2018-10-10 00:59:25 +02:00
|
|
|
ret->show_peerlist = true;
|
|
|
|
ret->active_box = -1;
|
2013-09-15 22:38:38 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2020-05-07 02:00:00 +02:00
|
|
|
|
|
|
|
#ifdef AUDIO
|
|
|
|
|
|
|
|
#define CONFAV_SAMPLE_RATE 48000
|
|
|
|
#define CONFAV_FRAME_DURATION 20
|
|
|
|
#define CONFAV_AUDIO_CHANNELS 1
|
|
|
|
#define CONFAV_SAMPLES_PER_FRAME (CONFAV_SAMPLE_RATE * CONFAV_FRAME_DURATION / 1000)
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
void audio_conference_callback(void *tox, uint32_t conferencenum, uint32_t peernum, const int16_t *pcm,
|
2020-05-07 02:00:00 +02:00
|
|
|
unsigned int samples, uint8_t channels, uint32_t sample_rate, void *userdata)
|
|
|
|
{
|
2020-05-07 02:00:00 +02:00
|
|
|
ConferencePeer *peer = peer_in_conference(conferencenum, peernum);
|
2020-05-07 02:00:00 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
if (peer == NULL) {
|
2020-05-07 02:00:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
if (!peer->sending_audio) {
|
|
|
|
if (open_output_device(&peer->audio_out_idx,
|
|
|
|
sample_rate, CONFAV_FRAME_DURATION, channels) != de_None) {
|
|
|
|
// TODO: error message?
|
|
|
|
return;
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
peer->sending_audio = true;
|
2020-05-07 02:00:00 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
set_peer_audio_position(tox, conferencenum, peernum);
|
|
|
|
}
|
2020-05-07 02:00:00 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
write_out(peer->audio_out_idx, pcm, samples, channels, sample_rate);
|
2020-05-07 02:00:00 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
peer->last_audio_time = get_unix_time();
|
2020-05-07 02:00:00 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
return;
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void conference_read_device_callback(const int16_t *captured, uint32_t size, void *data)
|
|
|
|
{
|
|
|
|
UNUSED_VAR(size);
|
|
|
|
|
|
|
|
AudioInputCallbackData *audio_input_callback_data = (AudioInputCallbackData *)data;
|
|
|
|
|
|
|
|
conferences[audio_input_callback_data->conferencenum].last_sent_audio = get_unix_time();
|
|
|
|
|
|
|
|
toxav_group_send_audio(audio_input_callback_data->tox,
|
|
|
|
audio_input_callback_data->conferencenum,
|
|
|
|
captured, CONFAV_SAMPLES_PER_FRAME,
|
|
|
|
CONFAV_AUDIO_CHANNELS, CONFAV_SAMPLE_RATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool init_conference_audio_input(Tox *tox, uint32_t conferencenum)
|
|
|
|
{
|
|
|
|
ConferenceChat *chat = &conferences[conferencenum];
|
|
|
|
|
|
|
|
if (!chat->active || chat->audio_enabled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const AudioInputCallbackData audio_input_callback_data = { tox, conferencenum };
|
|
|
|
chat->audio_input_callback_data = audio_input_callback_data;
|
|
|
|
|
|
|
|
bool success = (open_input_device(&chat->audio_in_idx,
|
|
|
|
conference_read_device_callback, &chat->audio_input_callback_data, true,
|
|
|
|
CONFAV_SAMPLE_RATE, CONFAV_FRAME_DURATION, CONFAV_AUDIO_CHANNELS)
|
|
|
|
== de_None);
|
|
|
|
|
|
|
|
chat->audio_enabled = success;
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool enable_conference_audio(Tox *tox, uint32_t conferencenum)
|
|
|
|
{
|
|
|
|
if (!toxav_groupchat_av_enabled(tox, conferencenum)) {
|
|
|
|
if (toxav_groupchat_enable_av(tox, conferencenum, audio_conference_callback, NULL) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return init_conference_audio_input(tox, conferencenum);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool disable_conference_audio(Tox *tox, uint32_t conferencenum)
|
|
|
|
{
|
|
|
|
ConferenceChat *chat = &conferences[conferencenum];
|
|
|
|
|
|
|
|
if (!chat->active) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chat->audio_enabled) {
|
|
|
|
close_device(input, chat->audio_in_idx);
|
|
|
|
chat->audio_enabled = false;
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
return toxav_groupchat_disable_av(tox, conferencenum) == 0;
|
2020-05-07 02:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool conference_mute_self(uint32_t conferencenum)
|
|
|
|
{
|
2020-05-07 02:00:00 +02:00
|
|
|
const ConferenceChat *chat = &conferences[conferencenum];
|
2020-05-07 02:00:00 +02:00
|
|
|
|
|
|
|
if (!chat->active || !chat->audio_enabled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_mute(input, chat->audio_in_idx);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool conference_mute_peer(const Tox *m, uint32_t conferencenum, uint32_t peernum)
|
|
|
|
{
|
|
|
|
if (tox_conference_peer_number_is_ours(m, conferencenum, peernum, NULL)) {
|
|
|
|
return conference_mute_self(conferencenum);
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
const ConferenceChat *chat = &conferences[conferencenum];
|
2020-05-07 02:00:00 +02:00
|
|
|
|
|
|
|
if (!chat->active || !chat->audio_enabled
|
|
|
|
|| peernum > chat->max_idx) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
const ConferencePeer *peer = peer_in_conference(conferencenum, peernum);
|
2020-05-07 02:00:00 +02:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
if (peer == NULL || !peer->sending_audio) {
|
2020-05-07 02:00:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_mute(output, peer->audio_out_idx);
|
|
|
|
return true;
|
|
|
|
}
|
2020-05-07 02:00:00 +02:00
|
|
|
|
|
|
|
bool conference_set_VAD_threshold(uint32_t conferencenum, float threshold)
|
|
|
|
{
|
|
|
|
const ConferenceChat *chat = &conferences[conferencenum];
|
|
|
|
|
|
|
|
if (!chat->active || !chat->audio_enabled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (device_set_VAD_threshold(chat->audio_in_idx, threshold) == de_None);
|
|
|
|
}
|
|
|
|
|
|
|
|
float conference_get_VAD_threshold(uint32_t conferencenum)
|
|
|
|
{
|
|
|
|
const ConferenceChat *chat = &conferences[conferencenum];
|
|
|
|
|
|
|
|
if (!chat->active || !chat->audio_enabled) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return device_get_VAD_threshold(chat->audio_in_idx);
|
|
|
|
}
|
2020-05-07 02:00:00 +02:00
|
|
|
#endif
|