mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 10:11:41 -05:00
new messages.getDialogs() is used for all dialog types (chats, groups, channels, supergroups)
This commit is contained in:
parent
37de0904af
commit
1fa4fd269e
8 changed files with 102 additions and 74 deletions
|
@ -918,11 +918,10 @@ namespace App {
|
|||
return false;
|
||||
}
|
||||
|
||||
void feedMsgs(const MTPVector<MTPMessage> &msgs, NewMessageType type) {
|
||||
const QVector<MTPMessage> &v(msgs.c_vector().v);
|
||||
void feedMsgs(const QVector<MTPMessage> &msgs, NewMessageType type) {
|
||||
QMap<uint64, int32> msgsIds;
|
||||
for (int32 i = 0, l = v.size(); i < l; ++i) {
|
||||
const MTPMessage &msg(v.at(i));
|
||||
for (int32 i = 0, l = msgs.size(); i < l; ++i) {
|
||||
const MTPMessage &msg(msgs.at(i));
|
||||
switch (msg.type()) {
|
||||
case mtpc_message: {
|
||||
const MTPDmessage &d(msg.c_message());
|
||||
|
@ -942,10 +941,14 @@ namespace App {
|
|||
}
|
||||
}
|
||||
for (QMap<uint64, int32>::const_iterator i = msgsIds.cbegin(), e = msgsIds.cend(); i != e; ++i) {
|
||||
histories().addNewMessage(v.at(i.value()), type);
|
||||
histories().addNewMessage(msgs.at(i.value()), type);
|
||||
}
|
||||
}
|
||||
|
||||
void feedMsgs(const MTPVector<MTPMessage> &msgs, NewMessageType type) {
|
||||
return feedMsgs(msgs.c_vector().v, type);
|
||||
}
|
||||
|
||||
ImagePtr image(const MTPPhotoSize &size) {
|
||||
switch (size.type()) {
|
||||
case mtpc_photoSize: {
|
||||
|
|
|
@ -116,6 +116,7 @@ namespace App {
|
|||
void feedChatAdmins(const MTPDupdateChatAdmins &d, bool emitPeerUpdated = true);
|
||||
void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d, bool emitPeerUpdated = true);
|
||||
bool checkEntitiesAndViewsUpdate(const MTPDmessage &m); // returns true if item found and it is not detached
|
||||
void feedMsgs(const QVector<MTPMessage> &msgs, NewMessageType type);
|
||||
void feedMsgs(const MTPVector<MTPMessage> &msgs, NewMessageType type);
|
||||
void feedInboxRead(const PeerId &peer, MsgId upTo);
|
||||
void feedOutboxRead(const PeerId &peer, MsgId upTo);
|
||||
|
|
|
@ -1552,10 +1552,11 @@ MsgId DialogsInner::lastSearchMigratedId() const {
|
|||
DialogsWidget::DialogsWidget(MainWidget *parent) : TWidget(parent)
|
||||
, _dragInScroll(false)
|
||||
, _dragForward(false)
|
||||
, _dialogsOffset(0)
|
||||
, _dialogsCount(-1)
|
||||
, _dialogsFull(false)
|
||||
, _dialogsOffsetDate(0)
|
||||
, _dialogsOffsetId(0)
|
||||
, _dialogsOffsetPeer(0)
|
||||
, _dialogsRequest(0)
|
||||
, _channelDialogsRequest(0)
|
||||
, _contactsRequest(0)
|
||||
, _filter(this, st::dlgFilter, lang(lng_dlg_filter))
|
||||
, _newGroup(this, st::btnNewGroup)
|
||||
|
@ -1744,24 +1745,24 @@ void DialogsWidget::unreadCountsReceived(const QVector<MTPDialog> &dialogs) {
|
|||
}
|
||||
|
||||
void DialogsWidget::dialogsReceived(const MTPmessages_Dialogs &dialogs, mtpRequestId req) {
|
||||
const QVector<MTPDialog> *dlgList = 0;
|
||||
int32 count = 0;
|
||||
if (_dialogsRequest != req) return;
|
||||
|
||||
const QVector<MTPDialog> *v = 0;
|
||||
const QVector<MTPMessage> *m = 0;
|
||||
switch (dialogs.type()) {
|
||||
case mtpc_messages_dialogs: {
|
||||
const MTPDmessages_dialogs &data(dialogs.c_messages_dialogs());
|
||||
App::feedUsers(data.vusers);
|
||||
App::feedChats(data.vchats);
|
||||
App::feedMsgs(data.vmessages, NewMessageLast);
|
||||
dlgList = &data.vdialogs.c_vector().v;
|
||||
count = dlgList->size();
|
||||
m = &data.vmessages.c_vector().v;
|
||||
v = &data.vdialogs.c_vector().v;
|
||||
} break;
|
||||
case mtpc_messages_dialogsSlice: {
|
||||
const MTPDmessages_dialogsSlice &data(dialogs.c_messages_dialogsSlice());
|
||||
App::feedUsers(data.vusers);
|
||||
App::feedChats(data.vchats);
|
||||
App::feedMsgs(data.vmessages, NewMessageLast);
|
||||
dlgList = &data.vdialogs.c_vector().v;
|
||||
count = data.vcount.v;
|
||||
m = &data.vmessages.c_vector().v;
|
||||
v = &data.vdialogs.c_vector().v;
|
||||
} break;
|
||||
}
|
||||
|
||||
|
@ -1769,44 +1770,61 @@ void DialogsWidget::dialogsReceived(const MTPmessages_Dialogs &dialogs, mtpReque
|
|||
_contactsRequest = MTP::send(MTPcontacts_GetContacts(MTP_string("")), rpcDone(&DialogsWidget::contactsReceived), rpcFail(&DialogsWidget::contactsFailed));
|
||||
}
|
||||
|
||||
if (_dialogsRequest == req) {
|
||||
_dialogsCount = count;
|
||||
if (dlgList) {
|
||||
unreadCountsReceived(*dlgList);
|
||||
_inner.dialogsReceived(*dlgList);
|
||||
onListScroll();
|
||||
|
||||
if (dlgList->size()) {
|
||||
_dialogsOffset += dlgList->size();
|
||||
} else {
|
||||
_dialogsCount = _dialogsOffset;
|
||||
}
|
||||
} else {
|
||||
_dialogsCount = _dialogsOffset;
|
||||
}
|
||||
|
||||
_dialogsRequest = 0;
|
||||
if (dlgList) {
|
||||
loadDialogs();
|
||||
}
|
||||
} else if (_channelDialogsRequest == req) {
|
||||
//_channelDialogsCount = count;
|
||||
if (dlgList) {
|
||||
unreadCountsReceived(*dlgList);
|
||||
_inner.dialogsReceived(*dlgList);
|
||||
onListScroll();
|
||||
|
||||
// if (dlgList->size()) {
|
||||
// _channelDialogsOffset += dlgList->size();
|
||||
// } else {
|
||||
// _channelDialogsCount = _channelDialogsOffset;
|
||||
// }
|
||||
//} else {
|
||||
// _channelDialogsCount = _channelDialogsOffset;
|
||||
}
|
||||
|
||||
//_channelDialogsRequest = 0;
|
||||
if (m) {
|
||||
App::feedMsgs(*m, NewMessageLast);
|
||||
}
|
||||
if (v) {
|
||||
unreadCountsReceived(*v);
|
||||
_inner.dialogsReceived(*v);
|
||||
onListScroll();
|
||||
|
||||
int32 lastDate = 0;
|
||||
PeerId lastPeer = 0;
|
||||
MsgId lastMsgId = 0;
|
||||
for (int32 i = v->size(); i > 0;) {
|
||||
PeerId peer = 0;
|
||||
MsgId msgId = 0;
|
||||
const MTPDialog &d(v->at(--i));
|
||||
switch (d.type()) {
|
||||
case mtpc_dialog:
|
||||
msgId = d.c_dialog().vtop_message.v;
|
||||
peer = peerFromMTP(d.c_dialog().vpeer);
|
||||
break;
|
||||
case mtpc_dialogChannel:
|
||||
msgId = d.c_dialogChannel().vtop_important_message.v;
|
||||
if (!msgId) msgId = d.c_dialogChannel().vtop_message.v;
|
||||
peer = peerFromMTP(d.c_dialogChannel().vpeer);
|
||||
break;
|
||||
}
|
||||
if (peer) {
|
||||
if (!lastPeer) lastPeer = peer;
|
||||
if (msgId) {
|
||||
if (!lastMsgId) lastMsgId = msgId;
|
||||
for (int32 j = m->size(); j > 0;) {
|
||||
const MTPMessage &d(m->at(--j));
|
||||
if (idFromMessage(d) == msgId) {
|
||||
int32 date = dateFromMessage(d);
|
||||
if (date) lastDate = date;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastDate) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lastDate) {
|
||||
_dialogsOffsetDate = lastDate;
|
||||
_dialogsOffsetId = lastMsgId;
|
||||
_dialogsOffsetPeer = App::peer(lastPeer);
|
||||
} else {
|
||||
_dialogsFull = true;
|
||||
}
|
||||
} else {
|
||||
_dialogsFull = true;
|
||||
}
|
||||
|
||||
_dialogsRequest = 0;
|
||||
loadDialogs();
|
||||
}
|
||||
|
||||
bool DialogsWidget::dialogsFailed(const RPCError &error, mtpRequestId req) {
|
||||
|
@ -1815,8 +1833,6 @@ bool DialogsWidget::dialogsFailed(const RPCError &error, mtpRequestId req) {
|
|||
LOG(("RPC Error: %1 %2: %3").arg(error.code()).arg(error.type()).arg(error.description()));
|
||||
if (_dialogsRequest == req) {
|
||||
_dialogsRequest = 0;
|
||||
} else if (_channelDialogsRequest == req) {
|
||||
_channelDialogsRequest = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1931,17 +1947,14 @@ void DialogsWidget::onSearchMore() {
|
|||
|
||||
void DialogsWidget::loadDialogs() {
|
||||
if (_dialogsRequest) return;
|
||||
if (_dialogsCount >= 0 && _dialogsOffset >= _dialogsCount) {
|
||||
if (_dialogsFull) {
|
||||
_inner.addAllSavedPeers();
|
||||
cSetDialogsReceived(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int32 loadCount = _dialogsOffset ? DialogsPerPage : DialogsFirstLoad;
|
||||
_dialogsRequest = MTP::send(MTPmessages_GetDialogs(MTP_int(_dialogsOffset), MTP_int(loadCount)), rpcDone(&DialogsWidget::dialogsReceived), rpcFail(&DialogsWidget::dialogsFailed), 0, _channelDialogsRequest ? 0 : 5);
|
||||
if (!_channelDialogsRequest) {
|
||||
_channelDialogsRequest = MTP::send(MTPchannels_GetDialogs(MTP_int(0), MTP_int(DialogsPerPage)), rpcDone(&DialogsWidget::dialogsReceived), rpcFail(&DialogsWidget::dialogsFailed));
|
||||
}
|
||||
int32 loadCount = _dialogsOffsetDate ? DialogsPerPage : DialogsFirstLoad;
|
||||
_dialogsRequest = MTP::send(MTPmessages_GetDialogs(MTP_int(_dialogsOffsetDate), MTP_int(_dialogsOffsetId), _dialogsOffsetPeer ? _dialogsOffsetPeer->input : MTP_inputPeerEmpty(), MTP_int(loadCount)), rpcDone(&DialogsWidget::dialogsReceived), rpcFail(&DialogsWidget::dialogsFailed));
|
||||
}
|
||||
|
||||
void DialogsWidget::contactsReceived(const MTPcontacts_Contacts &contacts) {
|
||||
|
|
|
@ -277,8 +277,11 @@ private:
|
|||
bool searchFailed(DialogsSearchRequestType type, const RPCError &error, mtpRequestId req);
|
||||
bool peopleFailed(const RPCError &error, mtpRequestId req);
|
||||
|
||||
int32 _dialogsOffset, _dialogsCount;
|
||||
mtpRequestId _dialogsRequest, _channelDialogsRequest, _contactsRequest;
|
||||
bool _dialogsFull;
|
||||
int32 _dialogsOffsetDate;
|
||||
MsgId _dialogsOffsetId;
|
||||
PeerData *_dialogsOffsetPeer;
|
||||
mtpRequestId _dialogsRequest, _contactsRequest;
|
||||
|
||||
FlatInput _filter;
|
||||
IconedButton _newGroup, _addContact, _cancelSearch;
|
||||
|
|
|
@ -368,7 +368,7 @@ static const mtpTypeId mtpLayers[] = {
|
|||
mtpTypeId(mtpc_invokeWithLayer18),
|
||||
};
|
||||
static const uint32 mtpLayerMaxSingle = sizeof(mtpLayers) / sizeof(mtpLayers[0]);
|
||||
static const mtpPrime mtpCurrentLayer = 41;
|
||||
static const mtpPrime mtpCurrentLayer = 42;
|
||||
|
||||
template <typename bareT>
|
||||
class MTPBoxed : public bareT {
|
||||
|
|
|
@ -6184,8 +6184,10 @@ void _serialize_messages_getDialogs(MTPStringLogger &to, int32 stage, int32 lev,
|
|||
to.add("\n").addSpaces(lev);
|
||||
}
|
||||
switch (stage) {
|
||||
case 0: to.add(" offset: "); ++stages.back(); types.push_back(mtpc_int); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;
|
||||
case 1: to.add(" limit: "); ++stages.back(); types.push_back(mtpc_int); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;
|
||||
case 0: to.add(" offset_date: "); ++stages.back(); types.push_back(mtpc_int); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;
|
||||
case 1: to.add(" offset_id: "); ++stages.back(); types.push_back(mtpc_int); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;
|
||||
case 2: to.add(" offset_peer: "); ++stages.back(); types.push_back(0); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;
|
||||
case 3: to.add(" limit: "); ++stages.back(); types.push_back(mtpc_int); vtypes.push_back(0); stages.push_back(0); flags.push_back(0); break;
|
||||
default: to.add("}"); types.pop_back(); vtypes.pop_back(); stages.pop_back(); flags.pop_back(); break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -496,7 +496,7 @@ enum {
|
|||
mtpc_contacts_search = 0x11f812d8,
|
||||
mtpc_contacts_resolveUsername = 0xf93ccba3,
|
||||
mtpc_messages_getMessages = 0x4222fa74,
|
||||
mtpc_messages_getDialogs = 0x859b3d3c,
|
||||
mtpc_messages_getDialogs = 0x6b47f94d,
|
||||
mtpc_messages_getHistory = 0x8a8ec2da,
|
||||
mtpc_messages_search = 0xd4569248,
|
||||
mtpc_messages_readHistory = 0xe306d3a,
|
||||
|
@ -15477,7 +15477,9 @@ public:
|
|||
|
||||
class MTPmessages_getDialogs { // RPC method 'messages.getDialogs'
|
||||
public:
|
||||
MTPint voffset;
|
||||
MTPint voffset_date;
|
||||
MTPint voffset_id;
|
||||
MTPInputPeer voffset_peer;
|
||||
MTPint vlimit;
|
||||
|
||||
MTPmessages_getDialogs() {
|
||||
|
@ -15485,21 +15487,25 @@ public:
|
|||
MTPmessages_getDialogs(const mtpPrime *&from, const mtpPrime *end, mtpTypeId cons = mtpc_messages_getDialogs) {
|
||||
read(from, end, cons);
|
||||
}
|
||||
MTPmessages_getDialogs(MTPint _offset, MTPint _limit) : voffset(_offset), vlimit(_limit) {
|
||||
MTPmessages_getDialogs(MTPint _offset_date, MTPint _offset_id, const MTPInputPeer &_offset_peer, MTPint _limit) : voffset_date(_offset_date), voffset_id(_offset_id), voffset_peer(_offset_peer), vlimit(_limit) {
|
||||
}
|
||||
|
||||
uint32 innerLength() const {
|
||||
return voffset.innerLength() + vlimit.innerLength();
|
||||
return voffset_date.innerLength() + voffset_id.innerLength() + voffset_peer.innerLength() + vlimit.innerLength();
|
||||
}
|
||||
mtpTypeId type() const {
|
||||
return mtpc_messages_getDialogs;
|
||||
}
|
||||
void read(const mtpPrime *&from, const mtpPrime *end, mtpTypeId cons = mtpc_messages_getDialogs) {
|
||||
voffset.read(from, end);
|
||||
voffset_date.read(from, end);
|
||||
voffset_id.read(from, end);
|
||||
voffset_peer.read(from, end);
|
||||
vlimit.read(from, end);
|
||||
}
|
||||
void write(mtpBuffer &to) const {
|
||||
voffset.write(to);
|
||||
voffset_date.write(to);
|
||||
voffset_id.write(to);
|
||||
voffset_peer.write(to);
|
||||
vlimit.write(to);
|
||||
}
|
||||
|
||||
|
@ -15513,7 +15519,7 @@ public:
|
|||
}
|
||||
MTPmessages_GetDialogs(const mtpPrime *&from, const mtpPrime *end, mtpTypeId cons = 0) : MTPBoxed<MTPmessages_getDialogs>(from, end, cons) {
|
||||
}
|
||||
MTPmessages_GetDialogs(MTPint _offset, MTPint _limit) : MTPBoxed<MTPmessages_getDialogs>(MTPmessages_getDialogs(_offset, _limit)) {
|
||||
MTPmessages_GetDialogs(MTPint _offset_date, MTPint _offset_id, const MTPInputPeer &_offset_peer, MTPint _limit) : MTPBoxed<MTPmessages_getDialogs>(MTPmessages_getDialogs(_offset_date, _offset_id, _offset_peer, _limit)) {
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -692,7 +692,7 @@ contacts.search#11f812d8 q:string limit:int = contacts.Found;
|
|||
contacts.resolveUsername#f93ccba3 username:string = contacts.ResolvedPeer;
|
||||
|
||||
messages.getMessages#4222fa74 id:Vector<int> = messages.Messages;
|
||||
messages.getDialogs#859b3d3c offset:int limit:int = messages.Dialogs;
|
||||
messages.getDialogs#6b47f94d offset_date:int offset_id:int offset_peer:InputPeer limit:int = messages.Dialogs;
|
||||
messages.getHistory#8a8ec2da peer:InputPeer offset_id:int add_offset:int limit:int max_id:int min_id:int = messages.Messages;
|
||||
messages.search#d4569248 flags:# important_only:flags.0?true peer:InputPeer q:string filter:MessagesFilter min_date:int max_date:int offset:int max_id:int limit:int = messages.Messages;
|
||||
messages.readHistory#e306d3a peer:InputPeer max_id:int = messages.AffectedMessages;
|
||||
|
|
Loading…
Add table
Reference in a new issue