feat(activity-center): Display album of images

Fixes: #9951
This commit is contained in:
Boris Melnik 2023-09-01 00:41:45 +03:00
parent 1f85ec1bd6
commit c102d2de07
6 changed files with 55 additions and 11 deletions

View File

@ -80,7 +80,7 @@ method unreadActivityCenterNotificationsCountChanged*(self: Module) =
method hasUnseenActivityCenterNotificationsChanged*(self: Module) =
self.view.hasUnseenActivityCenterNotificationsChanged()
proc createMessageItemFromDto(self: Module, message: MessageDto, communityId: string): MessageItem =
proc createMessageItemFromDto(self: Module, message: MessageDto, communityId: string, albumMessages: seq[MessageDto]): MessageItem =
let contactDetails = self.controller.getContactDetails(message.`from`)
let communityChats = self.controller.getCommunityById(communityId).chats
@ -91,6 +91,13 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, communityId: st
else:
quotedMessageAuthorDetails = self.controller.getContactDetails(message.quotedMessage.`from`)
var imagesAlbum: seq[string]
var albumMessageIds: seq[string]
if message.albumId != "":
for msg in albumMessages:
imagesAlbum.add(msg.image)
albumMessageIds.add(msg.id)
return msg_item_qobj.newMessageItem(msg_item.initItem(
message.id,
communityId, # we don't received community id via `activityCenterNotifications` api call
@ -133,8 +140,8 @@ proc createMessageItemFromDto(self: Module, message: MessageDto, communityId: st
message.quotedMessage.discordMessage,
quotedMessageAuthorDetails,
message.albumId,
if (len(message.albumId) == 0): @[] else: @[message.image],
if (len(message.albumId) == 0): @[] else: @[message.id],
imagesAlbum,
albumMessageIds,
message.albumImagesCount,
))
@ -155,13 +162,13 @@ method convertToItems*(
if (notification.message.id != ""):
let communityId = sectionId
# If there is a message in the Notification, transfer it to a MessageItem (QObject)
messageItem = self.createMessageItemFromDto(notification.message, communityId)
messageItem = self.createMessageItemFromDto(notification.message, communityId, notification.albumMessages)
if (notification.notificationType == ActivityCenterNotificationType.Reply and notification.message.responseTo != ""):
repliedMessageItem = self.createMessageItemFromDto(notification.replyMessage, communityId)
repliedMessageItem = self.createMessageItemFromDto(notification.replyMessage, communityId, @[])
if (notification.notificationType == ActivityCenterNotificationType.ContactVerification):
repliedMessageItem = self.createMessageItemFromDto(notification.replyMessage, communityId)
repliedMessageItem = self.createMessageItemFromDto(notification.replyMessage, communityId, @[])
return notification_item.initItem(
notification.id,

View File

@ -1,4 +1,4 @@
import NimQml, std/wrapnils
import NimQml, std/wrapnils, strutils, strformat, sugar
import ./message_item
QtObject:
@ -185,3 +185,15 @@ QtObject:
proc reactionsModel*(self: MessageItem): QVariant {.slot.} = result = newQVariant(?.self.messageItem.reactionsModel)
QtProperty[QVariant] reactionsModel:
read = reactionsModel
proc albumId*(self: MessageItem): string {.slot.} = result = ?.self.messageItem.albumId
QtProperty[string] albumId:
read = albumId
proc albumMessageImages*(self: MessageItem): string {.slot.} = result = ?.self.messageItem.albumMessageImages.join(" ")
QtProperty[string] albumMessageImages:
read = albumMessageImages
proc albumImagesCount*(self: MessageItem): int {.slot.} = result = ?.self.messageItem.albumImagesCount
QtProperty[int] albumImagesCount:
read = albumImagesCount

View File

@ -57,6 +57,7 @@ type ActivityCenterNotificationDto* = ref object of RootObj
notificationType*: ActivityCenterNotificationType
message*: MessageDto
replyMessage*: MessageDto
albumMessages*: seq[MessageDto]
timestamp*: int64
read*: bool
dismissed*: bool
@ -117,13 +118,18 @@ proc toActivityCenterNotificationDto*(jsonObj: JsonNode): ActivityCenterNotifica
discard jsonObj.getProp("accepted", result.accepted)
if jsonObj.contains("message") and jsonObj{"message"}.kind != JNull:
result.message = jsonObj{"message"}.toMessageDto()
result.message = jsonObj["message"].toMessageDto()
elif result.notificationType == ActivityCenterNotificationType.NewOneToOne and
jsonObj.contains("lastMessage") and jsonObj{"lastMessage"}.kind != JNull:
result.message = jsonObj{"lastMessage"}.toMessageDto()
result.message = jsonObj["lastMessage"].toMessageDto()
if jsonObj.contains("replyMessage") and jsonObj{"replyMessage"}.kind != JNull:
result.replyMessage = jsonObj{"replyMessage"}.toMessageDto()
result.replyMessage = jsonObj["replyMessage"].toMessageDto()
if jsonObj.contains("albumMessages") and jsonObj{"albumMessages"}.kind != JNull:
let jsonAlbum = jsonObj["albumMessages"]
for msg in jsonAlbum:
result.albumMessages.add(toMessageDto(msg))
proc parseActivityCenterNotifications*(rpcResult: JsonNode): (string, seq[ActivityCenterNotificationDto]) =
var notifs: seq[ActivityCenterNotificationDto] = @[]

View File

@ -40,6 +40,10 @@ ActivityNotificationBase {
colorId: Utils.colorIdForPubkey(contactId)
colorHash: Utils.getColorHashAsJson(contactId, sender.isEnsVerified)
}
contentType: notification && notification.message ? notification.message.contentType : StatusMessage.ContentType.Unknown
album: notification && notification.message ? notification.message.albumMessageImages.split(" ") : []
albumCount: notification && notification.message ? notification.message.albumImagesCount : 0
messageContent: notification && notification.message ? notification.message.messageImage : ""
}
property Component messageSubheaderComponent: null

View File

@ -5,6 +5,7 @@ import StatusQ.Core 0.1
import StatusQ.Core.Utils 0.1 as CoreUtils
import StatusQ.Core.Theme 0.1
import StatusQ.Components 0.1
import StatusQ.Components.private 0.1
import shared 1.0
import utils 1.0
@ -89,5 +90,19 @@ RowLayout {
Layout.fillWidth: !!root.messageBadgeComponent
}
}
Loader {
active: root.messageDetails.contentType === Constants.messageContentType.imageType
visible: active
Layout.fillWidth: true
sourceComponent: StatusMessageImageAlbum {
width: parent.width
album: root.messageDetails.albumCount > 0 ? root.messageDetails.album : [root.messageDetails.messageContent]
albumCount: root.messageDetails.albumCount || 1
imageWidth: 56
loadingComponentHeight: 56
shapeType: StatusImageMessage.ShapeType.ROUNDED
}
}
}
}

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit ad971278d948fbe80050cc56441b6470ca905326
Subproject commit d3c4ba315a90875ead7a68b238549a4c0163fc80