Skip to content

Commit

Permalink
fix range + message updates; implement album filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jgibbon authored and Mikhail Barashkov committed May 5, 2024
1 parent 4b68f60 commit 6cae9b4
Show file tree
Hide file tree
Showing 21 changed files with 1,649 additions and 68 deletions.
10 changes: 10 additions & 0 deletions harbour-fernschreiber.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ DEFINES += QT_STATICPLUGIN

SOURCES += src/harbour-fernschreiber.cpp \
src/appsettings.cpp \
src/boolfiltermodel.cpp \
src/chatpermissionfiltermodel.cpp \
src/chatlistmodel.cpp \
src/chatmodel.cpp \
Expand Down Expand Up @@ -105,14 +106,21 @@ DISTFILES += qml/harbour-fernschreiber.qml \
qml/components/messageContent/MessageGame.qml \
qml/components/messageContent/MessageLocation.qml \
qml/components/messageContent/MessagePhoto.qml \
qml/components/messageContent/MessagePhotoAlbum.qml \
qml/components/messageContent/MessagePoll.qml \
qml/components/messageContent/MessageSticker.qml \
qml/components/messageContent/MessageVenue.qml \
qml/components/messageContent/MessageVideoAlbum.qml \
qml/components/messageContent/MessageVideoNote.qml \
qml/components/messageContent/MessageVideo.qml \
qml/components/messageContent/MessageVoiceNote.qml \
qml/components/messageContent/SponsoredMessage.qml \
qml/components/messageContent/WebPagePreview.qml \
qml/components/messageContent/mediaAlbumPage/FullscreenOverlay.qml \
qml/components/messageContent/mediaAlbumPage/PhotoComponent.qml \
qml/components/messageContent/mediaAlbumPage/VideoComponent.qml \
qml/components/messageContent/mediaAlbumPage/ZoomArea.qml \
qml/components/messageContent/mediaAlbumPage/ZoomImage.qml \
qml/components/settingsPage/Accordion.qml \
qml/components/settingsPage/AccordionItem.qml \
qml/components/settingsPage/ResponsiveGrid.qml \
Expand All @@ -130,6 +138,7 @@ DISTFILES += qml/harbour-fernschreiber.qml \
qml/pages/CoverPage.qml \
qml/pages/DebugPage.qml \
qml/pages/InitializationPage.qml \
qml/pages/MediaAlbumPage.qml \
qml/pages/NewChatPage.qml \
qml/pages/OverviewPage.qml \
qml/pages/AboutPage.qml \
Expand Down Expand Up @@ -212,6 +221,7 @@ INSTALLS += telegram 86.png 108.png 128.png 172.png 256.png \

