#include "Utils.h" #include #include #include #include #include #include #include #include #include "Config.h" using TimelineEvent = mtx::events::collections::TimelineEvents; QString utils::localUser() { QSettings settings; return settings.value("auth/user_id").toString(); } void utils::setScaleFactor(float factor) { if (factor < 1 || factor > 3) return; QSettings settings; settings.setValue("settings/scale_factor", factor); } float utils::scaleFactor() { QSettings settings("nheko", "nheko"); return settings.value("settings/scale_factor", -1).toFloat(); } bool utils::respondsToKeyRequests(const std::string &roomId) { return respondsToKeyRequests(QString::fromStdString(roomId)); } bool utils::respondsToKeyRequests(const QString &roomId) { if (roomId.isEmpty()) return false; QSettings settings; return settings.value("rooms/respond_to_key_requests/" + roomId, false).toBool(); } void utils::setKeyRequestsPreference(QString roomId, bool value) { if (roomId.isEmpty()) return; QSettings settings; settings.setValue("rooms/respond_to_key_requests/" + roomId, value); } QString utils::descriptiveTime(const QDateTime &then) { const auto now = QDateTime::currentDateTime(); const auto days = then.daysTo(now); if (days == 0) return then.toString("HH:mm"); else if (days < 2) return QString("Yesterday"); else if (days < 365) return then.toString("dd/MM"); return then.toString("dd/MM/yy"); } DescInfo utils::getMessageDescription(const TimelineEvent &event, const QString &localUser, const QString &room_id) { using Audio = mtx::events::RoomEvent; using Emote = mtx::events::RoomEvent; using File = mtx::events::RoomEvent; using Image = mtx::events::RoomEvent; using Notice = mtx::events::RoomEvent; using Text = mtx::events::RoomEvent; using Video = mtx::events::RoomEvent; using Encrypted = mtx::events::EncryptedEvent; if (boost::get