blob: 1d8ae429e3b11773135f5522356cf43875553245 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/*
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <QJsonDocument>
#include <QPixmap>
#include <QUrl>
#include "AliasesEventContent.h"
#include "AvatarEventContent.h"
#include "CanonicalAliasEventContent.h"
#include "CreateEventContent.h"
#include "HistoryVisibilityEventContent.h"
#include "JoinRulesEventContent.h"
#include "MemberEventContent.h"
#include "NameEventContent.h"
#include "PowerLevelsEventContent.h"
#include "TopicEventContent.h"
#include "Event.h"
#include "RoomEvent.h"
#include "StateEvent.h"
namespace events = matrix::events;
class RoomState
{
public:
// Calculate room data that are not immediatly accessible. Like room name and avatar.
//
// e.g If the room is 1-on-1 name and avatar should be extracted from a user.
void resolveName();
void resolveAvatar();
void parse(const QJsonObject &object);
inline QUrl getAvatar() const;
inline QString getName() const;
inline QString getTopic() const;
void removeLeaveMemberships();
void update(const RoomState &state);
QJsonObject serialize() const;
// The latest state events.
events::StateEvent<events::AliasesEventContent> aliases;
events::StateEvent<events::AvatarEventContent> avatar;
events::StateEvent<events::CanonicalAliasEventContent> canonical_alias;
events::StateEvent<events::CreateEventContent> create;
events::StateEvent<events::HistoryVisibilityEventContent> history_visibility;
events::StateEvent<events::JoinRulesEventContent> join_rules;
events::StateEvent<events::NameEventContent> name;
events::StateEvent<events::PowerLevelsEventContent> power_levels;
events::StateEvent<events::TopicEventContent> topic;
// Contains the m.room.member events for all the joined users.
QMap<QString, events::StateEvent<events::MemberEventContent>> memberships;
private:
QUrl avatar_;
QString name_;
// It defines the user whose avatar is used for the room. If the room has an avatar
// event this should be empty.
QString userAvatar_;
};
inline QString RoomState::getTopic() const
{
return topic.content().topic().simplified();
}
inline QString RoomState::getName() const
{
return name_;
}
inline QUrl RoomState::getAvatar() const
{
return avatar_;
}
|