Skip to content

Conversation

@mnaturel
Copy link
Contributor

@mnaturel mnaturel commented May 23, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Introducing DeactivateLiveLocationShareWorker to set the isActive field to false after a live location share is timed out.

Motivation and context

Closes #6123
It enables also auto-refresh of the message tile when on timeline view when a live has just timed out.
It will ease the request on database to find all currently active lives in a room.

Screenshots / GIFs

Tests

  • Ensure the location sharing in enabled in Settings -> Preferences
  • Ensure the live location feature is enabled in Settings -> Labs
  • Go to a room
  • Start sharing your live location for 15 minutes
  • Take a coffee and wait for 15 minutes
  • Check the timeline the message tile is refreshed from running state to stopped state

Tested devices

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

Checklist

@mnaturel mnaturel changed the title [Location sharing] - Update DB entity when a live is timed out [Location sharing] - Update DB entity when a live is timed out (PSF-999) May 23, 2022
@mnaturel mnaturel requested review from a team, bmarty and ericdecanini and removed request for a team May 23, 2022 14:30
@mnaturel mnaturel marked this pull request as ready for review May 23, 2022 14:31
@github-actions
Copy link

github-actions bot commented May 23, 2022

Unit Test Results

124 files  ±0  124 suites  ±0   2m 11s ⏱️ -8s
220 tests ±0  220 ✔️ ±0  0 💤 ±0  0 ±0 
726 runs  ±0  726 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit 791d4fb. ± Comparison against base commit 9a38d59.

This pull request removes 1 and adds 1 tests. Note that renamed tests count towards both.
im.vector.app.features.onboarding.ftueauth.FtueMissingRegistrationStagesComparatorTest ‑ when ordering stages, then prioritizes email
im.vector.app.features.onboarding.ftueauth.MatrixOrgRegistrationStagesComparatorTest ‑ when ordering stages, then prioritizes email

♻️ This comment has been updated with latest results.

@mnaturel mnaturel force-pushed the feature/mna/PSF-999-auto-refresh-db branch from a8a9c7f to b05fc76 Compare May 23, 2022 15:40
@mnaturel mnaturel requested a review from onurays May 24, 2022 08:36
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.

Nice improvement. This is required to mark other users' timeout, in case of they cannot update state event because of network problems etc., right?

@mnaturel
Copy link
Contributor Author

Nice improvement. This is required to mark other users' timeout, in case of they cannot update state event because of network problems etc., right?

In fact, this was done mainly for 2 reasons:

  • auto-refresh of the message tile when on timeline view when a live has just timed out.
  • ease the request on database to find all currently active lives in a room (we just need to rely on 1 field).

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.

Nice improvement, thanks!
Only some minor comments.


private suspend fun deactivateLiveLocationShare(params: Params) {
awaitTransaction(realmConfiguration) { realm ->
val aggregatedSummary = LiveLocationShareAggregatedSummaryEntity.getOrCreate(
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 need a getOrCreate here? I mean if the instance is not found, does it worth creating it? I guess it will be always found, except after a clear cache maybe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I changed it in b081429

}

private fun scheduleDeactivationAfterTimeout(eventId: String, roomId: String, endOfLiveTimestampMillis: Long?) {
endOfLiveTimestampMillis?.let { endOfLiveMillis ->
Copy link
Member

Choose a reason for hiding this comment

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

Nit: personnally I prefer to have this first line:

endOfLiveTimestampMillis?: return

It has the advantage to avoid to "rename" endOfLiveTimestampMillis to endOfLiveMillis and also reduce the indentation level.

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 I agree it is more readable. I changed it in cfdc18d

endOfLiveTimestampMillis?.let { endOfLiveMillis ->
val workParams = DeactivateLiveLocationShareWorker.Params(sessionId = sessionId, eventId = eventId, roomId = roomId)
val workData = WorkerParamsFactory.toData(workParams)
val workName = DeactivateLiveLocationShareWorker.getWorkName(eventId = eventId, roomId = roomId)
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 using named parameters!


workManagerProvider.workManager.enqueueUniqueWork(
workName,
ExistingWorkPolicy.KEEP,
Copy link
Member

Choose a reason for hiding this comment

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

I think you should use ExistingWorkPolicy.REPLACE here.

Copy link
Contributor Author

@mnaturel mnaturel May 25, 2022

Choose a reason for hiding this comment

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

I have done the change in 8864a3c. But I am not sure if it will make a big difference.

companion object {
private const val WORK_NAME_PREFIX = "DeactivateLiveLocationWork-"

fun getWorkName(eventId: String, roomId: String) = "${WORK_NAME_PREFIX}$eventId-$roomId"
Copy link
Member

Choose a reason for hiding this comment

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

I do not know if the length of the string passed for uniqueWorkName can be limited, but maybe better to be safe here:
Maybe call .md5(), so replace by:

        fun getWorkName(eventId: String, roomId: String): String {
            val hash = "$eventId$roomId".md5()
            return "DeactivateLiveLocationWork-$hash"
        }

(you can keep the const WORK_NAME_PREFIX if you prefer)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. I updated the code, see 791d4fb

@sonarqubecloud
Copy link

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

No Coverage information No Coverage information
0.0% 0.0% Duplication

@mnaturel mnaturel requested review from bmarty and removed request for ericdecanini May 25, 2022 09:33
eventId: String,
): LiveLocationShareAggregatedSummaryEntity? {
return LiveLocationShareAggregatedSummaryEntity.where(realm, roomId, eventId).findFirst()
}
Copy link
Member

Choose a reason for hiding this comment

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

Not for this PR, but now the line 55 could be replaced by a call to this new method.

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 for the update!
can be merged from my POV.

@mnaturel mnaturel merged commit c8fb034 into develop May 25, 2022
@mnaturel mnaturel deleted the feature/mna/PSF-999-auto-refresh-db branch May 25, 2022 12:59
@github-actions
Copy link

Matrix SDK

Integration Tests Results:

  • [org.matrix.android.sdk.session]
    = passed=20 failures=0 errors=0 skipped=3
  • [org.matrix.android.sdk.account]
    = passed=3 failures=0 errors=0 skipped=2
  • [org.matrix.android.sdk.internal]
    = passed=6 failures=1 errors=0 skipped=0
  • [org.matrix.android.sdk.ordering]
    = passed=16 failures=0 errors=0 skipped=0
  • [org.matrix.android.sdk.PermalinkParserTest]
    = passed=2 failures=0 errors=0 skipped=0

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] - Update DB entity when a live is timed out

4 participants