Update default profile picture when changing display name

This commit is contained in:
Benoit Martins 2024-12-13 14:41:27 +01:00
parent 0e635ec9fc
commit 8609f880fb
2 changed files with 23 additions and 16 deletions

View file

@ -317,11 +317,19 @@ struct ConversationInfoFragment: View {
}
VStack {
Text(participantConversationModel.name)
.foregroundStyle(Color.grayMain2c700)
.default_text_style(styleSize: 14)
.frame(maxWidth: .infinity, alignment: .leading)
.lineLimit(1)
if conversationViewModel.myParticipantConversationModel != nil && conversationViewModel.myParticipantConversationModel!.address != participantConversationModel.address {
Text(participantConversationModel.name)
.foregroundStyle(Color.grayMain2c700)
.default_text_style(styleSize: 14)
.frame(maxWidth: .infinity, alignment: .leading)
.lineLimit(1)
} else {
Text(accountProfileViewModel.displayName.isEmpty ? participantConversationModel.name : accountProfileViewModel.displayName)
.foregroundStyle(Color.grayMain2c700)
.default_text_style(styleSize: 14)
.frame(maxWidth: .infinity, alignment: .leading)
.lineLimit(1)
}
let participantConversationModelIsAdmin = conversationViewModel.participantConversationModelAdmin.first(
where: {$0.address == participantConversationModel.address})

View file

@ -36,22 +36,21 @@ class AccountProfileViewModel: ObservableObject {
func saveChangesWhenLeaving() {
CoreContext.shared.doOnCoreQueue { core in
let newParams = core.defaultAccount!.params?.clone()
print("getImagePath 0 \(self.displayName) \(newParams?.identityAddress?.displayName ?? "NIL")")
if self.displayName != newParams?.identityAddress?.displayName {
if (self.displayName != newParams?.identityAddress?.displayName)
&& (newParams?.identityAddress?.displayName != nil || !self.displayName.isEmpty) {
if let newIdentityAddress = newParams?.identityAddress?.clone() {
try? newIdentityAddress.setDisplayname(newValue: self.displayName)
try? newParams?.setIdentityaddress(newValue: newIdentityAddress)
}
print("getImagePath 1 \(self.getImagePath().lastPathComponent)")
if self.getImagePath().lastPathComponent.contains("-default") {
print("getImagePath 2")
self.saveImage(
image: ContactsManager.shared.textToImage(
firstName: self.displayName.isEmpty ? core.defaultAccount!.displayName() : self.displayName, lastName: ""),
name: self.displayName.isEmpty ? core.defaultAccount!.displayName() : self.displayName,
prefix: "-default")
if self.getImagePath().lastPathComponent.contains("-default") || self.getImagePath().lastPathComponent == "Documents" {
DispatchQueue.main.async {
self.saveImage(
image: ContactsManager.shared.textToImage(
firstName: self.displayName.isEmpty ? core.defaultAccount!.displayName() : self.displayName, lastName: ""),
name: self.displayName.isEmpty ? core.defaultAccount!.displayName() : self.displayName,
prefix: "-default")
}
}
}