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

@@ -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)));
}
}

View File

@@ -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