mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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;
|
return value ? value->get() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stories::requestUserStories(not_null<UserData*> user) {
|
void Stories::requestUserStories(
|
||||||
if (!_requestingUserStories.emplace(user).second) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
const auto finish = [=] {
|
||||||
|
if (const auto callbacks = _requestingUserStories.take(user)) {
|
||||||
|
for (const auto &callback : *callbacks) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
_owner->session().api().request(MTPstories_GetUserStories(
|
_owner->session().api().request(MTPstories_GetUserStories(
|
||||||
user->inputUser
|
user->inputUser
|
||||||
)).done([=](const MTPstories_UserStories &result) {
|
)).done([=](const MTPstories_UserStories &result) {
|
||||||
_requestingUserStories.remove(user);
|
|
||||||
const auto &data = result.data();
|
const auto &data = result.data();
|
||||||
_owner->processUsers(data.vusers());
|
_owner->processUsers(data.vusers());
|
||||||
parseAndApply(data.vstories());
|
parseAndApply(data.vstories());
|
||||||
|
finish();
|
||||||
}).fail([=] {
|
}).fail([=] {
|
||||||
_requestingUserStories.remove(user);
|
|
||||||
applyDeletedFromSources(user->id, StorySourcesList::NotHidden);
|
applyDeletedFromSources(user->id, StorySourcesList::NotHidden);
|
||||||
applyDeletedFromSources(user->id, StorySourcesList::Hidden);
|
applyDeletedFromSources(user->id, StorySourcesList::Hidden);
|
||||||
|
finish();
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,6 +303,7 @@ void Stories::parseAndApply(const MTPUserStories &stories) {
|
||||||
if (result.ids.empty()) {
|
if (result.ids.empty()) {
|
||||||
applyDeletedFromSources(peerId, StorySourcesList::NotHidden);
|
applyDeletedFromSources(peerId, StorySourcesList::NotHidden);
|
||||||
applyDeletedFromSources(peerId, StorySourcesList::Hidden);
|
applyDeletedFromSources(peerId, StorySourcesList::Hidden);
|
||||||
|
user->setStoriesState(UserData::StoriesState::None);
|
||||||
return;
|
return;
|
||||||
} else if (user->isSelf()) {
|
} else if (user->isSelf()) {
|
||||||
result.readTill = result.ids.back().id;
|
result.readTill = result.ids.back().id;
|
||||||
|
|
|
@ -218,6 +218,9 @@ public:
|
||||||
|
|
||||||
bool registerPolling(FullStoryId id, Polling polling);
|
bool registerPolling(FullStoryId id, Polling polling);
|
||||||
void unregisterPolling(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);
|
void savedStateChanged(not_null<Story*> story);
|
||||||
[[nodiscard]] std::shared_ptr<HistoryItem> lookupItem(
|
[[nodiscard]] std::shared_ptr<HistoryItem> lookupItem(
|
||||||
|
@ -266,7 +269,6 @@ private:
|
||||||
void sendIncrementViewsRequests();
|
void sendIncrementViewsRequests();
|
||||||
void checkQuitPreventFinished();
|
void checkQuitPreventFinished();
|
||||||
|
|
||||||
void requestUserStories(not_null<UserData*> user);
|
|
||||||
void registerExpiring(TimeId expires, FullStoryId id);
|
void registerExpiring(TimeId expires, FullStoryId id);
|
||||||
void scheduleExpireTimer();
|
void scheduleExpireTimer();
|
||||||
void processExpired();
|
void processExpired();
|
||||||
|
@ -335,7 +337,9 @@ private:
|
||||||
base::flat_set<PeerId> _markReadPending;
|
base::flat_set<PeerId> _markReadPending;
|
||||||
base::Timer _markReadTimer;
|
base::Timer _markReadTimer;
|
||||||
base::flat_set<PeerId> _markReadRequests;
|
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::flat_map<PeerId, base::flat_set<StoryId>> _incrementViewsPending;
|
||||||
base::Timer _incrementViewsTimer;
|
base::Timer _incrementViewsTimer;
|
||||||
|
|
|
@ -2528,9 +2528,10 @@ void SessionController::openPeerStory(
|
||||||
if (from) {
|
if (from) {
|
||||||
window().openInMediaView(OpenRequest(this, *from, context));
|
window().openInMediaView(OpenRequest(this, *from, context));
|
||||||
} else if (from.error() == Data::NoStory::Unknown) {
|
} 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);
|
openPeerStory(peer, storyId, context);
|
||||||
}));
|
});
|
||||||
|
stories.resolve({ peer->id, storyId }, done);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2540,6 +2541,7 @@ void SessionController::openPeerStories(
|
||||||
using namespace Media::View;
|
using namespace Media::View;
|
||||||
using namespace Data;
|
using namespace Data;
|
||||||
|
|
||||||
|
invalidate_weak_ptrs(&_storyOpenGuard);
|
||||||
auto &stories = session().data().stories();
|
auto &stories = session().data().stories();
|
||||||
if (const auto source = stories.source(peerId)) {
|
if (const auto source = stories.source(peerId)) {
|
||||||
if (const auto idDates = source->toOpen()) {
|
if (const auto idDates = source->toOpen()) {
|
||||||
|
@ -2550,6 +2552,13 @@ void SessionController::openPeerStories(
|
||||||
? StoriesContext{ *list }
|
? StoriesContext{ *list }
|
||||||
: StoriesContext{ StoriesContextPeer() }));
|
: 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