-
Notifications
You must be signed in to change notification settings - Fork 760
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
Conversation
d7071ed
to
332fcc5
Compare
a7bd31b
to
97b6caf
Compare
8150790
to
67c7c0f
Compare
d5d584a
to
7ab6faf
Compare
roomId = params.roomId, | ||
reason = params.reason | ||
) | ||
relatedEventIds.forEach { eventId -> |
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.
if one of these fails should we continue the redactions?
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.
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() |
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.
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) |
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 function name always catches me off guard as it's a create and persist unlike the other functions on localEchoEventFactory
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 agree it can be confusing, I will try to find a better name for it.
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 renamed it, see efa356e
} | ||
|
||
@Test | ||
fun `given parameters when calling the task then it is correctly executed`() = runTest { |
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 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)
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.
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( |
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 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) + |
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.
using a single return when
here could help reduce the amount of exit points (and in turn the complexity of the function)
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.
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( |
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.
does this class need to be specific to LocationShare
? looks like it might be able to become aIsEventRedactedUseCase
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.
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) |
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.
we could also verify no interactions for reacting to help make the test more resilient
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.
It was done implicitely by not mocking the call to the redact
method in this case. But I added an explicit verification. See f784fa2
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.
so many tests and usecases 😍 !
59632bf
to
add7a5f
Compare
7ab6faf
to
e845f33
Compare
|
||
suspend fun execute(event: Event, room: Room, reason: String?) { | ||
event.eventId | ||
?.takeUnless { it.isEmpty() } |
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.
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) |
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.
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 |
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.
Why we added location data as displayable?
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 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.
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.
Very nice implementation. Thanks for the tests!
61e6f30
to
91559c2
Compare
6eb05f8
to
9c61900
Compare
91559c2
to
b2d7ef9
Compare
SonarCloud Quality Gate failed. |
Type of change
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
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
Checklist