2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 typedef insp::intrusive_list<Invite, LocalUser> List;
32 class Invite::APIBase : public DataProvider
35 APIBase(Module* parent);
37 /** Create or extend an Invite.
38 * When a user is invited to join a channel either a new Invite object is created or
39 * or the expiration timestamp is updated if there is already a pending Invite for
40 * the given (user, channel) pair and the new expiration time is further than the current.
41 * @param user Target user
42 * @param chan Target channel
43 * @param timeout Timestamp when the invite should expire, 0 for no expiration
45 virtual void Create(LocalUser* user, Channel* chan, time_t timeout) = 0;
47 /** Retrieves the Invite object for the given (user, channel) pair
48 * @param user Target user
49 * @param chan Target channel
50 * @return Invite object for the given (channel, user) pair if it exists, NULL otherwise
52 virtual Invite* Find(LocalUser* user, Channel* chan) = 0;
54 /** Returns the list of channels a user has been invited to but has not yet joined.
55 * @param user User whose invite list to retrieve
56 * @return List of channels the user is invited to or NULL if the list is empty
58 virtual const List* GetList(LocalUser* user) = 0;
60 /** Check if a user is invited to a channel
61 * @param user User to check
62 * @param chan Channel to check
63 * @return True if the user is invited to the channel, false otherwise
65 bool IsInvited(LocalUser* user, Channel* chan) { return (Find(user, chan) != NULL); }
67 /** Removes an Invite if it exists
68 * @param user User whose invite to remove
69 * @param chan Channel to remove the invite to
70 * @return True if the user was invited to the channel and the invite was removed, false if the user wasn't invited
72 virtual bool Remove(LocalUser* user, Channel* chan) = 0;
75 class Invite::API : public dynamic_reference<APIBase>
79 : dynamic_reference<APIBase>(parent, "core_channel_invite")
85 * The Invite class contains all data about a pending invite.
86 * Invite objects are referenced from the user and the channel they belong to.
88 class Invite::Invite : public insp::intrusive_list_node<Invite, LocalUser>, public insp::intrusive_list_node<Invite, Channel>
91 /** User the invite is for
93 LocalUser* const user;
95 /** Channel where the user is invited to
99 /** Check whether the invite will expire or not
100 * @return True if the invite is timed, false if it doesn't expire
102 bool IsTimed() const { return (expiretimer != NULL); }
104 /** Serialize this object
105 * @param human Whether to serialize for human consumption or not.
106 * @param show_chans True to include channel in the output, false to include the nick/uuid
107 * @param out Output will be appended to this string
109 void Serialize(bool human, bool show_chans, std::string& out);
111 friend class APIImpl;
114 /** Timer handling expiration. If NULL this invite doesn't expire.
118 /** Constructor, only available to the module providing the invite API (core_channel).
119 * To create Invites use InviteAPI::Create().
120 * @param user User being invited
121 * @param chan Channel the user is invited to
123 Invite(LocalUser* user, Channel* chan);
125 /** Destructor, only available to the module providing the invite API (core_channel).
126 * To remove Invites use InviteAPI::Remove().