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.right: parent.right
id: closeButton
width: 64
height: 64

View File

@@ -30,6 +30,24 @@ Dialog {
hint: room.displayName
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 {
@@ -230,7 +248,7 @@ Dialog {
text: "Set background image"
onClicked: {
var fileDialog = chatBackgroundDialog.createObject(ApplicationWindow.overlay)
var fileDialog = openFileDialog.createObject(ApplicationWindow.overlay)
fileDialog.chosen.connect(function(path) {
if (!path) return
@@ -262,7 +280,7 @@ Dialog {
}
Component {
id: chatBackgroundDialog
id: openFileDialog
OpenFileDialog {}
}

View File

@@ -8,8 +8,10 @@
#include "events/roommessageevent.h"
#include "csapi/account-data.h"
#include "csapi/content-repo.h"
#include "csapi/joining.h"
#include "csapi/logout.h"
#include "csapi/profile.h"
#include "utils.h"
@@ -310,3 +312,12 @@ int Controller::dpi() {
void Controller::setDpi(int 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 createDirectChat(Connection* c, const QString& userID);
void playAudio(QUrl localFile);
void changeAvatar(Connection* conn, QUrl localFile);
};
#endif // CONTROLLER_H

View File

@@ -6,6 +6,8 @@
#include "csapi/account-data.h"
#include "csapi/content-repo.h"
#include "csapi/leaving.h"
#include "csapi/room_state.h"
#include "csapi/rooms.h"
#include "csapi/typing.h"
#include "events/accountdataevents.h"
#include "events/typingevent.h"
@@ -304,3 +306,13 @@ QString SpectralRoom::backgroundMediaId() {
auto url = backgroundUrl();
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 replyContent,
QString sendContent);
void changeAvatar(QUrl localFile);
};
#endif // SpectralRoom_H