Skip to content
This repository has been archived by the owner on Apr 15, 2022. It is now read-only.

Commit

Permalink
Load additional messages for replies and stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
curoviyxru committed Apr 2, 2022
1 parent 0e0b881 commit 22524e9
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 14 deletions.
1 change: 1 addition & 0 deletions rc/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<file>icons/hicolor/scalable/options.svg</file>
<file>styles/stylesheet.css</file>
<file>icons/hicolor/80x80/apps/kutegram.png</file>
<file>icons/hicolor/48x48/apps/kutegram.png</file>
</qresource>
</RCC>
16 changes: 11 additions & 5 deletions src/devicehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ bool isInSilentMode()

void showChatIcon()
{
//TODO: QSystemTrayIcon
#if defined(Q_OS_SYMBIAN) && defined(SYMBIAN3_READY)
static bool chatIconStatus = false;
if (!chatIconStatus) {
Expand All @@ -63,6 +64,7 @@ void showChatIcon()

void hideChatIcon()
{
//TODO: QSystemTrayIcon
#if defined(Q_OS_SYMBIAN) && defined(SYMBIAN3_READY)
RProperty iProperty;
iProperty.Set(KPSUidCoreApplicationUIs, KCoreAppUIsUipInd, ECoreAppUIsDoNotShow);
Expand Down Expand Up @@ -96,18 +98,22 @@ void notificationBlink(int device) {

void showSystemNotificationPopup(QString title, QString message)
{
//TODO: only 1 message in 5 seconds
#if defined(Q_OS_SYMBIAN) && defined(SYMBIAN3_READY)
static TUid symbianUid = {SYMBIAN_UID};
TPtrC16 sTitle(reinterpret_cast<const TUint16*>(title.utf16()));
TPtrC16 sMessage(reinterpret_cast<const TUint16*>(message.utf16()));
//TODO: icon?
TRAP_IGNORE(CAknDiscreetPopup::ShowGlobalPopupL(sTitle, sMessage, KAknsIIDNone, KNullDesC, 0, 0, KAknDiscreetPopupDurationLong, 0, NULL, symbianUid));
#elif !defined(Q_OS_SYMBIAN)
QSystemTrayIcon icon;
icon.show();
icon.setToolTip("Kutegram");
icon.showMessage(title, message);
icon.hide();
static QSystemTrayIcon* icon = 0;
if (!icon) {
icon = new QSystemTrayIcon();
icon->setIcon(QIcon(":/icons/hicolor/48x48/apps/kutegram.png"));
icon->setToolTip("Kutegram");
icon->show();
}
icon->showMessage(title, message, QSystemTrayIcon::Information, 2000);
#endif
}

Expand Down
51 changes: 46 additions & 5 deletions src/historywindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ HistoryWindow::HistoryWindow(TelegramClient *client, TObject input, QWidget *par
offsetId(),
offsetDate(),
requestId(),
replyRequestId(),
loadEnds(),
messages(),
labels(),
replies(),
chats(),
users(),
lastMin(),
Expand Down Expand Up @@ -110,7 +112,7 @@ void HistoryWindow::loadMessages()
{
QMutexLocker locker(&loadMutex);

if (requestId || loadEnds) return;
if (replyRequestId || requestId || loadEnds) return;
requestId = client->getHistory(peer, offsetId, offsetDate, 0, 40);
}

Expand All @@ -122,9 +124,10 @@ void HistoryWindow::client_gotMessages(qint64 mtm, qint32 count, TVector m, TVec
gotHistoryMessages(mtm, count, m, c, u, offsetIdOffset, nextRate, inexact);
requestId = 0;
}
// else if (mtm == replyRequestId) {
// gotReplyMessages(mtm, count, m, c, u, offsetIdOffset, nextRate, inexact);
// }
else if (mtm == replyRequestId) {
gotReplyMessages(mtm, count, m, c, u, offsetIdOffset, nextRate, inexact);
replyRequestId = 0;
}
}

void HistoryWindow::gotHistoryMessages(qint64 mtm, qint32 count, TVector m, TVector c, TVector u, qint32 offsetIdOffset, qint32 nextRate, bool inexact)
Expand All @@ -140,6 +143,7 @@ void HistoryWindow::gotHistoryMessages(qint64 mtm, qint32 count, TVector m, TVec
users.insert(item["id"].toLongLong(), item);
}

TVector notFoundReplies;
for (qint32 i = 0; i < m.size(); ++i) {
TObject msg = m[i].toMap();
messages.insert(msg["id"].toInt(), msg);
Expand All @@ -151,8 +155,42 @@ void HistoryWindow::gotHistoryMessages(qint64 mtm, qint32 count, TVector m, TVec
}

for (qint32 i = 0; i < m.size(); ++i) {
addMessageWidget(m[i].toMap(), true);
TObject msg = m[i].toMap();

qint32 replyingId = msg["reply_to"].toMap()["reply_to_msg_id"].toInt();
if (ID(msg["reply_to"].toMap()) && !ID(messages[replyingId])) {
notFoundReplies.append(getInputMessage(msg["reply_to"].toMap()));
replies.insert(replyingId, msg);
TGOBJECT(emptyMessage, MessageEmpty);
messages.insert(replyingId, emptyMessage);
}

addMessageWidget(msg, true);
}

if (!notFoundReplies.isEmpty())
replyRequestId = client->getMessages(notFoundReplies);
}

void HistoryWindow::gotReplyMessages(qint64 mtm, qint32 count, TVector m, TVector c, TVector u, qint32 offsetIdOffset, qint32 nextRate, bool inexact)
{
for (qint32 i = 0; i < c.size(); ++i) {
TObject item = c[i].toMap();
chats.insert(item["id"].toLongLong(), item);
}

for (qint32 i = 0; i < u.size(); ++i) {
TObject item = u[i].toMap();
users.insert(item["id"].toLongLong(), item);
}

for (qint32 i = 0; i < m.size(); ++i) {
TObject msg = m[i].toMap();
messages.insert(msg["id"].toInt(), msg);
updateMessageWidget(replies[msg["id"].toInt()]);
}

replies.clear();
}

TObject HistoryWindow::getMessagePeer(TObject msg)
Expand Down Expand Up @@ -246,6 +284,9 @@ void HistoryWindow::client_updateDeleteMessages(TVector msgs, qint32 pts, qint32
{
QMutexLocker locker(&loadMutex);

//TODO: test PTS sequence
//TODO: load needed information

for (qint32 i = 0; i < msgs.size(); ++i) {
qint32 id = msgs[i].toInt();
messages.remove(id);
Expand Down
2 changes: 2 additions & 0 deletions src/historywindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ public slots:
qint32 offsetId;
qint32 offsetDate;
qint64 requestId;
qint64 replyRequestId;
bool loadEnds;

QHash<qint32, TObject> messages;
QHash<qint64, TObject> chats;
QHash<qint64, TObject> users;
QHash<qint32, MessageLabel*> labels;
QHash<qint32, TObject> replies;

qint32 lastMin;
qint32 lastMax;
Expand Down
2 changes: 1 addition & 1 deletion src/library
3 changes: 3 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ void MainWindow::dialogView_activated(QModelIndex index)
void MainWindow::client_updateNewMessage(TObject msg, qint32 pts, qint32 pts_count)
{
//TODO: improve it.
if (getPeerId(msg["from_id"].toMap()).toLongLong() == client->userId() ||
getPeerId(msg["peer_id"].toMap()).toLongLong() == client->userId()) return;

showNotification(QApplication::translate("MainWindow", "New message", 0, QApplication::UnicodeUTF8),
msg["message"].toString().mid(0, 40));
}
9 changes: 6 additions & 3 deletions src/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QStringList>
#include <QDebug>
#include <QApplication>
#include "tlschema.h"
#include "avatars.h"

Expand Down Expand Up @@ -29,14 +30,16 @@ QString peerNameToHtml(TObject peer)

QString replyToHtml(TObject reply, TObject replyPeer)
{
if (ID(reply) != Message) {
qint32 id = ID(reply);
if (id != Message && id != MessageEmpty) {
qWarning() << "[replyToHtml] Invalid object." << ID(reply);
return QString();
}

QString replyText = reply["message"].toString().replace('\n', " ");
QString replyText = id == MessageEmpty ? QApplication::translate("Messages", "Loading...", 0, QApplication::UnicodeUTF8) : reply["message"].toString().replace('\n', " ");
QString peerName = id == MessageEmpty ? replyText : peerNameToHtml(replyPeer);

return "<table><tr><td style=\"background-color:" + userColor(replyPeer["id"].toLongLong()).name() + ";\">&nbsp;</td><td>&nbsp;" + peerNameToHtml(replyPeer) + "<br>&nbsp;" + replyText.mid(0, 40) + (replyText.length() > 40 ? "..." : "") + "</td></tr></table>";
return "<table><tr><td style=\"background-color:" + userColor(replyPeer["id"].toLongLong()).name() + ";\">&nbsp;</td><td>&nbsp;" + peerName + "<br>&nbsp;" + replyText.mid(0, 40) + (replyText.length() > 40 ? "..." : "") + "</td></tr></table>";
}

QString messageToHtml(TObject message)
Expand Down

0 comments on commit 22524e9

Please sign in to comment.