refactor: unify ChatMessage and Message, and move Chat and Message to status folder
This commit is contained in:
parent
9a2144fe75
commit
8fb3368925
|
@ -3,9 +3,9 @@ import Tables
|
||||||
import json
|
import json
|
||||||
import chronicles
|
import chronicles
|
||||||
|
|
||||||
import ../../signals/types
|
|
||||||
import ../../status/chat
|
|
||||||
import ../../status/status
|
import ../../status/status
|
||||||
|
import ../../status/chat as status_chat
|
||||||
|
import ../../status/chat/[chat, message]
|
||||||
|
|
||||||
import views/channels_list
|
import views/channels_list
|
||||||
import views/message_list
|
import views/message_list
|
||||||
|
@ -84,7 +84,7 @@ QtObject:
|
||||||
|
|
||||||
proc messagePushed*(self: ChatsView) {.signal.}
|
proc messagePushed*(self: ChatsView) {.signal.}
|
||||||
|
|
||||||
proc pushMessage*(self:ChatsView, message: ChatMessage) =
|
proc pushMessage*(self:ChatsView, message: Message) =
|
||||||
self.upsertChannel(message.chatId)
|
self.upsertChannel(message.chatId)
|
||||||
self.messageList[message.chatId].add(message)
|
self.messageList[message.chatId].add(message)
|
||||||
self.messagePushed()
|
self.messagePushed()
|
||||||
|
@ -92,7 +92,7 @@ QtObject:
|
||||||
proc pushMessages*(self:ChatsView, messages: seq[Message]) =
|
proc pushMessages*(self:ChatsView, messages: seq[Message]) =
|
||||||
for msg in messages:
|
for msg in messages:
|
||||||
self.upsertChannel(msg.chatId)
|
self.upsertChannel(msg.chatId)
|
||||||
self.messageList[msg.chatId].add(msg.toChatMessage())
|
self.messageList[msg.chatId].add(msg)
|
||||||
self.messagePushed()
|
self.messagePushed()
|
||||||
|
|
||||||
proc getMessageList(self: ChatsView): QVariant {.slot.} =
|
proc getMessageList(self: ChatsView): QVariant {.slot.} =
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import NimQml, Tables
|
import NimQml, Tables
|
||||||
import ../../../status/chat
|
import ../../../status/chat/[chat, message]
|
||||||
import ../../../signals/types
|
|
||||||
|
|
||||||
type
|
type
|
||||||
ChannelsRoles {.pure.} = enum
|
ChannelsRoles {.pure.} = enum
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
import std/wrapnils
|
import std/wrapnils
|
||||||
import ../../../status/chat
|
import ../../../status/chat/chat
|
||||||
import ../../../signals/types
|
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type ChatItemView* = ref object of QObject
|
type ChatItemView* = ref object of QObject
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import NimQml, Tables
|
import NimQml, Tables
|
||||||
import ../../../status/chat
|
import ../../../status/chat
|
||||||
import ../../../signals/types
|
import ../../../status/chat/[message,stickers]
|
||||||
|
|
||||||
type
|
type
|
||||||
ChatMessageRoles {.pure.} = enum
|
ChatMessageRoles {.pure.} = enum
|
||||||
|
@ -19,19 +19,17 @@ type
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
ChatMessageList* = ref object of QAbstractListModel
|
ChatMessageList* = ref object of QAbstractListModel
|
||||||
messages*: seq[ChatMessage]
|
messages*: seq[Message]
|
||||||
|
|
||||||
proc delete(self: ChatMessageList) =
|
proc delete(self: ChatMessageList) =
|
||||||
self.QAbstractListModel.delete
|
self.QAbstractListModel.delete
|
||||||
for message in self.messages:
|
|
||||||
message.delete
|
|
||||||
self.messages = @[]
|
self.messages = @[]
|
||||||
|
|
||||||
proc setup(self: ChatMessageList) =
|
proc setup(self: ChatMessageList) =
|
||||||
self.QAbstractListModel.setup
|
self.QAbstractListModel.setup
|
||||||
|
|
||||||
proc chatIdentifier(self: ChatMessageList, chatId:string): ChatMessage =
|
proc chatIdentifier(self: ChatMessageList, chatId:string): Message =
|
||||||
result = newChatMessage();
|
result = Message()
|
||||||
result.contentType = ContentType.ChatIdentifier;
|
result.contentType = ContentType.ChatIdentifier;
|
||||||
result.chatId = chatId
|
result.chatId = chatId
|
||||||
|
|
||||||
|
@ -44,7 +42,7 @@ QtObject:
|
||||||
method rowCount(self: ChatMessageList, index: QModelIndex = nil): int =
|
method rowCount(self: ChatMessageList, index: QModelIndex = nil): int =
|
||||||
return self.messages.len
|
return self.messages.len
|
||||||
|
|
||||||
proc sectionIdentifier(message: ChatMessage): string =
|
proc sectionIdentifier(message: Message): string =
|
||||||
result = message.fromAuthor
|
result = message.fromAuthor
|
||||||
# Force section change, because group status messages are sent with the
|
# Force section change, because group status messages are sent with the
|
||||||
# same fromAuthor, and ends up causing the header to not be shown
|
# same fromAuthor, and ends up causing the header to not be shown
|
||||||
|
@ -59,14 +57,14 @@ QtObject:
|
||||||
let message = self.messages[index.row]
|
let message = self.messages[index.row]
|
||||||
let chatMessageRole = role.ChatMessageRoles
|
let chatMessageRole = role.ChatMessageRoles
|
||||||
case chatMessageRole:
|
case chatMessageRole:
|
||||||
of ChatMessageRoles.UserName: result = newQVariant(message.userName)
|
of ChatMessageRoles.UserName: result = newQVariant(message.alias)
|
||||||
of ChatMessageRoles.Message: result = newQVariant(message.message)
|
of ChatMessageRoles.Message: result = newQVariant(message.text)
|
||||||
of ChatMessageRoles.Timestamp: result = newQVariant(message.timestamp)
|
of ChatMessageRoles.Timestamp: result = newQVariant(message.timestamp)
|
||||||
of ChatMessageRoles.Clock: result = newQVariant($message.clock)
|
of ChatMessageRoles.Clock: result = newQVariant($message.clock)
|
||||||
of ChatMessageRoles.Identicon: result = newQVariant(message.identicon)
|
of ChatMessageRoles.Identicon: result = newQVariant(message.identicon)
|
||||||
of ChatMessageRoles.IsCurrentUser: result = newQVariant(message.isCurrentUser)
|
of ChatMessageRoles.IsCurrentUser: result = newQVariant(message.isCurrentUser)
|
||||||
of ChatMessageRoles.ContentType: result = newQVariant(message.contentType.int)
|
of ChatMessageRoles.ContentType: result = newQVariant(message.contentType.int)
|
||||||
of ChatMessageRoles.Sticker: result = newQVariant(message.sticker)
|
of ChatMessageRoles.Sticker: result = newQVariant(message.stickerHash.decodeContentHash())
|
||||||
of ChatMessageRoles.FromAuthor: result = newQVariant(message.fromAuthor)
|
of ChatMessageRoles.FromAuthor: result = newQVariant(message.fromAuthor)
|
||||||
of ChatMessageRoles.ChatId: result = newQVariant(message.chatId)
|
of ChatMessageRoles.ChatId: result = newQVariant(message.chatId)
|
||||||
of ChatMessageRoles.SectionIdentifier: result = newQVariant(sectionIdentifier(message))
|
of ChatMessageRoles.SectionIdentifier: result = newQVariant(sectionIdentifier(message))
|
||||||
|
@ -87,12 +85,12 @@ QtObject:
|
||||||
ChatMessageRoles.SectionIdentifier.int: "sectionIdentifier"
|
ChatMessageRoles.SectionIdentifier.int: "sectionIdentifier"
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
proc add*(self: ChatMessageList, message: ChatMessage) =
|
proc add*(self: ChatMessageList, message: Message) =
|
||||||
self.beginInsertRows(newQModelIndex(), self.messages.len, self.messages.len)
|
self.beginInsertRows(newQModelIndex(), self.messages.len, self.messages.len)
|
||||||
self.messages.add(message)
|
self.messages.add(message)
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
|
|
||||||
proc add*(self: ChatMessageList, messages: seq[ChatMessage]) =
|
proc add*(self: ChatMessageList, messages: seq[Message]) =
|
||||||
self.beginInsertRows(newQModelIndex(), self.messages.len, self.messages.len)
|
self.beginInsertRows(newQModelIndex(), self.messages.len, self.messages.len)
|
||||||
for message in messages:
|
for message in messages:
|
||||||
self.messages.add(message)
|
self.messages.add(message)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import types
|
import types
|
||||||
import ../status/libstatus/accounts as status_accounts
|
import ../status/libstatus/accounts as status_accounts
|
||||||
|
import ../status/chat/[chat, message]
|
||||||
import random
|
import random
|
||||||
|
|
||||||
proc toMessage*(jsonMsg: JsonNode): Message
|
proc toMessage*(jsonMsg: JsonNode): Message
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import chronicles
|
import chronicles
|
||||||
import ../status/libstatus/types
|
import ../status/libstatus/types
|
||||||
|
import ../status/chat/[chat, message]
|
||||||
import json_serialization
|
import json_serialization
|
||||||
|
|
||||||
type SignalSubscriber* = ref object of RootObj
|
type SignalSubscriber* = ref object of RootObj
|
||||||
|
@ -17,74 +18,10 @@ type NodeSignal* = ref object of Signal
|
||||||
type WalletSignal* = ref object of Signal
|
type WalletSignal* = ref object of Signal
|
||||||
content*: string
|
content*: string
|
||||||
|
|
||||||
type ContentType* {.pure.} = enum
|
|
||||||
ChatIdentifier = -1,
|
|
||||||
Unknown = 0,
|
|
||||||
Message = 1,
|
|
||||||
Sticker = 2,
|
|
||||||
Status = 3,
|
|
||||||
Emoji = 4,
|
|
||||||
Transaction = 5,
|
|
||||||
Group = 6
|
|
||||||
|
|
||||||
type Message* = object
|
|
||||||
alias*: string
|
|
||||||
chatId*: string
|
|
||||||
clock*: int
|
|
||||||
# commandParameters*: # ???
|
|
||||||
contentType*: ContentType # ???
|
|
||||||
ensName*: string # ???
|
|
||||||
fromAuthor*: string
|
|
||||||
id*: string
|
|
||||||
identicon*: string
|
|
||||||
lineCount*: int
|
|
||||||
localChatId*: string
|
|
||||||
messageType*: string # ???
|
|
||||||
# parsedText: # ???
|
|
||||||
# quotedMessage: # ???
|
|
||||||
replace*: string # ???
|
|
||||||
responseTo*: string # ???
|
|
||||||
rtl*: bool # ???
|
|
||||||
seen*: bool
|
|
||||||
# sticker: # ???
|
|
||||||
text*: string
|
|
||||||
timestamp*: string
|
|
||||||
whisperTimestamp*: string
|
|
||||||
isCurrentUser*: bool
|
|
||||||
stickerHash*: string
|
|
||||||
|
|
||||||
# Override this method
|
# Override this method
|
||||||
method onSignal*(self: SignalSubscriber, data: Signal) {.base.} =
|
method onSignal*(self: SignalSubscriber, data: Signal) {.base.} =
|
||||||
error "onSignal must be overriden in controller. Signal is unhandled"
|
error "onSignal must be overriden in controller. Signal is unhandled"
|
||||||
|
|
||||||
type ChatType* {.pure.}= enum
|
|
||||||
Unknown = 0,
|
|
||||||
OneToOne = 1,
|
|
||||||
Public = 2,
|
|
||||||
PrivateGroupChat = 3
|
|
||||||
|
|
||||||
proc isOneToOne*(self: ChatType): bool = self == ChatType.OneToOne
|
|
||||||
|
|
||||||
type ChatMember* = object
|
|
||||||
admin*: bool
|
|
||||||
id*: string
|
|
||||||
joined*: bool
|
|
||||||
|
|
||||||
type Chat* = ref object
|
|
||||||
id*: string # ID is the id of the chat, for public chats it is the name e.g. status, for one-to-one is the hex encoded public key and for group chats is a random uuid appended with the hex encoded pk of the creator of the chat
|
|
||||||
name*: string
|
|
||||||
color*: string
|
|
||||||
identicon*: string
|
|
||||||
active*: bool # indicates whether the chat has been soft deleted
|
|
||||||
chatType*: ChatType
|
|
||||||
timestamp*: int64 # indicates the last time this chat has received/sent a message
|
|
||||||
lastClockValue*: int64 # indicates the last clock value to be used when sending messages
|
|
||||||
deletedAtClockValue*: int64 # indicates the clock value at time of deletion, messages with lower clock value of this should be discarded
|
|
||||||
unviewedMessagesCount*: int
|
|
||||||
lastMessage*: Message
|
|
||||||
members*: seq[ChatMember]
|
|
||||||
# membershipUpdateEvents # ?
|
|
||||||
|
|
||||||
type MessageSignal* = ref object of Signal
|
type MessageSignal* = ref object of Signal
|
||||||
messages*: seq[Message]
|
messages*: seq[Message]
|
||||||
chats*: seq[Chat]
|
chats*: seq[Chat]
|
||||||
|
@ -102,18 +39,3 @@ type WhisperFilterSignal* = ref object of Signal
|
||||||
|
|
||||||
type DiscoverySummarySignal* = ref object of Signal
|
type DiscoverySummarySignal* = ref object of Signal
|
||||||
enodes*: seq[string]
|
enodes*: seq[string]
|
||||||
|
|
||||||
proc findIndexById*(self: seq[Chat], id: string): int =
|
|
||||||
result = -1
|
|
||||||
var idx = -1
|
|
||||||
for item in self:
|
|
||||||
inc idx
|
|
||||||
if(item.id == id):
|
|
||||||
result = idx
|
|
||||||
break
|
|
||||||
|
|
||||||
proc isMember*(self: Chat, pubKey: string): bool =
|
|
||||||
for member in self.members:
|
|
||||||
if member.id == pubKey and member.joined: return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,10 @@ import eventemitter, json
|
||||||
import sequtils
|
import sequtils
|
||||||
import libstatus/chat as status_chat
|
import libstatus/chat as status_chat
|
||||||
import chronicles
|
import chronicles
|
||||||
import ../signals/types
|
import chat/[chat, message]
|
||||||
import ../signals/messages
|
import ../signals/messages
|
||||||
import chat/chat_message
|
|
||||||
import tables
|
import tables
|
||||||
|
|
||||||
export chat_message
|
|
||||||
export Chat
|
|
||||||
|
|
||||||
type
|
type
|
||||||
PushMessageArgs* = ref object of Args
|
PushMessageArgs* = ref object of Args
|
||||||
chats*: seq[Chat]
|
chats*: seq[Chat]
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
import message
|
||||||
|
|
||||||
|
type ChatType* {.pure.}= enum
|
||||||
|
Unknown = 0,
|
||||||
|
OneToOne = 1,
|
||||||
|
Public = 2,
|
||||||
|
PrivateGroupChat = 3
|
||||||
|
|
||||||
|
proc isOneToOne*(self: ChatType): bool = self == ChatType.OneToOne
|
||||||
|
|
||||||
|
type ChatMember* = object
|
||||||
|
admin*: bool
|
||||||
|
id*: string
|
||||||
|
joined*: bool
|
||||||
|
|
||||||
|
type Chat* = ref object
|
||||||
|
id*: string # ID is the id of the chat, for public chats it is the name e.g. status, for one-to-one is the hex encoded public key and for group chats is a random uuid appended with the hex encoded pk of the creator of the chat
|
||||||
|
name*: string
|
||||||
|
color*: string
|
||||||
|
identicon*: string
|
||||||
|
active*: bool # indicates whether the chat has been soft deleted
|
||||||
|
chatType*: ChatType
|
||||||
|
timestamp*: int64 # indicates the last time this chat has received/sent a message
|
||||||
|
lastClockValue*: int64 # indicates the last clock value to be used when sending messages
|
||||||
|
deletedAtClockValue*: int64 # indicates the clock value at time of deletion, messages with lower clock value of this should be discarded
|
||||||
|
unviewedMessagesCount*: int
|
||||||
|
lastMessage*: Message
|
||||||
|
members*: seq[ChatMember]
|
||||||
|
# membershipUpdateEvents # ?
|
||||||
|
|
||||||
|
proc findIndexById*(self: seq[Chat], id: string): int =
|
||||||
|
result = -1
|
||||||
|
var idx = -1
|
||||||
|
for item in self:
|
||||||
|
inc idx
|
||||||
|
if(item.id == id):
|
||||||
|
result = idx
|
||||||
|
break
|
||||||
|
|
||||||
|
proc isMember*(self: Chat, pubKey: string): bool =
|
||||||
|
for member in self.members:
|
||||||
|
if member.id == pubKey and member.joined: return true
|
||||||
|
return false
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
import json
|
|
||||||
import ../../signals/types
|
|
||||||
import stickers
|
|
||||||
|
|
||||||
type ChatMessage* = ref object
|
|
||||||
userName*: string
|
|
||||||
message*: string
|
|
||||||
fromAuthor*: string
|
|
||||||
timestamp*: string
|
|
||||||
clock*: int
|
|
||||||
identicon*: string
|
|
||||||
isCurrentUser*: bool
|
|
||||||
contentType*: ContentType
|
|
||||||
sticker*: string
|
|
||||||
chatId*: string
|
|
||||||
|
|
||||||
proc delete*(self: ChatMessage) =
|
|
||||||
discard
|
|
||||||
|
|
||||||
proc newChatMessage*(): ChatMessage =
|
|
||||||
result = ChatMessage()
|
|
||||||
result.userName = ""
|
|
||||||
result.message = ""
|
|
||||||
result.fromAuthor = ""
|
|
||||||
result.clock = 0
|
|
||||||
result.timestamp = "0"
|
|
||||||
result.identicon = ""
|
|
||||||
result.isCurrentUser = false
|
|
||||||
result.contentType = ContentType.Unknown
|
|
||||||
result.sticker = ""
|
|
||||||
result.chatId = ""
|
|
||||||
|
|
||||||
proc toChatMessage*(payload: JsonNode): ChatMessage =
|
|
||||||
result = ChatMessage(
|
|
||||||
chatId: payload["localChatId"].str,
|
|
||||||
fromAuthor: payload["from"].getStr,
|
|
||||||
userName: payload["alias"].str,
|
|
||||||
message: payload["text"].str,
|
|
||||||
timestamp: $payload["timestamp"],
|
|
||||||
clock: payload["clock"].getInt,
|
|
||||||
identicon: payload["identicon"].str,
|
|
||||||
isCurrentUser: payload{"outgoingStatus"}.getStr == "sending",
|
|
||||||
contentType: ContentType(payload["contentType"].getInt),
|
|
||||||
sticker: "" # TODO: implement when implementing stickers from user
|
|
||||||
)
|
|
||||||
|
|
||||||
proc toChatMessage*(message: Message): ChatMessage =
|
|
||||||
result = ChatMessage(
|
|
||||||
chatId: message.chatId,
|
|
||||||
userName: message.alias,
|
|
||||||
clock: message.clock,
|
|
||||||
fromAuthor: message.fromAuthor,
|
|
||||||
message: message.text,
|
|
||||||
timestamp: message.timestamp,
|
|
||||||
identicon: message.identicon,
|
|
||||||
isCurrentUser: message.isCurrentUser,
|
|
||||||
contentType: message.contentType,
|
|
||||||
sticker: message.stickerHash.decodeContentHash()
|
|
||||||
)
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
type ContentType* {.pure.} = enum
|
||||||
|
ChatIdentifier = -1,
|
||||||
|
Unknown = 0,
|
||||||
|
Message = 1,
|
||||||
|
Sticker = 2,
|
||||||
|
Status = 3,
|
||||||
|
Emoji = 4,
|
||||||
|
Transaction = 5,
|
||||||
|
Group = 6
|
||||||
|
|
||||||
|
type Message* = object
|
||||||
|
alias*: string
|
||||||
|
chatId*: string
|
||||||
|
clock*: int
|
||||||
|
# commandParameters*: # ???
|
||||||
|
contentType*: ContentType # ???
|
||||||
|
ensName*: string # ???
|
||||||
|
fromAuthor*: string
|
||||||
|
id*: string
|
||||||
|
identicon*: string
|
||||||
|
lineCount*: int
|
||||||
|
localChatId*: string
|
||||||
|
messageType*: string # ???
|
||||||
|
# parsedText: # ???
|
||||||
|
# quotedMessage: # ???
|
||||||
|
replace*: string # ???
|
||||||
|
responseTo*: string # ???
|
||||||
|
rtl*: bool # ???
|
||||||
|
seen*: bool
|
||||||
|
sticker*: string
|
||||||
|
text*: string
|
||||||
|
timestamp*: string
|
||||||
|
whisperTimestamp*: string
|
||||||
|
isCurrentUser*: bool
|
||||||
|
stickerHash*: string
|
|
@ -4,7 +4,7 @@ import utils
|
||||||
import times
|
import times
|
||||||
import strutils
|
import strutils
|
||||||
import chronicles
|
import chronicles
|
||||||
import ../../signals/types
|
import ../chat/[chat, message]
|
||||||
import ../../signals/messages
|
import ../../signals/messages
|
||||||
|
|
||||||
proc buildFilter*(chatId: string, filterId: string = "", symKeyId: string = "", oneToOne: bool = false, identity: string = "", topic: string = "", discovery: bool = false, negotiated: bool = false, listen: bool = true):JsonNode =
|
proc buildFilter*(chatId: string, filterId: string = "", symKeyId: string = "", oneToOne: bool = false, identity: string = "", topic: string = "", discovery: bool = false, negotiated: bool = false, listen: bool = true):JsonNode =
|
||||||
|
|
Loading…
Reference in New Issue