mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Implement replies in qml timeline
This commit is contained in:
parent
5c87d6faa6
commit
62d0cd74da
3 changed files with 57 additions and 0 deletions
|
@ -95,6 +95,8 @@ Rectangle {
|
||||||
source: replyButtonImg
|
source: replyButtonImg
|
||||||
color: replyButton.hovered ? colors.highlight : colors.buttonText
|
color: replyButton.hovered ? colors.highlight : colors.buttonText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onClicked: chat.model.replyAction(model.id)
|
||||||
}
|
}
|
||||||
Button {
|
Button {
|
||||||
Layout.alignment: Qt.AlignRight | Qt.AlignTop
|
Layout.alignment: Qt.AlignRight | Qt.AlignTop
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
#include "ChatPage.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "Olm.h"
|
#include "Olm.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
@ -37,6 +38,33 @@ eventTimestamp(const T &event)
|
||||||
return QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
|
return QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
std::string
|
||||||
|
eventMsgType(const mtx::events::Event<T> &)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
template<class T>
|
||||||
|
auto
|
||||||
|
eventMsgType(const mtx::events::RoomEvent<T> &e) -> decltype(e.content.msgtype)
|
||||||
|
{
|
||||||
|
return e.content.msgtype;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
QString
|
||||||
|
eventBody(const mtx::events::Event<T> &)
|
||||||
|
{
|
||||||
|
return QString("");
|
||||||
|
}
|
||||||
|
template<class T>
|
||||||
|
auto
|
||||||
|
eventBody(const mtx::events::RoomEvent<T> &e)
|
||||||
|
-> std::enable_if_t<std::is_same<decltype(e.content.body), std::string>::value, QString>
|
||||||
|
{
|
||||||
|
return QString::fromStdString(e.content.body);
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
QString
|
QString
|
||||||
eventFormattedBody(const mtx::events::Event<T> &)
|
eventFormattedBody(const mtx::events::Event<T> &)
|
||||||
|
@ -293,6 +321,9 @@ TimelineModel::data(const QModelIndex &index, int role) const
|
||||||
return QVariant(boost::apply_visitor(
|
return QVariant(boost::apply_visitor(
|
||||||
[](const auto &e) -> qml_mtx_events::EventType { return toRoomEventType(e); },
|
[](const auto &e) -> qml_mtx_events::EventType { return toRoomEventType(e); },
|
||||||
event));
|
event));
|
||||||
|
case Body:
|
||||||
|
return QVariant(utils::replaceEmoji(boost::apply_visitor(
|
||||||
|
[](const auto &e) -> QString { return eventBody(e); }, event)));
|
||||||
case FormattedBody:
|
case FormattedBody:
|
||||||
return QVariant(utils::replaceEmoji(boost::apply_visitor(
|
return QVariant(utils::replaceEmoji(boost::apply_visitor(
|
||||||
[](const auto &e) -> QString { return eventFormattedBody(e); }, event)));
|
[](const auto &e) -> QString { return eventFormattedBody(e); }, event)));
|
||||||
|
@ -571,3 +602,26 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEvent<mtx::events::msg::
|
||||||
.toStdString();
|
.toStdString();
|
||||||
return {dummy, false};
|
return {dummy, false};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TimelineModel::replyAction(QString id)
|
||||||
|
{
|
||||||
|
auto event = events.value(id);
|
||||||
|
RelatedInfo related = boost::apply_visitor(
|
||||||
|
[](const auto &ev) -> RelatedInfo {
|
||||||
|
RelatedInfo related_ = {};
|
||||||
|
related_.quoted_user = QString::fromStdString(ev.sender);
|
||||||
|
related_.related_event = ev.event_id;
|
||||||
|
return related_;
|
||||||
|
},
|
||||||
|
event);
|
||||||
|
related.type = mtx::events::getMessageType(boost::apply_visitor(
|
||||||
|
[](const auto &e) -> std::string { return eventMsgType(e); }, event));
|
||||||
|
related.quoted_body =
|
||||||
|
boost::apply_visitor([](const auto &e) -> QString { return eventBody(e); }, event);
|
||||||
|
|
||||||
|
if (related.quoted_body.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
emit ChatPage::instance()->messageReply(related);
|
||||||
|
}
|
||||||
|
|
|
@ -111,6 +111,7 @@ public:
|
||||||
Q_INVOKABLE QString formatDateSeparator(QDate date) const;
|
Q_INVOKABLE QString formatDateSeparator(QDate date) const;
|
||||||
Q_INVOKABLE QString escapeEmoji(QString str) const;
|
Q_INVOKABLE QString escapeEmoji(QString str) const;
|
||||||
Q_INVOKABLE void viewRawMessage(QString id) const;
|
Q_INVOKABLE void viewRawMessage(QString id) const;
|
||||||
|
Q_INVOKABLE void replyAction(QString id);
|
||||||
|
|
||||||
void addEvents(const mtx::responses::Timeline &events);
|
void addEvents(const mtx::responses::Timeline &events);
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
Loading…
Reference in a new issue