| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 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 | |
|---|
| 31 | namespace msg { class entity; } |
|---|
| 32 | |
|---|
| 33 | namespace 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 |
|---|