root/db/msg.hh

Revision 2114058982a08f59f0f312544a16250eceab0098, 3.9 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 17 months ago)

#14: Support moderators with kill/mark-as-spam and resurrection powers

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

  • Property mode set to 100644
Line 
1/*  This file is part of Alue, the multiprotocol Internet discussion daemon
2
3    Copyright © 2009, 2010, 2011 Antti-Juhani Kaijanaho
4
5    Alue is free software: you can redistribute it and/or modify it
6    under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    Alue is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with Alue.  If not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20#ifndef GUARD_MSG_MSG_HH
21#define GUARD_MSG_MSG_HH
22
23#include "../db/article_number_type.hh"
24#include "../util.hh"
25
26#include <boost/shared_ptr.hpp>
27#include <boost/tuple/tuple.hpp>
28#include <list>
29#include <map>
30
31namespace msg { class entity; }
32
33namespace db
34{
35
36        class group; class user; class thread_node;
37
38        class msg
39        {
40        public:
41                struct moderation
42                {
43                        const enum kind_type { CLEAR, KILL, SPAM } kind;
44                        const boost::shared_ptr<const user> u;
45                        const std::string reason;
46
47                        moderation(kind_type k,
48                                   boost::shared_ptr<const user> u,
49                                   std::string reason)
50                                : kind(k)
51                                , u(u)
52                                , reason(reason)
53                                {}
54
55                        bool is_censure() const { return kind != CLEAR; }
56                };
57
58                typedef boost::shared_ptr<msg> ptr;
59                typedef boost::shared_ptr<const msg> const_ptr;
60
61                typedef std::map<boost::shared_ptr<group>,
62                                 article_number_type>
63                xref_type;
64
65                explicit msg(std::string msgid,
66                             boost::shared_ptr< ::msg::entity >,
67                             boost::shared_ptr<user>);
68                explicit msg(boost::shared_ptr< ::msg::entity >,
69                             boost::shared_ptr<user>);
70
71                void moderate(moderation m) { mods.push_back(m); }
72
73                bool is_censured() const 
74                        { return !mods.empty() && mods.back().is_censure(); }
75
76                boost::shared_ptr<const user> censor() const {
77                        boost::shared_ptr<const user> rv;
78                        if (!mods.empty()) rv = mods.back().u;
79                        return rv;
80                }
81
82                const std::list<moderation> &get_moderations() const
83                        { return mods; }
84
85                boost::shared_ptr<const ::msg::entity> get_entity() const
86                        { return actual; }
87
88                std::list<std::string> get_newsgroups() const;
89
90                const xref_type &get_xref() const
91                        { return the_xref; }
92
93                std::string get_xref_field(bool full) const;
94
95                std::string msgid() const { return the_msgid; }
96
97                void xref(boost::shared_ptr<group> gr,
98                          article_number_type n)
99                        { the_xref[gr] = n; }
100
101                boost::shared_ptr<const user> get_poster() const {
102                        return poster;
103                }
104
105                bool reading_authz(boost::shared_ptr<const user> u) const;
106                bool posting_authz(boost::shared_ptr<const user> u) const;
107        private:
108                std::string the_msgid;
109                xref_type the_xref;
110                boost::shared_ptr< ::msg::entity > actual;
111                boost::shared_ptr<user> poster;
112                std::list<moderation> mods;
113        };
114       
115};
116
117#endif /* GUARD_MSG_MSG_HH */
Note: See TracBrowser for help on using the browser.