| 1207 | } |
| 1208 | |
| 1209 | void Stories::loadAround(FullStoryId id, StoriesContext context) { |
| 1210 | if (v::is<StoriesContextSingle>(context.data) |
| 1211 | || v::is<StoriesContextAlbum>(context.data)) { |
| 1212 | return; |
| 1213 | } |
| 1214 | const auto i = _all.find(id.peer); |
| 1215 | if (i == end(_all)) { |
| 1216 | return; |
| 1217 | } |
| 1218 | const auto j = i->second.ids.lower_bound(StoryIdDates{ id.story }); |
| 1219 | if (j == end(i->second.ids) || j->id != id.story) { |
| 1220 | return; |
| 1221 | } |
| 1222 | const auto ignore = [&] { |
| 1223 | const auto side = kIgnorePreloadAroundIfLoaded; |
| 1224 | const auto left = ranges::min(int(j - begin(i->second.ids)), side); |
| 1225 | const auto right = ranges::min(int(end(i->second.ids) - j), side); |
| 1226 | for (auto k = j - left; k != j + right; ++k) { |
| 1227 | const auto maybeStory = lookup({ id.peer, k->id }); |
| 1228 | if (!maybeStory && maybeStory.error() == NoStory::Unknown) { |
| 1229 | return false; |
| 1230 | } |
| 1231 | } |
| 1232 | return true; |
| 1233 | }(); |
| 1234 | if (ignore) { |
| 1235 | return; |
| 1236 | } |
| 1237 | const auto side = kPreloadAroundCount; |
| 1238 | const auto left = ranges::min(int(j - begin(i->second.ids)), side); |
| 1239 | const auto right = ranges::min(int(end(i->second.ids) - j), side); |
| 1240 | const auto from = j - left; |
| 1241 | const auto till = j + right; |
| 1242 | for (auto k = from; k != till; ++k) { |
| 1243 | resolve({ id.peer, k->id }, nullptr); |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | void Stories::markAsRead(FullStoryId id, bool viewed) { |
| 1248 | if (id.peer == _owner->session().userPeerId()) { |