Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the "persistent conference" callback changes as new functions. #799

Merged
merged 1 commit into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion auto_tests/monolith_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int main(int argc, char *argv[])
CHECK_SIZE(Friend_Requests, 1080);
// toxcore/group
CHECK_SIZE(Group_c, 728);
CHECK_SIZE(Group_Chats, 2112);
CHECK_SIZE(Group_Chats, 2128);
CHECK_SIZE(Group_Peer, 480);
// toxcore/list
CHECK_SIZE(BS_LIST, 32);
Expand Down
10 changes: 6 additions & 4 deletions other/astyle/format-source
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ apidsl_curl() {
}

# Check if apidsl generated sources are up to date.
$APIDSL toxcore/crypto_core.api.h > toxcore/crypto_core.h
$APIDSL toxcore/tox.api.h > toxcore/tox.h
$APIDSL toxav/toxav.api.h > toxav/toxav.h
$APIDSL toxencryptsave/toxencryptsave.api.h > toxencryptsave/toxencryptsave.h
$APIDSL toxcore/crypto_core.api.h > toxcore/crypto_core.h &
$APIDSL toxcore/tox.api.h > toxcore/tox.h &
$APIDSL toxav/toxav.api.h > toxav/toxav.h &
$APIDSL toxencryptsave/toxencryptsave.api.h > toxencryptsave/toxencryptsave.h &

wait; wait; wait; wait

if grep '<unresolved>' */*.h; then
echo "error: some apidsl references were unresolved"
Expand Down
39 changes: 36 additions & 3 deletions toxcore/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,11 @@ static int addpeer(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_p
add_to_closest(g_c, groupnumber, real_pk, temp_pk);

if (do_gc_callback && g_c->group_namelistchange) {
g_c->group_namelistchange(g_c->m, groupnumber, 0, CHAT_CHANGE_OCCURRED, userdata);
g_c->group_namelistchange(g_c->m, groupnumber, g->numpeers - 1, CHAT_CHANGE_PEER_ADD, userdata);
}

if (do_gc_callback && g_c->peer_list_changed_callback) {
g_c->peer_list_changed_callback(g_c->m, groupnumber, userdata);
}

if (g->peer_on_join) {
Expand Down Expand Up @@ -544,7 +548,11 @@ static int delpeer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, void
}

if (g_c->group_namelistchange) {
g_c->group_namelistchange(g_c->m, groupnumber, 0, CHAT_CHANGE_OCCURRED, userdata);
g_c->group_namelistchange(g_c->m, groupnumber, peer_index, CHAT_CHANGE_PEER_DEL, userdata);
}

if (g_c->peer_list_changed_callback) {
g_c->peer_list_changed_callback(g_c->m, groupnumber, userdata);
}

if (g->peer_on_leave) {
Expand Down Expand Up @@ -593,6 +601,10 @@ static int setnick(Group_Chats *g_c, uint32_t groupnumber, int peer_index, const
g_c->group_namelistchange(g_c->m, groupnumber, peer_index, CHAT_CHANGE_PEER_NAME, userdata);
}

if (do_gc_callback && g_c->peer_name_callback) {
g_c->peer_name_callback(g_c->m, groupnumber, peer_index, nick, nick_len, userdata);
}

return 0;
}

Expand Down Expand Up @@ -1143,13 +1155,34 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, u
g_c->message_callback = function;
}

/* Set callback function for peer nickname changes.
*
* It gets called every time a peer changes their nickname.
* Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, const uint8_t *nick, size_t nick_len, void *userdata)
*/
void g_callback_peer_name(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *,
size_t, void *))
{
g_c->peer_name_callback = function;
}

/* Set callback function for peer list changes.
*
* It gets called every time the name list changes(new peer, deleted peer)
* Function(Group_Chats *g_c, uint32_t groupnumber, void *userdata)
*/
void g_callback_peer_list_changed(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, void *))
{
g_c->peer_list_changed_callback = function;
}

// TODO(sudden6): function signatures in comments are incorrect
/* Set callback function for peer name list changes.
*
* It gets called every time the name list changes(new peer/name, deleted peer)
* Function(Group_Chats *g_c, int groupnumber, int peernumber, TOX_CHAT_CHANGE change, void *userdata)
*/
void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *, uint32_t, uint32_t, uint8_t,
void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *, uint32_t, uint32_t, int,
void *))
{
g_c->group_namelistchange = function;
Expand Down
27 changes: 22 additions & 5 deletions toxcore/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ typedef struct {

void (*invite_callback)(Messenger *m, uint32_t, int, const uint8_t *, size_t, void *);
void (*message_callback)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *);
void (*group_namelistchange)(Messenger *m, uint32_t, uint32_t, uint8_t, void *);
void (*peer_name_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *);
void (*peer_list_changed_callback)(Messenger *m, uint32_t, void *);
void (*group_namelistchange)(Messenger *m, uint32_t, uint32_t, int, void *);
void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *);

struct {
Expand Down Expand Up @@ -150,17 +152,32 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, u
void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *,
size_t, void *));

/* Set callback function for peer nickname changes.
*
* It gets called every time a peer changes their nickname.
* Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, const uint8_t *nick, size_t nick_len, void *userdata)
*/
void g_callback_peer_name(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *,
size_t, void *));

/* Set callback function for peer list changes.
*
* It gets called every time the name list changes(new peer, deleted peer)
* Function(Group_Chats *g_c, uint32_t groupnumber, void *userdata)
*/
void g_callback_peer_list_changed(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, void *));

