mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Show only hidden stories in Contacts.
This commit is contained in:
parent
19d0bf142c
commit
8d2fd4bd69
7 changed files with 79 additions and 73 deletions
|
@ -85,7 +85,7 @@ object_ptr<Ui::BoxContent> PrepareContactsBox(
|
||||||
st::dialogsStoriesList,
|
st::dialogsStoriesList,
|
||||||
Stories::ContentForSession(
|
Stories::ContentForSession(
|
||||||
&sessionController->session(),
|
&sessionController->session(),
|
||||||
Data::StorySourcesList::All),
|
Data::StorySourcesList::Hidden),
|
||||||
[=] { return state->stories->height() - box->scrollTop(); });
|
[=] { return state->stories->height() - box->scrollTop(); });
|
||||||
const auto raw = state->stories = stories.data();
|
const auto raw = state->stories = stories.data();
|
||||||
box->peerListSetAboveWidget(object_ptr<::Ui::PaddingWrap<>>(
|
box->peerListSetAboveWidget(object_ptr<::Ui::PaddingWrap<>>(
|
||||||
|
@ -97,7 +97,7 @@ object_ptr<Ui::BoxContent> PrepareContactsBox(
|
||||||
) | rpl::start_with_next([=](uint64 id) {
|
) | rpl::start_with_next([=](uint64 id) {
|
||||||
sessionController->openPeerStories(
|
sessionController->openPeerStories(
|
||||||
PeerId(int64(id)),
|
PeerId(int64(id)),
|
||||||
Data::StorySourcesList::All);
|
Data::StorySourcesList::Hidden);
|
||||||
}, raw->lifetime());
|
}, raw->lifetime());
|
||||||
|
|
||||||
raw->showProfileRequests(
|
raw->showProfileRequests(
|
||||||
|
@ -116,7 +116,7 @@ object_ptr<Ui::BoxContent> PrepareContactsBox(
|
||||||
raw->loadMoreRequests(
|
raw->loadMoreRequests(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
sessionController->session().data().stories().loadMore(
|
sessionController->session().data().stories().loadMore(
|
||||||
Data::StorySourcesList::All);
|
Data::StorySourcesList::Hidden);
|
||||||
}, raw->lifetime());
|
}, raw->lifetime());
|
||||||
};
|
};
|
||||||
return Box<PeerListBox>(std::move(controller), std::move(init));
|
return Box<PeerListBox>(std::move(controller), std::move(init));
|
||||||
|
|
|
@ -419,8 +419,9 @@ void Stories::apply(const MTPDupdateStory &data) {
|
||||||
sort(list);
|
sort(list);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
refreshInList(StorySourcesList::All);
|
if (user->hasStoriesHidden()) {
|
||||||
if (!user->hasStoriesHidden()) {
|
refreshInList(StorySourcesList::Hidden);
|
||||||
|
} else {
|
||||||
refreshInList(StorySourcesList::NotHidden);
|
refreshInList(StorySourcesList::NotHidden);
|
||||||
}
|
}
|
||||||
_sourceChanged.fire_copy(peerId);
|
_sourceChanged.fire_copy(peerId);
|
||||||
|
@ -428,7 +429,8 @@ void Stories::apply(const MTPDupdateStory &data) {
|
||||||
|
|
||||||
void Stories::apply(not_null<PeerData*> peer, const MTPUserStories *data) {
|
void Stories::apply(not_null<PeerData*> peer, const MTPUserStories *data) {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
applyDeletedFromSources(peer->id, StorySourcesList::All);
|
applyDeletedFromSources(peer->id, StorySourcesList::NotHidden);
|
||||||
|
applyDeletedFromSources(peer->id, StorySourcesList::Hidden);
|
||||||
_all.erase(peer->id);
|
_all.erase(peer->id);
|
||||||
_sourceChanged.fire_copy(peer->id);
|
_sourceChanged.fire_copy(peer->id);
|
||||||
} else {
|
} else {
|
||||||
|
@ -449,7 +451,8 @@ void Stories::requestUserStories(not_null<UserData*> user) {
|
||||||
parseAndApply(data.vstories());
|
parseAndApply(data.vstories());
|
||||||
}).fail([=] {
|
}).fail([=] {
|
||||||
_requestingUserStories.remove(user);
|
_requestingUserStories.remove(user);
|
||||||
applyDeletedFromSources(user->id, StorySourcesList::All);
|
applyDeletedFromSources(user->id, StorySourcesList::NotHidden);
|
||||||
|
applyDeletedFromSources(user->id, StorySourcesList::Hidden);
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,7 +531,8 @@ void Stories::parseAndApply(const MTPUserStories &stories) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result.ids.empty()) {
|
if (result.ids.empty()) {
|
||||||
applyDeletedFromSources(peerId, StorySourcesList::All);
|
applyDeletedFromSources(peerId, StorySourcesList::NotHidden);
|
||||||
|
applyDeletedFromSources(peerId, StorySourcesList::Hidden);
|
||||||
return;
|
return;
|
||||||
} else if (user->isSelf()) {
|
} else if (user->isSelf()) {
|
||||||
result.readTill = result.ids.back().id;
|
result.readTill = result.ids.back().id;
|
||||||
|
@ -558,14 +562,15 @@ void Stories::parseAndApply(const MTPUserStories &stories) {
|
||||||
sort(list);
|
sort(list);
|
||||||
};
|
};
|
||||||
if (result.user->isContact()) {
|
if (result.user->isContact()) {
|
||||||
add(StorySourcesList::All);
|
const auto hidden = result.user->hasStoriesHidden();
|
||||||
if (result.user->hasStoriesHidden()) {
|
using List = StorySourcesList;
|
||||||
applyDeletedFromSources(peerId, StorySourcesList::NotHidden);
|
add(hidden ? List::Hidden : List::NotHidden);
|
||||||
} else {
|
applyDeletedFromSources(
|
||||||
add(StorySourcesList::NotHidden);
|
peerId,
|
||||||
}
|
hidden ? List::NotHidden : List::Hidden);
|
||||||
} else {
|
} else {
|
||||||
applyDeletedFromSources(peerId, StorySourcesList::All);
|
applyDeletedFromSources(peerId, StorySourcesList::NotHidden);
|
||||||
|
applyDeletedFromSources(peerId, StorySourcesList::Hidden);
|
||||||
}
|
}
|
||||||
_sourceChanged.fire_copy(peerId);
|
_sourceChanged.fire_copy(peerId);
|
||||||
}
|
}
|
||||||
|
@ -725,11 +730,11 @@ void Stories::loadMore(StorySourcesList list) {
|
||||||
if (_loadMoreRequestId[index] || _sourcesLoaded[index]) {
|
if (_loadMoreRequestId[index] || _sourcesLoaded[index]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto all = (list == StorySourcesList::All);
|
const auto hidden = (list == StorySourcesList::Hidden);
|
||||||
const auto api = &_owner->session().api();
|
const auto api = &_owner->session().api();
|
||||||
using Flag = MTPstories_GetAllStories::Flag;
|
using Flag = MTPstories_GetAllStories::Flag;
|
||||||
_loadMoreRequestId[index] = api->request(MTPstories_GetAllStories(
|
_loadMoreRequestId[index] = api->request(MTPstories_GetAllStories(
|
||||||
MTP_flags((all ? Flag::f_include_hidden : Flag())
|
MTP_flags((hidden ? Flag::f_hidden : Flag())
|
||||||
| (_sourcesStates[index].isEmpty()
|
| (_sourcesStates[index].isEmpty()
|
||||||
? Flag(0)
|
? Flag(0)
|
||||||
: (Flag::f_next | Flag::f_state))),
|
: (Flag::f_next | Flag::f_state))),
|
||||||
|
@ -917,7 +922,7 @@ void Stories::applyRemovedFromActive(FullStoryId id) {
|
||||||
if (i->second.ids.empty()) {
|
if (i->second.ids.empty()) {
|
||||||
_all.erase(i);
|
_all.erase(i);
|
||||||
removeFromList(StorySourcesList::NotHidden);
|
removeFromList(StorySourcesList::NotHidden);
|
||||||
removeFromList(StorySourcesList::All);
|
removeFromList(StorySourcesList::Hidden);
|
||||||
}
|
}
|
||||||
_sourceChanged.fire_copy(id.peer);
|
_sourceChanged.fire_copy(id.peer);
|
||||||
}
|
}
|
||||||
|
@ -925,21 +930,15 @@ void Stories::applyRemovedFromActive(FullStoryId id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stories::applyDeletedFromSources(PeerId id, StorySourcesList list) {
|
void Stories::applyDeletedFromSources(PeerId id, StorySourcesList list) {
|
||||||
const auto removeFromList = [&](StorySourcesList from) {
|
auto &sources = _sources[static_cast<int>(list)];
|
||||||
auto &sources = _sources[static_cast<int>(from)];
|
const auto i = ranges::find(
|
||||||
const auto i = ranges::find(
|
sources,
|
||||||
sources,
|
id,
|
||||||
id,
|
&StoriesSourceInfo::id);
|
||||||
&StoriesSourceInfo::id);
|
if (i != end(sources)) {
|
||||||
if (i != end(sources)) {
|
sources.erase(i);
|
||||||
sources.erase(i);
|
|
||||||
}
|
|
||||||
_sourcesChanged[static_cast<int>(from)].fire({});
|
|
||||||
};
|
|
||||||
removeFromList(StorySourcesList::NotHidden);
|
|
||||||
if (list == StorySourcesList::All) {
|
|
||||||
removeFromList(StorySourcesList::All);
|
|
||||||
}
|
}
|
||||||
|
_sourcesChanged[static_cast<int>(list)].fire({});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stories::removeDependencyStory(not_null<Story*> story) {
|
void Stories::removeDependencyStory(not_null<Story*> story) {
|
||||||
|
@ -1146,8 +1145,8 @@ void Stories::markAsRead(FullStoryId id, bool viewed) {
|
||||||
sort(list);
|
sort(list);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
refreshInList(StorySourcesList::All);
|
|
||||||
refreshInList(StorySourcesList::NotHidden);
|
refreshInList(StorySourcesList::NotHidden);
|
||||||
|
refreshInList(StorySourcesList::Hidden);
|
||||||
}
|
}
|
||||||
_markReadTimer.callOnce(kMarkAsReadDelay);
|
_markReadTimer.callOnce(kMarkAsReadDelay);
|
||||||
}
|
}
|
||||||
|
@ -1181,37 +1180,36 @@ void Stories::toggleHidden(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
i->second.hidden = hidden;
|
i->second.hidden = hidden;
|
||||||
|
const auto info = i->second.info();
|
||||||
const auto main = static_cast<int>(StorySourcesList::NotHidden);
|
const auto main = static_cast<int>(StorySourcesList::NotHidden);
|
||||||
const auto all = static_cast<int>(StorySourcesList::All);
|
const auto other = static_cast<int>(StorySourcesList::Hidden);
|
||||||
|
const auto proj = &StoriesSourceInfo::id;
|
||||||
if (hidden) {
|
if (hidden) {
|
||||||
const auto i = ranges::find(
|
const auto i = ranges::find(_sources[main], peerId, proj);
|
||||||
_sources[main],
|
|
||||||
peerId,
|
|
||||||
&StoriesSourceInfo::id);
|
|
||||||
if (i != end(_sources[main])) {
|
if (i != end(_sources[main])) {
|
||||||
_sources[main].erase(i);
|
_sources[main].erase(i);
|
||||||
_sourcesChanged[main].fire({});
|
_sourcesChanged[main].fire({});
|
||||||
}
|
}
|
||||||
const auto j = ranges::find(_sources[all], peerId, &StoriesSourceInfo::id);
|
const auto j = ranges::find(_sources[other], peerId, proj);
|
||||||
if (j != end(_sources[all])) {
|
if (j == end(_sources[other])) {
|
||||||
j->hidden = hidden;
|
_sources[other].push_back(info);
|
||||||
_sourcesChanged[all].fire({});
|
} else {
|
||||||
|
*j = info;
|
||||||
}
|
}
|
||||||
|
sort(StorySourcesList::Hidden);
|
||||||
} else {
|
} else {
|
||||||
const auto i = ranges::find(
|
const auto i = ranges::find(_sources[other], peerId, proj);
|
||||||
_sources[all],
|
if (i != end(_sources[other])) {
|
||||||
peerId,
|
_sources[other].erase(i);
|
||||||
&StoriesSourceInfo::id);
|
_sourcesChanged[other].fire({});
|
||||||
if (i != end(_sources[all])) {
|
|
||||||
i->hidden = hidden;
|
|
||||||
_sourcesChanged[all].fire({});
|
|
||||||
|
|
||||||
auto &sources = _sources[main];
|
|
||||||
if (!ranges::contains(sources, peerId, &StoriesSourceInfo::id)) {
|
|
||||||
sources.push_back(*i);
|
|
||||||
sort(StorySourcesList::NotHidden);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const auto j = ranges::find(_sources[main], peerId, proj);
|
||||||
|
if (j == end(_sources[main])) {
|
||||||
|
_sources[main].push_back(info);
|
||||||
|
} else {
|
||||||
|
*j = info;
|
||||||
|
}
|
||||||
|
sort(StorySourcesList::NotHidden);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -172,7 +172,7 @@ enum class NoStory : uchar {
|
||||||
|
|
||||||
enum class StorySourcesList : uchar {
|
enum class StorySourcesList : uchar {
|
||||||
NotHidden,
|
NotHidden,
|
||||||
All,
|
Hidden,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StoriesContextSingle {
|
struct StoriesContextSingle {
|
||||||
|
|
|
@ -322,7 +322,9 @@ State::State(not_null<Data::Stories*> data, Data::StorySourcesList list)
|
||||||
}
|
}
|
||||||
|
|
||||||
Content State::next() {
|
Content State::next() {
|
||||||
auto result = Content{ .full = (_list == Data::StorySourcesList::All) };
|
auto result = Content{
|
||||||
|
.hidden = (_list == Data::StorySourcesList::Hidden)
|
||||||
|
};
|
||||||
const auto &sources = _data->sources(_list);
|
const auto &sources = _data->sources(_list);
|
||||||
result.elements.reserve(sources.size());
|
result.elements.reserve(sources.size());
|
||||||
for (const auto &info : sources) {
|
for (const auto &info : sources) {
|
||||||
|
@ -344,7 +346,8 @@ Content State::next() {
|
||||||
: user->shortName()),
|
: user->shortName()),
|
||||||
.thumbnail = std::move(userpic),
|
.thumbnail = std::move(userpic),
|
||||||
.unread = info.unread,
|
.unread = info.unread,
|
||||||
.hidden = info.hidden,
|
.suggestHide = !info.hidden,
|
||||||
|
.suggestUnhide = info.hidden,
|
||||||
.profile = true,
|
.profile = true,
|
||||||
.skipSmall = user->isSelf(),
|
.skipSmall = user->isSelf(),
|
||||||
});
|
});
|
||||||
|
@ -420,7 +423,7 @@ rpl::producer<Content> LastForPeer(not_null<PeerData*> peer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto resolving = false;
|
auto resolving = false;
|
||||||
auto result = Content{ .full = true };
|
auto result = Content{};
|
||||||
for (const auto id : ids) {
|
for (const auto id : ids) {
|
||||||
const auto storyId = FullStoryId{ peerId, id };
|
const auto storyId = FullStoryId{ peerId, id };
|
||||||
const auto maybe = stories->lookup(storyId);
|
const auto maybe = stories->lookup(storyId);
|
||||||
|
|
|
@ -102,7 +102,9 @@ void List::showContent(Content &&content) {
|
||||||
item.nameCache = QImage();
|
item.nameCache = QImage();
|
||||||
}
|
}
|
||||||
item.element.unread = element.unread;
|
item.element.unread = element.unread;
|
||||||
item.element.hidden = element.hidden;
|
item.element.suggestHide = element.suggestHide;
|
||||||
|
item.element.suggestUnhide = element.suggestUnhide;
|
||||||
|
item.element.profile = element.profile;
|
||||||
} else {
|
} else {
|
||||||
_data.items.emplace_back(Item{ .element = element });
|
_data.items.emplace_back(Item{ .element = element });
|
||||||
}
|
}
|
||||||
|
@ -762,17 +764,19 @@ void List::contextMenuEvent(QContextMenuEvent *e) {
|
||||||
_menu = base::make_unique_q<Ui::PopupMenu>(this);
|
_menu = base::make_unique_q<Ui::PopupMenu>(this);
|
||||||
|
|
||||||
const auto id = item.element.id;
|
const auto id = item.element.id;
|
||||||
const auto hidden = item.element.hidden;
|
|
||||||
if (item.element.profile) {
|
if (item.element.profile) {
|
||||||
_menu->addAction(tr::lng_context_view_profile(tr::now), [=] {
|
_menu->addAction(tr::lng_context_view_profile(tr::now), [=] {
|
||||||
_showProfileRequests.fire_copy(id);
|
_showProfileRequests.fire_copy(id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!_content.full || hidden) {
|
if (item.element.suggestHide) {
|
||||||
_menu->addAction(hidden
|
_menu->addAction(
|
||||||
? tr::lng_stories_show_in_chats(tr::now)
|
tr::lng_stories_hide_to_contacts(tr::now),
|
||||||
: tr::lng_stories_hide_to_contacts(tr::now),
|
[=] { _toggleShown.fire({ .id = id, .shown = false }); });
|
||||||
[=] { _toggleShown.fire({ .id = id, .shown = hidden }); });
|
} else if (item.element.suggestUnhide) {
|
||||||
|
_menu->addAction(
|
||||||
|
tr::lng_stories_show_in_chats(tr::now),
|
||||||
|
[=] { _toggleShown.fire({ .id = id, .shown = true }); });
|
||||||
}
|
}
|
||||||
const auto updateAfterMenuDestroyed = [=] {
|
const auto updateAfterMenuDestroyed = [=] {
|
||||||
const auto globalPosition = QCursor::pos();
|
const auto globalPosition = QCursor::pos();
|
||||||
|
|
|
@ -34,10 +34,11 @@ struct Element {
|
||||||
uint64 id = 0;
|
uint64 id = 0;
|
||||||
QString name;
|
QString name;
|
||||||
std::shared_ptr<Thumbnail> thumbnail;
|
std::shared_ptr<Thumbnail> thumbnail;
|
||||||
bool unread = false;
|
bool unread : 1 = false;
|
||||||
bool hidden = false;
|
bool suggestHide : 1 = false;
|
||||||
bool profile = false;
|
bool suggestUnhide : 1 = false;
|
||||||
bool skipSmall = false;
|
bool profile : 1 = false;
|
||||||
|
bool skipSmall : 1 = false;
|
||||||
|
|
||||||
friend inline bool operator==(
|
friend inline bool operator==(
|
||||||
const Element &a,
|
const Element &a,
|
||||||
|
@ -46,7 +47,7 @@ struct Element {
|
||||||
|
|
||||||
struct Content {
|
struct Content {
|
||||||
std::vector<Element> elements;
|
std::vector<Element> elements;
|
||||||
bool full = false;
|
bool hidden = false;
|
||||||
|
|
||||||
friend inline bool operator==(
|
friend inline bool operator==(
|
||||||
const Content &a,
|
const Content &a,
|
||||||
|
|
|
@ -129,7 +129,7 @@ messageMediaInvoice#f6a548d3 flags:# shipping_address_requested:flags.1?true tes
|
||||||
messageMediaGeoLive#b940c666 flags:# geo:GeoPoint heading:flags.0?int period:int proximity_notification_radius:flags.1?int = MessageMedia;
|
messageMediaGeoLive#b940c666 flags:# geo:GeoPoint heading:flags.0?int period:int proximity_notification_radius:flags.1?int = MessageMedia;
|
||||||
messageMediaPoll#4bd6e798 poll:Poll results:PollResults = MessageMedia;
|
messageMediaPoll#4bd6e798 poll:Poll results:PollResults = MessageMedia;
|
||||||
messageMediaDice#3f7ee58b value:int emoticon:string = MessageMedia;
|
messageMediaDice#3f7ee58b value:int emoticon:string = MessageMedia;
|
||||||
messageMediaStory#cbb20d88 flags:# user_id:long id:int story:flags.0?StoryItem = MessageMedia;
|
messageMediaStory#cbb20d88 flags:# via_mention:flags.1?true user_id:long id:int story:flags.0?StoryItem = MessageMedia;
|
||||||
|
|
||||||
messageActionEmpty#b6aef7b0 = MessageAction;
|
messageActionEmpty#b6aef7b0 = MessageAction;
|
||||||
messageActionChatCreate#bd47cbad title:string users:Vector<long> = MessageAction;
|
messageActionChatCreate#bd47cbad title:string users:Vector<long> = MessageAction;
|
||||||
|
@ -2091,7 +2091,7 @@ stories.sendStory#424cd47a flags:# pinned:flags.2?true media:InputMedia caption:
|
||||||
stories.editStory#2aae7a41 flags:# id:int media:flags.0?InputMedia caption:flags.1?string entities:flags.1?Vector<MessageEntity> privacy_rules:flags.2?Vector<InputPrivacyRule> = Updates;
|
stories.editStory#2aae7a41 flags:# id:int media:flags.0?InputMedia caption:flags.1?string entities:flags.1?Vector<MessageEntity> privacy_rules:flags.2?Vector<InputPrivacyRule> = Updates;
|
||||||
stories.deleteStories#b5d501d7 id:Vector<int> = Vector<int>;
|
stories.deleteStories#b5d501d7 id:Vector<int> = Vector<int>;
|
||||||
stories.togglePinned#51602944 id:Vector<int> pinned:Bool = Vector<int>;
|
stories.togglePinned#51602944 id:Vector<int> pinned:Bool = Vector<int>;
|
||||||
stories.getAllStories#eeb0d625 flags:# next:flags.1?true include_hidden:flags.2?true state:flags.0?string = stories.AllStories;
|
stories.getAllStories#eeb0d625 flags:# next:flags.1?true hidden:flags.2?true state:flags.0?string = stories.AllStories;
|
||||||
stories.getUserStories#96d528e0 user_id:InputUser = stories.UserStories;
|
stories.getUserStories#96d528e0 user_id:InputUser = stories.UserStories;
|
||||||
stories.getPinnedStories#b471137 user_id:InputUser offset_id:int limit:int = stories.Stories;
|
stories.getPinnedStories#b471137 user_id:InputUser offset_id:int limit:int = stories.Stories;
|
||||||
stories.getStoriesArchive#1f5bc5d2 offset_id:int limit:int = stories.Stories;
|
stories.getStoriesArchive#1f5bc5d2 offset_id:int limit:int = stories.Stories;
|
||||||
|
|
Loading…
Add table
Reference in a new issue