feat: Add contacts to message signal and show ens usernames in contact

list
This commit is contained in:
Richard Ramos 2020-06-16 13:17:19 -04:00 committed by Iuri Matias
parent 0f7e08075b
commit ee81c43ddc
7 changed files with 39 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import NimQml
import Tables
import strformat
import ../../../status/profile
from ../../../status/ens import nil
type
ContactRoles {.pure.} = enum
@ -25,6 +26,12 @@ QtObject:
method rowCount(self: ContactList, index: QModelIndex = nil): int =
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 =
if not index.isValid:
return
@ -32,7 +39,7 @@ QtObject:
return
let contact = self.contacts[index.row]
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.Identicon: result = newQVariant(contact.identicon)

View File

@ -3,6 +3,7 @@ import types
import ../status/libstatus/accounts as status_accounts
import ../status/chat/[chat, message]
import random
import tables
proc toMessage*(jsonMsg: JsonNode): Message
@ -11,6 +12,16 @@ proc toChat*(jsonChat: JsonNode): Chat
proc fromEvent*(event: JsonNode): Signal =
var signal:MessageSignal = MessageSignal()
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:
for jsonMsg in event["event"]["messages"]:

View File

@ -3,6 +3,7 @@ import chronicles
import ../status/libstatus/types
import ../status/chat/[chat, message]
import json_serialization
import tables
type SignalSubscriber* = ref object of RootObj
@ -25,6 +26,7 @@ method onSignal*(self: SignalSubscriber, data: Signal) {.base.} =
type MessageSignal* = ref object of Signal
messages*: seq[Message]
chats*: seq[Chat]
contacts*: Table[string, ChatContact]
type Filter* = object
chatId*: string

View File

@ -47,6 +47,7 @@ proc update*(self: ChatModel, chats: seq[Chat], messages: seq[Message]) =
for chat in chats:
if chat.isActive:
self.channels[chat.id] = chat
self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats))
proc hasChannel*(self: ChatModel, chatId: string): bool =

View File

@ -11,6 +11,11 @@ type ChatType* {.pure.}= enum
proc isOneToOne*(self: ChatType): bool = self == ChatType.OneToOne
type ChatContact* = object
id*: string
name*: string
ensVerified*: bool
type ChatMember* = object
admin*: bool
id*: string

9
src/status/ens.nim Normal file
View 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

View File

@ -9,7 +9,7 @@ type
name*, endpoint*: string
type Profile* = ref object
id*, alias*, username*, identicon*, address*: string
id*, alias*, username*, identicon*, address*, ensName*: string
ensVerified*: bool
ensVerifiedAt*: int
ensVerificationRetries*: int
@ -21,6 +21,7 @@ proc toProfileModel*(account: Account): Profile =
username: account.name,
identicon: account.photoPath,
alias: account.name,
ensName: "",
ensVerified: false,
ensVerifiedAt: 0,
ensVerificationRetries: 0,
@ -38,6 +39,7 @@ proc toProfileModel*(profile: JsonNode): Profile =
identicon: profile["identicon"].str,
address: profile["id"].str,
alias: profile["alias"].str,
ensName: profile["name"].str,
ensVerified: profile["ensVerified"].getBool,
ensVerifiedAt: profile["ensVerifiedAt"].getInt,
ensVerificationRetries: profile["ensVerificationRetries"].getInt,