Skip to content

Commit c3105c8

Browse files
authored
Merge pull request #6486 from vector-im/feature/mna/delete-lls
[Location sharing] - Delete action on a live message (PSG-523)
2 parents b08337e + b2d7ef9 commit c3105c8

File tree

41 files changed

+1059
-41
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1059
-41
lines changed

changelog.d/6437.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Location sharing] - Delete action on a live message

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ fun Event.isPoll(): Boolean = getClearType() in EventType.POLL_START || getClear
371371

372372
fun Event.isSticker(): Boolean = getClearType() == EventType.STICKER
373373

374+
fun Event.isLiveLocation(): Boolean = getClearType() in EventType.STATE_ROOM_BEACON_INFO
375+
374376
fun Event.getRelationContent(): RelationDefaultContent? {
375377
return if (isEncrypted()) {
376378
content.toModel<EncryptedEventContent>()?.relatesTo

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/location/LocationSharingService.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.matrix.android.sdk.api.session.room.location
1818

19-
import androidx.annotation.MainThread
2019
import androidx.lifecycle.LiveData
2120
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationShareAggregatedSummary
2221
import org.matrix.android.sdk.api.util.Cancelable
@@ -59,16 +58,21 @@ interface LocationSharingService {
5958
*/
6059
suspend fun stopLiveLocationShare(): UpdateLiveLocationShareResult
6160

61+
/**
62+
* Redact (delete) the live associated to the given beacon info event id.
63+
* @param beaconInfoEventId event id of the initial beacon info state event
64+
* @param reason Optional reason string
65+
*/
66+
suspend fun redactLiveLocationShare(beaconInfoEventId: String, reason: String?)
67+
6268
/**
6369
* Returns a LiveData on the list of current running live location shares.
6470
*/
65-
@MainThread
6671
fun getRunningLiveLocationShareSummaries(): LiveData<List<LiveLocationShareAggregatedSummary>>
6772

6873
/**
6974
* Returns a LiveData on the live location share summary with the given eventId.
7075
* @param beaconInfoEventId event id of the initial beacon info state event
7176
*/
72-
@MainThread
7377
fun getLiveLocationShareSummary(beaconInfoEventId: String): LiveData<Optional<LiveLocationShareAggregatedSummary>>
7478
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/timeline/TimelineEvent.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.matrix.android.sdk.api.session.events.model.EventType
2323
import org.matrix.android.sdk.api.session.events.model.RelationType
2424
import org.matrix.android.sdk.api.session.events.model.getRelationContent
2525
import org.matrix.android.sdk.api.session.events.model.isEdition
26+
import org.matrix.android.sdk.api.session.events.model.isLiveLocation
2627
import org.matrix.android.sdk.api.session.events.model.isPoll
2728
import org.matrix.android.sdk.api.session.events.model.isReply
2829
import org.matrix.android.sdk.api.session.events.model.isSticker
@@ -165,6 +166,10 @@ fun TimelineEvent.isSticker(): Boolean {
165166
return root.isSticker()
166167
}
167168

169+
fun TimelineEvent.isLiveLocation(): Boolean {
170+
return root.isLiveLocation()
171+
}
172+
168173
/**
169174
* Returns whether or not the event is a root thread event.
170175
*/

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo029
4949
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo030
5050
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo031
5151
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo032
52+
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo033
5253
import org.matrix.android.sdk.internal.util.Normalizer
5354
import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration
5455
import javax.inject.Inject
@@ -57,7 +58,7 @@ internal class RealmSessionStoreMigration @Inject constructor(
5758
private val normalizer: Normalizer
5859
) : MatrixRealmMigration(
5960
dbName = "Session",
60-
schemaVersion = 32L,
61+
schemaVersion = 33L,
6162
) {
6263
/**
6364
* Forces all RealmSessionStoreMigration instances to be equal.
@@ -99,5 +100,6 @@ internal class RealmSessionStoreMigration @Inject constructor(
99100
if (oldVersion < 30) MigrateSessionTo030(realm).perform()
100101
if (oldVersion < 31) MigrateSessionTo031(realm).perform()
101102
if (oldVersion < 32) MigrateSessionTo032(realm).perform()
103+
if (oldVersion < 33) MigrateSessionTo033(realm).perform()
102104
}
103105
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.matrix.android.sdk.internal.database.migration
18+
19+
import io.realm.DynamicRealm
20+
import org.matrix.android.sdk.internal.database.model.livelocation.LiveLocationShareAggregatedSummaryEntityFields
21+
import org.matrix.android.sdk.internal.util.database.RealmMigrator
22+
23+
/**
24+
* Migrating to:
25+
* Live location sharing aggregated summary: adding new field relatedEventIds.
26+
*/
27+
internal class MigrateSessionTo033(realm: DynamicRealm) : RealmMigrator(realm, 33) {
28+
29+
override fun doMigrate(realm: DynamicRealm) {
30+
realm.schema.get("LiveLocationShareAggregatedSummaryEntity")
31+
?.addRealmListField(LiveLocationShareAggregatedSummaryEntityFields.RELATED_EVENT_IDS.`$`, String::class.java)
32+
}
33+
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/livelocation/LiveLocationShareAggregatedSummaryEntity.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.matrix.android.sdk.internal.database.model.livelocation
1818

19+
import io.realm.RealmList
1920
import io.realm.RealmObject
2021
import io.realm.annotations.PrimaryKey
2122

@@ -29,6 +30,11 @@ internal open class LiveLocationShareAggregatedSummaryEntity(
2930
@PrimaryKey
3031
var eventId: String = "",
3132

33+
/**
34+
* List of event ids used to compute the aggregated summary data.
35+
*/
36+
var relatedEventIds: RealmList<String> = RealmList(),
37+
3238
var roomId: String = "",
3339

3440
var userId: String = "",

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/EventAnnotationsSummaryEntityQuery.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import org.matrix.android.sdk.internal.database.model.EventAnnotationsSummaryEnt
2323
import org.matrix.android.sdk.internal.database.model.EventAnnotationsSummaryEntityFields
2424
import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
2525

26+
internal fun EventAnnotationsSummaryEntity.Companion.where(realm: Realm, eventId: String): RealmQuery<EventAnnotationsSummaryEntity> {
27+
return realm.where<EventAnnotationsSummaryEntity>()
28+
.equalTo(EventAnnotationsSummaryEntityFields.EVENT_ID, eventId)
29+
}
30+
2631
internal fun EventAnnotationsSummaryEntity.Companion.where(realm: Realm, roomId: String, eventId: String): RealmQuery<EventAnnotationsSummaryEntity> {
2732
return realm.where<EventAnnotationsSummaryEntity>()
2833
.equalTo(EventAnnotationsSummaryEntityFields.ROOM_ID, roomId)
@@ -44,3 +49,7 @@ internal fun EventAnnotationsSummaryEntity.Companion.getOrCreate(realm: Realm, r
4449
return EventAnnotationsSummaryEntity.where(realm, roomId, eventId).findFirst()
4550
?: EventAnnotationsSummaryEntity.create(realm, roomId, eventId)
4651
}
52+
53+
internal fun EventAnnotationsSummaryEntity.Companion.get(realm: Realm, eventId: String): EventAnnotationsSummaryEntity? {
54+
return EventAnnotationsSummaryEntity.where(realm, eventId).findFirst()
55+
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/LiveLocationShareAggregatedSummaryEntityQuery.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ import org.matrix.android.sdk.internal.database.model.EventAnnotationsSummaryEnt
2323
import org.matrix.android.sdk.internal.database.model.livelocation.LiveLocationShareAggregatedSummaryEntity
2424
import org.matrix.android.sdk.internal.database.model.livelocation.LiveLocationShareAggregatedSummaryEntityFields
2525

26+
internal fun LiveLocationShareAggregatedSummaryEntity.Companion.where(
27+
realm: Realm,
28+
eventId: String,
29+
): RealmQuery<LiveLocationShareAggregatedSummaryEntity> {
30+
return realm.where<LiveLocationShareAggregatedSummaryEntity>()
31+
.equalTo(LiveLocationShareAggregatedSummaryEntityFields.EVENT_ID, eventId)
32+
}
33+
2634
internal fun LiveLocationShareAggregatedSummaryEntity.Companion.where(
2735
realm: Realm,
2836
roomId: String,
@@ -72,6 +80,13 @@ internal fun LiveLocationShareAggregatedSummaryEntity.Companion.get(
7280
return LiveLocationShareAggregatedSummaryEntity.where(realm, roomId, eventId).findFirst()
7381
}
7482

83+
internal fun LiveLocationShareAggregatedSummaryEntity.Companion.get(
84+
realm: Realm,
85+
eventId: String,
86+
): LiveLocationShareAggregatedSummaryEntity? {
87+
return LiveLocationShareAggregatedSummaryEntity.where(realm, eventId).findFirst()
88+
}
89+
7590
internal fun LiveLocationShareAggregatedSummaryEntity.Companion.findActiveLiveInRoomForUser(
7691
realm: Realm,
7792
roomId: String,

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionModule.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import org.matrix.android.sdk.internal.session.room.EventRelationsAggregationPro
8888
import org.matrix.android.sdk.internal.session.room.aggregation.poll.DefaultPollAggregationProcessor
8989
import org.matrix.android.sdk.internal.session.room.aggregation.poll.PollAggregationProcessor
9090
import org.matrix.android.sdk.internal.session.room.create.RoomCreateEventProcessor
91+
import org.matrix.android.sdk.internal.session.room.location.LiveLocationShareRedactionEventProcessor
9192
import org.matrix.android.sdk.internal.session.room.prune.RedactionEventProcessor
9293
import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor
9394
import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessorCoroutine
@@ -321,6 +322,10 @@ internal abstract class SessionModule {
321322
@IntoSet
322323
abstract fun bindEventRedactionProcessor(processor: RedactionEventProcessor): EventInsertLiveProcessor
323324

325+
@Binds
326+
@IntoSet
327+
abstract fun bindLiveLocationShareRedactionEventProcessor(processor: LiveLocationShareRedactionEventProcessor): EventInsertLiveProcessor
328+
324329
@Binds
325330
@IntoSet
326331
abstract fun bindEventRelationsAggregationProcessor(processor: EventRelationsAggregationProcessor): EventInsertLiveProcessor

0 commit comments

Comments
 (0)