summaryrefslogtreecommitdiff
path: root/toxcore/tox.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/tox.c')
-rw-r--r--toxcore/tox.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 39a63fd9..789ef3c9 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -26,6 +26,7 @@
26#endif 26#endif
27 27
28#include "Messenger.h" 28#include "Messenger.h"
29#include "group.h"
29#include "logger.h" 30#include "logger.h"
30 31
31#define __TOX_DEFINED__ 32#define __TOX_DEFINED__
@@ -544,13 +545,15 @@ int tox_send_lossless_packet(const Tox *tox, int32_t friendnumber, const uint8_t
544 545
545/* Set the callback for group invites. 546/* Set the callback for group invites.
546 * 547 *
547 * Function(Tox *tox, int32_t friendnumber, uint8_t *group_public_key, void *userdata) 548 * Function(Tox *tox, int32_t friendnumber, uint8_t *data, uint16_t length, void *userdata)
549 *
550 * data of length is what needs to be passed to join_groupchat().
548 */ 551 */
549void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, void *), 552void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, uint16_t, void *),
550 void *userdata) 553 void *userdata)
551{ 554{
552 Messenger *m = tox; 555 Messenger *m = tox;
553 //m_callback_group_invite(m, function, userdata); 556 g_callback_group_invite(m->group_chat_object, function, userdata);
554} 557}
555 558
556/* Set the callback for group messages. 559/* Set the callback for group messages.
@@ -561,7 +564,7 @@ void tox_callback_group_message(Tox *tox, void (*function)(Messenger *tox, int,
561 void *userdata) 564 void *userdata)
562{ 565{
563 Messenger *m = tox; 566 Messenger *m = tox;
564 //m_callback_group_message(m, function, userdata); 567 g_callback_group_message(m->group_chat_object, function, userdata);
565} 568}
566 569
567/* Set the callback for group actions. 570/* Set the callback for group actions.
@@ -594,8 +597,9 @@ void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int
594int tox_add_groupchat(Tox *tox) 597int tox_add_groupchat(Tox *tox)
595{ 598{
596 Messenger *m = tox; 599 Messenger *m = tox;
597 //return add_groupchat(m); 600 return add_groupchat(m->group_chat_object);
598} 601}
602
599/* Delete a groupchat from the chats array. 603/* Delete a groupchat from the chats array.
600 * 604 *
601 * return 0 on success. 605 * return 0 on success.
@@ -605,6 +609,7 @@ int tox_del_groupchat(Tox *tox, int groupnumber)
605{ 609{
606 Messenger *m = tox; 610 Messenger *m = tox;
607 //return del_groupchat(m, groupnumber); 611 //return del_groupchat(m, groupnumber);
612 return -1;
608} 613}
609 614
610/* Copy the name of peernumber who is in groupnumber to name. 615/* Copy the name of peernumber who is in groupnumber to name.
@@ -617,7 +622,9 @@ int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t
617{ 622{
618 const Messenger *m = tox; 623 const Messenger *m = tox;
619 //return m_group_peername(m, groupnumber, peernumber, name); 624 //return m_group_peername(m, groupnumber, peernumber, name);
625 return -1;
620} 626}
627
621/* invite friendnumber to groupnumber 628/* invite friendnumber to groupnumber
622 * return 0 on success 629 * return 0 on success
623 * return -1 on failure 630 * return -1 on failure
@@ -625,37 +632,40 @@ int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t
625int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber) 632int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber)
626{ 633{
627 Messenger *m = tox; 634 Messenger *m = tox;
628 //return invite_friend(m, friendnumber, groupnumber); 635 return invite_friend(m->group_chat_object, friendnumber, groupnumber);
629} 636}
630/* Join a group (you need to have been invited first.) 637
638/* Join a group (you need to have been invited first.) using data of length obtained
639 * in the group invite callback.
631 * 640 *
632 * returns group number on success 641 * returns group number on success
633 * returns -1 on failure. 642 * returns -1 on failure.
634 */ 643 */
635int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *friend_group_public_key) 644int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length)
636{ 645{
637 Messenger *m = tox; 646 Messenger *m = tox;
638 //return join_groupchat(m, friendnumber, friend_group_public_key); 647 return join_groupchat(m->group_chat_object, friendnumber, data, length);
639} 648}
640 649
641/* send a group message 650/* send a group message
642 * return 0 on success 651 * return 0 on success
643 * return -1 on failure 652 * return -1 on failure
644 */ 653 */
645int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint32_t length) 654int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint16_t length)
646{ 655{
647 Messenger *m = tox; 656 Messenger *m = tox;
648 //return group_message_send(m, groupnumber, message, length); 657 return group_message_send(m->group_chat_object, groupnumber, message, length);
649} 658}
650 659
651/* send a group action 660/* send a group action
652 * return 0 on success 661 * return 0 on success
653 * return -1 on failure 662 * return -1 on failure
654 */ 663 */
655int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint32_t length) 664int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length)
656{ 665{
657 Messenger *m = tox; 666 Messenger *m = tox;
658 //return group_action_send(m, groupnumber, action, length); 667 //return group_action_send(m, groupnumber, action, length);
668 return -1;
659} 669}
660 670
661/* Return the number of peers in the group chat on success. 671/* Return the number of peers in the group chat on success.
@@ -665,6 +675,7 @@ int tox_group_number_peers(const Tox *tox, int groupnumber)
665{ 675{
666 const Messenger *m = tox; 676 const Messenger *m = tox;
667 //return group_number_peers(m, groupnumber); 677 //return group_number_peers(m, groupnumber);
678 return -1;
668} 679}
669 680
670/* List all the peers in the group chat. 681/* List all the peers in the group chat.
@@ -682,6 +693,7 @@ int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX
682{ 693{
683 const Messenger *m = tox; 694 const Messenger *m = tox;
684 //return group_names(m, groupnumber, names, lengths, length); 695 //return group_names(m, groupnumber, names, lengths, length);
696 return -1;
685} 697}
686 698
687/* Return the number of chats in the instance m. 699/* Return the number of chats in the instance m.
@@ -691,6 +703,7 @@ uint32_t tox_count_chatlist(const Tox *tox)
691{ 703{
692 const Messenger *m = tox; 704 const Messenger *m = tox;
693 //return count_chatlist(m); 705 //return count_chatlist(m);
706 return 0;
694} 707}
695 708
696/* Copy a list of valid chat IDs into the array out_list. 709/* Copy a list of valid chat IDs into the array out_list.
@@ -702,6 +715,7 @@ uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size)
702{ 715{
703 const Messenger *m = tox; 716 const Messenger *m = tox;
704 //return copy_chatlist(m, out_list, list_size); 717 //return copy_chatlist(m, out_list, list_size);
718 return 0;
705} 719}
706 720
707 721
@@ -947,7 +961,14 @@ Tox *tox_new(Tox_Options *options)
947 } 961 }
948 } 962 }
949 963
950 return new_messenger(&m_options); 964 Messenger *m = new_messenger(&m_options);
965
966 if (!new_groupchats(m)) {
967 kill_messenger(m);
968 return NULL;
969 }
970
971 return m;
951} 972}
952 973
953/* Run this before closing shop. 974/* Run this before closing shop.
@@ -956,6 +977,7 @@ Tox *tox_new(Tox_Options *options)
956void tox_kill(Tox *tox) 977void tox_kill(Tox *tox)
957{ 978{
958 Messenger *m = tox; 979 Messenger *m = tox;
980 kill_groupchats(m->group_chat_object);
959 kill_messenger(m); 981 kill_messenger(m);
960} 982}
961 983