Add messageSourceScreenshot and notify about screenshotted codes.
This commit is contained in:
parent
da813f3ee9
commit
340312e3da
@ -1217,6 +1217,9 @@ messageSourceChatEventLog = MessageSource;
|
||||
//@description The message is from a notification
|
||||
messageSourceNotification = MessageSource;
|
||||
|
||||
//@description The message was screenshotted; the source must be used only if the message content was visible during the screenshot
|
||||
messageSourceScreenshot = MessageSource;
|
||||
|
||||
//@description The message is from some other source
|
||||
messageSourceOther = MessageSource;
|
||||
|
||||
|
@ -582,6 +582,26 @@ class ImportContactTokenQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class InvalidateSignInCodesQuery final : public Td::ResultHandler {
|
||||
public:
|
||||
void send(vector<string> &&codes) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_invalidateSignInCodes(std::move(codes))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_invalidateSignInCodes>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "Receive result for InvalidateSignInCodesQuery: " << result_ptr.ok();
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
LOG(DEBUG) << "Receive error for InvalidateSignInCodesQuery: " << status;
|
||||
}
|
||||
};
|
||||
|
||||
void set_default_message_ttl(Td *td, int32 message_ttl, Promise<Unit> &&promise) {
|
||||
td->create_handler<SetDefaultHistoryTtlQuery>(std::move(promise))->send(message_ttl);
|
||||
}
|
||||
@ -658,4 +678,8 @@ void import_contact_token(Td *td, const string &token, Promise<td_api::object_pt
|
||||
td->create_handler<ImportContactTokenQuery>(std::move(promise))->send(token);
|
||||
}
|
||||
|
||||
void invalidate_authentication_codes(Td *td, vector<string> &&authentication_codes) {
|
||||
td->create_handler<InvalidateSignInCodesQuery>()->send(std::move(authentication_codes));
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -48,4 +48,6 @@ void export_contact_token(Td *td, Promise<td_api::object_ptr<td_api::userLink>>
|
||||
|
||||
void import_contact_token(Td *td, const string &token, Promise<td_api::object_ptr<td_api::user>> &&promise);
|
||||
|
||||
void invalidate_authentication_codes(Td *td, vector<string> &&authentication_codes);
|
||||
|
||||
} // namespace td
|
||||
|
@ -28,6 +28,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, MessageSource source) {
|
||||
return string_builder << "DialogEventLog";
|
||||
case MessageSource::Notification:
|
||||
return string_builder << "Notification";
|
||||
case MessageSource::Screenshot:
|
||||
return string_builder << "Screenshot";
|
||||
case MessageSource::Other:
|
||||
return string_builder << "Other";
|
||||
default:
|
||||
@ -56,6 +58,8 @@ MessageSource get_message_source(const td_api::object_ptr<td_api::MessageSource>
|
||||
return MessageSource::DialogEventLog;
|
||||
case td_api::messageSourceNotification::ID:
|
||||
return MessageSource::Notification;
|
||||
case td_api::messageSourceScreenshot::ID:
|
||||
return MessageSource::Screenshot;
|
||||
case td_api::messageSourceOther::ID:
|
||||
return MessageSource::Other;
|
||||
default:
|
||||
|
@ -23,6 +23,7 @@ enum class MessageSource : int32 {
|
||||
Search,
|
||||
DialogEventLog,
|
||||
Notification,
|
||||
Screenshot,
|
||||
Other
|
||||
};
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
#include "td/telegram/MessagesManager.h"
|
||||
|
||||
#include "td/telegram/Account.h"
|
||||
#include "td/telegram/AuthManager.h"
|
||||
#include "td/telegram/BackgroundInfo.hpp"
|
||||
#include "td/telegram/ChainId.h"
|
||||
@ -6504,6 +6505,37 @@ MessagesManager::Dialog *MessagesManager::get_service_notifications_dialog() {
|
||||
return get_dialog(service_notifications_dialog_id);
|
||||
}
|
||||
|
||||
void MessagesManager::extract_authentication_codes(DialogId dialog_id, const Message *m,
|
||||
vector<string> &authentication_codes) {
|
||||
CHECK(m != nullptr);
|
||||
if (dialog_id != DialogId(ContactsManager::get_service_notifications_user_id()) || !m->message_id.is_valid() ||
|
||||
!m->message_id.is_server() || m->content->get_type() != MessageContentType::Text || m->is_outgoing) {
|
||||
return;
|
||||
}
|
||||
auto *formatted_text = get_message_content_text(m->content.get());
|
||||
CHECK(formatted_text != nullptr);
|
||||
const string &text = formatted_text->text;
|
||||
for (size_t i = 0; i < text.size(); i++) {
|
||||
if (is_digit(text[i])) {
|
||||
string code;
|
||||
do {
|
||||
if (is_digit(text[i])) {
|
||||
code += text[i++];
|
||||
continue;
|
||||
}
|
||||
if (text[i] == '-') {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} while (true);
|
||||
if (5 <= code.size() && code.size() <= 7) {
|
||||
authentication_codes.push_back(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesManager::save_auth_notification_ids() {
|
||||
auto min_date = G()->unix_time() - AUTH_NOTIFICATION_ID_CACHE_TIME;
|
||||
vector<string> stored_ids;
|
||||
@ -19843,6 +19875,9 @@ Status MessagesManager::view_messages(DialogId dialog_id, vector<MessageId> mess
|
||||
source == MessageSource::DialogList || source == MessageSource::Other;
|
||||
bool need_mark_download_as_viewed = is_dialog_history || source == MessageSource::HistoryPreview ||
|
||||
source == MessageSource::Search || source == MessageSource::Other;
|
||||
bool need_invalidate_authentication_code =
|
||||
dialog_id == DialogId(ContactsManager::get_service_notifications_user_id()) &&
|
||||
source == MessageSource::Screenshot;
|
||||
|
||||
// keep only valid message identifiers
|
||||
size_t pos = 0;
|
||||
@ -19968,6 +20003,7 @@ Status MessagesManager::view_messages(DialogId dialog_id, vector<MessageId> mess
|
||||
vector<MessageId> read_reaction_message_ids;
|
||||
vector<MessageId> new_viewed_message_ids;
|
||||
vector<MessageId> viewed_reaction_message_ids;
|
||||
vector<string> authentication_codes;
|
||||
for (auto message_id : message_ids) {
|
||||
auto *m = get_message_force(d, message_id, "view_messages 4");
|
||||
if (m != nullptr) {
|
||||
@ -20027,6 +20063,10 @@ Status MessagesManager::view_messages(DialogId dialog_id, vector<MessageId> mess
|
||||
view_id = ++info->current_view_id;
|
||||
info->recently_viewed_messages[view_id] = message_id;
|
||||
}
|
||||
|
||||
if (need_invalidate_authentication_code) {
|
||||
extract_authentication_codes(dialog_id, m, authentication_codes);
|
||||
}
|
||||
} else if (!message_id.is_yet_unsent() && message_id > max_message_id) {
|
||||
if ((d->notification_info != nullptr && message_id <= d->notification_info->max_notification_message_id_) ||
|
||||
message_id <= d->last_new_message_id || message_id <= max_thread_message_id) {
|
||||
@ -20072,6 +20112,9 @@ Status MessagesManager::view_messages(DialogId dialog_id, vector<MessageId> mess
|
||||
if (td_->is_online() && dialog_viewed_messages_.count(dialog_id) != 0) {
|
||||
update_viewed_messages_timeout_.add_timeout_in(dialog_id.get(), UPDATE_VIEWED_MESSAGES_PERIOD);
|
||||
}
|
||||
if (!authentication_codes.empty()) {
|
||||
invalidate_authentication_codes(td_, std::move(authentication_codes));
|
||||
}
|
||||
|
||||
if (!need_read) {
|
||||
return Status::OK();
|
||||
|
@ -3107,6 +3107,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
Dialog *get_service_notifications_dialog();
|
||||
|
||||
static void extract_authentication_codes(DialogId dialog_id, const Message *m, vector<string> &authentication_codes);
|
||||
|
||||
void save_auth_notification_ids();
|
||||
|
||||
MessageId get_next_message_id(Dialog *d, MessageType type) const;
|
||||
|
@ -5221,7 +5221,7 @@ class CliClient final : public Actor {
|
||||
} else if (op == "rrh") {
|
||||
const string &hashtag = args;
|
||||
send_request(td_api::make_object<td_api::removeRecentHashtag>(hashtag));
|
||||
} else if (op == "view" || op == "viewh" || op == "viewt") {
|
||||
} else if (op == "view" || op == "viewh" || op == "viewt" || op == "views") {
|
||||
ChatId chat_id;
|
||||
string message_ids;
|
||||
get_args(args, chat_id, message_ids);
|
||||
@ -5230,6 +5230,8 @@ class CliClient final : public Actor {
|
||||
source = td_api::make_object<td_api::messageSourceChatHistory>();
|
||||
} else if (op == "viewt") {
|
||||
source = td_api::make_object<td_api::messageSourceMessageThreadHistory>();
|
||||
} else if (op == "views") {
|
||||
source = td_api::make_object<td_api::messageSourceScreenshot>();
|
||||
}
|
||||
send_request(
|
||||
td_api::make_object<td_api::viewMessages>(chat_id, as_message_ids(message_ids), std::move(source), true));
|
||||
|
Loading…
x
Reference in New Issue
Block a user