mirror of
https://github.com/status-im/status-lib.git
synced 2025-01-14 14:34:39 +00:00
refactor: signals removed
This commit is contained in:
parent
0bc0110e9a
commit
79be86551b
@ -1,16 +0,0 @@
|
||||
import json
|
||||
import json_serialization
|
||||
import signal_type
|
||||
import ../status
|
||||
import ../types/rpc_response
|
||||
|
||||
import ../../eventemitter
|
||||
|
||||
export signal_type
|
||||
|
||||
type Signal* = ref object of Args
|
||||
signalType* {.serializedFieldName("type").}: SignalType
|
||||
signalTypeStr*: string
|
||||
|
||||
type NodeSignal* = ref object of Signal
|
||||
event*: StatusGoError
|
@ -1,12 +0,0 @@
|
||||
import json
|
||||
import base
|
||||
import signal_type
|
||||
|
||||
type ChroniclesLogsSignal* = ref object of Signal
|
||||
content*: string
|
||||
|
||||
proc fromEvent*(T: type ChroniclesLogsSignal, jsonSignal: JsonNode): ChroniclesLogsSignal =
|
||||
result = ChroniclesLogsSignal()
|
||||
result.signalType = SignalType.ChroniclesLogs
|
||||
if jsonSignal["event"].kind != JNull:
|
||||
result.content = jsonSignal["event"].getStr()
|
@ -1,14 +0,0 @@
|
||||
import json
|
||||
|
||||
import base
|
||||
|
||||
import status/types/community
|
||||
import signal_type
|
||||
|
||||
type CommunitySignal* = ref object of Signal
|
||||
community*: Community
|
||||
|
||||
proc fromEvent*(T: type CommunitySignal, event: JsonNode): CommunitySignal =
|
||||
result = CommunitySignal()
|
||||
result.signalType = SignalType.CommunityFound
|
||||
result.community = event["event"].toCommunity()
|
@ -1,14 +0,0 @@
|
||||
import json
|
||||
|
||||
import base
|
||||
import signal_type
|
||||
|
||||
type DiscoverySummarySignal* = ref object of Signal
|
||||
enodes*: seq[string]
|
||||
|
||||
proc fromEvent*(T: type DiscoverySummarySignal, jsonSignal: JsonNode): DiscoverySummarySignal =
|
||||
result = DiscoverySummarySignal()
|
||||
result.signalType = SignalType.DiscoverySummary
|
||||
if jsonSignal["event"].kind != JNull:
|
||||
for discoveryItem in jsonSignal["event"]:
|
||||
result.enodes.add(discoveryItem["enode"].getStr)
|
@ -1,15 +0,0 @@
|
||||
import json
|
||||
|
||||
import base
|
||||
import signal_type
|
||||
|
||||
type EnvelopeSentSignal* = ref object of Signal
|
||||
messageIds*: seq[string]
|
||||
|
||||
proc fromEvent*(T: type EnvelopeSentSignal, jsonSignal: JsonNode): EnvelopeSentSignal =
|
||||
result = EnvelopeSentSignal()
|
||||
result.signalType = SignalType.EnvelopeSent
|
||||
if jsonSignal["event"].kind != JNull and jsonSignal["event"].hasKey("ids") and jsonSignal["event"]["ids"].kind != JNull:
|
||||
for messageId in jsonSignal["event"]["ids"]:
|
||||
result.messageIds.add(messageId.getStr)
|
||||
|
@ -1,15 +0,0 @@
|
||||
import json
|
||||
|
||||
import base
|
||||
import signal_type
|
||||
|
||||
type EnvelopeExpiredSignal* = ref object of Signal
|
||||
messageIds*: seq[string]
|
||||
|
||||
proc fromEvent*(T: type EnvelopeExpiredSignal, jsonSignal: JsonNode): EnvelopeExpiredSignal =
|
||||
result = EnvelopeExpiredSignal()
|
||||
result.signalType = SignalType.EnvelopeExpired
|
||||
if jsonSignal["event"].kind != JNull and jsonSignal["event"].hasKey("ids") and jsonSignal["event"]["ids"].kind != JNull:
|
||||
for messageId in jsonSignal["event"]["ids"]:
|
||||
result.messageIds.add(messageId.getStr)
|
||||
|
@ -1,11 +0,0 @@
|
||||
import json
|
||||
|
||||
import base
|
||||
import signal_type
|
||||
|
||||
type KeycardConnectedSignal* = ref object of Signal
|
||||
started*: string
|
||||
|
||||
proc fromEvent*(T: type KeycardConnectedSignal, event: JsonNode): KeycardConnectedSignal =
|
||||
result = KeycardConnectedSignal()
|
||||
result.started = event["event"].getStr()
|
@ -1,95 +0,0 @@
|
||||
import json
|
||||
|
||||
import base
|
||||
|
||||
import status/types/[message, chat, community, profile, installation,
|
||||
activity_center_notification, status_update, removed_message]
|
||||
|
||||
type MessageSignal* = ref object of Signal
|
||||
messages*: seq[Message]
|
||||
pinnedMessages*: seq[Message]
|
||||
chats*: seq[Chat]
|
||||
contacts*: seq[Profile]
|
||||
installations*: seq[Installation]
|
||||
emojiReactions*: seq[Reaction]
|
||||
communities*: seq[Community]
|
||||
membershipRequests*: seq[CommunityMembershipRequest]
|
||||
activityCenterNotification*: seq[ActivityCenterNotification]
|
||||
statusUpdates*: seq[StatusUpdate]
|
||||
deletedMessages*: seq[RemovedMessage]
|
||||
|
||||
proc fromEvent*(T: type MessageSignal, event: JsonNode, logMessage: bool = false): MessageSignal =
|
||||
var signal:MessageSignal = MessageSignal()
|
||||
signal.messages = @[]
|
||||
signal.contacts = @[]
|
||||
|
||||
if event["event"]{"contacts"} != nil:
|
||||
for jsonContact in event["event"]["contacts"]:
|
||||
signal.contacts.add(jsonContact.toProfile())
|
||||
|
||||
var chatsWithMentions: seq[string] = @[]
|
||||
|
||||
if event["event"]{"messages"} != nil:
|
||||
for jsonMsg in event["event"]["messages"]:
|
||||
var message = jsonMsg.toMessage(logMessage)
|
||||
if message.hasMention:
|
||||
chatsWithMentions.add(message.chatId)
|
||||
signal.messages.add(message)
|
||||
|
||||
if event["event"]{"chats"} != nil:
|
||||
for jsonChat in event["event"]["chats"]:
|
||||
var chat = jsonChat.toChat
|
||||
if chatsWithMentions.contains(chat.id):
|
||||
chat.mentionsCount.inc
|
||||
signal.chats.add(chat)
|
||||
|
||||
if event["event"]{"statusUpdates"} != nil:
|
||||
for jsonStatusUpdate in event["event"]["statusUpdates"]:
|
||||
var statusUpdate = jsonStatusUpdate.toStatusUpdate
|
||||
signal.statusUpdates.add(statusUpdate)
|
||||
|
||||
if event["event"]{"installations"} != nil:
|
||||
for jsonInstallation in event["event"]["installations"]:
|
||||
signal.installations.add(jsonInstallation.toInstallation)
|
||||
|
||||
if event["event"]{"emojiReactions"} != nil:
|
||||
for jsonReaction in event["event"]["emojiReactions"]:
|
||||
signal.emojiReactions.add(jsonReaction.toReaction)
|
||||
|
||||
if event["event"]{"communities"} != nil:
|
||||
for jsonCommunity in event["event"]["communities"]:
|
||||
signal.communities.add(jsonCommunity.toCommunity)
|
||||
|
||||
if event["event"]{"requestsToJoinCommunity"} != nil:
|
||||
for jsonCommunity in event["event"]["requestsToJoinCommunity"]:
|
||||
signal.membershipRequests.add(jsonCommunity.toCommunityMembershipRequest)
|
||||
|
||||
if event["event"]{"removedMessages"} != nil:
|
||||
for jsonRemovedMessage in event["event"]["removedMessages"]:
|
||||
signal.deletedMessages.add(jsonRemovedMessage.toRemovedMessage)
|
||||
|
||||
if event["event"]{"activityCenterNotifications"} != nil:
|
||||
for jsonNotification in event["event"]["activityCenterNotifications"]:
|
||||
signal.activityCenterNotification.add(jsonNotification.toActivityCenterNotification())
|
||||
|
||||
if event["event"]{"pinMessages"} != nil:
|
||||
for jsonPinnedMessage in event["event"]["pinMessages"]:
|
||||
var contentType: ContentType
|
||||
try:
|
||||
contentType = ContentType(jsonPinnedMessage{"contentType"}.getInt)
|
||||
except:
|
||||
contentType = ContentType.Message
|
||||
signal.pinnedMessages.add(Message(
|
||||
id: jsonPinnedMessage{"message_id"}.getStr,
|
||||
chatId: jsonPinnedMessage{"chat_id"}.getStr,
|
||||
localChatId: jsonPinnedMessage{"localChatId"}.getStr,
|
||||
pinnedBy: jsonPinnedMessage{"from"}.getStr,
|
||||
identicon: jsonPinnedMessage{"identicon"}.getStr,
|
||||
alias: jsonPinnedMessage{"alias"}.getStr,
|
||||
clock: jsonPinnedMessage{"clock"}.getInt,
|
||||
isPinned: jsonPinnedMessage{"pinned"}.getBool,
|
||||
contentType: contentType
|
||||
))
|
||||
|
||||
result = signal
|
||||
|
@ -1,14 +0,0 @@
|
||||
import json
|
||||
import base
|
||||
import signal_type
|
||||
|
||||
type PeerStatsSignal* = ref object of Signal
|
||||
peers*: seq[string]
|
||||
|
||||
proc fromEvent*(T: type PeerStatsSignal, jsonSignal: JsonNode): PeerStatsSignal =
|
||||
result = PeerStatsSignal()
|
||||
result.signalType = SignalType.PeerStats
|
||||
if jsonSignal["event"].kind != JNull:
|
||||
for (node, protocols) in jsonSignal["event"]["peers"].pairs():
|
||||
if protocols.getElems.len != 0:
|
||||
result.peers.add(node)
|
@ -1,22 +0,0 @@
|
||||
import json
|
||||
|
||||
import base
|
||||
import signal_type
|
||||
|
||||
type Stats* = object
|
||||
uploadRate*: uint64
|
||||
downloadRate*: uint64
|
||||
|
||||
type StatsSignal* = ref object of Signal
|
||||
stats*: Stats
|
||||
|
||||
proc toStats(jsonMsg: JsonNode): Stats =
|
||||
result = Stats(
|
||||
uploadRate: uint64(jsonMsg{"uploadRate"}.getBiggestInt()),
|
||||
downloadRate: uint64(jsonMsg{"downloadRate"}.getBiggestInt())
|
||||
)
|
||||
|
||||
proc fromEvent*(T: type StatsSignal, event: JsonNode): StatsSignal =
|
||||
result = StatsSignal()
|
||||
result.signalType = SignalType.Stats
|
||||
result.stats = event["event"].toStats
|
@ -1,28 +0,0 @@
|
||||
import json
|
||||
|
||||
import base
|
||||
import signal_type
|
||||
|
||||
type WalletSignal* = ref object of Signal
|
||||
content*: string
|
||||
eventType*: string
|
||||
blockNumber*: int
|
||||
accounts*: seq[string]
|
||||
baseFeePerGas*: string
|
||||
# newTransactions*: ???
|
||||
erc20*: bool
|
||||
|
||||
proc fromEvent*(T: type WalletSignal, jsonSignal: JsonNode): WalletSignal =
|
||||
result = WalletSignal()
|
||||
result.signalType = SignalType.Wallet
|
||||
result.content = $jsonSignal
|
||||
if jsonSignal["event"].kind != JNull:
|
||||
result.eventType = jsonSignal["event"]["type"].getStr
|
||||
result.blockNumber = jsonSignal["event"]{"blockNumber"}.getInt
|
||||
result.baseFeePerGas = jsonSignal["event"]{"baseFeePerGas"}.getStr
|
||||
result.erc20 = jsonSignal["event"]{"erc20"}.getBool
|
||||
result.accounts = @[]
|
||||
if jsonSignal["event"]["accounts"].kind != JNull:
|
||||
for account in jsonSignal["event"]["accounts"]:
|
||||
result.accounts.add(account.getStr)
|
||||
|
@ -1,29 +0,0 @@
|
||||
import json
|
||||
|
||||
import base
|
||||
|
||||
type Filter* = object
|
||||
chatId*: string
|
||||
symKeyId*: string
|
||||
listen*: bool
|
||||
filterId*: string
|
||||
identity*: string
|
||||
topic*: string
|
||||
|
||||
type WhisperFilterSignal* = ref object of Signal
|
||||
filters*: seq[Filter]
|
||||
|
||||
proc toFilter(jsonMsg: JsonNode): Filter =
|
||||
result = Filter(
|
||||
chatId: jsonMsg{"chatId"}.getStr,
|
||||
symKeyId: jsonMsg{"symKeyId"}.getStr,
|
||||
listen: jsonMsg{"listen"}.getBool,
|
||||
filterId: jsonMsg{"filterId"}.getStr,
|
||||
identity: jsonMsg{"identity"}.getStr,
|
||||
topic: jsonMsg{"topic"}.getStr,
|
||||
)
|
||||
|
||||
proc fromEvent*(T: type WhisperFilterSignal, event: JsonNode): WhisperFilterSignal =
|
||||
if event["event"]{"filters"} != nil:
|
||||
for jsonMsg in event["event"]["filters"]:
|
||||
result.filters.add(jsonMsg.toFilter)
|
Loading…
x
Reference in New Issue
Block a user