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

[Location sharing] - Delete action on a live message (PSG-523) #6486

Merged
merged 19 commits into from
Jul 19, 2022

Conversation

mnaturel
Copy link
Contributor

@mnaturel mnaturel commented Jul 6, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Adding the remove action to a live location share message. Aggregated summaries for a live are removed from database after it has been redacted.

Motivation and context

Closes #6437

Screenshots / GIFs

Tests

  • Go to a room
  • Share a live location
  • Long press on the message
  • Check the "Remove" action is available
  • Press the "Remove" action
  • Check a dialog to confirm is displayed
  • Confirm the remove
  • Check the message is replaced by a "Deleted message" texts
  • Check the location sharing service is stopped (in the case the live was not manually stopped before remove)

As there is a database migration, try to update the app from a previous version and check there is no crash at startup.

Tested devices

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

Checklist

@mnaturel mnaturel force-pushed the feature/mna/delete-lls branch from d7071ed to 332fcc5 Compare July 8, 2022 14:40
@mnaturel mnaturel changed the base branch from develop to feature/mna/collapse-deleted-events July 8, 2022 14:40
@mnaturel mnaturel force-pushed the feature/mna/delete-lls branch from a7bd31b to 97b6caf Compare July 11, 2022 12:54
@mnaturel mnaturel force-pushed the feature/mna/collapse-deleted-events branch from 8150790 to 67c7c0f Compare July 11, 2022 14:29
@mnaturel mnaturel force-pushed the feature/mna/delete-lls branch 3 times, most recently from d5d584a to 7ab6faf Compare July 12, 2022 15:07
@mnaturel mnaturel marked this pull request as ready for review July 12, 2022 15:09
@mnaturel mnaturel requested review from a team and ouchadam and removed request for a team July 12, 2022 15:09
roomId = params.roomId,
reason = params.reason
)
relatedEventIds.forEach { eventId ->
Copy link
Contributor

Choose a reason for hiding this comment

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

if one of these fails should we continue the redactions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In here, we are only creating and posting tasks to redact the events. It means errors and retries will be handled internally inside the EventSenderProcessor. I don't know how to handle it differently since we want to have fast UI feedback when doing such action.


@After
fun tearDown() {
unmockkAll()
Copy link
Contributor

@ouchadam ouchadam Jul 14, 2022

Choose a reason for hiding this comment

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

if there's no statics being mocked we can avoid the tear down

just seen further down the FakeRealmConfiguration needs it!

private fun redactEvent(eventId: String, roomId: String, reason: String?) {
Timber.d("redacting event of id $eventId")
val redactionEcho = localEchoEventFactory.createRedactEvent(roomId, eventId, reason)
localEchoEventFactory.createLocalEcho(redactionEcho)
Copy link
Contributor

Choose a reason for hiding this comment

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

this function name always catches me off guard as it's a create and persist unlike the other functions on localEchoEventFactory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it can be confusing, I will try to find a better name for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed it, see efa356e

}

@Test
fun `given parameters when calling the task then it is correctly executed`() = runTest {
Copy link
Contributor

@ouchadam ouchadam Jul 14, 2022

Choose a reason for hiding this comment

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

this test name feels a little bit generic 🤔 if we match the implementation then we would get when redacting then redacts event and related and creates redacted local echos

due to the amount of setup needed it makes the test a bit tricky to quickly read, what do you think about extracting some of the setup/verification?

val summary = createSummary(RELATED_EVENT_IDS) 
givenSummaryForEventId(AN_EVENT_ID, aggregatedSummaryEntity)
val redactedEchos = givenCreatesRedactedLocalEchos(AN_EVENT_ID + RELATED_EVENT_IDS) 

defaultRedactLiveLocationShareTask.execute(params)

verifyEventsRedacted(AN_EVENT_ID + RELATED_EVENT_IDS)
verifyLocalEchosCreated(redactedEchos)
verifyEventsRedacted(redactedEchos)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree thanks for the suggestions. I did some refactoring on this test. See 131f97b

import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import javax.inject.Inject

class CheckIfCanRedactEventUseCase @Inject constructor(
Copy link
Contributor

Choose a reason for hiding this comment

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

💯 for extracting the use case


fun execute(event: TimelineEvent, actionPermissions: ActionPermissions): Boolean {
// Only some event types are supported for the moment
val canRedactEventTypes = listOf(EventType.MESSAGE, EventType.STICKER) +
Copy link
Contributor

Choose a reason for hiding this comment

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

using a single return when here could help reduce the amount of exit points (and in turn the complexity of the function)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, in fact a simple if is easier to read here. See 1e872a8

import timber.log.Timber
import javax.inject.Inject

class CheckIfLiveLocationShareIsRedactedUseCase @Inject constructor(
Copy link
Contributor

Choose a reason for hiding this comment

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

does this class need to be specific to LocationShare? looks like it might be able to become aIsEventRedactedUseCase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you are right. I extracted the use case into a dedicated feature/redaction package so that it can be reused elsewhere. See 7252047

fun `given an event with empty id when calling use case then nothing is done`() = runTest {
val event = Event(eventId = "")

redactLiveLocationShareEventUseCase.execute(event = event, room = fakeRoom, reason = A_REASON)
Copy link
Contributor

Choose a reason for hiding this comment

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

we could also verify no interactions for reacting to help make the test more resilient

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was done implicitely by not mocking the call to the redact method in this case. But I added an explicit verification. See f784fa2

Copy link
Contributor

@ouchadam ouchadam left a comment

Choose a reason for hiding this comment

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

so many tests and usecases 😍 !

@mnaturel mnaturel force-pushed the feature/mna/collapse-deleted-events branch from 59632bf to add7a5f Compare July 18, 2022 08:05
@mnaturel mnaturel force-pushed the feature/mna/delete-lls branch from 7ab6faf to e845f33 Compare July 18, 2022 08:23
@mnaturel mnaturel requested a review from onurays July 18, 2022 13:25

suspend fun execute(event: Event, room: Room, reason: String?) {
event.eventId
?.takeUnless { it.isEmpty() }
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice.


return event.root.getClearType() in canRedactEventTypes &&
// Message sent by the current user can always be redacted, else check permission for messages sent by other users
(event.root.senderId == activeSessionHolder.getActiveSession().myUserId || actionPermissions.canRedact)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch.

@@ -51,7 +51,7 @@ object TimelineDisplayableEvents {
EventType.STATE_ROOM_JOIN_RULES,
EventType.KEY_VERIFICATION_DONE,
EventType.KEY_VERIFICATION_CANCEL,
) + EventType.POLL_START + EventType.STATE_ROOM_BEACON_INFO
) + EventType.POLL_START + EventType.STATE_ROOM_BEACON_INFO + EventType.BEACON_LOCATION_DATA
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we added location data as displayable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it because we want the redacted events to appear in the timeline (there are still hidden in the general case). I aligned the behavior on what is done in web. I think this is good to see the redacted events to inform the user the location events were redacted.

Copy link
Contributor

@onurays onurays left a comment

Choose a reason for hiding this comment

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

Very nice implementation. Thanks for the tests!

@mnaturel mnaturel force-pushed the feature/mna/delete-lls branch from 61e6f30 to 91559c2 Compare July 19, 2022 07:31
@mnaturel mnaturel force-pushed the feature/mna/collapse-deleted-events branch from 6eb05f8 to 9c61900 Compare July 19, 2022 12:05
@mnaturel mnaturel force-pushed the feature/mna/delete-lls branch from 91559c2 to b2d7ef9 Compare July 19, 2022 12:07
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

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

66.5% 66.5% Coverage
0.0% 0.0% Duplication

Base automatically changed from feature/mna/collapse-deleted-events to develop July 19, 2022 14:39
@mnaturel mnaturel merged commit c3105c8 into develop Jul 19, 2022
@mnaturel mnaturel deleted the feature/mna/delete-lls branch July 19, 2022 14:43
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.

[Location sharing] - Delete action on a live message
3 participants