Only display outgoing messages when entering viewer through my stories.

This commit is contained in:
Alex Hart
2022-07-25 15:33:34 -03:00
committed by Cody Henthorne
parent d40be0abf8
commit cb7b2d90d5
15 changed files with 52 additions and 38 deletions

View File

@@ -191,7 +191,7 @@ public abstract class MessageDatabase extends Database implements MmsSmsColumns
public abstract @NonNull Reader getOutgoingStoriesTo(@NonNull RecipientId recipientId);
public abstract @NonNull Reader getAllOutgoingStories(boolean reverse, int limit);
public abstract @NonNull Reader getAllOutgoingStoriesAt(long sentTimestamp);
public abstract @NonNull List<StoryResult> getOrderedStoryRecipientsAndIds();
public abstract @NonNull List<StoryResult> getOrderedStoryRecipientsAndIds(boolean isOutgoingOnly);
public abstract @NonNull Reader getAllStoriesFor(@NonNull RecipientId recipientId, int limit);
public abstract @NonNull MessageId getStoryId(@NonNull RecipientId authorId, long sentTimestamp) throws NoSuchMessageException;
public abstract int getNumberOfStoryReplies(long parentStoryId);

View File

@@ -613,7 +613,7 @@ public class MmsDatabase extends MessageDatabase {
whereArgs = SqlUtil.buildArgs(recipientId);
} else {
where += " AND " + THREAD_ID_WHERE;
whereArgs = SqlUtil.buildArgs(1, 0, threadId);
whereArgs = SqlUtil.buildArgs(threadId);
}
return new Reader(rawQuery(where, whereArgs));
@@ -798,7 +798,8 @@ public class MmsDatabase extends MessageDatabase {
}
@Override
public @NonNull List<StoryResult> getOrderedStoryRecipientsAndIds() {
public @NonNull List<StoryResult> getOrderedStoryRecipientsAndIds(boolean isOutgoingOnly) {
String where = "WHERE is_story > 0 AND remote_deleted = 0" + (isOutgoingOnly ? " AND is_outgoing != 0" : "") + "\n";
SQLiteDatabase db = getReadableDatabase();
String query = "SELECT\n"
+ " mms.date AS sent_timestamp,\n"
@@ -812,7 +813,7 @@ public class MmsDatabase extends MessageDatabase {
+ "FROM mms\n"
+ "JOIN thread\n"
+ "ON mms.thread_id = thread._id\n"
+ "WHERE is_story > 0 AND remote_deleted = 0\n"
+ where
+ "ORDER BY\n"
+ "is_unread DESC,\n"
+ "CASE\n"

View File

@@ -1413,7 +1413,7 @@ public class SmsDatabase extends MessageDatabase {
}
@Override
public @NonNull List<StoryResult> getOrderedStoryRecipientsAndIds() {
public @NonNull List<StoryResult> getOrderedStoryRecipientsAndIds(boolean isOutgoingOnly) {
throw new UnsupportedOperationException();
}

View File

@@ -22,7 +22,8 @@ data class StoryViewerArgs(
val groupReplyStartPosition: Int = -1,
val isUnviewedOnly: Boolean = false,
val isFromInfoContextMenuAction: Boolean = false,
val isFromQuote: Boolean = false
val isFromQuote: Boolean = false,
val isFromMyStories: Boolean = false
) : Parcelable {
class Builder(private val recipientId: RecipientId, private val isInHiddenStoryMode: Boolean) {

View File

@@ -34,7 +34,7 @@ class StoriesLandingRepository(context: Context) {
val myStoriesId = SignalDatabase.recipients.getOrInsertFromDistributionListId(DistributionListId.MY_STORY)
val myStories = Recipient.resolved(myStoriesId)
val stories = SignalDatabase.mms.orderedStoryRecipientsAndIds
val stories = SignalDatabase.mms.getOrderedStoryRecipientsAndIds(false)
val mapping: MutableMap<Recipient, List<StoryResult>> = mutableMapOf()
stories.forEach {

View File

@@ -151,7 +151,8 @@ class MyStoriesFragment : DSLSettingsFragment(
storyThumbTextModel = text,
storyThumbUri = image,
storyThumbBlur = blur,
isFromInfoContextMenuAction = isFromInfoContextMenuAction
isFromInfoContextMenuAction = isFromInfoContextMenuAction,
isFromMyStories = true
)
),
options.toBundle()

View File

@@ -51,6 +51,7 @@ class StoryViewerFragment :
storyViewerArgs.isFromNotification,
storyViewerArgs.groupReplyStartPosition,
storyViewerArgs.isUnviewedOnly,
storyViewerArgs.isFromMyStories,
storyViewerArgs.isFromInfoContextMenuAction
)

View File

@@ -13,6 +13,7 @@ class StoryViewerPagerAdapter(
private val isFromNotification: Boolean,
private val groupReplyStartPosition: Int,
private val isUnviewedOnly: Boolean,
private val isOutgoingOnly: Boolean,
private val isFromInfoContextMenuAction: Boolean
) : FragmentStateAdapter(fragment) {
@@ -34,7 +35,7 @@ class StoryViewerPagerAdapter(
override fun getItemCount(): Int = pages.size
override fun createFragment(position: Int): Fragment {
return StoryViewerPageFragment.create(pages[position], initialStoryId, isFromNotification, groupReplyStartPosition, isUnviewedOnly, isFromInfoContextMenuAction)
return StoryViewerPageFragment.create(pages[position], initialStoryId, isFromNotification, groupReplyStartPosition, isUnviewedOnly, isOutgoingOnly, isFromInfoContextMenuAction)
}
private class Callback(

View File

@@ -36,12 +36,12 @@ open class StoryViewerRepository {
}
}
fun getStories(hiddenStories: Boolean, unviewedOnly: Boolean): Single<List<RecipientId>> {
fun getStories(hiddenStories: Boolean, unviewedOnly: Boolean, isOutgoingOnly: Boolean): Single<List<RecipientId>> {
return Single.create<List<RecipientId>> { emitter ->
val myStoriesId = SignalDatabase.recipients.getOrInsertFromDistributionListId(DistributionListId.MY_STORY)
val myStories = Recipient.resolved(myStoriesId)
val releaseChannelId = SignalStore.releaseChannelValues().releaseChannelRecipientId
val recipientIds = SignalDatabase.mms.orderedStoryRecipientsAndIds.groupBy {
val recipientIds = SignalDatabase.mms.getOrderedStoryRecipientsAndIds(isOutgoingOnly).groupBy {
val recipient = Recipient.resolved(it.recipientId)
if (recipient.isDistributionList) {
myStories

View File

@@ -89,7 +89,8 @@ class StoryViewerViewModel(
} else {
repository.getStories(
hiddenStories = storyViewerArgs.isInHiddenStoryMode,
unviewedOnly = storyViewerArgs.isUnviewedOnly
unviewedOnly = storyViewerArgs.isUnviewedOnly,
isOutgoingOnly = storyViewerArgs.isFromMyStories
)
}
}

View File

@@ -115,6 +115,7 @@ class StoryViewerPageFragment :
storyRecipientId,
initialStoryId,
isUnviewedOnly,
isOutgoingOnly,
StoryViewerPageRepository(
requireContext()
),
@@ -150,6 +151,9 @@ class StoryViewerPageFragment :
private val isUnviewedOnly: Boolean
get() = requireArguments().getBoolean(ARG_IS_UNVIEWED_ONLY, false)
private val isOutgoingOnly: Boolean
get() = requireArguments().getBoolean(ARG_IS_OUTGOING_ONLY, false)
private val isFromInfoContextMenuAction: Boolean
get() = requireArguments().getBoolean(ARG_IS_FROM_INFO_CONTEXT_MENU_ACTION, false)
@@ -985,6 +989,7 @@ class StoryViewerPageFragment :
private const val ARG_IS_FROM_NOTIFICATION = "is_from_notification"
private const val ARG_GROUP_REPLY_START_POSITION = "group_reply_start_position"
private const val ARG_IS_UNVIEWED_ONLY = "is_unviewed_only"
private const val ARG_IS_OUTGOING_ONLY = "is_outgoing_only"
private const val ARG_IS_FROM_INFO_CONTEXT_MENU_ACTION = "is_from_info_context_menu_action"
fun create(
@@ -993,6 +998,7 @@ class StoryViewerPageFragment :
isFromNotification: Boolean,
groupReplyStartPosition: Int,
isUnviewedOnly: Boolean,
isOutgoingOnly: Boolean,
isFromInfoContextMenuAction: Boolean
): Fragment {
return StoryViewerPageFragment().apply {
@@ -1002,7 +1008,8 @@ class StoryViewerPageFragment :
ARG_IS_FROM_NOTIFICATION to isFromNotification,
ARG_GROUP_REPLY_START_POSITION to groupReplyStartPosition,
ARG_IS_UNVIEWED_ONLY to isUnviewedOnly,
ARG_IS_FROM_INFO_CONTEXT_MENU_ACTION to isFromInfoContextMenuAction
ARG_IS_OUTGOING_ONLY to isOutgoingOnly,
ARG_IS_FROM_INFO_CONTEXT_MENU_ACTION to isFromInfoContextMenuAction,
)
}
}

View File

@@ -39,7 +39,7 @@ open class StoryViewerPageRepository(context: Context) {
fun isReadReceiptsEnabled(): Boolean = TextSecurePreferences.isReadReceiptsEnabled(context)
private fun getStoryRecords(recipientId: RecipientId, isUnviewedOnly: Boolean): Observable<List<MessageRecord>> {
private fun getStoryRecords(recipientId: RecipientId, isUnviewedOnly: Boolean, isOutgoingOnly: Boolean): Observable<List<MessageRecord>> {
return Observable.create { emitter ->
val recipient = Recipient.resolved(recipientId)
@@ -48,16 +48,14 @@ open class StoryViewerPageRepository(context: Context) {
SignalDatabase.mms.getAllOutgoingStories(false, 100)
} else if (isUnviewedOnly) {
SignalDatabase.mms.getUnreadStories(recipientId, 100)
} else if (isOutgoingOnly) {
SignalDatabase.mms.getOutgoingStoriesTo(recipientId)
} else {
SignalDatabase.mms.getAllStoriesFor(recipientId, 100)
}
val results = mutableListOf<MessageRecord>()
while (stories.next != null) {
if (!(recipient.isMyStory && stories.current.recipient.isGroup)) {
results.add(stories.current)
}
val results = stories.filterNot {
recipient.isMyStory && it.recipient.isGroup
}
emitter.onNext(results)
@@ -150,8 +148,8 @@ open class StoryViewerPageRepository(context: Context) {
return Stories.enqueueAttachmentsFromStoryForDownload(post.conversationMessage.messageRecord as MmsMessageRecord, true)
}
fun getStoryPostsFor(recipientId: RecipientId, isUnviewedOnly: Boolean): Observable<List<StoryPost>> {
return getStoryRecords(recipientId, isUnviewedOnly)
fun getStoryPostsFor(recipientId: RecipientId, isUnviewedOnly: Boolean, isOutgoingOnly: Boolean): Observable<List<StoryPost>> {
return getStoryRecords(recipientId, isUnviewedOnly, isOutgoingOnly)
.switchMap { records ->
val posts = records.map { getStoryPostFromRecord(recipientId, it) }
if (posts.isEmpty()) {

View File

@@ -26,6 +26,7 @@ class StoryViewerPageViewModel(
private val recipientId: RecipientId,
private val initialStoryId: Long,
private val isUnviewedOnly: Boolean,
private val isOutgoingOnly: Boolean,
private val repository: StoryViewerPageRepository,
val storyCache: StoryCache
) : ViewModel() {
@@ -61,7 +62,7 @@ class StoryViewerPageViewModel(
fun refresh() {
disposables.clear()
disposables += repository.getStoryPostsFor(recipientId, isUnviewedOnly).subscribe { posts ->
disposables += repository.getStoryPostsFor(recipientId, isUnviewedOnly, isOutgoingOnly).subscribe { posts ->
store.update { state ->
val isDisplayingInitialState = state.posts.isEmpty() && posts.isNotEmpty()
val startIndex = if (state.posts.isEmpty() && initialStoryId > 0) {
@@ -286,11 +287,12 @@ class StoryViewerPageViewModel(
private val recipientId: RecipientId,
private val initialStoryId: Long,
private val isUnviewedOnly: Boolean,
private val isOutgoingOnly: Boolean,
private val repository: StoryViewerPageRepository,
private val storyCache: StoryCache
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return modelClass.cast(StoryViewerPageViewModel(recipientId, initialStoryId, isUnviewedOnly, repository, storyCache)) as T
return modelClass.cast(StoryViewerPageViewModel(recipientId, initialStoryId, isUnviewedOnly, isOutgoingOnly, repository, storyCache)) as T
}
}
}