mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-06 22:13:31 +01:00
Widgets: display widget events in timeline
This commit is contained in:
parent
31c82b4ba6
commit
d4706b38b8
@ -31,6 +31,8 @@ data class WidgetContent(
|
||||
@Json(name = "waitForIframeLoad") val waitForIframeLoad: Boolean = false
|
||||
) {
|
||||
|
||||
fun isActive() = type != null && url != null
|
||||
|
||||
/**
|
||||
* @return the human name
|
||||
*/
|
||||
|
@ -29,7 +29,7 @@ data class Widget(
|
||||
val computedUrl: String?
|
||||
) {
|
||||
|
||||
val isActive = widgetContent.type != null && computedUrl != null
|
||||
val isActive = widgetContent.isActive()
|
||||
|
||||
val name = widgetContent.getHumanName()
|
||||
}
|
||||
|
@ -54,6 +54,8 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me
|
||||
EventType.STATE_ROOM_JOIN_RULES,
|
||||
EventType.STATE_ROOM_HISTORY_VISIBILITY,
|
||||
EventType.STATE_ROOM_GUEST_ACCESS,
|
||||
EventType.STATE_ROOM_WIDGET_LEGACY,
|
||||
EventType.STATE_ROOM_WIDGET,
|
||||
EventType.CALL_INVITE,
|
||||
EventType.CALL_HANGUP,
|
||||
EventType.CALL_ANSWER,
|
||||
|
@ -34,6 +34,7 @@ import im.vector.matrix.android.api.session.room.model.RoomTopicContent
|
||||
import im.vector.matrix.android.api.session.room.model.call.CallInviteContent
|
||||
import im.vector.matrix.android.api.session.room.model.create.RoomCreateContent
|
||||
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
||||
import im.vector.matrix.android.api.session.widgets.model.WidgetContent
|
||||
import im.vector.matrix.android.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM
|
||||
import im.vector.matrix.android.internal.crypto.model.event.EncryptionEventContent
|
||||
import im.vector.riotx.R
|
||||
@ -58,6 +59,8 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
|
||||
EventType.STATE_ROOM_GUEST_ACCESS -> formatRoomGuestAccessEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
|
||||
EventType.STATE_ROOM_ENCRYPTION -> formatRoomEncryptionEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
|
||||
EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(timelineEvent.senderInfo.disambiguatedDisplayName)
|
||||
EventType.STATE_ROOM_WIDGET,
|
||||
EventType.STATE_ROOM_WIDGET_LEGACY -> formatWidgetEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
|
||||
EventType.CALL_INVITE,
|
||||
EventType.CALL_HANGUP,
|
||||
EventType.CALL_ANSWER -> formatCallEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
|
||||
@ -78,6 +81,18 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatWidgetEvent(event: Event, disambiguatedDisplayName: String): CharSequence? {
|
||||
val widgetContent: WidgetContent = event.getClearContent().toModel() ?: return null
|
||||
val previousWidgetContent: WidgetContent? = event.prevContent.toModel()
|
||||
return if (widgetContent.isActive()) {
|
||||
val name = widgetContent.getHumanName()
|
||||
sp.getString(R.string.event_formatter_widget_added, name, disambiguatedDisplayName)
|
||||
} else {
|
||||
val name = previousWidgetContent?.getHumanName() ?: sp.getString(R.string.room_widget_activity_title)
|
||||
sp.getString(R.string.event_formatter_widget_removed, name, disambiguatedDisplayName)
|
||||
}
|
||||
}
|
||||
|
||||
fun format(event: Event, senderName: String?): CharSequence? {
|
||||
return when (val type = event.getClearType()) {
|
||||
EventType.STATE_ROOM_JOIN_RULES -> formatJoinRulesEvent(event, senderName)
|
||||
|
@ -24,6 +24,8 @@ object TimelineDisplayableEvents {
|
||||
|
||||
val DISPLAYABLE_TYPES = listOf(
|
||||
EventType.MESSAGE,
|
||||
EventType.STATE_ROOM_WIDGET_LEGACY,
|
||||
EventType.STATE_ROOM_WIDGET,
|
||||
EventType.STATE_ROOM_NAME,
|
||||
EventType.STATE_ROOM_TOPIC,
|
||||
EventType.STATE_ROOM_MEMBER,
|
||||
|
Loading…
x
Reference in New Issue
Block a user