mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 10:23:26 +01:00
Add group callbacks for password, peerlimit and privacy state changes
This commit is contained in:
parent
a846c38695
commit
23bb980173
@ -4,7 +4,7 @@ Toxic is a [Tox](https://tox.im)-based instant messenging client which formerly
|
||||
[![Toxic Screenshot](https://i.imgur.com/san99Z2.png "Home Screen")](https://i.imgur.com/san99Z2.png)
|
||||
|
||||
## Installation
|
||||
[Use our repositories](https://wiki.tox.im/Binaries#Linux)<br />
|
||||
[Use our repositories](https://wiki.tox.chat/Binaries#Linux)<br />
|
||||
[Compile it yourself](/INSTALL.md)
|
||||
|
||||
## Downloads
|
||||
|
@ -22,7 +22,6 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "toxic.h"
|
||||
#include "windows.h"
|
||||
#include "line_info.h"
|
||||
|
@ -419,10 +419,72 @@ static void groupchat_onGroupTopicChange(ToxWindow *self, Tox *m, uint32_t group
|
||||
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, MAGENTA, "-!- %s set the topic to: %s", nick, topic);
|
||||
|
||||
char tmp_event[MAX_STR_SIZE];
|
||||
snprintf(tmp_event, sizeof(tmp_event), " set the group topic to %s", topic);
|
||||
snprintf(tmp_event, sizeof(tmp_event), " set the topic to %s", topic);
|
||||
write_to_log(tmp_event, nick, ctx->log, true);
|
||||
}
|
||||
|
||||
static void groupchat_onGroupPeerLimit(ToxWindow *self, Tox *m, uint32_t groupnumber, uint32_t peer_limit)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if (self->num != groupnumber)
|
||||
return;
|
||||
|
||||
char timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
|
||||
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- The group founder has set the peer limit to %d", peer_limit);
|
||||
|
||||
char tmp_event[MAX_STR_SIZE];
|
||||
snprintf(tmp_event, sizeof(tmp_event), " set the peer limit to %d", peer_limit);
|
||||
write_to_log(tmp_event, "The founder", ctx->log, true);
|
||||
}
|
||||
|
||||
static void groupchat_onGroupPrivacyState(ToxWindow *self, Tox *m, uint32_t groupnumber, TOX_GROUP_PRIVACY_STATE state)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if (self->num != groupnumber)
|
||||
return;
|
||||
|
||||
const char *state_str = state == TOX_GROUP_PRIVACY_STATE_PUBLIC ? "public" : "private";
|
||||
|
||||
char timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
|
||||
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- The group founder has set the group to %s.", state_str);
|
||||
|
||||
char tmp_event[MAX_STR_SIZE];
|
||||
snprintf(tmp_event, sizeof(tmp_event), " set the group to %s.", state_str);
|
||||
write_to_log(tmp_event, "The founder", ctx->log, true);
|
||||
}
|
||||
|
||||
static void groupchat_onGroupPassword(ToxWindow *self, Tox *m, uint32_t groupnumber, const char *password,
|
||||
size_t length)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if (self->num != groupnumber)
|
||||
return;
|
||||
|
||||
char timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
|
||||
if (length > 0) {
|
||||
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- The group founder has password protected the group.");
|
||||
|
||||
char tmp_event[MAX_STR_SIZE];
|
||||
snprintf(tmp_event, sizeof(tmp_event), " set a new password.");
|
||||
write_to_log(tmp_event, "The founder", ctx->log, true);
|
||||
} else {
|
||||
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- The group founder has removed password protection.");
|
||||
|
||||
char tmp_event[MAX_STR_SIZE];
|
||||
snprintf(tmp_event, sizeof(tmp_event), " removed password protection.");
|
||||
write_to_log(tmp_event, "The founder", ctx->log, true);
|
||||
}
|
||||
}
|
||||
|
||||
/* Copies peer names/lengths */
|
||||
static void copy_peernames(int gnum, uint8_t peerlist[][TOX_MAX_NAME_LENGTH], uint16_t lengths[], int npeers)
|
||||
{
|
||||
@ -1055,6 +1117,9 @@ ToxWindow new_group_chat(Tox *m, uint32_t groupnum, const char *groupname, int l
|
||||
ret.onGroupPeerJoin = &groupchat_onGroupPeerJoin;
|
||||
ret.onGroupPeerExit = &groupchat_onGroupPeerExit;
|
||||
ret.onGroupTopicChange = &groupchat_onGroupTopicChange;
|
||||
ret.onGroupPeerLimit = &groupchat_onGroupPeerLimit;
|
||||
ret.onGroupPrivacyState = &groupchat_onGroupPrivacyState;
|
||||
ret.onGroupPassword = &groupchat_onGroupPassword;
|
||||
ret.onGroupNickChange = &groupchat_onGroupNickChange;
|
||||
ret.onGroupSelfJoin = &groupchat_onGroupSelfJoin;
|
||||
ret.onGroupRejected = &groupchat_onGroupRejected;
|
||||
|
@ -575,11 +575,9 @@ static void init_tox_callbacks(Tox *m)
|
||||
tox_callback_group_peer_exit(m, on_group_peer_exit, NULL);
|
||||
tox_callback_group_peer_name(m, on_group_nick_change, NULL);
|
||||
tox_callback_group_topic(m, on_group_topic_change, NULL);
|
||||
|
||||
// tox_callback_group_peer_limit(m, on_group_peer_limit, NULL);
|
||||
// tox_callback_group_privacy_state(m, on_group_privacy_state, NULL);
|
||||
// tox_callback_group_password(m, on_group_password, NULL);
|
||||
|
||||
tox_callback_group_peer_limit(m, on_group_peer_limit, NULL);
|
||||
tox_callback_group_privacy_state(m, on_group_privacy_state, NULL);
|
||||
tox_callback_group_password(m, on_group_password, NULL);
|
||||
tox_callback_group_self_join(m, on_group_self_join, NULL);
|
||||
tox_callback_group_join_fail(m, on_group_rejected, NULL);
|
||||
tox_callback_group_moderation(m, on_group_moderation, NULL);
|
||||
|
@ -123,6 +123,9 @@ void on_group_namelistchange(Tox *m, uint32_t groupnumber, void *userdata);
|
||||
void on_group_peer_join(Tox *m, uint32_t groupnumber, uint32_t peernumber, void *userdata);
|
||||
void on_group_peer_exit(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *partmsg, size_t length, void *userdata);
|
||||
void on_group_topic_change(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *topic, size_t length, void *userdata);
|
||||
void on_group_peer_limit(Tox *m, uint32_t groupnumber, uint32_t peer_limit, void *userdata);
|
||||
void on_group_privacy_state(Tox *m, uint32_t groupnumber, TOX_GROUP_PRIVACY_STATE privacy_state, void *userdata);
|
||||
void on_group_password(Tox *m, uint32_t groupnumber, const uint8_t *password, size_t length, void *userdata);
|
||||
void on_group_nick_change(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *newname, size_t length, void *userdata);
|
||||
void on_group_self_join(Tox *m, uint32_t groupnumber, void *userdata);
|
||||
void on_group_rejected(Tox *m, uint32_t groupnumber, TOX_GROUP_JOIN_FAIL type, void *userdata);
|
||||
|
@ -243,6 +243,36 @@ void on_group_topic_change(Tox *m, uint32_t groupnumber, uint32_t peernumber, co
|
||||
}
|
||||
}
|
||||
|
||||
void on_group_peer_limit(Tox *m, uint32_t groupnumber, uint32_t peer_limit, void *userdata)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onGroupPeerLimit != NULL)
|
||||
windows[i].onGroupPeerLimit(&windows[i], m, groupnumber, peer_limit);
|
||||
}
|
||||
}
|
||||
|
||||
void on_group_privacy_state(Tox *m, uint32_t groupnumber, TOX_GROUP_PRIVACY_STATE privacy_state, void *userdata)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onGroupPrivacyState != NULL)
|
||||
windows[i].onGroupPrivacyState(&windows[i], m, groupnumber, privacy_state);
|
||||
}
|
||||
}
|
||||
|
||||
void on_group_password(Tox *m, uint32_t groupnumber, const uint8_t *password, size_t length, void *userdata)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onGroupPassword != NULL)
|
||||
windows[i].onGroupPassword(&windows[i], m, groupnumber, (char *) password, length);
|
||||
}
|
||||
}
|
||||
|
||||
void on_group_nick_change(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *newname, size_t length,
|
||||
void *userdata)
|
||||
{
|
||||
|
@ -136,6 +136,9 @@ struct ToxWindow {
|
||||
void(*onGroupPeerExit)(ToxWindow *, Tox *, uint32_t, uint32_t, const char *, size_t);
|
||||
void(*onGroupNickChange)(ToxWindow *, Tox *, uint32_t, uint32_t, const char *, size_t);
|
||||
void(*onGroupTopicChange)(ToxWindow *, Tox *, uint32_t, uint32_t, const char *, size_t);
|
||||
void(*onGroupPeerLimit)(ToxWindow *, Tox *, uint32_t, uint32_t);
|
||||
void(*onGroupPrivacyState)(ToxWindow *, Tox *, uint32_t, TOX_GROUP_PRIVACY_STATE);
|
||||
void(*onGroupPassword)(ToxWindow *, Tox *, uint32_t, const char *, size_t);
|
||||
void(*onGroupSelfJoin)(ToxWindow *, Tox *, uint32_t);
|
||||
void(*onGroupRejected)(ToxWindow *, Tox *, uint32_t, TOX_GROUP_JOIN_FAIL);
|
||||
void(*onGroupModeration)(ToxWindow *, Tox *, uint32_t, uint32_t, uint32_t, TOX_GROUP_MOD_EVENT);
|
||||
|
Loading…
Reference in New Issue
Block a user