refactor: chats view
Extract private groups, reactions, stickers and transactions procs to individual view files
This commit is contained in:
parent
3951d0fff5
commit
ae83818eed
|
@ -122,19 +122,19 @@ message object:
|
|||
|
||||
*chatsModel.joinChat(channel: string, chatTypeInt: int)* - join a channel
|
||||
|
||||
*chatsModel.joinGroup()* - confirm joining group
|
||||
*chatsModel.groups.join()* - confirm joining group
|
||||
|
||||
*chatsModel.leaveActiveChat()* - leave currently active channel
|
||||
|
||||
*chatsModel.clearChatHistory()* - clear chat history of currently active channel
|
||||
|
||||
*chatsModel.renameGroup(newName: string)* - rename current active group
|
||||
*chatsModel.groups.rename(newName: string)* - rename current active group
|
||||
|
||||
*chatsModel.blockContact(id: string)* - block contact
|
||||
|
||||
*chatsModel.addContact(id: string)*
|
||||
|
||||
*chatsModel.createGroup(groupName: string, pubKeys: string)*
|
||||
*chatsModel.groups.create(groupName: string, pubKeys: string)*
|
||||
|
||||
**TODO**: document all exposed APIs to QML
|
||||
|
||||
|
|
|
@ -4,9 +4,8 @@ import ../../status/mailservers as mailserver_model
|
|||
import ../../status/messages as messages_model
|
||||
import ../../status/signals/types
|
||||
import ../../status/libstatus/types as status_types
|
||||
import ../../status/libstatus/settings as status_settings
|
||||
import ../../status/[chat, contacts, status, wallet, stickers]
|
||||
import view, views/channels_list, views/message_list
|
||||
import view, views/channels_list, views/message_list, views/reactions, views/stickers as stickers_view
|
||||
import ../../eventemitter
|
||||
|
||||
logScope:
|
||||
|
@ -38,11 +37,10 @@ proc init*(self: ChatController) =
|
|||
self.status.mailservers.init()
|
||||
self.status.chat.init()
|
||||
self.status.stickers.init()
|
||||
let pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||
self.view.pubKey = pubKey
|
||||
self.view.reactions.init()
|
||||
|
||||
let recentStickers = self.status.stickers.getRecentStickers()
|
||||
for sticker in recentStickers:
|
||||
self.view.addRecentStickerToList(sticker)
|
||||
self.view.stickers.addRecentStickerToList(sticker)
|
||||
self.status.stickers.addStickerToRecent(sticker)
|
||||
self.view.obtainAvailableStickerPacks()
|
||||
self.view.stickers.obtainAvailableStickerPacks()
|
||||
|
|
|
@ -6,7 +6,7 @@ proc handleChatEvents(self: ChatController) =
|
|||
self.view.pushMessages(MsgsLoadedArgs(e).messages)
|
||||
# Display emoji reactions
|
||||
self.status.events.on("reactionsLoaded") do(e:Args):
|
||||
self.view.pushReactions(ReactionsLoadedArgs(e).reactions)
|
||||
self.view.reactions.push(ReactionsLoadedArgs(e).reactions)
|
||||
|
||||
self.status.events.on("contactUpdate") do(e: Args):
|
||||
var evArgs = ContactUpdateArgs(e)
|
||||
|
@ -23,7 +23,7 @@ proc handleChatEvents(self: ChatController) =
|
|||
if (message.replace != ""):
|
||||
# Delete the message taht this message replaces
|
||||
self.view.deleteMessage(message.chatId, message.replace)
|
||||
self.view.pushReactions(evArgs.emojiReactions)
|
||||
self.view.reactions.push(evArgs.emojiReactions)
|
||||
|
||||
self.status.events.on("channelUpdate") do(e: Args):
|
||||
var evArgs = ChatUpdateArgs(e)
|
||||
|
@ -82,11 +82,11 @@ proc handleChatEvents(self: ChatController) =
|
|||
|
||||
self.status.events.on(PendingTransactionType.BuyStickerPack.confirmed) do(e: Args):
|
||||
var tx = TransactionMinedArgs(e)
|
||||
self.view.transactionCompleted(tx.success, tx.transactionHash, tx.revertReason)
|
||||
self.view.stickers.transactionCompleted(tx.success, tx.transactionHash, tx.revertReason)
|
||||
if tx.success:
|
||||
self.view.installStickerPack(tx.data.parseInt)
|
||||
self.view.stickers.install(tx.data.parseInt)
|
||||
else:
|
||||
self.view.resetStickerPackBuyAttempt(tx.data.parseInt)
|
||||
self.view.stickers.resetBuyAttempt(tx.data.parseInt)
|
||||
|
||||
proc handleMailserverEvents(self: ChatController) =
|
||||
self.status.events.on("mailserverTopics") do(e: Args):
|
||||
|
|
|
@ -1,25 +1,19 @@
|
|||
import NimQml, Tables, json, sequtils, chronicles, times, re, sugar, strutils, os, sets, strformat
|
||||
import NimQml, Tables, json, sequtils, chronicles, times, re, sugar, strutils, os, strformat
|
||||
import ../../status/status
|
||||
import ../../status/mailservers
|
||||
import ../../status/stickers
|
||||
import ../../status/libstatus/accounts/constants
|
||||
import ../../status/libstatus/mailservers as status_mailservers
|
||||
import ../../status/accounts as status_accounts
|
||||
import ../../status/chat as status_chat
|
||||
import ../../status/messages as status_messages
|
||||
import ../../status/libstatus/wallet as status_wallet
|
||||
import ../../status/libstatus/stickers as status_stickers
|
||||
import ../../status/contacts as status_contacts
|
||||
import ../../status/ens as status_ens
|
||||
import ../../status/chat/[chat, message]
|
||||
import ../../status/wallet
|
||||
import ../../status/libstatus/types
|
||||
import ../../status/profile/profile
|
||||
import web3/[conversions, ethtypes]
|
||||
import ../../status/threads
|
||||
import views/channels_list, views/message_list, views/chat_item, views/sticker_pack_list, views/sticker_list, views/suggestions_list
|
||||
import views/[channels_list, message_list, chat_item, suggestions_list, reactions, stickers, groups, transactions]
|
||||
import json_serialization
|
||||
import ../../status/libstatus/utils
|
||||
|
||||
logScope:
|
||||
topics = "chats-view"
|
||||
|
@ -32,11 +26,12 @@ QtObject:
|
|||
currentSuggestions*: SuggestionsList
|
||||
callResult: string
|
||||
messageList*: Table[string, ChatMessageList]
|
||||
reactions*: ReactionView
|
||||
stickers*: StickersView
|
||||
groups*: GroupsView
|
||||
transactions*: TransactionsView
|
||||
activeChannel*: ChatItemView
|
||||
stickerPacks*: StickerPackList
|
||||
recentStickers*: StickerList
|
||||
replyTo: string
|
||||
pubKey*: string
|
||||
channelOpenTime*: Table[string, int64]
|
||||
connected: bool
|
||||
unreadMessageCnt: int
|
||||
|
@ -51,6 +46,10 @@ QtObject:
|
|||
self.currentSuggestions.delete
|
||||
for msg in self.messageList.values:
|
||||
msg.delete
|
||||
self.reactions.delete
|
||||
self.stickers.delete
|
||||
self.groups.delete
|
||||
self.transactions.delete
|
||||
self.messageList = initTable[string, ChatMessageList]()
|
||||
self.channelOpenTime = initTable[string, int64]()
|
||||
self.QAbstractListModel.delete
|
||||
|
@ -63,10 +62,11 @@ QtObject:
|
|||
result.activeChannel = newChatItemView(status)
|
||||
result.currentSuggestions = newSuggestionsList()
|
||||
result.messageList = initTable[string, ChatMessageList]()
|
||||
result.stickerPacks = newStickerPackList()
|
||||
result.recentStickers = newStickerList()
|
||||
result.reactions = newReactionView(status, result.messageList.addr, result.activeChannel)
|
||||
result.stickers = newStickersView(status, result.activeChannel)
|
||||
result.groups = newGroupsView(status,result.activeChannel)
|
||||
result.transactions = newTransactionsView(status)
|
||||
result.unreadMessageCnt = 0
|
||||
result.pubKey = ""
|
||||
result.loadingMessages = false
|
||||
result.setup()
|
||||
|
||||
|
@ -91,74 +91,6 @@ QtObject:
|
|||
self.oldestMessageTimestamp = times.toUnix(times.getTime())
|
||||
self.oldestMessageTimestampChanged()
|
||||
|
||||
proc addStickerPackToList*(self: ChatsView, stickerPack: StickerPack, isInstalled, isBought, isPending: bool) =
|
||||
self.stickerPacks.addStickerPackToList(stickerPack, newStickerList(stickerPack.stickers), isInstalled, isBought, isPending)
|
||||
|
||||
proc getStickerPackList(self: ChatsView): QVariant {.slot.} =
|
||||
newQVariant(self.stickerPacks)
|
||||
|
||||
QtProperty[QVariant] stickerPacks:
|
||||
read = getStickerPackList
|
||||
|
||||
proc buyPackGasEstimate*(self: ChatsView, packId: int, address: string, price: string): int {.slot.} =
|
||||
var success: bool
|
||||
result = self.status.stickers.estimateGas(packId, address, price, success)
|
||||
if not success:
|
||||
result = 325000
|
||||
|
||||
proc transactionWasSent*(self: ChatsView, txResult: string) {.signal.}
|
||||
proc transactionCompleted*(self: ChatsView, success: bool, txHash: string, revertReason: string = "") {.signal.}
|
||||
|
||||
proc buyStickerPack*(self: ChatsView, packId: int, address: string, price: string, gas: string, gasPrice: string, password: string): string {.slot.} =
|
||||
var success: bool
|
||||
let response = self.status.stickers.buyPack(packId, address, price, gas, gasPrice, password, success)
|
||||
# TODO:
|
||||
# check if response["error"] is not null and handle the error
|
||||
result = $(%* { "result": %response, "success": %success })
|
||||
if success:
|
||||
self.stickerPacks.updateStickerPackInList(packId, false, true)
|
||||
self.transactionWasSent(response)
|
||||
|
||||
proc obtainAvailableStickerPacks*(self: ChatsView) =
|
||||
spawnAndSend(self, "setAvailableStickerPacks") do:
|
||||
let availableStickerPacks = status_stickers.getAvailableStickerPacks()
|
||||
var packs: seq[StickerPack] = @[]
|
||||
for packId, stickerPack in availableStickerPacks.pairs:
|
||||
packs.add(stickerPack)
|
||||
$(%*(packs))
|
||||
|
||||
proc stickerPacksLoaded*(self: ChatsView) {.signal.}
|
||||
|
||||
proc installedStickerPacksUpdated*(self: ChatsView) {.signal.}
|
||||
|
||||
proc recentStickersUpdated*(self: ChatsView) {.signal.}
|
||||
|
||||
proc setAvailableStickerPacks*(self: ChatsView, availableStickersJSON: string) {.slot.} =
|
||||
let
|
||||
accounts = status_wallet.getWalletAccounts() # TODO: make generic
|
||||
installedStickerPacks = self.status.stickers.getInstalledStickerPacks()
|
||||
var
|
||||
purchasedStickerPacks: seq[int]
|
||||
for account in accounts:
|
||||
let address = parseAddress(account.address)
|
||||
purchasedStickerPacks = self.status.stickers.getPurchasedStickerPacks(address)
|
||||
let availableStickers = JSON.decode($availableStickersJSON, seq[StickerPack])
|
||||
|
||||
let pendingTransactions = status_wallet.getPendingTransactions().parseJson["result"]
|
||||
var pendingStickerPacks = initHashSet[int]()
|
||||
for trx in pendingTransactions.getElems():
|
||||
if trx["type"].getStr == $PendingTransactionType.BuyStickerPack:
|
||||
pendingStickerPacks.incl(trx["data"].getStr.parseInt)
|
||||
|
||||
for stickerPack in availableStickers:
|
||||
let isInstalled = installedStickerPacks.hasKey(stickerPack.id)
|
||||
let isBought = purchasedStickerPacks.contains(stickerPack.id)
|
||||
let isPending = pendingStickerPacks.contains(stickerPack.id) and not isBought
|
||||
self.status.stickers.availableStickerPacks[stickerPack.id] = stickerPack
|
||||
self.addStickerPackToList(stickerPack, isInstalled, isBought, isPending)
|
||||
self.stickerPacksLoaded()
|
||||
self.installedStickerPacksUpdated()
|
||||
|
||||
proc getChatsList(self: ChatsView): QVariant {.slot.} =
|
||||
newQVariant(self.chats)
|
||||
|
||||
|
@ -272,36 +204,6 @@ QtObject:
|
|||
write = setActiveChannelByIndex
|
||||
notify = activeChannelChanged
|
||||
|
||||
proc getNumInstalledStickerPacks(self: ChatsView): QVariant {.slot.} =
|
||||
newQVariant(self.status.stickers.installedStickerPacks.len)
|
||||
|
||||
QtProperty[QVariant] numInstalledStickerPacks:
|
||||
read = getNumInstalledStickerPacks
|
||||
notify = installedStickerPacksUpdated
|
||||
|
||||
proc installStickerPack*(self: ChatsView, packId: int) {.slot.} =
|
||||
self.status.stickers.installStickerPack(packId)
|
||||
self.stickerPacks.updateStickerPackInList(packId, true, false)
|
||||
self.installedStickerPacksUpdated()
|
||||
|
||||
proc resetStickerPackBuyAttempt*(self: ChatsView, packId: int) {.slot.} =
|
||||
self.stickerPacks.updateStickerPackInList(packId, false, false)
|
||||
|
||||
proc uninstallStickerPack*(self: ChatsView, packId: int) {.slot.} =
|
||||
self.status.stickers.uninstallStickerPack(packId)
|
||||
self.status.stickers.removeRecentStickers(packId)
|
||||
self.stickerPacks.updateStickerPackInList(packId, false, false)
|
||||
self.recentStickers.removeStickersFromList(packId)
|
||||
self.installedStickerPacksUpdated()
|
||||
self.recentStickersUpdated()
|
||||
|
||||
proc getRecentStickerList*(self: ChatsView): QVariant {.slot.} =
|
||||
result = newQVariant(self.recentStickers)
|
||||
|
||||
QtProperty[QVariant] recentStickers:
|
||||
read = getRecentStickerList
|
||||
notify = recentStickersUpdated
|
||||
|
||||
proc setActiveChannel*(self: ChatsView, channel: string) {.slot.} =
|
||||
if(channel == ""): return
|
||||
self.activeChannel.setChatItem(self.chats.getChannel(self.chats.chats.findIndexById(channel)))
|
||||
|
@ -317,7 +219,6 @@ QtObject:
|
|||
write = setActiveChannel
|
||||
notify = activeChannelChanged
|
||||
|
||||
|
||||
proc getCurrentSuggestions(self: ChatsView): QVariant {.slot.} =
|
||||
return newQVariant(self.currentSuggestions)
|
||||
|
||||
|
@ -366,48 +267,6 @@ QtObject:
|
|||
discard self.status.chat.markMessagesSeen(msg.chatId, @[msg.id])
|
||||
self.newMessagePushed()
|
||||
|
||||
proc messageEmojiReactionId(self: ChatsView, chatId: string, messageId: string, emojiId: int): string =
|
||||
if (self.messageList[chatId].getReactions(messageId) == "") :
|
||||
return ""
|
||||
|
||||
let oldReactions = parseJson(self.messageList[chatId].getReactions(messageId))
|
||||
|
||||
for pair in oldReactions.pairs:
|
||||
if (pair[1]["emojiId"].getInt == emojiId and pair[1]["from"].getStr == self.pubKey):
|
||||
return pair[0]
|
||||
return ""
|
||||
|
||||
proc toggleEmojiReaction*(self: ChatsView, messageId: string, emojiId: int) {.slot.} =
|
||||
let emojiReactionId = self.messageEmojiReactionId(self.activeChannel.id, messageId, emojiId)
|
||||
if (emojiReactionId == ""):
|
||||
self.status.chat.addEmojiReaction(self.activeChannel.id, messageId, emojiId)
|
||||
else:
|
||||
self.status.chat.removeEmojiReaction(emojiReactionId)
|
||||
|
||||
proc pushReactions*(self:ChatsView, reactions: var seq[Reaction]) =
|
||||
let t = reactions.len
|
||||
for reaction in reactions.mitems:
|
||||
let messageList = self.messageList[reaction.chatId]
|
||||
var emojiReactions = messageList.getReactions(reaction.messageId)
|
||||
var oldReactions: JsonNode
|
||||
if (emojiReactions == "") :
|
||||
oldReactions = %*{}
|
||||
else:
|
||||
oldReactions = parseJson(emojiReactions)
|
||||
|
||||
if (oldReactions.hasKey(reaction.id)):
|
||||
if (reaction.retracted):
|
||||
# Remove the reaction
|
||||
oldReactions.delete(reaction.id)
|
||||
messageList.setMessageReactions(reaction.messageId, $oldReactions)
|
||||
continue
|
||||
|
||||
oldReactions[reaction.id] = %* {
|
||||
"from": reaction.fromAccount,
|
||||
"emojiId": reaction.emojiId
|
||||
}
|
||||
messageList.setMessageReactions(reaction.messageId, $oldReactions)
|
||||
|
||||
|
||||
proc updateUsernames*(self:ChatsView, contacts: seq[Profile]) =
|
||||
if contacts.len > 0:
|
||||
|
@ -448,10 +307,6 @@ QtObject:
|
|||
proc pushChatItem*(self: ChatsView, chatItem: Chat) =
|
||||
discard self.chats.addChatItemToList(chatItem)
|
||||
self.messagePushed()
|
||||
|
||||
proc addRecentStickerToList*(self: ChatsView, sticker: Sticker) =
|
||||
self.recentStickers.addStickerToList(sticker)
|
||||
self.recentStickersUpdated()
|
||||
|
||||
proc copyToClipboard*(self: ChatsView, content: string) {.slot.} =
|
||||
setClipBoardText(content)
|
||||
|
@ -459,11 +314,6 @@ QtObject:
|
|||
proc getLinkPreviewData*(self: ChatsView, link: string): string {.slot.} =
|
||||
result = $self.status.chat.getLinkPreviewData(link)
|
||||
|
||||
proc sendSticker*(self: ChatsView, hash: string, pack: int) {.slot.} =
|
||||
let sticker = Sticker(hash: hash, packId: pack)
|
||||
self.addRecentStickerToList(sticker)
|
||||
self.status.chat.sendSticker(self.activeChannel.id, sticker)
|
||||
|
||||
proc joinChat*(self: ChatsView, channel: string, chatTypeInt: int): int {.slot.} =
|
||||
self.status.chat.join(channel, ChatType(chatTypeInt))
|
||||
self.setActiveChannel(channel)
|
||||
|
@ -472,13 +322,6 @@ QtObject:
|
|||
self.status.chat.join(channel, ChatType.OneToOne, ensName=status_ens.addDomain(ensName))
|
||||
self.setActiveChannel(channel)
|
||||
|
||||
proc chatGroupJoined(self: ChatsView, channel: string) {.signal.}
|
||||
|
||||
proc joinGroup*(self: ChatsView) {.slot.} =
|
||||
self.status.chat.confirmJoiningGroup(self.activeChannel.id)
|
||||
self.activeChannel.membershipChanged()
|
||||
self.chatGroupJoined(self.activeChannel.id)
|
||||
|
||||
proc messagesLoaded*(self: ChatsView) {.signal.}
|
||||
|
||||
proc loadMoreMessages*(self: ChatsView) {.slot.} =
|
||||
|
@ -580,23 +423,6 @@ QtObject:
|
|||
proc deleteMessage*(self: ChatsView, channelId: string, messageId: string) =
|
||||
self.messageList[channelId].deleteMessage(messageId)
|
||||
|
||||
proc renameGroup*(self: ChatsView, newName: string) {.slot.} =
|
||||
self.status.chat.renameGroup(self.activeChannel.id, newName)
|
||||
|
||||
proc createGroup*(self: ChatsView, groupName: string, pubKeys: string) {.slot.} =
|
||||
let pubKeysSeq = map(parseJson(pubKeys).getElems(), proc(x:JsonNode):string = x.getStr)
|
||||
self.status.chat.createGroup(groupName, pubKeysSeq)
|
||||
|
||||
proc addGroupMembers*(self: ChatsView, chatId: string, pubKeys: string) {.slot.} =
|
||||
let pubKeysSeq = map(parseJson(pubKeys).getElems(), proc(x:JsonNode):string = x.getStr)
|
||||
self.status.chat.addGroupMembers(chatId, pubKeysSeq)
|
||||
|
||||
proc kickGroupMember*(self: ChatsView, chatId: string, pubKey: string) {.slot.} =
|
||||
self.status.chat.kickGroupMember(chatId, pubKey)
|
||||
|
||||
proc makeAdmin*(self: ChatsView, chatId: string, pubKey: string) {.slot.} =
|
||||
self.status.chat.makeAdmin(chatId, pubKey)
|
||||
|
||||
proc isEnsVerified*(self: ChatsView, id: string): bool {.slot.} =
|
||||
if id == "": return false
|
||||
let contact = self.status.contacts.getContactByID(id)
|
||||
|
@ -655,19 +481,26 @@ QtObject:
|
|||
if (selectedChannel == nil): return false
|
||||
result = selectedChannel.muted
|
||||
|
||||
### Chat commands functions ###
|
||||
proc acceptRequestAddressForTransaction*(self: ChatsView, messageId: string , address: string) {.slot.} =
|
||||
self.status.chat.acceptRequestAddressForTransaction(messageId, address)
|
||||
proc getReactions*(self: ChatsView): QVariant {.slot.} =
|
||||
newQVariant(self.reactions)
|
||||
|
||||
proc declineRequestAddressForTransaction*(self: ChatsView, messageId: string) {.slot.} =
|
||||
self.status.chat.declineRequestAddressForTransaction(messageId)
|
||||
QtProperty[QVariant] reactions:
|
||||
read = getReactions
|
||||
|
||||
proc declineRequestTransaction*(self: ChatsView, messageId: string) {.slot.} =
|
||||
self.status.chat.declineRequestTransaction(messageId)
|
||||
proc getStickers*(self: ChatsView): QVariant {.slot.} =
|
||||
newQVariant(self.stickers)
|
||||
|
||||
proc requestAddressForTransaction*(self: ChatsView, chatId: string, fromAddress: string, amount: string, tokenAddress: string) {.slot.} =
|
||||
self.status.chat.requestAddressForTransaction(chatId, fromAddress, amount, tokenAddress)
|
||||
|
||||
QtProperty[QVariant] stickers:
|
||||
read = getStickers
|
||||
|
||||
proc requestTransaction*(self: ChatsView, chatId: string, fromAddress: string, amount: string, tokenAddress: string) {.slot.} =
|
||||
self.status.chat.requestTransaction(chatId, fromAddress, amount, tokenAddress)
|
||||
proc getGroups*(self: ChatsView): QVariant {.slot.} =
|
||||
newQVariant(self.groups)
|
||||
|
||||
QtProperty[QVariant] groups:
|
||||
read = getGroups
|
||||
|
||||
proc getTransactions*(self: ChatsView): QVariant {.slot.} =
|
||||
newQVariant(self.transactions)
|
||||
|
||||
QtProperty[QVariant] transactions:
|
||||
read = getTransactions
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
import NimQml, chronicles, sequtils, json
|
||||
import ../../../status/status
|
||||
import chat_item
|
||||
|
||||
logScope:
|
||||
topics = "groups-view"
|
||||
|
||||
QtObject:
|
||||
type GroupsView* = ref object of QObject
|
||||
activeChannel: ChatItemView
|
||||
status: Status
|
||||
|
||||
proc setup(self: GroupsView) =
|
||||
self.QObject.setup
|
||||
|
||||
proc delete*(self: GroupsView) =
|
||||
self.QObject.delete
|
||||
|
||||
proc newGroupsView*(status: Status, activeChannel: ChatItemView): GroupsView =
|
||||
new(result, delete)
|
||||
result = GroupsView()
|
||||
result.status = status
|
||||
result.activeChannel = activeChannel
|
||||
result.setup
|
||||
|
||||
proc groupJoined(self: GroupsView, channel: string) {.signal.}
|
||||
|
||||
proc join*(self: GroupsView) {.slot.} =
|
||||
self.status.chat.confirmJoiningGroup(self.activeChannel.id)
|
||||
self.activeChannel.membershipChanged()
|
||||
self.groupJoined(self.activeChannel.id)
|
||||
|
||||
proc rename*(self: GroupsView, newName: string) {.slot.} =
|
||||
self.status.chat.renameGroup(self.activeChannel.id, newName)
|
||||
|
||||
proc create*(self: GroupsView, groupName: string, pubKeys: string) {.slot.} =
|
||||
let pubKeysSeq = map(parseJson(pubKeys).getElems(), proc(x:JsonNode):string = x.getStr)
|
||||
self.status.chat.createGroup(groupName, pubKeysSeq)
|
||||
|
||||
proc addMembers*(self: GroupsView, chatId: string, pubKeys: string) {.slot.} =
|
||||
let pubKeysSeq = map(parseJson(pubKeys).getElems(), proc(x:JsonNode):string = x.getStr)
|
||||
self.status.chat.addGroupMembers(chatId, pubKeysSeq)
|
||||
|
||||
proc kickMember*(self: GroupsView, chatId: string, pubKey: string) {.slot.} =
|
||||
self.status.chat.kickGroupMember(chatId, pubKey)
|
||||
|
||||
proc makeAdmin*(self: GroupsView, chatId: string, pubKey: string) {.slot.} =
|
||||
self.status.chat.makeAdmin(chatId, pubKey)
|
|
@ -0,0 +1,74 @@
|
|||
import NimQml, tables, json, chronicles
|
||||
import ../../../status/[status, chat/message]
|
||||
import message_list, chat_item
|
||||
import ../../../status/libstatus/settings as status_settings
|
||||
import ../../../status/libstatus/types
|
||||
|
||||
logScope:
|
||||
topics = "reactions-view"
|
||||
|
||||
QtObject:
|
||||
type ReactionView* = ref object of QObject
|
||||
messageList: ptr Table[string, ChatMessageList]
|
||||
activeChannel: ChatItemView
|
||||
status: Status
|
||||
pubKey*: string
|
||||
|
||||
proc setup(self: ReactionView) =
|
||||
self.QObject.setup
|
||||
|
||||
proc delete*(self: ReactionView) =
|
||||
self.QObject.delete
|
||||
|
||||
proc newReactionView*(status: Status, messageList: ptr Table[string, ChatMessageList], activeChannel: ChatItemView): ReactionView =
|
||||
new(result, delete)
|
||||
result = ReactionView()
|
||||
result.messageList = messageList
|
||||
result.status = status
|
||||
result.activeChannel = activeChannel
|
||||
result.setup
|
||||
|
||||
proc init*(self: ReactionView) =
|
||||
self.pubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||
|
||||
proc messageEmojiReactionId(self: ReactionView, chatId: string, messageId: string, emojiId: int): string =
|
||||
if (self.messageList[][chatId].getReactions(messageId) == "") :
|
||||
return ""
|
||||
|
||||
let oldReactions = parseJson(self.messageList[][chatId].getReactions(messageId))
|
||||
|
||||
for pair in oldReactions.pairs:
|
||||
if (pair[1]["emojiId"].getInt == emojiId and pair[1]["from"].getStr == self.pubKey):
|
||||
return pair[0]
|
||||
return ""
|
||||
|
||||
proc toggle*(self: ReactionView, messageId: string, emojiId: int) {.slot.} =
|
||||
let emojiReactionId = self.messageEmojiReactionId(self.activeChannel.id, messageId, emojiId)
|
||||
if (emojiReactionId == ""):
|
||||
self.status.chat.addEmojiReaction(self.activeChannel.id, messageId, emojiId)
|
||||
else:
|
||||
self.status.chat.removeEmojiReaction(emojiReactionId)
|
||||
|
||||
proc push*(self: ReactionView, reactions: var seq[Reaction]) =
|
||||
let t = reactions.len
|
||||
for reaction in reactions.mitems:
|
||||
let messageList = self.messageList[][reaction.chatId]
|
||||
var emojiReactions = messageList.getReactions(reaction.messageId)
|
||||
var oldReactions: JsonNode
|
||||
if (emojiReactions == "") :
|
||||
oldReactions = %*{}
|
||||
else:
|
||||
oldReactions = parseJson(emojiReactions)
|
||||
|
||||
if (oldReactions.hasKey(reaction.id)):
|
||||
if (reaction.retracted):
|
||||
# Remove the reaction
|
||||
oldReactions.delete(reaction.id)
|
||||
messageList.setMessageReactions(reaction.messageId, $oldReactions)
|
||||
continue
|
||||
|
||||
oldReactions[reaction.id] = %* {
|
||||
"from": reaction.fromAccount,
|
||||
"emojiId": reaction.emojiId
|
||||
}
|
||||
messageList.setMessageReactions(reaction.messageId, $oldReactions)
|
|
@ -0,0 +1,140 @@
|
|||
import NimQml, tables, json, chronicles, sets, strutils
|
||||
import ../../../status/[status, stickers, threads]
|
||||
import ../../../status/libstatus/[types, utils]
|
||||
import ../../../status/libstatus/stickers as status_stickers
|
||||
import ../../../status/libstatus/wallet as status_wallet
|
||||
import sticker_pack_list, sticker_list, chat_item
|
||||
import json_serialization
|
||||
|
||||
logScope:
|
||||
topics = "stickers-view"
|
||||
|
||||
QtObject:
|
||||
type StickersView* = ref object of QObject
|
||||
status: Status
|
||||
activeChannel: ChatItemView
|
||||
stickerPacks*: StickerPackList
|
||||
recentStickers*: StickerList
|
||||
|
||||
proc setup(self: StickersView) =
|
||||
self.QObject.setup
|
||||
|
||||
proc delete*(self: StickersView) =
|
||||
self.QObject.delete
|
||||
|
||||
proc newStickersView*(status: Status, activeChannel: ChatItemView): StickersView =
|
||||
new(result, delete)
|
||||
result = StickersView()
|
||||
result.status = status
|
||||
result.stickerPacks = newStickerPackList()
|
||||
result.recentStickers = newStickerList()
|
||||
result.activeChannel = activeChannel
|
||||
result.setup
|
||||
|
||||
proc addStickerPackToList*(self: StickersView, stickerPack: StickerPack, isInstalled, isBought, isPending: bool) =
|
||||
self.stickerPacks.addStickerPackToList(stickerPack, newStickerList(stickerPack.stickers), isInstalled, isBought, isPending)
|
||||
|
||||
proc getStickerPackList(self: StickersView): QVariant {.slot.} =
|
||||
newQVariant(self.stickerPacks)
|
||||
|
||||
QtProperty[QVariant] stickerPacks:
|
||||
read = getStickerPackList
|
||||
|
||||
proc transactionWasSent*(self: StickersView, txResult: string) {.signal.}
|
||||
|
||||
proc transactionCompleted*(self: StickersView, success: bool, txHash: string, revertReason: string = "") {.signal.}
|
||||
|
||||
proc estimate*(self: StickersView, packId: int, address: string, price: string): int {.slot.} =
|
||||
var success: bool
|
||||
result = self.status.stickers.estimateGas(packId, address, price, success)
|
||||
if not success:
|
||||
result = 325000
|
||||
|
||||
proc buy*(self: StickersView, packId: int, address: string, price: string, gas: string, gasPrice: string, password: string): string {.slot.} =
|
||||
var success: bool
|
||||
let response = self.status.stickers.buyPack(packId, address, price, gas, gasPrice, password, success)
|
||||
# TODO:
|
||||
# check if response["error"] is not null and handle the error
|
||||
result = $(%* { "result": %response, "success": %success })
|
||||
if success:
|
||||
self.stickerPacks.updateStickerPackInList(packId, false, true)
|
||||
self.transactionWasSent(response)
|
||||
|
||||
proc obtainAvailableStickerPacks*(self: StickersView) =
|
||||
spawnAndSend(self, "setAvailableStickerPacks") do:
|
||||
let availableStickerPacks = status_stickers.getAvailableStickerPacks()
|
||||
var packs: seq[StickerPack] = @[]
|
||||
for packId, stickerPack in availableStickerPacks.pairs:
|
||||
packs.add(stickerPack)
|
||||
$(%*(packs))
|
||||
|
||||
proc stickerPacksLoaded*(self: StickersView) {.signal.}
|
||||
|
||||
proc installedStickerPacksUpdated*(self: StickersView) {.signal.}
|
||||
|
||||
proc recentStickersUpdated*(self: StickersView) {.signal.}
|
||||
|
||||
proc setAvailableStickerPacks*(self: StickersView, availableStickersJSON: string) {.slot.} =
|
||||
let
|
||||
accounts = status_wallet.getWalletAccounts() # TODO: make generic
|
||||
installedStickerPacks = self.status.stickers.getInstalledStickerPacks()
|
||||
var
|
||||
purchasedStickerPacks: seq[int]
|
||||
for account in accounts:
|
||||
let address = parseAddress(account.address)
|
||||
purchasedStickerPacks = self.status.stickers.getPurchasedStickerPacks(address)
|
||||
let availableStickers = JSON.decode($availableStickersJSON, seq[StickerPack])
|
||||
|
||||
let pendingTransactions = status_wallet.getPendingTransactions().parseJson["result"]
|
||||
var pendingStickerPacks = initHashSet[int]()
|
||||
for trx in pendingTransactions.getElems():
|
||||
if trx["type"].getStr == $PendingTransactionType.BuyStickerPack:
|
||||
pendingStickerPacks.incl(trx["data"].getStr.parseInt)
|
||||
|
||||
for stickerPack in availableStickers:
|
||||
let isInstalled = installedStickerPacks.hasKey(stickerPack.id)
|
||||
let isBought = purchasedStickerPacks.contains(stickerPack.id)
|
||||
let isPending = pendingStickerPacks.contains(stickerPack.id) and not isBought
|
||||
self.status.stickers.availableStickerPacks[stickerPack.id] = stickerPack
|
||||
self.addStickerPackToList(stickerPack, isInstalled, isBought, isPending)
|
||||
self.stickerPacksLoaded()
|
||||
self.installedStickerPacksUpdated()
|
||||
|
||||
proc getNumInstalledStickerPacks(self: StickersView): QVariant {.slot.} =
|
||||
newQVariant(self.status.stickers.installedStickerPacks.len)
|
||||
|
||||
QtProperty[QVariant] numInstalledStickerPacks:
|
||||
read = getNumInstalledStickerPacks
|
||||
notify = installedStickerPacksUpdated
|
||||
|
||||
proc install*(self: StickersView, packId: int) {.slot.} =
|
||||
self.status.stickers.installStickerPack(packId)
|
||||
self.stickerPacks.updateStickerPackInList(packId, true, false)
|
||||
self.installedStickerPacksUpdated()
|
||||
|
||||
proc resetBuyAttempt*(self: StickersView, packId: int) {.slot.} =
|
||||
self.stickerPacks.updateStickerPackInList(packId, false, false)
|
||||
|
||||
proc uninstall*(self: StickersView, packId: int) {.slot.} =
|
||||
self.status.stickers.uninstallStickerPack(packId)
|
||||
self.status.stickers.removeRecentStickers(packId)
|
||||
self.stickerPacks.updateStickerPackInList(packId, false, false)
|
||||
self.recentStickers.removeStickersFromList(packId)
|
||||
self.installedStickerPacksUpdated()
|
||||
self.recentStickersUpdated()
|
||||
|
||||
proc getRecentStickerList*(self: StickersView): QVariant {.slot.} =
|
||||
result = newQVariant(self.recentStickers)
|
||||
|
||||
QtProperty[QVariant] recent:
|
||||
read = getRecentStickerList
|
||||
notify = recentStickersUpdated
|
||||
|
||||
proc addRecentStickerToList*(self: StickersView, sticker: Sticker) =
|
||||
self.recentStickers.addStickerToList(sticker)
|
||||
self.recentStickersUpdated()
|
||||
|
||||
proc send*(self: StickersView, hash: string, pack: int) {.slot.} =
|
||||
let sticker = Sticker(hash: hash, packId: pack)
|
||||
self.addRecentStickerToList(sticker)
|
||||
self.status.chat.sendSticker(self.activeChannel.id, sticker)
|
|
@ -0,0 +1,36 @@
|
|||
import NimQml, chronicles
|
||||
import ../../../status/status
|
||||
|
||||
logScope:
|
||||
topics = "transactions-view"
|
||||
|
||||
QtObject:
|
||||
type TransactionsView* = ref object of QObject
|
||||
status: Status
|
||||
|
||||
proc setup(self: TransactionsView) =
|
||||
self.QObject.setup
|
||||
|
||||
proc delete*(self: TransactionsView) =
|
||||
self.QObject.delete
|
||||
|
||||
proc newTransactionsView*(status: Status): TransactionsView =
|
||||
new(result, delete)
|
||||
result = TransactionsView()
|
||||
result.status = status
|
||||
result.setup
|
||||
|
||||
proc acceptAddressRequest*(self: TransactionsView, messageId: string , address: string) {.slot.} =
|
||||
self.status.chat.acceptRequestAddressForTransaction(messageId, address)
|
||||
|
||||
proc declineAddressRequest*(self: TransactionsView, messageId: string) {.slot.} =
|
||||
self.status.chat.declineRequestAddressForTransaction(messageId)
|
||||
|
||||
proc requestAddress*(self: TransactionsView, chatId: string, fromAddress: string, amount: string, tokenAddress: string) {.slot.} =
|
||||
self.status.chat.requestAddressForTransaction(chatId, fromAddress, amount, tokenAddress)
|
||||
|
||||
proc request*(self: TransactionsView, chatId: string, fromAddress: string, amount: string, tokenAddress: string) {.slot.} =
|
||||
self.status.chat.requestTransaction(chatId, fromAddress, amount, tokenAddress)
|
||||
|
||||
proc declineRequest*(self: TransactionsView, messageId: string) {.slot.} =
|
||||
self.status.chat.declineRequestTransaction(messageId)
|
|
@ -56,15 +56,15 @@ StackLayout {
|
|||
|
||||
function requestAddressForTransaction(address, amount, tokenAddress, tokenDecimals = 18) {
|
||||
amount = utilsModel.eth2Wei(amount.toString(), tokenDecimals)
|
||||
chatsModel.requestAddressForTransaction(chatsModel.activeChannel.id,
|
||||
address,
|
||||
amount,
|
||||
tokenAddress)
|
||||
chatsModel.transactions.requestAddress(chatsModel.activeChannel.id,
|
||||
address,
|
||||
amount,
|
||||
tokenAddress)
|
||||
txModalLoader.close()
|
||||
}
|
||||
function requestTransaction(address, amount, tokenAddress, tokenDecimals = 18) {
|
||||
amount = utilsModel.eth2Wei(amount.toString(), tokenDecimals)
|
||||
chatsModel.requestTransaction(chatsModel.activeChannel.id,
|
||||
chatsModel.transactions.request(chatsModel.activeChannel.id,
|
||||
address,
|
||||
amount,
|
||||
tokenAddress)
|
||||
|
@ -250,8 +250,8 @@ StackLayout {
|
|||
qsTr("This user has been blocked.") :
|
||||
qsTr("Type a message.")
|
||||
anchors.bottom: parent.bottom
|
||||
recentStickers: chatsModel.recentStickers
|
||||
stickerPackList: chatsModel.stickerPacks
|
||||
recentStickers: chatsModel.stickers.recent
|
||||
stickerPackList: chatsModel.stickers.stickerPacks
|
||||
chatType: chatsModel.activeChannel.chatType
|
||||
onSendTransactionCommandButtonClicked: {
|
||||
if (chatsModel.activeChannel.ensVerified) {
|
||||
|
@ -266,7 +266,7 @@ StackLayout {
|
|||
txModalLoader.item.open()
|
||||
}
|
||||
onStickerSelected: {
|
||||
chatsModel.sendSticker(hashId, packId)
|
||||
chatsModel.stickers.send(hashId, packId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ Item {
|
|||
cursorShape: Qt.PointingHandCursor
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
chatsModel.joinGroup()
|
||||
chatsModel.groups.join()
|
||||
joinOrDecline.visible = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ Item {
|
|||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
chatsModel.toggleEmojiReaction(messageId, modelData.emojiId)
|
||||
chatsModel.reactions.toggle(messageId, modelData.emojiId)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,9 +68,9 @@ Item {
|
|||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
if (root.state === Constants.addressRequested) {
|
||||
chatsModel.declineRequestAddressForTransaction(messageId)
|
||||
chatsModel.transactions.declineAddressRequest(messageId)
|
||||
} else if (root.state === Constants.transactionRequested) {
|
||||
chatsModel.declineRequestTransaction(messageId)
|
||||
chatsModel.transactions.declineRequest(messageId)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ Item {
|
|||
SelectAccountModal {
|
||||
id: selectAccountModal
|
||||
onSelectAndShareAddressButtonClicked: {
|
||||
chatsModel.acceptRequestAddressForTransaction(messageId, accountSelector.selectedAccount)
|
||||
chatsModel.transactions.acceptAddressRequest(messageId, accountSelector.selectedAccount)
|
||||
selectAccountModal.close()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ SVGImage {
|
|||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
chatsModel.toggleEmojiReaction(SelectedMessage.messageId, emojiId)
|
||||
chatsModel.reactions.toggle(SelectedMessage.messageId, emojiId)
|
||||
reactionImage.closeModal()
|
||||
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ ModalPopup {
|
|||
if(pubKeys.length === 0) {
|
||||
return;
|
||||
}
|
||||
chatsModel.createGroup(Utils.filterXSS(groupName.text), JSON.stringify(pubKeys));
|
||||
chatsModel.groups.create(Utils.filterXSS(groupName.text), JSON.stringify(pubKeys));
|
||||
popup.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ ModalPopup {
|
|||
|
||||
function doAddMembers(){
|
||||
if(pubKeys.length === 0) return;
|
||||
chatsModel.addGroupMembers(chatsModel.activeChannel.id, JSON.stringify(pubKeys));
|
||||
chatsModel.groups.addMembers(chatsModel.activeChannel.id, JSON.stringify(pubKeys));
|
||||
popup.close();
|
||||
}
|
||||
|
||||
|
@ -326,14 +326,14 @@ ModalPopup {
|
|||
icon.source: "../../../img/make-admin.svg"
|
||||
//% "Make Admin"
|
||||
text: qsTrId("make-admin")
|
||||
onTriggered: chatsModel.makeAdmin(chatsModel.activeChannel.id, model.pubKey)
|
||||
onTriggered: chatsModel.groups.makeAdmin(chatsModel.activeChannel.id, model.pubKey)
|
||||
}
|
||||
Action {
|
||||
icon.source: "../../../img/remove-from-group.svg"
|
||||
icon.color: Style.current.red
|
||||
//% "Remove From Group"
|
||||
text: qsTrId("remove-from-group")
|
||||
onTriggered: chatsModel.kickGroupMember(chatsModel.activeChannel.id, model.pubKey)
|
||||
onTriggered: chatsModel.groups.kickMember(chatsModel.activeChannel.id, model.pubKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import "./"
|
|||
|
||||
ModalPopup {
|
||||
function doRename(){
|
||||
chatsModel.renameGroup(groupName.text)
|
||||
chatsModel.groups.rename(groupName.text)
|
||||
popup.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,12 +24,12 @@ ModalPopup {
|
|||
}
|
||||
|
||||
function sendTransaction() {
|
||||
let responseStr = chatsModel.buyStickerPack(root.stickerPackId,
|
||||
selectFromAccount.selectedAccount.address,
|
||||
root.packPrice,
|
||||
gasSelector.selectedGasLimit,
|
||||
gasSelector.selectedGasPrice,
|
||||
transactionSigner.enteredPassword)
|
||||
let responseStr = chatsModel.stickers.buy(root.stickerPackId,
|
||||
selectFromAccount.selectedAccount.address,
|
||||
root.packPrice,
|
||||
gasSelector.selectedGasLimit,
|
||||
gasSelector.selectedGasPrice,
|
||||
transactionSigner.enteredPassword)
|
||||
let response = JSON.parse(responseStr)
|
||||
|
||||
if (!response.success) {
|
||||
|
@ -99,7 +99,7 @@ ModalPopup {
|
|||
selectedGasLimit = 325000
|
||||
return
|
||||
}
|
||||
selectedGasLimit = chatsModel.buyPackGasEstimate(root.stickerPackId, selectFromAccount.selectedAccount.address, root.packPrice)
|
||||
selectedGasLimit = chatsModel.stickers.estimate(root.stickerPackId, selectFromAccount.selectedAccount.address, root.packPrice)
|
||||
})
|
||||
}
|
||||
GasValidator {
|
||||
|
@ -194,7 +194,7 @@ ModalPopup {
|
|||
}
|
||||
|
||||
Connections {
|
||||
target: chatsModel
|
||||
target: chatsModel.stickers
|
||||
onTransactionWasSent: {
|
||||
//% "Transaction pending..."
|
||||
toastMessage.title = qsTrId("ens-transaction-pending")
|
||||
|
|
|
@ -46,12 +46,12 @@ Popup {
|
|||
Layout.fillHeight: true
|
||||
stickerPacks: stickerPackList
|
||||
onInstallClicked: {
|
||||
chatsModel.installStickerPack(packId)
|
||||
chatsModel.stickers.install(packId)
|
||||
stickerGrid.model = stickers
|
||||
stickerPackListView.itemAt(index).clicked()
|
||||
}
|
||||
onUninstallClicked: {
|
||||
chatsModel.uninstallStickerPack(packId)
|
||||
chatsModel.stickers.uninstall(packId)
|
||||
stickerGrid.model = recentStickers
|
||||
btnHistory.clicked()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue