Add accept/reject and use .cache

This commit is contained in:
Black Hat
2018-08-17 12:55:57 +08:00
parent 6f527402e0
commit 43e0ccaf2f
8 changed files with 95 additions and 41 deletions

View File

@@ -145,3 +145,10 @@ void Controller::saveFileAs(Room* room, QString eventId) {
if (!fileName.isEmpty())
room->downloadFile(eventId, QUrl::fromLocalFile(fileName));
}
void Controller::acceptRoom(Room* room) { room->setJoinState(JoinState::Join); }
void Controller::rejectRoom(Room* room) {
room->setJoinState(JoinState::Leave);
forgetRoom(room->id());
}

View File

@@ -5,9 +5,9 @@
#include "roomlistmodel.h"
#include "user.h"
#include <QObject>
#include <QApplication>
#include <QMimeDatabase>
#include <QObject>
using namespace QMatrixClient;
@@ -111,6 +111,8 @@ class Controller : public QObject {
void createDirectChat(const QString& userID);
void copyToClipboard(const QString& text);
void saveFileAs(Room* room, QString eventId);
void acceptRoom(Room* room);
void rejectRoom(Room* room);
};
#endif // CONTROLLER_H

View File

@@ -4,11 +4,11 @@
#include <QQmlContext>
#include "controller.h"
#include "emojimodel.h"
#include "imageprovider.h"
#include "messageeventmodel.h"
#include "room.h"
#include "roomlistmodel.h"
#include "emojimodel.h"
#include "csapi/joining.h"
#include "csapi/leaving.h"
@@ -30,7 +30,9 @@ int main(int argc, char *argv[]) {
qmlRegisterType<RoomListModel>("Matrique", 0, 1, "RoomListModel");
qmlRegisterType<MessageEventModel>("Matrique", 0, 1, "MessageEventModel");
qmlRegisterType<EmojiModel>("Matrique", 0, 1, "EmojiModel");
qmlRegisterUncreatableType<RoomMessageEvent>("Matrique", 0, 1, "RoomMessageEvent", "ENUM");
qmlRegisterUncreatableType<RoomMessageEvent>("Matrique", 0, 1,
"RoomMessageEvent", "ENUM");
qmlRegisterUncreatableType<RoomType>("Matrique", 0, 1, "RoomType", "ENUM");
QQmlApplicationEngine engine;

View File

@@ -33,8 +33,6 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const {
return roles;
}
MessageEventModel::~MessageEventModel() {}
MessageEventModel::MessageEventModel(QObject* parent)
: QAbstractListModel(parent), m_currentRoom(nullptr) {
using namespace QMatrixClient;
@@ -44,6 +42,8 @@ MessageEventModel::MessageEventModel(QObject* parent)
"Matrique", 0, 1, "EventStatus", "EventStatus is not an creatable type");
}
MessageEventModel::~MessageEventModel() {}
void MessageEventModel::setRoom(QMatrixClient::Room* room) {
if (room == m_currentRoom) return;
@@ -587,8 +587,9 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
}
}
if (evt.isRedacted())
return Settings().value("UI/show_redacted").toBool()
? EventStatus::Redacted : EventStatus::Hidden;
return Settings().value("UI/show_redacted").toBool()
? EventStatus::Redacted
: EventStatus::Hidden;
if (evt.isStateEvent() &&
static_cast<const StateEventBase&>(evt).repeatsState() &&

View File

@@ -5,6 +5,7 @@
#include <QtCore/QDebug>
#include <QtGui/QBrush>
#include <QtGui/QColor>
#include <QtQuick>
RoomListModel::RoomListModel(QObject* parent) : QAbstractListModel(parent) {}
@@ -136,33 +137,22 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const {
return QVariant();
}
Room* room = m_rooms.at(index.row());
if (role == NameRole) {
return room->displayName();
}
if (role == NameRole) return room->displayName();
if (role == AvatarRole) {
if (room->avatarUrl().toString() != "") {
return room->avatarUrl();
}
return QVariant();
}
if (role == TopicRole) {
return room->topic();
}
if (role == TopicRole) return room->topic();
if (role == CategoryRole) {
// if (!room->isDirectChat())
// qDebug() << room->displayName() << "is not direct.";
if (room->isFavourite()) return "Favorites";
if (room->isDirectChat()) return "People";
if (room->isLowPriority()) return "Low Priorities";
return "Rooms";
}
if (role == HighlightRole) {
if (room->highlightCount() > 0) return QBrush(QColor("orange"));
return QVariant();
}
if (role == UnreadCountRole) {
return room->unreadCount();
if (room->joinState() == JoinState::Invite) return RoomType::Invited;
if (room->isFavourite()) return RoomType::Favorite;
if (room->isDirectChat()) return RoomType::Direct;
if (room->isLowPriority()) return RoomType::Deprioritized;
return RoomType::Normal;
}
if (role == UnreadCountRole) return room->unreadCount();
return QVariant();
}
@@ -192,7 +182,6 @@ QHash<int, QByteArray> RoomListModel::roleNames() const {
roles[AvatarRole] = "avatar";
roles[TopicRole] = "topic";
roles[CategoryRole] = "category";
roles[HighlightRole] = "highlight";
roles[UnreadCountRole] = "unreadCount";
return roles;
}

View File

@@ -7,6 +7,20 @@
using namespace QMatrixClient;
class RoomType : public QObject {
Q_OBJECT
public:
enum Types {
Invited = 1,
Favorite,
Normal,
Direct,
Deprioritized,
};
REGISTER_ENUM(Types)
};
class RoomListModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(Connection* connection READ getConnection WRITE setConnection)
@@ -17,8 +31,7 @@ class RoomListModel : public QAbstractListModel {
AvatarRole,
TopicRole,
CategoryRole,
HighlightRole,
UnreadCountRole
UnreadCountRole,
};
RoomListModel(QObject* parent = 0);