Commit ebe2e772 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Fix avatar not being displayed on some servers.

parent a051ca4c
......@@ -50,6 +50,7 @@ class LoginPresenter @Inject constructor(
) {
// TODO - we should validate the current server when opening the app, and have a nonnull get()
private var currentServer = serverInteractor.get()!!
private val token = tokenRepository.get(currentServer)
private lateinit var client: RocketChatClient
private lateinit var settings: PublicSettings
......@@ -140,7 +141,7 @@ class LoginPresenter @Inject constructor(
val logo = settings.wideTile()?.let {
currentServer.serverLogoUrl(it)
}
val thumb = currentServer.avatarUrl(username)
val thumb = currentServer.avatarUrl(username, token?.userId, token?.authToken)
val account = Account(currentServer, icon, logo, username, thumb)
saveAccountInteractor.save(account)
}
......
......@@ -54,6 +54,7 @@ class LoginOptionsPresenter @Inject constructor(
) {
// TODO - we should validate the current server when opening the app, and have a nonnull get()
private var currentServer = serverInteractor.get()!!
private val token = tokenRepository.get(currentServer)
private lateinit var client: RocketChatClient
private lateinit var settings: PublicSettings
private lateinit var credentialToken: String
......@@ -180,7 +181,7 @@ class LoginOptionsPresenter @Inject constructor(
val logo = settings.wideTile()?.let {
currentServer.serverLogoUrl(it)
}
val thumb = currentServer.avatarUrl(username)
val thumb = currentServer.avatarUrl(username, token?.userId, token?.authToken)
val account = Account(currentServer, icon, logo, username, thumb)
saveAccountInteractor.save(account)
}
......
......@@ -39,7 +39,8 @@ class RegisterUsernamePresenter @Inject constructor(
) {
private val currentServer = serverInteractor.get()!!
private val client: RocketChatClient = factory.get(currentServer)
private var settings: PublicSettings = settingsInteractor.get(serverInteractor.get()!!)
private var settings: PublicSettings = settingsInteractor.get(currentServer)
private val token = tokenRepository.get(currentServer)
fun registerUsername(username: String, userId: String, authToken: String) {
launchUI(strategy) {
......@@ -72,14 +73,14 @@ class RegisterUsernamePresenter @Inject constructor(
}
}
private suspend fun saveAccount(username: String) {
private fun saveAccount(username: String) {
val icon = settings.favicon()?.let {
currentServer.serverLogoUrl(it)
}
val logo = settings.wideTile()?.let {
currentServer.serverLogoUrl(it)
}
val thumb = currentServer.avatarUrl(username)
val thumb = currentServer.avatarUrl(username, token?.userId, token?.authToken)
val account = Account(currentServer, icon, logo, username, thumb)
saveAccountInteractor.save(account)
}
......
......@@ -10,6 +10,7 @@ import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.domain.PublicSettings
import chat.rocket.android.server.domain.SaveAccountInteractor
import chat.rocket.android.server.domain.SaveCurrentServerInteractor
import chat.rocket.android.server.domain.TokenRepository
import chat.rocket.android.server.domain.favicon
import chat.rocket.android.server.domain.model.Account
import chat.rocket.android.server.domain.wideTile
......@@ -38,10 +39,12 @@ class SignupPresenter @Inject constructor(
private val analyticsManager: AnalyticsManager,
private val factory: RocketChatClientFactory,
private val saveAccountInteractor: SaveAccountInteractor,
tokenRepository: TokenRepository,
settingsInteractor: GetSettingsInteractor
) {
private val currentServer = serverInteractor.get()!!
private var settings: PublicSettings = settingsInteractor.get(serverInteractor.get()!!)
private var settings: PublicSettings = settingsInteractor.get(currentServer)
private val token = tokenRepository.get(currentServer)
fun signup(name: String, username: String, password: String, email: String) {
val client = factory.get(currentServer)
......@@ -98,7 +101,7 @@ class SignupPresenter @Inject constructor(
val logo = settings.wideTile()?.let {
currentServer.serverLogoUrl(it)
}
val thumb = currentServer.avatarUrl(me.username!!)
val thumb = currentServer.avatarUrl(me.username!!, token?.userId, token?.authToken)
val account = Account(currentServer, icon, logo, me.username!!, thumb)
saveAccountInteractor.save(account)
}
......
......@@ -43,7 +43,8 @@ class TwoFAPresenter @Inject constructor(
val settingsInteractor: GetSettingsInteractor
) {
private val currentServer = serverInteractor.get()!!
private var settings: PublicSettings = settingsInteractor.get(serverInteractor.get()!!)
private var settings: PublicSettings = settingsInteractor.get(currentServer)
private val token = tokenRepository.get(currentServer)
fun authenticate(
usernameOrEmail: String,
......@@ -101,7 +102,7 @@ class TwoFAPresenter @Inject constructor(
val logo = settings.wideTile()?.let {
currentServer.serverLogoUrl(it)
}
val thumb = currentServer.avatarUrl(me.username!!)
val thumb = currentServer.avatarUrl(me.username!!, token?.userId, token?.authToken)
val account = Account(currentServer, icon, logo, me.username!!, thumb)
saveAccountInteractor.save(account)
}
......
......@@ -56,6 +56,7 @@ class ChatRoomFragmentModule {
context: Application,
repository: SettingsRepository,
userInteractor: GetCurrentUserInteractor,
tokenRepository: TokenRepository,
@Named("currentServer") serverUrl: String,
permissionsInteractor: PermissionsInteractor
): RoomUiModelMapper {
......@@ -63,6 +64,7 @@ class ChatRoomFragmentModule {
context,
repository.get(serverUrl),
userInteractor,
tokenRepository,
serverUrl,
permissionsInteractor
)
......
......@@ -29,6 +29,7 @@ import chat.rocket.android.server.domain.JobSchedulerInteractor
import chat.rocket.android.server.domain.MessagesRepository
import chat.rocket.android.server.domain.PermissionsInteractor
import chat.rocket.android.server.domain.PublicSettings
import chat.rocket.android.server.domain.TokenRepository
import chat.rocket.android.server.domain.UsersRepository
import chat.rocket.android.server.domain.uploadMaxFileSize
import chat.rocket.android.server.domain.uploadMimeTypeFilter
......@@ -101,6 +102,7 @@ class ChatRoomPresenter @Inject constructor(
private val jobSchedulerInteractor: JobSchedulerInteractor,
private val messageHelper: MessageHelper,
private val dbManager: DatabaseManager,
tokenRepository: TokenRepository,
getSettingsInteractor: GetSettingsInteractor,
serverInteractor: GetCurrentServerInteractor,
factory: ConnectionManagerFactory
......@@ -109,6 +111,7 @@ class ChatRoomPresenter @Inject constructor(
private val manager = factory.create(currentServer)
private val client = manager.client
private var settings: PublicSettings = getSettingsInteractor.get(serverInteractor.get()!!)
private val token = tokenRepository.get(currentServer)
private val currentLoggedUsername = userHelper.username()
private val messagesChannel = Channel<Message>()
......@@ -327,7 +330,7 @@ class ChatRoomPresenter @Inject constructor(
timestamp = Instant.now().toEpochMilli(),
sender = SimpleUser(user?.id, user?.username ?: username, user?.name),
attachments = null,
avatar = currentServer.avatarUrl(username ?: ""),
avatar = currentServer.avatarUrl(username!!, token?.userId, token?.authToken),
channels = null,
editedAt = null,
editedBy = null,
......@@ -812,7 +815,7 @@ class ChatRoomPresenter @Inject constructor(
val sender = it.sender
val username = sender?.username ?: ""
val name = sender?.name ?: ""
val avatarUrl = currentServer.avatarUrl(username)
val avatarUrl = currentServer.avatarUrl(username, token?.userId, token?.authToken)
val found = members.firstOrNull { member -> member.username == username }
val status = if (found != null) found.status else UserStatus.Offline()
val searchList = mutableListOf(username, name)
......@@ -833,7 +836,7 @@ class ChatRoomPresenter @Inject constructor(
activeUsers.addAll(others.map {
val username = it.username ?: ""
val name = it.name ?: ""
val avatarUrl = currentServer.avatarUrl(username)
val avatarUrl = currentServer.avatarUrl(username, token?.userId, token?.authToken)
val searchList = mutableListOf(username, name)
PeopleSuggestionUiModel(
avatarUrl,
......@@ -869,7 +872,7 @@ class ChatRoomPresenter @Inject constructor(
val searchList = mutableListOf(username, name)
it.emails?.forEach { email -> searchList.add(email.address) }
PeopleSuggestionUiModel(
currentServer.avatarUrl(username),
currentServer.avatarUrl(username, token?.userId, token?.authToken),
username, username, name, it.status, false, searchList
)
}.filterNot { filterSelfOut && self != null && self == it.text })
......
......@@ -108,7 +108,7 @@ class UiModelMapper @Inject constructor(
readReceipts.forEach {
list.add(
ReadReceiptViewModel(
avatar = baseUrl.avatarUrl(it.user.username ?: ""),
avatar = baseUrl.avatarUrl(it.user.username!!, token?.userId, token?.authToken),
name = userHelper.displayName(it.user),
time = DateTimeHelper.getTime(DateTimeHelper.getLocalDateTime(it.timestamp))
)
......@@ -526,7 +526,7 @@ class UiModelMapper @Inject constructor(
val username = message.sender?.username ?: "?"
return baseUrl.let {
baseUrl.avatarUrl(username)
baseUrl.avatarUrl(username, token?.userId, token?.authToken)
}
}
......
......@@ -8,11 +8,13 @@ import chat.rocket.android.db.model.ChatRoom
import chat.rocket.android.server.domain.GetCurrentUserInteractor
import chat.rocket.android.server.domain.PermissionsInteractor
import chat.rocket.android.server.domain.PublicSettings
import chat.rocket.android.server.domain.TokenRepository
import chat.rocket.android.server.domain.showLastMessage
import chat.rocket.android.server.domain.useRealName
import chat.rocket.android.server.domain.useSpecialCharsOnRoom
import chat.rocket.android.util.extensions.avatarUrl
import chat.rocket.android.util.extensions.date
import chat.rocket.android.util.extensions.isNotNullNorEmpty
import chat.rocket.android.util.extensions.localDateTime
import chat.rocket.common.model.RoomType
import chat.rocket.common.model.User
......@@ -26,10 +28,12 @@ class RoomUiModelMapper(
private val context: Application,
private val settings: PublicSettings,
private val userInteractor: GetCurrentUserInteractor,
private val tokenRepository: TokenRepository,
private val serverUrl: String,
private val permissions: PermissionsInteractor
) {
private val currentUser by lazy { userInteractor.get() }
private val token by lazy { tokenRepository.get(serverUrl) }
fun map(
rooms: List<ChatRoom>,
......@@ -80,7 +84,7 @@ class RoomUiModelMapper(
private fun mapUser(user: User): RoomUiModel = with(user) {
val name = mapName(user.username!!, user.name)
val status = user.status
val avatar = serverUrl.avatarUrl(user.username!!)
val avatar = serverUrl.avatarUrl(user.username!!, token?.userId, token?.authToken)
val username = user.username!!
RoomUiModel(
......@@ -98,7 +102,7 @@ class RoomUiModelMapper(
id = id,
name = name!!,
type = type,
avatar = serverUrl.avatarUrl(name!!, isGroupOrChannel = true),
avatar = serverUrl.avatarUrl(name!!, token?.userId, token?.authToken, isGroupOrChannel = true),
lastMessage = if (showLastMessage) {
mapLastMessage(
lastMessage?.sender?.id, lastMessage?.sender?.username,
......@@ -113,17 +117,19 @@ class RoomUiModelMapper(
)
}
fun map(chatRoom: ChatRoom, showLastMessage: Boolean = true): RoomUiModel = with(chatRoom.chatRoom) {
fun map(chatRoom: ChatRoom, showLastMessage: Boolean = true): RoomUiModel =
with(chatRoom.chatRoom) {
val isUnread = alert || unread > 0
val type = roomTypeOf(type)
val status = chatRoom.status?.let { userStatusOf(it) }
val roomName = mapName(name, fullname)
val favorite = favorite
val timestamp = mapDate(lastMessageTimestamp ?: updatedAt)
val avatar = if (type is RoomType.DirectMessage) {
serverUrl.avatarUrl(name)
val avatar =
if (type is RoomType.DirectMessage) {
serverUrl.avatarUrl(name, token?.userId, token?.authToken)
} else {
serverUrl.avatarUrl(name, isGroupOrChannel = true)
serverUrl.avatarUrl(name, token?.userId, token?.authToken, isGroupOrChannel = true)
}
val unread = mapUnread(unread)
val lastMessage = if (showLastMessage) {
......@@ -139,10 +145,12 @@ class RoomUiModelMapper(
}
val hasMentions = mapMentions(userMentions, groupMentions)
val open = open
val lastMessageMarkdown = lastMessage?.let { Markwon.markdown(context, it.toString()).toString() }
val lastMessageMarkdown =
lastMessage?.let { Markwon.markdown(context, it.toString()).toString() }
RoomUiModel(
id = id,
isDiscussion = parentId.isNotNullNorEmpty(),
name = roomName,
type = type,
avatar = avatar,
......
......@@ -11,6 +11,9 @@ import chat.rocket.android.chatrooms.adapter.model.RoomUiModel
import chat.rocket.android.util.extension.setTextViewAppearance
import chat.rocket.common.model.RoomType
import chat.rocket.common.model.UserStatus
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import kotlinx.android.synthetic.main.item_chat.view.*
import kotlinx.android.synthetic.main.unread_messages_badge.view.*
......@@ -19,6 +22,7 @@ class RoomViewHolder(itemView: View, private val listener: (RoomUiModel) -> Unit
private val resources: Resources = itemView.resources
private val channelIcon: Drawable = resources.getDrawable(R.drawable.ic_hashtag_12dp, null)
private val groupIcon: Drawable = resources.getDrawable(R.drawable.ic_lock_12_dp, null)
private val discussionIcon: Drawable = resources.getDrawable(R.drawable.ic_discussion_20dp, null)
private val onlineIcon: Drawable = resources.getDrawable(R.drawable.ic_status_online_12dp, null)
private val awayIcon: Drawable = resources.getDrawable(R.drawable.ic_status_away_12dp, null)
private val busyIcon: Drawable = resources.getDrawable(R.drawable.ic_status_busy_12dp, null)
......@@ -27,10 +31,18 @@ class RoomViewHolder(itemView: View, private val listener: (RoomUiModel) -> Unit
override fun bindViews(data: RoomItemHolder) {
val room = data.data
with(itemView) {
image_avatar.setImageURI(room.avatar)
val avatar = room.avatar
Glide.with(image_avatar.context)
.load(room.avatar)
.apply(RequestOptions.bitmapTransform(RoundedCorners(10)))
.into(image_avatar)
text_chat_name.text = room.name
if (room.status != null && room.type is RoomType.DirectMessage) {
if (room.isDiscussion) {
image_chat_icon.setImageDrawable(discussionIcon)
} else if (room.status != null && room.type is RoomType.DirectMessage) {
image_chat_icon.setImageDrawable(getStatusDrawable(room.status))
} else {
image_chat_icon.setImageDrawable(getRoomDrawable(room.type))
......
......@@ -5,6 +5,7 @@ import chat.rocket.common.model.UserStatus
data class RoomUiModel(
val id: String,
val isDiscussion: Boolean = false,
val type: RoomType,
val name: CharSequence,
val avatar: String,
......
......@@ -86,12 +86,20 @@ class ChatRoomsFragmentModule {
@PerFragment
fun provideRoomMapper(
context: Application,
repository: SettingsRepository,
settingsRepository: SettingsRepository,
userInteractor: GetCurrentUserInteractor,
tokenRepository: TokenRepository,
@Named("currentServer") serverUrl: String,
permissionsInteractor: PermissionsInteractor
): RoomUiModelMapper {
return RoomUiModelMapper(context, repository.get(serverUrl), userInteractor, serverUrl, permissionsInteractor)
return RoomUiModelMapper(
context,
settingsRepository.get(serverUrl),
userInteractor,
tokenRepository,
serverUrl,
permissionsInteractor
)
}
@Provides
......
package chat.rocket.android.directory.uimodel
import chat.rocket.android.util.extensions.avatarUrl
import chat.rocket.common.model.Token
import chat.rocket.core.model.DirectoryResult
class DirectoryUiModel(
private val directoryResult: DirectoryResult,
private val baseUrl: String?
private val baseUrl: String?,
private val token: Token?
) {
val id: String = directoryResult.id
val channelAvatarUri: String?
......@@ -22,12 +24,12 @@ class DirectoryUiModel(
}
private fun getChannelAvatar(): String? {
return baseUrl?.avatarUrl(name, isGroupOrChannel = true)
return baseUrl?.avatarUrl(name, token?.userId, token?.authToken, isGroupOrChannel = true)
}
private fun getUserAvatar(): String? {
return directoryResult.username?.let {
baseUrl?.avatarUrl(it)
baseUrl?.avatarUrl(it, token?.userId, token?.authToken)
}
}
}
package chat.rocket.android.directory.uimodel
import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.domain.TokenRepository
import chat.rocket.android.server.domain.baseUrl
import chat.rocket.core.model.DirectoryResult
import chat.rocket.core.model.Value
......@@ -9,13 +10,14 @@ import javax.inject.Named
class DirectoryUiModelMapper @Inject constructor(
getSettingsInteractor: GetSettingsInteractor,
@Named("currentServer") private val currentServer: String
@Named("currentServer") private val currentServer: String,
tokenRepository: TokenRepository
) {
private var settings: Map<String, Value<Any>> = getSettingsInteractor.get(currentServer)
private val baseUrl = settings.baseUrl()
private val token = tokenRepository.get(currentServer)
fun mapToUiModelList(directoryList: List<DirectoryResult>): List<DirectoryUiModel> {
return directoryList.map { DirectoryUiModel(it, baseUrl) }
return directoryList.map { DirectoryUiModel(it, baseUrl, token) }
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package chat.rocket.android.members.uimodel
import chat.rocket.android.server.domain.useRealName
import chat.rocket.android.util.extensions.avatarUrl
import chat.rocket.common.model.Token
import chat.rocket.common.model.User
import chat.rocket.common.model.UserStatus
import chat.rocket.core.model.Value
......@@ -9,7 +10,8 @@ import chat.rocket.core.model.Value
class MemberUiModel(
private val member: User,
private val settings: Map<String, Value<Any>>,
private val baseUrl: String?
private val baseUrl: String?,
private val token: Token?
) {
val userId: String = member.id
val avatarUri: String?
......@@ -33,7 +35,7 @@ class MemberUiModel(
private fun getUserAvatar(): String? {
val username = member.username ?: "?"
return baseUrl?.let {
baseUrl.avatarUrl(username, format = "png")
baseUrl.avatarUrl(username, token?.userId, token?.authToken, format = "png")
}
}
......
......@@ -2,19 +2,24 @@ package chat.rocket.android.members.uimodel
import chat.rocket.android.server.domain.GetCurrentServerInteractor
import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.domain.TokenRepository
import chat.rocket.android.server.domain.baseUrl
import chat.rocket.common.model.User
import chat.rocket.core.model.Value
import javax.inject.Inject
import javax.inject.Named
class MemberUiModelMapper @Inject constructor(
serverInteractor: GetCurrentServerInteractor,
getSettingsInteractor: GetSettingsInteractor
getSettingsInteractor: GetSettingsInteractor,
@Named("currentServer") private val currentServer: String,
tokenRepository: TokenRepository
) {
private var settings: Map<String, Value<Any>> = getSettingsInteractor.get(serverInteractor.get()!!)
private val baseUrl = settings.baseUrl()
private val token = tokenRepository.get(currentServer)
fun mapToUiModelList(memberList: List<User>): List<MemberUiModel> {
return memberList.map { MemberUiModel(it, settings, baseUrl) }
return memberList.map { MemberUiModel(it, settings, baseUrl, token) }
}
}
......@@ -57,6 +57,7 @@ class ProfilePresenter @Inject constructor(
private val serverUrl = serverInteractor.get()!!
private val client: RocketChatClient = factory.get(serverUrl)
private val user = userHelper.user()
private val token = tokenRepository.get(serverUrl)
fun loadUserProfile() {
launchUI(strategy) {
......@@ -68,7 +69,7 @@ class ProfilePresenter @Inject constructor(
view.showProfile(
me.status.toString(),
serverUrl.avatarUrl(me.username ?: ""),
serverUrl.avatarUrl(me.username!!, token?.userId, token?.authToken),
me.name ?: "",
me.username ?: "",
me.emails?.getOrNull(0)?.address ?: ""
......@@ -97,7 +98,7 @@ class ProfilePresenter @Inject constructor(
view.showProfileUpdateSuccessfullyMessage()
view.showProfile(
user.status.toString(),
serverUrl.avatarUrl(user.username ?: ""),
serverUrl.avatarUrl(user.username!!, token?.userId, token?.authToken),
name,
username,
email
......@@ -127,7 +128,15 @@ class ProfilePresenter @Inject constructor(
uriInteractor.getInputStream(uri)
}
}
user?.username?.let { view.reloadUserAvatar(serverUrl.avatarUrl(it)) }
user?.username?.let {
view.reloadUserAvatar(
serverUrl.avatarUrl(
it,
token?.userId,
token?.authToken
)
)
}
} catch (exception: RocketChatException) {
exception.message?.let {
view.showMessage(it)
......@@ -155,7 +164,15 @@ class ProfilePresenter @Inject constructor(
}
}
user?.username?.let { view.reloadUserAvatar(serverUrl.avatarUrl(it)) }
user?.username?.let {
view.reloadUserAvatar(
serverUrl.avatarUrl(
it,
token?.userId,
token?.authToken
)
)
}
} catch (exception: RocketChatException) {
exception.message?.let {
view.showMessage(it)
......@@ -175,7 +192,15 @@ class ProfilePresenter @Inject constructor(
user?.id?.let { id ->
retryIO { client.resetAvatar(id) }
}
user?.username?.let { view.reloadUserAvatar(serverUrl.avatarUrl(it)) }
user?.username?.let {
view.reloadUserAvatar(
serverUrl.avatarUrl(
it,
token?.userId,
token?.authToken
)
)
}
} catch (exception: RocketChatException) {
exception.message?.let {
view.showMessage(it)
......
......@@ -56,6 +56,7 @@ class SettingsPresenter @Inject constructor(
tokenView = view,
navigator = navigator
) {
private val token = tokenRepository.get(currentServer)
fun setupView() {
launchUI(strategy) {
......@@ -70,7 +71,7 @@ class SettingsPresenter @Inject constructor(
userHelper.user()?.let { user ->
view.setupSettingsView(
currentServer.avatarUrl(me.username ?: ""),
currentServer.avatarUrl(me.username!!, token?.userId, token?.authToken),
userHelper.displayName(user) ?: me.username ?: "",
me.status.toString(),
permissions.isAdministrationEnabled(),
......
......@@ -8,12 +8,14 @@ import chat.rocket.android.db.model.ChatRoomEntity
import chat.rocket.android.db.model.UserEntity
import chat.rocket.android.server.domain.CurrentServerRepository
import chat.rocket.android.server.domain.GetSettingsInteractor
import chat.rocket.android.server.domain.TokenRepository
import chat.rocket.android.server.domain.isJitsiEnabled
import chat.rocket.android.server.infrastructure.ConnectionManagerFactory
import chat.rocket.android.util.extension.launchUI
import chat.rocket.android.util.extensions.avatarUrl
import chat.rocket.android.util.retryIO
import chat.rocket.common.model.RoomType
import chat.rocket.common.model.Token
import chat.rocket.common.util.ifNull
import chat.rocket.core.internal.rest.createDirectMessage
import kotlinx.coroutines.Dispatchers
......@@ -26,6 +28,7 @@ class UserDetailsPresenter @Inject constructor(
private val dbManager: DatabaseManager,
private val strategy: CancelStrategy,
private val navigator: ChatRoomNavigator,
tokenRepository: TokenRepository,
settingsInteractor: GetSettingsInteractor,
serverInteractor: CurrentServerRepository,
factory: ConnectionManagerFactory
......@@ -35,6 +38,7 @@ class UserDetailsPresenter @Inject constructor(
private val client = manager.client
private val interactor = FetchChatRoomsInteractor(client, dbManager)
private val settings = settingsInteractor.get(currentServer)
private val token = tokenRepository.get(currentServer)
private lateinit var userEntity: UserEntity
fun loadUserDetails(userId: String) {
......@@ -44,7 +48,13 @@ class UserDetailsPresenter @Inject constructor(
dbManager.getUser(userId)?.let {
userEntity = it
val avatarUrl =
userEntity.username?.let { username -> currentServer.avatarUrl(avatar = username) }
userEntity.username?.let { username ->
currentServer.avatarUrl(
username,
token?.userId,
token?.authToken
)
}
val username = userEntity.username
val name = userEntity.name
val utcOffset =
......
......@@ -21,13 +21,15 @@ fun String.sanitize(): String {
fun String.avatarUrl(
avatar: String,
userId: String?,
token: String?,
isGroupOrChannel: Boolean = false,
format: String = "jpeg"
): String {
return if (isGroupOrChannel) {
"${removeTrailingSlash()}/avatar/%23${avatar.removeTrailingSlash()}?format=$format"
"${removeTrailingSlash()}/avatar/%23${avatar.removeTrailingSlash()}?format=$format&rc_uid=$userId&rc_token=$token"
} else {
"${removeTrailingSlash()}/avatar/${avatar.removeTrailingSlash()}?format=$format"
"${removeTrailingSlash()}/avatar/${avatar.removeTrailingSlash()}?format=$format&rc_uid=$userId&rc_token=$token"
}
}
......
......@@ -8,21 +8,22 @@
android:paddingStart="@dimen/screen_edge_left_and_right_padding"
android:paddingTop="@dimen/chat_item_top_and_bottom_padding"
android:paddingEnd="@dimen/screen_edge_left_and_right_padding"
android:paddingBottom="@dimen/chat_item_top_and_bottom_padding">
android:paddingBottom="@dimen/chat_item_top_and_bottom_padding"
tools:context=".chatrooms.adapter.RoomsAdapter">
<com.facebook.drawee.view.SimpleDraweeView
<ImageView
android:id="@+id/image_avatar"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="5dp"
android:layout_marginTop="2dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:roundedCornerRadius="4dp" />
tools:src="@tools:sample/avatars" />
<ImageView
android:id="@+id/image_chat_icon"
android:layout_width="12dp"
android:layout_height="0dp"
android:layout_height="12dp"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="@+id/text_chat_name"
app:layout_constraintStart_toEndOf="@+id/image_avatar"
......@@ -35,6 +36,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/text_view_drawable_padding"
android:layout_marginEnd="@dimen/text_view_drawable_padding"
android:textDirection="locale"
app:layout_constraintEnd_toStartOf="@+id/text_timestamp"
app:layout_constraintStart_toEndOf="@+id/image_chat_icon"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment