Wrote group chat invite code.
parent
4c6e739527
commit
f81176881f
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Håvard Pettersson <haavard.pettersson@gmail.com>
|
||||
*
|
||||
* This file is part of Tox-WeeChat.
|
||||
*
|
||||
* Tox-WeeChat is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tox-WeeChat is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tox-WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <weechat/weechat-plugin.h>
|
||||
#include <tox/tox.h>
|
||||
|
||||
#include "twc.h"
|
||||
#include "twc-list.h"
|
||||
#include "twc-profile.h"
|
||||
#include "twc-utils.h"
|
||||
|
||||
#include "twc-group-invite.h"
|
||||
|
||||
/**
|
||||
* Add a new group invite to a profile.
|
||||
*
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
int
|
||||
twc_group_chat_invite_add(struct t_twc_profile *profile,
|
||||
int32_t friend_number,
|
||||
const uint8_t *data,
|
||||
size_t size)
|
||||
{
|
||||
// create a new invite object
|
||||
struct t_twc_group_chat_invite *invite
|
||||
= malloc(sizeof(struct t_twc_group_chat_invite));
|
||||
if (!invite)
|
||||
return -1;
|
||||
|
||||
invite->profile = profile;
|
||||
invite->data = data;
|
||||
invite->data_size = size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept a group chat invite. Remove and free the invite.
|
||||
*/
|
||||
void
|
||||
twc_group_chat_invite_accept(struct t_twc_group_chat_invite *invite)
|
||||
{
|
||||
tox_join_groupchat(invite->profile->tox,
|
||||
invite->friend_number,
|
||||
invite->data,
|
||||
invite->data_size);
|
||||
twc_group_chat_invite_remove(invite);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove and free a group chat invite.
|
||||
*/
|
||||
void
|
||||
twc_group_chat_invite_remove(struct t_twc_group_chat_invite *invite)
|
||||
{
|
||||
twc_list_remove_with_data(invite->profile->group_chat_invites, invite);
|
||||
twc_group_chat_invite_free(invite);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get group chat invite with a given index.
|
||||
*/
|
||||
struct t_twc_group_chat_invite *
|
||||
twc_group_chat_invite_with_index(struct t_twc_profile *profile,
|
||||
int64_t index)
|
||||
{
|
||||
return twc_list_get(profile->group_chat_invites, index)->group_chat_invite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free a group chat invite.
|
||||
*/
|
||||
void
|
||||
twc_group_chat_invite_free(struct t_twc_group_chat_invite *invite)
|
||||
{
|
||||
free(invite);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free a list of group chat invites.
|
||||
*/
|
||||
void
|
||||
twc_group_chat_invite_free_list(struct t_twc_list *list)
|
||||
{
|
||||
struct t_twc_group_chat_invite *invite;
|
||||
while ((invite = twc_list_pop(list)))
|
||||
twc_group_chat_invite_free(invite);
|
||||
|
||||
free(list);
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Håvard Pettersson <haavard.pettersson@gmail.com>
|
||||
*
|
||||
* This file is part of Tox-WeeChat.
|
||||
*
|
||||
* Tox-WeeChat is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tox-WeeChat is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tox-WeeChat. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TOX_WEECHAT_GROUP_INVITE_H
|
||||
#define TOX_WEECHAT_GROUP_INVITE_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <tox/tox.h>
|
||||
|
||||
struct t_twc_list;
|
||||
|
||||
/**
|
||||
* Represents a group chat invite.
|
||||
*/
|
||||
struct t_twc_group_chat_invite
|
||||
{
|
||||
struct t_twc_profile *profile;
|
||||
|
||||
int32_t friend_number;
|
||||
const uint8_t *data;
|
||||
size_t data_size;
|
||||
};
|
||||
|
||||
int
|
||||
twc_group_chat_invite_add(struct t_twc_profile *profile,
|
||||
int32_t friend_number,
|
||||
const uint8_t *data,
|
||||
size_t size);
|
||||
|
||||
void
|
||||
twc_group_chat_invite_accept(struct t_twc_group_chat_invite *invite);
|
||||
|
||||
void
|
||||
twc_group_chat_invite_remove(struct t_twc_group_chat_invite *invite);
|
||||
|
||||
struct t_twc_group_chat_invite *
|
||||
twc_group_chat_invite_with_index(struct t_twc_profile *profile,
|
||||
int64_t index);
|
||||
|
||||
void
|
||||
twc_group_chat_invite_free(struct t_twc_group_chat_invite *invite);
|
||||
|
||||
void
|
||||
twc_group_chat_invite_free_list(struct t_twc_list *list);
|
||||
|
||||
#endif // TOX_WEECHAT_GROUP_INVITE_H
|
||||
|
Loading…
Reference in New Issue