From 6953e55361f600a591c08b9cd287a350230b3ef8 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Mon, 23 Aug 2021 08:42:49 +0200 Subject: Room: isMember(); memberState() only needs user id Room::memberJoinState() was only used to check if the user has joined the room (it couldn't be used for anything else), meaning that its best replacement is actually not memberState() but isMember() introduced hereby. It's also better to pass user ids instead of User objects to memberState() and isMember() since that is enough to check membership. # Conflicts: # lib/room.cpp # lib/room.h --- lib/room.cpp | 29 +++++++++++++++++------------ lib/room.h | 7 +++++-- 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/room.cpp b/lib/room.cpp index 398b3ec8..45f1af53 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -590,9 +590,14 @@ JoinState Room::memberJoinState(User* user) const : JoinState::Leave; } -Membership Room::memberState(User* user) const +Membership Room::memberState(const QString& userId) const { - return d->getCurrentState(user->id())->membership(); + return d->getCurrentState(userId)->membership(); +} + +bool Room::isMember(const QString& userId) const +{ + return memberState(userId) == Membership::Join; } JoinState Room::joinState() const { return d->joinState; } @@ -2698,11 +2703,10 @@ Room::Changes Room::processEphemeralEvent(EventPtr&& event) et.start(); if (auto* evt = eventCast(event)) { d->usersTyping.clear(); - for (const auto& userId : evt->users()) { - auto u = user(userId); - if (memberJoinState(u) == JoinState::Join) - d->usersTyping.append(u); - } + for (const auto& userId : evt->users()) + if (isMember(userId)) + d->usersTyping.append(user(userId)); + if (evt->users().size() > 3 || et.nsecsElapsed() >= profilerMinNsecs()) qCDebug(PROFILER) << "*** Room::processEphemeralEvent(typing):" << evt->users().size() << "users," << et; @@ -2726,9 +2730,9 @@ Room::Changes Room::processEphemeralEvent(EventPtr&& event) for (const Receipt& r : p.receipts) { if (r.userId == connection()->userId()) continue; // FIXME, #185 - auto u = user(r.userId); - if (memberJoinState(u) == JoinState::Join) - changes |= d->promoteReadMarker(u, newMarker); + if (isMember(r.userId)) + changes |= + d->promoteReadMarker(user(r.userId), newMarker); } } else { qCDebug(EPHEMERAL) << "Event" << p.evtId @@ -2740,9 +2744,10 @@ Room::Changes Room::processEphemeralEvent(EventPtr&& event) for (const Receipt& r : p.receipts) { if (r.userId == connection()->userId()) continue; // FIXME, #185 + if (!isMember(r.userId)) + continue; auto u = user(r.userId); - if (memberJoinState(u) == JoinState::Join - && readMarker(u) == historyEdge()) + if (readMarker(u) == historyEdge()) changes |= d->setLastReadEvent(u, p.evtId); } } diff --git a/lib/room.h b/lib/room.h index de0c7504..179295d0 100644 --- a/lib/room.h +++ b/lib/room.h @@ -240,13 +240,16 @@ public: * * \return Join if the user is a room member; Leave otherwise */ - Q_DECL_DEPRECATED_X("Use memberState and check against the mask") // + Q_DECL_DEPRECATED_X("Use isMember() instead") Q_INVOKABLE Quotient::JoinState memberJoinState(Quotient::User* user) const; //! \brief Check the join state of a given user in this room //! //! \return the given user's state with respect to the room - Q_INVOKABLE Quotient::Membership memberState(User* user) const; + Q_INVOKABLE Quotient::Membership memberState(const QString& userId) const; + + //! Check whether a user with the given id is a member of the room + Q_INVOKABLE bool isMember(const QString& userId) const; //! \brief Get a display name (without disambiguation) for the given member //! -- cgit v1.2.3