mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge pull request #434 from nurupo/master
Replaced friendstatus with connectionstatus
This commit is contained in:
commit
7f3cbfdc2f
|
@ -169,7 +169,7 @@ int m_addfriend_norequest(uint8_t * client_id)
|
||||||
for (i = 0; i <= numfriends; ++i) {
|
for (i = 0; i <= numfriends; ++i) {
|
||||||
if(friendlist[i].status == NOFRIEND) {
|
if(friendlist[i].status == NOFRIEND) {
|
||||||
DHT_addfriend(client_id);
|
DHT_addfriend(client_id);
|
||||||
set_friend_status(i, FRIEND_REQUESTED);
|
friendlist[i].status = FRIEND_REQUESTED;
|
||||||
friendlist[i].crypt_connection_id = -1;
|
friendlist[i].crypt_connection_id = -1;
|
||||||
friendlist[i].friend_request_id = -1;
|
friendlist[i].friend_request_id = -1;
|
||||||
memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
|
memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
|
||||||
|
@ -482,18 +482,29 @@ void m_callback_read_receipt(void (*function)(int, uint32_t))
|
||||||
read_receipt_isset = 1;
|
read_receipt_isset = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void (*friend_statuschange)(int, uint8_t);
|
static void (*friend_connectionstatuschange)(int, uint8_t);
|
||||||
static uint8_t friend_statuschange_isset = 0;
|
static uint8_t friend_connectionstatuschange_isset = 0;
|
||||||
void m_callback_friendstatus(void (*function)(int, uint8_t))
|
void m_callback_connectionstatus(void (*function)(int, uint8_t))
|
||||||
{
|
{
|
||||||
friend_statuschange = function;
|
friend_connectionstatuschange = function;
|
||||||
friend_statuschange_isset = 1;
|
friend_connectionstatuschange_isset = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void check_friend_connectionstatus(int friendnumber, uint8_t status)
|
||||||
|
{
|
||||||
|
if (!friend_connectionstatuschange_isset)
|
||||||
|
return;
|
||||||
|
if (status == NOFRIEND)
|
||||||
|
return;
|
||||||
|
const uint8_t is_connected = friendlist[friendnumber].status == FRIEND_ONLINE;
|
||||||
|
const uint8_t was_connected = status == FRIEND_ONLINE;
|
||||||
|
if (is_connected != was_connected)
|
||||||
|
friend_connectionstatuschange(friendnumber, is_connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_friend_status(int friendnumber, uint8_t status)
|
static void set_friend_status(int friendnumber, uint8_t status)
|
||||||
{
|
{
|
||||||
if (friendlist[friendnumber].status != status && friend_statuschange_isset)
|
check_friend_connectionstatus(friendnumber, status);
|
||||||
friend_statuschange(friendnumber, status);
|
|
||||||
friendlist[friendnumber].status = status;
|
friendlist[friendnumber].status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,9 +211,15 @@ void m_callback_userstatus(void (*function)(int, USERSTATUS));
|
||||||
in that case, you should discard it. */
|
in that case, you should discard it. */
|
||||||
void m_callback_read_receipt(void (*function)(int, uint32_t));
|
void m_callback_read_receipt(void (*function)(int, uint32_t));
|
||||||
|
|
||||||
/* set the callback for friend status changes
|
/* set the callback for conenction status changes
|
||||||
function(int friendnumber, uint8_t status) */
|
function(int friendnumber, uint8_t status)
|
||||||
void m_callback_friendstatus(void (*function)(int, uint8_t));
|
status:
|
||||||
|
0 -- friend went offline after being previously online
|
||||||
|
1 -- friend went online
|
||||||
|
note that this callback is not called when adding friends, thus the "after
|
||||||
|
being previously online" part. it's assumed that when adding friends,
|
||||||
|
their connection status is offline. */
|
||||||
|
void m_callback_connectionstatus(void (*function)(int, uint8_t));
|
||||||
|
|
||||||
/* run this at startup
|
/* run this at startup
|
||||||
returns 0 if no connection problems
|
returns 0 if no connection problems
|
||||||
|
|
Loading…
Reference in New Issue
Block a user