From 68e2dab715998c84e1ab7569211e59579b1c997b Mon Sep 17 00:00:00 2001 From: John Gibbon Date: Sun, 8 Nov 2020 20:37:17 +0100 Subject: [PATCH] set some properties readonly --- qml/components/MessageListViewItem.qml | 16 +++++------ qml/pages/ChatPage.qml | 37 +++++++++++++------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/qml/components/MessageListViewItem.qml b/qml/components/MessageListViewItem.qml index 663e535..5b002f5 100644 --- a/qml/components/MessageListViewItem.qml +++ b/qml/components/MessageListViewItem.qml @@ -25,19 +25,19 @@ import QtQml.Models 2.3 ListItem { id: messageListItem contentHeight: messageBackground.height + Theme.paddingMedium - property var myMessage: display - property var userInformation: tdLibWrapper.getUserInformation(myMessage.sender_user_id) + readonly property var myMessage: display + readonly property var userInformation: tdLibWrapper.getUserInformation(myMessage.sender_user_id) property QtObject precalculatedValues: ListView.view.precalculatedValues - property color textColor: isOwnMessage ? Theme.highlightColor : Theme.primaryColor - property int textAlign: isOwnMessage ? Text.AlignRight : Text.AlignLeft - property Page page: precalculatedValues.page + readonly property color textColor: isOwnMessage ? Theme.highlightColor : Theme.primaryColor + readonly property int textAlign: isOwnMessage ? Text.AlignRight : Text.AlignLeft + readonly property Page page: precalculatedValues.page - property bool isOwnMessage: page.myUserId === myMessage.sender_user_id - property string extraContentComponentName: typeof myMessage.content !== "undefined" + readonly property bool isOwnMessage: page.myUserId === myMessage.sender_user_id + readonly property string extraContentComponentName: typeof myMessage.content !== "undefined" && typeof chatView.contentComponentNames[myMessage.content['@type']] !== "undefined" ? chatView.contentComponentNames[myMessage.content['@type']] : "" - property ObjectModel additionalContextItems: ObjectModel {} + readonly property ObjectModel additionalContextItems: ObjectModel {} onPressAndHold: { contextMenuLoader.active = true; diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 5dc90dd..deb8145 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -32,7 +32,7 @@ Page { property bool loading: true; property bool isInitialized: false; - property int myUserId: tdLibWrapper.getUserInformation().id; + readonly property int myUserId: tdLibWrapper.getUserInformation().id; property var chatInformation; property bool isPrivateChat: false; property bool isBasicGroup: false; @@ -42,7 +42,7 @@ Page { property var chatGroupInformation; property int chatOnlineMemberCount: 0; property var emojiProposals; - property bool userIsMember: (isPrivateChat && chatInformation["@type"]) || // should be optimized + readonly property bool userIsMember: (isPrivateChat && chatInformation["@type"]) || // should be optimized (isBasicGroup || isSuperGroup) && ( (chatGroupInformation.status["@type"] === "chatMemberStatusMember") || (chatGroupInformation.status["@type"] === "chatMemberStatusAdministrator") @@ -82,11 +82,11 @@ Page { chatPartnerInformation = tdLibWrapper.getUserInformation(chatInformation.type.user_id); updateChatPartnerStatusText(); } - if (isBasicGroup) { + else if (isBasicGroup) { chatGroupInformation = tdLibWrapper.getBasicGroup(chatInformation.type.basic_group_id); updateGroupStatusText(); } - if (isSuperGroup) { + else if (isSuperGroup) { chatGroupInformation = tdLibWrapper.getSuperGroup(chatInformation.type.supergroup_id); isChannel = chatGroupInformation.is_channel; updateGroupStatusText(); @@ -232,7 +232,6 @@ Page { } break; } - } Connections { @@ -535,18 +534,18 @@ Page { property bool inCooldown: false property bool manuallyScrolledToBottom property QtObject precalculatedValues: QtObject { - property alias page: chatPage - property bool showUserInfo: page.isBasicGroup || ( page.isSuperGroup && !page.isChannel) - property int profileThumbnailDimensions: showUserInfo ? Theme.itemSizeSmall : 0 - property int pageMarginDouble: 2 * Theme.horizontalPageMargin - property int paddingMediumDouble: 2 * Theme.paddingMedium - property int entryWidth: chatView.width - pageMarginDouble - property int textItemWidth: entryWidth - profileThumbnailDimensions - Theme.paddingSmall - property int backgroundWidth: textItemWidth - pageMarginDouble - property int backgroundRadius: textItemWidth/50 - property int textColumnWidth: backgroundWidth - Theme.horizontalPageMargin - property int messageInReplyToHeight: Theme.fontSizeExtraSmall * 2.571428571 + Theme.paddingSmall; - property int webPagePreviewHeight: ( (textColumnWidth * 2 / 3) + (6 * Theme.fontSizeExtraSmall) + ( 7 * Theme.paddingSmall) ) + readonly property alias page: chatPage + readonly property bool showUserInfo: page.isBasicGroup || ( page.isSuperGroup && !page.isChannel) + readonly property int profileThumbnailDimensions: showUserInfo ? Theme.itemSizeSmall : 0 + readonly property int pageMarginDouble: 2 * Theme.horizontalPageMargin + readonly property int paddingMediumDouble: 2 * Theme.paddingMedium + readonly property int entryWidth: chatView.width - pageMarginDouble + readonly property int textItemWidth: entryWidth - profileThumbnailDimensions - Theme.paddingSmall + readonly property int backgroundWidth: textItemWidth - pageMarginDouble + readonly property int backgroundRadius: textItemWidth/50 + readonly property int textColumnWidth: backgroundWidth - Theme.horizontalPageMargin + readonly property int messageInReplyToHeight: Theme.fontSizeExtraSmall * 2.571428571 + Theme.paddingSmall; + readonly property int webPagePreviewHeight: ( (textColumnWidth * 2 / 3) + (6 * Theme.fontSizeExtraSmall) + ( 7 * Theme.paddingSmall) ) } function handleScrollPositionChanged() { @@ -593,7 +592,7 @@ Page { } model: chatModel - property var contentComponentNames: ({ + readonly property var contentComponentNames: ({ messageSticker: "StickerPreview", messagePhoto: "ImagePreview", messageVideo: "VideoPreview", @@ -622,7 +621,7 @@ Page { } } - property var simpleDelegateMessages: ["messageBasicGroupChatCreate", "messageChatAddMembers", "messageChatChangePhoto", "messageChatChangeTitle", "messageChatDeleteMember", "messageChatDeletePhoto", "messageChatJoinByLink", "messageChatSetTtl", "messageChatUpgradeFrom", "messageChatUpgradeTo", "messageCustomServiceAction", "messagePinMessage", "messageScreenshotTaken", "messageSupergroupChatCreate", "messageUnsupported"] + readonly property var simpleDelegateMessages: ["messageBasicGroupChatCreate", "messageChatAddMembers", "messageChatChangePhoto", "messageChatChangeTitle", "messageChatDeleteMember", "messageChatDeletePhoto", "messageChatJoinByLink", "messageChatSetTtl", "messageChatUpgradeFrom", "messageChatUpgradeTo", "messageCustomServiceAction", "messagePinMessage", "messageScreenshotTaken", "messageSupergroupChatCreate", "messageUnsupported"] delegate: Loader { width: chatView.width Component {