Process telegram_api::updateStory updates.

This commit is contained in:
levlam 2023-06-01 16:27:00 +03:00
parent 7bea5721bf
commit eec9826dec
4 changed files with 46 additions and 5 deletions

View File

@ -535,6 +535,31 @@ void StoryManager::change_story_files(StoryFullId story_full_id, const Story *st
}
}
void StoryManager::on_get_story(DialogId owner_dialog_id,
telegram_api::object_ptr<telegram_api::StoryItem> &&story_item_ptr) {
if (!owner_dialog_id.is_valid()) {
LOG(ERROR) << "Receive a story in " << owner_dialog_id;
return;
}
CHECK(story_item_ptr != nullptr);
switch (story_item_ptr->get_id()) {
case telegram_api::storyItemDeleted::ID: {
auto story_item = telegram_api::move_object_as<telegram_api::storyItemDeleted>(story_item_ptr);
on_delete_story(owner_dialog_id, StoryId(story_item->id_));
break;
}
case telegram_api::storyItemSkipped::ID:
LOG(ERROR) << "Receive storyItemSkipped";
break;
case telegram_api::storyItem::ID: {
on_get_story(owner_dialog_id, telegram_api::move_object_as<telegram_api::storyItem>(story_item_ptr));
break;
}
default:
UNREACHABLE();
}
}
StoryId StoryManager::on_get_story(DialogId owner_dialog_id,
telegram_api::object_ptr<telegram_api::storyItem> &&story_item) {
CHECK(story_item != nullptr);
@ -602,6 +627,16 @@ StoryId StoryManager::on_get_story(DialogId owner_dialog_id,
return story_id;
}
void StoryManager::on_delete_story(DialogId owner_dialog_id, StoryId story_id) {
if (!story_id.is_server()) {
LOG(ERROR) << "Receive deleted " << story_id << " in " << owner_dialog_id;
return;
}
StoryFullId story_full_id{owner_dialog_id, story_id};
stories_.erase(story_full_id);
}
void StoryManager::on_story_changed(StoryFullId story_full_id, const Story *story, bool is_changed,
bool need_save_to_database) {
if (is_changed || need_save_to_database) {

View File

@ -93,7 +93,7 @@ class StoryManager final : public Actor {
void get_dialog_expiring_stories(DialogId owner_dialog_id, Promise<td_api::object_ptr<td_api::stories>> &&promise);
StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr<telegram_api::storyItem> &&story_item);
void on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr<telegram_api::StoryItem> &&story_item_ptr);
std::pair<int32, vector<StoryId>> on_get_stories(DialogId owner_dialog_id,
telegram_api::object_ptr<telegram_api::stories_stories> &&stories);
@ -125,6 +125,10 @@ class StoryManager final : public Actor {
td_api::object_ptr<td_api::story> get_story_object(StoryFullId story_full_id, const Story *story) const;
StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr<telegram_api::storyItem> &&story_item);
void on_delete_story(DialogId owner_dialog_id, StoryId story_id);
vector<StoryId> on_get_stories(DialogId owner_dialog_id,
vector<telegram_api::object_ptr<telegram_api::StoryItem>> &&stories);

View File

@ -54,6 +54,7 @@
#include "td/telegram/StickerSetId.h"
#include "td/telegram/StickersManager.h"
#include "td/telegram/StickerType.h"
#include "td/telegram/StoryManager.h"
#include "td/telegram/Td.h"
#include "td/telegram/td_api.h"
#include "td/telegram/TdDb.h"
@ -4189,12 +4190,13 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateAutoSaveSetting
promise.set_value(Unit());
}
// unsupported updates
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateStory> update, Promise<Unit> &&promise) {
td_->story_manager_->on_get_story(DialogId(UserId(update->user_id_)), std::move(update->story_));
promise.set_value(Unit());
}
// unsupported updates
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadStories> update, Promise<Unit> &&promise) {
promise.set_value(Unit());
}

View File

@ -613,10 +613,10 @@ class UpdatesManager final : public Actor {
void on_update(tl_object_ptr<telegram_api::updateAutoSaveSettings> update, Promise<Unit> &&promise);
// unsupported updates
void on_update(tl_object_ptr<telegram_api::updateStory> update, Promise<Unit> &&promise);
// unsupported updates
void on_update(tl_object_ptr<telegram_api::updateReadStories> update, Promise<Unit> &&promise);
void on_update(tl_object_ptr<telegram_api::updateStoryID> update, Promise<Unit> &&promise);