-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify the way we decide whether a room is a DM or a group room #3100
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the magic happens. I'm bad at naming classes 🥲 .
📱 Scan the QR code below to install the build (arm64 only) for this PR. |
/** | ||
* Verifies if a room is considered a direct message one for Element. | ||
*/ | ||
object DmChecker { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not introduce a class for this, but rather create some extensions, like RoomInfo.isElementDm()
, MatrixRoomInfo.isElementDm()
, etc.
If all those extensions have the same name, and all in the same file, I think it can work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid if we have 3, 4 of these extensions with exactly the same code inside them we might want to update them and forget about some of them. That was why I created this object.
We could make it so the extensions all called the same private function underneath though, so we could ensure the check is done with the same piece of code for every one of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
. o O (Why do we have so many types to describe the same thing?)
Still it will be cleaner and less error prone to use an extension at the call site.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of places where it wouldn't be possible to just use extensions:
RoomSummaryDetailsFactory.create
: it uses a RustRoomInfo
which is not available in thematrix.api
module.NotificationMapper.map
, we only have theNotificationRoomInfo
, which also comes from Rust and is not available inmatrix.api
.
Either we keep the DmChecker
object for those or we create a public fun isRoomDm(isDirect: Boolean, activeMemeberCount: Int): Boolean
that can be called for these cases.
WDYT?
Also add extension functions for `MatrixRoom` and `MatrixRoomInfo`.
…ncluding: - Room list. - Room details screen. - Invites. - Notifications. Replace most `isDirect` usages with `isDm`.
345ad1c
to
c610aa3
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3100 +/- ##
========================================
Coverage 76.11% 76.12%
========================================
Files 1640 1641 +1
Lines 38622 38629 +7
Branches 7469 7468 -1
========================================
+ Hits 29396 29405 +9
+ Misses 5333 5332 -1
+ Partials 3893 3892 -1 ☔ View full report in Codecov by Sentry. |
dba05a6
to
0ba80b3
Compare
0ba80b3
to
5266c32
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, only a few remarks left, let me know what you think.
* @param activeMembersCount the number of active members in the room (joined or invited) | ||
*/ | ||
fun isDm(isDirect: Boolean, activeMembersCount: Int): Boolean { | ||
return isDirect && activeMembersCount <= 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly we cannot rely on the number of activeMembersCount since we can have bot like AuditBot
or AdminBot
in all the DM.
We will have to find a solution to manage such rooms.
But I agree that this is not new with this PR, so we may handle this later, and so this is not a blocker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we should make explicit changes in the SDK to support bots in DMs.
/** | ||
* Returns whether the [MatrixRoomInfo] is from a DM. | ||
*/ | ||
val MatrixRoomInfo.isDm get() = isDm(isDirect, activeMembersCount.toInt()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for those handy extensions!
@@ -290,5 +290,5 @@ internal fun RoomListRoomSummary.toInviteData() = InviteData( | |||
roomId = roomId, | |||
// Note: `name` should not be null at this point, but just in case, fallback to the roomId | |||
roomName = name ?: roomId.value, | |||
isDirect = isDirect, | |||
isDirect = isDm, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity, maybe rename InviteData.isDirect
to InviteData.isDm
?
isDirect
should be reserved for the value from the Matrix protocol.
Also, and related, on JoinRoomPresenter, maybe replace
isDirect = isDirect
by
isDm = isDm(isDirect, numberOfMembers?.toInt() ?: 2)
@@ -91,6 +90,8 @@ class FakeMatrixRoom( | |||
canRedactOwn: Boolean = false, | |||
canRedactOther: Boolean = false, | |||
) : MatrixRoom { | |||
override val isOneToOne: Boolean = activeMemberCount <= 2L |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to override the default value (which is activeMemberCount == 2L
) here? It looks like this is against what the spec says.
@frebib FWIW this PR removes the 'isEncrypted' check for DMs, so I think it should be quite similar to what your previous PR did (only here we try to centralise the check for the whole app). |
Nice, thanks. I'll give it a try later |
@@ -265,7 +265,7 @@ class AcceptDeclineInvitePresenterTest { | |||
return InviteData( | |||
roomId = roomId, | |||
roomName = name, | |||
isDirect = isDirect | |||
isDm = isDirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename also the parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Quality Gate passedIssues Measures |
Content
fun isDm(isDirect: Boolean, activeMembersCount: Int): Boolean
.isDm
using existing data forMatrixRoom
andMatrixRoomInfo
.Motivation and context
Up until now, different parts of the app used different definitions of what a DM is or when should we distinguish between a group room and a direct one. The idea is to always use this function as the source of truth in all parts of the app.
Tests
Most things should work as before, but unencrypted direct rooms with 2 people should also be considered DMs and have the alternative UI/logic, matching Element Web's behaviour (except when there are more than 2 people in the room).
Notifications now also use the more strict definition of what a DM is in order to display custom avatar images or texts.
Tested devices
Checklist