Add and use MessageOrigin::get_message_full_id.
This commit is contained in:
parent
7b1408d44e
commit
9e82513802
@ -103,6 +103,13 @@ bool MessageOrigin::is_sender_hidden() const {
|
|||||||
return sender_dialog_id_ == hidden_sender_dialog_id && !author_signature_.empty() && !message_id_.is_valid();
|
return sender_dialog_id_ == hidden_sender_dialog_id && !author_signature_.empty() && !message_id_.is_valid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MessageFullId MessageOrigin::get_message_full_id() const {
|
||||||
|
if (!message_id_.is_valid() || !sender_dialog_id_.is_valid() || is_sender_hidden()) {
|
||||||
|
return MessageFullId();
|
||||||
|
}
|
||||||
|
return {sender_dialog_id_, message_id_};
|
||||||
|
}
|
||||||
|
|
||||||
DialogId MessageOrigin::get_sender() const {
|
DialogId MessageOrigin::get_sender() const {
|
||||||
if (is_sender_hidden()) {
|
if (is_sender_hidden()) {
|
||||||
return DialogId();
|
return DialogId();
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "td/telegram/ChannelId.h"
|
#include "td/telegram/ChannelId.h"
|
||||||
#include "td/telegram/DialogId.h"
|
#include "td/telegram/DialogId.h"
|
||||||
|
#include "td/telegram/MessageFullId.h"
|
||||||
#include "td/telegram/MessageId.h"
|
#include "td/telegram/MessageId.h"
|
||||||
#include "td/telegram/td_api.h"
|
#include "td/telegram/td_api.h"
|
||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
@ -48,6 +49,8 @@ struct MessageOrigin {
|
|||||||
|
|
||||||
bool is_sender_hidden() const;
|
bool is_sender_hidden() const;
|
||||||
|
|
||||||
|
MessageFullId get_message_full_id() const;
|
||||||
|
|
||||||
bool is_channel_post() const {
|
bool is_channel_post() const {
|
||||||
return message_id_.is_valid();
|
return message_id_.is_valid();
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,7 @@ void MessageOrigin::parse(ParserT &parser) {
|
|||||||
}
|
}
|
||||||
if (has_sender_dialog_id) {
|
if (has_sender_dialog_id) {
|
||||||
td::parse(sender_dialog_id_, parser);
|
td::parse(sender_dialog_id_, parser);
|
||||||
|
CHECK(sender_dialog_id_.get_type() == DialogType::Channel);
|
||||||
}
|
}
|
||||||
if (has_message_id) {
|
if (has_message_id) {
|
||||||
td::parse(message_id_, parser);
|
td::parse(message_id_, parser);
|
||||||
|
@ -18460,10 +18460,12 @@ Status MessagesManager::can_get_media_timestamp_link(DialogId dialog_id, const M
|
|||||||
if (dialog_id.get_type() != DialogType::Channel) {
|
if (dialog_id.get_type() != DialogType::Channel) {
|
||||||
auto forward_info = m->forward_info.get();
|
auto forward_info = m->forward_info.get();
|
||||||
if (!can_message_content_have_media_timestamp(m->content.get()) || forward_info == nullptr ||
|
if (!can_message_content_have_media_timestamp(m->content.get()) || forward_info == nullptr ||
|
||||||
forward_info->is_imported || is_forward_info_sender_hidden(forward_info) ||
|
forward_info->is_imported) {
|
||||||
!forward_info->origin.message_id_.is_valid() || !m->forward_info->origin.message_id_.is_server() ||
|
return Status::Error(400, "Message links are available only for messages in supergroups and channel chats");
|
||||||
!forward_info->origin.sender_dialog_id_.is_valid() ||
|
}
|
||||||
forward_info->origin.sender_dialog_id_.get_type() != DialogType::Channel) {
|
auto origin_message_full_id = forward_info->origin.get_message_full_id();
|
||||||
|
auto origin_message_id = origin_message_full_id.get_message_id();
|
||||||
|
if (!origin_message_id.is_valid() || !origin_message_id.is_server()) {
|
||||||
return Status::Error(400, "Message links are available only for messages in supergroups and channel chats");
|
return Status::Error(400, "Message links are available only for messages in supergroups and channel chats");
|
||||||
}
|
}
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
@ -18525,13 +18527,14 @@ Result<std::pair<string, bool>> MessagesManager::get_message_link(MessageFullId
|
|||||||
auto message_id = m->message_id;
|
auto message_id = m->message_id;
|
||||||
if (dialog_id.get_type() != DialogType::Channel) {
|
if (dialog_id.get_type() != DialogType::Channel) {
|
||||||
CHECK(m->forward_info != nullptr);
|
CHECK(m->forward_info != nullptr);
|
||||||
CHECK(m->forward_info->origin.sender_dialog_id_.get_type() == DialogType::Channel);
|
|
||||||
|
|
||||||
dialog_id = m->forward_info->origin.sender_dialog_id_;
|
auto origin_message_full_id = m->forward_info->origin.get_message_full_id();
|
||||||
message_id = m->forward_info->origin.message_id_;
|
dialog_id = origin_message_full_id.get_dialog_id();
|
||||||
|
message_id = origin_message_full_id.get_message_id();
|
||||||
|
CHECK(dialog_id.get_type() == DialogType::Channel);
|
||||||
for_group = false;
|
for_group = false;
|
||||||
in_message_thread = false;
|
in_message_thread = false;
|
||||||
auto channel_message = get_message({dialog_id, message_id});
|
auto channel_message = get_message(origin_message_full_id);
|
||||||
if (channel_message != nullptr && channel_message->media_album_id == 0) {
|
if (channel_message != nullptr && channel_message->media_album_id == 0) {
|
||||||
for_group = true; // default is true
|
for_group = true; // default is true
|
||||||
}
|
}
|
||||||
@ -38875,20 +38878,26 @@ void MessagesManager::update_top_dialogs(DialogId dialog_id, const Message *m) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::update_forward_count(DialogId dialog_id, const Message *m) {
|
void MessagesManager::update_forward_count(DialogId dialog_id, const Message *m) {
|
||||||
if (!td_->auth_manager_->is_bot() && m->forward_info != nullptr &&
|
if (td_->auth_manager_->is_bot() || m->forward_info == nullptr) {
|
||||||
m->forward_info->origin.sender_dialog_id_.is_valid() && m->forward_info->origin.message_id_.is_valid() &&
|
return;
|
||||||
(!is_discussion_message(dialog_id, m) ||
|
|
||||||
m->forward_info->origin.sender_dialog_id_ != m->forward_info->from_dialog_id ||
|
|
||||||
m->forward_info->origin.message_id_ != m->forward_info->from_message_id)) {
|
|
||||||
update_forward_count(m->forward_info->origin.sender_dialog_id_, m->forward_info->origin.message_id_, m->date);
|
|
||||||
}
|
}
|
||||||
|
auto origin_message_full_id = m->forward_info->origin.get_message_full_id();
|
||||||
|
if (!origin_message_full_id.get_message_id().is_valid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (is_discussion_message(dialog_id, m) &&
|
||||||
|
origin_message_full_id == MessageFullId(m->forward_info->from_dialog_id, m->forward_info->from_message_id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
update_forward_count(origin_message_full_id, m->date);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::update_forward_count(DialogId dialog_id, MessageId message_id, int32 update_date) {
|
void MessagesManager::update_forward_count(MessageFullId message_full_id, int32 update_date) {
|
||||||
CHECK(!td_->auth_manager_->is_bot());
|
CHECK(!td_->auth_manager_->is_bot());
|
||||||
|
auto dialog_id = message_full_id.get_dialog_id();
|
||||||
Dialog *d = get_dialog(dialog_id);
|
Dialog *d = get_dialog(dialog_id);
|
||||||
CHECK(d != nullptr);
|
CHECK(d != nullptr);
|
||||||
Message *m = get_message_force(d, message_id, "update_forward_count");
|
Message *m = get_message_force(d, message_full_id.get_message_id(), "update_forward_count");
|
||||||
if (m != nullptr && !m->message_id.is_scheduled() && m->message_id.is_server() && m->view_count > 0 &&
|
if (m != nullptr && !m->message_id.is_scheduled() && m->message_id.is_server() && m->view_count > 0 &&
|
||||||
m->interaction_info_update_date < update_date) {
|
m->interaction_info_update_date < update_date) {
|
||||||
if (m->forward_count == 0) {
|
if (m->forward_count == 0) {
|
||||||
|
@ -3140,7 +3140,7 @@ class MessagesManager final : public Actor {
|
|||||||
|
|
||||||
void update_forward_count(DialogId dialog_id, const Message *m);
|
void update_forward_count(DialogId dialog_id, const Message *m);
|
||||||
|
|
||||||
void update_forward_count(DialogId dialog_id, MessageId message_id, int32 update_date);
|
void update_forward_count(MessageFullId message_full_id, int32 update_date);
|
||||||
|
|
||||||
void update_has_outgoing_messages(DialogId dialog_id, const Message *m);
|
void update_has_outgoing_messages(DialogId dialog_id, const Message *m);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user