chore(chat/stickers): propagate stickers loading failure
This commit is contained in:
parent
d5478babfb
commit
8b4d527651
|
@ -82,6 +82,9 @@ proc init*(self: Controller) =
|
|||
self.events.on(SIGNAL_ALL_STICKER_PACKS_LOADED) do(e: Args):
|
||||
self.delegate.allPacksLoaded()
|
||||
|
||||
self.events.on(SIGNAL_ALL_STICKER_PACKS_LOAD_FAILED) do(e: Args):
|
||||
self.delegate.allPacksLoadFailed()
|
||||
|
||||
self.events.on(SIGNAL_STICKER_GAS_ESTIMATED) do(e: Args):
|
||||
let args = StickerGasEstimatedArgs(e)
|
||||
self.delegate.gasEstimateReturned(args.estimate, args.uuid)
|
||||
|
|
|
@ -40,6 +40,9 @@ method getNumInstalledStickerPacks*(self: AccessInterface): int {.base.} =
|
|||
method allPacksLoaded*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method allPacksLoadFailed*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method estimate*(self: AccessInterface, packId: string, address: string, price: string, uuid: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
|
|
@ -158,6 +158,9 @@ method clearStickerPacks*(self: Module) =
|
|||
method allPacksLoaded*(self: Module) =
|
||||
self.view.allPacksLoaded()
|
||||
|
||||
method allPacksLoadFailed*(self: Module) =
|
||||
self.view.allPacksLoadFailed()
|
||||
|
||||
method populateInstalledStickerPacks*(self: Module, stickers: Table[string, StickerPackDto]) =
|
||||
var stickerPackItems: seq[PackItem] = @[]
|
||||
for stickerPack in stickers.values:
|
||||
|
|
|
@ -9,6 +9,7 @@ QtObject:
|
|||
View* = ref object of QObject
|
||||
delegate: io_interface.AccessInterface
|
||||
packsLoaded*: bool
|
||||
packsLoadFailed*: bool
|
||||
stickerPacks*: StickerPackList
|
||||
recentStickers*: StickerList
|
||||
signingPhrase: string
|
||||
|
@ -66,6 +67,8 @@ QtObject:
|
|||
|
||||
proc stickerPacksLoaded*(self: View) {.signal.}
|
||||
|
||||
proc packsLoadFailedChanged*(self: View) {.signal.}
|
||||
|
||||
proc installedStickerPacksUpdated*(self: View) {.signal.}
|
||||
|
||||
proc clearStickerPacks*(self: View) =
|
||||
|
@ -110,9 +113,23 @@ QtObject:
|
|||
|
||||
proc allPacksLoaded*(self: View) =
|
||||
self.packsLoaded = true
|
||||
self.packsLoadFailed = false
|
||||
|
||||
self.stickerPacksLoaded()
|
||||
self.packsLoadFailedChanged()
|
||||
self.installedStickerPacksUpdated()
|
||||
|
||||
proc allPacksLoadFailed*(self: View) =
|
||||
self.packsLoadFailed = true
|
||||
self.packsLoadFailedChanged()
|
||||
|
||||
proc getPacksLoadFailed(self: View): bool {.slot.} =
|
||||
self.packsLoadFailed
|
||||
|
||||
QtProperty[bool] packsLoadFailed:
|
||||
read = getPacksLoadFailed
|
||||
notify = packsLoadFailedChanged
|
||||
|
||||
proc send*(self: View, channelId: string, hash: string, replyTo: string, pack: string, url: string) {.slot.} =
|
||||
let sticker = initItem(hash, pack, url)
|
||||
self.addRecentStickerToList(sticker)
|
||||
|
|
|
@ -11,18 +11,18 @@ type
|
|||
chainId*: int
|
||||
running*: ByteAddress # pointer to threadpool's `.running` Atomic[bool]
|
||||
|
||||
proc getMarketStickerPacks*(running: var Atomic[bool], chainId: int): Table[string, StickerPackDto] =
|
||||
result = initTable[string, StickerPackDto]()
|
||||
proc getMarketStickerPacks*(running: var Atomic[bool], chainId: int):
|
||||
tuple[stickers: Table[string, StickerPackDto], error: string] =
|
||||
result = (initTable[string, StickerPackDto](), "")
|
||||
try:
|
||||
let marketResponse = status_stickers.market(chainId)
|
||||
if marketResponse.result.kind != JArray: return
|
||||
for currItem in marketResponse.result.items():
|
||||
let stickerPack = currItem.toStickerPackDto()
|
||||
result[stickerPack.id] = stickerPack
|
||||
result.stickers[stickerPack.id] = stickerPack
|
||||
except RpcException:
|
||||
error "Error in getMarketStickerPacks", message = getCurrentExceptionMsg()
|
||||
result = initTable[string, StickerPackDto]()
|
||||
|
||||
result.error = getCurrentExceptionMsg()
|
||||
|
||||
# The pragmas `{.gcsafe, nimcall.}` in this context do not force the compiler
|
||||
# to accept unsafe code, rather they work in conjunction with the proc
|
||||
|
@ -45,8 +45,9 @@ const estimateTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
|||
const obtainMarketStickerPacksTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||
let arg = decode[ObtainMarketStickerPacksTaskArg](argEncoded)
|
||||
var running = cast[ptr Atomic[bool]](arg.running)
|
||||
let marketStickerPacks = getMarketStickerPacks(running[], arg.chainId)
|
||||
let (marketStickerPacks, error) = getMarketStickerPacks(running[], arg.chainId)
|
||||
var packs: seq[StickerPackDto] = @[]
|
||||
for packId, stickerPack in marketStickerPacks.pairs:
|
||||
packs.add(stickerPack)
|
||||
arg.finish(%*(packs))
|
||||
let tpl: tuple[packs: seq[StickerPackDto], error: string] = (packs, error)
|
||||
arg.finish(tpl)
|
||||
|
|
|
@ -54,8 +54,8 @@ type
|
|||
# Signals which may be emitted by this service:
|
||||
const SIGNAL_STICKER_PACK_LOADED* = "stickerPackLoaded"
|
||||
const SIGNAL_ALL_STICKER_PACKS_LOADED* = "allStickerPacksLoaded"
|
||||
const SIGNAL_ALL_STICKER_PACKS_LOAD_FAILED* = "allStickerPacksLoadFailed"
|
||||
const SIGNAL_STICKER_GAS_ESTIMATED* = "stickerGasEstimated"
|
||||
const SIGNAL_INSTALLED_STICKER_PACKS_LOADED* = "installedStickerPacksLoaded"
|
||||
const SIGNAL_STICKER_TRANSACTION_CONFIRMED* = "stickerTransactionConfirmed"
|
||||
const SIGNAL_STICKER_TRANSACTION_REVERTED* = "stickerTransactionReverted"
|
||||
|
||||
|
@ -245,8 +245,14 @@ QtObject:
|
|||
|
||||
result = (response: $response, success: success)
|
||||
|
||||
proc setMarketStickerPacks*(self: Service, availableStickersJSON: string) {.slot.} =
|
||||
let availableStickers = JSON.decode($availableStickersJSON, seq[StickerPackDto])
|
||||
proc setMarketStickerPacks*(self: Service, strickersJSON: string) {.slot.} =
|
||||
let stickersResult = Json.decode(strickersJSON, tuple[packs: seq[StickerPackDto], error: string])
|
||||
|
||||
if stickersResult.error != "":
|
||||
self.events.emit(SIGNAL_ALL_STICKER_PACKS_LOAD_FAILED, Args())
|
||||
return
|
||||
|
||||
let availableStickers = stickersResult.packs
|
||||
|
||||
for stickerPack in availableStickers:
|
||||
if self.marketStickerPacks.contains(stickerPack.id): continue
|
||||
|
@ -259,7 +265,6 @@ QtObject:
|
|||
isPending: false
|
||||
))
|
||||
|
||||
|
||||
let chainId = self.networkService.getNetworkForStickers().chainId
|
||||
let pendingStickerPacksResponse = status_stickers.pending()
|
||||
for (packID, stickerPackJson) in pendingStickerPacksResponse.result.pairs():
|
||||
|
|
Loading…
Reference in New Issue