2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2012, 2015 Attila Molnar <attilamolnar@hush.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 typedef insp::intrusive_list<Invite, LocalUser> List;
31 class Invite::APIBase : public DataProvider
34 APIBase(Module* parent);
36 /** Create or extend an Invite.
37 * When a user is invited to join a channel either a new Invite object is created or
38 * or the expiration timestamp is updated if there is already a pending Invite for
39 * the given (user, channel) pair and the new expiration time is further than the current.
40 * @param user Target user
41 * @param chan Target channel
42 * @param timeout Timestamp when the invite should expire, 0 for no expiration
44 virtual void Create(LocalUser* user, Channel* chan, time_t timeout) = 0;
46 /** Retrieves the Invite object for the given (user, channel) pair
47 * @param user Target user
48 * @param chan Target channel
49 * @return Invite object for the given (channel, user) pair if it exists, NULL otherwise
51 virtual Invite* Find(LocalUser* user, Channel* chan) = 0;
53 /** Returns the list of channels a user has been invited to but has not yet joined.
54 * @param user User whose invite list to retrieve
55 * @return List of channels the user is invited to or NULL if the list is empty
57 virtual const List* GetList(LocalUser* user) = 0;
59 /** Check if a user is invited to a channel
60 * @param user User to check
61 * @param chan Channel to check
62 * @return True if the user is invited to the channel, false otherwise
64 bool IsInvited(LocalUser* user, Channel* chan) { return (Find(user, chan) != NULL); }
66 /** Removes an Invite if it exists
67 * @param user User whose invite to remove
68 * @param chan Channel to remove the invite to
69 * @return True if the user was invited to the channel and the invite was removed, false if the user wasn't invited
71 virtual bool Remove(LocalUser* user, Channel* chan) = 0;
74 class Invite::API : public dynamic_reference<APIBase>
78 : dynamic_reference<APIBase>(parent, "core_channel_invite")
84 * The Invite class contains all data about a pending invite.
85 * Invite objects are referenced from the user and the channel they belong to.
87 class Invite::Invite : public insp::intrusive_list_node<Invite, LocalUser>, public insp::intrusive_list_node<Invite, Channel>
90 /** User the invite is for
92 LocalUser* const user;
94 /** Channel where the user is invited to
98 /** Check whether the invite will expire or not
99 * @return True if the invite is timed, false if it doesn't expire
101 bool IsTimed() const { return (expiretimer != NULL); }
103 /** Serialize this object
104 * @param human Whether to serialize for human consumption or not.
105 * @param show_chans True to include channel in the output, false to include the nick/uuid
106 * @param out Output will be appended to this string
108 void Serialize(bool human, bool show_chans, std::string& out);
110 friend class APIImpl;
113 /** Timer handling expiration. If NULL this invite doesn't expire.
117 /** Constructor, only available to the module providing the invite API (core_channel).
118 * To create Invites use InviteAPI::Create().
119 * @param user User being invited
120 * @param chan Channel the user is invited to
122 Invite(LocalUser* user, Channel* chan);
124 /** Destructor, only available to the module providing the invite API (core_channel).
125 * To remove Invites use InviteAPI::Remove().