Support media timestamps in replies to stories.

This commit is contained in:
levlam 2023-06-13 18:20:26 +03:00
parent f182e105eb
commit 29a1b7e3d6
3 changed files with 58 additions and 1 deletions

View File

@ -3505,6 +3505,7 @@ bool can_message_content_have_media_timestamp(const MessageContent *content) {
CHECK(content != nullptr);
switch (content->get_type()) {
case MessageContentType::Audio:
case MessageContentType::Story:
case MessageContentType::Video:
case MessageContentType::VideoNote:
case MessageContentType::VoiceNote:
@ -4334,6 +4335,9 @@ void register_message_content(Td *td, const MessageContent *content, FullMessage
case MessageContentType::SuggestProfilePhoto:
return td->contacts_manager_->register_suggested_profile_photo(
static_cast<const MessageSuggestProfilePhoto *>(content)->photo);
case MessageContentType::Story:
return td->story_manager_->register_story(static_cast<const MessageStory *>(content)->story_full_id,
full_message_id, source);
default:
return;
}
@ -4387,6 +4391,12 @@ void reregister_message_content(Td *td, const MessageContent *old_content, const
return;
}
break;
case MessageContentType::Story:
if (static_cast<const MessageStory *>(old_content)->story_full_id ==
static_cast<const MessageStory *>(new_content)->story_full_id) {
return;
}
break;
default:
return;
}
@ -4424,6 +4434,9 @@ void unregister_message_content(Td *td, const MessageContent *content, FullMessa
case MessageContentType::GiftPremium:
return td->stickers_manager_->unregister_premium_gift(static_cast<const MessageGiftPremium *>(content)->months,
full_message_id, source);
case MessageContentType::Story:
return td->story_manager_->unregister_story(static_cast<const MessageStory *>(content)->story_full_id,
full_message_id, source);
default:
return;
}
@ -6112,6 +6125,10 @@ int32 get_message_content_media_duration(const MessageContent *content, const Td
}
case MessageContentType::Invoice:
return static_cast<const MessageInvoice *>(content)->input_invoice.get_duration(td);
case MessageContentType::Story: {
auto story_full_id = static_cast<const MessageStory *>(content)->story_full_id;
return td->story_manager_->get_story_duration(story_full_id);
}
case MessageContentType::Text: {
auto web_page_id = static_cast<const MessageText *>(content)->web_page_id;
return td->web_pages_manager_->get_web_page_media_duration(web_page_id);

View File

@ -465,7 +465,8 @@ StoryManager::StoryManager(Td *td, ActorShared<> parent) : td_(td), parent_(std:
}
StoryManager::~StoryManager() {
Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), story_full_id_to_file_source_id_, stories_);
Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), story_full_id_to_file_source_id_, stories_,
inaccessible_story_full_ids_, deleted_story_full_ids_, story_messages_);
}
void StoryManager::tear_down() {
@ -637,6 +638,28 @@ int32 StoryManager::get_story_duration(StoryFullId story_full_id) const {
return get_story_content_duration(td_, content);
}
void StoryManager::register_story(StoryFullId story_full_id, FullMessageId full_message_id, const char *source) {
if (td_->auth_manager_->is_bot()) {
return;
}
LOG(INFO) << "Register " << story_full_id << " from " << full_message_id << " from " << source;
story_messages_[story_full_id].insert(full_message_id);
}
void StoryManager::unregister_story(StoryFullId story_full_id, FullMessageId full_message_id, const char *source) {
if (td_->auth_manager_->is_bot()) {
return;
}
LOG(INFO) << "Unregister " << story_full_id << " from " << full_message_id << " from " << source;
auto &message_ids = story_messages_[story_full_id];
auto is_deleted = message_ids.erase(full_message_id) > 0;
LOG_CHECK(is_deleted) << source << ' ' << story_full_id << ' ' << full_message_id;
if (message_ids.empty()) {
story_messages_.erase(story_full_id);
}
}
td_api::object_ptr<td_api::story> StoryManager::get_story_object(StoryFullId story_full_id) const {
return get_story_object(story_full_id, get_story(story_full_id));
}
@ -881,6 +904,16 @@ void StoryManager::on_story_changed(StoryFullId story_full_id, const Story *stor
send_closure_later(G()->messages_manager(),
&MessagesManager::update_story_max_reply_media_timestamp_in_replied_messages, story_full_id);
send_closure_later(G()->web_pages_manager(), &WebPagesManager::on_story_changed, story_full_id);
if (story_messages_.count(story_full_id) != 0) {
vector<FullMessageId> full_message_ids;
story_messages_[story_full_id].foreach(
[&full_message_ids](const FullMessageId &full_message_id) { full_message_ids.push_back(full_message_id); });
CHECK(!full_message_ids.empty());
for (const auto &full_message_id : full_message_ids) {
td_->messages_manager_->on_external_update_message_content(full_message_id);
}
}
}
}

View File

@ -9,6 +9,7 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/FullMessageId.h"
#include "td/telegram/MessageEntity.h"
#include "td/telegram/StoryFullId.h"
#include "td/telegram/StoryId.h"
@ -116,6 +117,10 @@ class StoryManager final : public Actor {
int32 get_story_duration(StoryFullId story_full_id) const;
void register_story(StoryFullId story_full_id, FullMessageId full_message_id, const char *source);
void unregister_story(StoryFullId story_full_id, FullMessageId full_message_id, const char *source);
td_api::object_ptr<td_api::story> get_story_object(StoryFullId story_full_id) const;
td_api::object_ptr<td_api::stories> get_stories_object(int32 total_count,
@ -203,6 +208,8 @@ class StoryManager final : public Actor {
WaitFreeHashSet<StoryFullId, StoryFullIdHash> deleted_story_full_ids_;
WaitFreeHashMap<StoryFullId, WaitFreeHashSet<FullMessageId, FullMessageIdHash>, StoryFullIdHash> story_messages_;
FlatHashMap<StoryFullId, unique_ptr<BeingEditedStory>, StoryFullIdHash> being_edited_stories_;
uint32 send_story_count_ = 0;