Skip to content
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

Merged
merged 8 commits into from
Jul 10, 2024

Conversation

jmartinesp
Copy link
Member

@jmartinesp jmartinesp commented Jun 26, 2024

Content

  • Add fun isDm(isDirect: Boolean, activeMembersCount: Int): Boolean.
  • Add extension functions that call this isDm using existing data for MatrixRoom and MatrixRoomInfo.
  • Apply these changes through the app.

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

  • Physical
  • Emulator
  • OS version(s): 14

Checklist

Copy link
Member Author

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 🥲 .

Copy link
Contributor

github-actions bot commented Jun 26, 2024

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/b2oG82

/**
* Verifies if a room is considered a direct message one for Element.
*/
object DmChecker {
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@bmarty bmarty Jun 26, 2024

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.

Copy link
Member Author

@jmartinesp jmartinesp Jul 4, 2024

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 Rust RoomInfo which is not available in the matrix.api module.
  • NotificationMapper.map, we only have the NotificationRoomInfo, which also comes from Rust and is not available in matrix.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?

Base automatically changed from misc/jme/new-authentication-flow-rust to develop June 27, 2024 09:44
Also add extension functions for `MatrixRoom` and `MatrixRoomInfo`.
…ncluding:

- Room list.
- Room details screen.
- Invites.
- Notifications.

Replace most `isDirect` usages with `isDm`.
@jmartinesp jmartinesp force-pushed the misc/jme/3078-unify-dm-room-check branch from 345ad1c to c610aa3 Compare July 9, 2024 10:24
@jmartinesp jmartinesp added the PR-Change For updates to an existing feature label Jul 9, 2024
@jmartinesp jmartinesp marked this pull request as ready for review July 9, 2024 10:30
@jmartinesp jmartinesp requested a review from a team as a code owner July 9, 2024 10:30
@jmartinesp jmartinesp requested review from bmarty and removed request for a team July 9, 2024 10:30
@jmartinesp jmartinesp added the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jul 9, 2024
@github-actions github-actions bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jul 9, 2024
Copy link

codecov bot commented Jul 9, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 5 lines in your changes missing coverage. Please review.

Project coverage is 76.12%. Comparing base (b0c9091) to head (6f3deb0).
Report is 25 commits behind head on develop.

Files Patch % Lines
...push/impl/notifications/NotificationDataFactory.kt 25.00% 0 Missing and 3 partials ⚠️
...eatures/roomlist/impl/components/RoomSummaryRow.kt 66.66% 0 Missing and 1 partial ⚠️
...pl/notifications/DefaultNotifiableEventResolver.kt 80.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@jmartinesp jmartinesp force-pushed the misc/jme/3078-unify-dm-room-check branch from dba05a6 to 0ba80b3 Compare July 9, 2024 14:14
@jmartinesp jmartinesp force-pushed the misc/jme/3078-unify-dm-room-check branch from 0ba80b3 to 5266c32 Compare July 9, 2024 14:36
Copy link
Member

@bmarty bmarty left a 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
Copy link
Member

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.

Copy link
Member Author

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())
Copy link
Member

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,
Copy link
Member

@bmarty bmarty Jul 10, 2024

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
Copy link
Member

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.

@jmartinesp
Copy link
Member Author

@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).

@jmartinesp jmartinesp added the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jul 10, 2024
@github-actions github-actions bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jul 10, 2024
@frebib
Copy link
Contributor

frebib commented Jul 10, 2024

Nice, thanks. I'll give it a try later

@jmartinesp jmartinesp requested a review from bmarty July 10, 2024 13:56
@@ -265,7 +265,7 @@ class AcceptDeclineInvitePresenterTest {
return InviteData(
roomId = roomId,
roomName = name,
isDirect = isDirect
isDm = isDirect
Copy link
Member

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.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jmartinesp jmartinesp added the Run-Maestro Starts a Maestro Cloud session to run integration tests label Jul 10, 2024
@jmartinesp jmartinesp enabled auto-merge (squash) July 10, 2024 16:06
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label Jul 10, 2024
Copy link

sonarcloud bot commented Jul 10, 2024

@jmartinesp jmartinesp merged commit 0be7058 into develop Jul 10, 2024
28 checks passed
@jmartinesp jmartinesp deleted the misc/jme/3078-unify-dm-room-check branch July 10, 2024 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Change For updates to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants