mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix crash in inconsistent local send as peer data.
This commit is contained in:
parent
133f64f370
commit
27e80b8e42
2 changed files with 23 additions and 0 deletions
|
@ -8,7 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/session/send_as_peers.h"
|
#include "main/session/send_as_peers.h"
|
||||||
|
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
|
#include "data/data_channel.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
#include "data/data_changes.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
|
||||||
|
@ -22,6 +24,21 @@ constexpr auto kRequestEach = 30 * crl::time(1000);
|
||||||
SendAsPeers::SendAsPeers(not_null<Session*> session)
|
SendAsPeers::SendAsPeers(not_null<Session*> session)
|
||||||
: _session(session)
|
: _session(session)
|
||||||
, _onlyMe({ session->user() }) {
|
, _onlyMe({ session->user() }) {
|
||||||
|
_session->changes().peerUpdates(
|
||||||
|
Data::PeerUpdate::Flag::Rights
|
||||||
|
) | rpl::map([=](const Data::PeerUpdate &update) {
|
||||||
|
const auto peer = update.peer;
|
||||||
|
const auto channel = peer->asChannel();
|
||||||
|
return std::tuple(
|
||||||
|
peer,
|
||||||
|
peer->amAnonymous(),
|
||||||
|
channel ? channel->isPublic() : false);
|
||||||
|
}) | rpl::distinct_until_changed(
|
||||||
|
) | rpl::filter([=](not_null<PeerData*> peer, bool, bool) {
|
||||||
|
return _lists.contains(peer);
|
||||||
|
}) | rpl::start_with_next([=](not_null<PeerData*> peer, bool, bool) {
|
||||||
|
refresh(peer);
|
||||||
|
}, _lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SendAsPeers::shouldChoose(not_null<PeerData*> peer) {
|
bool SendAsPeers::shouldChoose(not_null<PeerData*> peer) {
|
||||||
|
@ -96,6 +113,8 @@ not_null<PeerData*> SendAsPeers::ResolveChosen(
|
||||||
const auto i = ranges::find(list, chosen, &PeerData::id);
|
const auto i = ranges::find(list, chosen, &PeerData::id);
|
||||||
return (i != end(list))
|
return (i != end(list))
|
||||||
? (*i)
|
? (*i)
|
||||||
|
: !list.empty()
|
||||||
|
? list.front()
|
||||||
: (peer->isMegagroup() && peer->amAnonymous())
|
: (peer->isMegagroup() && peer->amAnonymous())
|
||||||
? peer
|
? peer
|
||||||
: peer->session().user();
|
: peer->session().user();
|
||||||
|
|
|
@ -26,6 +26,8 @@ public:
|
||||||
void saveChosen(not_null<PeerData*> peer, not_null<PeerData*> chosen);
|
void saveChosen(not_null<PeerData*> peer, not_null<PeerData*> chosen);
|
||||||
void setChosen(not_null<PeerData*> peer, PeerId chosenId);
|
void setChosen(not_null<PeerData*> peer, PeerId chosenId);
|
||||||
[[nodiscard]] PeerId chosen(not_null<PeerData*> peer) const;
|
[[nodiscard]] PeerId chosen(not_null<PeerData*> peer) const;
|
||||||
|
|
||||||
|
// If !list(peer).empty() then the result will be from that list.
|
||||||
[[nodiscard]] not_null<PeerData*> resolveChosen(
|
[[nodiscard]] not_null<PeerData*> resolveChosen(
|
||||||
not_null<PeerData*> peer) const;
|
not_null<PeerData*> peer) const;
|
||||||
|
|
||||||
|
@ -48,6 +50,8 @@ private:
|
||||||
|
|
||||||
rpl::event_stream<not_null<PeerData*>> _updates;
|
rpl::event_stream<not_null<PeerData*>> _updates;
|
||||||
|
|
||||||
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Main
|
} // namespace Main
|
||||||
|
|
Loading…
Add table
Reference in a new issue