fix: add PreferredDisplayName to user_model
- excludes logic of resolving preferred display name to shared contacts_utils - expose PreferredDisplayName role from user_model - improves PreferredDisplayName handling in member_model Closes: #16429
This commit is contained in:
parent
ee9091377f
commit
f8d33656e6
|
@ -0,0 +1,8 @@
|
||||||
|
proc resolvePreferredDisplayName*(localNickName: string, ensName: string, displayName: string, alias: string): string =
|
||||||
|
if localNickname != "":
|
||||||
|
return localNickname
|
||||||
|
if ensName != "":
|
||||||
|
return ensName
|
||||||
|
if displayName != "":
|
||||||
|
return displayName
|
||||||
|
return alias
|
|
@ -5,6 +5,7 @@ import NimQml, Tables, stew/shims/strformat, sequtils, sugar
|
||||||
import ../../../app_service/common/types
|
import ../../../app_service/common/types
|
||||||
import ../../../app_service/service/contacts/dto/contacts
|
import ../../../app_service/service/contacts/dto/contacts
|
||||||
import member_item
|
import member_item
|
||||||
|
import contacts_utils
|
||||||
|
|
||||||
type
|
type
|
||||||
ModelRole {.pure.} = enum
|
ModelRole {.pure.} = enum
|
||||||
|
@ -120,13 +121,8 @@ QtObject:
|
||||||
of ModelRole.DisplayName:
|
of ModelRole.DisplayName:
|
||||||
result = newQVariant(item.displayName)
|
result = newQVariant(item.displayName)
|
||||||
of ModelRole.PreferredDisplayName:
|
of ModelRole.PreferredDisplayName:
|
||||||
if item.localNickname != "":
|
return newQVariant(resolvePreferredDisplayName(
|
||||||
return newQVariant(item.localNickname)
|
item.localNickname, item.ensName, item.displayName, item.alias))
|
||||||
if item.ensName != "":
|
|
||||||
return newQVariant(item.ensName)
|
|
||||||
if item.displayName != "":
|
|
||||||
return newQVariant(item.displayName)
|
|
||||||
return newQVariant(item.alias)
|
|
||||||
of ModelRole.EnsName:
|
of ModelRole.EnsName:
|
||||||
result = newQVariant(item.ensName)
|
result = newQVariant(item.ensName)
|
||||||
of ModelRole.IsEnsVerified:
|
of ModelRole.IsEnsVerified:
|
||||||
|
@ -219,6 +215,10 @@ QtObject:
|
||||||
|
|
||||||
var roles: seq[int] = @[]
|
var roles: seq[int] = @[]
|
||||||
|
|
||||||
|
let preferredDisplayNameChanged =
|
||||||
|
resolvePreferredDisplayName(self.items[ind].localNickname, self.items[ind].ensName, self.items[ind].displayName, self.items[ind].alias) !=
|
||||||
|
resolvePreferredDisplayName(localNickname, ensName, displayName, self.items[ind].alias)
|
||||||
|
|
||||||
if self.items[ind].displayName != displayName:
|
if self.items[ind].displayName != displayName:
|
||||||
self.items[ind].displayName = displayName
|
self.items[ind].displayName = displayName
|
||||||
roles.add(ModelRole.DisplayName.int)
|
roles.add(ModelRole.DisplayName.int)
|
||||||
|
@ -234,7 +234,8 @@ QtObject:
|
||||||
if roles.len == 0:
|
if roles.len == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
roles.add(ModelRole.PreferredDisplayName.int)
|
if preferredDisplayNameChanged:
|
||||||
|
roles.add(ModelRole.PreferredDisplayName.int)
|
||||||
|
|
||||||
let index = self.createIndex(ind, 0, nil)
|
let index = self.createIndex(ind, 0, nil)
|
||||||
defer: index.delete
|
defer: index.delete
|
||||||
|
@ -275,21 +276,20 @@ QtObject:
|
||||||
|
|
||||||
var roles: seq[int] = @[]
|
var roles: seq[int] = @[]
|
||||||
|
|
||||||
var preferredNameMightHaveChanged = false
|
let preferredDisplayNameChanged =
|
||||||
|
resolvePreferredDisplayName(self.items[ind].localNickname, self.items[ind].ensName, self.items[ind].displayName, self.items[ind].alias) !=
|
||||||
|
resolvePreferredDisplayName(localNickname, ensName, displayName, alias)
|
||||||
|
|
||||||
if self.items[ind].displayName != displayName:
|
if self.items[ind].displayName != displayName:
|
||||||
self.items[ind].displayName = displayName
|
self.items[ind].displayName = displayName
|
||||||
preferredNameMightHaveChanged = true
|
|
||||||
roles.add(ModelRole.DisplayName.int)
|
roles.add(ModelRole.DisplayName.int)
|
||||||
|
|
||||||
if self.items[ind].ensName != ensName:
|
if self.items[ind].ensName != ensName:
|
||||||
self.items[ind].ensName = ensName
|
self.items[ind].ensName = ensName
|
||||||
preferredNameMightHaveChanged = true
|
|
||||||
roles.add(ModelRole.EnsName.int)
|
roles.add(ModelRole.EnsName.int)
|
||||||
|
|
||||||
if self.items[ind].localNickname != localNickname:
|
if self.items[ind].localNickname != localNickname:
|
||||||
self.items[ind].localNickname = localNickname
|
self.items[ind].localNickname = localNickname
|
||||||
preferredNameMightHaveChanged = true
|
|
||||||
roles.add(ModelRole.LocalNickname.int)
|
roles.add(ModelRole.LocalNickname.int)
|
||||||
|
|
||||||
if self.items[ind].isEnsVerified != isEnsVerified:
|
if self.items[ind].isEnsVerified != isEnsVerified:
|
||||||
|
@ -298,7 +298,6 @@ QtObject:
|
||||||
|
|
||||||
if self.items[ind].alias != alias:
|
if self.items[ind].alias != alias:
|
||||||
self.items[ind].alias = alias
|
self.items[ind].alias = alias
|
||||||
preferredNameMightHaveChanged = true
|
|
||||||
roles.add(ModelRole.Alias.int)
|
roles.add(ModelRole.Alias.int)
|
||||||
|
|
||||||
if self.items[ind].icon != icon:
|
if self.items[ind].icon != icon:
|
||||||
|
@ -325,7 +324,7 @@ QtObject:
|
||||||
self.items[ind].isUntrustworthy = isUntrustworthy
|
self.items[ind].isUntrustworthy = isUntrustworthy
|
||||||
roles.add(ModelRole.IsUntrustworthy.int)
|
roles.add(ModelRole.IsUntrustworthy.int)
|
||||||
|
|
||||||
if preferredNameMightHaveChanged:
|
if preferredDisplayNameChanged:
|
||||||
roles.add(ModelRole.PreferredDisplayName.int)
|
roles.add(ModelRole.PreferredDisplayName.int)
|
||||||
|
|
||||||
if roles.len == 0:
|
if roles.len == 0:
|
||||||
|
|
|
@ -2,11 +2,13 @@ import NimQml, Tables, stew/shims/strformat, sequtils, sugar
|
||||||
import user_item
|
import user_item
|
||||||
|
|
||||||
import ../../../app_service/common/types
|
import ../../../app_service/common/types
|
||||||
|
import contacts_utils
|
||||||
|
|
||||||
type
|
type
|
||||||
ModelRole {.pure.} = enum
|
ModelRole {.pure.} = enum
|
||||||
PubKey = UserRole + 1
|
PubKey = UserRole + 1
|
||||||
DisplayName
|
DisplayName
|
||||||
|
PreferredDisplayName
|
||||||
EnsName
|
EnsName
|
||||||
IsEnsVerified
|
IsEnsVerified
|
||||||
LocalNickname
|
LocalNickname
|
||||||
|
@ -83,6 +85,7 @@ QtObject:
|
||||||
{
|
{
|
||||||
ModelRole.PubKey.int: "pubKey",
|
ModelRole.PubKey.int: "pubKey",
|
||||||
ModelRole.DisplayName.int: "displayName",
|
ModelRole.DisplayName.int: "displayName",
|
||||||
|
ModelRole.PreferredDisplayName.int: "preferredDisplayName",
|
||||||
ModelRole.EnsName.int: "ensName",
|
ModelRole.EnsName.int: "ensName",
|
||||||
ModelRole.IsEnsVerified.int: "isEnsVerified",
|
ModelRole.IsEnsVerified.int: "isEnsVerified",
|
||||||
ModelRole.LocalNickname.int: "localNickname",
|
ModelRole.LocalNickname.int: "localNickname",
|
||||||
|
@ -128,6 +131,9 @@ QtObject:
|
||||||
result = newQVariant(item.pubKey)
|
result = newQVariant(item.pubKey)
|
||||||
of ModelRole.DisplayName:
|
of ModelRole.DisplayName:
|
||||||
result = newQVariant(item.displayName)
|
result = newQVariant(item.displayName)
|
||||||
|
of ModelRole.PreferredDisplayName:
|
||||||
|
return newQVariant(resolvePreferredDisplayName(
|
||||||
|
item.localNickname, item.ensName, item.displayName, item.alias))
|
||||||
of ModelRole.EnsName:
|
of ModelRole.EnsName:
|
||||||
result = newQVariant(item.ensName)
|
result = newQVariant(item.ensName)
|
||||||
of ModelRole.IsEnsVerified:
|
of ModelRole.IsEnsVerified:
|
||||||
|
@ -260,17 +266,33 @@ QtObject:
|
||||||
if(ind == -1):
|
if(ind == -1):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.items[ind].displayName = displayName
|
var roles: seq[int] = @[]
|
||||||
self.items[ind].ensName = ensName
|
|
||||||
self.items[ind].localNickname = localNickname
|
let preferredDisplayNameChanged =
|
||||||
|
resolvePreferredDisplayName(self.items[ind].localNickname, self.items[ind].ensName, self.items[ind].displayName, self.items[ind].alias) !=
|
||||||
|
resolvePreferredDisplayName(localNickname, ensName, displayName, self.items[ind].alias)
|
||||||
|
|
||||||
|
if self.items[ind].displayName != displayName:
|
||||||
|
self.items[ind].displayName = displayName
|
||||||
|
roles.add(ModelRole.DisplayName.int)
|
||||||
|
|
||||||
|
if self.items[ind].ensName != ensName:
|
||||||
|
self.items[ind].ensName = ensName
|
||||||
|
roles.add(ModelRole.EnsName.int)
|
||||||
|
|
||||||
|
if self.items[ind].localNickname != localNickname:
|
||||||
|
self.items[ind].localNickname = localNickname
|
||||||
|
roles.add(ModelRole.LocalNickname.int)
|
||||||
|
|
||||||
|
if preferredDisplayNameChanged:
|
||||||
|
roles.add(ModelRole.PreferredDisplayName.int)
|
||||||
|
|
||||||
|
if roles.len == 0:
|
||||||
|
return
|
||||||
|
|
||||||
let index = self.createIndex(ind, 0, nil)
|
let index = self.createIndex(ind, 0, nil)
|
||||||
defer: index.delete
|
defer: index.delete
|
||||||
self.dataChanged(index, index, @[
|
self.dataChanged(index, index, roles)
|
||||||
ModelRole.DisplayName.int,
|
|
||||||
ModelRole.EnsName.int,
|
|
||||||
ModelRole.LocalNickname.int,
|
|
||||||
])
|
|
||||||
self.itemChanged(pubKey)
|
self.itemChanged(pubKey)
|
||||||
|
|
||||||
proc setIcon*(self: Model, pubKey: string, icon: string) =
|
proc setIcon*(self: Model, pubKey: string, icon: string) =
|
||||||
|
@ -300,25 +322,49 @@ QtObject:
|
||||||
if(ind == -1):
|
if(ind == -1):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.items[ind].displayName = displayName
|
var roles: seq[int] = @[]
|
||||||
self.items[ind].ensName = ensName
|
|
||||||
self.items[ind].isEnsVerified = isEnsVerified
|
let preferredDisplayNameChanged =
|
||||||
self.items[ind].localNickname = localNickname
|
resolvePreferredDisplayName(self.items[ind].localNickname, self.items[ind].ensName, self.items[ind].displayName, self.items[ind].alias) !=
|
||||||
self.items[ind].alias = alias
|
resolvePreferredDisplayName(localNickname, ensName, displayName, alias)
|
||||||
self.items[ind].icon = icon
|
|
||||||
self.items[ind].isUntrustworthy = isUntrustworthy
|
if self.items[ind].displayName != displayName:
|
||||||
|
self.items[ind].displayName = displayName
|
||||||
|
roles.add(ModelRole.DisplayName.int)
|
||||||
|
|
||||||
|
if self.items[ind].ensName != ensName:
|
||||||
|
self.items[ind].ensName = ensName
|
||||||
|
roles.add(ModelRole.EnsName.int)
|
||||||
|
|
||||||
|
if self.items[ind].isEnsVerified != isEnsVerified:
|
||||||
|
self.items[ind].isEnsVerified = isEnsVerified
|
||||||
|
roles.add(ModelRole.IsEnsVerified.int)
|
||||||
|
|
||||||
|
if self.items[ind].localNickname != localNickname:
|
||||||
|
self.items[ind].localNickname = localNickname
|
||||||
|
roles.add(ModelRole.LocalNickname.int)
|
||||||
|
|
||||||
|
if self.items[ind].alias != alias:
|
||||||
|
self.items[ind].alias = alias
|
||||||
|
roles.add(ModelRole.Alias.int)
|
||||||
|
|
||||||
|
if self.items[ind].icon != icon:
|
||||||
|
self.items[ind].icon = icon
|
||||||
|
roles.add(ModelRole.Icon.int)
|
||||||
|
|
||||||
|
if self.items[ind].isUntrustworthy != isUntrustworthy:
|
||||||
|
self.items[ind].isUntrustworthy = isUntrustworthy
|
||||||
|
roles.add(ModelRole.IsUntrustworthy.int)
|
||||||
|
|
||||||
|
if preferredDisplayNameChanged:
|
||||||
|
roles.add(ModelRole.PreferredDisplayName.int)
|
||||||
|
|
||||||
|
if roles.len == 0:
|
||||||
|
return
|
||||||
|
|
||||||
let index = self.createIndex(ind, 0, nil)
|
let index = self.createIndex(ind, 0, nil)
|
||||||
defer: index.delete
|
defer: index.delete
|
||||||
self.dataChanged(index, index, @[
|
self.dataChanged(index, index, roles)
|
||||||
ModelRole.DisplayName.int,
|
|
||||||
ModelRole.EnsName.int,
|
|
||||||
ModelRole.IsEnsVerified.int,
|
|
||||||
ModelRole.LocalNickname.int,
|
|
||||||
ModelRole.Alias.int,
|
|
||||||
ModelRole.Icon.int,
|
|
||||||
ModelRole.IsUntrustworthy.int,
|
|
||||||
])
|
|
||||||
self.itemChanged(pubKey)
|
self.itemChanged(pubKey)
|
||||||
|
|
||||||
proc updateIncomingRequestStatus*(
|
proc updateIncomingRequestStatus*(
|
||||||
|
|
Loading…
Reference in New Issue