Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstreaming coderus fixies #10

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 40 additions & 37 deletions autogenerated/clientsyncmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,37 @@

void ClientSyncManager::syncUpdate(Update* u, UpdatesState* clientstate)
{
if(u->constructorId() == TLTypes::UpdateNewMessage)
ClientSyncManager::syncPts(u->pts(), clientstate);
else if(u->constructorId() == TLTypes::UpdateDeleteMessages)
ClientSyncManager::syncPts(u->pts(), clientstate);
else if(u->constructorId() == TLTypes::UpdateUserPhoto)
ClientSyncManager::syncDate(u->date(), clientstate);
else if(u->constructorId() == TLTypes::UpdateContactRegistered)
ClientSyncManager::syncDate(u->date(), clientstate);
else if(u->constructorId() == TLTypes::UpdateNewAuthorization)
ClientSyncManager::syncDate(u->date(), clientstate);
else if(u->constructorId() == TLTypes::UpdateNewEncryptedMessage)
ClientSyncManager::syncQts(u->qts(), clientstate);
else if(u->constructorId() == TLTypes::UpdateEncryption)
ClientSyncManager::syncDate(u->date(), clientstate);
else if(u->constructorId() == TLTypes::UpdateEncryptedMessagesRead)
ClientSyncManager::syncDate(u->date(), clientstate);
else if(u->constructorId() == TLTypes::UpdateChatParticipantAdd)
ClientSyncManager::syncDate(u->date(), clientstate);
else if(u->constructorId() == TLTypes::UpdateReadHistoryInbox)
ClientSyncManager::syncPts(u->pts(), clientstate);
else if(u->constructorId() == TLTypes::UpdateReadHistoryOutbox)
ClientSyncManager::syncPts(u->pts(), clientstate);
else if(u->constructorId() == TLTypes::UpdateWebPage)
ClientSyncManager::syncPts(u->pts(), clientstate);
else if(u->constructorId() == TLTypes::UpdateReadMessagesContents)
ClientSyncManager::syncPts(u->pts(), clientstate);
else if(u->constructorId() == TLTypes::UpdateChannelTooLong)
ClientSyncManager::syncPts(u->pts(), clientstate);
else if(u->constructorId() == TLTypes::UpdateNewChannelMessage)
ClientSyncManager::syncPts(u->pts(), clientstate);
else if(u->constructorId() == TLTypes::UpdateDeleteChannelMessages)
ClientSyncManager::syncPts(u->pts(), clientstate);
else if(u->constructorId() == TLTypes::UpdateEditChannelMessage)
ClientSyncManager::syncPts(u->pts(), clientstate);
else if(u->constructorId() == TLTypes::UpdateEditMessage)
ClientSyncManager::syncPts(u->pts(), clientstate);
switch(u->constructorId()) {
case TLTypes::UpdateNewMessage:
case TLTypes::UpdateDeleteMessages:
case TLTypes::UpdateReadHistoryInbox:
case TLTypes::UpdateReadHistoryOutbox:
case TLTypes::UpdateWebPage:
case TLTypes::UpdateReadMessagesContents:
case TLTypes::UpdateChannelTooLong:
case TLTypes::UpdateEditMessage:
ClientSyncManager::syncPts(u->pts(), clientstate);
break;
case TLTypes::UpdateUserPhoto:
case TLTypes::UpdateContactRegistered:
case TLTypes::UpdateNewAuthorization:
case TLTypes::UpdateEncryption:
case TLTypes::UpdateEncryptedMessagesRead:
case TLTypes::UpdateChatParticipantAdd:
ClientSyncManager::syncDate(u->date(), clientstate);
break;
case TLTypes::UpdateNewChannelMessage:
ClientSyncManager::syncPts(u->pts(), TelegramCache_dialog(u->messageUpdatenewchannelmessage()->toId()->channelId()));
break;
case TLTypes::UpdateEditChannelMessage:
ClientSyncManager::syncPts(u->pts(), TelegramCache_dialog(u->message()->toId()->channelId()));
break;
case TLTypes::UpdateDeleteChannelMessages:
ClientSyncManager::syncPts(u->pts(), TelegramCache_dialog(u->channelId()));
break;
default:
break;
}
}

void ClientSyncManager::syncUpdates(Updates* u, UpdatesState* clientstate)
Expand Down Expand Up @@ -77,7 +72,7 @@ void ClientSyncManager::syncUpdates(Updates* u, UpdatesState* clientstate)
void ClientSyncManager::syncState(UpdatesState* serverstate)
{
UpdatesState* clientstate = TelegramConfig_clientState;

ClientSyncManager::syncPts(serverstate->pts(), clientstate);
ClientSyncManager::syncQts(serverstate->qts(), clientstate);
ClientSyncManager::syncDate(serverstate->date(), clientstate);
Expand All @@ -93,6 +88,14 @@ void ClientSyncManager::syncPts(TLInt pts, UpdatesState* clientstate)
clientstate->setPts(pts);
}

void ClientSyncManager::syncPts(TLInt pts, Dialog *dialog)
{
if(pts <= dialog->pts())
return;

dialog->setPts(pts);
}

