mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-26 04:33:36 +00:00
Show story rings for self and if you sent a story to a group.
This commit is contained in:
committed by
Greyson Parrelli
parent
8c1ddcf1c0
commit
556dc0d1ec
@@ -36,6 +36,8 @@ import net.zetetic.database.sqlcipher.SQLiteStatement;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.signal.core.util.CursorUtil;
|
||||
import org.signal.core.util.SqlUtil;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.signal.libsignal.protocol.util.Pair;
|
||||
import org.thoughtcrime.securesms.attachments.Attachment;
|
||||
@@ -79,10 +81,8 @@ import org.thoughtcrime.securesms.revealable.ViewOnceUtil;
|
||||
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
|
||||
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
||||
import org.thoughtcrime.securesms.stories.Stories;
|
||||
import org.signal.core.util.CursorUtil;
|
||||
import org.thoughtcrime.securesms.util.JsonUtils;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.signal.core.util.SqlUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.google.protobuf.ByteString
|
||||
import com.google.protobuf.InvalidProtocolBufferException
|
||||
import net.zetetic.database.sqlcipher.SQLiteConstraintException
|
||||
import org.signal.core.util.Bitmask
|
||||
import org.signal.core.util.CursorUtil
|
||||
import org.signal.core.util.SqlUtil
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.core.util.optionalBlob
|
||||
@@ -599,6 +600,17 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
).recipientId
|
||||
}
|
||||
|
||||
fun getDistributionListRecipientIds(): List<RecipientId> {
|
||||
val recipientIds = mutableListOf<RecipientId>()
|
||||
readableDatabase.query(TABLE_NAME, arrayOf(ID), "$DISTRIBUTION_LIST_ID is not NULL", null, null, null, null).use { cursor ->
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
recipientIds.add(RecipientId.from(CursorUtil.requireLong(cursor, ID)))
|
||||
}
|
||||
}
|
||||
|
||||
return recipientIds
|
||||
}
|
||||
|
||||
fun getOrInsertFromGroupId(groupId: GroupId): RecipientId {
|
||||
var existing = getByGroupId(groupId)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import org.thoughtcrime.securesms.database.DatabaseObserver
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
|
||||
/**
|
||||
@@ -18,6 +19,30 @@ enum class StoryViewState {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getForRecipientId(recipientId: RecipientId): Observable<StoryViewState> {
|
||||
if (recipientId.equals(Recipient.self().id)) {
|
||||
return Observable.fromCallable {
|
||||
SignalDatabase.recipients.getDistributionListRecipientIds()
|
||||
}.flatMap { ids ->
|
||||
Observable.combineLatest(ids.map { getState(it) }) { combined ->
|
||||
if (combined.isEmpty()) {
|
||||
NONE
|
||||
} else {
|
||||
val results = combined.toList() as List<StoryViewState>
|
||||
when {
|
||||
results.any { it == UNVIEWED } -> UNVIEWED
|
||||
results.any { it == VIEWED } -> VIEWED
|
||||
else -> NONE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return getState(recipientId)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
private fun getState(recipientId: RecipientId): Observable<StoryViewState> {
|
||||
return Observable.create<StoryViewState> { emitter ->
|
||||
fun refresh() {
|
||||
emitter.onNext(SignalDatabase.mms.getStoryViewState(recipientId))
|
||||
|
||||
@@ -70,11 +70,11 @@ class StoriesLandingRepository(context: Context) {
|
||||
}
|
||||
|
||||
private fun createStoriesLandingItemData(sender: Recipient, messageRecords: List<MessageRecord>): Observable<StoriesLandingItemData> {
|
||||
return Observable.create { emitter ->
|
||||
val itemDataObservable = Observable.create<StoriesLandingItemData> { emitter ->
|
||||
fun refresh(sender: Recipient) {
|
||||
val itemData = StoriesLandingItemData(
|
||||
storyRecipient = sender,
|
||||
storyViewState = getStoryViewState(messageRecords),
|
||||
storyViewState = StoryViewState.NONE,
|
||||
hasReplies = messageRecords.any { SignalDatabase.mms.getNumberOfStoryReplies(it.id) > 0 },
|
||||
hasRepliesFromSelf = messageRecords.any { SignalDatabase.mms.hasSelfReplyInStory(it.id) },
|
||||
isHidden = sender.shouldHideStory(),
|
||||
@@ -106,6 +106,12 @@ class StoriesLandingRepository(context: Context) {
|
||||
|
||||
refresh(sender)
|
||||
}
|
||||
|
||||
val storyViewedStateObservable = StoryViewState.getForRecipientId(if (sender.isMyStory) Recipient.self().id else sender.id)
|
||||
|
||||
return Observable.combineLatest(itemDataObservable, storyViewedStateObservable) { data, state ->
|
||||
data.copy(storyViewState = state)
|
||||
}
|
||||
}
|
||||
|
||||
fun setHideStory(recipientId: RecipientId, hideStory: Boolean): Completable {
|
||||
@@ -113,17 +119,4 @@ class StoriesLandingRepository(context: Context) {
|
||||
SignalDatabase.recipients.setHideStory(recipientId, hideStory)
|
||||
}.subscribeOn(Schedulers.io())
|
||||
}
|
||||
|
||||
private fun getStoryViewState(messageRecords: List<MessageRecord>): StoryViewState {
|
||||
val incoming = messageRecords.filterNot { it.isOutgoing }
|
||||
if (incoming.isEmpty()) {
|
||||
return StoryViewState.NONE
|
||||
}
|
||||
|
||||
if (incoming.any { it.viewedReceiptCount == 0 }) {
|
||||
return StoryViewState.UNVIEWED
|
||||
}
|
||||
|
||||
return StoryViewState.VIEWED
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user