summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Messenger.c27
-rw-r--r--core/Messenger.h12
2 files changed, 28 insertions, 11 deletions
diff --git a/core/Messenger.c b/core/Messenger.c
index d26bba56..4ea7e507 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -169,7 +169,7 @@ int m_addfriend_norequest(uint8_t * client_id)
169 for (i = 0; i <= numfriends; ++i) { 169 for (i = 0; i <= numfriends; ++i) {
170 if(friendlist[i].status == NOFRIEND) { 170 if(friendlist[i].status == NOFRIEND) {
171 DHT_addfriend(client_id); 171 DHT_addfriend(client_id);
172 set_friend_status(i, FRIEND_REQUESTED); 172 friendlist[i].status = FRIEND_REQUESTED;
173 friendlist[i].crypt_connection_id = -1; 173 friendlist[i].crypt_connection_id = -1;
174 friendlist[i].friend_request_id = -1; 174 friendlist[i].friend_request_id = -1;
175 memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE); 175 memcpy(friendlist[i].client_id, client_id, CLIENT_ID_SIZE);
@@ -482,18 +482,29 @@ void m_callback_read_receipt(void (*function)(int, uint32_t))
482 read_receipt_isset = 1; 482 read_receipt_isset = 1;
483} 483}
484 484
485static void (*friend_statuschange)(int, uint8_t); 485static void (*friend_connectionstatuschange)(int, uint8_t);
486static uint8_t friend_statuschange_isset = 0; 486static uint8_t friend_connectionstatuschange_isset = 0;
487void m_callback_friendstatus(void (*function)(int, uint8_t)) 487void m_callback_connectionstatus(void (*function)(int, uint8_t))
488{ 488{
489 friend_statuschange = function; 489 friend_connectionstatuschange = function;
490 friend_statuschange_isset = 1; 490 friend_connectionstatuschange_isset = 1;
491}
492
493static void check_friend_connectionstatus(int friendnumber, uint8_t status)
494{
495 if (!friend_connectionstatuschange_isset)
496 return;
497 if (status == NOFRIEND)
498 return;
499 const uint8_t is_connected = friendlist[friendnumber].status == FRIEND_ONLINE;
500 const uint8_t was_connected = status == FRIEND_ONLINE;
501 if (is_connected != was_connected)
502 friend_connectionstatuschange(friendnumber, is_connected);
491} 503}
492 504
493static void set_friend_status(int friendnumber, uint8_t status) 505static void set_friend_status(int friendnumber, uint8_t status)
494{ 506{
495 if (friendlist[friendnumber].status != status && friend_statuschange_isset) 507 check_friend_connectionstatus(friendnumber, status);
496 friend_statuschange(friendnumber, status);
497 friendlist[friendnumber].status = status; 508 friendlist[friendnumber].status = status;
498} 509}
499 510
diff --git a/core/Messenger.h b/core/Messenger.h
index 55c86682..fa0daf41 100644
--- a/core/Messenger.h
+++ b/core/Messenger.h
@@ -211,9 +211,15 @@ void m_callback_userstatus(void (*function)(int, USERSTATUS));
211 in that case, you should discard it. */ 211 in that case, you should discard it. */
212void m_callback_read_receipt(void (*function)(int, uint32_t)); 212void m_callback_read_receipt(void (*function)(int, uint32_t));
213 213
214/* set the callback for friend status changes 214/* set the callback for conenction status changes
215 function(int friendnumber, uint8_t status) */ 215 function(int friendnumber, uint8_t status)
216void m_callback_friendstatus(void (*function)(int, uint8_t)); 216 status:
217 0 -- friend went offline after being previously online
218 1 -- friend went online
219 note that this callback is not called when adding friends, thus the "after
220 being previously online" part. it's assumed that when adding friends,
221 their connection status is offline. */
222void m_callback_connectionstatus(void (*function)(int, uint8_t));
217 223
218/* run this at startup 224/* run this at startup
219 returns 0 if no connection problems 225 returns 0 if no connection problems