/* Set callback function for peer name list changes.
*
* It gets called every time the name list changes(new peer/name, deleted peer)
* Function(Group_Chats *g_c, int groupnumber, int peernumber, TOX_CHAT_CHANGE change, void *userdata)
* Function(Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, TOX_CHAT_CHANGE change, void *userdata)
*/
enum {
CHAT_CHANGE_OCCURRED,
CHAT_CHANGE_PEER_ADD,
CHAT_CHANGE_PEER_DEL,
CHAT_CHANGE_PEER_NAME,
};
void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, uint8_t,
void *));
void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, void *));

/* Creates a new groupchat and puts it in the chats array.
*
Expand Down
40 changes: 37 additions & 3 deletions toxcore/tox.api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2105,15 +2105,47 @@ namespace conference {
typedef void(uint32_t conference_number, uint32_t peer_number, const uint8_t[length] title);
}

namespace peer {

/**
* This event is triggered when a peer changes their name.
*/
event name const {
/**
* @param conference_number The conference number of the conference the
* peer is in.
* @param peer_number The ID of the peer who changed their nickname.
* @param name A byte array containing the new nickname.
* @param length The size of the name byte array.
*/
typedef void(uint32_t conference_number, uint32_t peer_number, const uint8_t[length] name);
}

/**
* This event is triggered when a peer joins or leaves the conference.
*/
event list_changed const {
/**
* @param conference_number The conference number of the conference the
* peer is in.
*/
typedef void(uint32_t conference_number);
}

}

/**
* Peer list state change types.
*/
enum class STATE_CHANGE {
/**
* Some changes to list have occurred. Rebuild of list required.
* peer_number is undefined (always 0 for api compatibility)
* A peer has joined the conference.
*/
PEER_JOIN,
/**
* A peer has exited the conference.
*/
LIST_CHANGED,
PEER_EXIT,
/**
* A peer has changed their name.
*/
Expand All @@ -2122,6 +2154,8 @@ namespace conference {

/**
* This event is triggered when the peer list changes (name change, peer join, peer exit).
*
* @deprecated Use the `${event peer.name}` and `${event peer.list_changed}` events, instead.
*/
event namelist_change const {
/**
Expand Down
17 changes: 14 additions & 3 deletions toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,12 +1103,23 @@ void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback)
g_callback_group_title((Group_Chats *)m->conferences_object, callback);
}

void tox_callback_conference_peer_name(Tox *tox, tox_conference_peer_name_cb *callback)
{
Messenger *m = tox;
g_callback_peer_name((Group_Chats *)m->conferences_object, callback);
}

void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_list_changed_cb *callback)
{
Messenger *m = tox;
g_callback_peer_list_changed((Group_Chats *)m->conferences_object, callback);
}

void tox_callback_conference_namelist_change(Tox *tox, tox_conference_namelist_change_cb *callback)
{
Messenger *m = tox;
g_callback_group_namelistchange((Group_Chats *)m->conferences_object, (void (*)(struct Messenger *, uint32_t, uint32_t,
uint8_t,
void *))callback);
g_callback_group_namelistchange((Group_Chats *)m->conferences_object,
(void (*)(struct Messenger *, uint32_t, uint32_t, int, void *))callback);
}

uint32_t tox_conference_new(Tox *tox, TOX_ERR_CONFERENCE_NEW *error)
Expand Down
44 changes: 41 additions & 3 deletions toxcore/tox.h
Original file line number Diff line number Diff line change
Expand Up @@ -2387,16 +2387,52 @@ typedef void tox_conference_title_cb(Tox *tox, uint32_t conference_number, uint3
*/
void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback);

/**
* @param conference_number The conference number of the conference the
* peer is in.
* @param peer_number The ID of the peer who changed their nickname.
* @param name A byte array containing the new nickname.
* @param length The size of the name byte array.
*/
typedef void tox_conference_peer_name_cb(Tox *tox, uint32_t conference_number, uint32_t peer_number,
const uint8_t *name, size_t length, void *user_data);


/**
* Set the callback for the `conference_peer_name` event. Pass NULL to unset.
*
* This event is triggered when a peer changes their name.
*/
void tox_callback_conference_peer_name(Tox *tox, tox_conference_peer_name_cb *callback);

/**
* @param conference_number The conference number of the conference the
* peer is in.
*/
typedef void tox_conference_peer_list_changed_cb(Tox *tox, uint32_t conference_number, void *user_data);


/**
* Set the callback for the `conference_peer_list_changed` event. Pass NULL to unset.
*
* This event is triggered when a peer joins or leaves the conference.
*/
void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_list_changed_cb *callback);

/**
* Peer list state change types.
*/
typedef enum TOX_CONFERENCE_STATE_CHANGE {

/**
* Some changes to list have occurred. Rebuild of list required.
* peer_number is undefined (always 0 for api compatibility)
* A peer has joined the conference.
*/
TOX_CONFERENCE_STATE_CHANGE_LIST_CHANGED,
TOX_CONFERENCE_STATE_CHANGE_PEER_JOIN,

/**
* A peer has exited the conference.
*/
TOX_CONFERENCE_STATE_CHANGE_PEER_EXIT,

/**
* A peer has changed their name.
Expand All @@ -2419,6 +2455,8 @@ typedef void tox_conference_namelist_change_cb(Tox *tox, uint32_t conference_num
* Set the callback for the `conference_namelist_change` event. Pass NULL to unset.
*
* This event is triggered when the peer list changes (name change, peer join, peer exit).
*
* @deprecated Use the `conference_peer_name` and `conference_peer_list_changed` events, instead.
*/
void tox_callback_conference_namelist_change(Tox *tox, tox_conference_namelist_change_cb *callback);

Expand Down