Add/remove reactions.

This commit is contained in:
Black Hat
2019-07-26 17:48:17 +08:00
parent 18c42b6af6
commit 442b68558e
4 changed files with 42 additions and 3 deletions

View File

@@ -222,6 +222,8 @@ ColumnLayout {
} }
ReactionDelegate { ReactionDelegate {
Layout.fillWidth: true
Layout.topMargin: 0 Layout.topMargin: 0
Layout.bottomMargin: 8 Layout.bottomMargin: 8
Layout.leftMargin: 16 Layout.leftMargin: 16

View File

@@ -3,9 +3,11 @@ import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import Spectral.Setting 0.1 import Spectral.Setting 0.1
RowLayout { Flow {
visible: reaction || false visible: reaction || false
spacing: 8
Repeater { Repeater {
model: reaction model: reaction
@@ -40,6 +42,8 @@ RowLayout {
return text return text
} }
onClicked: currentRoom.toggleReaction(eventId, modelData.reaction)
} }
} }

View File

@@ -10,9 +10,9 @@
#include "csapi/rooms.h" #include "csapi/rooms.h"
#include "csapi/typing.h" #include "csapi/typing.h"
#include "events/accountdataevents.h" #include "events/accountdataevents.h"
#include "events/reactionevent.h"
#include "events/roommessageevent.h" #include "events/roommessageevent.h"
#include "events/typingevent.h" #include "events/typingevent.h"
#include "events/reactionevent.h"
#include "jobs/downloadfilejob.h" #include "jobs/downloadfilejob.h"
#include <QFileDialog> #include <QFileDialog>
@@ -306,7 +306,7 @@ QString SpectralRoom::markdownToHTML(const QString& markdown) {
std::string html(tmp_buf); std::string html(tmp_buf);
free((char *)tmp_buf); free((char*)tmp_buf);
auto result = QString::fromStdString(html).trimmed(); auto result = QString::fromStdString(html).trimmed();
@@ -420,3 +420,35 @@ void SpectralRoom::postHtmlMessage(const QString& text,
Room::postHtmlMessage(text, html, type); Room::postHtmlMessage(text, html, type);
} }
void SpectralRoom::toggleReaction(const QString& eventId,
const QString& reaction) {
const auto eventIt = findInTimeline(eventId);
if (eventIt == timelineEdge())
return;
const auto& evt = **eventIt;
QString redactEventId = "";
const auto& annotations = relatedEvents(evt, EventRelation::Annotation());
if (!annotations.isEmpty()) {
for (const auto& a : annotations) {
if (auto e = eventCast<const ReactionEvent>(a)) {
if (e->relation().key != reaction)
continue;
if (e->senderId() == localUser()->id()) {
redactEventId = e->id();
break;
}
}
}
}
if (!redactEventId.isEmpty()) {
redactEvent(redactEventId);
} else {
postEvent(new ReactionEvent(EventRelation::annotate(eventId, reaction)));
}
}

View File

@@ -315,6 +315,7 @@ class SpectralRoom : public Room {
void changeAvatar(QUrl localFile); void changeAvatar(QUrl localFile);
void addLocalAlias(const QString& alias); void addLocalAlias(const QString& alias);
void removeLocalAlias(const QString& alias); void removeLocalAlias(const QString& alias);
void toggleReaction(const QString& eventId, const QString& reaction);
}; };
#endif // SpectralRoom_H #endif // SpectralRoom_H