Put group chat functions in the public API.

Group chats are not complete, they seem to work very well though.

This means that the functions will change.
This commit is contained in:
irungentoo 2013-09-12 20:29:30 -04:00
parent 41b162eb18
commit f8b979a92a
4 changed files with 136 additions and 9 deletions

View File

@ -354,7 +354,7 @@ void line_eval(Tox *m, char *line)
new_lines(idstring);
} else if (inpt_command == 'g') { //create new group chat
char msg[256];
sprintf(msg, "[g] Created new group chat with number: %u", add_groupchat(m));
sprintf(msg, "[g] Created new group chat with number: %u", tox_add_groupchat(m));
new_lines(msg);
} else if (inpt_command == 'i') { //invite friendnum to groupnum
char *posi[1];
@ -362,7 +362,7 @@ void line_eval(Tox *m, char *line)
int groupnumber = strtoul(*posi + 1, NULL, 0);
char msg[256];
sprintf(msg, "[g] Invited friend number %u to group number %u, returned: %u (0 means success)", friendnumber,
groupnumber, invite_friend(m, friendnumber, groupnumber));
groupnumber, tox_invite_friend(m, friendnumber, groupnumber));
new_lines(msg);
} else if (inpt_command == 'z') { //send message to groupnum
char *posi[1];
@ -371,7 +371,7 @@ void line_eval(Tox *m, char *line)
if (**posi != 0) {
char msg[256 + 1024];
sprintf(msg, "[g] sent message: %s to group num: %u returned: %u (0 means success)", *posi + 1, groupnumber,
group_message_send(m, groupnumber, (uint8_t *)*posi + 1, strlen(*posi + 1) + 1));
tox_group_message_send(m, groupnumber, (uint8_t *)*posi + 1, strlen(*posi + 1) + 1));
new_lines(msg);
}
@ -556,15 +556,15 @@ void print_help(void)
puts("\t-f\t-\tSpecify a keyfile to read (or write to) from.");
}
void print_invite(Messenger *m, int friendnumber, uint8_t *group_public_key, void *userdata)
void print_invite(Tox *m, int friendnumber, uint8_t *group_public_key, void *userdata)
{
char msg[256];
sprintf(msg, "[i] recieved group chat invite from: %u, auto accepting and joining. group number: %u", friendnumber,
join_groupchat(m, friendnumber, group_public_key));
tox_join_groupchat(m, friendnumber, group_public_key));
new_lines(msg);
}
void print_groupmessage(Messenger *m, int groupnumber, uint8_t *message, uint16_t length, void *userdata)
void print_groupmessage(Tox *m, int groupnumber, uint8_t *message, uint16_t length, void *userdata)
{
char msg[256 + length];
sprintf(msg, "[g] %u: %s", groupnumber, message);
@ -616,8 +616,8 @@ int main(int argc, char *argv[])
tox_callback_friendmessage(m, print_message, NULL);
tox_callback_namechange(m, print_nickchange, NULL);
tox_callback_statusmessage(m, print_statuschange, NULL);
m_callback_group_invite(m, print_invite, NULL);
m_callback_group_message(m, print_groupmessage, NULL);
tox_callback_group_invite(m, print_invite, NULL);
tox_callback_group_message(m, print_groupmessage, NULL);
initscr();
noecho();

View File

@ -31,7 +31,6 @@
#include <ctype.h>
#include "../toxcore/tox.h"
#include "../toxcore/Messenger.h" //TODO: remove this
#define STRING_LENGTH 256
#define HISTORY 50
#define PUB_KEY_BYTES 32

View File

@ -366,6 +366,81 @@ void tox_callback_connectionstatus(void *tox, void (*function)(Messenger *tox, i
m_callback_connectionstatus(m, function, userdata);
}
/**********GROUP CHAT FUNCTIONS: WARNING WILL BREAK A LOT************/
/* Set the callback for group invites.
*
* Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata)
*/
void tox_callback_group_invite(void *tox, void (*function)(Messenger *tox, int, uint8_t *, void *), void *userdata)
{
Messenger *m = tox;
m_callback_group_invite(m, function, userdata);
}
/* Set the callback for group messages.
*
* Function(Tox *tox, int groupnumber, uint8_t * message, uint16_t length, void *userdata)
*/
void tox_callback_group_message(void *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *),
void *userdata)
{
Messenger *m = tox;
m_callback_group_message(m, function, userdata);
}
/* Creates a new groupchat and puts it in the chats array.
*
* return group number on success.
* return -1 on failure.
*/
int tox_add_groupchat(void *tox)
{
Messenger *m = tox;
return add_groupchat(m);
}
/* Delete a groupchat from the chats array.
*
* return 0 on success.
* return -1 if failure.
*/
int tox_del_groupchat(void *tox, int groupnumber)
{
Messenger *m = tox;
return del_groupchat(m, groupnumber);
}
/* invite friendnumber to groupnumber
* return 0 on success
* return -1 on failure
*/
int tox_invite_friend(void *tox, int friendnumber, int groupnumber)
{
Messenger *m = tox;
return invite_friend(m, friendnumber, groupnumber);
}
/* Join a group (you need to have been invited first.)
*
* returns group number on success
* returns -1 on failure.
*/
int tox_join_groupchat(void *tox, int friendnumber, uint8_t *friend_group_public_key)
{
Messenger *m = tox;
return join_groupchat(m, friendnumber, friend_group_public_key);
}
/* send a group message
* return 0 on success
* return -1 on failure
*/
int tox_group_message_send(void *tox, int groupnumber, uint8_t *message, uint32_t length)
{
Messenger *m = tox;
return group_message_send(m, groupnumber, message, length);
}
/******************END OF GROUP CHAT FUNCTIONS************************/
/* Use this function to bootstrap the client.
* Sends a get nodes request to the given node with ip port and public_key.
*/

View File

@ -289,6 +289,59 @@ void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int, uint32_
*/
void tox_callback_connectionstatus(Tox *tox, void (*function)(Tox *tox, int, uint8_t, void *), void *userdata);
/**********GROUP CHAT FUNCTIONS: WARNING WILL BREAK A LOT************/
/* Set the callback for group invites.
*
* Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata)
*/
void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, void *), void *userdata);
/* Set the callback for group messages.
*
* Function(Tox *tox, int groupnumber, uint8_t * message, uint16_t length, void *userdata)
*/
void tox_callback_group_message(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *),
void *userdata);
/* Creates a new groupchat and puts it in the chats array.
*
* return group number on success.
* return -1 on failure.
*/
int tox_add_groupchat(Tox *tox);
/* Delete a groupchat from the chats array.
*
* return 0 on success.
* return -1 if failure.
*/
int tox_del_groupchat(Tox *tox, int groupnumber);
/* invite friendnumber to groupnumber
* return 0 on success
* return -1 on failure
*/
int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber);
/* Join a group (you need to have been invited first.)
*
* returns group number on success
* returns -1 on failure.
*/
int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_key);
/* send a group message
* return 0 on success
* return -1 on failure
*/
int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length);
/******************END OF GROUP CHAT FUNCTIONS************************/
/* Use this function to bootstrap the client.
* Sends a get nodes request to the given node with ip port and public_key.
*/