change (media preview config) : use the new apis
This commit is contained in:
parent
682897cdb6
commit
0b748aa8cb
10 changed files with 158 additions and 60 deletions
|
|
@ -22,10 +22,8 @@ interface AppPreferencesStore {
|
|||
suspend fun setTheme(theme: String)
|
||||
fun getThemeFlow(): Flow<String?>
|
||||
|
||||
suspend fun setHideInviteAvatars(value: Boolean)
|
||||
fun getHideInviteAvatarsFlow(): Flow<Boolean>
|
||||
|
||||
suspend fun setTimelineMediaPreviewValue(value: MediaPreviewValue)
|
||||
fun getTimelineMediaPreviewValueFlow(): Flow<MediaPreviewValue>
|
||||
|
||||
suspend fun setTracingLogLevel(logLevel: LogLevel)
|
||||
|
|
|
|||
|
|
@ -85,24 +85,12 @@ class DefaultAppPreferencesStore @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun setHideInviteAvatars(value: Boolean) {
|
||||
store.edit { prefs ->
|
||||
prefs[hideInviteAvatarsKey] = value
|
||||
}
|
||||
}
|
||||
|
||||
override fun getHideInviteAvatarsFlow(): Flow<Boolean> {
|
||||
return store.data.map { prefs ->
|
||||
prefs[hideInviteAvatarsKey] == true
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun setTimelineMediaPreviewValue(value: MediaPreviewValue) {
|
||||
store.edit { prefs ->
|
||||
prefs[timelineMediaPreviewValueKey] = value.name
|
||||
}
|
||||
}
|
||||
|
||||
override fun getTimelineMediaPreviewValueFlow(): Flow<MediaPreviewValue> {
|
||||
return store.data.map { prefs ->
|
||||
prefs[timelineMediaPreviewValueKey]?.let { MediaPreviewValue.valueOf(it) } ?: MediaPreviewValue.On
|
||||
|
|
|
|||
|
|
@ -55,18 +55,10 @@ class InMemoryAppPreferencesStore(
|
|||
return theme
|
||||
}
|
||||
|
||||
override suspend fun setHideInviteAvatars(value: Boolean) {
|
||||
hideInviteAvatars.value = value
|
||||
}
|
||||
|
||||
override fun getHideInviteAvatarsFlow(): Flow<Boolean> {
|
||||
return hideInviteAvatars
|
||||
}
|
||||
|
||||
override suspend fun setTimelineMediaPreviewValue(value: MediaPreviewValue) {
|
||||
timelineMediaPreviewValue.value = value
|
||||
}
|
||||
|
||||
override fun getTimelineMediaPreviewValueFlow(): Flow<MediaPreviewValue> {
|
||||
return timelineMediaPreviewValue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ import io.element.android.libraries.matrix.api.timeline.item.event.TextMessageTy
|
|||
import io.element.android.libraries.matrix.api.timeline.item.event.VideoMessageType
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.VoiceMessageType
|
||||
import io.element.android.libraries.matrix.ui.messages.toPlainText
|
||||
import io.element.android.libraries.preferences.api.store.AppPreferencesStore
|
||||
import io.element.android.libraries.push.impl.R
|
||||
import io.element.android.libraries.push.impl.notifications.model.FallbackNotifiableEvent
|
||||
import io.element.android.libraries.push.impl.notifications.model.InviteNotifiableEvent
|
||||
|
|
@ -50,7 +49,6 @@ import io.element.android.libraries.push.impl.notifications.model.ResolvedPushEv
|
|||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
import io.element.android.services.toolbox.api.strings.StringProvider
|
||||
import io.element.android.services.toolbox.api.systemclock.SystemClock
|
||||
import kotlinx.coroutines.flow.first
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -79,7 +77,6 @@ class DefaultNotifiableEventResolver @Inject constructor(
|
|||
@ApplicationContext private val context: Context,
|
||||
private val permalinkParser: PermalinkParser,
|
||||
private val callNotificationEventResolver: CallNotificationEventResolver,
|
||||
private val appPreferencesStore: AppPreferencesStore,
|
||||
) : NotifiableEventResolver {
|
||||
override suspend fun resolveEvents(
|
||||
sessionId: SessionId,
|
||||
|
|
@ -117,6 +114,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
|
|||
): Result<ResolvedPushEvent> = runCatchingExceptions {
|
||||
when (val content = this.content) {
|
||||
is NotificationContent.MessageLike.RoomMessage -> {
|
||||
val showMediaPreview = client.mediaPreviewService().getMediaPreviewValue() == MediaPreviewValue.On
|
||||
val senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId)
|
||||
val messageBody = descriptionFromMessageContent(content, senderDisambiguatedDisplayName)
|
||||
val notifiableMessageEvent = buildNotifiableMessageEvent(
|
||||
|
|
@ -129,8 +127,8 @@ class DefaultNotifiableEventResolver @Inject constructor(
|
|||
timestamp = this.timestamp,
|
||||
senderDisambiguatedDisplayName = senderDisambiguatedDisplayName,
|
||||
body = messageBody,
|
||||
imageUriString = content.fetchImageIfPresent(client)?.toString(),
|
||||
imageMimeType = content.getImageMimetype(),
|
||||
imageUriString = if (showMediaPreview) content.fetchImageIfPresent(client)?.toString() else null,
|
||||
imageMimeType = if (showMediaPreview) content.getImageMimetype() else null,
|
||||
roomName = roomDisplayName,
|
||||
roomIsDm = isDm,
|
||||
roomAvatarPath = roomAvatarUrl,
|
||||
|
|
@ -323,9 +321,6 @@ class DefaultNotifiableEventResolver @Inject constructor(
|
|||
}
|
||||
|
||||
private suspend fun NotificationContent.MessageLike.RoomMessage.fetchImageIfPresent(client: MatrixClient): Uri? {
|
||||
if (appPreferencesStore.getTimelineMediaPreviewValueFlow().first() != MediaPreviewValue.On) {
|
||||
return null
|
||||
}
|
||||
val fileResult = when (val messageType = messageType) {
|
||||
is ImageMessageType -> notificationMediaRepoFactory.create(client)
|
||||
.getMediaFile(
|
||||
|
|
@ -349,10 +344,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
|
|||
.getOrNull()
|
||||
}
|
||||
|
||||
private suspend fun NotificationContent.MessageLike.RoomMessage.getImageMimetype(): String? {
|
||||
if (appPreferencesStore.getTimelineMediaPreviewValueFlow().first() != MediaPreviewValue.On) {
|
||||
return null
|
||||
}
|
||||
private fun NotificationContent.MessageLike.RoomMessage.getImageMimetype(): String? {
|
||||
return when (val messageType = messageType) {
|
||||
is ImageMessageType -> messageType.info?.mimetype
|
||||
is VideoMessageType -> null // Use the thumbnail here?
|
||||
|
|
|
|||
|
|
@ -826,7 +826,6 @@ class DefaultNotifiableEventResolverTest {
|
|||
private fun createDefaultNotifiableEventResolver(
|
||||
notificationService: FakeNotificationService? = FakeNotificationService(),
|
||||
notificationResult: Result<Map<EventId, NotificationData>> = Result.success(emptyMap()),
|
||||
appPreferencesStore: AppPreferencesStore = InMemoryAppPreferencesStore(),
|
||||
callNotificationEventResolver: FakeCallNotificationEventResolver = FakeCallNotificationEventResolver(),
|
||||
): DefaultNotifiableEventResolver {
|
||||
val context = RuntimeEnvironment.getApplication() as Context
|
||||
|
|
@ -849,7 +848,6 @@ class DefaultNotifiableEventResolverTest {
|
|||
context = context,
|
||||
permalinkParser = FakePermalinkParser(),
|
||||
callNotificationEventResolver = callNotificationEventResolver,
|
||||
appPreferencesStore = appPreferencesStore,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue