mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 02:10:44 +01:00
Ensure my story is always at the top of the list.
This commit is contained in:
committed by
Cody Henthorne
parent
8703707d62
commit
b05f4430f6
@@ -27,14 +27,13 @@ class MyStoriesRepository(context: Context) {
|
||||
fun refresh() {
|
||||
val storiesMap = mutableMapOf<Recipient, List<MessageRecord>>()
|
||||
SignalDatabase.mms.getAllOutgoingStories(true, -1).use {
|
||||
while (it.next != null) {
|
||||
val messageRecord = it.current
|
||||
for (messageRecord in it) {
|
||||
val currentList = storiesMap[messageRecord.recipient] ?: emptyList()
|
||||
storiesMap[messageRecord.recipient] = (currentList + messageRecord)
|
||||
}
|
||||
}
|
||||
|
||||
emitter.onNext(storiesMap.map { (r, m) -> createDistributionSet(r, m) })
|
||||
emitter.onNext(storiesMap.toSortedMap(MyStoryBiasComparator()).map { (r, m) -> createDistributionSet(r, m) })
|
||||
}
|
||||
|
||||
val observer = DatabaseObserver.Observer {
|
||||
@@ -58,4 +57,18 @@ class MyStoriesRepository(context: Context) {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Biases "My Story" to the top of the list.
|
||||
*/
|
||||
class MyStoryBiasComparator : Comparator<Recipient> {
|
||||
override fun compare(o1: Recipient, o2: Recipient): Int {
|
||||
return when {
|
||||
o1 == o2 -> 0
|
||||
o1.isMyStory -> -1
|
||||
o2.isMyStory -> 1
|
||||
else -> -1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user