Add/remove reactions.
This commit is contained in:
@@ -222,6 +222,8 @@ ColumnLayout {
|
||||
}
|
||||
|
||||
ReactionDelegate {
|
||||
Layout.fillWidth: true
|
||||
|
||||
Layout.topMargin: 0
|
||||
Layout.bottomMargin: 8
|
||||
Layout.leftMargin: 16
|
||||
|
||||
@@ -3,9 +3,11 @@ import QtQuick.Controls 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import Spectral.Setting 0.1
|
||||
|
||||
RowLayout {
|
||||
Flow {
|
||||
visible: reaction || false
|
||||
|
||||
spacing: 8
|
||||
|
||||
Repeater {
|
||||
model: reaction
|
||||
|
||||
@@ -40,6 +42,8 @@ RowLayout {
|
||||
|
||||
return text
|
||||
}
|
||||
|
||||
onClicked: currentRoom.toggleReaction(eventId, modelData.reaction)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include "csapi/rooms.h"
|
||||
#include "csapi/typing.h"
|
||||
#include "events/accountdataevents.h"
|
||||
#include "events/reactionevent.h"
|
||||
#include "events/roommessageevent.h"
|
||||
#include "events/typingevent.h"
|
||||
#include "events/reactionevent.h"
|
||||
#include "jobs/downloadfilejob.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
@@ -306,7 +306,7 @@ QString SpectralRoom::markdownToHTML(const QString& markdown) {
|
||||
|
||||
std::string html(tmp_buf);
|
||||
|
||||
free((char *)tmp_buf);
|
||||
free((char*)tmp_buf);
|
||||
|
||||
auto result = QString::fromStdString(html).trimmed();
|
||||
|
||||
@@ -420,3 +420,35 @@ void SpectralRoom::postHtmlMessage(const QString& text,
|
||||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,6 +315,7 @@ class SpectralRoom : public Room {
|
||||
void changeAvatar(QUrl localFile);
|
||||
void addLocalAlias(const QString& alias);
|
||||
void removeLocalAlias(const QString& alias);
|
||||
void toggleReaction(const QString& eventId, const QString& reaction);
|
||||
};
|
||||
|
||||
#endif // SpectralRoom_H
|
||||
|
||||
Reference in New Issue
Block a user