| 166 | } |
| 167 | |
| 168 | void Forum::requestTopics() { |
| 169 | if (_topicsList.loaded() || _requestId) { |
| 170 | return; |
| 171 | } |
| 172 | const auto firstLoad = !_offset.date; |
| 173 | const auto loadCount = firstLoad ? kTopicsFirstLoad : kTopicsPerPage; |
| 174 | _requestId = session().api().request(MTPmessages_GetForumTopics( |
| 175 | MTP_flags(0), |
| 176 | peer()->input(), |
| 177 | MTPstring(), // q |
| 178 | MTP_int(_offset.date), |
| 179 | MTP_int(_offset.id), |
| 180 | MTP_int(_offset.topicId), |
| 181 | MTP_int(loadCount) |
| 182 | )).done([=](const MTPmessages_ForumTopics &result) { |
| 183 | const auto previousOffset = _offset; |
| 184 | applyReceivedTopics(result, _offset); |
| 185 | const auto &list = result.data().vtopics().v; |
| 186 | if (list.isEmpty() |
| 187 | || list.size() == result.data().vcount().v |
| 188 | || (_offset == previousOffset)) { |
| 189 | _topicsList.setLoaded(); |
| 190 | } |
| 191 | _requestId = 0; |
| 192 | _chatsListChanges.fire({}); |
| 193 | if (_topicsList.loaded()) { |
| 194 | _chatsListLoadedEvents.fire({}); |
| 195 | } |
| 196 | reorderLastTopics(); |
| 197 | requestSomeStale(); |
| 198 | }).fail([=](const MTP::Error &error) { |
| 199 | _requestId = 0; |
| 200 | _topicsList.setLoaded(); |
| 201 | if (error.type() == u"CHANNEL_FORUM_MISSING"_q && channel()) { |
| 202 | const auto flags = channel()->flags() & ~ChannelDataFlag::Forum; |
| 203 | channel()->setFlags(flags); |
| 204 | } |
| 205 | }).send(); |
| 206 | } |
| 207 | |
| 208 | void Forum::applyTopicDeleted(MsgId rootId) { |
| 209 | _topicsDeleted.emplace(rootId); |