Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
36 KB
Referenced Files
None
Subscribers
None
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 18f4d6e..a3a98c6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,19 +1,20 @@
set(kazv_SRCS
main.cpp
matrix-sdk.cpp
matrix-room.cpp
matrix-room-list.cpp
matrix-room-timeline.cpp
+ matrix-room-member.cpp
matrix-event.cpp
meta-types.cpp
resources.qrc
)
add_executable(kazv ${kazv_SRCS})
target_link_libraries(kazv
libkazv::kazvall
libkazv::kazvbase
libkazv::kazvjob
Threads::Threads
Qt5::Core Qt5::Gui Qt5::Qml Qt5::Quick Qt5::QuickControls2 Qt5::Svg KF5::I18n)
install(TARGETS kazv ${KF5_INSTALL_TARGETS_DEFAULT_ARGS})
diff --git a/src/contents/ui/EventView.qml b/src/contents/ui/EventView.qml
new file mode 100644
index 0000000..55b882c
--- /dev/null
+++ b/src/contents/ui/EventView.qml
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
+ *
+ * This file is part of kazv.
+ *
+ * kazv is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * kazv 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with kazv. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+import QtQuick 2.2
+import QtQuick.Layouts 1.15
+import QtQuick.Controls 2.15
+
+import org.kde.kirigami 2.13 as Kirigami
+
+Item {
+ property var event
+ property var sender
+
+ property var iconSize: Kirigami.Units.iconSizes.large
+ property var senderNameSize: Kirigami.Units.gridUnit * 1.2
+
+ height: layout.implicitHeight
+ //padding: Kirigami.Units.largeSpacing
+
+ ColumnLayout {
+ id: layout
+ RowLayout {
+ width: parent.width
+ Layout.leftMargin: Kirigami.Units.largeSpacing
+ Layout.rightMargin: Kirigami.Units.largeSpacing
+ Layout.topMargin: Kirigami.Units.largeSpacing
+
+ Kirigami.Avatar {
+ //width: iconSize
+ //height: iconSize
+ Layout.alignment: Qt.AlignTop
+ sourceSize: iconSize
+ source: sender.avatarMxcUri ? matrixSdk.mxcUriToHttp(sender.avatarMxcUri) : 'user-none'
+ name: sender.name || sender.userId
+ }
+
+ ColumnLayout {
+ Layout.fillWidth: true
+ Layout.leftMargin: Kirigami.Units.largeSpacing
+ Label {
+ text: sender.name || sender.userId
+ }
+
+ Label {
+ text: getText()
+ leftPadding: Kirigami.Units.largeSpacing
+ }
+ }
+ }
+ }
+
+ function getText() {
+ if (event.type == "m.room.message") {
+ if (event.content.msgtype == "m.text") {
+ return event.content.body
+ }
+ }
+ return "Not supported"
+ }
+}
diff --git a/src/contents/ui/RoomListView.qml b/src/contents/ui/RoomListView.qml
index 9a67683..c57ca91 100644
--- a/src/contents/ui/RoomListView.qml
+++ b/src/contents/ui/RoomListView.qml
@@ -1,70 +1,84 @@
/*
* Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
*
* This file is part of kazv.
*
* kazv is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* kazv 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with kazv. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.2
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import org.kde.kirigami 2.13 as Kirigami
ListView {
id: roomListView
property var roomList
property var roomIds: roomList.roomIds
+ property var iconSize: Kirigami.Units.iconSizes.medium
+
//matrixSdk.currentRoomId
width: parent.width
Layout.fillHeight: true
model: roomList.count
Layout.minimumHeight: childrenRect.height
currentIndex: roomIds.indexOf(matrixSdk.currentRoomId)
/* onModelChanged: currentIndex = Qt.binding(function() { */
/* print("current room id is: `%1`".arg(matrixSdk.currentRoomId)) */
/* print("index is: ", roomIds.indexOf(matrixSdk.currentRoomId)) */
/* return roomIds.indexOf(matrixSdk.currentRoomId) */
/* }) */
/* onCurrentIndexChanged: { */
/* root.roomPage.roomId = roomList.roomIdAt(currentIndex) */
/* } */
+
delegate: Kirigami.SwipeListItem {
property var item: roomList.at(index)
onClicked: {
matrixSdk.currentRoomId = item.roomId
}
checkable: true
checked: matrixSdk.currentRoomId == item.roomId
autoExclusive: true
- Label {
- text: i18n("%1 (%2)", item.name, item.roomId)
+ RowLayout {
+ width: parent.width
+
+ Kirigami.Icon {
+ width: iconSize
+ height: iconSize
+ source: item.avatarMxcUri ? matrixSdk.mxcUriToHttp(item.avatarMxcUri) : "system-reboot"
+ }
+
+ Label {
+ text: i18n("%1 (%2)", item.name, item.roomId)
+ Layout.fillWidth: true
+ }
}
actions: [
Kirigami.Action {
text: i18n("Set as favourite")
iconName: "non-starred-symbolic"
onTriggered: showPassiveNotification(i18n("Set %1 as favourite", item.name))
}
]
}
}
diff --git a/src/contents/ui/RoomTimelineView.qml b/src/contents/ui/RoomTimelineView.qml
index 2f0f590..4a503bc 100644
--- a/src/contents/ui/RoomTimelineView.qml
+++ b/src/contents/ui/RoomTimelineView.qml
@@ -1,65 +1,73 @@
/*
* Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
*
* This file is part of kazv.
*
* kazv is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* kazv 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with kazv. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.2
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import org.kde.kirigami 2.13 as Kirigami
ListView {
id: roomTimelineView
property var timeline
property var eventIds: timeline.eventIds
property string selectedEventId
+ spacing: Kirigami.Units.largeSpacing
+
width: parent.width
Layout.fillHeight: true
model: timeline.count
Layout.minimumHeight: childrenRect.height
currentIndex: -1
//currentIndex: eventIds.indexOf(selectedEventId)
//onModelChanged: currentIndex = Qt.binding(function() { return eventIds.indexOf(selectedEventId) })
- delegate: Kirigami.BasicListItem {
- property var item: timeline.at(index)
- //onClicked: roomTimelineView.selectedEventId = item.eventId
- onClicked: {}
- checkable: false
- checked: false
- //onClicked: print("clicked room %1".arg(index))
- //checkable: true
- //checked: roomTimelineView.selectedEventId == item.eventId
- //autoExclusive: true
- Label {
- text: i18n("Message from %1 of type %2: %3", item.sender, item.type, item.content)
- }
-/* actions: [
- Kirigami.Action {
- text: i18n("Set as favourite")
- iconName: "non-starred-symbolic"
- onTriggered: showPassiveNotification(i18n("Set %1 as favourite", item.name))
- }
- ]*/
+ delegate: EventView {
+ event: timeline.at(index)
+ sender: room.member(event.sender)
}
+
+
+/* Kirigami.BasicListItem { */
+/* property var item: timeline.at(index) */
+/* //onClicked: roomTimelineView.selectedEventId = item.eventId */
+/* onClicked: {} */
+/* checkable: false */
+/* checked: false */
+/* //onClicked: print("clicked room %1".arg(index)) */
+/* //checkable: true */
+/* //checked: roomTimelineView.selectedEventId == item.eventId */
+/* //autoExclusive: true */
+/* Label { */
+/* text: i18n("Message from %1 of type %2: %3", item.sender, item.type, item.content) */
+/* } */
+/* /\* actions: [ */
+/* Kirigami.Action { */
+/* text: i18n("Set as favourite") */
+/* iconName: "non-starred-symbolic" */
+/* onTriggered: showPassiveNotification(i18n("Set %1 as favourite", item.name)) */
+/* } */
+/* ]*\/ */
+ /* } */
}
diff --git a/src/contents/ui/main.qml b/src/contents/ui/main.qml
index e8aefac..53d36e9 100644
--- a/src/contents/ui/main.qml
+++ b/src/contents/ui/main.qml
@@ -1,90 +1,97 @@
/*
* Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
*
* This file is part of kazv.
*
* kazv is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* kazv 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with kazv. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.1
import org.kde.kirigami 2.4 as Kirigami
import QtQuick.Controls 2.0 as Controls
import moe.kazv.mxc.kazv 0.0 as MK
import '.' as Kazv
Kirigami.ApplicationWindow {
id: root
property var matrixSdk: MK.MatrixSdk {
onLoginSuccessful: switchToMainPage()
property string currentRoomId: ""
}
property var roomList: matrixSdk.roomList()
title: i18n("kazv")
globalDrawer: Kirigami.GlobalDrawer {
title: i18n("kazv")
titleIcon: "applications-graphics"
actions: [
Kirigami.Action {
text: i18n("Switch to main page")
iconName: "view-list-icons"
onTriggered: switchToMainPage()
},
Kirigami.Action {
text: i18n("Action 1")
onTriggered: showPassiveNotification(i18n("Action 1 clicked"))
},
Kirigami.Action {
text: i18n("Action 2")
onTriggered: showPassiveNotification(i18n("Action 2 clicked"))
}
]
}
contextDrawer: Kirigami.ContextDrawer {
id: contextDrawer
}
pageStack.initialPage: Qt.resolvedUrl("LoginPage.qml")
property var mainPage: Kazv.MainPage {
id: mainPage
}
property var roomPage: Kazv.RoomPage {
id: roomPage
}
+ property var emptyPage: Kirigami.Page {
+ title: i18n("No rooms selected")
+ Controls.Label {
+ text: i18n("There is no room selected now.")
+ }
+ }
+
function activateRoomPage() {
roomPage.roomId = matrixSdk.currentRoomId
pageStack.push(roomPage)
}
function switchToMainPage() {
- pageStack.replace([mainPage, roomPage])
+ pageStack.replace([mainPage, emptyPage])
pageStack.currentIndex = 0
}
Connections {
target: matrixSdk
function onCurrentRoomIdChanged() {
activateRoomPage()
}
}
}
diff --git a/src/main.cpp b/src/main.cpp
index 2aed4f8..f965264 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,58 +1,60 @@
/*
* Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
*
* This file is part of kazv.
*
* kazv is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* kazv 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with kazv. If not, see <https://www.gnu.org/licenses/>.
*/
#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
#include <QUrl>
#include <KLocalizedContext>
#include "matrix-sdk.hpp"
#include "matrix-room-list.hpp"
#include "matrix-room.hpp"
#include "matrix-room-timeline.hpp"
+#include "matrix-room-member.hpp"
#include "matrix-event.hpp"
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QCoreApplication::setOrganizationName("The Kazv Project");
QCoreApplication::setOrganizationDomain("kazv.moe");
QCoreApplication::setApplicationName("kazv");
QQmlApplicationEngine engine;
qmlRegisterType<MatrixSdk>("moe.kazv.mxc.kazv", 0, 0, "MatrixSdk");
qmlRegisterUncreatableType<MatrixRoomList>("moe.kazv.mxc.kazv", 0, 0, "MatrixRoomList", "");
qmlRegisterUncreatableType<MatrixRoom>("moe.kazv.mxc.kazv", 0, 0, "MatrixRoom", "");
+ qmlRegisterUncreatableType<MatrixRoomMember>("moe.kazv.mxc.kazv", 0, 0, "MatrixRoomMember", "");
qmlRegisterUncreatableType<MatrixRoomTimeline>("moe.kazv.mxc.kazv", 0, 0, "MatrixRoomTimeline", "");
qmlRegisterUncreatableType<MatrixEvent>("moe.kazv.mxc.kazv", 0, 0, "MatrixEvent", "");
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
if (engine.rootObjects().isEmpty()) {
return -1;
}
return app.exec();
}
diff --git a/src/matrix-event.cpp b/src/matrix-event.cpp
index 673334a..8aff3fb 100644
--- a/src/matrix-event.cpp
+++ b/src/matrix-event.cpp
@@ -1,40 +1,40 @@
/*
* Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
*
* This file is part of kazv.
*
* kazv is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* kazv 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with kazv. If not, see <https://www.gnu.org/licenses/>.
*/
#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
#include "matrix-event.hpp"
#include "helper.hpp"
using namespace Kazv;
MatrixEvent::MatrixEvent(lager::reader<Event> event, QObject *parent)
: QObject(parent)
, m_event(event)
, LAGER_QT(eventId)(m_event.xform(zug::map([](Event e) { return e.id(); }) | strToQt))
, LAGER_QT(sender)(m_event.xform(zug::map([](Event e) { return e.sender(); }) | strToQt))
, LAGER_QT(type)(m_event.xform(zug::map([](Event e) { return e.type(); }) | strToQt))
, LAGER_QT(stateKey)(m_event.xform(zug::map([](Event e) { return e.stateKey(); }) | strToQt))
- , LAGER_QT(content)(m_event.xform(zug::map([](Event e) { return e.content().get().dump(); }) | strToQt))
+ , LAGER_QT(content)(m_event.xform(zug::map([](Event e) { return e.content().get().get<QJsonObject>(); })))
, LAGER_QT(encrypted)(m_event.xform(zug::map([](Event e) { return e.encrypted(); })))
{
}
MatrixEvent::~MatrixEvent() = default;
diff --git a/src/matrix-event.hpp b/src/matrix-event.hpp
index f443e34..defeede 100644
--- a/src/matrix-event.hpp
+++ b/src/matrix-event.hpp
@@ -1,49 +1,51 @@
/*
* Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
*
* This file is part of kazv.
*
* kazv is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* kazv 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with kazv. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
#include <QObject>
#include <QQmlEngine>
#include <lager/extra/qt.hpp>
#include <client/room/room.hpp>
+#include "qt-json.hpp"
+
class MatrixEvent : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("")
lager::reader<Kazv::Event> m_event;
public:
explicit MatrixEvent(lager::reader<Kazv::Event> event, QObject *parent = 0);
~MatrixEvent() override;
LAGER_QT_READER(QString, eventId);
LAGER_QT_READER(QString, sender);
LAGER_QT_READER(QString, type);
LAGER_QT_READER(QString, stateKey);
- LAGER_QT_READER(QString, content);
+ LAGER_QT_READER(QJsonObject, content);
LAGER_QT_READER(bool, encrypted);
};
diff --git a/src/matrix-event.cpp b/src/matrix-room-member.cpp
similarity index 50%
copy from src/matrix-event.cpp
copy to src/matrix-room-member.cpp
index 673334a..c99344e 100644
--- a/src/matrix-event.cpp
+++ b/src/matrix-room-member.cpp
@@ -1,40 +1,39 @@
/*
* Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
*
* This file is part of kazv.
*
* kazv is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* kazv 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with kazv. If not, see <https://www.gnu.org/licenses/>.
*/
-#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
-
-#include "matrix-event.hpp"
+#include <client/cursorutil.hpp>
+#include "matrix-room-member.hpp"
#include "helper.hpp"
+
using namespace Kazv;
+using namespace std::literals::string_literals;
-MatrixEvent::MatrixEvent(lager::reader<Event> event, QObject *parent)
+MatrixRoomMember::MatrixRoomMember(lager::reader<Kazv::Event> memberEvent, QObject *parent)
: QObject(parent)
- , m_event(event)
- , LAGER_QT(eventId)(m_event.xform(zug::map([](Event e) { return e.id(); }) | strToQt))
- , LAGER_QT(sender)(m_event.xform(zug::map([](Event e) { return e.sender(); }) | strToQt))
- , LAGER_QT(type)(m_event.xform(zug::map([](Event e) { return e.type(); }) | strToQt))
- , LAGER_QT(stateKey)(m_event.xform(zug::map([](Event e) { return e.stateKey(); }) | strToQt))
- , LAGER_QT(content)(m_event.xform(zug::map([](Event e) { return e.content().get().dump(); }) | strToQt))
- , LAGER_QT(encrypted)(m_event.xform(zug::map([](Event e) { return e.encrypted(); })))
+ , m_memberEvent(memberEvent)
+ , LAGER_QT(membership)(m_memberEvent.xform(eventContent | jsonAtOr("membership"s, ""s) | strToQt))
+ , LAGER_QT(userId)(m_memberEvent.xform(zug::map([](Event e) { return e.stateKey(); }) | strToQt))
+ , LAGER_QT(name)(m_memberEvent.xform(eventContent | jsonAtOr("displayname"s, ""s) | strToQt))
+ , LAGER_QT(avatarMxcUri)(m_memberEvent.xform(eventContent | jsonAtOr("avatar_url"s, ""s) | strToQt))
{
}
-MatrixEvent::~MatrixEvent() = default;
+MatrixRoomMember::~MatrixRoomMember() = default;
diff --git a/src/matrix-room.hpp b/src/matrix-room-member.hpp
similarity index 71%
copy from src/matrix-room.hpp
copy to src/matrix-room-member.hpp
index 731b1a2..08d25ca 100644
--- a/src/matrix-room.hpp
+++ b/src/matrix-room-member.hpp
@@ -1,52 +1,47 @@
/*
* Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
*
* This file is part of kazv.
*
* kazv is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* kazv 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with kazv. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
#include <QObject>
#include <QQmlEngine>
#include <lager/extra/qt.hpp>
-#include <client/room/room.hpp>
+#include <base/event.hpp>
-class MatrixRoomTimeline;
-
-class MatrixRoom : public QObject
+class MatrixRoomMember : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("")
- Kazv::Room m_room;
+ lager::reader<Kazv::Event> m_memberEvent;
public:
- explicit MatrixRoom(Kazv::Room room, QObject *parent = 0);
- ~MatrixRoom() override;
+ explicit MatrixRoomMember(lager::reader<Kazv::Event> memberEvent, QObject *parent = 0);
+ ~MatrixRoomMember() override;
- LAGER_QT_READER(QString, roomId);
+ LAGER_QT_READER(QString, membership);
+ LAGER_QT_READER(QString, userId);
LAGER_QT_READER(QString, name);
- LAGER_QT_CURSOR(QString, localDraft);
-
- Q_INVOKABLE MatrixRoomTimeline *timeline() const;
-
- Q_INVOKABLE void sendTextMessage(QString text) const;
+ LAGER_QT_READER(QString, avatarMxcUri);
};
diff --git a/src/matrix-room.cpp b/src/matrix-room.cpp
index bd8fabe..37de905 100644
--- a/src/matrix-room.cpp
+++ b/src/matrix-room.cpp
@@ -1,53 +1,72 @@
/*
* Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
*
* This file is part of kazv.
*
* kazv is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* kazv 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with kazv. If not, see <https://www.gnu.org/licenses/>.
*/
#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
#include <lager/setter.hpp>
#include "matrix-room.hpp"
#include "matrix-room-timeline.hpp"
+#include "matrix-room-member.hpp"
#include "helper.hpp"
MatrixRoom::MatrixRoom(Kazv::Room room, QObject *parent)
: QObject(parent)
, m_room(room)
+ , m_memberNames(m_room.members())
, LAGER_QT(roomId)(m_room.roomId().xform(strToQt))
, LAGER_QT(name)(m_room.name().xform(strToQt))
+ , LAGER_QT(avatarMxcUri)(m_room.avatarMxcUri().xform(strToQt))
, LAGER_QT(localDraft)(lager::with_setter(
m_room.localDraft().xform(strToQt).make(),
[this](QString localDraft) {
m_room.setLocalDraft(localDraft.toStdString());
},
lager::automatic_tag{}))
+ , LAGER_QT(memberNames)(m_memberNames.xform(
+ zug::map(
+ [](auto container) {
+ return zug::into(QStringList{}, strToQt, std::move(container));
+ })))
{
}
MatrixRoom::~MatrixRoom() = default;
MatrixRoomTimeline *MatrixRoom::timeline() const
{
return new MatrixRoomTimeline(m_room);
}
void MatrixRoom::sendTextMessage(QString text) const
{
m_room.sendTextMessage(text.toStdString());
}
+
+MatrixRoomMember *MatrixRoom::memberAt(int index) const
+{
+ return new MatrixRoomMember(m_room.memberEventByCursor(
+ m_memberNames[index][lager::lenses::or_default]));
+}
+
+MatrixRoomMember *MatrixRoom::member(QString userId) const
+{
+ return new MatrixRoomMember(m_room.memberEventFor(userId.toStdString()));
+}
diff --git a/src/matrix-room.hpp b/src/matrix-room.hpp
index 731b1a2..921b84a 100644
--- a/src/matrix-room.hpp
+++ b/src/matrix-room.hpp
@@ -1,52 +1,61 @@
/*
* Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
*
* This file is part of kazv.
*
* kazv is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* kazv 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with kazv. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
#include <QObject>
#include <QQmlEngine>
#include <lager/extra/qt.hpp>
#include <client/room/room.hpp>
class MatrixRoomTimeline;
+class MatrixRoomMember;
class MatrixRoom : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("")
Kazv::Room m_room;
+ lager::reader<immer::flex_vector<std::string>> m_memberNames;
public:
explicit MatrixRoom(Kazv::Room room, QObject *parent = 0);
~MatrixRoom() override;
LAGER_QT_READER(QString, roomId);
LAGER_QT_READER(QString, name);
+ LAGER_QT_READER(QString, avatarMxcUri);
LAGER_QT_CURSOR(QString, localDraft);
+ LAGER_QT_READER(QStringList, memberNames);
+
+ Q_INVOKABLE MatrixRoomMember *memberAt(int index) const;
+
+ Q_INVOKABLE MatrixRoomMember *member(QString userId) const;
+
Q_INVOKABLE MatrixRoomTimeline *timeline() const;
Q_INVOKABLE void sendTextMessage(QString text) const;
};
diff --git a/src/matrix-sdk.cpp b/src/matrix-sdk.cpp
index c888443..7057c8d 100644
--- a/src/matrix-sdk.cpp
+++ b/src/matrix-sdk.cpp
@@ -1,129 +1,134 @@
/*
* Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
*
* This file is part of kazv.
*
* kazv is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* kazv 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with kazv. If not, see <https://www.gnu.org/licenses/>.
*/
#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
#include <eventemitter/lagerstoreeventemitter.hpp>
#include <job/cprjobhandler.hpp>
#include <client/sdk.hpp>
#include <base/descendent.hpp>
#include <lager/event_loop/boost_asio.hpp>
#include <zug/util.hpp>
#include <boost/asio.hpp>
#include "matrix-sdk.hpp"
#include "matrix-room-list.hpp"
#include "helper.hpp"
using namespace Kazv;
// Sdk with Boost event loop, identity transform and no enhancers
using ExecT = decltype(std::declval<boost::asio::io_context>().get_executor());
using SdkT =
decltype(makeSdk(
SdkModel{},
detail::declref<JobInterface>(),
detail::declref<EventInterface>(),
lager::with_boost_asio_event_loop{std::declval<boost::asio::io_context>().get_executor()},
zug::identity));
struct MatrixSdkPrivate
{
MatrixSdkPrivate();
boost::asio::io_context io;
CprJobHandler jobHandler;
LagerStoreEventEmitter ee;
LagerStoreEventEmitter::Watchable watchable;
SdkT sdk;
};
MatrixSdkPrivate::MatrixSdkPrivate()
: io{}
, jobHandler{io.get_executor()}
, ee{lager::with_boost_asio_event_loop{io.get_executor()}}
, watchable(ee.watchable())
, sdk(makeSdk(
SdkModel{},
static_cast<JobInterface &>(jobHandler),
static_cast<EventInterface &>(ee),
lager::with_boost_asio_event_loop{io.get_executor()},
zug::identity))
{
}
MatrixSdk::MatrixSdk(QObject *parent)
: QObject(parent)
, m_d(new MatrixSdkPrivate)
, LAGER_QT(userId)(m_d->sdk.client().userId().xform(strToQt))
, LAGER_QT(token)(m_d->sdk.client().token().xform(strToQt))
{
m_d->watchable.afterAll(
[this](KazvEvent e) {
Q_EMIT this->trigger(e);
});
m_d->watchable.after<LoginSuccessful>(
[this](LoginSuccessful e) {
Q_EMIT this->loginSuccessful(e);
});
m_d->watchable.after<LoginFailed>(
[this](LoginFailed e) {
Q_EMIT this->loginFailed(e);
});
connect(this, &MatrixSdk::trigger,
this, [](KazvEvent e) {
qDebug() << "receiving trigger:";
if (std::holds_alternative<LoginSuccessful>(e)) {
qDebug() << "Login successful";
}
});
}
MatrixSdk::~MatrixSdk() = default;
+QString MatrixSdk::mxcUriToHttp(QString mxcUri) const
+{
+ return QString::fromStdString(m_d->sdk.client().mxcUriToHttp(mxcUri.toStdString()));
+}
+
void MatrixSdk::login(const QString &userId, const QString &password)
{
auto l = userId.split(':');
if (l.size() != 2) {
qDebug() << "User id format error";
return;
}
auto serverUrl = QString("https://") + l[1];
m_d->sdk.client()
.passwordLogin(
serverUrl.toStdString(),
userId.toStdString(),
password.toStdString(),
"kazv 0.0.0"
);
std::thread([&] {
qDebug() << "running io context...";
m_d->io.run();
qDebug() << "should never reach here--";
}).detach();
}
MatrixRoomList *MatrixSdk::roomList() const
{
return new MatrixRoomList(m_d->sdk.client());
};
diff --git a/src/matrix-sdk.hpp b/src/matrix-sdk.hpp
index ff72574..c2868ff 100644
--- a/src/matrix-sdk.hpp
+++ b/src/matrix-sdk.hpp
@@ -1,60 +1,62 @@
/*
* Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
*
* This file is part of kazv.
*
* kazv is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* kazv 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with kazv. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
#include <QObject>
#include <QQmlEngine>
#include <QString>
#include <QScopedPointer>
#include <lager/extra/qt.hpp>
#include "meta-types.hpp"
class MatrixRoomList;
struct MatrixSdkPrivate;
class MatrixSdk : public QObject
{
Q_OBJECT
QML_ELEMENT
QScopedPointer<MatrixSdkPrivate> m_d;
public:
explicit MatrixSdk(QObject *parent = 0);
~MatrixSdk() override;
LAGER_QT_READER(QString, userId);
LAGER_QT_READER(QString, token);
Q_INVOKABLE MatrixRoomList *roomList() const;
+ Q_INVOKABLE QString mxcUriToHttp(QString mxcUri) const;
+
Q_SIGNALS:
void trigger(Kazv::KazvEvent e);
void loginSuccessful(Kazv::KazvEvent e);
void loginFailed(Kazv::KazvEvent e);
public Q_SLOTS:
void login(const QString &userId, const QString &password);
};
diff --git a/src/qt-json.hpp b/src/qt-json.hpp
new file mode 100644
index 0000000..fee468b
--- /dev/null
+++ b/src/qt-json.hpp
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2020 Tusooa Zhu <tusooa@vista.aero>
+ *
+ * This file is part of kazv.
+ *
+ * kazv is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * kazv 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with kazv. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
+
+#include <nlohmann/json.hpp>
+#include <QJsonObject>
+#include <QJsonArray>
+#include <QJsonValue>
+
+inline void to_json(nlohmann::json& j, const QJsonObject& qj);
+inline void from_json(const nlohmann::json& j, QJsonObject& qj);
+inline void to_json(nlohmann::json& j, const QJsonArray& qj);
+inline void from_json(const nlohmann::json& j, QJsonArray& qj);
+inline void to_json(nlohmann::json& j, const QJsonValue& qj);
+inline void to_json(nlohmann::json& j, const QJsonValue& qj);
+
+
+inline void to_json(nlohmann::json& j, const QJsonValue& qj) {
+ if (qj.isArray()) {
+ j = qj.toArray();
+ } else if (qj.isObject()) {
+ j = qj.toObject();
+ } else if (qj.isBool()) {
+ j = qj.toBool();
+ } else if (qj.isDouble()) {
+ j = qj.toDouble();
+ } else if (qj.isString()) {
+ j = qj.toString().toStdString();
+ }
+}
+
+inline void from_json(const nlohmann::json& j, QJsonValue& qj) {
+ if (j.is_array()) {
+ qj = QJsonValue(j.get<QJsonArray>());
+ } else if (j.is_object()) {
+ qj = QJsonValue(j.get<QJsonObject>());
+ } else if (j.is_boolean()) {
+ qj = QJsonValue(j.get<bool>());
+ } else if (j.is_number()) {
+ qj = QJsonValue(j.get<double>());
+ } else if (j.is_string()) {
+ qj = QJsonValue(QString::fromStdString(j.get<std::string>()));
+ } else if (j.is_null()) {
+ qj = QJsonValue();
+ }
+}
+
+inline void to_json(nlohmann::json& j, const QJsonObject& qj) {
+ for (auto it = qj.constBegin(); it != qj.constEnd(); ++it) {
+ j[it.key().toStdString()] = it.value();
+ }
+}
+
+inline void from_json(const nlohmann::json& j, QJsonObject& qj) {
+ for (const auto &[k, v]: j.items()) {
+ qj.insert(QString::fromStdString(k), v.get<QJsonValue>());
+ }
+}
+
+inline void to_json(nlohmann::json& j, const QJsonArray& qj) {
+ for (const auto &i: qj) {
+ j.push_back(i);
+ }
+}
+
+inline void from_json(const nlohmann::json& j, QJsonArray& qj) {
+ for (const auto &i: j) {
+ qj.push_back(i.get<QJsonValue>());
+ }
+}
diff --git a/src/resources.qrc b/src/resources.qrc
index 373d80e..5715c15 100644
--- a/src/resources.qrc
+++ b/src/resources.qrc
@@ -1,13 +1,14 @@
<RCC>
<qresource prefix="/">
<file alias="main.qml">contents/ui/main.qml</file>
<file alias="LoginPage.qml">contents/ui/LoginPage.qml</file>
<file alias="MainPage.qml">contents/ui/MainPage.qml</file>
<file alias="TabView.qml">contents/ui/TabView.qml</file>
<file alias="Tab.qml">contents/ui/Tab.qml</file>
<file alias="RoomListView.qml">contents/ui/RoomListView.qml</file>
<file alias="RoomPage.qml">contents/ui/RoomPage.qml</file>
<file alias="RoomTimelineView.qml">contents/ui/RoomTimelineView.qml</file>
<file alias="SendMessageBox.qml">contents/ui/SendMessageBox.qml</file>
+ <file alias="EventView.qml">contents/ui/EventView.qml</file>
</qresource>
</RCC>

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 2, 8:09 AM (4 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1803717
Default Alt Text
(36 KB)

Event Timeline