Commit 963ff78c authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Pinned messages support in messages view and header

parent 82f991c3
......@@ -757,6 +757,7 @@ ApplicationWindow {
ColumnContainer {
id: delegateMsgText;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageText messageContentItem : null;
......@@ -876,6 +877,7 @@ ApplicationWindow {
ColumnContainer {
id: delegateMsgPhoto;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessagePhoto messageContentItem : null;
......@@ -911,6 +913,7 @@ ApplicationWindow {
id: delegateMsgDocument;
spacing: Theme.paddingMedium;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageDocument messageContentItem : null;
......@@ -1044,6 +1047,7 @@ ApplicationWindow {
ColumnContainer {
id: delegateMsgSticker;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageSticker messageContentItem : null;
......@@ -1099,6 +1103,7 @@ ApplicationWindow {
ColumnContainer {
id: delegateMsgVideo;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageVideo messageContentItem : null;
......@@ -1205,6 +1210,7 @@ ApplicationWindow {
ColumnContainer {
id: delegateMsgAudio;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageAudio messageContentItem : null;
......@@ -1341,6 +1347,7 @@ ApplicationWindow {
id: delegateMsgAnimation;
implicitHeight: placeholderAnim.height;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageAnimation messageContentItem : null;
......@@ -1439,6 +1446,7 @@ ApplicationWindow {
id: delegateMsgVoiceNote;
spacing: Theme.paddingSmall;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageVoiceNote messageContentItem : null;
......@@ -1589,6 +1597,7 @@ ApplicationWindow {
wrapMode: Text.WrapAtWordBoundaryOrAnywhere;
font.italic: true;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageChatJoinByLink messageContentItem : null;
}
......@@ -1600,6 +1609,7 @@ ApplicationWindow {
id: delegateMsgChatAddMembers;
spacing: Theme.paddingSmall;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageChatAddMembers messageContentItem : null;
......@@ -1646,6 +1656,7 @@ ApplicationWindow {
id: delegateMsgChatDeleteMember;
spacing: Theme.paddingSmall;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageChatDeleteMember messageContentItem : null;
......@@ -1694,6 +1705,7 @@ ApplicationWindow {
wrapMode: Text.WrapAtWordBoundaryOrAnywhere;
font.italic: true;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageChatChangeTitle messageContentItem : null;
}
......@@ -1707,6 +1719,7 @@ ApplicationWindow {
wrapMode: Text.WrapAtWordBoundaryOrAnywhere;
font.italic: true;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageChatUpgradeFrom messageContentItem : null;
}
......@@ -1720,6 +1733,7 @@ ApplicationWindow {
wrapMode: Text.WrapAtWordBoundaryOrAnywhere;
font.italic: true;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageChatUpgradeTo messageContentItem : null;
}
......@@ -1733,8 +1747,30 @@ ApplicationWindow {
wrapMode: Text.WrapAtWordBoundaryOrAnywhere;
font.italic: true;
property TD_Message messageItem : null;
property TD_MessageContactRegistered messageContentItem : null;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessagePinMessage messageContentItem : null;
}
}
Component {
id: compoMsgPinMessage;
LabelFixed {
text: (messageContentItem
? (messageContentItem.messageId !== "0"
? qsTr ("Pinned message : %1").arg (pinnedMessageItem ? pinnedMessageItem.preview (TD_Message.MINIMAL) : qsTr ("deleted message"))
: qsTr ("Unpinned message"))
: "")
color: Theme.secondaryHighlightColor;
wrapMode: Text.WrapAtWordBoundaryOrAnywhere;
font.italic: true;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessagePinMessage messageContentItem : null;
readonly property TD_MessageRefWatcher pinnedMsgRefWatcher : (chatItem ? chatItem.getMessageRefById (messageContentItem.messageId) : null);
readonly property TD_Message pinnedMessageItem : (pinnedMsgRefWatcher ? pinnedMsgRefWatcher.messageItem : null);
}
}
Component {
......@@ -1746,6 +1782,7 @@ ApplicationWindow {
wrapMode: Text.WrapAtWordBoundaryOrAnywhere;
font.italic: true;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageBasicGroupChatCreate messageContentItem : null;
}
......@@ -1759,6 +1796,7 @@ ApplicationWindow {
wrapMode: Text.WrapAtWordBoundaryOrAnywhere;
font.italic: true;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageSupergroupChatCreate messageContentItem : null;
}
......@@ -1783,6 +1821,7 @@ ApplicationWindow {
wrapMode: Text.WrapAtWordBoundaryOrAnywhere;
font.italic: true;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageCall messageContentItem : null;
......@@ -1796,6 +1835,7 @@ ApplicationWindow {
id: delegateMsgChatChangePhoto;
spacing: Theme.paddingSmall;
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageChatChangePhoto messageContentItem : null;
......@@ -1824,6 +1864,7 @@ ApplicationWindow {
text: qsTr ("<Unsupported>");
color: "magenta";
property TD_Chat chatItem : null;
property TD_Message messageItem : null;
property TD_MessageContent messageContentItem : null;
}
......
......@@ -56,6 +56,14 @@ Page {
? replyingToMessageRefWatcher.messageItem
: null);
readonly property TD_MessageRefWatcher pinnedMessageRefWatcher : (currentChatSupergroupItem && currentChatSupergroupItem.pinnedMessageId
? currentChat.getMessageRefById (currentChatSupergroupItem.pinnedMessageId)
: null);
readonly property TD_Message pinnedMessageItem : (pinnedMessageRefWatcher
? pinnedMessageRefWatcher.messageItem
: null);
readonly property TD_User currentChatUserItem : (currentChat && currentChat.type.typeOf === TD_ObjectType.CHAT_TYPE_PRIVATE
? TD_Global.getUserItemById (currentChat.type ["userId"])
: null);
......@@ -185,7 +193,7 @@ Page {
}
model: (currentChat ? currentChat.messagesModel : 0);
spaceBefore: headerChat.height;
spaceBefore: (headerChat.height + (stripPinned.visible ? stripPinned.height : 0));
//spaceAfter: footerChat.height;
delegate: ListItem {
id: delegateMsg;
......@@ -319,6 +327,12 @@ Page {
value: delegateMsg.messageItem;
when: (loaderMsgContent.item && delegateMsg.messageItem);
}
Binding {
target: loaderMsgContent.item;
property: "chatItem";
value: currentChat;
when: (loaderMsgContent.item && currentChat);
}
ColumnContainer {
id: layoutMessage;
spacing: Theme.paddingSmall;
......@@ -389,7 +403,7 @@ Page {
ExtraAnchors.horizontalFill: parent;
}
LabelFixed {
text: qsTr ("<b>Reply</b>: %1").arg (originalMessageItem ? originalMessageItem.preview (true).replace (/\n/g, "<br>") : qsTr ("<i>deleted message</i>"));
text: qsTr ("<b>Reply</b>: %1").arg (originalMessageItem ? originalMessageItem.preview (TD_Message.SHOW_TITLE | TD_Message.MULTILINE).replace (/\n/g, "<br>") : qsTr ("<i>deleted message</i>"));
color: Theme.secondaryHighlightColor;
elide: Text.ElideRight;
visible: originalMsgRefWatcher;
......@@ -433,6 +447,7 @@ Page {
case TD_ObjectType.MESSAGE_CHAT_UPGRADE_FROM: return compoMsgChatUpgradeFrom;
case TD_ObjectType.MESSAGE_CHAT_UPGRADE_TO: return compoMsgChatUpgradeTo;
case TD_ObjectType.MESSAGE_CONTACT_REGISTERED: return compoMsgChatContactRegistered;
case TD_ObjectType.MESSAGE_PIN_MESSAGE: return compoMsgPinMessage;
case TD_ObjectType.MESSAGE_BASIC_GROUP_CHAT_CREATE: return compoMsgBasicGroupChatCreate;
case TD_ObjectType.MESSAGE_SUPERGROUP_CHAT_CREATE: return compoMsgSupergroupChatCreate;
}
......@@ -642,7 +657,7 @@ Page {
ExtraAnchors.horizontalFill: parent;
LabelFixed {
text: qsTr ("<b>Reply</b>: %1").arg (replyingToMessageItem ? replyingToMessageItem.preview (true).replace (/\n/g, "<br>") : qsTr ("<i>deleted message</i>"));
text: qsTr ("<b>Reply</b>: %1").arg (replyingToMessageItem ? replyingToMessageItem.preview (TD_Message.SHOW_TITLE | TD_Message.MULTILINE).replace (/\n/g, "<br>") : qsTr ("<i>deleted message</i>"));
color: Theme.secondaryHighlightColor;
elide: Text.ElideRight;
wrapMode: Text.WrapAtWordBoundaryOrAnywhere;
......@@ -661,6 +676,40 @@ Page {
}
}
}
MouseArea {
id: stripPinned;
visible: (pinnedMessageItem !== null);
implicitHeight: (lblPinned.height + lblPinned.anchors.margins * 2);
anchors.top: headerChat.bottom;
ExtraAnchors.horizontalFill: parent;
onClicked: {
longJumpToMsg (pinnedMessageItem.id);
}
Rectangle {
color: Qt.rgba (1.0 - Theme.primaryColor.r, 1.0 - Theme.primaryColor.g, 1.0 - Theme.primaryColor.b, 0.85);
anchors.fill: parent;
Rectangle {
color: Theme.secondaryHighlightColor;
opacity: 0.15;
anchors.fill: parent;
}
}
LabelFixed {
id: lblPinned;
text: qsTr ("<b>Pinned</b>: %1").arg (pinnedMessageItem ? pinnedMessageItem.preview (TD_Message.MINIMAL) : qsTr ("<i>deleted message</i>"));
color: Theme.secondaryHighlightColor;
elide: Text.ElideRight;
textFormat: Text.StyledText;
font.pixelSize: Theme.fontSizeExtraSmall;
anchors {
margins: Theme.paddingSmall;
verticalCenter: parent.verticalCenter;
}
ExtraAnchors.horizontalFill: parent;
}
}
MouseArea {
id: headerChat;
opacity: (pulleyTop.active ? 0.65 : 1.0);
......
......@@ -458,7 +458,7 @@ Page {
readonly property TD_User lastMsgUserItem : (lastMsgItem ? TD_Global.getUserItemById (lastMsgItem.senderUserId) : null);
readonly property TD_MessageContent lastMsgContentItem : (lastMsgItem ? lastMsgItem.content : null);
readonly property int unreadCount : (chatItem.notificationSettings && chatItem.notificationSettings.muteFor === 0 ? chatItem.unreadCount : 0);
readonly property string description : (lastMsgItem ? lastMsgItem.preview () : "");
readonly property string description : (lastMsgItem ? lastMsgItem.preview (TD_Message.SHOW_TITLE) : "");
Connections {
target: delegateChat.chatItem;
......
......@@ -37,8 +37,8 @@ QtTdLibChat::QtTdLibChat (const qint64 id, QObject * parent)
m_notif.setItemCount (m_unreadCount);
m_notif.setSummary (m_title);
m_notif.setTimestamp (lastMsg->get_date ());
m_notif.setBody (lastMsg->preview ());
m_notif.setPreviewBody (lastMsg->preview ());
m_notif.setBody (lastMsg->preview (QtTdLibMessage::SHOW_TITLE));
m_notif.setPreviewBody (lastMsg->preview (QtTdLibMessage::SHOW_TITLE));
m_notif.setPreviewSummary (m_title);
m_notif.publish ();
}
......
......@@ -67,6 +67,7 @@ QtTdLibObjectType::Type QtTdLibEnums::objectTypeEnumFromString (const QString &
{ "messageChatUpgradeFrom", QtTdLibObjectType::MESSAGE_CHAT_UPGRADE_FROM },
{ "messageChatUpgradeTo", QtTdLibObjectType::MESSAGE_CHAT_UPGRADE_TO },
{ "messageContactRegistered", QtTdLibObjectType::MESSAGE_CONTACT_REGISTERED },
{ "messagePinMessage", QtTdLibObjectType::MESSAGE_PIN_MESSAGE },
{ "messageDocument", QtTdLibObjectType::MESSAGE_DOCUMENT },
{ "messagePhoto", QtTdLibObjectType::MESSAGE_PHOTO },
{ "messages", QtTdLibObjectType::MESSAGES },
......
......@@ -71,6 +71,7 @@ QML_ENUM_CLASS (QtTdLibObjectType,
MESSAGE_CHAT_UPGRADE_FROM,
MESSAGE_CHAT_UPGRADE_TO,
MESSAGE_CONTACT_REGISTERED,
MESSAGE_PIN_MESSAGE,
MESSAGE_DOCUMENT,
MESSAGE_PHOTO,
MESSAGE_STICKER,
......
......@@ -29,6 +29,7 @@ QtTdLibMessageContent * QtTdLibMessageContent::createAbstract (const QJsonObject
case QtTdLibObjectType::MESSAGE_CHAT_UPGRADE_TO: return QtTdLibMessageChatUpgradeTo::create (json, parent);
case QtTdLibObjectType::MESSAGE_CHAT_UPGRADE_FROM: return QtTdLibMessageChatUpgradeFrom::create (json, parent);
case QtTdLibObjectType::MESSAGE_CONTACT_REGISTERED: return QtTdLibMessageContactRegistered::create (json, parent);
case QtTdLibObjectType::MESSAGE_PIN_MESSAGE: return QtTdLibMessagePinMessage::create (json, parent);
case QtTdLibObjectType::MESSAGE_CALL: return QtTdLibMessageCall::create (json, parent);
default: return Q_NULLPTR;
}
......@@ -88,21 +89,23 @@ void QtTdLibMessage::updateFromJson (const QJsonObject & json) {
set_content_withJSON (json ["content"], &QtTdLibMessageContent::createAbstract);
}
QString QtTdLibMessage::preview (const bool multiline) const {
QString QtTdLibMessage::preview (const int flags) const {
QString ret { };
if (QtTdLibUser * userItem = { QtTdLibCollection::allUsers.value (m_senderUserId, Q_NULLPTR) }) {
ret += userItem->get_firstName ();
ret += ' ';
ret += userItem->get_lastName ();
ret += " : ";
}
else if (QtTdLibChat * chatItem = { QtTdLibCollection::allChats.value (m_chatId, Q_NULLPTR) }) {
ret += chatItem->get_title ();
ret += " : ";
}
else { }
if (multiline) {
ret += "\n";
if (flags & SHOW_TITLE) {
if (QtTdLibUser * userItem = { QtTdLibCollection::allUsers.value (m_senderUserId, Q_NULLPTR) }) {
ret += userItem->get_firstName ();
ret += ' ';
ret += userItem->get_lastName ();
ret += " : ";
}
else if (QtTdLibChat * chatItem = { QtTdLibCollection::allChats.value (m_chatId, Q_NULLPTR) }) {
ret += chatItem->get_title ();
ret += " : ";
}
else { }
if (flags & MULTILINE) {
ret += "\n";
}
}
if (m_content) {
ret += m_content->asString ();
......@@ -408,6 +411,18 @@ QString QtTdLibMessageContactRegistered::asString (void) const {
return tr ("Registered in Telegram");
}
QtTdLibMessagePinMessage::QtTdLibMessagePinMessage (QObject * parent)
: QtTdLibMessageContent { QtTdLibObjectType::MESSAGE_PIN_MESSAGE, parent }
{ }
void QtTdLibMessagePinMessage::updateFromJson (const QJsonObject & json) {
set_messageId_withJSON (json ["message_id"]);
}
QString QtTdLibMessagePinMessage::asString (void) const {
return tr ("Pinned message");
}
QtTdLibMessageCall::QtTdLibMessageCall (QObject * parent)
: QtTdLibMessageContent { QtTdLibObjectType::MESSAGE_CALL, parent }
{ }
......
......@@ -258,6 +258,18 @@ public:
QString asString (void) const Q_DECL_FINAL;
};
class QtTdLibMessagePinMessage : public QtTdLibMessageContent, public FactoryNoId<QtTdLibMessagePinMessage> {
Q_OBJECT
Q_TDLIB_PROPERTY_ID53 (messageId)
public:
explicit QtTdLibMessagePinMessage (QObject * parent = Q_NULLPTR);
void updateFromJson (const QJsonObject & json) Q_DECL_FINAL;
QString asString (void) const Q_DECL_FINAL;
};
class QtTdLibCallDiscardReason : public QtTdLibAbstractObject {
Q_OBJECT
......@@ -360,7 +372,14 @@ public:
void updateFromJson (const QJsonObject & json) Q_DECL_FINAL;
Q_INVOKABLE QString preview (const bool multiline = false) const;
enum PreviewFlags {
MINIMAL = 0,
SHOW_TITLE = (1 << 1),
MULTILINE = (2 << 1),
};
Q_ENUM (PreviewFlags)
Q_INVOKABLE QString preview (const int flags) const;
};
#endif // QtTdLibMessage_H
......@@ -95,6 +95,7 @@ int main (int argc, char * argv []) {
qmlRegisterType<QtTdLibMessageChatUpgradeFrom> ("harbour.Telegrame", 1, 0, "TD_MessageChatUpgradeFrom");
qmlRegisterType<QtTdLibMessageChatUpgradeTo> ("harbour.Telegrame", 1, 0, "TD_MessageChatUpgradeTo");
qmlRegisterType<QtTdLibMessageContactRegistered> ("harbour.Telegrame", 1, 0, "TD_MessageContactRegistered");
qmlRegisterType<QtTdLibMessagePinMessage> ("harbour.Telegrame", 1, 0, "TD_MessagePinMessage");
qmlRegisterType<QtTdLibMessageContent> ("harbour.Telegrame", 1, 0, "TD_MessageContent");
qmlRegisterType<QtTdLibMessageDocument> ("harbour.Telegrame", 1, 0, "TD_MessageDocument");
qmlRegisterType<QtTdLibMessagePhoto> ("harbour.Telegrame", 1, 0, "TD_MessagePhoto");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment