Widgets: fix extracting user widgets
This commit is contained in:
parent
df973a6275
commit
cfa31e6332
|
@ -32,6 +32,7 @@ import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAcco
|
|||
import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataEvent
|
||||
import im.vector.matrix.android.internal.session.user.accountdata.AccountDataDataSource
|
||||
import im.vector.matrix.android.internal.session.user.accountdata.UpdateUserAccountDataTask
|
||||
import im.vector.matrix.android.internal.session.widgets.Widget
|
||||
import im.vector.matrix.android.internal.session.widgets.helper.extractWidgetSequence
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
import im.vector.matrix.android.internal.task.configureWith
|
||||
|
@ -297,9 +298,9 @@ internal class IntegrationManager @Inject constructor(private val taskExecutor:
|
|||
private fun UserAccountDataEvent.asIntegrationManagerWidgetContent(): WidgetContent? {
|
||||
return extractWidgetSequence()
|
||||
.filter {
|
||||
it.type == INTEGRATION_MANAGER_WIDGET
|
||||
it.widgetContent.type == INTEGRATION_MANAGER_WIDGET
|
||||
}
|
||||
.firstOrNull()
|
||||
.firstOrNull()?.widgetContent
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -146,13 +146,10 @@ internal class WidgetManager @Inject constructor(private val integrationManager:
|
|||
excludedTypes: Set<String>? = null): List<Widget> {
|
||||
return extractWidgetSequence()
|
||||
.filter {
|
||||
val widgetType = it.type ?: return@filter false
|
||||
val widgetType = it.widgetContent.type ?: return@filter false
|
||||
(widgetTypes == null || widgetTypes.contains(widgetType))
|
||||
&& (excludedTypes == null || !excludedTypes.contains(widgetType))
|
||||
}
|
||||
.map {
|
||||
Widget(it)
|
||||
}
|
||||
.toList()
|
||||
}
|
||||
|
||||
|
|
|
@ -16,15 +16,24 @@
|
|||
|
||||
package im.vector.matrix.android.internal.session.widgets.helper
|
||||
|
||||
import im.vector.matrix.android.api.session.events.model.Content
|
||||
import im.vector.matrix.android.api.session.events.model.Event
|
||||
import im.vector.matrix.android.api.session.events.model.toModel
|
||||
import im.vector.matrix.android.api.session.widgets.model.WidgetContent
|
||||
import im.vector.matrix.android.api.util.JsonDict
|
||||
import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataEvent
|
||||
import im.vector.matrix.android.internal.session.widgets.Widget
|
||||
|
||||
internal fun UserAccountDataEvent.extractWidgetSequence(): Sequence<WidgetContent> {
|
||||
internal fun UserAccountDataEvent.extractWidgetSequence(): Sequence<Widget> {
|
||||
return content.asSequence()
|
||||
.mapNotNull {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(it.value as? Content)?.toModel<WidgetContent>()
|
||||
(it.value as? JsonDict)?.toModel<Event>()
|
||||
}.mapNotNull { event ->
|
||||
val content = event.content?.toModel<WidgetContent>()
|
||||
if (content == null) {
|
||||
null
|
||||
} else {
|
||||
Widget(content, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,13 +202,12 @@ class WidgetPostAPIHandler @AssistedInject constructor(@Assisted private val roo
|
|||
return
|
||||
}
|
||||
Timber.d("Received request to get widget in room $roomId")
|
||||
val roomWidgets = session.widgetService().getRoomWidgets(roomId)
|
||||
val responseData = ArrayList<JsonDict>()
|
||||
for (widget in roomWidgets) {
|
||||
val allWidgets = session.widgetService().getRoomWidgets(roomId) + session.widgetService().getUserWidgets()
|
||||
for (widget in allWidgets) {
|
||||
val map = widget.event.toContent()
|
||||
responseData.add(map)
|
||||
}
|
||||
// TODO ADD USER WIDGETS
|
||||
Timber.d("## getWidgets() returns $responseData")
|
||||
widgetPostAPIMediator.sendObjectResponse(List::class.java, responseData, eventData)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue