nheko/src/timeline2/TimelineViewManager.cpp

56 lines
1.6 KiB
C++
Raw Normal View History

2019-08-30 19:29:25 +02:00
#include "TimelineViewManager.h"
2019-08-30 23:20:53 +02:00
#include <QMetaType>
#include <QQmlContext>
#include "Logging.h"
2019-08-30 19:29:25 +02:00
TimelineViewManager::TimelineViewManager(QWidget *parent)
{
view = new QQuickView();
container = QWidget::createWindowContainer(view, parent);
container->setMinimumSize(200, 200);
2019-08-31 22:43:31 +02:00
view->rootContext()->setContextProperty("timelineManager", this);
2019-08-30 19:29:25 +02:00
view->setSource(QUrl("qrc:///qml/TimelineView.qml"));
2019-08-30 23:20:53 +02:00
}
void
TimelineViewManager::initialize(const mtx::responses::Rooms &rooms)
{
for (auto it = rooms.join.cbegin(); it != rooms.join.cend(); ++it) {
addRoom(QString::fromStdString(it->first));
2019-08-31 22:43:31 +02:00
models.value(QString::fromStdString(it->first))->addEvents(it->second.timeline);
2019-08-30 23:20:53 +02:00
}
}
void
TimelineViewManager::addRoom(const QString &room_id)
{
if (!models.contains(room_id))
models.insert(room_id, QSharedPointer<TimelineModel>(new TimelineModel(room_id)));
2019-08-30 23:20:53 +02:00
}
void
TimelineViewManager::setHistoryView(const QString &room_id)
{
nhlog::ui()->info("Trying to activate room {}", room_id.toStdString());
auto room = models.find(room_id);
if (room != models.end()) {
2019-08-31 22:43:31 +02:00
timeline_ = room.value().get();
timeline_->fetchHistory();
2019-08-31 22:43:31 +02:00
emit activeTimelineChanged(timeline_);
2019-08-30 23:20:53 +02:00
nhlog::ui()->info("Activated room {}", room_id.toStdString());
}
}
void
TimelineViewManager::initWithMessages(const std::map<QString, mtx::responses::Timeline> &msgs)
{
for (const auto &e : msgs) {
addRoom(e.first);
2019-08-31 22:43:31 +02:00
models.value(e.first)->addEvents(e.second);
2019-08-30 23:20:53 +02:00
}
2019-08-30 19:29:25 +02:00
}