summary refs log tree commit diff
path: root/src/RoomDirectoryModel.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-08-17 14:21:04 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-08-17 14:21:04 +0200
commit028bcd5b7c116564b6b44a4ce4c4bdac5ddcb926 (patch)
tree0aae35cd3593b2c356a53792efcf0346f5e9e8b7 /src/RoomDirectoryModel.cpp
parentMerge pull request #659 from kamathmanu/nhekoRoomDirectory (diff)
downloadnheko-028bcd5b7c116564b6b44a4ce4c4bdac5ddcb926.tar.xz
Update join button in room directory after join
Diffstat (limited to 'src/RoomDirectoryModel.cpp')
-rw-r--r--src/RoomDirectoryModel.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/RoomDirectoryModel.cpp b/src/RoomDirectoryModel.cpp
index 61c3eb72..14e0fe84 100644
--- a/src/RoomDirectoryModel.cpp
+++ b/src/RoomDirectoryModel.cpp
@@ -8,10 +8,23 @@
 

 #include <algorithm>

 

-RoomDirectoryModel::RoomDirectoryModel(QObject *parent, const std::string &s)

+RoomDirectoryModel::RoomDirectoryModel(QObject *parent, const std::string &server)

   : QAbstractListModel(parent)

-  , server_(s)

+  , server_(server)

 {

+        connect(ChatPage::instance(), &ChatPage::newRoom, this, [this](const QString &roomid) {

+                auto roomid_ = roomid.toStdString();

+

+                int i = 0;

+                for (const auto &room : publicRoomsData_) {

+                        if (room.room_id == roomid_) {

+                                emit dataChanged(index(i), index(i), {Roles::CanJoin});

+                                break;

+                        }

+                        i++;

+                }

+        });

+

         connect(this,

                 &RoomDirectoryModel::fetchedRoomsBatch,

                 this,

@@ -29,6 +42,7 @@ RoomDirectoryModel::roleNames() const
           {Roles::Topic, "topic"},

           {Roles::MemberCount, "numMembers"},

           {Roles::Previewable, "canPreview"},

+          {Roles::CanJoin, "canJoin"},

         };

 }

 

@@ -67,10 +81,9 @@ RoomDirectoryModel::setSearchTerm(const QString &f)
 }

 

 bool

-RoomDirectoryModel::canJoinRoom(const QByteArray &room)

+RoomDirectoryModel::canJoinRoom(const QString &room) const

 {

-        const QString room_id(room);

-        return !room_id.isEmpty() && !cache::getRoomInfo({room_id.toStdString()}).count(room_id);

+        return !room.isEmpty() && cache::getRoomInfo({room.toStdString()}).empty();

 }

 

 std::vector<std::string>

@@ -116,6 +129,8 @@ RoomDirectoryModel::data(const QModelIndex &index, int role) const
                         return QVariant::fromValue(room_chunk.num_joined_members);

                 case Roles::Previewable:

                         return QVariant::fromValue(room_chunk.world_readable);

+                case Roles::CanJoin:

+                        return canJoinRoom(QString::fromStdString(room_chunk.room_id));

                 }

         }

         return {};