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

@ -1,6 +1,7 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.2
import Qt.labs.platform 1.0
Item {
property bool openOnFinished: false
@ -27,7 +28,7 @@ Item {
else
{
openOnFinished = true
currentRoom.downloadFile(eventId)
currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_") + ".tmp")
}
}

View File

@ -89,15 +89,36 @@ Item {
pattern: searchField.text
caseSensitivity: Qt.CaseInsensitive
}
proxyRoles: [
ExpressionRole { name: "isFavorite"; expression: category === "Favorites" },
ExpressionRole { name: "isDirectChat"; expression: category === "People" },
ExpressionRole { name: "isLowPriority"; expression: category === "Low Priorities" }
]
proxyRoles: ExpressionRole {
name: "display"
expression: {
switch (category) {
case 1: return "Invited"
case 2: return "Favorites"
case 3: return "Rooms"
case 4: return "People"
case 5: return "Low Priorities"
}
}
}
sorters: [
RoleSorter { roleName: "isFavorite"; sortOrder: Qt.DescendingOrder },
RoleSorter { roleName: "isLowPriority" },
RoleSorter { roleName: "isDirectChat" },
ExpressionSorter {
expression: {
var leftCategory = modelLeft.category
var rightCategory = modelRight.category
if (leftCategory === 1) return true
if (rightCategory === 1) return false
if (leftCategory === 2) return true
if (rightCategory === 2) return false
if (leftCategory === 5) return false
if (rightCategory === 5) return true
if (leftCategory === 4) return false
if (rightCategory === 4) return true
return true
}
},
StringSorter { roleName: "name" }
]
}
@ -126,7 +147,7 @@ Item {
height: 80
onPressed: listView.currentIndex = index
onPressAndHold: roomListMenu.popup()
onClicked: enterRoom()
onClicked: category === RoomType.Invited ? inviteDialog.open() : enterRoom()
ToolTip.visible: mini && hovered
ToolTip.text: name
@ -180,7 +201,7 @@ Item {
}
}
section.property: "category"
section.property: "display"
section.criteria: ViewSection.FullString
section.delegate: Label {
width: parent.width
@ -192,11 +213,29 @@ Item {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: mini ? Text.AlignHCenter : undefined
background: Rectangle {
anchors.fill:parent
anchors.fill: parent
color: Material.theme == Material.Light ? "#dbdbdb" : "#363636"
}
}
Dialog {
id: inviteDialog
parent: ApplicationWindow.overlay
x: (window.width - width) / 2
y: (window.height - height) / 2
width: 360
title: "Action Required"
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel
contentItem: Label { text: "Accept this invitation?" }
onAccepted: matriqueController.acceptRoom(currentRoom)
onRejected: matriqueController.rejectRoom(currentRoom)
}
Menu {
id: roomListMenu

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;
@ -588,7 +588,8 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
}
if (evt.isRedacted())
return Settings().value("UI/show_redacted").toBool()
? EventStatus::Redacted : EventStatus::Hidden;
? 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);