mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix possible crash in global media search.
This commit is contained in:
parent
188d65d700
commit
82e890746b
1 changed files with 6 additions and 2 deletions
|
@ -240,7 +240,7 @@ rpl::producer<GlobalMediaSlice> Provider::source(
|
||||||
auto lifetime = rpl::lifetime();
|
auto lifetime = rpl::lifetime();
|
||||||
const auto session = &_controller->session();
|
const auto session = &_controller->session();
|
||||||
|
|
||||||
struct State {
|
struct State : base::has_weak_ptr {
|
||||||
State(not_null<Main::Session*> session) : session(session) {
|
State(not_null<Main::Session*> session) : session(session) {
|
||||||
}
|
}
|
||||||
~State() {
|
~State() {
|
||||||
|
@ -252,11 +252,15 @@ rpl::producer<GlobalMediaSlice> Provider::source(
|
||||||
mtpRequestId requestId = 0;
|
mtpRequestId requestId = 0;
|
||||||
};
|
};
|
||||||
const auto state = lifetime.make_state<State>(session);
|
const auto state = lifetime.make_state<State>(session);
|
||||||
|
const auto guard = base::make_weak(state);
|
||||||
|
|
||||||
state->pushAndLoadMore = [=] {
|
state->pushAndLoadMore = [=] {
|
||||||
auto result = fillRequest(aroundId, limitBefore, limitAfter);
|
auto result = fillRequest(aroundId, limitBefore, limitAfter);
|
||||||
|
|
||||||
|
// May destroy 'state' by calling source() with different args.
|
||||||
consumer.put_next(std::move(result.slice));
|
consumer.put_next(std::move(result.slice));
|
||||||
if (!currentList()->loaded && result.notEnough) {
|
|
||||||
|
if (guard && !currentList()->loaded && result.notEnough) {
|
||||||
state->requestId = requestMore(state->pushAndLoadMore);
|
state->requestId = requestMore(state->pushAndLoadMore);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue