2017-05-07 17:15:38 +03:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2017-05-16 21:46:45 +03:00
|
|
|
#pragma once
|
2017-05-07 17:15:38 +03:00
|
|
|
|
2017-07-29 11:49:00 +03:00
|
|
|
#include <QJsonDocument>
|
2017-05-07 17:15:38 +03:00
|
|
|
#include <QPixmap>
|
2017-05-26 21:34:16 +03:00
|
|
|
#include <QUrl>
|
2017-05-07 17:15:38 +03:00
|
|
|
|
|
|
|
#include "AliasesEventContent.h"
|
|
|
|
#include "AvatarEventContent.h"
|
|
|
|
#include "CanonicalAliasEventContent.h"
|
|
|
|
#include "CreateEventContent.h"
|
|
|
|
#include "HistoryVisibilityEventContent.h"
|
|
|
|
#include "JoinRulesEventContent.h"
|
2017-05-26 21:34:16 +03:00
|
|
|
#include "MemberEventContent.h"
|
2017-05-07 17:15:38 +03:00
|
|
|
#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:
|
2017-10-28 20:46:34 +03:00
|
|
|
RoomState();
|
|
|
|
RoomState(const QJsonArray &events);
|
|
|
|
|
2017-10-01 12:11:33 +03:00
|
|
|
// Calculate room data that are not immediatly accessible. Like room name and
|
|
|
|
// avatar.
|
2017-08-26 13:49:16 +03:00
|
|
|
//
|
|
|
|
// 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);
|
|
|
|
|
2017-10-22 19:03:55 +03:00
|
|
|
QUrl getAvatar() const { return avatar_; };
|
|
|
|
QString getName() const { return name_; };
|
|
|
|
QString getTopic() const { return topic.content().topic().simplified(); };
|
2017-08-26 13:49:16 +03:00
|
|
|
|
|
|
|
void removeLeaveMemberships();
|
|
|
|
void update(const RoomState &state);
|
|
|
|
void updateFromEvents(const QJsonArray &events);
|
|
|
|
|
|
|
|
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.
|
2017-10-28 20:46:34 +03:00
|
|
|
using UserID = QString;
|
|
|
|
QMap<UserID, events::StateEvent<events::MemberEventContent>> memberships;
|
2017-05-26 21:34:16 +03:00
|
|
|
|
|
|
|
private:
|
2017-08-26 13:49:16 +03:00
|
|
|
QUrl avatar_;
|
|
|
|
QString name_;
|
2017-05-26 21:34:16 +03:00
|
|
|
|
2017-10-01 12:11:33 +03:00
|
|
|
// It defines the user whose avatar is used for the room. If the room has an
|
|
|
|
// avatar event this should be empty.
|
2017-08-26 13:49:16 +03:00
|
|
|
QString userAvatar_;
|
2017-05-07 17:15:38 +03:00
|
|
|
};
|