diff options
-rw-r--r-- | connection.cpp | 23 | ||||
-rw-r--r-- | connection.h | 3 |
2 files changed, 26 insertions, 0 deletions
diff --git a/connection.cpp b/connection.cpp index fb946392..df9fd35f 100644 --- a/connection.cpp +++ b/connection.cpp @@ -525,6 +525,29 @@ QUrl Connection::homeserver() const return d->data->baseUrl(); } +Room* Connection::room(const QString& roomId, JoinStates states) const +{ + Room* room = d->roomMap.value({roomId, false}, nullptr); + if (states.testFlag(JoinState::Join) && + room && room->joinState() == JoinState::Join) + return room; + + if (states.testFlag(JoinState::Invite)) + if (Room* invRoom = invitation(roomId)) + return invRoom; + + if (states.testFlag(JoinState::Leave) && + room && room->joinState() == JoinState::Leave) + return room; + + return nullptr; +} + +Room* Connection::invitation(const QString& roomId) const +{ + return d->roomMap.value({roomId, true}, nullptr); +} + User* Connection::user(const QString& userId) { if( d->userMap.contains(userId) ) diff --git a/connection.h b/connection.h index e046d4a0..4497e200 100644 --- a/connection.h +++ b/connection.h @@ -107,6 +107,9 @@ namespace QMatrixClient // FIXME: Convert Q_INVOKABLEs to Q_PROPERTIES // (breaks back-compatibility) QUrl homeserver() const; + Q_INVOKABLE Room* room(const QString& roomId, + JoinStates states = JoinState::Invite|JoinState::Join) const; + Q_INVOKABLE Room* invitation(const QString& roomId) const; Q_INVOKABLE User* user(const QString& userId); const User* user() const; User* user(); |