mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
basic group titles
This commit is contained in:
parent
3b10a248dc
commit
4a9661f08b
|
@ -513,6 +513,29 @@ static int setnick(Group_Chats *g_c, int groupnumber, int peer_index, const uint
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int settitle(Group_Chats *g_c, int groupnumber, int peer_index, const uint8_t *title, uint16_t title_len)
|
||||||
|
{
|
||||||
|
if (title_len > MAX_NAME_LENGTH || title_len == 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
Group_c *g = get_group_c(g_c, groupnumber);
|
||||||
|
|
||||||
|
if (!g)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* same as already set? */
|
||||||
|
if (g->title_len == title_len && !memcmp(g->title, title, title_len))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
memcpy(g->title, title, title_len);
|
||||||
|
g->title_len = title_len;
|
||||||
|
|
||||||
|
if (g_c->title_callback)
|
||||||
|
g_c->title_callback(g_c->m, groupnumber, peer_index, title, title_len, g_c->title_callback_userdata);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int remove_close_conn(Group_Chats *g_c, int groupnumber, int friendcon_id)
|
static int remove_close_conn(Group_Chats *g_c, int groupnumber, int friendcon_id)
|
||||||
{
|
{
|
||||||
Group_c *g = get_group_c(g_c, groupnumber);
|
Group_c *g = get_group_c(g_c, groupnumber);
|
||||||
|
@ -973,6 +996,17 @@ void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenge
|
||||||
g_c->group_namelistchange_userdata = userdata;
|
g_c->group_namelistchange_userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set callback funciton for title changes.
|
||||||
|
*
|
||||||
|
* Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint16_t length, void *userdata)
|
||||||
|
*/
|
||||||
|
void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t,
|
||||||
|
void *), void *userdata)
|
||||||
|
{
|
||||||
|
g_c->title_callback = function;
|
||||||
|
g_c->title_callback_userdata = userdata;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set a function to be called when a new peer joins a group chat.
|
/* Set a function to be called when a new peer joins a group chat.
|
||||||
*
|
*
|
||||||
* Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber)
|
* Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber)
|
||||||
|
@ -1102,6 +1136,23 @@ static int group_name_send(const Group_Chats *g_c, int groupnumber, const uint8_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define GROUP_MESSAGE_TITLE_ID 49
|
||||||
|
|
||||||
|
/* set the group's title, limited to MAX_NAME_LENGTH
|
||||||
|
* return 0 on success
|
||||||
|
* return -1 on failure
|
||||||
|
*/
|
||||||
|
int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint16_t length)
|
||||||
|
{
|
||||||
|
if (length > MAX_NAME_LENGTH)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_TITLE_ID, title, length))
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_friend_invite_packet(Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length)
|
static void handle_friend_invite_packet(Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length)
|
||||||
{
|
{
|
||||||
Group_Chats *g_c = m->group_chat_object;
|
Group_Chats *g_c = m->group_chat_object;
|
||||||
|
@ -1664,6 +1715,12 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GROUP_MESSAGE_TITLE_ID: {
|
||||||
|
if (settitle(g_c, groupnumber, index, msg_data, msg_data_len) == -1)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case PACKET_ID_MESSAGE: {
|
case PACKET_ID_MESSAGE: {
|
||||||
if (msg_data_len == 0)
|
if (msg_data_len == 0)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -60,7 +60,7 @@ typedef struct {
|
||||||
|
|
||||||
#define DESIRED_CLOSE_CONNECTIONS 4
|
#define DESIRED_CLOSE_CONNECTIONS 4
|
||||||
#define MAX_GROUP_CONNECTIONS 16
|
#define MAX_GROUP_CONNECTIONS 16
|
||||||
#define GROUP_IDENTIFIER_LENGTH (1 + crypto_box_KEYBYTES) /* crypto_box_KEYBYTES so we can use new_symmetric_key(...) to fill it */
|
#define GROUP_IDENTIFIER_LENGTH (1 + crypto_box_KEYBYTES) /* type + crypto_box_KEYBYTES so we can use new_symmetric_key(...) to fill it */
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
GROUPCHAT_CLOSE_NONE,
|
GROUPCHAT_CLOSE_NONE,
|
||||||
|
@ -91,6 +91,9 @@ typedef struct {
|
||||||
|
|
||||||
uint8_t identifier[GROUP_IDENTIFIER_LENGTH];
|
uint8_t identifier[GROUP_IDENTIFIER_LENGTH];
|
||||||
|
|
||||||
|
uint8_t title[MAX_NAME_LENGTH];
|
||||||
|
uint8_t title_len;
|
||||||
|
|
||||||
uint32_t message_number;
|
uint32_t message_number;
|
||||||
uint16_t lossy_message_number;
|
uint16_t lossy_message_number;
|
||||||
uint16_t peer_number;
|
uint16_t peer_number;
|
||||||
|
@ -121,6 +124,8 @@ typedef struct {
|
||||||
void *action_callback_userdata;
|
void *action_callback_userdata;
|
||||||
void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *);
|
void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *);
|
||||||
void *group_namelistchange_userdata;
|
void *group_namelistchange_userdata;
|
||||||
|
void (*title_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *);
|
||||||
|
void *title_callback_userdata;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int (*function)(void *, int, int, void *, const uint8_t *, uint16_t);
|
int (*function)(void *, int, int, void *, const uint8_t *, uint16_t);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user