mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-09-03 08:05:12 +00:00
Improve update handling for legacy chats.
This commit is contained in:
@@ -146,224 +146,6 @@ namespace App {
|
||||
return Auth().data().processChats(chats);
|
||||
}
|
||||
|
||||
void feedParticipants(const MTPChatParticipants &p, bool requestBotInfos) {
|
||||
ChatData *chat = 0;
|
||||
switch (p.type()) {
|
||||
case mtpc_chatParticipantsForbidden: {
|
||||
const auto &d(p.c_chatParticipantsForbidden());
|
||||
chat = App::chat(d.vchat_id.v);
|
||||
chat->count = -1;
|
||||
chat->invalidateParticipants();
|
||||
} break;
|
||||
|
||||
case mtpc_chatParticipants: {
|
||||
const auto &d(p.c_chatParticipants());
|
||||
chat = App::chat(d.vchat_id.v);
|
||||
if (!requestBotInfos || chat->version <= d.vversion.v) { // !requestBotInfos is true on getFullChat result
|
||||
chat->version = d.vversion.v;
|
||||
auto &v = d.vparticipants.v;
|
||||
chat->count = v.size();
|
||||
int32 pversion = chat->participants.empty()
|
||||
? 1
|
||||
: (chat->participants.begin()->second + 1);
|
||||
chat->invitedByMe.clear();
|
||||
chat->admins.clear();
|
||||
// #TODO groups
|
||||
//chat->removeFlags(MTPDchat::Flag::f_admin);
|
||||
for (auto i = v.cbegin(), e = v.cend(); i != e; ++i) {
|
||||
int32 uid = 0, inviter = 0;
|
||||
switch (i->type()) {
|
||||
case mtpc_chatParticipantCreator: {
|
||||
const auto &p(i->c_chatParticipantCreator());
|
||||
uid = p.vuser_id.v;
|
||||
chat->creator = uid;
|
||||
} break;
|
||||
case mtpc_chatParticipantAdmin: {
|
||||
const auto &p(i->c_chatParticipantAdmin());
|
||||
uid = p.vuser_id.v;
|
||||
inviter = p.vinviter_id.v;
|
||||
} break;
|
||||
case mtpc_chatParticipant: {
|
||||
const auto &p(i->c_chatParticipant());
|
||||
uid = p.vuser_id.v;
|
||||
inviter = p.vinviter_id.v;
|
||||
} break;
|
||||
}
|
||||
if (!uid) continue;
|
||||
|
||||
UserData *user = App::userLoaded(uid);
|
||||
if (user) {
|
||||
chat->participants[user] = pversion;
|
||||
if (inviter == Auth().userId()) {
|
||||
chat->invitedByMe.insert(user);
|
||||
}
|
||||
if (i->type() == mtpc_chatParticipantAdmin) {
|
||||
chat->admins.insert(user);
|
||||
if (user->isSelf()) {
|
||||
// #TODO groups
|
||||
// chat->addFlags(MTPDchat::Flag::f_admin);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
chat->invalidateParticipants();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!chat->participants.empty()) {
|
||||
auto h = App::historyLoaded(chat->id);
|
||||
bool found = !h || !h->lastKeyboardFrom;
|
||||
auto botStatus = -1;
|
||||
for (auto i = chat->participants.begin(); i != chat->participants.end();) {
|
||||
const auto [user, version] = *i;
|
||||
if (version < pversion) {
|
||||
i = chat->participants.erase(i);
|
||||
} else {
|
||||
if (user->botInfo) {
|
||||
botStatus = 2;// (botStatus > 0/* || !user->botInfo->readsAllHistory*/) ? 2 : 1;
|
||||
if (requestBotInfos && !user->botInfo->inited) {
|
||||
Auth().api().requestFullPeer(user);
|
||||
}
|
||||
}
|
||||
if (!found && user->id == h->lastKeyboardFrom) {
|
||||
found = true;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
chat->botStatus = botStatus;
|
||||
if (!found) {
|
||||
h->clearLastKeyboard();
|
||||
}
|
||||
}
|
||||
}
|
||||
} break;
|
||||
}
|
||||
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::MembersChanged | Notify::PeerUpdate::Flag::AdminsChanged);
|
||||
}
|
||||
|
||||
void feedParticipantAdd(const MTPDupdateChatParticipantAdd &d) {
|
||||
ChatData *chat = App::chat(d.vchat_id.v);
|
||||
if (chat->version + 1 < d.vversion.v) {
|
||||
chat->version = d.vversion.v;
|
||||
chat->invalidateParticipants();
|
||||
Auth().api().requestPeer(chat);
|
||||
} else if (chat->version <= d.vversion.v && chat->count >= 0) {
|
||||
chat->version = d.vversion.v;
|
||||
UserData *user = App::userLoaded(d.vuser_id.v);
|
||||
if (user) {
|
||||
if (chat->participants.empty() && chat->count) {
|
||||
chat->count++;
|
||||
chat->botStatus = 0;
|
||||
} else if (chat->participants.find(user) == chat->participants.end()) {
|
||||
chat->participants[user] = (chat->participants.empty() ? 1 : chat->participants.begin()->second);
|
||||
if (d.vinviter_id.v == Auth().userId()) {
|
||||
chat->invitedByMe.insert(user);
|
||||
} else {
|
||||
chat->invitedByMe.remove(user);
|
||||
}
|
||||
chat->count++;
|
||||
if (user->botInfo) {
|
||||
chat->botStatus = 2;// (chat->botStatus > 0/* || !user->botInfo->readsAllHistory*/) ? 2 : 1;
|
||||
if (!user->botInfo->inited) {
|
||||
Auth().api().requestFullPeer(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
chat->invalidateParticipants();
|
||||
chat->count++;
|
||||
}
|
||||
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::MembersChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void feedParticipantDelete(const MTPDupdateChatParticipantDelete &d) {
|
||||
ChatData *chat = App::chat(d.vchat_id.v);
|
||||
if (chat->version + 1 < d.vversion.v) {
|
||||
chat->version = d.vversion.v;
|
||||
chat->invalidateParticipants();
|
||||
Auth().api().requestPeer(chat);
|
||||
} else if (chat->version <= d.vversion.v && chat->count > 0) {
|
||||
chat->version = d.vversion.v;
|
||||
const auto user = App::userLoaded(d.vuser_id.v);
|
||||
if (user) {
|
||||
if (chat->participants.empty()) {
|
||||
if (chat->count > 0) {
|
||||
chat->count--;
|
||||
}
|
||||
} else {
|
||||
auto i = chat->participants.find(user);
|
||||
if (i != chat->participants.end()) {
|
||||
chat->participants.erase(i);
|
||||
chat->count--;
|
||||
chat->invitedByMe.remove(user);
|
||||
chat->admins.remove(user);
|
||||
if (user->isSelf()) {
|
||||
// #TODO groups
|
||||
// chat->removeFlags(MTPDchat::Flag::f_admin);
|
||||
}
|
||||
|
||||
History *h = App::historyLoaded(chat->id);
|
||||
if (h && h->lastKeyboardFrom == user->id) {
|
||||
h->clearLastKeyboard();
|
||||
}
|
||||
}
|
||||
if (chat->botStatus > 0 && user->botInfo) {
|
||||
int32 botStatus = -1;
|
||||
for (const auto [participant, v] : chat->participants) {
|
||||
if (participant->botInfo) {
|
||||
if (true || botStatus > 0/* || !participant->botInfo->readsAllHistory*/) {
|
||||
botStatus = 2;
|
||||
break;
|
||||
}
|
||||
botStatus = 1;
|
||||
}
|
||||
}
|
||||
chat->botStatus = botStatus;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
chat->invalidateParticipants();
|
||||
chat->count--;
|
||||
}
|
||||
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::MembersChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d) {
|
||||
const auto chat = App::chat(d.vchat_id.v);
|
||||
if (chat->version + 1 < d.vversion.v) {
|
||||
chat->version = d.vversion.v;
|
||||
chat->invalidateParticipants();
|
||||
Auth().api().requestPeer(chat);
|
||||
} else if (chat->version <= d.vversion.v && chat->count > 0) {
|
||||
chat->version = d.vversion.v;
|
||||
const auto user = App::userLoaded(d.vuser_id.v);
|
||||
if (user) {
|
||||
if (mtpIsTrue(d.vis_admin)) {
|
||||
if (user->isSelf()) {
|
||||
// #TODO groups
|
||||
// chat->addFlags(MTPDchat::Flag::f_admin);
|
||||
}
|
||||
if (chat->noParticipantInfo()) {
|
||||
Auth().api().requestFullPeer(chat);
|
||||
} else {
|
||||
chat->admins.insert(user);
|
||||
}
|
||||
} else {
|
||||
if (user->isSelf()) {
|
||||
// #TODO groups
|
||||
//chat->removeFlags(MTPDchat::Flag::f_admin);
|
||||
}
|
||||
chat->admins.remove(user);
|
||||
}
|
||||
} else {
|
||||
chat->invalidateParticipants();
|
||||
}
|
||||
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::AdminsChanged);
|
||||
}
|
||||
}
|
||||
|
||||
bool checkEntitiesAndViewsUpdate(const MTPDmessage &m) {
|
||||
auto peerId = peerFromMTP(m.vto_id);
|
||||
if (m.has_from_id() && peerId == Auth().userPeerId()) {
|
||||
|
Reference in New Issue
Block a user