forked from element-hq/element-android
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using com.famedly.marked_unnread, as per MSC2867 (matrix-org/matrix-spec-proposals#2867) TODO: - Currently, when upgrading from an older version, already existing unread flags are ignored until cache is cleared manually Change-Id: I3b66fadb134c96f0eb428afd673035d790c16340
- Loading branch information
1 parent
3defe44
commit 3fb2df7
Showing
33 changed files
with
325 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...id/src/main/java/org/matrix/android/sdk/internal/session/room/read/MarkedUnreadContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2020 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.internal.session.room.read | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class MarkedUnreadContent( | ||
@Json(name = "unread") val markedUnread: Boolean | ||
) |
72 changes: 72 additions & 0 deletions
72
...id/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetMarkedUnreadTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2020 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.internal.session.room.read | ||
|
||
import com.zhuinden.monarchy.Monarchy | ||
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity | ||
import org.matrix.android.sdk.internal.database.query.where | ||
import org.matrix.android.sdk.internal.di.SessionDatabase | ||
import org.matrix.android.sdk.internal.di.UserId | ||
import org.matrix.android.sdk.internal.network.executeRequest | ||
import org.matrix.android.sdk.internal.task.Task | ||
import org.matrix.android.sdk.internal.util.awaitTransaction | ||
import org.greenrobot.eventbus.EventBus | ||
import org.matrix.android.sdk.api.session.events.model.EventType | ||
import org.matrix.android.sdk.internal.database.query.isMarkedUnread | ||
import org.matrix.android.sdk.internal.session.sync.RoomMarkedUnreadHandler | ||
import org.matrix.android.sdk.internal.session.user.accountdata.AccountDataAPI | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
internal interface SetMarkedUnreadTask : Task<SetMarkedUnreadTask.Params, Unit> { | ||
|
||
data class Params( | ||
val roomId: String, | ||
val markedUnread: Boolean, | ||
val markedUnreadContent: MarkedUnreadContent = MarkedUnreadContent(markedUnread) | ||
) | ||
} | ||
|
||
internal class DefaultSetMarkedUnreadTask @Inject constructor( | ||
private val accountDataApi: AccountDataAPI, | ||
@SessionDatabase private val monarchy: Monarchy, | ||
private val roomMarkedUnreadHandler: RoomMarkedUnreadHandler, | ||
@UserId private val userId: String, | ||
private val eventBus: EventBus | ||
) : SetMarkedUnreadTask { | ||
|
||
override suspend fun execute(params: SetMarkedUnreadTask.Params) { | ||
Timber.v("Execute set marked unread with params: $params") | ||
|
||
if (isMarkedUnread(monarchy.realmConfiguration, params.roomId) != params.markedUnread) { | ||
updateDatabase(params.roomId, params.markedUnread) | ||
executeRequest<Unit>(eventBus) { | ||
isRetryable = true | ||
apiCall = accountDataApi.setRoomAccountData(userId, params.roomId, EventType.MARKED_UNREAD, params.markedUnreadContent) | ||
} | ||
} | ||
} | ||
|
||
private suspend fun updateDatabase(roomId: String, markedUnread: Boolean) { | ||
monarchy.awaitTransaction { realm -> | ||
roomMarkedUnreadHandler.handle(realm, roomId, MarkedUnreadContent(markedUnread)) | ||
val roomSummary = RoomSummaryEntity.where(realm, roomId).findFirst() | ||
?: return@awaitTransaction | ||
roomSummary.markedUnread = markedUnread | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...oid/src/main/java/org/matrix/android/sdk/internal/session/sync/RoomMarkedUnreadHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2020 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.internal.session.sync | ||
|
||
import org.matrix.android.sdk.internal.session.room.read.MarkedUnreadContent | ||
import io.realm.Realm | ||
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity | ||
import org.matrix.android.sdk.internal.database.query.getOrCreate | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
internal class RoomMarkedUnreadHandler @Inject constructor() { | ||
|
||
fun handle(realm: Realm, roomId: String, content: MarkedUnreadContent?) { | ||
if (content == null) { | ||
return | ||
} | ||
Timber.v("Handle for roomId: $roomId markedUnread: ${content.markedUnread}") | ||
|
||
RoomSummaryEntity.getOrCreate(realm, roomId).apply { | ||
markedUnread = content.markedUnread | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.