Skip to content
Snippets Groups Projects
Commit be9dd0d0 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk
Browse files

conversation: fix long loading time for images

Change-Id: Id88cfbd571f4b504f258758bd13b4e4a91bf1b49
parent 168165a1
No related branches found
No related tags found
No related merge requests found
...@@ -252,10 +252,11 @@ Loader { ...@@ -252,10 +252,11 @@ Loader {
Loader { Loader {
id: localMediaCompLoader id: localMediaCompLoader
anchors.right: isOutgoing ? parent.right : undefined anchors.right: isOutgoing ? parent.right : undefined
asynchronous: true
width: sourceComponent.width width: sourceComponent.width
height: sourceComponent.height height: sourceComponent.height
sourceComponent: mediaInfo.isImage !== undefined ? sourceComponent: mediaInfo.isImage !== undefined ?
imageComp : imageComp : mediaInfo.isAnimatedImage !== undefined ? animatedImageComp :
avComp avComp
Component { Component {
id: avComp id: avComp
...@@ -302,9 +303,9 @@ Loader { ...@@ -302,9 +303,9 @@ Loader {
} }
} }
Component { Component {
id: imageComp id: animatedImageComp
AnimatedImage { AnimatedImage {
id: img id: animatedImg
anchors.right: isOutgoing ? parent.right : undefined anchors.right: isOutgoing ? parent.right : undefined
property real minSize: 192 property real minSize: 192
property real maxSize: 256 property real maxSize: 256
...@@ -327,6 +328,51 @@ Loader { ...@@ -327,6 +328,51 @@ Loader {
anchors.fill: parent anchors.fill: parent
} }
layer.enabled: true layer.enabled: true
layer.effect: OpacityMask {
maskSource: MessageBubble {
out: isOutgoing
type: seq
width: animatedImg.width
height: animatedImg.height
radius: msgRadius
}
}
HoverHandler {
target : parent
onHoveredChanged: {
localMediaMsgItem.hoveredLink = hovered ? animatedImg.source : ""
}
cursorShape: Qt.PointingHandCursor
}
}
}
Component {
id: imageComp
Image {
id: img
anchors.right: isOutgoing ? parent.right : undefined
property real minSize: 192
property real maxSize: 256
cache: true
fillMode: Image.PreserveAspectCrop
mipmap: true
antialiasing: true
autoTransform: false
asynchronous: true
source: "file:///" + Body
property real aspectRatio: implicitWidth / implicitHeight
property real adjustedWidth: Math.min(maxSize,
Math.max(minSize,
innerContent.width - senderMargin))
width: adjustedWidth
height: Math.ceil(adjustedWidth / aspectRatio)
Rectangle {
color: JamiTheme.previewImageBackgroundColor
z: -1
anchors.fill: parent
}
layer.enabled: true
layer.effect: OpacityMask { layer.effect: OpacityMask {
maskSource: MessageBubble { maskSource: MessageBubble {
out: isOutgoing out: isOutgoing
......
...@@ -458,13 +458,24 @@ MessagesAdapter::conversationTypersUrlToName(const QSet<QString>& typersSet) ...@@ -458,13 +458,24 @@ MessagesAdapter::conversationTypersUrlToName(const QSet<QString>& typersSet)
return nameList; return nameList;
} }
bool QVariantMap
MessagesAdapter::isLocalImage(const QString& msg) MessagesAdapter::isLocalImage(const QString& msg)
{ {
QImageReader reader; QImageReader reader;
reader.setDecideFormatFromContent(true); reader.setDecideFormatFromContent(true);
reader.setFileName(msg); reader.setFileName(msg);
return !reader.read().isNull(); QByteArray fileFormat = reader.format();
if (fileFormat == "gif") {
return {{"isAnimatedImage", true}};
}
QList<QByteArray> supportedFormats = reader.supportedImageFormats();
auto iterator = std::find_if(supportedFormats.begin(),
supportedFormats.end(),
[fileFormat](QByteArray format) { return format == fileFormat; });
if (iterator != supportedFormats.end()) {
return {{"isImage", true}};
}
return {{"isImage", false}};
} }
QVariantMap QVariantMap
...@@ -476,8 +487,9 @@ MessagesAdapter::getMediaInfo(const QString& msg) ...@@ -476,8 +487,9 @@ MessagesAdapter::getMediaInfo(const QString& msg)
"<%1 style='width:100%;height:%2;outline:none;background-color:#f1f3f4;" "<%1 style='width:100%;height:%2;outline:none;background-color:#f1f3f4;"
"object-fit:cover;' " "object-fit:cover;' "
"controls controlsList='nodownload' src='file://%3' type='%4'/></body>"; "controls controlsList='nodownload' src='file://%3' type='%4'/></body>";
if (isLocalImage(msg)) { QVariantMap fileInfo = isLocalImage(msg);
return {{"isImage", true}}; if (fileInfo["isImage"].toBool() || fileInfo["isAnimatedImage"].toBool()) {
return fileInfo;
} }
QRegularExpression vPattern("[^\\s]+(.*?)\\.(avi|mov|webm|webp|rmvb)$", QRegularExpression vPattern("[^\\s]+(.*?)\\.(avi|mov|webm|webp|rmvb)$",
QRegularExpression::CaseInsensitiveOption); QRegularExpression::CaseInsensitiveOption);
......
...@@ -101,7 +101,7 @@ protected: ...@@ -101,7 +101,7 @@ protected:
Q_INVOKABLE void deleteInteraction(const QString& interactionId); Q_INVOKABLE void deleteInteraction(const QString& interactionId);
Q_INVOKABLE void copyToDownloads(const QString& interactionId, const QString& displayName); Q_INVOKABLE void copyToDownloads(const QString& interactionId, const QString& displayName);
Q_INVOKABLE void userIsComposing(bool isComposing); Q_INVOKABLE void userIsComposing(bool isComposing);
Q_INVOKABLE bool isLocalImage(const QString& msg); Q_INVOKABLE QVariantMap isLocalImage(const QString& msg);
Q_INVOKABLE QVariantMap getMediaInfo(const QString& msg); Q_INVOKABLE QVariantMap getMediaInfo(const QString& msg);
Q_INVOKABLE bool isRemoteImage(const QString& msg); Q_INVOKABLE bool isRemoteImage(const QString& msg);
Q_INVOKABLE QString getFormattedTime(const quint64 timestamp); Q_INVOKABLE QString getFormattedTime(const quint64 timestamp);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment