summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/Messenger.c20
-rw-r--r--toxcore/Messenger.h19
-rw-r--r--toxcore/tox.c25
-rw-r--r--toxcore/tox.h28
4 files changed, 55 insertions, 37 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index ff2c31aa..07893e02 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -275,18 +275,20 @@ int m_delfriend(Messenger *m, int friendnumber)
275 return 0; 275 return 0;
276} 276}
277 277
278/* return FRIEND_ONLINE if friend is online. 278int m_get_friend_connectionstatus(Messenger *m, int friendnumber)
279 * return FRIEND_CONFIRMED if friend is confirmed. 279{
280 * return FRIEND_REQUESTED if the friend request was sent. 280 if (friend_not_valid(m, friendnumber))
281 * return FRIEND_ADDED if the friend was added. 281 return -1;
282 * return NOFRIEND if there is no friend with that number. 282
283 */ 283 return m->friendlist[friendnumber].status == FRIEND_ONLINE;
284int m_friendstatus(Messenger *m, int friendnumber) 284}
285
286int m_friend_exists(Messenger *m, int friendnumber)
285{ 287{
286 if (friend_not_valid(m, friendnumber)) 288 if (friend_not_valid(m, friendnumber))
287 return NOFRIEND; 289 return 0;
288 290
289 return m->friendlist[friendnumber].status; 291 return m->friendlist[friendnumber].status > NOFRIEND;
290} 292}
291 293
292/* Send a text chat message to an online friend. 294/* Send a text chat message to an online friend.
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index a4c6114b..c512245c 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -202,13 +202,20 @@ int getclient_id(Messenger *m, int friend_id, uint8_t *client_id);
202/* Remove a friend. */ 202/* Remove a friend. */
203int m_delfriend(Messenger *m, int friendnumber); 203int m_delfriend(Messenger *m, int friendnumber);
204 204
205/* return 4 if friend is online. 205/* Checks friend's connecting status.
206 * return 3 if friend is confirmed. 206 *
207 * return 2 if the friend request was sent. 207 * return 1 if friend is connected to us (Online).
208 * return 1 if the friend was added. 208 * return 0 if friend is not connected to us (Offline).
209 * return 0 if there is no friend with that number. 209 * return -1 on failure.
210 */
211int m_get_friend_connectionstatus(Messenger *m, int friendnumber);
212
213/* Checks if there exists a friend with given friendnumber.
214 *
215 * return 1 if friend exists.
216 * return 0 if friend doesn't exist.
210 */ 217 */
211int m_friendstatus(Messenger *m, int friendnumber); 218int m_friend_exists(Messenger *m, int friendnumber);
212 219
213/* Send a text chat message to an online friend. 220/* Send a text chat message to an online friend.
214 * 221 *
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 0af07ede..83b19e9b 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -99,16 +99,27 @@ int tox_delfriend(void *tox, int friendnumber)
99 return m_delfriend(m, friendnumber); 99 return m_delfriend(m, friendnumber);
100} 100}
101 101
102/* return 4 if friend is online. 102/* Checks friend's connecting status.
103 * return 3 if friend is confirmed. 103 *
104 * return 2 if the friend request was sent. 104 * return 1 if friend is connected to us (Online).
105 * return 1 if the friend was added. 105 * return 0 if friend is not connected to us (Offline).
106 * return 0 if there is no friend with that number. 106 * return -1 on failure.
107 */
108int tox_get_friend_connectionstatus(void *tox, int friendnumber)
109{
110 Messenger *m = tox;
111 return m_get_friend_connectionstatus(m, friendnumber);
112}
113
114/* Checks if there exists a friend with given friendnumber.
115 *
116 * return 1 if friend exists.
117 * return 0 if friend doesn't exist.
107 */ 118 */
108int tox_friendstatus(void *tox, int friendnumber) 119int tox_friend_exists(void *tox, int friendnumber)
109{ 120{
110 Messenger *m = tox; 121 Messenger *m = tox;
111 return m_friendstatus(m, friendnumber); 122 return m_friend_exists(m, friendnumber);
112} 123}
113 124
114/* Send a text chat message to an online friend. 125/* Send a text chat message to an online friend.
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 718f817b..811e798b 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -50,15 +50,6 @@ typedef struct {
50 uint16_t padding; 50 uint16_t padding;
51} tox_IP_Port; 51} tox_IP_Port;
52 52
53/* Status definitions. */
54enum {
55 TOX_NOFRIEND,
56 TOX_FRIEND_ADDED,
57 TOX_FRIEND_REQUESTED,
58 TOX_FRIEND_CONFIRMED,
59 TOX_FRIEND_ONLINE,
60};
61
62/* Errors for m_addfriend 53/* Errors for m_addfriend
63 * FAERR - Friend Add Error 54 * FAERR - Friend Add Error
64 */ 55 */
@@ -130,13 +121,20 @@ int tox_getclient_id(Tox *tox, int friend_id, uint8_t *client_id);
130/* Remove a friend. */ 121/* Remove a friend. */
131int tox_delfriend(Tox *tox, int friendnumber); 122int tox_delfriend(Tox *tox, int friendnumber);
132 123
133/* return TOX_FRIEND_ONLINE if friend is online. 124/* Checks friend's connecting status.
134 * return TOX_FRIEND_CONFIRMED if friend is confirmed. 125 *
135 * return TOX_FRIEND_REQUESTED if the friend request was sent. 126 * return 1 if friend is connected to us (Online).
136 * return TOX_FRIEND_ADDED if the friend was added. 127 * return 0 if friend is not connected to us (Offline).
137 * return TOX_NOFRIEND if there is no friend with that number. 128 * return -1 on failure.
129 */
130int tox_get_friend_connectionstatus(Tox *tox, int friendnumber);
131
132/* Checks if there exists a friend with given friendnumber.
133 *
134 * return 1 if friend exists.
135 * return 0 if friend doesn't exist.
138 */ 136 */
139int tox_friendstatus(Tox *tox, int friendnumber); 137int tox_friend_exists(Tox *tox, int friendnumber);
140 138
141/* Send a text chat message to an online friend. 139/* Send a text chat message to an online friend.
142 * 140 *