mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Allow opening unknown stories from chats list.
This commit is contained in:
parent
3c28e7b585
commit
10f65c63e7
3 changed files with 35 additions and 8 deletions
|
@ -196,21 +196,34 @@ Story *Stories::applyFromWebpage(PeerId peerId, const MTPstoryItem &story) {
|
|||
return value ? value->get() : nullptr;
|
||||
}
|
||||
|
||||
void Stories::requestUserStories(not_null<UserData*> user) {
|
||||
if (!_requestingUserStories.emplace(user).second) {
|
||||
void Stories::requestUserStories(
|
||||
not_null<UserData*> user,
|
||||
Fn<void()> done) {
|
||||
const auto [i, ok] = _requestingUserStories.emplace(user);
|
||||
if (done) {
|
||||
i->second.push_back(std::move(done));
|
||||
}
|
||||
if (!ok) {
|
||||
return;
|
||||
}
|
||||
const auto finish = [=] {
|
||||
if (const auto callbacks = _requestingUserStories.take(user)) {
|
||||
for (const auto &callback : *callbacks) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
};
|
||||
_owner->session().api().request(MTPstories_GetUserStories(
|
||||
user->inputUser
|
||||
)).done([=](const MTPstories_UserStories &result) {
|
||||
_requestingUserStories.remove(user);
|
||||
const auto &data = result.data();
|
||||
_owner->processUsers(data.vusers());
|
||||
parseAndApply(data.vstories());
|
||||
finish();
|
||||
}).fail([=] {
|
||||
_requestingUserStories.remove(user);
|
||||
applyDeletedFromSources(user->id, StorySourcesList::NotHidden);
|
||||
applyDeletedFromSources(user->id, StorySourcesList::Hidden);
|
||||
finish();
|
||||
}).send();
|
||||
}
|
||||
|
||||
|
@ -290,6 +303,7 @@ void Stories::parseAndApply(const MTPUserStories &stories) {
|
|||
if (result.ids.empty()) {
|
||||
applyDeletedFromSources(peerId, StorySourcesList::NotHidden);
|
||||
applyDeletedFromSources(peerId, StorySourcesList::Hidden);
|
||||
user->setStoriesState(UserData::StoriesState::None);
|
||||
return;
|
||||
} else if (user->isSelf()) {
|
||||
result.readTill = result.ids.back().id;
|
||||
|
|
|
@ -218,6 +218,9 @@ public:
|
|||
|
||||
bool registerPolling(FullStoryId id, Polling polling);
|
||||
void unregisterPolling(FullStoryId id, Polling polling);
|
||||
void requestUserStories(
|
||||
not_null<UserData*> user,
|
||||
Fn<void()> done = nullptr);
|
||||
|
||||
void savedStateChanged(not_null<Story*> story);
|
||||
[[nodiscard]] std::shared_ptr<HistoryItem> lookupItem(
|
||||
|
@ -266,7 +269,6 @@ private:
|
|||
void sendIncrementViewsRequests();
|
||||
void checkQuitPreventFinished();
|
||||
|
||||
void requestUserStories(not_null<UserData*> user);
|
||||
void registerExpiring(TimeId expires, FullStoryId id);
|
||||
void scheduleExpireTimer();
|
||||
void processExpired();
|
||||
|
@ -335,7 +337,9 @@ private:
|
|||
base::flat_set<PeerId> _markReadPending;
|
||||
base::Timer _markReadTimer;
|
||||
base::flat_set<PeerId> _markReadRequests;
|
||||
base::flat_set<not_null<UserData*>> _requestingUserStories;
|
||||
base::flat_map<
|
||||
not_null<UserData*>,
|
||||
std::vector<Fn<void()>>> _requestingUserStories;
|
||||
|
||||
base::flat_map<PeerId, base::flat_set<StoryId>> _incrementViewsPending;
|
||||
base::Timer _incrementViewsTimer;
|
||||
|
|
|
@ -2528,9 +2528,10 @@ void SessionController::openPeerStory(
|
|||
if (from) {
|
||||
window().openInMediaView(OpenRequest(this, *from, context));
|
||||
} else if (from.error() == Data::NoStory::Unknown) {
|
||||
stories.resolve({ peer->id, storyId }, crl::guard(&_storyOpenGuard, [=] {
|
||||
const auto done = crl::guard(&_storyOpenGuard, [=] {
|
||||
openPeerStory(peer, storyId, context);
|
||||
}));
|
||||
});
|
||||
stories.resolve({ peer->id, storyId }, done);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2540,6 +2541,7 @@ void SessionController::openPeerStories(
|
|||
using namespace Media::View;
|
||||
using namespace Data;
|
||||
|
||||
invalidate_weak_ptrs(&_storyOpenGuard);
|
||||
auto &stories = session().data().stories();
|
||||
if (const auto source = stories.source(peerId)) {
|
||||
if (const auto idDates = source->toOpen()) {
|
||||
|
@ -2550,6 +2552,13 @@ void SessionController::openPeerStories(
|
|||
? StoriesContext{ *list }
|
||||
: StoriesContext{ StoriesContextPeer() }));
|
||||
}
|
||||
} else if (const auto userId = peerToUser(peerId)) {
|
||||
if (const auto user = session().data().userLoaded(userId)) {
|
||||
const auto done = crl::guard(&_storyOpenGuard, [=] {
|
||||
openPeerStories(peerId, list);
|
||||
});
|
||||
stories.requestUserStories(user, done);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue