diff options
author | irungentoo <irungentoo@gmail.com> | 2013-11-03 17:39:49 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-11-03 17:39:49 -0500 |
commit | 2e6250ee44378fcee331ebb4db7f60dcee396464 (patch) | |
tree | fc56bf1a4ac520b1a923ded6700a32fb11d04155 /toxcore/Messenger.c | |
parent | 41e083c173f53fb760ab9a5b4bea5e5109d2fe0c (diff) |
The group chats we invite a friend to are now stored.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index be3d82e0..c73161d3 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -868,13 +868,36 @@ int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *nam | |||
868 | 868 | ||
869 | return group_peername(m->chats[groupnumber], peernumber, name); | 869 | return group_peername(m->chats[groupnumber], peernumber, name); |
870 | } | 870 | } |
871 | |||
872 | /* Store the fact that we invited a specific friend. | ||
873 | */ | ||
874 | static void group_store_friendinvite(Messenger *m, int friendnumber, int groupnumber) | ||
875 | { | ||
876 | /* Add 1 to the groupchat number because 0 (default value in invited_groups) is a valid groupchat number */ | ||
877 | m->friendlist[friendnumber].invited_groups[m->friendlist[friendnumber].invited_groups_num % MAX_INVITED_GROUPS] = | ||
878 | groupnumber + 1; | ||
879 | ++m->friendlist[friendnumber].invited_groups_num; | ||
880 | } | ||
881 | |||
871 | /* return 1 if that friend was invited to the group | 882 | /* return 1 if that friend was invited to the group |
872 | * return 0 if the friend was not or error. | 883 | * return 0 if the friend was not or error. |
873 | */ | 884 | */ |
874 | static uint8_t group_invited(Messenger *m, int friendnumber, int groupnumber) | 885 | static uint8_t group_invited(Messenger *m, int friendnumber, int groupnumber) |
875 | { | 886 | { |
876 | //TODO: this function; | 887 | |
877 | return 1; | 888 | uint32_t i; |
889 | uint16_t num = MAX_INVITED_GROUPS; | ||
890 | |||
891 | if (MAX_INVITED_GROUPS > m->friendlist[friendnumber].invited_groups_num) | ||
892 | num = m->friendlist[friendnumber].invited_groups_num; | ||
893 | |||
894 | for (i = 0; i < num; ++i) { | ||
895 | if (m->friendlist[friendnumber].invited_groups[i] == groupnumber + 1) { | ||
896 | return 1; | ||
897 | } | ||
898 | } | ||
899 | |||
900 | return 0; | ||
878 | } | 901 | } |
879 | 902 | ||
880 | /* invite friendnumber to groupnumber | 903 | /* invite friendnumber to groupnumber |
@@ -892,7 +915,8 @@ int invite_friend(Messenger *m, int friendnumber, int groupnumber) | |||
892 | if (m->friendlist[friendnumber].status == NOFRIEND || m->chats[groupnumber] == NULL) | 915 | if (m->friendlist[friendnumber].status == NOFRIEND || m->chats[groupnumber] == NULL) |
893 | return -1; | 916 | return -1; |
894 | 917 | ||
895 | //TODO: store invited friends. | 918 | group_store_friendinvite(m, friendnumber, groupnumber); |
919 | |||
896 | if (write_cryptpacket_id(m, friendnumber, PACKET_ID_INVITE_GROUPCHAT, m->chats[groupnumber]->self_public_key, | 920 | if (write_cryptpacket_id(m, friendnumber, PACKET_ID_INVITE_GROUPCHAT, m->chats[groupnumber]->self_public_key, |
897 | crypto_box_PUBLICKEYBYTES) == 0) | 921 | crypto_box_PUBLICKEYBYTES) == 0) |
898 | return -1; | 922 | return -1; |