]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/invite.h
Remove the Kiwi links from the readme.
[user/henk/code/inspircd.git] / include / modules / invite.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
6  *
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.
10  *
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
14  * details.
15  *
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/>.
18  */
19
20
21 #pragma once
22
23 namespace Invite
24 {
25         class APIBase;
26         class API;
27         class Invite;
28
29         typedef insp::intrusive_list<Invite, LocalUser> List;
30 }
31
32 class Invite::APIBase : public DataProvider
33 {
34  public:
35         APIBase(Module* parent);
36
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
44          */
45         virtual void Create(LocalUser* user, Channel* chan, time_t timeout) = 0;
46
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
51          */
52         virtual Invite* Find(LocalUser* user, Channel* chan) = 0;
53
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
57          */
58         virtual const List* GetList(LocalUser* user) = 0;
59
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
64          */
65         bool IsInvited(LocalUser* user, Channel* chan) { return (Find(user, chan) != NULL); }
66
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
71          */
72         virtual bool Remove(LocalUser* user, Channel* chan) = 0;
73 };
74
75 class Invite::API : public dynamic_reference<APIBase>
76 {
77  public:
78         API(Module* parent)
79                 : dynamic_reference<APIBase>(parent, "core_channel_invite")
80         {
81         }
82 };
83
84 /**
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.
87  */
88 class Invite::Invite : public insp::intrusive_list_node<Invite, LocalUser>, public insp::intrusive_list_node<Invite, Channel>
89 {
90  public:
91         /** User the invite is for
92          */
93         LocalUser* const user;
94
95         /** Channel where the user is invited to
96          */
97         Channel* const chan;
98
99         /** Check whether the invite will expire or not
100          * @return True if the invite is timed, false if it doesn't expire
101          */
102         bool IsTimed() const { return (expiretimer != NULL); }
103
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
108          */
109         void Serialize(bool human, bool show_chans, std::string& out);
110
111         friend class APIImpl;
112
113  private:
114         /** Timer handling expiration. If NULL this invite doesn't expire.
115          */
116         Timer* expiretimer;
117
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
122          */
123         Invite(LocalUser* user, Channel* chan);
124
125         /** Destructor, only available to the module providing the invite API (core_channel).
126          * To remove Invites use InviteAPI::Remove().
127          */
128         ~Invite();
129 };