]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/invite.h
Rewrite invite system
[user/henk/code/inspircd.git] / include / modules / invite.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2012, 2015 Attila Molnar <attilamolnar@hush.com>
5  *
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.
9  *
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
13  * details.
14  *
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/>.
17  */
18
19
20 #pragma once
21
22 namespace Invite
23 {
24         class APIBase;
25         class API;
26         class Invite;
27
28         typedef insp::intrusive_list<Invite, LocalUser> List;
29 }
30
31 class Invite::APIBase : public DataProvider
32 {
33  public:
34         APIBase(Module* parent);
35
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
43          */
44         virtual void Create(LocalUser* user, Channel* chan, time_t timeout) = 0;
45
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
50          */
51         virtual Invite* Find(LocalUser* user, Channel* chan) = 0;
52
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
56          */
57         virtual const List* GetList(LocalUser* user) = 0;
58
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
63          */
64         bool IsInvited(LocalUser* user, Channel* chan) { return (Find(user, chan) != NULL); }
65
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
70          */
71         virtual bool Remove(LocalUser* user, Channel* chan) = 0;
72 };
73
74 class Invite::API : public dynamic_reference<APIBase>
75 {
76  public:
77         API(Module* parent)
78                 : dynamic_reference<APIBase>(parent, "core_channel_invite")
79         {
80         }
81 };
82
83 /**
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.
86  */
87 class Invite::Invite : public insp::intrusive_list_node<Invite, LocalUser>, public insp::intrusive_list_node<Invite, Channel>
88 {
89  public:
90         /** User the invite is for
91          */
92         LocalUser* const user;
93
94         /** Channel where the user is invited to
95          */
96         Channel* const chan;
97
98         /** Check whether the invite will expire or not
99          * @return True if the invite is timed, false if it doesn't expire
100          */
101         bool IsTimed() const { return (expiretimer != NULL); }
102
103         friend class APIImpl;
104
105  private:
106         /** Timer handling expiration. If NULL this invite doesn't expire.
107          */
108         Timer* expiretimer;
109
110         /** Constructor, only available to the module providing the invite API (core_channel).
111          * To create Invites use InviteAPI::Create().
112          * @param user User being invited
113          * @param chan Channel the user is invited to
114          */
115         Invite(LocalUser* user, Channel* chan);
116
117         /** Destructor, only available to the module providing the invite API (core_channel).
118          * To remove Invites use InviteAPI::Remove().
119          */
120         ~Invite();
121 };