Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
UpdateMessageShort/UpdateChatMessageShort handling
Browse files Browse the repository at this point in the history
This should fix messages receiving in PMs.
  • Loading branch information
curoviyxru committed Apr 17, 2022
1 parent f787f56 commit 5163d2f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
2 changes: 2 additions & 0 deletions telegramapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,6 @@ qint64 TelegramClient::getUpdatesDifference()
getDifference["date"] = this->updateDate;

return sendMTObject<&writeTLMethodUpdatesGetDifference>(getDifference);

//TODO: handle updates.Difference
}
20 changes: 11 additions & 9 deletions telegramstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,21 @@ typedef QVariantList TVector;
typedef QByteArray TInt128;
typedef QByteArray TInt256;

#define TGOBJECT(name, id) \
TelegramObject name; \
#define TOBJECT(name, id) \
TelegramObject name; \
name["_"] = id;

#define TOBJECT(name, id) \
TelegramObject name; \
name["_"] = id;
#define TGOBJECT(name, id) \
TOBJECT(name, id)

#define ID_PROPERTY(name) \
name["_"]

#define GETID(name) \
name["_"].toInt()
#define ID(name) \
ID_PROPERTY(name).toInt()

#define ID(name) \
name["_"].toInt()
#define GETID(name) \
ID(name)

#define INT32_BYTES 4
#define INT64_BYTES 8
Expand Down
35 changes: 31 additions & 4 deletions updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void TelegramClient::handleUpdateShortMessage(QByteArray data, qint64 mtm)
TelegramObject obj = var.toMap();

if (this->updatePts + obj["pts_count"].toInt() == obj["pts"].toInt()) {
//TODO: handle this update.
applyUpdate(obj, mtm);

this->updatePts = qMax(this->updatePts, obj["pts"].toInt());
this->updateDate = qMax(this->updateDate, obj["date"].toInt());
Expand All @@ -40,7 +40,7 @@ void TelegramClient::handleUpdateShortChatMessage(QByteArray data, qint64 mtm)
TelegramObject obj = var.toMap();

if (this->updatePts + obj["pts_count"].toInt() == obj["pts"].toInt()) {
//TODO: handle this update.
applyUpdate(obj, mtm);

this->updatePts = qMax(this->updatePts, obj["pts"].toInt());
this->updateDate = qMax(this->updateDate, obj["date"].toInt());
Expand Down Expand Up @@ -132,8 +132,6 @@ void TelegramClient::handleUpdateShortSentMessage(QByteArray data, qint64 mtm)

void TelegramClient::applyUpdate(TelegramObject obj, qint64 mtm)
{
qDebug() << "[UPD] Got an update with ID:" << QString::number((quint32) GETID(obj), 16);

switch (GETID(obj)) {
case TLType::UpdateNewMessage:
case TLType::UpdateNewChannelMessage:
Expand All @@ -147,6 +145,35 @@ void TelegramClient::applyUpdate(TelegramObject obj, qint64 mtm)
case TLType::UpdateDeleteChannelMessages:
emit updateDeleteMessages(obj["messages"].toList(), obj["pts"].toInt(), obj["pts_count"].toInt());
break;
case TLType::UpdateShortMessage:
{
ID_PROPERTY(obj) = TLType::Message;

TOBJECT(newPeer, TLType::PeerUser);
newPeer["user_id"] = obj["user_id"];
obj["from_id"] = obj["peer_id"] = newPeer;

emit updateNewMessage(obj, obj["pts"].toInt(), obj["pts_count"].toInt());
break;
}
case TLType::UpdateShortChatMessage:
{
ID_PROPERTY(obj) = TLType::Message;

TOBJECT(newUserPeer, TLType::PeerUser);
newUserPeer["user_id"] = obj["from_id"];
obj["from_id"] = newUserPeer;

TOBJECT(newChatPeer, TLType::PeerChat);
newChatPeer["chat_id"] = obj["chat_id"];
obj["peer_id"] = newChatPeer;

emit updateNewMessage(obj, obj["pts"].toInt(), obj["pts_count"].toInt());
break;
}
default:
qDebug() << "[UPD] Got an unhandled update with ID:" << QString::number((quint32) GETID(obj), 16);
break;
}
}

Expand Down

0 comments on commit 5163d2f

Please sign in to comment.