Use dedicated Files for message content

This commit is contained in:
John Gibbon 2021-01-15 10:55:34 +01:00
parent 282ab1d2b9
commit aa7a1f28ce
6 changed files with 84 additions and 58 deletions

View file

@ -62,7 +62,6 @@ DISTFILES += qml/harbour-fernschreiber.qml \
qml/components/StickerPicker.qml \
qml/components/PhotoTextsListItem.qml \
qml/components/VoiceNoteOverlay.qml \
qml/components/WebPagePreview.qml \
qml/components/chatInformationPage/ChatInformationEditArea.qml \
qml/components/chatInformationPage/ChatInformationPageContent.qml \
qml/components/chatInformationPage/ChatInformationProfilePicture.qml \
@ -89,6 +88,20 @@ DISTFILES += qml/harbour-fernschreiber.qml \
qml/components/inlineQueryResults/InlineQueryResultVenue.qml \
qml/components/inlineQueryResults/InlineQueryResultVideo.qml \
qml/components/inlineQueryResults/InlineQueryResultVoiceNote.qml \
qml/components/messageContent/MessageAnimation.qml \
qml/components/messageContent/MessageAudio.qml \
qml/components/messageContent/MessageContentBase.qml \
qml/components/messageContent/MessageDocument.qml \
qml/components/messageContent/MessageGame.qml \
qml/components/messageContent/MessageLocation.qml \
qml/components/messageContent/MessagePhoto.qml \
qml/components/messageContent/MessagePoll.qml \
qml/components/messageContent/MessageSticker.qml \
qml/components/messageContent/MessageVenue.qml \
qml/components/messageContent/MessageVideoNote.qml \
qml/components/messageContent/MessageVideo.qml \
qml/components/messageContent/MessageVoiceNote.qml \
qml/components/messageContent/WebPagePreview.qml \
qml/js/debug.js \
qml/js/functions.js \
qml/pages/ChatInformationPage.qml \

View file

