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

Integrate mentions in the composer #1799

Merged
merged 13 commits into from
Nov 20, 2023

Conversation

jmartinesp
Copy link
Member

@jmartinesp jmartinesp commented Nov 14, 2023

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

  • Integrates a new version of the RTE library with better support for mentions.
  • Sets a callback in the mention suggestion selection view to actually insert the selection.
  • Creates MentionSpanProvider to provide the RTE composer with the custom ReplacementSpan for mentions.

Motivation and context

Closes #1453

Screenshots / GIFs

Light Dark
image image

Tests

  • Open a room, type @ in the composer.
  • Select something from the list of suggestions.
  • A mention pill should be added to the editor and when sending, it'll be recognised as an actual mention.

Tested devices

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

Checklist

@jmartinesp jmartinesp force-pushed the feature/jme/integrate-mentions-with-composer branch from 8cabddd to 9270e29 Compare November 14, 2023 11:23
@jmartinesp jmartinesp changed the title WIP Integrate mentions in the composer Nov 14, 2023
Copy link

codecov bot commented Nov 14, 2023

Codecov Report

Attention: 25 lines in your changes are missing coverage. Please review.

Comparison is base (4585597) 63.40% compared to head (8d7f24e) 63.45%.
Report is 39 commits behind head on develop.

❗ Current head 8d7f24e differs from pull request most recent head c8dcfd2. Consider uploading reports for the commit c8dcfd2 to get more accurate results

Files Patch % Lines
...aries/textcomposer/mentions/MentionSpanProvider.kt 71.15% 7 Missing and 8 partials ⚠️
...ent/android/libraries/textcomposer/TextComposer.kt 57.14% 2 Missing and 1 partial ⚠️
...ent/android/features/messages/impl/MessagesView.kt 75.00% 2 Missing ⚠️
.../element/android/libraries/core/data/FilterUpTo.kt 71.42% 1 Missing and 1 partial ⚠️
...ages/impl/mentions/MentionSuggestionsPickerView.kt 87.50% 0 Missing and 1 partial ⚠️
...s/impl/messagecomposer/MessageComposerPresenter.kt 83.33% 0 Missing and 1 partial ⚠️
...ssages/impl/messagecomposer/MessageComposerView.kt 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1799      +/-   ##
===========================================
+ Coverage    63.40%   63.45%   +0.04%     
===========================================
  Files         1293     1296       +3     
  Lines        33628    33727      +99     
  Branches      6982     7002      +20     
===========================================
+ Hits         21322    21401      +79     
- Misses        9117     9129      +12     
- Partials      3189     3197       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jmartinesp jmartinesp force-pushed the feature/jme/integrate-mentions-with-composer branch from 9270e29 to ab624c6 Compare November 15, 2023 14:26
@jmartinesp jmartinesp mentioned this pull request Nov 16, 2023
1 task
Copy link
Contributor

github-actions bot commented Nov 17, 2023

📱 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/3ujdmH

jmartinesp and others added 8 commits November 17, 2023 13:23
    - Add `MentionSpanProvider`.
    - Add custom colors needed for mentions.
    - Use the span provider to render mentions in the composer.
    - Allow selecting users from the mentions suggestions to insert a mention.
@jmartinesp jmartinesp force-pushed the feature/jme/integrate-mentions-with-composer branch from 33689de to cb33a13 Compare November 17, 2023 12:23
@jmartinesp jmartinesp marked this pull request as ready for review November 17, 2023 12:36
@jmartinesp jmartinesp requested a review from a team as a code owner November 17, 2023 12:36
@jmartinesp jmartinesp requested review from ganfra and removed request for a team November 17, 2023 12:36
@frebib
Copy link
Contributor

frebib commented Nov 18, 2023

This works wonderfully! Nice work
There seems to be a small delay after hitting the @ symbol. Is that intended?

@jmartinesp
Copy link
Member Author

This works wonderfully! Nice work There seems to be a small delay after hitting the @ symbol. Is that intended?

Thanks for your comment, I hadn't noticed it myself, but I just realised the code is not working as expected: it's supposed to return the first 100 matching results for the mention, but it was actually returning all possible results, so in large rooms it could be quite slow. I just changed that.

append("mention", mentionSpan, 0)
append(" to the current user and this is a ")
append("mention", mentionSpan2, 0)
append("to other user")
Copy link
Member

Choose a reason for hiding this comment

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

add space before => " to other user" ?

sealed interface RoomMemberSuggestion {
data object Room : RoomMemberSuggestion
data class Member(val roomMember: RoomMember) : RoomMemberSuggestion
sealed interface MentionSuggestion {
Copy link
Member

Choose a reason for hiding this comment

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

I'd extract this class outs of this file


@Suppress("ComposableNaming")
@Composable
fun setup() {
Copy link
Member

Choose a reason for hiding this comment

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

make private?

Copy link
Member

Choose a reason for hiding this comment

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

Is this method called each time composer is recomposed?

Copy link
Member Author

Choose a reason for hiding this comment

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

make private?

I can make it internal at best, since it's used in the rememberMentionSpanProvider function.

Is this method called each time composer is recomposed?

I think so, yeah. Since those colors don't change I'm not sure if they will be re-calculated and re-assigned to each property, but I don't see any other way to be able to reach the @Composable color: we can't use remember or LaunchedEffect for that.

Copy link
Member

@ganfra ganfra left a comment

Choose a reason for hiding this comment

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

Some small remarks otherwise LGTM

@frebib
Copy link
Contributor

frebib commented Nov 20, 2023

This works wonderfully! Nice work There seems to be a small delay after hitting the @ symbol. Is that intended?

Thanks for your comment, I hadn't noticed it myself, but I just realised the code is not working as expected: it's supposed to return the first 100 matching results for the mention, but it was actually returning all possible results, so in large rooms it could be quite slow. I just changed that.

Interestingly (prior to your changes 8d7f24e) for me it consistently takes around 1 second to open both in a group chat with a few participants (~6 iirc) as well as Matrix HQ

@jmartinesp
Copy link
Member Author

Interestingly (prior to your changes 8d7f24e) for me it consistently takes around 1 second to open both in a group chat with a few participants (~6 iirc) as well as Matrix HQ

It's probably the .debounce(0.5.seconds) used to prevent too much computation when the user types really fast. Now that I'm aware of it the delay is quite noticeable, maybe it would be better to just remove this debounce so displaying the results is as immediate as possible.

@jmartinesp
Copy link
Member Author

Interestingly (prior to your changes 8d7f24e) for me it consistently takes around 1 second to open both in a group chat with a few participants (~6 iirc) as well as Matrix HQ

It's probably the .debounce(0.5.seconds) used to prevent too much computation when the user types really fast. Now that I'm aware of it the delay is quite noticeable, maybe it would be better to just remove this debounce so displaying the results is as immediate as possible.

This should now work better: the initial time to display when using @ will be as short as possible with no artificial delays, then when we want to filter out some more by continue typing, there will be slightly shorter debounce than before (0.3s between search runs).

Copy link

sonarcloud bot commented Nov 20, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@jmartinesp jmartinesp merged commit a8fbb88 into develop Nov 20, 2023
13 checks passed
@jmartinesp jmartinesp deleted the feature/jme/integrate-mentions-with-composer branch November 20, 2023 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mentions: @room mention pill
3 participants