|
|
@ -4,6 +4,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "RoomlistModel.h" |
|
|
|
#include "RoomlistModel.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Cache_p.h" |
|
|
|
#include "ChatPage.h" |
|
|
|
#include "ChatPage.h" |
|
|
|
#include "MatrixClient.h" |
|
|
|
#include "MatrixClient.h" |
|
|
|
#include "MxcImageProvider.h" |
|
|
|
#include "MxcImageProvider.h" |
|
|
@ -26,6 +27,11 @@ RoomlistModel::RoomlistModel(TimelineViewManager *parent) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(this, |
|
|
|
|
|
|
|
&RoomlistModel::totalUnreadMessageCountUpdated, |
|
|
|
|
|
|
|
ChatPage::instance(), |
|
|
|
|
|
|
|
&ChatPage::unreadMessages); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QHash<int, QByteArray> |
|
|
|
QHash<int, QByteArray> |
|
|
@ -34,8 +40,11 @@ RoomlistModel::roleNames() const |
|
|
|
return { |
|
|
|
return { |
|
|
|
{AvatarUrl, "avatarUrl"}, |
|
|
|
{AvatarUrl, "avatarUrl"}, |
|
|
|
{RoomName, "roomName"}, |
|
|
|
{RoomName, "roomName"}, |
|
|
|
|
|
|
|
{RoomId, "roomId"}, |
|
|
|
{LastMessage, "lastMessage"}, |
|
|
|
{LastMessage, "lastMessage"}, |
|
|
|
|
|
|
|
{Timestamp, "timestamp"}, |
|
|
|
{HasUnreadMessages, "hasUnreadMessages"}, |
|
|
|
{HasUnreadMessages, "hasUnreadMessages"}, |
|
|
|
|
|
|
|
{HasLoudNotification, "hasLoudNotification"}, |
|
|
|
{NotificationCount, "notificationCount"}, |
|
|
|
{NotificationCount, "notificationCount"}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
@ -44,18 +53,26 @@ QVariant |
|
|
|
RoomlistModel::data(const QModelIndex &index, int role) const |
|
|
|
RoomlistModel::data(const QModelIndex &index, int role) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (index.row() >= 0 && static_cast<size_t>(index.row()) < roomids.size()) { |
|
|
|
if (index.row() >= 0 && static_cast<size_t>(index.row()) < roomids.size()) { |
|
|
|
auto room = models.value(roomids.at(index.row())); |
|
|
|
auto roomid = roomids.at(index.row()); |
|
|
|
|
|
|
|
auto room = models.value(roomid); |
|
|
|
switch (role) { |
|
|
|
switch (role) { |
|
|
|
case Roles::AvatarUrl: |
|
|
|
case Roles::AvatarUrl: |
|
|
|
return room->roomAvatarUrl(); |
|
|
|
return room->roomAvatarUrl(); |
|
|
|
case Roles::RoomName: |
|
|
|
case Roles::RoomName: |
|
|
|
return room->roomName(); |
|
|
|
return room->roomName(); |
|
|
|
|
|
|
|
case Roles::RoomId: |
|
|
|
|
|
|
|
return room->roomId(); |
|
|
|
case Roles::LastMessage: |
|
|
|
case Roles::LastMessage: |
|
|
|
return QString("Nico: Hahaha, this is funny!"); |
|
|
|
return room->lastMessage().body; |
|
|
|
|
|
|
|
case Roles::Timestamp: |
|
|
|
|
|
|
|
return room->lastMessage().descriptiveTime; |
|
|
|
case Roles::HasUnreadMessages: |
|
|
|
case Roles::HasUnreadMessages: |
|
|
|
return true; |
|
|
|
return this->roomReadStatus.count(roomid) && |
|
|
|
|
|
|
|
this->roomReadStatus.at(roomid); |
|
|
|
|
|
|
|
case Roles::HasLoudNotification: |
|
|
|
|
|
|
|
return room->hasMentions(); |
|
|
|
case Roles::NotificationCount: |
|
|
|
case Roles::NotificationCount: |
|
|
|
return 5; |
|
|
|
return room->notificationCount(); |
|
|
|
default: |
|
|
|
default: |
|
|
|
return {}; |
|
|
|
return {}; |
|
|
|
} |
|
|
|
} |
|
|
@ -64,10 +81,38 @@ RoomlistModel::data(const QModelIndex &index, int role) const |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
RoomlistModel::updateReadStatus(const std::map<QString, bool> roomReadStatus_) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::vector<int> roomsToUpdate; |
|
|
|
|
|
|
|
roomsToUpdate.resize(roomReadStatus_.size()); |
|
|
|
|
|
|
|
for (const auto &[roomid, roomUnread] : roomReadStatus_) { |
|
|
|
|
|
|
|
if (roomUnread != roomReadStatus[roomid]) { |
|
|
|
|
|
|
|
roomsToUpdate.push_back(this->roomidToIndex(roomid)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this->roomReadStatus = roomReadStatus_; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (auto idx : roomsToUpdate) { |
|
|
|
|
|
|
|
emit dataChanged(index(idx), |
|
|
|
|
|
|
|
index(idx), |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Roles::HasUnreadMessages, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
void |
|
|
|
void |
|
|
|
RoomlistModel::addRoom(const QString &room_id, bool suppressInsertNotification) |
|
|
|
RoomlistModel::addRoom(const QString &room_id, bool suppressInsertNotification) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!models.contains(room_id)) { |
|
|
|
if (!models.contains(room_id)) { |
|
|
|
|
|
|
|
// ensure we get read status updates and are only connected once
|
|
|
|
|
|
|
|
connect(cache::client(), |
|
|
|
|
|
|
|
&Cache::roomReadStatus, |
|
|
|
|
|
|
|
this, |
|
|
|
|
|
|
|
&RoomlistModel::updateReadStatus, |
|
|
|
|
|
|
|
Qt::UniqueConnection); |
|
|
|
|
|
|
|
|
|
|
|
QSharedPointer<TimelineModel> newRoom(new TimelineModel(manager, room_id)); |
|
|
|
QSharedPointer<TimelineModel> newRoom(new TimelineModel(manager, room_id)); |
|
|
|
newRoom->setDecryptDescription( |
|
|
|
newRoom->setDecryptDescription( |
|
|
|
ChatPage::instance()->userSettings()->decryptSidebar()); |
|
|
|
ChatPage::instance()->userSettings()->decryptSidebar()); |
|
|
@ -80,6 +125,56 @@ RoomlistModel::addRoom(const QString &room_id, bool suppressInsertNotification) |
|
|
|
&TimelineModel::forwardToRoom, |
|
|
|
&TimelineModel::forwardToRoom, |
|
|
|
manager, |
|
|
|
manager, |
|
|
|
&TimelineViewManager::forwardMessageToRoom); |
|
|
|
&TimelineViewManager::forwardMessageToRoom); |
|
|
|
|
|
|
|
connect( |
|
|
|
|
|
|
|
newRoom.data(), &TimelineModel::lastMessageChanged, this, [room_id, this]() { |
|
|
|
|
|
|
|
auto idx = this->roomidToIndex(room_id); |
|
|
|
|
|
|
|
emit dataChanged(index(idx), |
|
|
|
|
|
|
|
index(idx), |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Roles::HasLoudNotification, |
|
|
|
|
|
|
|
Roles::LastMessage, |
|
|
|
|
|
|
|
Roles::Timestamp, |
|
|
|
|
|
|
|
Roles::NotificationCount, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
connect( |
|
|
|
|
|
|
|
newRoom.data(), &TimelineModel::roomAvatarUrlChanged, this, [room_id, this]() { |
|
|
|
|
|
|
|
auto idx = this->roomidToIndex(room_id); |
|
|
|
|
|
|
|
emit dataChanged(index(idx), |
|
|
|
|
|
|
|
index(idx), |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Roles::AvatarUrl, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
connect(newRoom.data(), &TimelineModel::roomNameChanged, this, [room_id, this]() { |
|
|
|
|
|
|
|
auto idx = this->roomidToIndex(room_id); |
|
|
|
|
|
|
|
emit dataChanged(index(idx), |
|
|
|
|
|
|
|
index(idx), |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Roles::RoomName, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
connect( |
|
|
|
|
|
|
|
newRoom.data(), &TimelineModel::notificationsChanged, this, [room_id, this]() { |
|
|
|
|
|
|
|
auto idx = this->roomidToIndex(room_id); |
|
|
|
|
|
|
|
emit dataChanged(index(idx), |
|
|
|
|
|
|
|
index(idx), |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Roles::HasLoudNotification, |
|
|
|
|
|
|
|
Roles::NotificationCount, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int total_unread_msgs = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto &room : models) { |
|
|
|
|
|
|
|
if (!room.isNull()) |
|
|
|
|
|
|
|
total_unread_msgs += room->notificationCount(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emit totalUnreadMessageCountUpdated(total_unread_msgs); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newRoom->updateLastMessage(); |
|
|
|
|
|
|
|
|
|
|
|
if (!suppressInsertNotification) |
|
|
|
if (!suppressInsertNotification) |
|
|
|
beginInsertRows(QModelIndex(), (int)roomids.size(), (int)roomids.size()); |
|
|
|
beginInsertRows(QModelIndex(), (int)roomids.size(), (int)roomids.size()); |
|
|
@ -97,8 +192,8 @@ RoomlistModel::sync(const mtx::responses::Rooms &rooms) |
|
|
|
// addRoom will only add the room, if it doesn't exist
|
|
|
|
// addRoom will only add the room, if it doesn't exist
|
|
|
|
addRoom(QString::fromStdString(room_id)); |
|
|
|
addRoom(QString::fromStdString(room_id)); |
|
|
|
const auto &room_model = models.value(QString::fromStdString(room_id)); |
|
|
|
const auto &room_model = models.value(QString::fromStdString(room_id)); |
|
|
|
room_model->syncState(room.state); |
|
|
|
room_model->sync(room); |
|
|
|
room_model->addEvents(room.timeline); |
|
|
|
// room_model->addEvents(room.timeline);
|
|
|
|
connect(room_model.data(), |
|
|
|
connect(room_model.data(), |
|
|
|
&TimelineModel::newCallEvent, |
|
|
|
&TimelineModel::newCallEvent, |
|
|
|
manager->callManager(), |
|
|
|
manager->callManager(), |
|
|
|