Timeline call tiles: show notice item for hidden events

This commit is contained in:
ganfra 2021-08-12 12:14:07 +02:00
parent 0d56707fd3
commit 27abf2f8d1
3 changed files with 38 additions and 13 deletions

View File

@ -40,6 +40,7 @@ class CallItemFactory @Inject constructor(
private val messageInformationDataFactory: MessageInformationDataFactory,
private val messageItemAttributesFactory: MessageItemAttributesFactory,
private val avatarSizeProvider: AvatarSizeProvider,
private val noticeItemFactory: NoticeItemFactory,
private val roomSummariesHolder: RoomSummariesHolder) {
fun create(params: TimelineItemFactoryParams): VectorEpoxyModel<*>? {
@ -50,9 +51,9 @@ class CallItemFactory @Inject constructor(
val roomId = event.roomId
val informationData = messageInformationDataFactory.create(params)
val callKind = if (callEventGrouper.isVideo()) CallTileTimelineItem.CallKind.VIDEO else CallTileTimelineItem.CallKind.AUDIO
return when (event.root.getClearType()) {
val callItem = when (event.root.getClearType()) {
EventType.CALL_ANSWER -> {
if (callEventGrouper.isInCall() || showHiddenEvents) {
if (callEventGrouper.isInCall()) {
createCallTileTimelineItem(
roomId = roomId,
callId = callEventGrouper.callId,
@ -69,7 +70,7 @@ class CallItemFactory @Inject constructor(
}
}
EventType.CALL_INVITE -> {
if (callEventGrouper.isRinging() || showHiddenEvents) {
if (callEventGrouper.isRinging()) {
createCallTileTimelineItem(
roomId = roomId,
callId = callEventGrouper.callId,
@ -113,6 +114,12 @@ class CallItemFactory @Inject constructor(
}
else -> null
}
return if (callItem == null && showHiddenEvents) {
// Fallback to notice item for showing hidden events
noticeItemFactory.create(params)
} else {
callItem
}
}
private fun createCallTileTimelineItem(

View File

@ -48,13 +48,13 @@ class WidgetItemFactory @Inject constructor(
val previousWidgetContent: WidgetContent? = event.root.resolvedPrevContent().toModel()
return when (WidgetType.fromString(widgetContent.type ?: previousWidgetContent?.type ?: "")) {
WidgetType.Jitsi -> createJitsiItem(params, widgetContent, previousWidgetContent)
WidgetType.Jitsi -> createJitsiItem(params, widgetContent)
// There is lot of other widget types we could improve here
else -> noticeItemFactory.create(params)
}
}
private fun createJitsiItem(params: TimelineItemFactoryParams, widgetContent: WidgetContent, prevWidgetContent: WidgetContent?): VectorEpoxyModel<*>? {
private fun createJitsiItem(params: TimelineItemFactoryParams, widgetContent: WidgetContent): VectorEpoxyModel<*>? {
val informationData = informationDataFactory.create(params)
val event = params.event
val roomId = event.roomId
@ -63,7 +63,13 @@ class WidgetItemFactory @Inject constructor(
val jitsiWidgetEventsGroup = params.eventsGroup?.let { JitsiWidgetEventsGroup(it) } ?: return null
val isCallStillActive = jitsiWidgetEventsGroup.isStillActive()
val showHiddenEvents = userPreferencesProvider.shouldShowHiddenEvents()
if (isActiveTile && !isCallStillActive && !showHiddenEvents) return null
if (isActiveTile && !isCallStillActive) {
return if (showHiddenEvents) {
noticeItemFactory.create(params)
} else {
null
}
}
val callStatus = if (isActiveTile && widgetContent.id == params.partialState.jitsiState.widgetId) {
if (params.partialState.jitsiState.hasJoined) {
CallTileTimelineItem.CallStatus.IN_CALL
@ -73,9 +79,8 @@ class WidgetItemFactory @Inject constructor(
} else {
CallTileTimelineItem.CallStatus.ENDED
}
val fakeCallId = widgetContent.id ?: prevWidgetContent?.id ?: return null
val attributes = CallTileTimelineItem.Attributes(
callId = fakeCallId,
callId = jitsiWidgetEventsGroup.callId,
callKind = CallTileTimelineItem.CallKind.CONFERENCE,
callStatus = callStatus,
informationData = informationData,

View File

@ -57,14 +57,25 @@ class TimelineEventsGroups {
val content = root.getClearContent()
return if (EventType.isCallEvent(type)) {
(content?.get("call_id") as? String)
} else {
} else if (type == EventType.STATE_ROOM_WIDGET || type == EventType.STATE_ROOM_WIDGET_LEGACY) {
val widgetContent: WidgetContent = root.getClearContent().toModel() ?: return null
val isJitsi = WidgetType.fromString(widgetContent.type ?: "") == WidgetType.Jitsi
if (isJitsi) {
widgetContent.id
if (widgetContent.isActive()) {
widgetContent.getJitsiIdOrNull()
} else {
null
val prevWidgetContent: WidgetContent = root.resolvedPrevContent().toModel() ?: return null
prevWidgetContent.getJitsiIdOrNull()
}
} else {
null
}
}
private fun WidgetContent.getJitsiIdOrNull(): String? {
val isJitsi = WidgetType.fromString(type ?: "") == WidgetType.Jitsi
return if (isJitsi) {
id
} else {
null
}
}
@ -75,6 +86,8 @@ class TimelineEventsGroups {
class JitsiWidgetEventsGroup(private val group: TimelineEventsGroup) {
val callId: String = group.groupId
fun isStillActive(): Boolean {
return group.events.none {
it.root.getClearContent().toModel<WidgetContent>()?.isActive() == false