Skip to content

Commit

Permalink
Fix possible crash in common groups list.
Browse files Browse the repository at this point in the history
Currently Data::Session::processChat() may change adminRights(),
that may change Data::CanSendAnyOf(peer, ...), that may lead to
Window::SessionController::updateThirdColumnToCurrentChat() call,
that destroys current third column to replace it with another one.

If common groups list was opened in the third column this will crash.

Fixes telegramdesktop#27640.
  • Loading branch information
john-preston committed May 1, 2024
1 parent ad6321d commit 12a24dd
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ For license and copyright information please follow this link:
*/
#include "info/common_groups/info_common_groups_inner_widget.h"

#include "base/weak_ptr.h"
#include "info/common_groups/info_common_groups_widget.h"
#include "info/info_controller.h"
#include "lang/lang_keys.h"
Expand All @@ -27,7 +28,9 @@ namespace {
constexpr auto kCommonGroupsPerPage = 40;
constexpr auto kCommonGroupsSearchAfter = 20;

class ListController final : public PeerListController {
class ListController final
: public PeerListController
, public base::has_weak_ptr {
public:
ListController(
not_null<Controller*> controller,
Expand Down Expand Up @@ -108,16 +111,30 @@ void ListController::loadMoreRows() {
return data.vchats().v;
});
if (!chats.empty()) {
auto add = std::vector<not_null<PeerData*>>();
auto allLoaded = _allLoaded;
auto preloadGroupId = _preloadGroupId;
const auto owner = &_user->owner();
const auto weak = base::make_weak(this);
for (const auto &chat : chats) {
if (const auto peer = _user->owner().processChat(chat)) {
if (const auto peer = owner->processChat(chat)) {
if (!peer->migrateTo()) {
delegate()->peerListAppendRow(
createRow(peer));
add.push_back(peer);
}
_preloadGroupId = peer->id;
_allLoaded = false;
preloadGroupId = peer->id;
allLoaded = false;
}
}
if (!weak) {
return;
}
for (const auto &peer : add) {
if (!delegate()->peerListFindRow(peer->id.value)) {
delegate()->peerListAppendRow(createRow(peer));
}
}
_preloadGroupId = preloadGroupId;
_allLoaded = allLoaded;
delegate()->peerListRefreshRows();
}
auto fullCount = delegate()->peerListFullRowsCount();
Expand Down

0 comments on commit 12a24dd

Please sign in to comment.