mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Let TimelineEvent be queried by SendState
This commit is contained in:
parent
7f09e64d63
commit
0949d29f9c
4 changed files with 67 additions and 61 deletions
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.matrix.android.api.session.room.send
|
package im.vector.matrix.android.api.session.room.send
|
||||||
|
|
||||||
|
|
||||||
enum class SendState {
|
enum class SendState {
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
// the event has not been sent
|
// the event has not been sent
|
||||||
|
@ -33,16 +34,19 @@ enum class SendState {
|
||||||
// the event failed to be sent because some unknown devices have been found while encrypting it
|
// the event failed to be sent because some unknown devices have been found while encrypting it
|
||||||
FAILED_UNKNOWN_DEVICES;
|
FAILED_UNKNOWN_DEVICES;
|
||||||
|
|
||||||
fun isSent(): Boolean {
|
internal companion object {
|
||||||
return this == SENT || this == SYNCED
|
val HAS_FAILED_STATES = listOf(UNDELIVERED, FAILED_UNKNOWN_DEVICES)
|
||||||
|
val IS_SENT_STATES = listOf(SENT, SYNCED)
|
||||||
|
val IS_SENDING_STATES = listOf(UNSENT, ENCRYPTING, SENDING)
|
||||||
|
val PENDING_STATES = IS_SENDING_STATES + HAS_FAILED_STATES
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasFailed(): Boolean {
|
fun isSent() = IS_SENT_STATES.contains(this)
|
||||||
return this == UNDELIVERED || this == FAILED_UNKNOWN_DEVICES
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isSending(): Boolean {
|
fun hasFailed() = HAS_FAILED_STATES.contains(this)
|
||||||
return this == UNSENT || this == ENCRYPTING || this == SENDING
|
|
||||||
}
|
fun isSending() = IS_SENDING_STATES.contains(this)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,10 @@
|
||||||
|
|
||||||
package im.vector.matrix.android.internal.database.query
|
package im.vector.matrix.android.internal.database.query
|
||||||
|
|
||||||
|
import im.vector.matrix.android.api.session.room.send.SendState
|
||||||
import im.vector.matrix.android.internal.database.model.*
|
import im.vector.matrix.android.internal.database.model.*
|
||||||
import im.vector.matrix.android.internal.database.model.EventEntity.LinkFilterMode.*
|
import im.vector.matrix.android.internal.database.model.EventEntity.LinkFilterMode.*
|
||||||
import io.realm.Realm
|
import io.realm.*
|
||||||
import io.realm.RealmList
|
|
||||||
import io.realm.RealmQuery
|
|
||||||
import io.realm.Sort
|
|
||||||
import io.realm.kotlin.where
|
import io.realm.kotlin.where
|
||||||
|
|
||||||
internal fun TimelineEventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery<TimelineEventEntity> {
|
internal fun TimelineEventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery<TimelineEventEntity> {
|
||||||
|
@ -114,3 +112,15 @@ internal fun RealmList<TimelineEventEntity>.find(eventId: String): TimelineEvent
|
||||||
.equalTo(TimelineEventEntityFields.ROOT.EVENT_ID, eventId)
|
.equalTo(TimelineEventEntityFields.ROOT.EVENT_ID, eventId)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun TimelineEventEntity.Companion.findAllInRoomWithSendStates(realm: Realm,
|
||||||
|
roomId: String,
|
||||||
|
sendStates: List<SendState>)
|
||||||
|
: RealmResults<TimelineEventEntity> {
|
||||||
|
|
||||||
|
val sendStatesStr = sendStates.map { it.name }.toTypedArray()
|
||||||
|
return realm.where<TimelineEventEntity>()
|
||||||
|
.equalTo(TimelineEventEntityFields.ROOM_ID, roomId)
|
||||||
|
.`in`(TimelineEventEntityFields.ROOT.SEND_STATE_STR,sendStatesStr)
|
||||||
|
.findAll()
|
||||||
|
}
|
|
@ -34,6 +34,7 @@ import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||||
import im.vector.matrix.android.internal.database.model.RoomEntity
|
import im.vector.matrix.android.internal.database.model.RoomEntity
|
||||||
import im.vector.matrix.android.internal.database.model.TimelineEventEntity
|
import im.vector.matrix.android.internal.database.model.TimelineEventEntity
|
||||||
|
import im.vector.matrix.android.internal.database.query.findAllInRoomWithSendStates
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
import im.vector.matrix.android.internal.session.content.UploadContentWorker
|
import im.vector.matrix.android.internal.session.content.UploadContentWorker
|
||||||
import im.vector.matrix.android.internal.session.room.timeline.TimelineSendEventWorkCommon
|
import im.vector.matrix.android.internal.session.room.timeline.TimelineSendEventWorkCommon
|
||||||
|
@ -188,48 +189,47 @@ internal class DefaultSendService @Inject constructor(private val context: Conte
|
||||||
|
|
||||||
override fun resendAllFailedMessages() {
|
override fun resendAllFailedMessages() {
|
||||||
monarchy.writeAsync { realm ->
|
monarchy.writeAsync { realm ->
|
||||||
RoomEntity.where(realm, roomId).findFirst()?.let { room ->
|
TimelineEventEntity
|
||||||
room.sendingTimelineEvents.filter {
|
.findAllInRoomWithSendStates(realm, roomId, SendState.HAS_FAILED_STATES)
|
||||||
it.root?.sendState?.hasFailed() ?: false
|
.sortedBy { it.root?.originServerTs ?: 0 }
|
||||||
}.sortedBy { it.root?.originServerTs ?: 0 }.forEach { timelineEventEntity ->
|
.forEach { timelineEventEntity ->
|
||||||
timelineEventEntity.root?.let {
|
timelineEventEntity.root?.let {
|
||||||
val event = it.asDomain()
|
val event = it.asDomain()
|
||||||
when (event.getClearType()) {
|
when (event.getClearType()) {
|
||||||
EventType.MESSAGE,
|
EventType.MESSAGE,
|
||||||
EventType.REDACTION,
|
EventType.REDACTION,
|
||||||
EventType.REACTION -> {
|
EventType.REACTION -> {
|
||||||
val content = event.getClearContent().toModel<MessageContent>()
|
val content = event.getClearContent().toModel<MessageContent>()
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
when (content.type) {
|
when (content.type) {
|
||||||
MessageType.MSGTYPE_EMOTE,
|
MessageType.MSGTYPE_EMOTE,
|
||||||
MessageType.MSGTYPE_NOTICE,
|
MessageType.MSGTYPE_NOTICE,
|
||||||
MessageType.MSGTYPE_LOCATION,
|
MessageType.MSGTYPE_LOCATION,
|
||||||
MessageType.MSGTYPE_TEXT -> {
|
MessageType.MSGTYPE_TEXT -> {
|
||||||
it.sendState = SendState.UNSENT
|
it.sendState = SendState.UNSENT
|
||||||
sendEvent(event)
|
sendEvent(event)
|
||||||
}
|
}
|
||||||
MessageType.MSGTYPE_FILE,
|
MessageType.MSGTYPE_FILE,
|
||||||
MessageType.MSGTYPE_VIDEO,
|
MessageType.MSGTYPE_VIDEO,
|
||||||
MessageType.MSGTYPE_IMAGE,
|
MessageType.MSGTYPE_IMAGE,
|
||||||
MessageType.MSGTYPE_AUDIO -> {
|
MessageType.MSGTYPE_AUDIO -> {
|
||||||
//need to resend the attachement
|
//need to resend the attachement
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
Timber.e("Cannot resend message ${event.type} / ${content.type}")
|
Timber.e("Cannot resend message ${event.type} / ${content.type}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Timber.e("Unsupported message to resend ${event.type}")
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else -> {
|
||||||
Timber.e("Unsupported message to resend ${event.type}")
|
Timber.e("Unsupported message to resend ${event.type}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
|
||||||
Timber.e("Unsupported message to resend ${event.type}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,16 +19,14 @@ package im.vector.matrix.android.internal.session.room.timeline
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
import im.vector.matrix.android.api.session.crypto.CryptoService
|
import im.vector.matrix.android.api.session.crypto.CryptoService
|
||||||
import im.vector.matrix.android.api.session.events.model.EventType
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
|
import im.vector.matrix.android.api.session.room.send.SendState
|
||||||
import im.vector.matrix.android.api.session.room.timeline.Timeline
|
import im.vector.matrix.android.api.session.room.timeline.Timeline
|
||||||
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
||||||
import im.vector.matrix.android.api.util.CancelableBag
|
import im.vector.matrix.android.api.util.CancelableBag
|
||||||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||||
import im.vector.matrix.android.internal.database.model.*
|
import im.vector.matrix.android.internal.database.model.*
|
||||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||||
import im.vector.matrix.android.internal.database.query.findIncludingEvent
|
import im.vector.matrix.android.internal.database.query.*
|
||||||
import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoom
|
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
|
||||||
import im.vector.matrix.android.internal.database.query.whereInRoom
|
|
||||||
import im.vector.matrix.android.internal.task.TaskConstraints
|
import im.vector.matrix.android.internal.task.TaskConstraints
|
||||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
import im.vector.matrix.android.internal.task.configureWith
|
import im.vector.matrix.android.internal.task.configureWith
|
||||||
|
@ -208,21 +206,15 @@ internal class DefaultTimeline(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pendingEventCount(): Int {
|
override fun pendingEventCount(): Int {
|
||||||
var count = 0
|
return Realm.getInstance(realmConfiguration).use {
|
||||||
Realm.getInstance(realmConfiguration).use {
|
RoomEntity.where(it, roomId).findFirst()?.sendingTimelineEvents?.count() ?: 0
|
||||||
count = RoomEntity.where(it, roomId).findFirst()?.sendingTimelineEvents?.count() ?: 0
|
|
||||||
}
|
}
|
||||||
return count
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun failedToDeliverEventCount(): Int {
|
override fun failedToDeliverEventCount(): Int {
|
||||||
var count = 0
|
return Realm.getInstance(realmConfiguration).use {
|
||||||
Realm.getInstance(realmConfiguration).use {
|
TimelineEventEntity.findAllInRoomWithSendStates(it, roomId, SendState.HAS_FAILED_STATES).count()
|
||||||
count = RoomEntity.where(it, roomId).findFirst()?.sendingTimelineEvents?.filter {
|
|
||||||
it.root?.sendState?.hasFailed() ?: false
|
|
||||||
}?.count() ?: 0
|
|
||||||
}
|
}
|
||||||
return count
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun start() {
|
override fun start() {
|
||||||
|
|
Loading…
Reference in a new issue