From 1b18a78efc72b7c993da8650dd0cc88acda6e3e9 Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Sun, 23 Aug 2020 19:17:30 +0200 Subject: [PATCH] Display profile pictures and names in groups --- qml/pages/ChatPage.qml | 144 +++++++++++++++-------- src/tdlibwrapper.cpp | 2 +- translations/harbour-fernschreiber-de.ts | 4 + translations/harbour-fernschreiber.ts | 4 + 4 files changed, 105 insertions(+), 49 deletions(-) diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index cedbf24..c6e13b9 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -182,7 +182,7 @@ Page { Row { id: headerRow width: parent.width - (3 * Theme.horizontalPageMargin) - height: chatOverviewColumn.height + ( 2 * Theme.horizontalPageMargin ) + height: chatOverviewColumn.height + ( 2 * Theme.paddingLarge ) anchors.horizontalCenter: parent.horizontalCenter spacing: Theme.paddingMedium @@ -260,64 +260,112 @@ Page { delegate: ListItem { id: messageListItem - contentHeight: messageTextItem.height + Theme.paddingMedium + contentHeight: messageBackground.height + Theme.paddingMedium contentWidth: parent.width property variant myMessage: display + property variant userInformation: tdLibWrapper.getUserInformation(display.sender_user_id) - Column { - id: messageTextItem - + Row { + id: messageTextRow spacing: Theme.paddingSmall + width: parent.width - ( 2 * Theme.horizontalPageMargin ) + anchors.horizontalCenter: parent.horizontalCenter - width: parent.width - height: messageText.height + messageDateText.height + Theme.paddingMedium - anchors.verticalCenter: parent.verticalCenter - - Text { - anchors { - left: parent.left - leftMargin: (chatPage.myUserId === display.sender_user_id) ? 4 * Theme.horizontalPageMargin : Theme.horizontalPageMargin - right: parent.right - rightMargin: (chatPage.myUserId === display.sender_user_id) ? Theme.horizontalPageMargin : 4 * Theme.horizontalPageMargin - } - - id: messageText - text: Emoji.emojify(Functions.getSimpleMessageText(display), font.pixelSize) - font.pixelSize: Theme.fontSizeSmall - color: chatPage.myUserId === display.sender_user_id ? Theme.highlightColor : Theme.primaryColor - wrapMode: Text.Wrap - textFormat: Text.StyledText - onLinkActivated: { - // Functions.handleLink(link); - } - horizontalAlignment: (chatPage.myUserId === display.sender_user_id) ? Text.AlignRight : Text.AlignLeft - linkColor: Theme.highlightColor + ProfileThumbnail { + id: messagePictureThumbnail + photoData: (typeof messageListItem.userInformation.profile_photo !== "undefined") ? messageListItem.userInformation.profile_photo.small : "" + replacementStringHint: userText.text + width: visible ? Theme.itemSizeSmall : 0 + height: visible ? Theme.itemSizeSmall : 0 + anchors.bottom: parent.bottom + anchors.bottomMargin: Theme.paddingSmall + visible: ( chatPage.isBasicGroup || chatPage.isSuperGroup ) && !chatPage.isChannel } - Timer { - id: messageDateUpdater - interval: 60000 - running: true - repeat: true - onTriggered: { - messageDateText.text = Functions.getDateTimeElapsed(display.date); - } - } + Item { + id: messageTextItem + + width: parent.width - messagePictureThumbnail.width - Theme.paddingSmall + height: messageBackground.height + + Rectangle { + id: messageBackground + anchors { + left: parent.left + leftMargin: (chatPage.myUserId === display.sender_user_id) ? 2 * Theme.horizontalPageMargin : 0 + right: parent.right + rightMargin: (chatPage.myUserId === display.sender_user_id) ? 0 : 2 * Theme.horizontalPageMargin + verticalCenter: parent.verticalCenter + } + height: messageTextColumn.height + ( 2 * Theme.paddingMedium ) + + color: Theme.secondaryColor + radius: parent.width / 50 + opacity: 0.2 + } + + Column { + id: messageTextColumn + + spacing: Theme.paddingSmall + + width: messageBackground.width - Theme.horizontalPageMargin + anchors.centerIn: messageBackground + + Text { + id: userText + + width: parent.width + text: display.sender_user_id !== chatPage.myUserId ? Emoji.emojify(Functions.getUserName(messageListItem.userInformation), font.pixelSize) : qsTr("You") + font.pixelSize: Theme.fontSizeExtraSmall + font.weight: Font.ExtraBold + color: (chatPage.myUserId === display.sender_user_id) ? Theme.highlightColor : Theme.primaryColor + maximumLineCount: 1 + elide: Text.ElideRight + textFormat: Text.StyledText + horizontalAlignment: (chatPage.myUserId === display.sender_user_id) ? Text.AlignRight : Text.AlignLeft + visible: ( chatPage.isBasicGroup || chatPage.isSuperGroup ) && !chatPage.isChannel + } + + Text { + id: messageText + + width: parent.width + text: Emoji.emojify(Functions.getSimpleMessageText(display), font.pixelSize) + font.pixelSize: Theme.fontSizeSmall + color: (chatPage.myUserId === display.sender_user_id) ? Theme.highlightColor : Theme.primaryColor + wrapMode: Text.Wrap + textFormat: Text.StyledText + onLinkActivated: { + // Functions.handleLink(link); + } + horizontalAlignment: (chatPage.myUserId === display.sender_user_id) ? Text.AlignRight : Text.AlignLeft + linkColor: Theme.highlightColor + } + + Timer { + id: messageDateUpdater + interval: 60000 + running: true + repeat: true + onTriggered: { + messageDateText.text = Functions.getDateTimeElapsed(display.date); + } + } + + Text { + width: parent.width + + id: messageDateText + text: Functions.getDateTimeElapsed(display.date) + font.pixelSize: Theme.fontSizeTiny + color: (chatPage.myUserId === display.sender_user_id) ? Theme.secondaryHighlightColor : Theme.secondaryColor + horizontalAlignment: (chatPage.myUserId === display.sender_user_id) ? Text.AlignRight : Text.AlignLeft + } - Text { - anchors { - left: parent.left - leftMargin: (chatPage.myUserId === display.sender_user_id) ? 4 * Theme.horizontalPageMargin : Theme.horizontalPageMargin - right: parent.right - rightMargin: (chatPage.myUserId === display.sender_user_id) ? Theme.horizontalPageMargin : 4 * Theme.horizontalPageMargin } - id: messageDateText - text: Functions.getDateTimeElapsed(display.date) - font.pixelSize: Theme.fontSizeTiny - color: chatPage.myUserId === display.sender_user_id ? Theme.secondaryHighlightColor : Theme.secondaryColor - horizontalAlignment: (chatPage.myUserId === display.sender_user_id) ? Text.AlignRight : Text.AlignLeft } } diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index a6ed782..e252da1 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -203,7 +203,7 @@ QVariantMap TDLibWrapper::getUserInformation() QVariantMap TDLibWrapper::getUserInformation(const QString &userId) { - qDebug() << "[TDLibWrapper] Returning user information for ID " << userId; + // qDebug() << "[TDLibWrapper] Returning user information for ID " << userId; return this->allUsers.value(userId).toMap(); } diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index 4a05354..ed5e208 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -130,6 +130,10 @@ %1 subscribers + + You + + CoverPage diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index 4a05354..ed5e208 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -130,6 +130,10 @@ %1 subscribers + + You + + CoverPage