@ -18,6 +18,7 @@
*/
import QtQuick 2.6
import Sailfish.Silica 1.0
import "./messageContent"
import "../js/twemoji.js" as Emoji
import "../js/functions.js" as Functions
import "../js/debug.js" as Debug
@ -40,7 +41,7 @@ ListItem {
return existingMessage.id === messageId
});
readonly property bool isOwnMessage: page.myUserId === myMessage.sender.user_id
property string extraContentComponentName
property bool hasContentComponent
highlighted: (down || isSelected) && !menuOpen
openMenuOnPressAndHold: !messageListItem.precalculatedValues.pageIsSelecting
@ -199,17 +200,16 @@ ListItem {
repeat: false
running: false
onTriggered: {
if (typeof myMessage.content !== "undefined") {
if (messageListItem.extraContentComponentName !== "") {
extraContentLoader.setSource(
"../components/" +messageListItem.extraContentComponentName +".qml",
{
messageListItem: messageListItem
})
} else {
if (typeof myMessage.content.web_page !== "undefined") { // only in messageText
webPagePreviewLoader.active = true;
}
if (messageListItem.hasContentComponent) {
var type = myMessage.content["@type"];
extraContentLoader.setSource(
"../components/messageContent/" + type.charAt(0).toUpperCase() + type.substring(1) + ".qml",
{
messageListItem: messageListItem
})
} else {
if (typeof myMessage.content.web_page !== "undefined") { // only in messageText
webPagePreviewLoader.active = true;
}
}
}
@ -435,7 +435,7 @@ ListItem {
id: extraContentLoader
width: parent.width
asynchronous: true
height: item ? item.height : (messageListItem.extraContentComponentName !== "" ? chatView.getContentComponentHeight(messageListItem.extraContentComponentName, myMessage.content, width) : 0)
height: item ? item.height : (messageListItem.hasContentComponent ? chatView.getContentComponentHeight(model.content_type, myMessage.content, width) : 0)
}
Binding {

View file

@ -18,6 +18,7 @@
*/
import QtQuick 2.6
import Sailfish.Silica 1.0
import "./messageContent"
import "../js/functions.js" as Functions
import "../js/twemoji.js" as Emoji
import "../js/debug.js" as Debug
@ -34,8 +35,7 @@ Flickable {
readonly property var userInformation: tdLibWrapper.getUserInformation(overlayMessage.sender.user_id);
readonly property bool isOwnMessage: tdLibWrapper.getUserInformation().id === overlayMessage.sender.user_id;
readonly property bool isAnonymous: overlayMessage.sender["@type"] === "messageSenderChat"
readonly property string extraContentComponentName: (typeof overlayMessage.content !== "undefined" && typeof chatView.contentComponentNames[overlayMessage.content['@type']] !== "undefined" )
? chatView.contentComponentNames[overlayMessage.content['@type']] : ""
property bool hasContentComponent: overlayMessage.content && chatView.delegateMessagesContent.indexOf(overlayMessage.content['@type']) > -1
signal requestClose;
function getOriginalAuthor(forwardInformation, fontSize) {
@ -61,18 +61,15 @@ Flickable {
repeat: false
running: false
onTriggered: {
if (typeof overlayMessage.content !== "undefined") {
if (messageOverlayFlickable.extraContentComponentName !== "") {
overlayExtraContentLoader.setSource(
"../components/" + messageOverlayFlickable.extraContentComponentName + ".qml",
{
overlayFlickable: messageOverlayFlickable
})
} else {
if (typeof overlayMessage.content.web_page !== "undefined") {
overlayWebPagePreviewLoader.active = true;
}
}
if (messageOverlayFlickable.hasContentComponent) {
var type = overlayMessage.content["@type"];
overlayExtraContentLoader.setSource(
"../components/messageContent/" + type.charAt(0).toUpperCase() + type.substring(1) + ".qml",
{
overlayFlickable: messageOverlayFlickable
})
} else if(overlayMessage.content && overlayMessage.content.web_page) {
overlayWebPagePreviewLoader.active = true;
}
}
}

View file

@ -20,7 +20,8 @@ import QtQuick 2.6
import QtGraphicalEffects 1.0
import Sailfish.Silica 1.0
import WerkWolf.Fernschreiber 1.0
import "../js/functions.js" as Functions
import "../"
import "../../js/functions.js" as Functions
Column {
id: webPagePreviewColumn

View file

@ -1056,39 +1056,53 @@ Page {
}
}
readonly property var contentComponentNames: ({
messageSticker: "StickerPreview",
messagePhoto: "ImagePreview",
messageVideo: "VideoPreview",
messageVideoNote: "VideoPreview",
messageAnimation: "VideoPreview",
messageAudio: "AudioPreview",
messageVoiceNote: "AudioPreview",
messageDocument: "DocumentPreview",
messageLocation: "LocationPreview",
messageVenue: "LocationPreview",
messagePoll: "PollPreview",
messageGame: "GamePreview"
})
function getContentComponentHeight(componentName, content, parentWidth) {
switch(componentName) {
case "StickerPreview": return content.sticker.height;
case "ImagePreview":
case "LocationPreview":
return parentWidth * 0.66666666; // 2 / 3;
case "VideoPreview":
return ( content['@type'] === "messageVideoNote" ) ? parentWidth : ( Functions.getVideoHeight(parentWidth, ( content['@type'] === "messageVideo" ) ? content.video : content.animation) );
case "AudioPreview":
return parentWidth / 2;
case "DocumentPreview":
function getContentComponentHeight(contentType, content, parentWidth) {
switch(contentType) {
case "messageAnimation":
return Functions.getVideoHeight(parentWidth, content.video);
case "messageAudio":
case "messageVoiceNote":
return Theme.itemSizeLarge;
case "messageDocument":
return Theme.itemSizeSmall;
case "PollPreview":
return Theme.itemSizeSmall * (4 + content.poll.options);
case "GamePreview":
case "messageGame":
return parentWidth * 0.66666666 + Theme.itemSizeLarge; // 2 / 3;
case "messageLocation":
case "messagePhoto":
case "messageVenue":
return parentWidth * 0.66666666; // 2 / 3;
case "messagePoll":
return Theme.itemSizeSmall * (4 + content.poll.options);
case "messageSticker":
return content.sticker.height;
case "messageVideo":
return Functions.getVideoHeight(parentWidth, content.video);
case "messageVideoNote":
return parentWidth
}
}
readonly property var delegateMessagesContent: [
"messageAnimation",
"messageAudio",
// "messageContact",
// "messageDice"
"messageDocument",
"messageGame",
// "messageInvoice",
"messageLocation",
// "messagePassportDataSent",
// "messagePaymentSuccessful",
"messagePhoto",
"messagePoll",
// "messageProximityAlertTriggered",
"messageSticker",
"messageVenue",
"messageVideo",
"messageVideoNote",
"messageVoiceNote"
]
readonly property var simpleDelegateMessages: ["messageBasicGroupChatCreate",
"messageChatAddMembers",
"messageChatChangePhoto",
@ -1098,6 +1112,7 @@ Page {
"messageChatJoinByLink",
"messageChatSetTtl",
"messageChatUpgradeFrom",
// "messageContactRegistered","messageExpiredPhoto", "messageExpiredVideo","messageWebsiteConnected"
"messageGameScore",
"messageChatUpgradeTo",
"messageCustomServiceAction",
@ -1115,7 +1130,7 @@ Page {
myMessage: model.display
messageId: model.message_id
messageIndex: model.index
extraContentComponentName: chatView.contentComponentNames[model.content_type] || ""
hasContentComponent: !!myMessage.content && chatView.delegateMessagesContent.indexOf(model.content_type) > -1
canReplyToMessage: chatPage.canSendMessages
onReplyToMessage: {
newMessageInReplyToRow.inReplyToMessage = myMessage