The group chats we invite a friend to are now stored.

This commit is contained in:
irungentoo 2013-11-03 17:39:49 -05:00
parent 41e083c173
commit 2e6250ee44
2 changed files with 32 additions and 3 deletions

View File

@ -868,13 +868,36 @@ int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *nam
return group_peername(m->chats[groupnumber], peernumber, name);
}
/* Store the fact that we invited a specific friend.
*/
static void group_store_friendinvite(Messenger *m, int friendnumber, int groupnumber)
{
/* Add 1 to the groupchat number because 0 (default value in invited_groups) is a valid groupchat number */
m->friendlist[friendnumber].invited_groups[m->friendlist[friendnumber].invited_groups_num % MAX_INVITED_GROUPS] =
groupnumber + 1;
++m->friendlist[friendnumber].invited_groups_num;
}
/* return 1 if that friend was invited to the group
* return 0 if the friend was not or error.
*/
static uint8_t group_invited(Messenger *m, int friendnumber, int groupnumber)
{
//TODO: this function;
uint32_t i;
uint16_t num = MAX_INVITED_GROUPS;
if (MAX_INVITED_GROUPS > m->friendlist[friendnumber].invited_groups_num)
num = m->friendlist[friendnumber].invited_groups_num;
for (i = 0; i < num; ++i) {
if (m->friendlist[friendnumber].invited_groups[i] == groupnumber + 1) {
return 1;
}
}
return 0;
}
/* invite friendnumber to groupnumber
@ -892,7 +915,8 @@ int invite_friend(Messenger *m, int friendnumber, int groupnumber)
if (m->friendlist[friendnumber].status == NOFRIEND || m->chats[groupnumber] == NULL)
return -1;
//TODO: store invited friends.
group_store_friendinvite(m, friendnumber, groupnumber);
if (write_cryptpacket_id(m, friendnumber, PACKET_ID_INVITE_GROUPCHAT, m->chats[groupnumber]->self_public_key,
crypto_box_PUBLICKEYBYTES) == 0)
return -1;

View File

@ -52,6 +52,9 @@
#define PACKET_ID_JOIN_GROUPCHAT 145
#define PACKET_ID_ACCEPT_GROUPCHAT 146
/* Max number of groups we can invite someone at the same time to. */
#define MAX_INVITED_GROUPS 64
/* Status definitions. */
enum {
NOFRIEND,
@ -148,6 +151,8 @@ typedef struct {
uint64_t ping_lastsent;
struct File_Transfers file_sending[MAX_CONCURRENT_FILE_PIPES];
struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
int invited_groups[MAX_INVITED_GROUPS];
uint16_t invited_groups_num;
} Friend;
typedef struct Messenger {