-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce state index trying to replicate RoomState logic. WIP #2
- Loading branch information
Showing
12 changed files
with
115 additions
and
63 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
41 changes: 41 additions & 0 deletions
41
...c/main/java/im/vector/matrix/android/internal/session/room/members/RoomMemberExtractor.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,41 @@ | ||
package im.vector.matrix.android.internal.session.room.members | ||
|
||
import im.vector.matrix.android.api.session.events.model.EventType | ||
import im.vector.matrix.android.api.session.room.model.RoomMember | ||
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.EventEntityFields | ||
import im.vector.matrix.android.internal.database.query.findMostSuitableStateEvent | ||
import im.vector.matrix.android.internal.database.query.last | ||
import im.vector.matrix.android.internal.database.query.where | ||
import io.realm.Realm | ||
import io.realm.RealmQuery | ||
|
||
internal class RoomMemberExtractor(private val realm: Realm, | ||
private val roomId: String) { | ||
|
||
fun extractFrom(event: EventEntity): RoomMember? { | ||
val stateIndex = event.stateIndex | ||
|
||
// First of all, try to get the most suitable state event coming from a chunk | ||
return buildQuery(realm, roomId, event.sender) | ||
.findMostSuitableStateEvent(stateIndex = stateIndex) | ||
?.asDomain() | ||
?.pickContent(stateIndex) | ||
|
||
// If the content is null, we try get the last state event, not coming from a chunk | ||
?: buildQuery(realm, roomId, event.sender) | ||
.last() | ||
?.asDomain() | ||
?.content() | ||
|
||
} | ||
|
||
private fun buildQuery(realm: Realm, roomId: String, sender: String?): RealmQuery<EventEntity> { | ||
return EventEntity | ||
.where(realm, roomId, EventType.STATE_ROOM_MEMBER) | ||
.equalTo(EventEntityFields.STATE_KEY, sender) | ||
} | ||
|
||
|
||
} |
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