Add FullMessageId.h.

GitOrigin-RevId: 758133149ff3317b3d9d3f86b1a841e8f34ca35a
This commit is contained in:
levlam 2019-11-26 19:53:10 +03:00
parent 099e767b6b
commit 0618005a95
15 changed files with 92 additions and 68 deletions

View File

@ -558,6 +558,7 @@ set(TDLIB_SOURCE
td/telegram/files/ResourceManager.h
td/telegram/files/ResourceState.h
td/telegram/FolderId.h
td/telegram/FullMessageId.h
td/telegram/Game.h
td/telegram/Global.h
td/telegram/HashtagHints.h

View File

@ -10,6 +10,7 @@
#include "td/telegram/telegram_api.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/FullMessageId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/UserId.h"

View File

@ -14,7 +14,7 @@
#include "td/telegram/ChatId.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/FullMessageId.h"
#include "td/telegram/PhotoSizeSource.h"
#include "td/telegram/SetWithPosition.h"
#include "td/telegram/UserId.h"

View File

@ -0,0 +1,70 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
//
// 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/MessageId.h"
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"
#include <functional>
namespace td {
struct FullMessageId {
private:
DialogId dialog_id;
MessageId message_id;
public:
FullMessageId() : dialog_id(), message_id() {
}
FullMessageId(DialogId dialog_id, MessageId message_id) : dialog_id(dialog_id), message_id(message_id) {
}
bool operator==(const FullMessageId &other) const {
return dialog_id == other.dialog_id && message_id == other.message_id;
}
bool operator!=(const FullMessageId &other) const {
return !(*this == other);
}
DialogId get_dialog_id() const {
return dialog_id;
}
MessageId get_message_id() const {
return message_id;
}
template <class StorerT>
void store(StorerT &storer) const {
dialog_id.store(storer);
message_id.store(storer);
}
template <class ParserT>
void parse(ParserT &parser) {
dialog_id.parse(parser);
message_id.parse(parser);
}
};
struct FullMessageIdHash {
std::size_t operator()(FullMessageId full_message_id) const {
return DialogIdHash()(full_message_id.get_dialog_id()) * 2023654985u +
MessageIdHash()(full_message_id.get_message_id());
}
};
inline StringBuilder &operator<<(StringBuilder &string_builder, FullMessageId full_message_id) {
return string_builder << full_message_id.get_message_id() << " in " << full_message_id.get_dialog_id();
}
} // namespace td

View File

@ -9,6 +9,7 @@
#include "td/telegram/Dependencies.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/FullMessageId.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/MessageEntity.h"
#include "td/telegram/MessageId.h"

View File

@ -63,6 +63,11 @@ MessageType MessageId::get_type() const {
}
}
ServerMessageId MessageId::get_server_message_id() const {
CHECK(id == 0 || is_server());
return ServerMessageId(narrow_cast<int32>(id >> SERVER_ID_SHIFT));
}
MessageId MessageId::get_next_message_id(MessageType type) const {
switch (type) {
case MessageType::Server:

View File

@ -6,12 +6,10 @@
//
#pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/ServerMessageId.h"
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"
#include "td/utils/tl_helpers.h"
#include <functional>
#include <limits>
@ -97,10 +95,7 @@ class MessageId {
return (id & SHORT_TYPE_MASK) == 0;
}
ServerMessageId get_server_message_id() const {
CHECK(id == 0 || is_server());
return ServerMessageId(narrow_cast<int32>(id >> SERVER_ID_SHIFT));
}
ServerMessageId get_server_message_id() const;
// returns greatest server message id not bigger than this message id
MessageId get_prev_server_message_id() const {
@ -144,57 +139,4 @@ struct MessageIdHash {
}
};
struct FullMessageId {
private:
DialogId dialog_id;
MessageId message_id;
public:
FullMessageId() : dialog_id(), message_id() {
}
FullMessageId(DialogId dialog_id, MessageId message_id) : dialog_id(dialog_id), message_id(message_id) {
}
bool operator==(const FullMessageId &other) const {
return dialog_id == other.dialog_id && message_id == other.message_id;
}
bool operator!=(const FullMessageId &other) const {
return !(*this == other);
}
DialogId get_dialog_id() const {
return dialog_id;
}
MessageId get_message_id() const {
return message_id;
}
template <class StorerT>
void store(StorerT &storer) const {
using ::td::store;
store(dialog_id, storer);
store(message_id, storer);
}
template <class ParserT>
void parse(ParserT &parser) {
using ::td::parse;
parse(dialog_id, parser);
parse(message_id, parser);
}
};
struct FullMessageIdHash {
std::size_t operator()(FullMessageId full_message_id) const {
return DialogIdHash()(full_message_id.get_dialog_id()) * 2023654985u +
MessageIdHash()(full_message_id.get_message_id());
}
};
inline StringBuilder &operator<<(StringBuilder &string_builder, FullMessageId full_message_id) {
return string_builder << full_message_id.get_message_id() << " in " << full_message_id.get_dialog_id();
}
} // namespace td

View File

@ -7,6 +7,7 @@
#pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/FullMessageId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/NotificationId.h"
#include "td/telegram/ServerMessageId.h"

View File

@ -24369,8 +24369,8 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
auto web_page_id = get_message_content_web_page_id(message->content.get());
if (web_page_id.is_valid() && !td_->web_pages_manager_->have_web_page(web_page_id)) {
waiting_for_web_page_messages_.emplace(dialog_id, message_id);
send_closure(G()->web_pages_manager(), &WebPagesManager::wait_for_pending_web_page, dialog_id, message_id,
web_page_id);
send_closure(G()->web_pages_manager(), &WebPagesManager::wait_for_pending_web_page,
FullMessageId{dialog_id, message_id}, web_page_id);
}
if (*need_update && message_id.get() <= d->last_new_message_id.get()) {

View File

@ -22,6 +22,7 @@
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/FolderId.h"
#include "td/telegram/FullMessageId.h"
#include "td/telegram/Global.h"
#include "td/telegram/MessageContent.h"
#include "td/telegram/MessageEntity.h"

View File

@ -9,6 +9,7 @@
#include "td/telegram/CallId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/Document.h"
#include "td/telegram/FullMessageId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/Notification.h"
#include "td/telegram/NotificationGroupId.h"

View File

@ -6,7 +6,7 @@
//
#pragma once
#include "td/telegram/MessageId.h"
#include "td/telegram/FullMessageId.h"
#include "td/telegram/net/NetQuery.h"
#include "td/telegram/PollId.h"
#include "td/telegram/ReplyMarkup.h"

View File

@ -34,6 +34,7 @@
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/files/FileType.h"
#include "td/telegram/FolderId.h"
#include "td/telegram/FullMessageId.h"
#include "td/telegram/Global.h"
#include "td/telegram/HashtagHints.h"
#include "td/telegram/InlineQueriesManager.h"

View File

@ -639,9 +639,9 @@ void WebPagesManager::on_get_web_page_by_url(const string &url, WebPageId web_pa
cached_web_page_id = web_page_id;
}
void WebPagesManager::wait_for_pending_web_page(DialogId dialog_id, MessageId message_id, WebPageId web_page_id) {
LOG(INFO) << "Waiting for " << web_page_id << " needed in " << message_id << " in " << dialog_id;
pending_web_pages_[web_page_id].emplace(dialog_id, message_id);
void WebPagesManager::wait_for_pending_web_page(FullMessageId full_message_id, WebPageId web_page_id) {
LOG(INFO) << "Waiting for " << web_page_id << " needed in " << full_message_id;
pending_web_pages_[web_page_id].emplace(full_message_id);
pending_web_pages_timeout_.add_timeout_in(web_page_id.get(), 1.0);
}

View File

@ -12,7 +12,7 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/FullMessageId.h"
#include "td/telegram/Photo.h"
#include "td/telegram/WebPageId.h"
@ -47,7 +47,7 @@ class WebPagesManager : public Actor {
void on_get_web_page_by_url(const string &url, WebPageId web_page_id, bool from_database);
void wait_for_pending_web_page(DialogId dialog_id, MessageId message_id, WebPageId web_page_id);
void wait_for_pending_web_page(FullMessageId full_message_id, WebPageId web_page_id);
bool have_web_page(WebPageId web_page_id) const;