HEADERS += \
src/appsettings.h \
src/boolfiltermodel.h \
src/chatpermissionfiltermodel.h \
src/chatlistmodel.h \
src/chatmodel.h \
Expand Down
47 changes: 32 additions & 15 deletions qml/components/MessageListViewItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ListItem {
property int messageIndex
property int messageViewCount
property var myMessage
property var messageAlbumMessageIds
property var reactions
property bool canReplyToMessage
readonly property bool isAnonymous: myMessage.sender_id["@type"] === "messageSenderChat"
Expand Down Expand Up @@ -68,7 +69,7 @@ ListItem {
property var chatReactions
property var messageReactions

highlighted: (down || isSelected || additionalOptionsOpened || wasNavigatedTo) && !menuOpen
highlighted: (down || (isSelected && messageAlbumMessageIds.length === 0) || additionalOptionsOpened || wasNavigatedTo) && !menuOpen
openMenuOnPressAndHold: !messageListItem.precalculatedValues.pageIsSelecting

signal replyToMessage()
Expand Down Expand Up @@ -278,20 +279,20 @@ ListItem {
Connections {
target: chatModel
onMessagesReceived: {
messageBackground.isUnread = index > chatModel.getLastReadMessageIndex() && myMessage['@type'] !== "sponsoredMessage";
messageBackground.isUnread = messageIndex > chatModel.getLastReadMessageIndex() && myMessage['@type'] !== "sponsoredMessage";
}
onMessagesIncrementalUpdate: {
messageBackground.isUnread = index > chatModel.getLastReadMessageIndex() && myMessage['@type'] !== "sponsoredMessage";
messageBackground.isUnread = messageIndex > chatModel.getLastReadMessageIndex() && myMessage['@type'] !== "sponsoredMessage";
}
onNewMessageReceived: {
messageBackground.isUnread = index > chatModel.getLastReadMessageIndex() && myMessage['@type'] !== "sponsoredMessage";
messageBackground.isUnread = messageIndex > chatModel.getLastReadMessageIndex() && myMessage['@type'] !== "sponsoredMessage";
}
onUnreadCountUpdated: {
messageBackground.isUnread = index > chatModel.getLastReadMessageIndex() && myMessage['@type'] !== "sponsoredMessage";
messageBackground.isUnread = messageIndex > chatModel.getLastReadMessageIndex() && myMessage['@type'] !== "sponsoredMessage";
}
onLastReadSentMessageUpdated: {
Debug.log("[ChatModel] Messages in this chat were read, new last read: ", lastReadSentIndex, ", updating description for index ", index, ", status: ", (index <= lastReadSentIndex));
messageDateText.text = getMessageStatusText(myMessage, index, lastReadSentIndex, messageDateText.useElapsed);
Debug.log("[ChatModel] Messages in this chat were read, new last read: ", lastReadSentIndex, ", updating description for index ", index, ", status: ", (messageIndex <= lastReadSentIndex));
messageDateText.text = getMessageStatusText(myMessage, messageIndex, lastReadSentIndex, messageDateText.useElapsed);
}
}

Expand All @@ -312,7 +313,7 @@ ListItem {
pageStack.currentPage === chatPage) {
Debug.log("Available reactions for this message: " + reactions);
messageListItem.messageReactions = reactions;
showItemCompletelyTimer.requestedIndex = index;
showItemCompletelyTimer.requestedIndex = messageIndex;
showItemCompletelyTimer.start();
} else {
messageListItem.messageReactions = null;
Expand All @@ -333,6 +334,13 @@ ListItem {
interval: 200
triggeredOnStart: false
onTriggered: {
if (requestedIndex === messageIndex) {
chatView.highlightMoveDuration = -1;
chatView.highlightResizeDuration = -1;
chatView.scrollToIndex(requestedIndex);
chatView.highlightMoveDuration = 0;
chatView.highlightResizeDuration = 0;
}
Debug.log("Show item completely timer triggered, requested index: " + requestedIndex + ", current index: " + index)
if (requestedIndex === index) {
var p = chatView.contentItem.mapFromItem(reactionsColumn, 0, 0)
Expand Down Expand Up @@ -386,8 +394,10 @@ ListItem {
onTriggered: {
if (messageListItem.hasContentComponent) {
var type = myMessage.content["@type"];
var albumComponentPart = (myMessage.media_album_id !== "0" && ['messagePhoto', 'messageVideo'].indexOf(type) !== -1) ? 'Album' : '';
console.log('delegateComponentLoadingTimer', myMessage.media_album_id, albumComponentPart)
extraContentLoader.setSource(
"../components/messageContent/" + type.charAt(0).toUpperCase() + type.substring(1) + ".qml",
"../components/messageContent/" + type.charAt(0).toUpperCase() + type.substring(1) + albumComponentPart + ".qml",
{
messageListItem: messageListItem
})
Expand Down Expand Up @@ -452,7 +462,7 @@ ListItem {
}
height: messageTextColumn.height + precalculatedValues.paddingMediumDouble
width: precalculatedValues.backgroundWidth
property bool isUnread: index > chatModel.getLastReadMessageIndex() && myMessage['@type'] !== "sponsoredMessage"
property bool isUnread: messageIndex > chatModel.getLastReadMessageIndex() && myMessage['@type'] !== "sponsoredMessage"
color: Theme.colorScheme === Theme.LightOnDark ? (isUnread ? Theme.secondaryHighlightColor : Theme.secondaryColor) : (isUnread ? Theme.backgroundGlowColor : Theme.overlayBackgroundColor)
radius: parent.width / 50
opacity: isUnread ? 0.5 : 0.2
Expand All @@ -474,7 +484,13 @@ ListItem {
id: userText

width: parent.width
text: messageListItem.isOwnMessage ? qsTr("You") : Emoji.emojify( myMessage['@type'] === "sponsoredMessage" ? tdLibWrapper.getChat(myMessage.sponsor_chat_id).title : ( messageListItem.isAnonymous ? page.chatInformation.title : Functions.getUserName(messageListItem.userInformation) ), font.pixelSize)
text: messageListItem.isOwnMessage
? qsTr("You")
: Emoji.emojify( myMessage['@type'] === "sponsoredMessage"
? tdLibWrapper.getChat(myMessage.sponsor_chat_id).title
: ( messageListItem.isAnonymous
? page.chatInformation.title
: Functions.getUserName(messageListItem.userInformation) ), font.pixelSize)
font.pixelSize: Theme.fontSizeExtraSmall
font.weight: Font.ExtraBold
color: messageListItem.textColor
Expand Down Expand Up @@ -658,7 +674,8 @@ ListItem {
id: extraContentLoader
width: parent.width * getContentWidthMultiplier()
asynchronous: true
height: item ? item.height : (messageListItem.hasContentComponent ? chatView.getContentComponentHeight(model.content_type, myMessage.content, width) : 0)
readonly property var defaultExtraContentHeight: messageListItem.hasContentComponent ? chatView.getContentComponentHeight(model.content_type, myMessage.content, width, model.album_message_ids.length) : 0
height: item ? item.height : defaultExtraContentHeight
}

Binding {
Expand All @@ -683,7 +700,7 @@ ListItem {
running: true
repeat: true
onTriggered: {
messageDateText.text = getMessageStatusText(myMessage, index, chatView.lastReadSentIndex, messageDateText.useElapsed);
messageDateText.text = getMessageStatusText(myMessage, messageIndex, chatView.lastReadSentIndex, messageDateText.useElapsed);
}
}

Expand All @@ -696,13 +713,13 @@ ListItem {
font.pixelSize: Theme.fontSizeTiny
color: messageListItem.isOwnMessage ? Theme.secondaryHighlightColor : Theme.secondaryColor
horizontalAlignment: messageListItem.textAlign
text: getMessageStatusText(myMessage, index, chatView.lastReadSentIndex, messageDateText.useElapsed)
text: getMessageStatusText(myMessage, messageIndex, chatView.lastReadSentIndex, messageDateText.useElapsed)
MouseArea {
anchors.fill: parent
enabled: !messageListItem.precalculatedValues.pageIsSelecting
onClicked: {
messageDateText.useElapsed = !messageDateText.useElapsed;
messageDateText.text = getMessageStatusText(myMessage, index, chatView.lastReadSentIndex, messageDateText.useElapsed);
messageDateText.text = getMessageStatusText(myMessage, messageIndex, chatView.lastReadSentIndex, messageDateText.useElapsed);
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions qml/components/TDLibMinithumbnail.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Loader {
id: loader
property var minithumbnail
property bool highlighted
property int fillMode: tdLibImage.fillMode
anchors.fill: parent
active: !!minithumbnail
sourceComponent: Component {
Expand All @@ -32,7 +33,7 @@ Loader {
id: minithumbnailImage
anchors.fill: parent
source: "data:image/jpg;base64,"+minithumbnail.data
fillMode: tdLibImage.fillMode
fillMode: loader.fillMode
opacity: status === Image.Ready ? 1.0 : 0.0
cache: false
visible: opacity > 0
Expand All @@ -43,12 +44,12 @@ Loader {
effect: PressEffect { source: minithumbnailImage }
}
}

FastBlur {
anchors.fill: parent
source: minithumbnailImage
radius: Theme.paddingLarge
}
// this had a visible impact on performance
// FastBlur {
// anchors.fill: parent
// source: minithumbnailImage
// radius: Theme.paddingLarge
// }
}
}
}
4 changes: 3 additions & 1 deletion qml/components/TDLibThumbnail.qml
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ Item {

readonly property bool hasVisibleThumbnail: thumbnailImage.opacity !== 1.0
&& !(videoThumbnailLoader.item && videoThumbnailLoader.item.opacity === 1.0)

property alias fillMode: thumbnailImage.fillMode
layer {
enabled: highlighted
effect: PressEffect { source: tdlibThumbnail }
}

TDLibMinithumbnail {
id: minithumbnailLoader
fillMode: thumbnailImage.fillMode
active: !!minithumbnail && thumbnailImage.opacity < 1.0
}
BackgroundImage {
Expand Down Expand Up @@ -103,6 +104,7 @@ Item {
sourceSize.width: width
sourceSize.height: height
mimeType: tdlibThumbnail.videoMimeType
fillMode: thumbnailImage.fillMode == Image.PreserveAspectFit ? Thumbnail.PreserveAspectFit : Thumbnail.PreserveAspectCrop
visible: opacity > 0
opacity: status === Thumbnail.Ready ? 1.0 : 0.0
Behavior on opacity { FadeAnimation {} }
Expand Down
1 change: 0 additions & 1 deletion qml/components/messageContent/MessageContentBase.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import QtQuick 2.6
import Sailfish.Silica 1.0
import QtMultimedia 5.6
import "../"
import "../../js/functions.js" as Functions
import "../../js/debug.js" as Debug

Item {
Expand Down
36 changes: 15 additions & 21 deletions qml/components/messageContent/MessagePhoto.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,30 @@ import "../"

MessageContentBase {

function calculateBiggest() {
var candidateBiggest = rawMessage.content.photo.sizes[rawMessage.content.photo.sizes.length - 1];
if (candidateBiggest.width === 0 && rawMessage.content.photo.sizes.length > 1) {
for (var i = (rawMessage.content.photo.sizes.length - 2); i >= 0; i--) {
candidateBiggest = rawMessage.content.photo.sizes[i];
if (candidateBiggest.width > 0) {
height: Math.max(Theme.itemSizeExtraSmall, Math.min(Math.round(width * 0.66666666), width / getAspectRatio()))
readonly property alias photoData: photo.photo;

onClicked: {
pageStack.push(Qt.resolvedUrl("../../pages/MediaAlbumPage.qml"), {
"messages" : [rawMessage],
})
}
function getAspectRatio() {
var candidate = photoData.sizes[photoData.sizes.length - 1];
if (candidate.width === 0 && photoData.sizes.length > 1) {
for (var i = (photoData.sizes.length - 2); i >= 0; i--) {
candidate = photoData.sizes[i];
if (candidate.width > 0) {
break;
}
}
}
return candidateBiggest;
}

height: Math.max(Theme.itemSizeExtraSmall, Math.min(defaultHeight, width / (biggest.width/biggest.height)))
readonly property int defaultHeight: Math.round(width * 0.66666666)
readonly property var biggest: calculateBiggest();

onClicked: {
pageStack.push(Qt.resolvedUrl("../../pages/ImagePage.qml"), {
"photoData" : photo.photo,
// "pictureFileInformation" : photo.fileInformation
})
return candidate.width / candidate.height;
}
TDLibPhoto {
id: photo
anchors.fill: parent
photo: rawMessage.content.photo
highlighted: parent.highlighted
}
BackgroundImage {
visible: !rawMessage.content.photo.minithumbnail && photo.image.status !== Image.Ready
}
}
Loading

0 comments on commit 6cae9b4

Please sign in to comment.