|
|
@ -57,6 +57,8 @@ 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 roomid = roomids.at(index.row()); |
|
|
|
auto roomid = roomids.at(index.row()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (models.contains(roomid)) { |
|
|
|
auto room = models.value(roomid); |
|
|
|
auto room = models.value(roomid); |
|
|
|
switch (role) { |
|
|
|
switch (role) { |
|
|
|
case Roles::AvatarUrl: |
|
|
|
case Roles::AvatarUrl: |
|
|
@ -70,7 +72,8 @@ RoomlistModel::data(const QModelIndex &index, int role) const |
|
|
|
case Roles::Time: |
|
|
|
case Roles::Time: |
|
|
|
return room->lastMessage().descriptiveTime; |
|
|
|
return room->lastMessage().descriptiveTime; |
|
|
|
case Roles::Timestamp: |
|
|
|
case Roles::Timestamp: |
|
|
|
return QVariant(static_cast<quint64>(room->lastMessage().timestamp)); |
|
|
|
return QVariant( |
|
|
|
|
|
|
|
static_cast<quint64>(room->lastMessage().timestamp)); |
|
|
|
case Roles::HasUnreadMessages: |
|
|
|
case Roles::HasUnreadMessages: |
|
|
|
return this->roomReadStatus.count(roomid) && |
|
|
|
return this->roomReadStatus.count(roomid) && |
|
|
|
this->roomReadStatus.at(roomid); |
|
|
|
this->roomReadStatus.at(roomid); |
|
|
@ -84,6 +87,36 @@ RoomlistModel::data(const QModelIndex &index, int role) const |
|
|
|
default: |
|
|
|
default: |
|
|
|
return {}; |
|
|
|
return {}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if (invites.contains(roomid)) { |
|
|
|
|
|
|
|
auto room = invites.value(roomid); |
|
|
|
|
|
|
|
switch (role) { |
|
|
|
|
|
|
|
case Roles::AvatarUrl: |
|
|
|
|
|
|
|
return QString::fromStdString(room.avatar_url); |
|
|
|
|
|
|
|
case Roles::RoomName: |
|
|
|
|
|
|
|
return QString::fromStdString(room.name); |
|
|
|
|
|
|
|
case Roles::RoomId: |
|
|
|
|
|
|
|
return roomid; |
|
|
|
|
|
|
|
case Roles::LastMessage: |
|
|
|
|
|
|
|
return room.msgInfo.body; |
|
|
|
|
|
|
|
case Roles::Time: |
|
|
|
|
|
|
|
return room.msgInfo.descriptiveTime; |
|
|
|
|
|
|
|
case Roles::Timestamp: |
|
|
|
|
|
|
|
return QVariant(static_cast<quint64>(room.msgInfo.timestamp)); |
|
|
|
|
|
|
|
case Roles::HasUnreadMessages: |
|
|
|
|
|
|
|
case Roles::HasLoudNotification: |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
case Roles::NotificationCount: |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
case Roles::IsInvite: |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
case Roles::IsSpace: |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return {}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return {}; |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return {}; |
|
|
|
return {}; |
|
|
|
} |
|
|
|
} |
|
|
@ -109,7 +142,7 @@ RoomlistModel::updateReadStatus(const std::map<QString, bool> roomReadStatus_) |
|
|
|
Roles::HasUnreadMessages, |
|
|
|
Roles::HasUnreadMessages, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
void |
|
|
|
void |
|
|
|
RoomlistModel::addRoom(const QString &room_id, bool suppressInsertNotification) |
|
|
|
RoomlistModel::addRoom(const QString &room_id, bool suppressInsertNotification) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -186,11 +219,21 @@ RoomlistModel::addRoom(const QString &room_id, bool suppressInsertNotification) |
|
|
|
|
|
|
|
|
|
|
|
newRoom->updateLastMessage(); |
|
|
|
newRoom->updateLastMessage(); |
|
|
|
|
|
|
|
|
|
|
|
if (!suppressInsertNotification) |
|
|
|
bool wasInvite = invites.contains(room_id); |
|
|
|
|
|
|
|
if (!suppressInsertNotification && !wasInvite) |
|
|
|
beginInsertRows(QModelIndex(), (int)roomids.size(), (int)roomids.size()); |
|
|
|
beginInsertRows(QModelIndex(), (int)roomids.size(), (int)roomids.size()); |
|
|
|
|
|
|
|
|
|
|
|
models.insert(room_id, std::move(newRoom)); |
|
|
|
models.insert(room_id, std::move(newRoom)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (wasInvite) { |
|
|
|
|
|
|
|
auto idx = roomidToIndex(room_id); |
|
|
|
|
|
|
|
invites.remove(room_id); |
|
|
|
|
|
|
|
emit dataChanged(index(idx), index(idx)); |
|
|
|
|
|
|
|
} else { |
|
|
|
roomids.push_back(room_id); |
|
|
|
roomids.push_back(room_id); |
|
|
|
if (!suppressInsertNotification) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!suppressInsertNotification && !wasInvite) |
|
|
|
endInsertRows(); |
|
|
|
endInsertRows(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -234,20 +277,50 @@ RoomlistModel::sync(const mtx::responses::Rooms &rooms) |
|
|
|
if (idx != -1) { |
|
|
|
if (idx != -1) { |
|
|
|
beginRemoveRows(QModelIndex(), idx, idx); |
|
|
|
beginRemoveRows(QModelIndex(), idx, idx); |
|
|
|
roomids.erase(roomids.begin() + idx); |
|
|
|
roomids.erase(roomids.begin() + idx); |
|
|
|
|
|
|
|
if (models.contains(QString::fromStdString(room_id))) |
|
|
|
models.remove(QString::fromStdString(room_id)); |
|
|
|
models.remove(QString::fromStdString(room_id)); |
|
|
|
|
|
|
|
else if (invites.contains(QString::fromStdString(room_id))) |
|
|
|
|
|
|
|
invites.remove(QString::fromStdString(room_id)); |
|
|
|
endRemoveRows(); |
|
|
|
endRemoveRows(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto &[room_id, room] : rooms.invite) { |
|
|
|
|
|
|
|
(void)room_id; |
|
|
|
|
|
|
|
auto qroomid = QString::fromStdString(room_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto invite = cache::client()->invite(room_id); |
|
|
|
|
|
|
|
if (!invite) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (invites.contains(qroomid)) { |
|
|
|
|
|
|
|
invites[qroomid] = *invite; |
|
|
|
|
|
|
|
auto idx = roomidToIndex(qroomid); |
|
|
|
|
|
|
|
emit dataChanged(index(idx), index(idx)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
beginInsertRows(QModelIndex(), (int)roomids.size(), (int)roomids.size()); |
|
|
|
|
|
|
|
invites.insert(qroomid, *invite); |
|
|
|
|
|
|
|
roomids.push_back(std::move(qroomid)); |
|
|
|
|
|
|
|
endInsertRows(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
RoomlistModel::initializeRooms(const std::vector<QString> &roomIds_) |
|
|
|
RoomlistModel::initializeRooms() |
|
|
|
{ |
|
|
|
{ |
|
|
|
beginResetModel(); |
|
|
|
beginResetModel(); |
|
|
|
models.clear(); |
|
|
|
models.clear(); |
|
|
|
roomids.clear(); |
|
|
|
roomids.clear(); |
|
|
|
for (const auto &id : roomIds_) |
|
|
|
invites.clear(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invites = cache::client()->invites(); |
|
|
|
|
|
|
|
for (const auto &id : invites.keys()) |
|
|
|
|
|
|
|
roomids.push_back(id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto &id : cache::client()->roomIds()) |
|
|
|
addRoom(id, true); |
|
|
|
addRoom(id, true); |
|
|
|
|
|
|
|
|
|
|
|
endResetModel(); |
|
|
|
endResetModel(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -256,10 +329,42 @@ RoomlistModel::clear() |
|
|
|
{ |
|
|
|
{ |
|
|
|
beginResetModel(); |
|
|
|
beginResetModel(); |
|
|
|
models.clear(); |
|
|
|
models.clear(); |
|
|
|
|
|
|
|
invites.clear(); |
|
|
|
roomids.clear(); |
|
|
|
roomids.clear(); |
|
|
|
endResetModel(); |
|
|
|
endResetModel(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
RoomlistModel::acceptInvite(QString roomid) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (invites.contains(roomid)) { |
|
|
|
|
|
|
|
auto idx = roomidToIndex(roomid); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (idx != -1) { |
|
|
|
|
|
|
|
beginRemoveRows(QModelIndex(), idx, idx); |
|
|
|
|
|
|
|
roomids.erase(roomids.begin() + idx); |
|
|
|
|
|
|
|
invites.remove(roomid); |
|
|
|
|
|
|
|
endRemoveRows(); |
|
|
|
|
|
|
|
ChatPage::instance()->joinRoom(roomid); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
RoomlistModel::declineInvite(QString roomid) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (invites.contains(roomid)) { |
|
|
|
|
|
|
|
auto idx = roomidToIndex(roomid); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (idx != -1) { |
|
|
|
|
|
|
|
beginRemoveRows(QModelIndex(), idx, idx); |
|
|
|
|
|
|
|
roomids.erase(roomids.begin() + idx); |
|
|
|
|
|
|
|
invites.remove(roomid); |
|
|
|
|
|
|
|
endRemoveRows(); |
|
|
|
|
|
|
|
ChatPage::instance()->leaveRoom(roomid); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
namespace { |
|
|
|
enum NotificationImportance : short |
|
|
|
enum NotificationImportance : short |
|
|
|
{ |
|
|
|
{ |
|
|
|