mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-23 03:58:49 +00:00
feat: Add contacts to message signal and show ens usernames in contact
list
This commit is contained in:
parent
0f7e08075b
commit
ee81c43ddc
@ -2,6 +2,7 @@ import NimQml
|
|||||||
import Tables
|
import Tables
|
||||||
import strformat
|
import strformat
|
||||||
import ../../../status/profile
|
import ../../../status/profile
|
||||||
|
from ../../../status/ens import nil
|
||||||
|
|
||||||
type
|
type
|
||||||
ContactRoles {.pure.} = enum
|
ContactRoles {.pure.} = enum
|
||||||
@ -25,6 +26,12 @@ QtObject:
|
|||||||
method rowCount(self: ContactList, index: QModelIndex = nil): int =
|
method rowCount(self: ContactList, index: QModelIndex = nil): int =
|
||||||
return self.contacts.len
|
return self.contacts.len
|
||||||
|
|
||||||
|
proc getUserName(contact: Profile): string =
|
||||||
|
if(contact.ensName != "" and contact.ensVerified):
|
||||||
|
result = "@" & ens.userName(contact.ensName)
|
||||||
|
else:
|
||||||
|
result = contact.alias
|
||||||
|
|
||||||
method data(self: ContactList, index: QModelIndex, role: int): QVariant =
|
method data(self: ContactList, index: QModelIndex, role: int): QVariant =
|
||||||
if not index.isValid:
|
if not index.isValid:
|
||||||
return
|
return
|
||||||
@ -32,7 +39,7 @@ QtObject:
|
|||||||
return
|
return
|
||||||
let contact = self.contacts[index.row]
|
let contact = self.contacts[index.row]
|
||||||
case role.ContactRoles:
|
case role.ContactRoles:
|
||||||
of ContactRoles.Name: result = newQVariant(contact.username)
|
of ContactRoles.Name: result = newQVariant(getUserName(contact))
|
||||||
of ContactRoles.Address: result = newQVariant(contact.address)
|
of ContactRoles.Address: result = newQVariant(contact.address)
|
||||||
of ContactRoles.Identicon: result = newQVariant(contact.identicon)
|
of ContactRoles.Identicon: result = newQVariant(contact.identicon)
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import types
|
|||||||
import ../status/libstatus/accounts as status_accounts
|
import ../status/libstatus/accounts as status_accounts
|
||||||
import ../status/chat/[chat, message]
|
import ../status/chat/[chat, message]
|
||||||
import random
|
import random
|
||||||
|
import tables
|
||||||
|
|
||||||
proc toMessage*(jsonMsg: JsonNode): Message
|
proc toMessage*(jsonMsg: JsonNode): Message
|
||||||
|
|
||||||
@ -11,6 +12,16 @@ proc toChat*(jsonChat: JsonNode): Chat
|
|||||||
proc fromEvent*(event: JsonNode): Signal =
|
proc fromEvent*(event: JsonNode): Signal =
|
||||||
var signal:MessageSignal = MessageSignal()
|
var signal:MessageSignal = MessageSignal()
|
||||||
signal.messages = @[]
|
signal.messages = @[]
|
||||||
|
signal.contacts = initTable[string, ChatContact]()
|
||||||
|
|
||||||
|
if event["event"]{"contacts"} != nil:
|
||||||
|
for jsonContact in event["event"]["contacts"]:
|
||||||
|
let contact = ChatContact(
|
||||||
|
id: jsonContact["id"].getStr,
|
||||||
|
name: jsonContact["name"].getStr,
|
||||||
|
ensVerified: jsonContact["ensVerified"].getBool
|
||||||
|
)
|
||||||
|
signal.contacts[contact.id] = contact
|
||||||
|
|
||||||
if event["event"]{"messages"} != nil:
|
if event["event"]{"messages"} != nil:
|
||||||
for jsonMsg in event["event"]["messages"]:
|
for jsonMsg in event["event"]["messages"]:
|
||||||
|
@ -3,6 +3,7 @@ import chronicles
|
|||||||
import ../status/libstatus/types
|
import ../status/libstatus/types
|
||||||
import ../status/chat/[chat, message]
|
import ../status/chat/[chat, message]
|
||||||
import json_serialization
|
import json_serialization
|
||||||
|
import tables
|
||||||
|
|
||||||
type SignalSubscriber* = ref object of RootObj
|
type SignalSubscriber* = ref object of RootObj
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ method onSignal*(self: SignalSubscriber, data: Signal) {.base.} =
|
|||||||
type MessageSignal* = ref object of Signal
|
type MessageSignal* = ref object of Signal
|
||||||
messages*: seq[Message]
|
messages*: seq[Message]
|
||||||
chats*: seq[Chat]
|
chats*: seq[Chat]
|
||||||
|
contacts*: Table[string, ChatContact]
|
||||||
|
|
||||||
type Filter* = object
|
type Filter* = object
|
||||||
chatId*: string
|
chatId*: string
|
||||||
|
@ -47,6 +47,7 @@ proc update*(self: ChatModel, chats: seq[Chat], messages: seq[Message]) =
|
|||||||
for chat in chats:
|
for chat in chats:
|
||||||
if chat.isActive:
|
if chat.isActive:
|
||||||
self.channels[chat.id] = chat
|
self.channels[chat.id] = chat
|
||||||
|
|
||||||
self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats))
|
self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats))
|
||||||
|
|
||||||
proc hasChannel*(self: ChatModel, chatId: string): bool =
|
proc hasChannel*(self: ChatModel, chatId: string): bool =
|
||||||
|
@ -11,6 +11,11 @@ type ChatType* {.pure.}= enum
|
|||||||
|
|
||||||
proc isOneToOne*(self: ChatType): bool = self == ChatType.OneToOne
|
proc isOneToOne*(self: ChatType): bool = self == ChatType.OneToOne
|
||||||
|
|
||||||
|
type ChatContact* = object
|
||||||
|
id*: string
|
||||||
|
name*: string
|
||||||
|
ensVerified*: bool
|
||||||
|
|
||||||
type ChatMember* = object
|
type ChatMember* = object
|
||||||
admin*: bool
|
admin*: bool
|
||||||
id*: string
|
id*: string
|
||||||
|
9
src/status/ens.nim
Normal file
9
src/status/ens.nim
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import strutils
|
||||||
|
|
||||||
|
let domain* = ".statusnet.eth"
|
||||||
|
|
||||||
|
proc userName*(ensName: string): string =
|
||||||
|
if ensName != "" and ensName.endsWith(domain):
|
||||||
|
result = ensName.split(".")[0]
|
||||||
|
else:
|
||||||
|
result = ensName
|
@ -9,7 +9,7 @@ type
|
|||||||
name*, endpoint*: string
|
name*, endpoint*: string
|
||||||
|
|
||||||
type Profile* = ref object
|
type Profile* = ref object
|
||||||
id*, alias*, username*, identicon*, address*: string
|
id*, alias*, username*, identicon*, address*, ensName*: string
|
||||||
ensVerified*: bool
|
ensVerified*: bool
|
||||||
ensVerifiedAt*: int
|
ensVerifiedAt*: int
|
||||||
ensVerificationRetries*: int
|
ensVerificationRetries*: int
|
||||||
@ -21,6 +21,7 @@ proc toProfileModel*(account: Account): Profile =
|
|||||||
username: account.name,
|
username: account.name,
|
||||||
identicon: account.photoPath,
|
identicon: account.photoPath,
|
||||||
alias: account.name,
|
alias: account.name,
|
||||||
|
ensName: "",
|
||||||
ensVerified: false,
|
ensVerified: false,
|
||||||
ensVerifiedAt: 0,
|
ensVerifiedAt: 0,
|
||||||
ensVerificationRetries: 0,
|
ensVerificationRetries: 0,
|
||||||
@ -38,6 +39,7 @@ proc toProfileModel*(profile: JsonNode): Profile =
|
|||||||
identicon: profile["identicon"].str,
|
identicon: profile["identicon"].str,
|
||||||
address: profile["id"].str,
|
address: profile["id"].str,
|
||||||
alias: profile["alias"].str,
|
alias: profile["alias"].str,
|
||||||
|
ensName: profile["name"].str,
|
||||||
ensVerified: profile["ensVerified"].getBool,
|
ensVerified: profile["ensVerified"].getBool,
|
||||||
ensVerifiedAt: profile["ensVerifiedAt"].getInt,
|
ensVerifiedAt: profile["ensVerifiedAt"].getInt,
|
||||||
ensVerificationRetries: profile["ensVerificationRetries"].getInt,
|
ensVerificationRetries: profile["ensVerificationRetries"].getInt,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user