Skip to content
Snippets Groups Projects
Commit 07b91771 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

conversation: load profile asynchronously

Change-Id: I0b8cb6f48491c93a55a582186516eae9ef897456
parent b15615dd
No related branches found
No related tags found
No related merge requests found
......@@ -132,10 +132,41 @@ class ContactDetailsActivity : AppCompatActivity(), TabLayout.OnTabSelectedListe
.withCircleCrop(true)
.build(this))
binding.title.text = vm.title
if (conversation.getDescription().isNullOrBlank())
if (vm.conversationProfile.description.isNullOrBlank())
binding.description.text = getString(R.string.swarm_description)
else
binding.description.text = conversation.getDescription()
binding.description.text = vm.conversationProfile.description
if (vm.mode == Conversation.Mode.OneToOne) {
binding.title.setOnClickListener(null)
binding.description.setOnClickListener(null)
} else {
binding.title.setOnClickListener {
val title = getString(R.string.dialogtitle_title)
val hint = getString(R.string.dialog_hint_title)
RenameSwarmDialog().apply {
arguments = Bundle().apply {
putString(RenameSwarmDialog.KEY, RenameSwarmDialog.KEY_TITLE)
}
setTitle(title)
setHint(hint)
setText(vm.conversationProfile.displayName)
setListener(this@ContactDetailsActivity)
}.show(supportFragmentManager, TAG)
}
binding.description.setOnClickListener {
val title = getString(R.string.dialogtitle_description)
val hint = getString(R.string.dialog_hint_description)
RenameSwarmDialog().apply {
arguments = Bundle().apply {
putString(RenameSwarmDialog.KEY, RenameSwarmDialog.KEY_DESCRIPTION)
}
setTitle(title)
setHint(hint)
setText(vm.conversationProfile.description)
setListener(this@ContactDetailsActivity)
}.show(supportFragmentManager, TAG)
}
}
}) { e ->
Log.e(TAG, "e", e)
finish()
......@@ -150,28 +181,6 @@ class ContactDetailsActivity : AppCompatActivity(), TabLayout.OnTabSelectedListe
binding.addMember.isVisible = true
binding.description.isVisible = true
binding.addMember.setOnClickListener { ContactPickerFragment().show(supportFragmentManager, ContactPickerFragment.TAG) }
binding.title.setOnClickListener {
val title = getString(R.string.dialogtitle_title)
val hint = getString(R.string.dialog_hint_title)
RenameSwarmDialog().apply {
arguments = Bundle().apply { putString(RenameSwarmDialog.KEY, RenameSwarmDialog.KEY_TITLE) }
setTitle(title)
setHint(hint)
setText(conversation.getTitle())
setListener(this@ContactDetailsActivity)
}.show(supportFragmentManager, TAG)
}
binding.description.setOnClickListener {
val title = getString(R.string.dialogtitle_description)
val hint = getString(R.string.dialog_hint_description)
RenameSwarmDialog().apply {
arguments = Bundle().apply { putString(RenameSwarmDialog.KEY, RenameSwarmDialog.KEY_DESCRIPTION) }
setTitle(title)
setHint(hint)
setText(conversation.getDescription())
setListener(this@ContactDetailsActivity)
}.show(supportFragmentManager, TAG)
}
} else {
binding.tabLayout.removeTabAt(TAB_MEMBER)
}
......
......@@ -74,6 +74,11 @@ class VCardServiceImpl(private val mContext: Context) : VCardService() {
VCardUtils.accountProfileReceived(mContext.filesDir, accountId, vcardFile)
.map { vcard -> readData(vcard) }
override fun loadConversationProfile(info: Map<String, String>): Single<Profile> =
Single.fromCallable { Profile(info["title"], BitmapUtils.base64ToBitmap(info["avatar"]), info["description"]) }
.cache()
.subscribeOn(Schedulers.computation())
override fun base64ToBitmap(base64: String?): Any? = BitmapUtils.base64ToBitmap(base64)
companion object {
......
......@@ -58,8 +58,6 @@ class Conversation : ConversationHistory {
var lastNotified: String? = null
private set
private val mMode: Subject<Mode>
private var description: String? = null
private var title: String? = null
private val profileSubject: Subject<Single<Profile>> = BehaviorSubject.createDefault(Profile.EMPTY_PROFILE_SINGLE)
val profile: Observable<Profile> = profileSubject.switchMapSingle { single -> single }
......@@ -640,20 +638,11 @@ class Conversation : ConversationHistory {
fun getSymbol(): Observable<CharSequence> = symbol
fun updateInfo(info: Map<String, String>) {
title = info["title"]
//avatar = info["avatar"]
setProfile(Profile(info["title"], info["avatar"]))
description = info["description"]
}
fun updatePreferences(preferences: Map<String, String>) {
preferences["color"]?.let { color.onNext(it.substring(1).toInt(16)) }
preferences["symbol"]?.let { symbol.onNext(it) }
}
fun getTitle() = title
fun getDescription() = description
fun isGroup(): Boolean = isSwarm && contacts.size > 2
@Synchronized
fun loadMessage(id: String, load: () -> Unit): Single<Interaction> {
......
......@@ -21,7 +21,7 @@ package net.jami.model
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.core.Single
open class Profile(val displayName: String?, val avatar: Any?) {
open class Profile(val displayName: String?, val avatar: Any?, val description: String? = null) {
companion object {
val EMPTY_PROFILE = Profile(null, null)
val EMPTY_PROFILE_SINGLE: Single<Profile> = Single.just(EMPTY_PROFILE)
......
......@@ -272,7 +272,7 @@ class AccountService(
}*/
val mode = if ("true" == info["syncing"]) Conversation.Mode.Syncing else Conversation.Mode.values()[info["mode"]!!.toInt()]
val conversation = account.newSwarm(conversationId, mode)
conversation.updateInfo(info)
conversation.setProfile(mVCardService.loadConversationProfile(info))
conversation.setLastMessageNotified(mHistoryService.getLastMessageNotified(accountId, conversation.uri))
for (member in JamiService.getConversationMembers(accountId, conversationId)) {
/*for (Map.Entry<String, String> i : member.entrySet()) {
......@@ -503,13 +503,7 @@ class AccountService(
JamiService.sendMessage(accountId, conversationUri.rawRingId, txt, replyTo ?: "", 0)
}
}
/**
* @return Account Ids list from Daemon
*/
/*public Single<List<String>> getAccountList() {
return Single.fromCallable(() -> (List<String>)new ArrayList<>(JamiService.getAccountList()))
.subscribeOn(Schedulers.from(mExecutor));
}*/
/**
* Sets the order of the accounts in the Daemon
*
......@@ -1274,7 +1268,7 @@ class AccountService(
}
fun conversationProfileUpdated(accountId: String, conversationId: String, info: StringMap) {
getAccount(accountId)?.getSwarm(conversationId)?.updateInfo(info)
getAccount(accountId)?.getSwarm(conversationId)?.setProfile(mVCardService.loadConversationProfile(info))
}
fun conversationPreferencesUpdated(accountId: String, conversationId: String, preferences: StringMap) {
......@@ -1331,7 +1325,7 @@ class AccountService(
}
val conversation = c
synchronized(conversation) {
conversation.updateInfo(info)
conversation.setProfile(mVCardService.loadConversationProfile(info))
// Making sure to add contacts before changing the mode
for (member in JamiService.getConversationMembers(accountId, conversationId)) {
val memberUri = Uri.fromId(member["uri"]!!)
......
......@@ -39,6 +39,7 @@ abstract class VCardService {
abstract fun loadVCardProfile(vcard: VCard): Single<Profile>
abstract fun peerProfileReceived(accountId: String, peerId: String, vcard: File): Single<Profile>
abstract fun loadConversationProfile(info: Map<String, String>): Single<Profile>
abstract fun accountProfileReceived(accountId: String, vcardFile: File): Single<Profile>
abstract fun base64ToBitmap(base64: String?): Any?
......
......@@ -216,23 +216,22 @@ object VCardUtils {
return vcard
}
fun accountProfileReceived(filesDir: File, accountId: String, vcard: File): Single<VCard> {
return Single.fromCallable {
fun accountProfileReceived(filesDir: File, accountId: String, vcard: File): Single<VCard> =
Single.fromCallable {
val card = loadFromDisk(vcard)!!
saveLocalProfileToDisk(card, accountId, filesDir)
.subscribeOn(Schedulers.io())
.subscribe({}) { e -> Log.e(TAG, "Error while saving vcard", e) }
card
}.subscribeOn(Schedulers.io())
}
fun peerProfileReceived(filesDir: File, accountId: String, peerId: String, vcard: File): Single<VCard> {
return Single.fromCallable<VCard> {
fun peerProfileReceived(filesDir: File, accountId: String, peerId: String, vcard: File): Single<VCard> =
Single.fromCallable<VCard> {
val filename = "$peerId.vcf"
val peerProfilePath = peerProfilePath(filesDir, accountId)
val file = File(peerProfilePath, filename)
moveFile(vcard, file)
loadFromDisk(file)
}.subscribeOn(Schedulers.io())
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment