Ability to change room avatar.

This commit is contained in:
Black Hat
2019-07-02 22:00:43 +08:00
parent a8cc5f4861
commit e561265e5c
6 changed files with 47 additions and 2 deletions

View File

@@ -36,6 +36,8 @@ ApplicationWindow {
anchors.top: parent.top anchors.top: parent.top
anchors.right: parent.right anchors.right: parent.right
id: closeButton
width: 64 width: 64
height: 64 height: 64

View File

@@ -30,6 +30,24 @@ Dialog {
hint: room.displayName hint: room.displayName
source: room.avatarMediaId source: room.avatarMediaId
RippleEffect {
anchors.fill: parent
circular: true
onClicked: {
var fileDialog = openFileDialog.createObject(ApplicationWindow.overlay)
fileDialog.chosen.connect(function(path) {
if (!path) return
room.changeAvatar(path)
})
fileDialog.open()
}
}
} }
ColumnLayout { ColumnLayout {
@@ -230,7 +248,7 @@ Dialog {
text: "Set background image" text: "Set background image"
onClicked: { onClicked: {
var fileDialog = chatBackgroundDialog.createObject(ApplicationWindow.overlay) var fileDialog = openFileDialog.createObject(ApplicationWindow.overlay)
fileDialog.chosen.connect(function(path) { fileDialog.chosen.connect(function(path) {
if (!path) return if (!path) return
@@ -262,7 +280,7 @@ Dialog {
} }
Component { Component {
id: chatBackgroundDialog id: openFileDialog
OpenFileDialog {} OpenFileDialog {}
} }

View File

@@ -8,8 +8,10 @@
#include "events/roommessageevent.h" #include "events/roommessageevent.h"
#include "csapi/account-data.h" #include "csapi/account-data.h"
#include "csapi/content-repo.h"
#include "csapi/joining.h" #include "csapi/joining.h"
#include "csapi/logout.h" #include "csapi/logout.h"
#include "csapi/profile.h"
#include "utils.h" #include "utils.h"
@@ -310,3 +312,12 @@ int Controller::dpi() {
void Controller::setDpi(int dpi) { void Controller::setDpi(int dpi) {
SettingsGroup("Interface").setValue("dpi", dpi); SettingsGroup("Interface").setValue("dpi", dpi);
} }
void Controller::changeAvatar(Connection* conn, QUrl localFile) {
auto job = conn->uploadFile(localFile.toLocalFile());
if (isJobRunning(job)) {
connect(job, &BaseJob::success, this, [this, conn, job] {
conn->callApi<SetAvatarUrlJob>(conn->userId(), job->contentUri());
});
}
}

View File

@@ -112,6 +112,7 @@ class Controller : public QObject {
void createRoom(Connection* c, const QString& name, const QString& topic); void createRoom(Connection* c, const QString& name, const QString& topic);
void createDirectChat(Connection* c, const QString& userID); void createDirectChat(Connection* c, const QString& userID);
void playAudio(QUrl localFile); void playAudio(QUrl localFile);
void changeAvatar(Connection* conn, QUrl localFile);
}; };
#endif // CONTROLLER_H #endif // CONTROLLER_H

View File

@@ -6,6 +6,8 @@
#include "csapi/account-data.h" #include "csapi/account-data.h"
#include "csapi/content-repo.h" #include "csapi/content-repo.h"
#include "csapi/leaving.h" #include "csapi/leaving.h"
#include "csapi/room_state.h"
#include "csapi/rooms.h"
#include "csapi/typing.h" #include "csapi/typing.h"
#include "events/accountdataevents.h" #include "events/accountdataevents.h"
#include "events/typingevent.h" #include "events/typingevent.h"
@@ -304,3 +306,13 @@ QString SpectralRoom::backgroundMediaId() {
auto url = backgroundUrl(); auto url = backgroundUrl();
return url.authority() + url.path(); return url.authority() + url.path();
} }
void SpectralRoom::changeAvatar(QUrl localFile) {
auto job = connection()->uploadFile(localFile.toLocalFile());
if (isJobRunning(job)) {
connect(job, &BaseJob::success, this, [this, job] {
connection()->callApi<SetRoomStateJob>(
id(), "m.room.avatar", QJsonObject{{"url", job->contentUri()}});
});
}
}

View File

@@ -305,6 +305,7 @@ class SpectralRoom : public Room {
QString eventId, QString eventId,
QString replyContent, QString replyContent,
QString sendContent); QString sendContent);
void changeAvatar(QUrl localFile);
}; };
#endif // SpectralRoom_H #endif // SpectralRoom_H