move contacts related methods to its own file

This commit is contained in:
Iuri Matias 2020-06-12 12:06:08 -04:00
parent 88bf4fca66
commit 9a03038126
11 changed files with 55 additions and 28 deletions

View File

@ -5,6 +5,7 @@ import chronicles
import ../../status/status import ../../status/status
import ../../status/chat as status_chat import ../../status/chat as status_chat
import ../../status/contacts as status_contacts
import ../../status/chat/[chat, message] import ../../status/chat/[chat, message]
import views/channels_list import views/channels_list
@ -133,4 +134,4 @@ QtObject:
self.status.chat.renameGroup(self.activeChannel.id, newName) self.status.chat.renameGroup(self.activeChannel.id, newName)
proc blockContact*(self: ChatsView, id: string): string {.slot.} = proc blockContact*(self: ChatsView, id: string): string {.slot.} =
return self.status.chat.blockContact(id) return self.status.contacts.blockContact(id)

View File

@ -6,6 +6,7 @@ import ../../status/libstatus/settings as status_settings
import json import json
import ../../status/profile import ../../status/profile
import ../../status/contacts
import ../../status/status import ../../status/status
import view import view

View File

@ -4,6 +4,7 @@ import views/contact_list
import views/profile_info import views/profile_info
import ../../status/profile import ../../status/profile
import ../../status/accounts as status_accounts import ../../status/accounts as status_accounts
import ../../status/contacts as status_contacts
import ../../status/status import ../../status/status
QtObject: QtObject:

View File

@ -2,6 +2,7 @@ import NimQml
import Tables import Tables
import strformat import strformat
import ../../../status/profile import ../../../status/profile
import ../../../status/contacts
type type
ContactRoles {.pure.} = enum ContactRoles {.pure.} = enum

View File

@ -162,6 +162,7 @@ proc confirmJoiningGroup*(self: ChatModel, chatId: string) =
var response = parseJson(status_chat.confirmJoiningGroup(chatId)) var response = parseJson(status_chat.confirmJoiningGroup(chatId))
var (chats, messages) = formatChatUpdate(response) var (chats, messages) = formatChatUpdate(response)
self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats)) self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats))
# self.events.emit("pushMessage", PushMessageArgs(messages: messages, chats: chats))
proc blockContact*(self: ChatModel, id: string): string = proc blockContact*(self: ChatModel, id: string): string =
var contact = status_profile.getContactByID(id) var contact = status_profile.getContactByID(id)

25
src/status/contacts.nim Normal file
View File

@ -0,0 +1,25 @@
import eventemitter
import json
import libstatus/contacts as status_contacts
import profile
type
Contact* = ref object
name*, address*: string
type
ContactModel* = ref object
events*: EventEmitter
proc newContactModel*(events: EventEmitter): ContactModel =
result = ContactModel()
result.events = events
proc getContactByID*(self: ContactModel, id: string): Profile =
let response = status_contacts.getContactByID(id)
toProfileModel(parseJSON($response)["result"])
proc blockContact*(self: ContactModel, id: string): string =
var contact = self.getContactByID(id)
contact.systemTags.add(":contact/blocked")
status_contacts.blockContact(contact)

View File

@ -7,7 +7,6 @@ import sequtils
import chronicles import chronicles
import ../chat/[chat, message] import ../chat/[chat, message]
import ../../signals/messages import ../../signals/messages
import ../profile
proc buildFilter*(chat: Chat):JsonNode = proc buildFilter*(chat: Chat):JsonNode =
if chat.chatType == ChatType.PrivateGroupChat: if chat.chatType == ChatType.PrivateGroupChat:
@ -103,19 +102,6 @@ proc sendChatMessage*(chatId: string, msg: string): string =
} }
]) ])
proc blockContact*(contact: Profile): string =
callPrivateRPC("blockContact".prefix, %* [
{
"id": contact.id,
"ensVerified": contact.ensVerified,
"ensVerifiedAt": contact.ensVerifiedAt,
"ensVerificationRetries": contact.ensVerificationRetries,
"alias": contact.alias,
"identicon": contact.identicon,
"systemTags": contact.systemTags
}
])
proc markAllRead*(chatId: string): string = proc markAllRead*(chatId: string): string =
callPrivateRPC("markAllRead".prefix, %* [chatId]) callPrivateRPC("markAllRead".prefix, %* [chatId])

View File

@ -0,0 +1,21 @@
import core
import json
import utils
import ../profile
# TODO: remove Profile from here
proc blockContact*(contact: Profile): string =
callPrivateRPC("blockContact".prefix, %* [
{
"id": contact.id,
"ensVerified": contact.ensVerified,
"ensVerifiedAt": contact.ensVerifiedAt,
"ensVerificationRetries": contact.ensVerificationRetries,
"alias": contact.alias,
"identicon": contact.identicon,
"systemTags": contact.systemTags
}
])
proc getContactByID*(id: string): string =
callPrivateRPC("getContactByID".prefix, %* [id])

View File

@ -43,6 +43,3 @@ proc removePeer*(peer: string) =
proc markTrustedPeer*(peer: string) = proc markTrustedPeer*(peer: string) =
discard callPrivateRPC("markTrustedPeer".prefix(false), %* [peer]) discard callPrivateRPC("markTrustedPeer".prefix(false), %* [peer])
proc getContactByID*(id: string): string =
result = callPrivateRPC("getContactByID".prefix, %* [id])

View File

@ -8,10 +8,6 @@ type
MailServer* = ref object MailServer* = ref object
name*, endpoint*: string name*, endpoint*: string
type
Contact* = ref object
name*, address*: string
type Profile* = ref object type Profile* = ref object
id*, alias*, username*, identicon*: string id*, alias*, username*, identicon*: string
ensVerified*: bool ensVerified*: bool
@ -47,10 +43,6 @@ proc toProfileModel*(profile: JsonNode): Profile =
systemTags: systemTags systemTags: systemTags
) )
proc getContactByID*(id: string): Profile =
let response = libstatus_core.getContactByID(id)
result = toProfileModel(parseJSON($response)["result"])
type type
ProfileModel* = ref object ProfileModel* = ref object
@ -59,5 +51,3 @@ proc newProfileModel*(): ProfileModel =
proc logout*(self: ProfileModel) = proc logout*(self: ProfileModel) =
discard status_accounts.logout() discard status_accounts.logout()

View File

@ -8,6 +8,7 @@ import accounts as accounts
import wallet as wallet import wallet as wallet
import node as node import node as node
import mailservers as mailservers import mailservers as mailservers
import contacts as contacts
import profile import profile
type Status* = ref object type Status* = ref object
@ -18,6 +19,7 @@ type Status* = ref object
wallet*: WalletModel wallet*: WalletModel
node*: NodeModel node*: NodeModel
profile*: ProfileModel profile*: ProfileModel
contacts*: ContactModel
proc newStatusInstance*(): Status = proc newStatusInstance*(): Status =
result = Status() result = Status()
@ -29,6 +31,7 @@ proc newStatusInstance*(): Status =
result.node = node.newNodeModel() result.node = node.newNodeModel()
result.mailservers = mailservers.newMailserverModel(result.events) result.mailservers = mailservers.newMailserverModel(result.events)
result.profile = profile.newProfileModel() result.profile = profile.newProfileModel()
result.contacts = contacts.newContactModel(result.events)
proc initNode*(self: Status) = proc initNode*(self: Status) =
libstatus_accounts.initNode() libstatus_accounts.initNode()