Create UserDataSource.getUserOrDefault().

This commit is contained in:
Benoit Marty 2022-10-14 12:13:21 +02:00
parent 5a2d74443d
commit 032fa37b64
2 changed files with 3 additions and 1 deletions

View File

@ -66,6 +66,8 @@ internal class UserDataSource @Inject constructor(
}
}
fun getUserOrDefault(userId: String): User = getUser(userId) ?: User(userId)
fun getUserLive(userId: String): LiveData<Optional<User>> {
val liveData = monarchy.findAllMappedWithChanges(
{ UserEntity.where(it, userId) },

View File

@ -74,7 +74,7 @@ internal class WidgetFactory @Inject constructor(
// Ref: https://github.com/matrix-org/matrix-widget-api/blob/master/src/templating/url-template.ts#L29-L33
fun computeURL(widget: Widget, isLightTheme: Boolean): String? {
var computedUrl = widget.widgetContent.url ?: return null
val myUser = userDataSource.getUser(userId) ?: User(userId)
val myUser = userDataSource.getUserOrDefault(userId)
val keyValue = widget.widgetContent.data.mapKeys { "\$${it.key}" }.toMutableMap()