From 640a73676e76a8f0c605e4887c8c784d99468872 Mon Sep 17 00:00:00 2001 From: Chukwudi Nwutobo Date: Fri, 7 Jan 2022 19:52:57 +0100 Subject: [PATCH] Version 0.1.3. - Bug fixes and performance improvements. --- debian/changelog | 7 +++++ resources/qml/MessagePage.qml | 7 +++-- resources/qml/components/ChatItem.qml | 2 +- resources/qml/components/MessageBubble.qml | 30 ++++++++------------ src/ChatModel.cpp | 32 +++++++++++++++++++++- src/Common.hpp | 2 +- 6 files changed, 57 insertions(+), 23 deletions(-) diff --git a/debian/changelog b/debian/changelog index 2a1f59b0..b9745f2d 100755 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +meegram (0.1.3) unstable; urgency=low + + * Add chat mute menu + * Bug fixes and performance improvements. + + -- Chukwudi Nwutobo Fri, 07 Jan 2022 19:47:26 +0100 + meegram (0.1.1) unstable; urgency=low * Bug fixes and performance improvements. diff --git a/resources/qml/MessagePage.qml b/resources/qml/MessagePage.qml index 896141df..849ffa8a 100644 --- a/resources/qml/MessagePage.qml +++ b/resources/qml/MessagePage.qml @@ -6,7 +6,10 @@ import "components" Page { id: root - property string chatId: "" + property variant chat: null + property int replyMessageId: 0 + property int editMessageId: 0 + property bool loading: true Flickable { @@ -366,6 +369,6 @@ Page { } } - Component.onCompleted: myMessageModel.openChat(chatId) + Component.onCompleted: myMessageModel.openChat(chat.id) Component.onDestruction: myMessageModel.closeChat() } diff --git a/resources/qml/components/ChatItem.qml b/resources/qml/components/ChatItem.qml index 9775f986..c4790325 100644 --- a/resources/qml/components/ChatItem.qml +++ b/resources/qml/components/ChatItem.qml @@ -134,7 +134,7 @@ Item { anchors.fill: parent onClicked: { - pageStack.push(Qt.createComponent("qrc:/qml/MessagePage.qml"), { chatId: myChatModel.get(index).id }) + pageStack.push(Qt.createComponent("qrc:/qml/MessagePage.qml"), { chat: myChatModel.get(index) }) } onPressAndHold: root.pressAndHold() } diff --git a/resources/qml/components/MessageBubble.qml b/resources/qml/components/MessageBubble.qml index a18e80f5..bfb7978e 100644 --- a/resources/qml/components/MessageBubble.qml +++ b/resources/qml/components/MessageBubble.qml @@ -4,12 +4,6 @@ import com.nokia.meego 1.1 Item { id: root - property string sender: model.sender - property string date: model.date - property bool isOutgoing: model.isOutgoing - - property bool isServiceMessage: model.isServiceMessage - property alias content: contentItem.children property int childrenWidth @@ -17,17 +11,17 @@ Item { signal clicked signal pressAndHold - height: isServiceMessage ? contentItem.children[0].height + 30 : contentItem.children[0].height + messageDate.height + (senderLabel.text !== "" ? senderLabel.height : 0) + (isOutgoing ? 28 : 30); + height: model.isServiceMessage ? contentItem.children[0].height + 30 : contentItem.children[0].height + messageDate.height + (senderLabel.text !== "" ? senderLabel.height : 0) + (model.isOutgoing ? 28 : 30); width: parent.width BorderImage { height: parent.height + (isOutgoing ? 2 : 0) - width: Math.max(childrenWidth, messageDate.paintedWidth + (isOutgoing ? 28 : 0), senderLabel.paintedWidth) + 26 + width: Math.max(childrenWidth, messageDate.paintedWidth + (model.isOutgoing ? 28 : 0), senderLabel.paintedWidth) + 26 anchors { left: parent.left - leftMargin: isServiceMessage ? (parent.width - width) / 2 : isOutgoing ? 10 : parent.width - width - 10 + leftMargin: model.isServiceMessage ? (parent.width - width) / 2 : model.isOutgoing ? 10 : parent.width - width - 10 top: parent.top - topMargin: isServiceMessage ? 2 : isOutgoing ? 8 : 1 + topMargin: model.isServiceMessage ? 2 : model.isOutgoing ? 8 : 1 } source: internal.getBubbleImage(); @@ -51,7 +45,7 @@ Item { width: parent.width -100 anchors { left: parent.left; leftMargin: 80 } color: "white" - text: sender + text: model.sender font.pixelSize: 20 font.bold: true wrapMode: Text.WrapAnywhere @@ -66,7 +60,7 @@ Item { height: contentItem.children[0].height anchors { top: parent.top - topMargin: isServiceMessage ? 15 : senderLabel.text === "" ? 16 : 46 + topMargin: model.isServiceMessage ? 15 : senderLabel.text === "" ? 16 : 46 } } @@ -80,12 +74,12 @@ Item { top: contentItem.bottom topMargin: 4 } - text: date - color: isOutgoing ? "black" : "white" + text: model.date + color: model.isOutgoing ? "black" : "white" font.pixelSize: 16 font.weight: Font.Light - horizontalAlignment: isServiceMessage ? Text.AlignHCenter : isOutgoing ? Text.AlignLeft : Text.AlignRight - visible: !isServiceMessage + horizontalAlignment: model.isServiceMessage ? Text.AlignHCenter : model.isOutgoing ? Text.AlignLeft : Text.AlignRight + visible: !model.isServiceMessage } QtObject { @@ -93,10 +87,10 @@ Item { function getBubbleImage() { var imageSrc = "qrc:/images/"; - if (isServiceMessage) { + if (model.isServiceMessage) { imageSrc += "notification" } else { - imageSrc += isOutgoing ? "outgoing" : "incoming" + imageSrc += model.isOutgoing ? "outgoing" : "incoming" imageSrc += mouseArea.pressed ? "-pressed" : "-normal" } diff --git a/src/ChatModel.cpp b/src/ChatModel.cpp index f39da90c..bbd6ae61 100644 --- a/src/ChatModel.cpp +++ b/src/ChatModel.cpp @@ -7,6 +7,36 @@ #include +namespace detail { + +QString getChatType(qint64 chatId) +{ + auto chat = TdApi::getInstance().chatStore->get(chatId); + + auto type = chat.value("type").toMap(); + auto chatType = type.value("@type").toByteArray(); + + switch (fnv::hashRuntime(chatType.constData())) + { + case fnv::hash("chatTypePrivate"): + return "private"; + case fnv::hash("chatTypeSecret"): + return "secret"; + case fnv::hash("chatTypeBasicGroup"): + return "group"; + case fnv::hash("chatTypeSupergroup"): { + if (type.value("is_channel").toBool()) + return "channel"; + + return "supergroup"; + } + } + + return {}; +} + +} // namespace detail + ChatModel::ChatModel(QObject *parent) : QAbstractListModel(parent) , m_sortTimer(new QTimer(this)) @@ -83,7 +113,7 @@ QVariant ChatModel::data(const QModelIndex &index, int role) const case IdRole: return QString::number(chatId); case TypeRole: - return {}; + return detail::getChatType(chatId); case TitleRole: return Utils::getChatTitle(chatId, true); case PhotoRole: { diff --git a/src/Common.hpp b/src/Common.hpp index 16f28468..1740457f 100644 --- a/src/Common.hpp +++ b/src/Common.hpp @@ -3,7 +3,7 @@ #include static constexpr auto AppName = "MeeGram"; -static constexpr auto AppVersion = "0.1.1"; +static constexpr auto AppVersion = "0.1.3"; static constexpr auto ApiId = 142713; static constexpr auto ApiHash = "9e9e687a70150c6436afe3a2b6bfd7d7";