mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-24 14:33:02 +02:00
feat: save deleted entities
This commit is contained in:
parent
06d8d14ad7
commit
608bcf7d42
3 changed files with 59 additions and 3 deletions
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "api/api_chat_participants.h"
|
||||
#include "api/api_text_entities.h"
|
||||
#include "ayu/utils/ayu_mapper.h"
|
||||
#include "ayu/ui/message_history/history_inner.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "core/application.h"
|
||||
|
@ -118,7 +119,10 @@ void GenerateItems(
|
|||
};
|
||||
|
||||
const auto text = QString::fromStdString(message.text);
|
||||
addSimpleTextMessage(Ui::Text::WithEntities(text));
|
||||
auto textAndEntities = Ui::Text::WithEntities(text);
|
||||
const auto entities = AyuMapper::deserializeTextWithEntities(message.textEntities);
|
||||
textAndEntities.entities = Api::EntitiesFromMTP(&history->session(), entities.v);
|
||||
addSimpleTextMessage(std::move(textAndEntities));
|
||||
}
|
||||
|
||||
} // namespace MessageHistory
|
||||
|
|
|
@ -6,9 +6,14 @@
|
|||
// Copyright @Radolyn, 2025
|
||||
#include "ayu_mapper.h"
|
||||
|
||||
#include "apiwrap.h"
|
||||
#include "api/api_text_entities.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/history_item_components.h"
|
||||
#include "main/main_session.h"
|
||||
#include "mtproto/connection_abstract.h"
|
||||
#include "mtproto/details/mtproto_dump_to_text.h"
|
||||
|
||||
namespace AyuMapper {
|
||||
|
||||
|
@ -39,17 +44,57 @@ constexpr auto kMessageFlagHasTTL = 0x02000000;
|
|||
constexpr auto kMessageFlagInvertMedia = 0x08000000;
|
||||
constexpr auto kMessageFlagHasSavedPeer = 0x10000000;
|
||||
|
||||
template<typename MTPObject>
|
||||
std::vector<char> serializeObject(MTPObject object) {
|
||||
mtpBuffer buffer;
|
||||
|
||||
object.write(buffer);
|
||||
|
||||
auto from = reinterpret_cast<char*>(buffer.data());
|
||||
const auto end = from + buffer.size() * sizeof(mtpBuffer);
|
||||
|
||||
std::vector<char> entities(from, end);
|
||||
return entities;
|
||||
}
|
||||
|
||||
template<typename MTPObject>
|
||||
MTPObject deserializeObject(std::vector<char> serialized) {
|
||||
gsl::span<char> span(serialized.data(), serialized.size());
|
||||
|
||||
auto from = reinterpret_cast<const mtpPrime*>(span.data());
|
||||
const auto end = from + span.size() / sizeof(mtpPrime);
|
||||
|
||||
MTPObject data;
|
||||
if (!data.read(from, end)) {
|
||||
LOG(("AyuMapper: Failed to deserialize object"));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
std::pair<std::string, std::vector<char>> serializeTextWithEntities(not_null<HistoryItem*> item) {
|
||||
if (item->emptyText()) {
|
||||
return std::make_pair("", std::vector<char>());
|
||||
}
|
||||
|
||||
auto textWithEntities = item->originalText();
|
||||
std::vector<char> entities; // todo: implement writing to buffer
|
||||
|
||||
|
||||
std::vector<char> entities;
|
||||
if (!textWithEntities.entities.empty()) {
|
||||
const auto mtpEntities = Api::EntitiesToMTP(
|
||||
&item->history()->session(),
|
||||
textWithEntities.entities,
|
||||
Api::ConvertOption::WithLocal);
|
||||
|
||||
entities = serializeObject(mtpEntities);
|
||||
}
|
||||
|
||||
return std::make_pair(textWithEntities.text.toStdString(), entities);
|
||||
}
|
||||
|
||||
MTPVector<MTPMessageEntity> deserializeTextWithEntities(std::vector<char> serialized) {
|
||||
return deserializeObject<MTPVector<MTPMessageEntity>>(serialized);
|
||||
}
|
||||
|
||||
int mapItemFlagsToMTPFlags(not_null<HistoryItem*> item) {
|
||||
int flags = 0;
|
||||
|
||||
|
|
|
@ -8,7 +8,14 @@
|
|||
|
||||
namespace AyuMapper {
|
||||
|
||||
template<typename MTPObject>
|
||||
[[nodiscard]] MTPObject deserializeObject(std::vector<char> serialized);
|
||||
|
||||
template<typename MTPObject>
|
||||
[[nodiscard]] std::vector<char> serializeObject(MTPObject object);
|
||||
|
||||
std::pair<std::string, std::vector<char>> serializeTextWithEntities(not_null<HistoryItem*> item);
|
||||
[[nodiscard]] MTPVector<MTPMessageEntity> deserializeTextWithEntities(std::vector<char> serialized);
|
||||
int mapItemFlagsToMTPFlags(not_null<HistoryItem*> item);
|
||||
|
||||
} // namespace AyuMapper
|
||||
|
|
Loading…
Add table
Reference in a new issue