Skip to content

Commit

Permalink
feat: add command to get the conference unique ID
Browse files Browse the repository at this point in the history
  • Loading branch information
JFreegman committed Jan 23, 2024
1 parent b81831b commit 011aac8
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/conference.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define _GNU_SOURCE /* needed for strcasestr() and wcswidth() */
#endif

#include <assert.h>
#include <inttypes.h>
#include <math.h>
#include <stdlib.h>
Expand Down Expand Up @@ -70,6 +71,8 @@ static int max_conference_index = 0;

extern struct Winthread Winthread;

static_assert(TOX_CONFERENCE_ID_SIZE == TOX_PUBLIC_KEY_SIZE, "TOX_CONFERENCE_ID_SIZE != TOX_PUBLIC_KEY_SIZE");

/* Array of conference command names used for tab completion. */
static const char *conference_cmd_list[] = {
"/accept",
Expand All @@ -78,6 +81,7 @@ static const char *conference_cmd_list[] = {
"/audio",
#endif
"/avatar",
"/chatid",
"/clear",
"/close",
"/color",
Expand Down
28 changes: 28 additions & 0 deletions src/conference_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@ static void print_err(ToxWindow *self, const Client_Config *c_config, const char
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%s", error_str);
}

void cmd_conference_chatid(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*argv)[MAX_STR_SIZE])
{
UNUSED_VAR(window);

if (toxic == NULL || self == NULL) {
return;
}

const Client_Config *c_config = toxic->c_config;

char id_string[TOX_GROUP_CHAT_ID_SIZE * 2 + 1] = {0};
char id[TOX_CONFERENCE_ID_SIZE];

if (!tox_conference_get_id(toxic->tox, self->num, (uint8_t *) id)) {
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve the Chat ID.");
return;
}

char tmp[3];

for (size_t i = 0; i < TOX_CONFERENCE_ID_SIZE; ++i) {
snprintf(tmp, sizeof(tmp), "%02X", id[i] & 0xff);
strcat(id_string, tmp);
}

line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%s", id_string);
}

void cmd_conference_set_title(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*argv)[MAX_STR_SIZE])
{
UNUSED_VAR(window);
Expand Down
1 change: 1 addition & 0 deletions src/conference_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "toxic.h"
#include "windows.h"

void cmd_conference_chatid(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_conference_set_title(WINDOW *, ToxWindow *, Toxic *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_enable_audio(WINDOW *, ToxWindow *, Toxic *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_conference_mute(WINDOW *, ToxWindow *, Toxic *, int argc, char (*argv)[MAX_STR_SIZE]);
Expand Down
1 change: 1 addition & 0 deletions src/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ static struct cmd_func chat_commands[] = {
};

static struct cmd_func conference_commands[] = {
{ "/chatid", cmd_conference_chatid },
{ "/title", cmd_conference_set_title },

#ifdef AUDIO
Expand Down
18 changes: 9 additions & 9 deletions src/groupchat_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ void cmd_chatid(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*

const Client_Config *c_config = toxic->c_config;

char chatid[TOX_GROUP_CHAT_ID_SIZE * 2 + 1] = {0};
char chat_public_key[TOX_GROUP_CHAT_ID_SIZE];
char id_string[TOX_GROUP_CHAT_ID_SIZE * 2 + 1] = {0};
char chat_id[TOX_GROUP_CHAT_ID_SIZE];

Tox_Err_Group_State_Queries err;

if (!tox_group_get_chat_id(toxic->tox, self->num, (uint8_t *) chat_public_key, &err)) {
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve the Chat ID (error %d).",
err);
if (!tox_group_get_chat_id(toxic->tox, self->num, (uint8_t *) chat_id, &err)) {
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve the Chat ID (error %d).", err);
return;
}

char tmp[3];

for (size_t i = 0; i < TOX_GROUP_CHAT_ID_SIZE; ++i) {
char xx[3];
snprintf(xx, sizeof(xx), "%02X", chat_public_key[i] & 0xff);
strcat(chatid, xx);
snprintf(tmp, sizeof(tmp), "%02X", chat_id[i] & 0xff);
strcat(id_string, tmp);
}

line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%s", chatid);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%s", id_string);
}

void cmd_disconnect(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*argv)[MAX_STR_SIZE])
Expand Down
1 change: 1 addition & 0 deletions src/groupchats.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define _GNU_SOURCE /* needed for strcasestr() and wcswidth() */
#endif

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
Expand Down
2 changes: 0 additions & 2 deletions src/groupchats.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#ifndef GROUPCHATS_H
#define GROUPCHATS_H

#include <assert.h>

#include "toxic.h"
#include "windows.h"

Expand Down
3 changes: 2 additions & 1 deletion src/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ static void help_draw_conference(ToxWindow *self)
wprintw(win, "Conference commands:\n");
wattroff(win, A_BOLD | COLOR_PAIR(RED));

wprintw(win, " /chatid : Print this conference's ID\n");
wprintw(win, " /title <msg> : Show/set conference title\n");
#ifdef AUDIO
wattron(win, A_BOLD);
Expand Down Expand Up @@ -467,7 +468,7 @@ void help_onKey(ToxWindow *self, wint_t key)
break;

case L'o':
height = 6;
height = 7;
#ifdef AUDIO
height += 7;
#endif
Expand Down

0 comments on commit 011aac8

Please sign in to comment.