fix(@dekstop/chat): higher cpu usage after opening gif selector

Fixes #4829
This commit is contained in:
Sale Djenic 2022-02-22 21:48:57 +01:00 committed by Iuri Matias
parent 6f3ce63f51
commit c855de98b6
14 changed files with 73 additions and 26 deletions

View File

@ -342,6 +342,12 @@ method onPinMessage*(self: Module, messageId: string, actionInitiatedBy: string)
method onUnpinMessage*(self: Module, messageId: string) = method onUnpinMessage*(self: Module, messageId: string) =
self.view.model().pinUnpinMessage(messageId, false, "") self.view.model().pinUnpinMessage(messageId, false, "")
method getSectionId*(self: Module): string =
return self.controller.getMySectionId()
method getChatId*(self: Module): string =
return self.controller.getMyChatId()
method getChatType*(self: Module): int = method getChatType*(self: Module): int =
let chatDto = self.controller.getChatDetails() let chatDto = self.controller.getChatDetails()
return chatDto.chatType.int return chatDto.chatType.int

View File

@ -10,6 +10,12 @@ method toggleReaction*(self: AccessInterface, messageId: string, emojiId: int) {
method pinUnpinMessage*(self: AccessInterface, messageId: string, pin: bool) {.base.} = method pinUnpinMessage*(self: AccessInterface, messageId: string, pin: bool) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getSectionId*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")
method getChatId*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")
method getChatType*(self: AccessInterface): int {.base.} = method getChatType*(self: AccessInterface): int {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -56,6 +56,12 @@ QtObject:
return "" return ""
return $jsonObj return $jsonObj
proc getSectionId*(self: View): string {.slot.} =
return self.delegate.getSectionId()
proc getChatId*(self: View): string {.slot.} =
return self.delegate.getChatId()
proc getChatType*(self: View): int {.slot.} = proc getChatType*(self: View): int {.slot.} =
return self.delegate.getChatType() return self.delegate.getChatType()

View File

@ -28,12 +28,9 @@ StatusAppThreePanelLayout {
property var contactsStore property var contactsStore
property bool hasAddedContacts: root.contactsStore.myContactsModel.count > 0 property bool hasAddedContacts: root.contactsStore.myContactsModel.count > 0
// Not Refactored property RootStore rootStore: RootStore {
property var messageStore contactsStore: root.contactsStore
}
property RootStore rootStore: RootStore {
contactsStore: root.contactsStore
}
property Component pinnedMessagesListPopupComponent property Component pinnedMessagesListPopupComponent
property bool stickersLoaded: false property bool stickersLoaded: false

View File

@ -6,6 +6,9 @@ QtObject {
property var messageModule property var messageModule
property var messagesModel property var messagesModel
property var chatSectionModule
property var loadingHistoryMessagesInProgress: root.chatSectionModule? root.chatSectionModule.loadingHistoryMessagesInProgress : false
onMessageModuleChanged: { onMessageModuleChanged: {
if(!messageModule) if(!messageModule)
@ -17,7 +20,8 @@ QtObject {
if(!messageModule) if(!messageModule)
return return
if(!messageModule.initialMessagesLoaded || chatCommunitySectionModule.loadingHistoryMessagesInProgress) if(!messageModule.initialMessagesLoaded ||
root.loadingHistoryMessagesInProgress? root.loadingHistoryMessagesInProgress : false)
return return
messageModule.loadMoreMessages() messageModule.loadMoreMessages()
@ -59,6 +63,20 @@ QtObject {
return obj return obj
} }
function getSectionId () {
if(!messageModule)
return ""
return messageModule.getSectionId()
}
function getChatId () {
if(!messageModule)
return ""
return messageModule.getChatId()
}
function getChatType () { function getChatType () {
if(!messageModule) if(!messageModule)
return Constants.chatType.unknown return Constants.chatType.unknown
@ -224,4 +242,23 @@ QtObject {
return true return true
return messageModule.didIJoinedChat(); return messageModule.didIJoinedChat();
} }
property bool playAnimation: {
if(!Global.applicationWindow.active)
return false
if(root.getSectionId() !== mainModule.activeSection.id)
return false
if(!root.chatSectionModule)
return false
if(root.chatSectionModule.activeItem.isSubItemActive &&
root.getChatId() !== root.chatSectionModule.activeItem.activeSubItem.id ||
!root.chatSectionModule.activeItem.isSubItemActive &&
root.getChatId() !== root.chatSectionModule.activeItem.id)
return false
return true
}
} }

View File

@ -290,6 +290,7 @@ ColumnLayout {
MessageStore { MessageStore {
id: messageStore id: messageStore
messageModule: chatContentModule? chatContentModule.messagesModule : null messageModule: chatContentModule? chatContentModule.messagesModule : null
chatSectionModule: chatContentRoot.rootStore.chatCommunitySectionModule
} }
MessageContextMenuView { MessageContextMenuView {

View File

@ -131,6 +131,7 @@ Loader {
chatHorizontalPadding: 0 chatHorizontalPadding: 0
container: root.container container: root.container
allCornersRounded: true allCornersRounded: true
playing: false
} }
Loader { Loader {

View File

@ -21,23 +21,12 @@ Item {
width: loadingImageLoader.active ? loadingImageLoader.width : imageMessage.width width: loadingImageLoader.active ? loadingImageLoader.width : imageMessage.width
height: loadingImageLoader.active ? loadingImageLoader.height : imageMessage.paintedHeight height: loadingImageLoader.active ? loadingImageLoader.height : imageMessage.paintedHeight
Connections {
target: Global.applicationWindow
onActiveChanged: {
if (Global.applicationWindow.active === false) {
imageMessage.playing = false
} else {
imageMessage.playing = Qt.binding(function () {return imageContainer.playing})
}
}
}
AnimatedImage { AnimatedImage {
id: imageMessage id: imageMessage
width: sourceSize.width > imageWidth ? imageWidth : sourceSize.width width: sourceSize.width > imageWidth ? imageWidth : sourceSize.width
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
source: imageContainer.source source: imageContainer.source
playing: isAnimated playing: imageContainer.isAnimated && imageContainer.playing
layer.enabled: true layer.enabled: true
layer.effect: OpacityMask { layer.effect: OpacityMask {
@ -77,12 +66,6 @@ Item {
acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.RightButton
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
if (imageContainer.isAnimated) {
// FIXME the ListView completely removes Items that scroll out of view
// so when we scroll backto the image, it gets reloaded and playing is reset
imageContainer.playing = !imageContainer.playing
return
}
imageContainer.clicked(imageMessage, mouse) imageContainer.clicked(imageMessage, mouse)
} }
} }

View File

@ -80,6 +80,7 @@ Rectangle {
chatHorizontalPadding: 0 chatHorizontalPadding: 0
container: root.container container: root.container
visible: root.contentType === Constants.messageContentType.imageType visible: root.contentType === Constants.messageContentType.imageType
playing: false
} }
StatusSticker { StatusSticker {

View File

@ -152,6 +152,8 @@ Popup {
} }
Loader { Loader {
id: gifsLoader
active: popup.opened
Layout.fillWidth: true Layout.fillWidth: true
Layout.rightMargin: Style.current.smallPadding / 2 Layout.rightMargin: Style.current.smallPadding / 2
Layout.leftMargin: Style.current.smallPadding / 2 Layout.leftMargin: Style.current.smallPadding / 2

View File

@ -512,6 +512,7 @@ Item {
z: 51 z: 51
sourceComponent: Component { sourceComponent: Component {
StatusChatImage { StatusChatImage {
playing: root.messageStore.playAnimation
imageSource: messageImage imageSource: messageImage
imageWidth: 200 imageWidth: 200
onClicked: { onClicked: {

View File

@ -222,7 +222,8 @@ Column {
source: linkData.thumbnailUrl source: linkData.thumbnailUrl
imageWidth: 300 imageWidth: 300
isCurrentUser: root.isCurrentUser isCurrentUser: root.isCurrentUser
onClicked: imageClick(linkImage.imageAlias) onClicked: imageClicked(linkImage.imageAlias)
playing: root.messageStore.playAnimation
} }
} }
} }
@ -253,6 +254,7 @@ Column {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: 1 anchors.topMargin: 1
playing: root.messageStore.playAnimation
} }
StatusBaseText { StatusBaseText {
id: linkTitle id: linkTitle

View File

@ -316,6 +316,7 @@ Column {
Component { Component {
id: statusUpdateComponent id: statusUpdateComponent
StatusUpdateView { StatusUpdateView {
messageStore: root.messageStore
statusAgeEpoch: root.statusAgeEpoch statusAgeEpoch: root.statusAgeEpoch
container: root container: root
// Not Refactored Yet // Not Refactored Yet
@ -348,6 +349,7 @@ Column {
id: compactMessageComponent id: compactMessageComponent
CompactMessageView { CompactMessageView {
container: root
store: root.store store: root.store
messageStore: root.messageStore messageStore: root.messageStore
usersStore: root.usersStore usersStore: root.usersStore

View File

@ -14,6 +14,7 @@ import StatusQ.Controls 0.1
MouseArea { MouseArea {
id: root id: root
// property var store // property var store
property var messageStore
property bool hovered: containsMouse property bool hovered: containsMouse
property var container property var container
property int statusAgeEpoch: 0 property int statusAgeEpoch: 0
@ -125,6 +126,7 @@ MouseArea {
sourceComponent: Component { sourceComponent: Component {
StatusChatImage { StatusChatImage {
playing: root.messageStore.playAnimation
imageSource: image imageSource: image
imageWidth: 200 imageWidth: 200
container: root.container container: root.container