From b1f1cb2b560aa56d485ba1e326bf111326c7aa74 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 27 Oct 2019 22:49:49 +0100 Subject: Redirect qt logger --- src/Logging.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/Logging.cpp') diff --git a/src/Logging.cpp b/src/Logging.cpp index 32287582..b5952aeb 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -5,14 +5,43 @@ #include "spdlog/sinks/stdout_color_sinks.h" #include +#include +#include + namespace { std::shared_ptr db_logger = nullptr; std::shared_ptr net_logger = nullptr; std::shared_ptr crypto_logger = nullptr; std::shared_ptr ui_logger = nullptr; +std::shared_ptr qml_logger = nullptr; constexpr auto MAX_FILE_SIZE = 1024 * 1024 * 6; constexpr auto MAX_LOG_FILES = 3; + +void +qmlMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + std::string localMsg = msg.toStdString(); + const char *file = context.file ? context.file : ""; + const char *function = context.function ? context.function : ""; + switch (type) { + case QtDebugMsg: + nhlog::qml()->debug("{} ({}:{}, {})", localMsg, file, context.line, function); + break; + case QtInfoMsg: + nhlog::qml()->info("{} ({}:{}, {})", localMsg, file, context.line, function); + break; + case QtWarningMsg: + nhlog::qml()->warn("{} ({}:{}, {})", localMsg, file, context.line, function); + break; + case QtCriticalMsg: + nhlog::qml()->critical("{} ({}:{}, {})", localMsg, file, context.line, function); + break; + case QtFatalMsg: + nhlog::qml()->critical("{} ({}:{}, {})", localMsg, file, context.line, function); + break; + } +} } namespace nhlog { @@ -35,12 +64,15 @@ init(const std::string &file_path) db_logger = std::make_shared("db", std::begin(sinks), std::end(sinks)); crypto_logger = std::make_shared("crypto", std::begin(sinks), std::end(sinks)); + qml_logger = std::make_shared("qml", std::begin(sinks), std::end(sinks)); if (nheko::enable_debug_log) { db_logger->set_level(spdlog::level::trace); ui_logger->set_level(spdlog::level::trace); crypto_logger->set_level(spdlog::level::trace); } + + qInstallMessageHandler(qmlMessageHandler); } std::shared_ptr @@ -66,4 +98,11 @@ crypto() { return crypto_logger; } + +std::shared_ptr +qml() +{ + return qml_logger; +} } + -- cgit 1.5.1 From 6b6085b270bcdffe56e19de1cd1171a73fe5fba1 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 31 Oct 2019 14:09:51 +0100 Subject: Actually fix updating roomlist on new messages --- src/Logging.cpp | 1 - src/timeline2/TimelineModel.cpp | 57 +++++++++++++++++++++-------------------- src/timeline2/TimelineModel.h | 3 +++ 3 files changed, 32 insertions(+), 29 deletions(-) (limited to 'src/Logging.cpp') diff --git a/src/Logging.cpp b/src/Logging.cpp index b5952aeb..126b3781 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -105,4 +105,3 @@ qml() return qml_logger; } } - diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp index 45126b36..2428ddb6 100644 --- a/src/timeline2/TimelineModel.cpp +++ b/src/timeline2/TimelineModel.cpp @@ -348,6 +348,9 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj events.remove(txn_id); events.insert(event_id, ev); + // mark our messages as read + readEvent(event_id.toStdString()); + // ask to be notified for read receipts cache::client()->addPendingReceipt(room_id_, event_id); @@ -525,25 +528,20 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline) this->eventOrder.insert(this->eventOrder.end(), ids.begin(), ids.end()); endInsertRows(); - for (auto id = eventOrder.rbegin(); id != eventOrder.rend(); id++) { - auto event = events.value(*id); - if (auto e = boost::get>( - &event)) { - event = decryptEvent(*e).event; - } + updateLastMessage(); +} - auto type = boost::apply_visitor( - [](const auto &e) -> mtx::events::EventType { return e.type; }, event); - if (type == mtx::events::EventType::RoomMessage || - type == mtx::events::EventType::Sticker) { - auto description = utils::getMessageDescription( - event, - QString::fromStdString(http::client()->user_id().to_string()), - room_id_); - emit manager_->updateRoomsLastMessage(room_id_, description); - break; - } +void +TimelineModel::updateLastMessage() +{ + auto event = events.value(eventOrder.back()); + if (auto e = boost::get>(&event)) { + event = decryptEvent(*e).event; } + + auto description = utils::getMessageDescription( + event, QString::fromStdString(http::client()->user_id().to_string()), room_id_); + emit manager_->updateRoomsLastMessage(room_id_, description); } std::vector @@ -634,20 +632,23 @@ TimelineModel::setCurrentIndex(int index) currentId = indexToId(index); emit currentIndexChanged(index); - if (oldIndex < index) { - http::client()->read_event(room_id_.toStdString(), - currentId.toStdString(), - [this](mtx::http::RequestErr err) { - if (err) { - nhlog::net()->warn( - "failed to read_event ({}, {})", - room_id_.toStdString(), - currentId.toStdString()); - } - }); + if (oldIndex < index && !pending.contains(currentId)) { + readEvent(currentId.toStdString()); } } +void +TimelineModel::readEvent(const std::string &id) +{ + http::client()->read_event(room_id_.toStdString(), id, [this](mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn("failed to read_event ({}, {})", + room_id_.toStdString(), + currentId.toStdString()); + } + }); +} + void TimelineModel::addBackwardsEvents(const mtx::responses::Messages &msgs) { diff --git a/src/timeline2/TimelineModel.h b/src/timeline2/TimelineModel.h index b7ff546b..6a1f3438 100644 --- a/src/timeline2/TimelineModel.h +++ b/src/timeline2/TimelineModel.h @@ -192,6 +192,8 @@ private: const std::string &user_id, const mtx::responses::ClaimKeys &res, mtx::http::RequestErr err); + void updateLastMessage(); + void readEvent(const std::string &id); QHash events; QSet pending, failed, read; @@ -229,6 +231,7 @@ TimelineModel::sendMessage(const T &msg) pending.insert(txn_id_qstr); this->eventOrder.insert(this->eventOrder.end(), txn_id_qstr); endInsertRows(); + updateLastMessage(); if (cache::client()->isRoomEncrypted(room_id_.toStdString())) sendEncryptedMessage(txn_id, nlohmann::json(msg)); -- cgit 1.5.1