Skip to content
Snippets Groups Projects
Commit 6f66771b authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Make sorting stabler

parent e5e90fc9
No related branches found
No related tags found
No related merge requests found
......@@ -104,24 +104,29 @@ bool RoomListSortProxy::lessThan(const QModelIndex &rLeft, const QModelIndex &rR
QModelIndex const left_idx = sourceModel()->index(rLeft.row(), 0, QModelIndex());
QModelIndex const right_idx = sourceModel()->index(rRight.row(), 0, QModelIndex());
qDebug() << "left tag:" << sourceModel()->data(left_idx, RoomListModel::TagRole).toString()
<< " right tag: " << sourceModel()->data(right_idx, RoomListModel::TagRole).toString()
<< " compare result: "
<< QString::localeAwareCompare(sourceModel()->data(left_idx, RoomListModel::TagRole).toString(),
sourceModel()->data(right_idx, RoomListModel::TagRole).toString());
if (sourceModel()->data(left_idx, RoomListModel::IsInvite) !=
sourceModel()->data(right_idx, RoomListModel::IsInvite))
return sourceModel()->data(left_idx, RoomListModel::IsInvite) >
sourceModel()->data(right_idx, RoomListModel::IsInvite);
auto left = [this, left_idx](RoomListModel::RoomRoles role) -> QVariant {
return sourceModel()->data(left_idx, role);
};
auto right = [this, right_idx](RoomListModel::RoomRoles role) -> QVariant {
return sourceModel()->data(right_idx, role);
};
qDebug() << "left tag:" << left(RoomListModel::TagRole).toString()
<< " right tag: " << right(RoomListModel::TagRole).toString() << " compare result: "
<< QString::localeAwareCompare(left(RoomListModel::TagRole).toString(),
right(RoomListModel::TagRole).toString());
if (left(RoomListModel::IsInvite) != right(RoomListModel::IsInvite))
return left(RoomListModel::IsInvite) > right(RoomListModel::IsInvite);
else {
if (sourceModel()->data(left_idx, RoomListModel::TagRole).toString() !=
sourceModel()->data(right_idx, RoomListModel::TagRole).toString()) {
return QString::localeAwareCompare(sourceModel()->data(left_idx, RoomListModel::TagRole).toString(),
sourceModel()->data(right_idx, RoomListModel::TagRole).toString()) < 0;
if (left(RoomListModel::TagRole).toString() != right(RoomListModel::TagRole).toString()) {
return QString::localeAwareCompare(left(RoomListModel::TagRole).toString(),
right(RoomListModel::TagRole).toString()) < 0;
} else {
return sourceModel()->data(left_idx, RoomListModel::UnreadNotificationsRole) >
sourceModel()->data(right_idx, RoomListModel::UnreadNotificationsRole);
if (left(RoomListModel::UnreadNotificationsRole) != right(RoomListModel::UnreadNotificationsRole))
return left(RoomListModel::UnreadNotificationsRole) > right(RoomListModel::UnreadNotificationsRole);
else
return rLeft.row() < rRight.row();
}
}
}
......@@ -113,13 +113,14 @@ void Sync::sync() {
qDebug() << QString::fromStdString(room->id);
std::vector<std::string> tags;
for (const auto& e : r.account_data.events)
{
if (const auto t = boost::get<mtx::events::Event<mtx::events::account_data::Tag>>(&e)) {
qDebug() << "Tag event";
std::vector<std::string> tags;
for (const auto &tag : t->content.tags)
tags.push_back(tag.first);
room->applyTags(tags);
}
}
......@@ -135,7 +136,7 @@ void Sync::sync() {
[&timeline](const auto &ev) { timeline.push_back(mtx::events::collections::TimelineEvents{ev}); },
e);
}
room->applyTags(tags);
room->applyEvents(timeline, r.timeline.prev_batch, res.next_batch);
room->applyUnreadNotifications(r.unread_notifications.notification_count);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment