Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: payment request nim input area model #16822

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/modules/main/activity_center/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, communityId: st
message.albumImagesCount,
message.bridgeMessage,
message.quotedMessage.bridgeMessage,
message.paymentRequests
))

method convertToItems*(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ../../../../../../app_service/service/contacts/service as contact_service
import ../../../../../../app_service/service/community/service as community_service
import ../../../../../../app_service/service/chat/service as chat_service
import ../../../../../../app_service/service/message/dto/link_preview
import ../../../../../../app_service/service/message/dto/payment_request
import ../../../../../../app_service/service/message/dto/urls_unfurling_plan
import ../../../../../../app_service/service/settings/dto/settings
import ../../../../../core/eventemitter
Expand Down Expand Up @@ -128,30 +129,34 @@ proc sendImages*(self: Controller,
msg: string,
replyTo: string,
preferredUsername: string = "",
linkPreviews: seq[LinkPreview]) =
linkPreviews: seq[LinkPreview],
paymentRequests: seq[PaymentRequest]) =
self.resetLinkPreviews()
self.chatService.asyncSendImages(
self.chatId,
imagePathsAndDataJson,
msg,
replyTo,
preferredUsername,
linkPreviews
linkPreviews,
paymentRequests
)

proc sendChatMessage*(self: Controller,
msg: string,
replyTo: string,
contentType: int,
preferredUsername: string = "",
linkPreviews: seq[LinkPreview]) =
linkPreviews: seq[LinkPreview],
paymentRequests: seq[PaymentRequest]) =
self.resetLinkPreviews()
self.chatService.asyncSendChatMessage(self.chatId,
msg,
replyTo,
contentType,
preferredUsername,
linkPreviews
linkPreviews,
paymentRequests
)

proc requestAddressForTransaction*(self: Controller, fromAddress: string, amount: string, tokenAddress: string) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import NimQml, tables

import ../../../../../../app_service/service/gif/dto
import ../../../../../../app_service/service/message/dto/link_preview
import ../../../../../../app_service/service/message/dto/payment_request
import ../../../../../../app_service/service/contacts/dto/contact_details

type
Expand All @@ -19,10 +20,10 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")

method sendChatMessage*(self: AccessInterface, msg: string, replyTo: string, contentType: int, linkPreviews: seq[LinkPreview]) {.base.} =
method sendChatMessage*(self: AccessInterface, msg: string, replyTo: string, contentType: int, linkPreviews: seq[LinkPreview], paymentRequests: seq[PaymentRequest]) {.base.} =
raise newException(ValueError, "No implementation available")

method sendImages*(self: AccessInterface, imagePathsJson: string, msg: string, replyTo: string, linkPreviews: seq[LinkPreview]) {.base.} =
method sendImages*(self: AccessInterface, imagePathsJson: string, msg: string, replyTo: string, linkPreviews: seq[LinkPreview], paymentRequests: seq[PaymentRequest]) {.base.} =
raise newException(ValueError, "No implementation available")

method requestAddressForTransaction*(self: AccessInterface, fromAddress: string, amount: string, tokenAddress: string) {.base.} =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ../../../../../core/eventemitter
import ../../../../../../app_service/service/settings/service as settings_service
import ../../../../../../app_service/service/message/service as message_service
import ../../../../../../app_service/service/message/dto/link_preview
import ../../../../../../app_service/service/message/dto/payment_request
import ../../../../../../app_service/service/chat/service as chat_service
import ../../../../../../app_service/service/community/service as community_service
import ../../../../../../app_service/service/contacts/service as contact_service
Expand Down Expand Up @@ -65,17 +66,18 @@ method getModuleAsVariant*(self: Module): QVariant =
proc getChatId*(self: Module): string =
return self.controller.getChatId()

method sendImages*(self: Module, imagePathsAndDataJson: string, msg: string, replyTo: string, linkPreviews: seq[LinkPreview]) =
self.controller.sendImages(imagePathsAndDataJson, msg, replyTo, singletonInstance.userProfile.getPreferredName(), linkPreviews)
method sendImages*(self: Module, imagePathsAndDataJson: string, msg: string, replyTo: string, linkPreviews: seq[LinkPreview], paymentRequests: seq[PaymentRequest]) =
self.controller.sendImages(imagePathsAndDataJson, msg, replyTo, singletonInstance.userProfile.getPreferredName(), linkPreviews, paymentRequests)

method sendChatMessage*(
self: Module,
msg: string,
replyTo: string,
contentType: int,
linkPreviews: seq[LinkPreview]) =
linkPreviews: seq[LinkPreview],
paymentRequests: seq[PaymentRequest]) =
self.controller.sendChatMessage(msg, replyTo, contentType,
singletonInstance.userProfile.getPreferredName(), linkPreviews)
singletonInstance.userProfile.getPreferredName(), linkPreviews, paymentRequests)

method requestAddressForTransaction*(self: Module, fromAddress: string, amount: string, tokenAddress: string) =
self.controller.requestAddressForTransaction(fromAddress, amount, tokenAddress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ./io_interface
import ./preserved_properties
import ./urls_model
import ../../../../../../app/modules/shared_models/link_preview_model as link_preview_model
import ../../../../../../app/modules/shared_models/payment_request_model as payment_request_model
import ../../../../../../app/modules/shared_models/emoji_reactions_model as emoji_reactions_model

QtObject:
Expand All @@ -13,6 +14,8 @@ QtObject:
preservedPropertiesVariant: QVariant
linkPreviewModel: link_preview_model.Model
linkPreviewModelVariant: QVariant
paymentRequestModel: payment_request_model.Model
paymentRequestModelVariant: QVariant
urlsModel: urls_model.Model
urlsModelVariant: QVariant
sendingInProgress: bool
Expand All @@ -28,6 +31,8 @@ QtObject:
self.preservedProperties.delete
self.linkPreviewModelVariant.delete
self.linkPreviewModel.delete
self.paymentRequestModelVariant.delete
self.paymentRequestModel.delete
self.urlsModelVariant.delete
self.urlsModel.delete
self.emojiReactionsModel.delete
Expand All @@ -41,6 +46,8 @@ QtObject:
result.preservedPropertiesVariant = newQVariant(result.preservedProperties)
result.linkPreviewModel = newLinkPreviewModel()
result.linkPreviewModelVariant = newQVariant(result.linkPreviewModel)
result.paymentRequestModel = newPaymentRequestModel()
result.paymentRequestModelVariant = newQVariant(result.paymentRequestModel)
result.urlsModel = newUrlsModel()
result.urlsModelVariant = newQVariant(result.urlsModel)
result.askToEnableLinkPreview = false
Expand All @@ -58,13 +65,13 @@ QtObject:
# FIXME: Update this when `setText` is async.
self.setSendingInProgress(true)
self.delegate.setText(msg, false)
self.delegate.sendChatMessage(msg, replyTo, contentType, self.linkPreviewModel.getUnfuledLinkPreviews())
self.delegate.sendChatMessage(msg, replyTo, contentType, self.linkPreviewModel.getUnfuledLinkPreviews(), self.payment_request_model.getPaymentRequests())

proc sendImages*(self: View, imagePathsAndDataJson: string, msg: string, replyTo: string) {.slot.} =
# FIXME: Update this when `setText` is async.
self.setSendingInProgress(true)
self.delegate.setText(msg, false)
self.delegate.sendImages(imagePathsAndDataJson, msg, replyTo, self.linkPreviewModel.getUnfuledLinkPreviews())
self.delegate.sendImages(imagePathsAndDataJson, msg, replyTo, self.linkPreviewModel.getUnfuledLinkPreviews(), self.payment_request_model.getPaymentRequests())

proc acceptAddressRequest*(self: View, messageId: string , address: string) {.slot.} =
self.delegate.acceptRequestAddressForTransaction(messageId, address)
Expand All @@ -90,6 +97,12 @@ QtObject:
QtProperty[QVariant] preservedProperties:
read = getPreservedProperties

proc getPaymentRequestModel*(self: View): QVariant {.slot.} =
return self.paymentRequestModelVariant

QtProperty[QVariant] paymentRequestModel:
read = getPaymentRequestModel

proc getLinkPreviewModel*(self: View): QVariant {.slot.} =
return self.linkPreviewModelVariant

Expand Down Expand Up @@ -149,6 +162,15 @@ QtObject:
proc removeLinkPreviewData*(self: View, index: int) {.slot.} =
self.linkPreviewModel.removePreviewData(index)

proc addPaymentRequest*(self: View, receiver: string, amount: string, symbol: string, chainId: int) {.slot.} =
self.paymentRequestModel.addPaymentRequest(receiver, amount, symbol, chainId)

proc removePaymentRequestPreviewData*(self: View, index: int) {.slot.} =
self.paymentRequestModel.removeItemWithIndex(index)

proc removeAllPaymentRequestPreviewData(self: View) {.slot.} =
self.paymentRequestModel.clearItems()

proc urlsModelChanged(self: View) {.signal.}
proc getUrlsModel*(self: View): QVariant {.slot.} =
return self.urlsModelVariant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ proc createMessageItemsFromMessageDtos(self: Module, messages: seq[MessageDto],
if (len(message.albumId) == 0): @[] else: @[message.id],
message.albumImagesCount,
message.bridgeMessage,
message.quotedMessage.bridgeMessage
message.quotedMessage.bridgeMessage,
message.paymentRequests
)

self.updateLinkPreviewsContacts(item, requestFromMailserver = item.seen)
Expand Down Expand Up @@ -290,6 +291,7 @@ proc createFetchMoreMessagesItem(self: Module): Item =
albumImagesCount = 0,
BridgeMessage(),
BridgeMessage(),
paymentRequests = @[]
)

proc createChatIdentifierItem(self: Module): Item =
Expand Down Expand Up @@ -358,6 +360,7 @@ proc createChatIdentifierItem(self: Module): Item =
albumImagesCount = 0,
bridgeMessage = BridgeMessage(),
quotedBridgeMessage = BridgeMessage(),
paymentRequests = @[]
)

proc checkIfMessageLoadedAndScroll(self: Module) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ proc buildPinnedMessageItem(self: Module, message: MessageDto, actionInitiatedBy
message.albumImagesCount,
message.bridgeMessage,
message.quotedMessage.bridgeMessage,
message.paymentRequests
)
item.pinned = true
item.pinnedBy = actionInitiatedBy
Expand Down
1 change: 1 addition & 0 deletions src/app/modules/main/chat_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ proc buildCommunityMemberMessageItem(self: Module, message: MessageDto): member_
message.albumImagesCount,
message.bridgeMessage,
message.quotedMessage.bridgeMessage,
message.paymentRequests
)

method delete*(self: Module) =
Expand Down
9 changes: 9 additions & 0 deletions src/app/modules/shared_models/message_item.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import ../../../app_service/common/types
import ../../../app_service/service/contacts/dto/contact_details
import ../../../app_service/service/message/dto/message
import ../../../app_service/service/message/dto/link_preview
import ../../../app_service/service/message/dto/payment_request
import ./link_preview_model as link_preview_model
import ./payment_request_model as payment_request_model
import ./emoji_reactions_model as emoji_reactions_model

export types.ContentType
Expand Down Expand Up @@ -72,6 +74,7 @@ type
albumMessageIds: seq[string]
albumImagesCount: int
bridgeName: string
paymentRequestModel: payment_request_model.Model

proc initItem*(
id,
Expand Down Expand Up @@ -126,6 +129,7 @@ proc initItem*(
albumImagesCount: int,
bridgeMessage: BridgeMessage,
quotedBridgeMessage: BridgeMessage,
paymentRequests: seq[PaymentRequest],
): Item =
result = Item()
result.id = id
Expand Down Expand Up @@ -184,6 +188,7 @@ proc initItem*(
result.albumMessageImages = albumMessageImages
result.albumMessageIds = albumMessageIds
result.albumImagesCount = albumImagesCount
result.paymentRequestModel = newPaymentRequestModel(paymentRequests)

if quotedMessageContentType == ContentType.DiscordMessage:
result.quotedMessageAuthorDisplayName = quotedMessageDiscordMessage.author.name
Expand Down Expand Up @@ -281,6 +286,7 @@ proc initNewMessagesMarkerItem*(clock, timestamp: int64): Item =
albumImagesCount = 0,
bridgeMessage = BridgeMessage(),
quotedBridgeMessage = BridgeMessage(),
paymentRequests = @[],
)

proc `$`*(self: Item): string =
Expand Down Expand Up @@ -508,6 +514,9 @@ proc `links=`*(self: Item, links: seq[string]) {.inline.} =
proc linkPreviewModel*(self: Item): link_preview_model.Model {.inline.} =
return self.linkPreviewModel

proc paymentRequestModel*(self: Item): payment_request_model.Model {.inline.} =
return self.paymentRequestModel

proc emojiReactionsModel*(self: Item): emoji_reactions_model.Model {.inline.} =
return self.emojiReactionsModel

Expand Down
4 changes: 4 additions & 0 deletions src/app/modules/shared_models/message_model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type
AlbumMessageImages
AlbumImagesCount
BridgeName
PaymentRequestModel

QtObject:
type
Expand Down Expand Up @@ -182,6 +183,7 @@ QtObject:
ModelRole.AlbumMessageImages.int: "albumMessageImages",
ModelRole.AlbumImagesCount.int: "albumImagesCount",
ModelRole.BridgeName.int: "bridgeName",
ModelRole.PaymentRequestModel.int: "paymentRequestModel",
}.toTable

method data(self: Model, index: QModelIndex, role: int): QVariant =
Expand Down Expand Up @@ -358,6 +360,8 @@ QtObject:
result = newQVariant(item.albumImagesCount)
of ModelRole.BridgeName:
result = newQVariant(item.bridgeName)
of ModelRole.PaymentRequestModel:
result = newQVariant(item.paymentRequestModel)

proc updateItemAtIndex(self: Model, index: int) =
let ind = self.createIndex(index, 0, nil)
Expand Down
Loading