Commit 001c5b9b authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Add a few actions on messages (copy text, open image/video in app)

Better handling of notifications (in C++)
parent 8735f10b
......@@ -164,6 +164,62 @@ Page {
id: delegateMsg;
contentHeight: layoutMessage.height;
menu: ContextMenu {
MenuItem {
text: qsTr ("Copy text");
visible: (formattedTextItem !== null);
onClicked: {
Clipboard.text = formattedTextItem.text;
}
readonly property TD_MessageText messageTextItem : (delegateMsg.messageItem &&
delegateMsg.messageItem.content &&
delegateMsg.messageItem.content.typeOf === TD_ObjectType.MESSAGE_TEXT
? delegateMsg.messageItem.content
: null);
readonly property TD_FormattedText formattedTextItem : (messageTextItem ? messageTextItem.text : null);
}
MenuItem {
text: qsTr ("Open image in viewer");
visible: (photoSizeItem !== null);
enabled: (photoSizeItem && photoSizeItem.photo && photoSizeItem.photo.local && photoSizeItem.photo.local.isDownloadingCompleted);
onClicked: {
Qt.openUrlExternally (TD_Global.urlFromLocalPath (photoSizeItem.photo.local.path));
}
readonly property TD_MessagePhoto messagePhotoItem : (delegateMsg.messageItem &&
delegateMsg.messageItem.content &&
delegateMsg.messageItem.content.typeOf === TD_ObjectType.MESSAGE_PHOTO
? delegateMsg.messageItem.content
: null);
readonly property TD_Photo photoItem : (messagePhotoItem ? messagePhotoItem.photo : null);
readonly property TD_PhotoSize photoSizeItem : {
var ret = null;
if (photoItem && photoItem.sizes.count > 0) {
var tmp = photoItem.sizes.get ("x");
ret = (tmp ? tmp : photoItem.sizes.getLast ());
}
return ret;
}
}
MenuItem {
text: qsTr ("Open video with player");
visible: (videoItem !== null);
enabled: (videoItem && videoItem.video && videoItem.video.local && videoItem.video.local.isDownloadingCompleted);
onClicked: {
Qt.openUrlExternally (TD_Global.urlFromLocalPath (videoItem.video.local.path));
}
readonly property TD_MessageVideo messageVideoItem : (delegateMsg.messageItem &&
delegateMsg.messageItem.content &&
delegateMsg.messageItem.content.typeOf === TD_ObjectType.MESSAGE_VIDEO
? delegateMsg.messageItem.content
: null);
readonly property TD_Video videoItem : (messageVideoItem ? messageVideoItem.video : null);
}
MenuItem {
text: qsTr ("Reply [TODO]");
enabled: false;
......
......@@ -406,22 +406,8 @@ Page {
onClicked: {
pageStack.push (compoPageChat, {
"currentChat" : chatItem,
});
}
onUnreadCountChanged: {
updateNotif ();
}
onLastMsgItemChanged: {
updateNotif ();
}
onDescriptionChanged: {
updateNotif ();
}
Component.onCompleted: {
updateNotif ();
}
Component.onDestruction: {
notification.close ();
},
PageStackAction.Animated);
}
readonly property TD_Chat chatItem : modelData;
......@@ -432,57 +418,16 @@ Page {
readonly property int unreadCount : (chatItem.notificationSettings.muteFor === 0 ? chatItem.unreadCount : 0);
readonly property string description : (lastMsgItem ? lastMsgItem.preview () : "");
function updateNotif () {
if (lastMsgItem) {
notification.summary = chatItem.title;
notification.appIcon = avatarChat.url;
notification.icon = avatarChat.url;
notification.body = description;
notification.timestamp = lastMsgItem.date;
notification.itemCount = unreadCount;
if (TD_Global.currentChat !== chatItem && !lastMsgItem.isOutgoing) {
notification.previewSummary = chatItem.title;
notification.previewBody = description;
}
else {
notification.previewSummary = "";
notification.previewBody = "";
}
if (unreadCount > 0) {
notification.publish ();
}
else {
notification.close ();
}
}
}
Notification {
id: notification;
appName: "Telegra'me";
maxContentLines: 3;
remoteActions: [
{
"name" : "default",
"displayName ": "Show chat",
"icon" : "",
"service" : "org.uniqueconception.telegrame",
"path" : "/org/uniqueconception/telegrame",
"iface" : "org.uniqueconception.telegrame",
"method" : "showChat",
"arguments" : [
"argument",
delegateChat.chatItem.id,
]
}
]
onClicked: {
Connections {
target: delegateChat.chatItem;
onDisplayRequested: {
console.log ("DISPLAY REQUESTED", delegateChat.chatItem.id);
window.activate ();
while (pageStack.depth > 1) {
pageStack.navigateBack (PageStackAction.Immediate);
}
pageStack.push (compoPageChat, {
"currentChat" : delegateChat.chatItem
"currentChat" : delegateChat.chatItem,
},
PageStackAction.Immediate);
}
......
#include "QtTdLibChat.h"
QtTdLibChatPhoto::QtTdLibChatPhoto (QObject * parent)
: QtTdLibAbstractObject { QtTdLibObjectType::CHAT_PHOTO, parent }
{ }
void QtTdLibChatPhoto::updateFromJson (const QJsonObject & json) {
set_big_withJSON (json ["big"].toObject (), &QtTdLibFile::create);
set_small_withJSON (json ["small"].toObject (), &QtTdLibFile::create);
}
QtTdLibChat::QtTdLibChat (const qint64 id, QObject * parent)
: QtTdLibAbstractInt53IdObject { QtTdLibObjectType::CHAT, id, parent }
, m_isCurrentChat { false }
{
QtTdLibCollection::allChats.insert (id, this);
static const QString ICON { "/usr/share/icons/hicolor/128x128/apps/harbour-telegrame.png" };
m_notif.setAppName ("Telegra'me");
m_notif.setIcon (ICON);
m_notif.setAppIcon (ICON);
m_notif.setMaxContentLines (3);
m_notif.setRemoteAction (Notification::remoteAction ("default",
"Show chat",
"org.uniqueconception.telegrame",
"/org/uniqueconception/telegrame",
"org.uniqueconception.telegrame",
"showChat",
QVariantList { /*"argument",*/ get_id () }));
connect (this, &QtTdLibChat::titleChanged, this, &QtTdLibChat::refreshNotification);
connect (this, &QtTdLibChat::unreadCountChanged, this, &QtTdLibChat::refreshNotification);
connect (this, &QtTdLibChat::isCurrentChatChanged, this, &QtTdLibChat::refreshNotification);
connect (&messagesModel, &QQmlFastObjectListModelBase::lastChanged, this, &QtTdLibChat::refreshNotification);
connect (&m_timer, &QTimer::timeout, this, [this] (void) {
if (m_unreadCount > 0 && !m_isCurrentChat && m_notificationSettings != Q_NULLPTR && m_notificationSettings->get_muteFor () == 0) {
if (QtTdLibMessage * lastMsg = { messagesModel.getLast () }) {
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.setPreviewSummary (m_title);
m_notif.publish ();
}
else {
m_notif.close ();
}
}
else {
m_notif.close ();
}
});
connect (&m_notif, &Notification::clicked, this, [this] (void) {
qWarning () << "CLICKED" << get_id ();
emit displayRequested ();
});
m_timer.setTimerType (Qt::CoarseTimer);
m_timer.setSingleShot (true);
m_timer.setInterval (350);
}
QtTdLibChat::~QtTdLibChat (void) {
m_timer.stop ();
m_notif.close ();
}
void QtTdLibChat::refreshNotification (void) {
m_timer.start ();
}
QtTdLibMessage * QtTdLibChat::getMessageItemById (const QString & id) const {
......@@ -66,6 +109,15 @@ void QtTdLibChat::updateFromJson (const QJsonObject & json) {
set_notificationSettings_withJSON (json ["notification_settings"].toObject (), &QtTdLibChatNotificationSettings::create);
}
QtTdLibChatPhoto::QtTdLibChatPhoto (QObject * parent)
: QtTdLibAbstractObject { QtTdLibObjectType::CHAT_PHOTO, parent }
{ }
void QtTdLibChatPhoto::updateFromJson (const QJsonObject & json) {
set_big_withJSON (json ["big"].toObject (), &QtTdLibFile::create);
set_small_withJSON (json ["small"].toObject (), &QtTdLibFile::create);
}
QtTdLibChatType::QtTdLibChatType (const QtTdLibObjectType::Type typeOf, QObject * parent)
: QtTdLibAbstractObject { typeOf, parent }
{ }
......
#ifndef QTTDCHAT_H
#define QTTDCHAT_H
#include <nemonotifications-qt5/notification.h>
#include <QTimer>
#include "QQmlFastObjectListModel.h"
#include "QtTdLibCommon.h"
......@@ -240,9 +244,11 @@ class QtTdLibChat : public QtTdLibAbstractInt53IdObject, public FactoryInt53Id<Q
QML_FASTOBJMODEL_PROPERTY (messagesModel, QtTdLibMessage)
//last_message:message
//draft_message:draftMessage
QML_READONLY_VAR_PROPERTY (isCurrentChat, bool)
public:
explicit QtTdLibChat (const qint64 id = 0, QObject * parent = Q_NULLPTR);
virtual ~QtTdLibChat (void);
QHash<qint64, QtTdLibMessage *> allMessages;
......@@ -254,6 +260,16 @@ public:
void removeMessageItem (QtTdLibMessage * messageItem);
void updateFromJson (const QJsonObject & json) Q_DECL_FINAL;
signals:
void displayRequested (void);
protected slots:
void refreshNotification (void);
private:
QTimer m_timer;
Notification m_notif;
};
#endif // QTTDCHAT_H
......@@ -320,6 +320,7 @@ void QtTdLibGlobal::setUserOnlineState (const bool online) {
void QtTdLibGlobal::openChat (QtTdLibChat * chatItem) {
closeChat (m_currentChat);
if (chatItem != Q_NULLPTR) {
chatItem->set_isCurrentChat (true);
set_currentChat (chatItem);
send (QJsonObject {
{ "@type", "openChat" },
......@@ -331,6 +332,7 @@ void QtTdLibGlobal::openChat (QtTdLibChat * chatItem) {
void QtTdLibGlobal::closeChat (QtTdLibChat * chatItem) {
if (chatItem != Q_NULLPTR) {
chatItem->set_isCurrentChat (false);
set_currentChat (Q_NULLPTR);
send (QJsonObject {
{ "@type", "closeChat" },
......@@ -911,7 +913,7 @@ void QtTdLibGlobal::onFrame (const QJsonObject & json) {
}
}
if (!messagesListJson.isEmpty ()) {
m_autoPreFetcher->start (850);
m_autoPreFetcher->start (150);
}
break;
}
......@@ -1051,10 +1053,10 @@ void QtTdLibGlobal::onFrame (const QJsonObject & json) {
void QtTdLibGlobal::onPrefetcherTick (void) {
if (m_currentChat != Q_NULLPTR) {
if (m_currentChat->messagesModel.count () < 50 ||
if (m_currentChat->messagesModel.count () < 30 ||
(m_currentChat->get_unreadCount () > 0 &&
m_currentChat->getMessageItemById (m_currentChat->get_lastReadInboxMessageId ()) == Q_NULLPTR)) {
loadMoreMessages (m_currentChat, 15); // FIXME : maybe a better way...
loadMoreMessages (m_currentChat, 30); // FIXME : maybe a better way...
}
}
}
......
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