void ClientSyncManager::syncQts(TLInt qts, UpdatesState* clientstate)
{
if(qts <= clientstate->qts())
Expand Down
2 changes: 2 additions & 0 deletions autogenerated/clientsyncmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// DO NOT EDIT!!!

#include "../config/telegramconfig.h"
#include "../cache/telegramcache.h"
#include "tltypes.h"
#include "types/updatesstate.h"
#include <QObject>
Expand All @@ -21,6 +22,7 @@ class ClientSyncManager: public QObject
static void syncState(UpdatesState* serverstate);
private:
static void syncPts(TLInt pts, UpdatesState* clientstate);
static void syncPts(TLInt pts, Dialog* dialog);
static void syncQts(TLInt qts, UpdatesState* clientstate);
static void syncDate(TLInt date, UpdatesState* clientstate);
static void syncSeq(TLInt seq, UpdatesState* clientstate);
Expand Down
4 changes: 3 additions & 1 deletion cache/telegramcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,9 @@ void TelegramCache::onChannelTooLong(Update *update)
if(!chat)
return;

this->_fetcher->getChannelDifference(chat, update->pts());
Dialog* dialog = this->dialog(update->channelId());

this->_fetcher->getChannelDifference(chat, dialog ? dialog->pts() : update->pts());
}

void TelegramCache::onUserPhoto(Update *update)
Expand Down
2 changes: 1 addition & 1 deletion models/abstract/telegrammodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define Emit_DataChangedRoles(i, roles) emit dataChanged(this->index(i, 0), this->index(i, 0), QVector<int>() << roles)
#define Emit_DataChangedRangeRoles(first, last, roles) emit dataChanged(this->index(first, 0), this->index(last, 0), QVector<int>() << roles)

#define Safe_MoveIdx(srcidx, destidx) (((destidx >= srcidx) && (destidx <= (srcidx + 1))) ? (destidx + 1) : destidx)
#define Safe_MoveIdx(srcidx, destidx) (destidx > (srcidx + 1) ? (destidx + 1) : destidx)

class TelegramModel : public QAbstractListModel
{
Expand Down
23 changes: 16 additions & 7 deletions models/dialogsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,13 @@ void DialogsModel::onDialogNewMessage(Dialog *dialog)
Emit_DataChanged(idx);
int newidx = this->insertionPoint(dialog);

if(idx == newidx)
if (newidx == idx || newidx == (idx + 1)) {
return;
}

this->beginMoveRows(QModelIndex(), idx, idx, QModelIndex(), Safe_MoveIdx(idx, newidx));
if (!this->beginMoveRows(QModelIndex(), idx, idx, QModelIndex(), Safe_MoveIdx(idx, newidx))) {
return;
}
this->_dialogs.move(idx, newidx);
this->endMoveRows();
}
Expand All @@ -423,10 +426,13 @@ void DialogsModel::onDialogNewDraftMessage(Dialog *dialog)
Emit_DataChanged(idx);
int newidx = this->insertionPoint(dialog);

if(idx == newidx)
if (newidx == idx || newidx == (idx + 1)) {
return;
}

this->beginMoveRows(QModelIndex(), idx, idx, QModelIndex(), Safe_MoveIdx(idx, newidx));
if (!this->beginMoveRows(QModelIndex(), idx, idx, QModelIndex(), Safe_MoveIdx(idx, newidx))) {
return;
}
this->_dialogs.move(idx, newidx);
this->endMoveRows();
}
Expand All @@ -441,11 +447,14 @@ void DialogsModel::onDialogDeleteMessage(Dialog *dialog)
Emit_DataChanged(idx);
int newidx = this->insertionPoint(dialog, idx);

if(idx == newidx)
if (newidx == idx || newidx == (idx + 1)) {
return;
}

this->beginMoveRows(QModelIndex(), idx, idx, QModelIndex(), Safe_MoveIdx(idx, newidx));
this->_dialogs.move(idx, newidx - 1);
if (!this->beginMoveRows(QModelIndex(), idx, idx, QModelIndex(), Safe_MoveIdx(idx, newidx))) {
return;
}
this->_dialogs.move(idx, newidx);
this->endMoveRows();
}

Expand Down
4 changes: 4 additions & 0 deletions mtproto/dc/dcsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ void DCSession::repeatRequests()

MTProtoRequest *DCSession::sendEncrypted(MTProtoStream *mtstream)
{
if (!this->_dc) {
return NULL;
}

MTProtoRequest* req = new MTProtoRequest(this->_dc->config());
req->setSessionId(this->_sessionid);
req->setBody(mtstream); // Take ownership
Expand Down
11 changes: 9 additions & 2 deletions objects/notifications/telegramnotifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ void TelegramNotifications::onLoginCompleted()
{
connect(UpdateHandler_instance, &MTProtoUpdateHandler::newSingleMessage, this, &TelegramNotifications::onIncomingMessage, Qt::UniqueConnection);
connect(TelegramCache_instance, &TelegramCache::readHistory, this, &TelegramNotifications::onReadHistory, Qt::UniqueConnection);
connect(TelegramCache_instance, &TelegramCache::dialogUnreadCountChanged, this, &TelegramNotifications::onReadHistory, Qt::UniqueConnection);
}

void TelegramNotifications::onIncomingMessage(Message *message, TLLong sessionid)
{
if(UpdateHandler_syncing || !DCSessionManager_OwnSession(sessionid))
if(UpdateHandler_syncing/* || !DCSessionManager_OwnSession(sessionid)*/)
return;

if(this->_mute || !this->_telegram || message->isOut() || (message->constructorId() != TLTypes::Message))
Expand All @@ -73,6 +74,10 @@ void TelegramNotifications::onIncomingMessage(Message *message, TLLong sessionid

PeerNotifySettings* notifysettings = dialog->notifySettings();

if (!notifysettings) {
return;
}

if(!message->isMentioned() && (notifysettings->isSilent() || (notifysettings->muteUntil() > 0)))
return;

Expand All @@ -91,5 +96,7 @@ void TelegramNotifications::onReadHistory(Dialog *dialog)
if((dialog->topMessage() - dialog->readInboxMaxId()) > 0)
return;

emit dismissNotification(dialog);
if (dialog->unreadCount() == 0) {
emit dismissNotification(dialog);
}
}