diff --git a/vector/build.gradle b/vector/build.gradle index 263df78e..f411f064 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -85,7 +85,7 @@ android { resValue "bool", "debug_mode", "true" buildConfigField "boolean", "LOW_PRIVACY_LOG_ENABLE", "false" buildConfigField "boolean", "SHOW_HIDDEN_TIMELINE_EVENTS", "false" - + signingConfig signingConfigs.debug } diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/HomeDrawerFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/home/HomeDrawerFragment.kt index 97baa539..66195881 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/HomeDrawerFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/HomeDrawerFragment.kt @@ -59,7 +59,7 @@ class HomeDrawerFragment : VectorBaseFragment() { // Debug menu homeDrawerHeaderDebugView.setOnClickListener { - navigator.openDebug() + navigator.openDebug(requireActivity()) } } } \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsViewModel.kt index 2a925894..1c293140 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsViewModel.kt @@ -15,6 +15,7 @@ */ package im.vector.riotredesign.features.home.room.detail.timeline.action +import com.airbnb.mvrx.FragmentViewModelContext import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.MvRxViewModelFactory import com.airbnb.mvrx.ViewModelContext @@ -25,8 +26,10 @@ import im.vector.matrix.android.api.session.room.model.message.MessageContent import im.vector.matrix.android.api.session.room.model.message.MessageTextContent import im.vector.matrix.android.api.session.room.model.message.MessageType import im.vector.riotredesign.core.platform.VectorViewModel +import im.vector.riotredesign.features.home.room.detail.timeline.format.NoticeEventFormatter import org.commonmark.parser.Parser import org.koin.android.ext.android.get +import org.koin.core.parameter.parametersOf import ru.noties.markwon.Markwon import ru.noties.markwon.html.HtmlPlugin import timber.log.Timber @@ -53,28 +56,45 @@ class MessageActionsViewModel(initialState: MessageActionState) : VectorViewMode override fun initialState(viewModelContext: ViewModelContext): MessageActionState? { val currentSession = viewModelContext.activity.get() + val fragment = (viewModelContext as? FragmentViewModelContext)?.fragment + val noticeFormatter = fragment?.get(parameters = { parametersOf(fragment) }) val parcel = viewModelContext.args as TimelineEventFragmentArgs val dateFormat = SimpleDateFormat("EEE, d MMM yyyy HH:mm", Locale.getDefault()) val event = currentSession.getRoom(parcel.roomId)?.getTimeLineEvent(parcel.eventId) + var body: CharSequence? = null + val originTs = event?.root?.originServerTs return if (event != null) { - val messageContent: MessageContent? = event.annotations?.editSummary?.aggregatedContent?.toModel() - ?: event.root.content.toModel() - val originTs = event.root.originServerTs - var body: CharSequence? = messageContent?.body - if (messageContent is MessageTextContent && messageContent.format == MessageType.FORMAT_MATRIX_HTML) { - val parser = Parser.builder().build() - val document = parser.parse(messageContent.formattedBody ?: messageContent.body) - body = Markwon.builder(viewModelContext.activity) - .usePlugin(HtmlPlugin.create()).build().render(document) + when (event.root.type) { + EventType.MESSAGE -> { + val messageContent: MessageContent? = event.annotations?.editSummary?.aggregatedContent?.toModel() + ?: event.root.content.toModel() + body = messageContent?.body + if (messageContent is MessageTextContent && messageContent.format == MessageType.FORMAT_MATRIX_HTML) { + val parser = Parser.builder().build() + val document = parser.parse(messageContent.formattedBody + ?: messageContent.body) + body = Markwon.builder(viewModelContext.activity) + .usePlugin(HtmlPlugin.create()).build().render(document) + } + } + EventType.STATE_ROOM_NAME, + EventType.STATE_ROOM_TOPIC, + EventType.STATE_ROOM_MEMBER, + EventType.STATE_HISTORY_VISIBILITY, + EventType.CALL_INVITE, + EventType.CALL_HANGUP, + EventType.CALL_ANSWER -> { + body = noticeFormatter?.format(event) + } } MessageActionState( userId = event.root.sender ?: "", - senderName = parcel.informationData.memberName.toString(), + senderName = parcel.informationData.memberName?.toString() ?: "", messageBody = body, ts = dateFormat.format(Date(originTs ?: 0)), - showPreview = event.root.type == EventType.MESSAGE, + showPreview = body != null, canReact = event.root.type == EventType.MESSAGE, senderAvatarPath = currentSession.contentUrlResolver().resolveFullSize(parcel.informationData.avatarUrl) ) diff --git a/vector/src/main/java/im/vector/riotredesign/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/riotredesign/features/navigation/DefaultNavigator.kt index 00207950..44c1cfe3 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/navigation/DefaultNavigator.kt @@ -52,7 +52,7 @@ class DefaultNavigator : Navigator { context.startActivity(intent) } - override fun openDebug() { - activity.startActivity(Intent(activity, DebugMenuActivity::class.java)) + override fun openDebug(context: Context) { + context.startActivity(Intent(context, DebugMenuActivity::class.java)) } } \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotredesign/features/navigation/Navigator.kt b/vector/src/main/java/im/vector/riotredesign/features/navigation/Navigator.kt index 02295964..8873227b 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/navigation/Navigator.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/navigation/Navigator.kt @@ -29,6 +29,6 @@ interface Navigator { fun openSettings(context: Context) - fun openDebug() + fun openDebug(context: Context) } \ No newline at end of file