Add td_api::messageViewers.
This commit is contained in:
parent
b27eeda8bd
commit
439dd7c2ca
@ -395,6 +395,7 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/MessageSource.cpp
|
td/telegram/MessageSource.cpp
|
||||||
td/telegram/MessageThreadDb.cpp
|
td/telegram/MessageThreadDb.cpp
|
||||||
td/telegram/MessageTtl.cpp
|
td/telegram/MessageTtl.cpp
|
||||||
|
td/telegram/MessageViewer.cpp
|
||||||
td/telegram/misc.cpp
|
td/telegram/misc.cpp
|
||||||
td/telegram/net/AuthDataShared.cpp
|
td/telegram/net/AuthDataShared.cpp
|
||||||
td/telegram/net/ConnectionCreator.cpp
|
td/telegram/net/ConnectionCreator.cpp
|
||||||
@ -651,6 +652,7 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/MessageThreadDb.h
|
td/telegram/MessageThreadDb.h
|
||||||
td/telegram/MessageThreadInfo.h
|
td/telegram/MessageThreadInfo.h
|
||||||
td/telegram/MessageTtl.h
|
td/telegram/MessageTtl.h
|
||||||
|
td/telegram/MessageViewer.h
|
||||||
td/telegram/MinChannel.h
|
td/telegram/MinChannel.h
|
||||||
td/telegram/misc.h
|
td/telegram/misc.h
|
||||||
td/telegram/net/AuthDataShared.h
|
td/telegram/net/AuthDataShared.h
|
||||||
|
@ -1001,6 +1001,13 @@ chatMessageSender sender:MessageSender needs_premium:Bool = ChatMessageSender;
|
|||||||
chatMessageSenders senders:vector<chatMessageSender> = ChatMessageSenders;
|
chatMessageSenders senders:vector<chatMessageSender> = ChatMessageSenders;
|
||||||
|
|
||||||
|
|
||||||
|
//@description Represents a viewer of a message @user_id User identifier of the viewer @view_date Point in time (Unix timestamp) when the message was viewed
|
||||||
|
messageViewer user_id:int53 view_date:int32 = MessageViewer;
|
||||||
|
|
||||||
|
//@description Represents a list of message viewers @viewers List of message viewers
|
||||||
|
messageViewers viewers:vector<messageViewer> = MessageViewers;
|
||||||
|
|
||||||
|
|
||||||
//@class MessageForwardOrigin @description Contains information about the origin of a forwarded message
|
//@class MessageForwardOrigin @description Contains information about the origin of a forwarded message
|
||||||
|
|
||||||
//@description The message was originally sent by a known user @sender_user_id Identifier of the user that originally sent the message
|
//@description The message was originally sent by a known user @sender_user_id Identifier of the user that originally sent the message
|
||||||
@ -5880,7 +5887,7 @@ getMessageThread chat_id:int53 message_id:int53 = MessageThreadInfo;
|
|||||||
//@description Returns viewers of a recent outgoing message in a basic group or a supergroup chat. For video notes and voice notes only users, opened content of the message, are returned. The method can be called if message.can_get_viewers == true
|
//@description Returns viewers of a recent outgoing message in a basic group or a supergroup chat. For video notes and voice notes only users, opened content of the message, are returned. The method can be called if message.can_get_viewers == true
|
||||||
//@chat_id Chat identifier
|
//@chat_id Chat identifier
|
||||||
//@message_id Identifier of the message
|
//@message_id Identifier of the message
|
||||||
getMessageViewers chat_id:int53 message_id:int53 = Users;
|
getMessageViewers chat_id:int53 message_id:int53 = MessageViewers;
|
||||||
|
|
||||||
//@description Returns information about a file; this is an offline request @file_id Identifier of the file to get
|
//@description Returns information about a file; this is an offline request @file_id Identifier of the file to get
|
||||||
getFile file_id:int32 = File;
|
getFile file_id:int32 = File;
|
||||||
|
48
td/telegram/MessageViewer.cpp
Normal file
48
td/telegram/MessageViewer.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
//
|
||||||
|
// 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)
|
||||||
|
//
|
||||||
|
#include "td/telegram/MessageViewer.h"
|
||||||
|
|
||||||
|
#include "td/telegram/ContactsManager.h"
|
||||||
|
|
||||||
|
#include "td/utils/algorithm.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
MessageViewer::MessageViewer(telegram_api::object_ptr<telegram_api::readParticipantDate> &&read_date)
|
||||||
|
: user_id_(read_date->user_id_), date_(read_date->date_) {
|
||||||
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::messageViewer> MessageViewer::get_message_viewer_object(
|
||||||
|
ContactsManager *contacts_manager) const {
|
||||||
|
return td_api::make_object<td_api::messageViewer>(
|
||||||
|
contacts_manager->get_user_id_object(user_id_, "get_message_viewer_object"), date_);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder &operator<<(StringBuilder &string_builder, const MessageViewer &viewer) {
|
||||||
|
return string_builder << '[' << viewer.user_id_ << " at " << viewer.date_ << ']';
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageViewers::MessageViewers(vector<telegram_api::object_ptr<telegram_api::readParticipantDate>> &&read_dates)
|
||||||
|
: message_viewers_(
|
||||||
|
transform(std::move(read_dates), [](telegram_api::object_ptr<telegram_api::readParticipantDate> &&read_date) {
|
||||||
|
return MessageViewer(std::move(read_date));
|
||||||
|
})) {
|
||||||
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::messageViewers> MessageViewers::get_message_viewers_object(
|
||||||
|
ContactsManager *contacts_manager) const {
|
||||||
|
return td_api::make_object<td_api::messageViewers>(
|
||||||
|
transform(message_viewers_, [contacts_manager](const MessageViewer &message_viewer) {
|
||||||
|
return message_viewer.get_message_viewer_object(contacts_manager);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder &operator<<(StringBuilder &string_builder, const MessageViewers &viewers) {
|
||||||
|
return string_builder << viewers.message_viewers_;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace td
|
48
td/telegram/MessageViewer.h
Normal file
48
td/telegram/MessageViewer.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
//
|
||||||
|
// 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/td_api.h"
|
||||||
|
#include "td/telegram/telegram_api.h"
|
||||||
|
#include "td/telegram/UserId.h"
|
||||||
|
|
||||||
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/StringBuilder.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
class ContactsManager;
|
||||||
|
|
||||||
|
class MessageViewer {
|
||||||
|
UserId user_id_;
|
||||||
|
int32 date_ = 0;
|
||||||
|
|
||||||
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const MessageViewer &viewer);
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit MessageViewer(telegram_api::object_ptr<telegram_api::readParticipantDate> &&read_date);
|
||||||
|
|
||||||
|
UserId get_user_id() const {
|
||||||
|
return user_id_;
|
||||||
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::messageViewer> get_message_viewer_object(ContactsManager *contacts_manager) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
StringBuilder &operator<<(StringBuilder &string_builder, const MessageViewer &viewer);
|
||||||
|
|
||||||
|
struct MessageViewers {
|
||||||
|
vector<MessageViewer> message_viewers_;
|
||||||
|
|
||||||
|
explicit MessageViewers(vector<telegram_api::object_ptr<telegram_api::readParticipantDate>> &&read_dates);
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::messageViewers> get_message_viewers_object(ContactsManager *contacts_manager) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
StringBuilder &operator<<(StringBuilder &string_builder, const MessageViewers &viewers);
|
||||||
|
|
||||||
|
} // namespace td
|
@ -679,11 +679,11 @@ class UnpinAllMessagesQuery final : public Td::ResultHandler {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class GetMessageReadParticipantsQuery final : public Td::ResultHandler {
|
class GetMessageReadParticipantsQuery final : public Td::ResultHandler {
|
||||||
Promise<vector<UserId>> promise_;
|
Promise<MessageViewers> promise_;
|
||||||
DialogId dialog_id_;
|
DialogId dialog_id_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GetMessageReadParticipantsQuery(Promise<vector<UserId>> &&promise) : promise_(std::move(promise)) {
|
explicit GetMessageReadParticipantsQuery(Promise<MessageViewers> &&promise) : promise_(std::move(promise)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void send(DialogId dialog_id, MessageId message_id) {
|
void send(DialogId dialog_id, MessageId message_id) {
|
||||||
@ -700,11 +700,7 @@ class GetMessageReadParticipantsQuery final : public Td::ResultHandler {
|
|||||||
return on_error(result_ptr.move_as_error());
|
return on_error(result_ptr.move_as_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto user_ids =
|
promise_.set_value(MessageViewers(result_ptr.move_as_ok()));
|
||||||
transform(result_ptr.ok(), [](const telegram_api::object_ptr<telegram_api::readParticipantDate> &user_date) {
|
|
||||||
return user_date->user_id_;
|
|
||||||
});
|
|
||||||
promise_.set_value(UserId::get_user_ids(user_ids));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_error(Status status) final {
|
void on_error(Status status) final {
|
||||||
@ -19009,11 +19005,11 @@ Status MessagesManager::can_get_message_viewers(DialogId dialog_id, const Messag
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::get_message_viewers(FullMessageId full_message_id,
|
void MessagesManager::get_message_viewers(FullMessageId full_message_id,
|
||||||
Promise<td_api::object_ptr<td_api::users>> &&promise) {
|
Promise<td_api::object_ptr<td_api::messageViewers>> &&promise) {
|
||||||
TRY_STATUS_PROMISE(promise, can_get_message_viewers(full_message_id));
|
TRY_STATUS_PROMISE(promise, can_get_message_viewers(full_message_id));
|
||||||
|
|
||||||
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), dialog_id = full_message_id.get_dialog_id(),
|
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), dialog_id = full_message_id.get_dialog_id(),
|
||||||
promise = std::move(promise)](Result<vector<UserId>> result) mutable {
|
promise = std::move(promise)](Result<MessageViewers> result) mutable {
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
return promise.set_error(result.move_as_error());
|
return promise.set_error(result.move_as_error());
|
||||||
}
|
}
|
||||||
@ -19025,11 +19021,12 @@ void MessagesManager::get_message_viewers(FullMessageId full_message_id,
|
|||||||
->send(full_message_id.get_dialog_id(), full_message_id.get_message_id());
|
->send(full_message_id.get_dialog_id(), full_message_id.get_message_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::on_get_message_viewers(DialogId dialog_id, vector<UserId> user_ids, bool is_recursive,
|
void MessagesManager::on_get_message_viewers(DialogId dialog_id, MessageViewers message_viewers, bool is_recursive,
|
||||||
Promise<td_api::object_ptr<td_api::users>> &&promise) {
|
Promise<td_api::object_ptr<td_api::messageViewers>> &&promise) {
|
||||||
if (!is_recursive) {
|
if (!is_recursive) {
|
||||||
bool need_participant_list = false;
|
bool need_participant_list = false;
|
||||||
for (auto user_id : user_ids) {
|
for (auto message_viewer : message_viewers.message_viewers_) {
|
||||||
|
auto user_id = message_viewer.get_user_id();
|
||||||
if (!user_id.is_valid()) {
|
if (!user_id.is_valid()) {
|
||||||
LOG(ERROR) << "Receive invalid " << user_id << " as viewer of a message in " << dialog_id;
|
LOG(ERROR) << "Receive invalid " << user_id << " as viewer of a message in " << dialog_id;
|
||||||
continue;
|
continue;
|
||||||
@ -19039,11 +19036,12 @@ void MessagesManager::on_get_message_viewers(DialogId dialog_id, vector<UserId>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (need_participant_list) {
|
if (need_participant_list) {
|
||||||
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, user_ids = std::move(user_ids),
|
auto query_promise =
|
||||||
promise = std::move(promise)](Unit result) mutable {
|
PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, message_viewers = std::move(message_viewers),
|
||||||
send_closure(actor_id, &MessagesManager::on_get_message_viewers, dialog_id, std::move(user_ids), true,
|
promise = std::move(promise)](Unit result) mutable {
|
||||||
std::move(promise));
|
send_closure(actor_id, &MessagesManager::on_get_message_viewers, dialog_id, std::move(message_viewers),
|
||||||
});
|
true, std::move(promise));
|
||||||
|
});
|
||||||
|
|
||||||
switch (dialog_id.get_type()) {
|
switch (dialog_id.get_type()) {
|
||||||
case DialogType::Chat:
|
case DialogType::Chat:
|
||||||
@ -19060,7 +19058,7 @@ void MessagesManager::on_get_message_viewers(DialogId dialog_id, vector<UserId>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
promise.set_value(td_->contacts_manager_->get_users_object(-1, user_ids));
|
promise.set_value(message_viewers.get_message_viewers_object(td_->contacts_manager_.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::translate_message_text(FullMessageId full_message_id, const string &to_language_code,
|
void MessagesManager::translate_message_text(FullMessageId full_message_id, const string &to_language_code,
|
||||||
@ -22634,8 +22632,9 @@ tl_object_ptr<td_api::messages> MessagesManager::get_dialog_history(DialogId dia
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG(INFO) << "Return " << messages.size() << " messages in result to getChatHistory";
|
LOG(INFO) << "Return " << messages.size() << " messages in result to getChatHistory";
|
||||||
promise.set_value(Unit()); // can return some messages
|
promise.set_value(Unit()); // can return some messages
|
||||||
return get_messages_object(-1, std::move(messages), false); // TODO return real total_count of messages in the dialog
|
return get_messages_object(-1, std::move(messages),
|
||||||
|
false); // TODO return real total_count of messages in the dialog
|
||||||
}
|
}
|
||||||
|
|
||||||
class MessagesManager::ReadHistoryOnServerLogEvent {
|
class MessagesManager::ReadHistoryOnServerLogEvent {
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include "td/telegram/MessageSource.h"
|
#include "td/telegram/MessageSource.h"
|
||||||
#include "td/telegram/MessageThreadInfo.h"
|
#include "td/telegram/MessageThreadInfo.h"
|
||||||
#include "td/telegram/MessageTtl.h"
|
#include "td/telegram/MessageTtl.h"
|
||||||
|
#include "td/telegram/MessageViewer.h"
|
||||||
#include "td/telegram/net/DcId.h"
|
#include "td/telegram/net/DcId.h"
|
||||||
#include "td/telegram/net/NetQuery.h"
|
#include "td/telegram/net/NetQuery.h"
|
||||||
#include "td/telegram/Notification.h"
|
#include "td/telegram/Notification.h"
|
||||||
@ -641,7 +642,8 @@ class MessagesManager final : public Actor {
|
|||||||
DialogId dialog_id, MessageId message_id, DialogId expected_dialog_id,
|
DialogId dialog_id, MessageId message_id, DialogId expected_dialog_id,
|
||||||
MessageId expected_message_id, Promise<MessageThreadInfo> promise);
|
MessageId expected_message_id, Promise<MessageThreadInfo> promise);
|
||||||
|
|
||||||
void get_message_viewers(FullMessageId full_message_id, Promise<td_api::object_ptr<td_api::users>> &&promise);
|
void get_message_viewers(FullMessageId full_message_id,
|
||||||
|
Promise<td_api::object_ptr<td_api::messageViewers>> &&promise);
|
||||||
|
|
||||||
void translate_message_text(FullMessageId full_message_id, const string &to_language_code,
|
void translate_message_text(FullMessageId full_message_id, const string &to_language_code,
|
||||||
Promise<td_api::object_ptr<td_api::formattedText>> &&promise);
|
Promise<td_api::object_ptr<td_api::formattedText>> &&promise);
|
||||||
@ -3062,8 +3064,8 @@ class MessagesManager final : public Actor {
|
|||||||
void on_get_discussion_message(DialogId dialog_id, MessageId message_id, MessageThreadInfo &&message_thread_info,
|
void on_get_discussion_message(DialogId dialog_id, MessageId message_id, MessageThreadInfo &&message_thread_info,
|
||||||
Promise<MessageThreadInfo> &&promise);
|
Promise<MessageThreadInfo> &&promise);
|
||||||
|
|
||||||
void on_get_message_viewers(DialogId dialog_id, vector<UserId> user_ids, bool is_recursive,
|
void on_get_message_viewers(DialogId dialog_id, MessageViewers message_viewers, bool is_recursive,
|
||||||
Promise<td_api::object_ptr<td_api::users>> &&promise);
|
Promise<td_api::object_ptr<td_api::messageViewers>> &&promise);
|
||||||
|
|
||||||
static MessageId get_first_database_message_id_by_index(const Dialog *d, MessageSearchFilter filter);
|
static MessageId get_first_database_message_id_by_index(const Dialog *d, MessageSearchFilter filter);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user