Add class StoryFullId.
This commit is contained in:
parent
50a0ae50af
commit
c202439a04
@ -763,6 +763,7 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/StorageManager.h
|
td/telegram/StorageManager.h
|
||||||
td/telegram/StoryContent.h
|
td/telegram/StoryContent.h
|
||||||
td/telegram/StoryContentType.h
|
td/telegram/StoryContentType.h
|
||||||
|
td/telegram/StoryFullId.h
|
||||||
td/telegram/StoryId.h
|
td/telegram/StoryId.h
|
||||||
td/telegram/StoryInteractionInfo.h
|
td/telegram/StoryInteractionInfo.h
|
||||||
td/telegram/StoryManager.h
|
td/telegram/StoryManager.h
|
||||||
|
69
td/telegram/StoryFullId.h
Normal file
69
td/telegram/StoryFullId.h
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/telegram/DialogId.h"
|
||||||
|
#include "td/telegram/StoryId.h"
|
||||||
|
|
||||||
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/StringBuilder.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
struct StoryFullId {
|
||||||
|
private:
|
||||||
|
DialogId dialog_id;
|
||||||
|
StoryId story_id;
|
||||||
|
|
||||||
|
public:
|
||||||
|
StoryFullId() : dialog_id(), story_id() {
|
||||||
|
}
|
||||||
|
|
||||||
|
StoryFullId(DialogId dialog_id, StoryId story_id) : dialog_id(dialog_id), story_id(story_id) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const StoryFullId &other) const {
|
||||||
|
return dialog_id == other.dialog_id && story_id == other.story_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const StoryFullId &other) const {
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
DialogId get_dialog_id() const {
|
||||||
|
return dialog_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
StoryId get_story_id() const {
|
||||||
|
return story_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class StorerT>
|
||||||
|
void store(StorerT &storer) const {
|
||||||
|
dialog_id.store(storer);
|
||||||
|
story_id.store(storer);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ParserT>
|
||||||
|
void parse(ParserT &parser) {
|
||||||
|
dialog_id.parse(parser);
|
||||||
|
story_id.parse(parser);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct StoryFullIdHash {
|
||||||
|
uint32 operator()(StoryFullId story_full_id) const {
|
||||||
|
return DialogIdHash()(story_full_id.get_dialog_id()) * 2023654985u +
|
||||||
|
StoryIdHash()(story_full_id.get_story_id());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline StringBuilder &operator<<(StringBuilder &string_builder, StoryFullId story_full_id) {
|
||||||
|
return string_builder << story_full_id.get_story_id() << " in " << story_full_id.get_dialog_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace td
|
@ -28,12 +28,12 @@ bool StoryManager::is_local_story_id(StoryId story_id) {
|
|||||||
return story_id.get() < 0;
|
return story_id.get() < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const StoryManager::Story *StoryManager::get_story(StoryId story_id) const {
|
const StoryManager::Story *StoryManager::get_story(StoryFullId story_full_id) const {
|
||||||
return stories_.get_pointer(story_id);
|
return stories_.get_pointer(story_full_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
StoryManager::Story *StoryManager::get_story_editable(StoryId story_id) {
|
StoryManager::Story *StoryManager::get_story_editable(StoryFullId story_full_id) {
|
||||||
return stories_.get_pointer(story_id);
|
return stories_.get_pointer(story_full_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
StoryId StoryManager::on_get_story(DialogId owner_dialog_id,
|
StoryId StoryManager::on_get_story(DialogId owner_dialog_id,
|
||||||
@ -44,13 +44,14 @@ StoryId StoryManager::on_get_story(DialogId owner_dialog_id,
|
|||||||
return StoryId();
|
return StoryId();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto story = get_story_editable(story_id);
|
StoryFullId story_full_id{owner_dialog_id, story_id};
|
||||||
|
auto story = get_story_editable(story_full_id);
|
||||||
bool is_changed = false;
|
bool is_changed = false;
|
||||||
bool need_save_to_database = false;
|
bool need_save_to_database = false;
|
||||||
if (story == nullptr) {
|
if (story == nullptr) {
|
||||||
auto s = make_unique<Story>();
|
auto s = make_unique<Story>();
|
||||||
story = s.get();
|
story = s.get();
|
||||||
stories_.set(story_id, std::move(s));
|
stories_.set(story_full_id, std::move(s));
|
||||||
}
|
}
|
||||||
CHECK(story != nullptr);
|
CHECK(story != nullptr);
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "td/telegram/DialogId.h"
|
#include "td/telegram/DialogId.h"
|
||||||
#include "td/telegram/MessageEntity.h"
|
#include "td/telegram/MessageEntity.h"
|
||||||
|
#include "td/telegram/StoryFullId.h"
|
||||||
#include "td/telegram/StoryId.h"
|
#include "td/telegram/StoryId.h"
|
||||||
#include "td/telegram/StoryInteractionInfo.h"
|
#include "td/telegram/StoryInteractionInfo.h"
|
||||||
#include "td/telegram/UserId.h"
|
#include "td/telegram/UserId.h"
|
||||||
@ -49,13 +50,13 @@ class StoryManager final : public Actor {
|
|||||||
|
|
||||||
void tear_down() final;
|
void tear_down() final;
|
||||||
|
|
||||||
const Story *get_story(StoryId story_id) const;
|
const Story *get_story(StoryFullId story_full_id) const;
|
||||||
|
|
||||||
Story *get_story_editable(StoryId story_id);
|
Story *get_story_editable(StoryFullId story_full_id);
|
||||||
|
|
||||||
static bool is_local_story_id(StoryId story_id);
|
static bool is_local_story_id(StoryId story_id);
|
||||||
|
|
||||||
WaitFreeHashMap<StoryId, unique_ptr<Story>, StoryIdHash> stories_;
|
WaitFreeHashMap<StoryFullId, unique_ptr<Story>, StoryFullIdHash> stories_;
|
||||||
|
|
||||||
Td *td_;
|
Td *td_;
|
||||||
ActorShared<> parent_;
|
ActorShared<> parent_;
|
||||||
|
Loading…
Reference in New Issue
Block a user