mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Remove some redundant functions
This commit is contained in:
parent
fd270dcd55
commit
9eddcfc42f
7 changed files with 30 additions and 50 deletions
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
#include "Cache_p.h"
|
#include "Cache_p.h"
|
||||||
|
#include "EventAccessors.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
@ -1947,13 +1948,14 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
|
||||||
|
|
||||||
json obj = json::object();
|
json obj = json::object();
|
||||||
|
|
||||||
obj["event"] = utils::serialize_event(e);
|
obj["event"] = mtx::accessors::serialize_event(e);
|
||||||
obj["token"] = res.prev_batch;
|
obj["token"] = res.prev_batch;
|
||||||
|
|
||||||
lmdb::dbi_put(txn,
|
lmdb::dbi_put(
|
||||||
db,
|
txn,
|
||||||
lmdb::val(std::to_string(utils::event_timestamp(e))),
|
db,
|
||||||
lmdb::val(obj.dump()));
|
lmdb::val(std::to_string(obj["event"]["origin_server_ts"].get<uint64_t>())),
|
||||||
|
lmdb::val(obj.dump()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2026,7 +2028,7 @@ Cache::saveTimelineMentions(lmdb::txn &txn,
|
||||||
using namespace mtx::events::state;
|
using namespace mtx::events::state;
|
||||||
|
|
||||||
for (const auto ¬if : res) {
|
for (const auto ¬if : res) {
|
||||||
const auto event_id = utils::event_id(notif.event);
|
const auto event_id = mtx::accessors::event_id(notif.event);
|
||||||
|
|
||||||
// double check that we have the correct room_id...
|
// double check that we have the correct room_id...
|
||||||
if (room_id.compare(notif.room_id) != 0) {
|
if (room_id.compare(notif.room_id) != 0) {
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
#include "Cache_p.h"
|
#include "Cache_p.h"
|
||||||
#include "ChatPage.h"
|
#include "ChatPage.h"
|
||||||
|
#include "EventAccessors.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
|
@ -885,7 +886,7 @@ void
|
||||||
ChatPage::sendDesktopNotifications(const mtx::responses::Notifications &res)
|
ChatPage::sendDesktopNotifications(const mtx::responses::Notifications &res)
|
||||||
{
|
{
|
||||||
for (const auto &item : res.notifications) {
|
for (const auto &item : res.notifications) {
|
||||||
const auto event_id = utils::event_id(item.event);
|
const auto event_id = mtx::accessors::event_id(item.event);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (item.read) {
|
if (item.read) {
|
||||||
|
@ -895,7 +896,8 @@ ChatPage::sendDesktopNotifications(const mtx::responses::Notifications &res)
|
||||||
|
|
||||||
if (!cache::isNotificationSent(event_id)) {
|
if (!cache::isNotificationSent(event_id)) {
|
||||||
const auto room_id = QString::fromStdString(item.room_id);
|
const auto room_id = QString::fromStdString(item.room_id);
|
||||||
const auto user_id = utils::event_sender(item.event);
|
const auto user_id =
|
||||||
|
QString::fromStdString(mtx::accessors::sender(item.event));
|
||||||
|
|
||||||
// We should only sent one notification per event.
|
// We should only sent one notification per event.
|
||||||
cache::markSentNotification(event_id);
|
cache::markSentNotification(event_id);
|
||||||
|
|
|
@ -400,3 +400,9 @@ mtx::accessors::media_width(const mtx::events::collections::TimelineEvents &even
|
||||||
{
|
{
|
||||||
return std::visit(EventMediaWidth{}, event);
|
return std::visit(EventMediaWidth{}, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nlohmann::json
|
||||||
|
mtx::accessors::serialize_event(const mtx::events::collections::TimelineEvents &event)
|
||||||
|
{
|
||||||
|
return std::visit([](const auto &e) { return nlohmann::json{e}; }, event);
|
||||||
|
}
|
||||||
|
|
|
@ -63,4 +63,7 @@ media_height(const mtx::events::collections::TimelineEvents &event);
|
||||||
|
|
||||||
uint64_t
|
uint64_t
|
||||||
media_width(const mtx::events::collections::TimelineEvents &event);
|
media_width(const mtx::events::collections::TimelineEvents &event);
|
||||||
|
|
||||||
|
nlohmann::json
|
||||||
|
serialize_event(const mtx::events::collections::TimelineEvents &event);
|
||||||
}
|
}
|
||||||
|
|
36
src/Utils.h
36
src/Utils.h
|
@ -186,42 +186,6 @@ erase_if(ContainerT &items, const PredicateT &predicate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint64_t
|
|
||||||
event_timestamp(const mtx::events::collections::TimelineEvents &event)
|
|
||||||
{
|
|
||||||
return std::visit([](auto msg) { return msg.origin_server_ts; }, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline nlohmann::json
|
|
||||||
serialize_event(const mtx::events::collections::TimelineEvents &event)
|
|
||||||
{
|
|
||||||
return std::visit([](auto msg) { return json(msg); }, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline mtx::events::EventType
|
|
||||||
event_type(const mtx::events::collections::TimelineEvents &event)
|
|
||||||
{
|
|
||||||
return std::visit([](auto msg) { return msg.type; }, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string
|
|
||||||
event_id(const mtx::events::collections::TimelineEvents &event)
|
|
||||||
{
|
|
||||||
return std::visit([](auto msg) { return msg.event_id; }, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline QString
|
|
||||||
eventId(const mtx::events::collections::TimelineEvents &event)
|
|
||||||
{
|
|
||||||
return QString::fromStdString(event_id(event));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline QString
|
|
||||||
event_sender(const mtx::events::collections::TimelineEvents &event)
|
|
||||||
{
|
|
||||||
return std::visit([](auto msg) { return QString::fromStdString(msg.sender); }, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
QString
|
QString
|
||||||
message_body(const mtx::events::collections::TimelineEvents &event)
|
message_body(const mtx::events::collections::TimelineEvents &event)
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
|
|
||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
#include "ChatPage.h"
|
#include "ChatPage.h"
|
||||||
|
#include "EventAccessors.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "UserMentions.h"
|
#include "UserMentions.h"
|
||||||
//#include "timeline/TimelineItem.h"
|
|
||||||
|
|
||||||
using namespace popups;
|
using namespace popups;
|
||||||
|
|
||||||
|
@ -75,12 +75,15 @@ UserMentions::initializeMentions(const QMap<QString, mtx::responses::Notificatio
|
||||||
|
|
||||||
for (const auto &item : notifs) {
|
for (const auto &item : notifs) {
|
||||||
for (const auto ¬if : item.notifications) {
|
for (const auto ¬if : item.notifications) {
|
||||||
const auto event_id = QString::fromStdString(utils::event_id(notif.event));
|
const auto event_id =
|
||||||
|
QString::fromStdString(mtx::accessors::event_id(notif.event));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const auto room_id = QString::fromStdString(notif.room_id);
|
const auto room_id = QString::fromStdString(notif.room_id);
|
||||||
const auto user_id = utils::event_sender(notif.event);
|
const auto user_id =
|
||||||
const auto body = utils::event_body(notif.event);
|
QString::fromStdString(mtx::accessors::sender(notif.event));
|
||||||
|
const auto body =
|
||||||
|
QString::fromStdString(mtx::accessors::body(notif.event));
|
||||||
|
|
||||||
pushItem(event_id,
|
pushItem(event_id,
|
||||||
user_id,
|
user_id,
|
||||||
|
|
|
@ -808,7 +808,7 @@ TimelineModel::escapeEmoji(QString str) const
|
||||||
void
|
void
|
||||||
TimelineModel::viewRawMessage(QString id) const
|
TimelineModel::viewRawMessage(QString id) const
|
||||||
{
|
{
|
||||||
std::string ev = utils::serialize_event(events.value(id)).dump(4);
|
std::string ev = mtx::accessors::serialize_event(events.value(id)).dump(4);
|
||||||
auto dialog = new dialogs::RawMessage(QString::fromStdString(ev));
|
auto dialog = new dialogs::RawMessage(QString::fromStdString(ev));
|
||||||
Q_UNUSED(dialog);
|
Q_UNUSED(dialog);
|
||||||
}
|
}
|
||||||
|
@ -822,7 +822,7 @@ TimelineModel::viewDecryptedRawMessage(QString id) const
|
||||||
event = decryptEvent(*e).event;
|
event = decryptEvent(*e).event;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ev = utils::serialize_event(event).dump(4);
|
std::string ev = mtx::accessors::serialize_event(event).dump(4);
|
||||||
auto dialog = new dialogs::RawMessage(QString::fromStdString(ev));
|
auto dialog = new dialogs::RawMessage(QString::fromStdString(ev));
|
||||||
Q_UNUSED(dialog);
|
Q_UNUSED(dialog);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue