summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordubslow <bunslow@gmail.com>2014-11-04 20:44:12 -0600
committerdubslow <bunslow@gmail.com>2014-11-11 17:19:36 -0600
commitc56853e623bd61b32cb6e6bb98050494a24d71a6 (patch)
treeb7f52c9da23d2d3bbca75470b040d0d7617b96cc
parent65aad4858448fe3c57496ec72ac514b05302bef3 (diff)
public api, finishing tweaks
-rw-r--r--toxcore/group.c24
-rw-r--r--toxcore/group.h2
-rw-r--r--toxcore/tox.c22
-rw-r--r--toxcore/tox.h14
4 files changed, 55 insertions, 7 deletions
diff --git a/toxcore/group.c b/toxcore/group.c
index 550c1b57..c158a91b 100644
--- a/toxcore/group.c
+++ b/toxcore/group.c
@@ -513,7 +513,7 @@ static int setnick(Group_Chats *g_c, int groupnumber, int peer_index, const uint
513 return 0; 513 return 0;
514} 514}
515 515
516static int settitle(Group_Chats *g_c, int groupnumber, int peer_index, const uint8_t *title, uint16_t title_len) 516static int settitle(Group_Chats *g_c, int groupnumber, int peer_index, const uint8_t *title, uint8_t title_len)
517{ 517{
518 if (title_len > MAX_NAME_LENGTH || title_len == 0) 518 if (title_len > MAX_NAME_LENGTH || title_len == 0)
519 return -1; 519 return -1;
@@ -998,10 +998,10 @@ void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenge
998 998
999/* Set callback funciton for title changes. 999/* Set callback funciton for title changes.
1000 * 1000 *
1001 * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint16_t length, void *userdata) 1001 * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata)
1002 * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) 1002 * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group)
1003 */ 1003 */
1004void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, 1004void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint8_t,
1005 void *), void *userdata) 1005 void *), void *userdata)
1006{ 1006{
1007 g_c->title_callback = function; 1007 g_c->title_callback = function;
@@ -1143,12 +1143,24 @@ static int group_name_send(const Group_Chats *g_c, int groupnumber, const uint8_
1143 * return 0 on success 1143 * return 0 on success
1144 * return -1 on failure 1144 * return -1 on failure
1145 */ 1145 */
1146int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint16_t length) 1146int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint8_t title_len)
1147{ 1147{
1148 if (length > MAX_NAME_LENGTH) 1148 if (title_len > MAX_NAME_LENGTH || title_len == 0)
1149 return -1; 1149 return -1;
1150 1150
1151 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_TITLE_ID, title, length)) 1151 Group_c *g = get_group_c(g_c, groupnumber);
1152
1153 if (!g)
1154 return -1;
1155
1156 /* same as already set? */
1157 if (g->title_len == title_len && !memcmp(g->title, title, title_len))
1158 return 0;
1159
1160 memcpy(g->title, title, title_len);
1161 g->title_len = title_len;
1162
1163 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_TITLE_ID, title, title_len))
1152 return 0; 1164 return 0;
1153 else 1165 else
1154 return -1; 1166 return -1;
diff --git a/toxcore/group.h b/toxcore/group.h
index 891100d4..8a82a5ab 100644
--- a/toxcore/group.h
+++ b/toxcore/group.h
@@ -124,7 +124,7 @@ typedef struct {
124 void *action_callback_userdata; 124 void *action_callback_userdata;
125 void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *); 125 void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *);
126 void *group_namelistchange_userdata; 126 void *group_namelistchange_userdata;
127 void (*title_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); 127 void (*title_callback)(Messenger *m, int, int, const uint8_t *, uint8_t, void *);
128 void *title_callback_userdata; 128 void *title_callback_userdata;
129 129
130 struct { 130 struct {
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 9e9a5057..2f578971 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -584,6 +584,18 @@ void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, i
584 g_callback_group_action(m->group_chat_object, function, userdata); 584 g_callback_group_action(m->group_chat_object, function, userdata);
585} 585}
586 586
587/* Set callback function for title changes.
588 *
589 * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * title, uint8_t length, void *userdata)
590 * if peernumber == -1, then author is unknown (e.g. initial joining the group)
591 */
592void tox_callback_group_title(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint16_t,
593 void *), void *userdata)
594{
595 Messenger *m = tox;
596 g_callback_group_title(m->group_chat_object, function, userdata);
597}
598
587/* Set callback function for peer name list changes. 599/* Set callback function for peer name list changes.
588 * 600 *
589 * It gets called every time the name list changes(new peer/name, deleted peer) 601 * It gets called every time the name list changes(new peer/name, deleted peer)
@@ -671,6 +683,16 @@ int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint
671 return group_action_send(m->group_chat_object, groupnumber, action, length); 683 return group_action_send(m->group_chat_object, groupnumber, action, length);
672} 684}
673 685
686/* set the group's title, limited to MAX_NAME_LENGTH
687 * return 0 on success
688 * return -1 on failure
689 */
690int tox_group_set_title(Tox *tox, int groupnumber, const uint8_t *title, uint8_t length)
691{
692 Messenger *m = tox;
693 return group_title_send(m->group_chat_object, groupnumber, title, length);
694}
695
674/* Check if the current peernumber corresponds to ours. 696/* Check if the current peernumber corresponds to ours.
675 * 697 *
676 * return 1 if the peernumber corresponds to ours. 698 * return 1 if the peernumber corresponds to ours.
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 4f93e608..40ab6c72 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -452,6 +452,14 @@ void tox_callback_group_message(Tox *tox, void (*function)(Tox *tox, int, int, c
452void tox_callback_group_action(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *), 452void tox_callback_group_action(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *),
453 void *userdata); 453 void *userdata);
454 454
455/* Set callback function for title changes.
456 *
457 * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * title, uint8_t length, void *userdata)
458 * if peernumber == -1, then author is unknown (e.g. initial joining the group)
459 */
460void tox_callback_group_title(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint16_t,
461 void *), void *userdata);
462
455/* Set callback function for peer name list changes. 463/* Set callback function for peer name list changes.
456 * 464 *
457 * It gets called every time the name list changes(new peer/name, deleted peer) 465 * It gets called every time the name list changes(new peer/name, deleted peer)
@@ -514,6 +522,12 @@ int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, ui
514 */ 522 */
515int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length); 523int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length);
516 524
525/* set the group's title, limited to MAX_NAME_LENGTH
526 * return 0 on success
527 * return -1 on failure
528 */
529int tox_group_set_title(Tox *tox, int groupnumber, const uint8_t *title, uint8_t length);
530
517/* Check if the current peernumber corresponds to ours. 531/* Check if the current peernumber corresponds to ours.
518 * 532 *
519 * return 1 if the peernumber corresponds to ours. 533 * return 1 if the peernumber corresponds to ours.