2020-10-01 18:28:10 +02:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2020-10-01 18:28:10 +02:00
|
|
|
//
|
|
|
|
// 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/DialogAction.h"
|
|
|
|
|
2021-09-15 16:11:44 +02:00
|
|
|
#include "td/telegram/misc.h"
|
2021-09-17 14:51:42 +02:00
|
|
|
#include "td/telegram/ServerMessageId.h"
|
2023-07-01 18:23:45 +02:00
|
|
|
#include "td/telegram/telegram_api.h"
|
2021-09-15 16:11:44 +02:00
|
|
|
|
2021-09-21 05:32:34 +02:00
|
|
|
#include "td/utils/emoji.h"
|
2021-01-21 21:19:40 +01:00
|
|
|
#include "td/utils/misc.h"
|
2021-09-18 23:47:05 +02:00
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
#include "td/utils/SliceBuilder.h"
|
2021-09-17 14:51:42 +02:00
|
|
|
#include "td/utils/utf8.h"
|
2021-01-21 21:19:40 +01:00
|
|
|
|
2020-10-01 18:28:10 +02:00
|
|
|
namespace td {
|
|
|
|
|
2021-09-15 16:11:44 +02:00
|
|
|
bool DialogAction::is_valid_emoji(string &emoji) {
|
|
|
|
if (!clean_input_string(emoji)) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-09-23 16:16:59 +02:00
|
|
|
return is_emoji(emoji);
|
2021-09-15 16:11:44 +02:00
|
|
|
}
|
|
|
|
|
2020-10-01 18:28:10 +02:00
|
|
|
void DialogAction::init(Type type) {
|
|
|
|
type_ = type;
|
|
|
|
progress_ = 0;
|
2021-09-15 16:11:44 +02:00
|
|
|
emoji_.clear();
|
2020-10-01 18:28:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogAction::init(Type type, int32 progress) {
|
|
|
|
type_ = type;
|
2021-01-21 21:19:40 +01:00
|
|
|
progress_ = clamp(progress, 0, 100);
|
2021-09-15 16:11:44 +02:00
|
|
|
emoji_.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogAction::init(Type type, string emoji) {
|
|
|
|
if (is_valid_emoji(emoji)) {
|
|
|
|
type_ = type;
|
|
|
|
progress_ = 0;
|
|
|
|
emoji_ = std::move(emoji);
|
|
|
|
} else {
|
|
|
|
init(Type::Cancel);
|
|
|
|
}
|
2020-10-01 18:28:10 +02:00
|
|
|
}
|
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
void DialogAction::init(Type type, int32 message_id, string emoji, const string &data) {
|
2021-09-17 14:51:42 +02:00
|
|
|
if (ServerMessageId(message_id).is_valid() && is_valid_emoji(emoji) && check_utf8(data)) {
|
|
|
|
type_ = type;
|
|
|
|
progress_ = message_id;
|
|
|
|
emoji_ = PSTRING() << emoji << '\xFF' << data;
|
|
|
|
} else {
|
|
|
|
init(Type::Cancel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-01 18:28:10 +02:00
|
|
|
DialogAction::DialogAction(Type type, int32 progress) {
|
|
|
|
init(type, progress);
|
|
|
|
}
|
|
|
|
|
2021-09-28 16:31:00 +02:00
|
|
|
DialogAction::DialogAction(td_api::object_ptr<td_api::ChatAction> &&action) {
|
2020-10-01 18:28:10 +02:00
|
|
|
if (action == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (action->get_id()) {
|
|
|
|
case td_api::chatActionCancel::ID:
|
|
|
|
init(Type::Cancel);
|
|
|
|
break;
|
|
|
|
case td_api::chatActionTyping::ID:
|
|
|
|
init(Type::Typing);
|
|
|
|
break;
|
|
|
|
case td_api::chatActionRecordingVideo::ID:
|
|
|
|
init(Type::RecordingVideo);
|
|
|
|
break;
|
|
|
|
case td_api::chatActionUploadingVideo::ID: {
|
|
|
|
auto uploading_action = move_tl_object_as<td_api::chatActionUploadingVideo>(action);
|
|
|
|
init(Type::UploadingVideo, uploading_action->progress_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::chatActionRecordingVoiceNote::ID:
|
|
|
|
init(Type::RecordingVoiceNote);
|
|
|
|
break;
|
|
|
|
case td_api::chatActionUploadingVoiceNote::ID: {
|
|
|
|
auto uploading_action = move_tl_object_as<td_api::chatActionUploadingVoiceNote>(action);
|
|
|
|
init(Type::UploadingVoiceNote, uploading_action->progress_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::chatActionUploadingPhoto::ID: {
|
|
|
|
auto uploading_action = move_tl_object_as<td_api::chatActionUploadingPhoto>(action);
|
|
|
|
init(Type::UploadingPhoto, uploading_action->progress_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::chatActionUploadingDocument::ID: {
|
|
|
|
auto uploading_action = move_tl_object_as<td_api::chatActionUploadingDocument>(action);
|
|
|
|
init(Type::UploadingDocument, uploading_action->progress_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::chatActionChoosingLocation::ID:
|
|
|
|
init(Type::ChoosingLocation);
|
|
|
|
break;
|
|
|
|
case td_api::chatActionChoosingContact::ID:
|
|
|
|
init(Type::ChoosingContact);
|
|
|
|
break;
|
|
|
|
case td_api::chatActionStartPlayingGame::ID:
|
|
|
|
init(Type::StartPlayingGame);
|
|
|
|
break;
|
|
|
|
case td_api::chatActionRecordingVideoNote::ID:
|
|
|
|
init(Type::RecordingVideoNote);
|
|
|
|
break;
|
|
|
|
case td_api::chatActionUploadingVideoNote::ID: {
|
|
|
|
auto uploading_action = move_tl_object_as<td_api::chatActionUploadingVideoNote>(action);
|
|
|
|
init(Type::UploadingVideoNote, uploading_action->progress_);
|
|
|
|
break;
|
|
|
|
}
|
2021-08-19 21:43:38 +02:00
|
|
|
case td_api::chatActionChoosingSticker::ID:
|
|
|
|
init(Type::ChoosingSticker);
|
|
|
|
break;
|
2021-09-19 20:40:07 +02:00
|
|
|
case td_api::chatActionWatchingAnimations::ID: {
|
|
|
|
auto watching_animations_action = move_tl_object_as<td_api::chatActionWatchingAnimations>(action);
|
|
|
|
init(Type::WatchingAnimations, std::move(watching_animations_action->emoji_));
|
2021-09-15 16:11:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-10-01 18:28:10 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 16:31:00 +02:00
|
|
|
DialogAction::DialogAction(telegram_api::object_ptr<telegram_api::SendMessageAction> &&action) {
|
2020-10-01 18:28:10 +02:00
|
|
|
switch (action->get_id()) {
|
|
|
|
case telegram_api::sendMessageCancelAction::ID:
|
|
|
|
init(Type::Cancel);
|
|
|
|
break;
|
|
|
|
case telegram_api::sendMessageTypingAction::ID:
|
|
|
|
init(Type::Typing);
|
|
|
|
break;
|
|
|
|
case telegram_api::sendMessageRecordVideoAction::ID:
|
|
|
|
init(Type::RecordingVideo);
|
|
|
|
break;
|
|
|
|
case telegram_api::sendMessageUploadVideoAction::ID: {
|
|
|
|
auto upload_video_action = move_tl_object_as<telegram_api::sendMessageUploadVideoAction>(action);
|
|
|
|
init(Type::UploadingVideo, upload_video_action->progress_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::sendMessageRecordAudioAction::ID:
|
|
|
|
init(Type::RecordingVoiceNote);
|
|
|
|
break;
|
|
|
|
case telegram_api::sendMessageUploadAudioAction::ID: {
|
|
|
|
auto upload_audio_action = move_tl_object_as<telegram_api::sendMessageUploadAudioAction>(action);
|
|
|
|
init(Type::UploadingVoiceNote, upload_audio_action->progress_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::sendMessageUploadPhotoAction::ID: {
|
|
|
|
auto upload_photo_action = move_tl_object_as<telegram_api::sendMessageUploadPhotoAction>(action);
|
|
|
|
init(Type::UploadingPhoto, upload_photo_action->progress_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::sendMessageUploadDocumentAction::ID: {
|
|
|
|
auto upload_document_action = move_tl_object_as<telegram_api::sendMessageUploadDocumentAction>(action);
|
|
|
|
init(Type::UploadingDocument, upload_document_action->progress_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::sendMessageGeoLocationAction::ID:
|
|
|
|
init(Type::ChoosingLocation);
|
|
|
|
break;
|
|
|
|
case telegram_api::sendMessageChooseContactAction::ID:
|
|
|
|
init(Type::ChoosingContact);
|
|
|
|
break;
|
|
|
|
case telegram_api::sendMessageGamePlayAction::ID:
|
|
|
|
init(Type::StartPlayingGame);
|
|
|
|
break;
|
|
|
|
case telegram_api::sendMessageRecordRoundAction::ID:
|
|
|
|
init(Type::RecordingVideoNote);
|
|
|
|
break;
|
|
|
|
case telegram_api::sendMessageUploadRoundAction::ID: {
|
|
|
|
auto upload_round_action = move_tl_object_as<telegram_api::sendMessageUploadRoundAction>(action);
|
|
|
|
init(Type::UploadingVideoNote, upload_round_action->progress_);
|
|
|
|
break;
|
|
|
|
}
|
2020-11-23 17:50:03 +01:00
|
|
|
case telegram_api::speakingInGroupCallAction::ID:
|
2020-12-04 15:06:37 +01:00
|
|
|
init(Type::SpeakingInVoiceChat);
|
2020-11-23 17:50:03 +01:00
|
|
|
break;
|
2021-01-20 23:50:21 +01:00
|
|
|
case telegram_api::sendMessageHistoryImportAction::ID: {
|
|
|
|
auto history_import_action = move_tl_object_as<telegram_api::sendMessageHistoryImportAction>(action);
|
|
|
|
init(Type::ImportingMessages, history_import_action->progress_);
|
|
|
|
break;
|
|
|
|
}
|
2021-08-19 21:43:38 +02:00
|
|
|
case telegram_api::sendMessageChooseStickerAction::ID:
|
|
|
|
init(Type::ChoosingSticker);
|
|
|
|
break;
|
2021-09-15 16:11:44 +02:00
|
|
|
case telegram_api::sendMessageEmojiInteractionSeen::ID: {
|
|
|
|
auto emoji_interaction_seen_action = move_tl_object_as<telegram_api::sendMessageEmojiInteractionSeen>(action);
|
2021-09-19 20:40:07 +02:00
|
|
|
init(Type::WatchingAnimations, std::move(emoji_interaction_seen_action->emoticon_));
|
2021-09-15 16:11:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2021-09-17 14:51:42 +02:00
|
|
|
case telegram_api::sendMessageEmojiInteraction::ID: {
|
|
|
|
auto emoji_interaction_action = move_tl_object_as<telegram_api::sendMessageEmojiInteraction>(action);
|
|
|
|
init(Type::ClickingAnimatedEmoji, emoji_interaction_action->msg_id_,
|
2021-10-19 17:11:16 +02:00
|
|
|
std::move(emoji_interaction_action->emoticon_), emoji_interaction_action->interaction_->data_);
|
2021-09-17 14:51:42 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-10-01 18:28:10 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::SendMessageAction> DialogAction::get_input_send_message_action() const {
|
|
|
|
switch (type_) {
|
|
|
|
case Type::Cancel:
|
|
|
|
return make_tl_object<telegram_api::sendMessageCancelAction>();
|
|
|
|
case Type::Typing:
|
|
|
|
return make_tl_object<telegram_api::sendMessageTypingAction>();
|
|
|
|
case Type::RecordingVideo:
|
|
|
|
return make_tl_object<telegram_api::sendMessageRecordVideoAction>();
|
|
|
|
case Type::UploadingVideo:
|
|
|
|
return make_tl_object<telegram_api::sendMessageUploadVideoAction>(progress_);
|
|
|
|
case Type::RecordingVoiceNote:
|
|
|
|
return make_tl_object<telegram_api::sendMessageRecordAudioAction>();
|
|
|
|
case Type::UploadingVoiceNote:
|
|
|
|
return make_tl_object<telegram_api::sendMessageUploadAudioAction>(progress_);
|
|
|
|
case Type::UploadingPhoto:
|
|
|
|
return make_tl_object<telegram_api::sendMessageUploadPhotoAction>(progress_);
|
|
|
|
case Type::UploadingDocument:
|
|
|
|
return make_tl_object<telegram_api::sendMessageUploadDocumentAction>(progress_);
|
|
|
|
case Type::ChoosingLocation:
|
|
|
|
return make_tl_object<telegram_api::sendMessageGeoLocationAction>();
|
|
|
|
case Type::ChoosingContact:
|
|
|
|
return make_tl_object<telegram_api::sendMessageChooseContactAction>();
|
2020-11-23 17:18:56 +01:00
|
|
|
case Type::StartPlayingGame:
|
|
|
|
return make_tl_object<telegram_api::sendMessageGamePlayAction>();
|
2020-10-01 18:28:10 +02:00
|
|
|
case Type::RecordingVideoNote:
|
|
|
|
return make_tl_object<telegram_api::sendMessageRecordRoundAction>();
|
|
|
|
case Type::UploadingVideoNote:
|
|
|
|
return make_tl_object<telegram_api::sendMessageUploadRoundAction>(progress_);
|
2020-12-04 15:06:37 +01:00
|
|
|
case Type::SpeakingInVoiceChat:
|
2020-11-23 17:50:03 +01:00
|
|
|
return make_tl_object<telegram_api::speakingInGroupCallAction>();
|
2021-01-20 23:50:21 +01:00
|
|
|
case Type::ImportingMessages:
|
|
|
|
return make_tl_object<telegram_api::sendMessageHistoryImportAction>(progress_);
|
2021-08-19 21:43:38 +02:00
|
|
|
case Type::ChoosingSticker:
|
|
|
|
return make_tl_object<telegram_api::sendMessageChooseStickerAction>();
|
2021-09-19 20:40:07 +02:00
|
|
|
case Type::WatchingAnimations:
|
2021-09-15 16:11:44 +02:00
|
|
|
return make_tl_object<telegram_api::sendMessageEmojiInteractionSeen>(emoji_);
|
2021-09-17 15:16:34 +02:00
|
|
|
case Type::ClickingAnimatedEmoji:
|
2020-10-01 18:28:10 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tl_object_ptr<secret_api::SendMessageAction> DialogAction::get_secret_input_send_message_action() const {
|
|
|
|
switch (type_) {
|
|
|
|
case Type::Cancel:
|
|
|
|
return make_tl_object<secret_api::sendMessageCancelAction>();
|
|
|
|
case Type::Typing:
|
|
|
|
return make_tl_object<secret_api::sendMessageTypingAction>();
|
|
|
|
case Type::RecordingVideo:
|
|
|
|
return make_tl_object<secret_api::sendMessageRecordVideoAction>();
|
|
|
|
case Type::UploadingVideo:
|
|
|
|
return make_tl_object<secret_api::sendMessageUploadVideoAction>();
|
|
|
|
case Type::RecordingVoiceNote:
|
|
|
|
return make_tl_object<secret_api::sendMessageRecordAudioAction>();
|
|
|
|
case Type::UploadingVoiceNote:
|
|
|
|
return make_tl_object<secret_api::sendMessageUploadAudioAction>();
|
|
|
|
case Type::UploadingPhoto:
|
|
|
|
return make_tl_object<secret_api::sendMessageUploadPhotoAction>();
|
|
|
|
case Type::UploadingDocument:
|
|
|
|
return make_tl_object<secret_api::sendMessageUploadDocumentAction>();
|
|
|
|
case Type::ChoosingLocation:
|
|
|
|
return make_tl_object<secret_api::sendMessageGeoLocationAction>();
|
|
|
|
case Type::ChoosingContact:
|
|
|
|
return make_tl_object<secret_api::sendMessageChooseContactAction>();
|
2020-11-23 17:18:56 +01:00
|
|
|
case Type::StartPlayingGame:
|
|
|
|
return make_tl_object<secret_api::sendMessageTypingAction>();
|
2020-10-01 18:28:10 +02:00
|
|
|
case Type::RecordingVideoNote:
|
|
|
|
return make_tl_object<secret_api::sendMessageRecordRoundAction>();
|
|
|
|
case Type::UploadingVideoNote:
|
|
|
|
return make_tl_object<secret_api::sendMessageUploadRoundAction>();
|
2020-12-04 15:06:37 +01:00
|
|
|
case Type::SpeakingInVoiceChat:
|
2020-11-23 17:50:03 +01:00
|
|
|
return make_tl_object<secret_api::sendMessageTypingAction>();
|
2021-01-20 23:50:21 +01:00
|
|
|
case Type::ImportingMessages:
|
|
|
|
return make_tl_object<secret_api::sendMessageTypingAction>();
|
2021-08-19 21:43:38 +02:00
|
|
|
case Type::ChoosingSticker:
|
|
|
|
return make_tl_object<secret_api::sendMessageTypingAction>();
|
2021-09-19 20:40:07 +02:00
|
|
|
case Type::WatchingAnimations:
|
2021-09-15 16:11:44 +02:00
|
|
|
return make_tl_object<secret_api::sendMessageTypingAction>();
|
2021-09-17 14:51:42 +02:00
|
|
|
case Type::ClickingAnimatedEmoji:
|
2020-10-01 18:28:10 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tl_object_ptr<td_api::ChatAction> DialogAction::get_chat_action_object() const {
|
|
|
|
switch (type_) {
|
|
|
|
case Type::Cancel:
|
|
|
|
return td_api::make_object<td_api::chatActionCancel>();
|
|
|
|
case Type::Typing:
|
|
|
|
return td_api::make_object<td_api::chatActionTyping>();
|
|
|
|
case Type::RecordingVideo:
|
|
|
|
return td_api::make_object<td_api::chatActionRecordingVideo>();
|
|
|
|
case Type::UploadingVideo:
|
|
|
|
return td_api::make_object<td_api::chatActionUploadingVideo>(progress_);
|
|
|
|
case Type::RecordingVoiceNote:
|
|
|
|
return td_api::make_object<td_api::chatActionRecordingVoiceNote>();
|
|
|
|
case Type::UploadingVoiceNote:
|
|
|
|
return td_api::make_object<td_api::chatActionUploadingVoiceNote>(progress_);
|
|
|
|
case Type::UploadingPhoto:
|
|
|
|
return td_api::make_object<td_api::chatActionUploadingPhoto>(progress_);
|
|
|
|
case Type::UploadingDocument:
|
|
|
|
return td_api::make_object<td_api::chatActionUploadingDocument>(progress_);
|
|
|
|
case Type::ChoosingLocation:
|
|
|
|
return td_api::make_object<td_api::chatActionChoosingLocation>();
|
|
|
|
case Type::ChoosingContact:
|
|
|
|
return td_api::make_object<td_api::chatActionChoosingContact>();
|
|
|
|
case Type::StartPlayingGame:
|
|
|
|
return td_api::make_object<td_api::chatActionStartPlayingGame>();
|
|
|
|
case Type::RecordingVideoNote:
|
|
|
|
return td_api::make_object<td_api::chatActionRecordingVideoNote>();
|
|
|
|
case Type::UploadingVideoNote:
|
|
|
|
return td_api::make_object<td_api::chatActionUploadingVideoNote>(progress_);
|
2021-08-19 21:43:38 +02:00
|
|
|
case Type::ChoosingSticker:
|
|
|
|
return td_api::make_object<td_api::chatActionChoosingSticker>();
|
2021-09-19 20:40:07 +02:00
|
|
|
case Type::WatchingAnimations:
|
|
|
|
return td_api::make_object<td_api::chatActionWatchingAnimations>(emoji_);
|
2021-01-20 23:50:21 +01:00
|
|
|
case Type::ImportingMessages:
|
2020-12-04 15:06:37 +01:00
|
|
|
case Type::SpeakingInVoiceChat:
|
2021-09-17 14:51:42 +02:00
|
|
|
case Type::ClickingAnimatedEmoji:
|
2020-10-01 18:28:10 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return td_api::make_object<td_api::chatActionCancel>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-31 20:51:48 +02:00
|
|
|
bool DialogAction::is_canceled_by_message_of_type(MessageContentType message_content_type) const {
|
2020-10-01 18:28:10 +02:00
|
|
|
if (message_content_type == MessageContentType::None) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type_ == Type::Typing) {
|
|
|
|
return message_content_type == MessageContentType::Text || message_content_type == MessageContentType::Game ||
|
|
|
|
can_have_message_content_caption(message_content_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (message_content_type) {
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
case MessageContentType::Audio:
|
|
|
|
case MessageContentType::Document:
|
|
|
|
return type_ == Type::UploadingDocument;
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
case MessageContentType::Photo:
|
|
|
|
return type_ == Type::UploadingPhoto;
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
case MessageContentType::Video:
|
|
|
|
return type_ == Type::RecordingVideo || type_ == Type::UploadingVideo;
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
return type_ == Type::RecordingVideoNote || type_ == Type::UploadingVideoNote;
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
return type_ == Type::RecordingVoiceNote || type_ == Type::UploadingVoiceNote;
|
|
|
|
case MessageContentType::Contact:
|
|
|
|
return type_ == Type::ChoosingContact;
|
|
|
|
case MessageContentType::LiveLocation:
|
|
|
|
case MessageContentType::Location:
|
|
|
|
case MessageContentType::Venue:
|
|
|
|
return type_ == Type::ChoosingLocation;
|
2021-08-19 21:43:38 +02:00
|
|
|
case MessageContentType::Sticker:
|
|
|
|
return type_ == Type::ChoosingSticker;
|
2020-10-01 18:28:10 +02:00
|
|
|
case MessageContentType::Game:
|
|
|
|
case MessageContentType::Invoice:
|
|
|
|
case MessageContentType::Text:
|
|
|
|
case MessageContentType::Unsupported:
|
|
|
|
case MessageContentType::ChatCreate:
|
|
|
|
case MessageContentType::ChatChangeTitle:
|
|
|
|
case MessageContentType::ChatChangePhoto:
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
case MessageContentType::ChatAddUsers:
|
|
|
|
case MessageContentType::ChatJoinedByLink:
|
|
|
|
case MessageContentType::ChatDeleteUser:
|
|
|
|
case MessageContentType::ChatMigrateTo:
|
|
|
|
case MessageContentType::ChannelCreate:
|
|
|
|
case MessageContentType::ChannelMigrateFrom:
|
|
|
|
case MessageContentType::PinMessage:
|
|
|
|
case MessageContentType::GameScore:
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
case MessageContentType::ChatSetTtl:
|
|
|
|
case MessageContentType::Call:
|
|
|
|
case MessageContentType::PaymentSuccessful:
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
case MessageContentType::CustomServiceAction:
|
|
|
|
case MessageContentType::WebsiteConnected:
|
|
|
|
case MessageContentType::PassportDataSent:
|
|
|
|
case MessageContentType::PassportDataReceived:
|
|
|
|
case MessageContentType::Poll:
|
|
|
|
case MessageContentType::Dice:
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered:
|
2020-11-24 12:33:16 +01:00
|
|
|
case MessageContentType::GroupCall:
|
|
|
|
case MessageContentType::InviteToGroupCall:
|
2021-08-27 18:29:58 +02:00
|
|
|
case MessageContentType::ChatSetTheme:
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent:
|
|
|
|
case MessageContentType::WebViewDataReceived:
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate:
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit:
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog:
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed:
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground:
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story:
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode:
|
2023-09-29 23:32:39 +02:00
|
|
|
case MessageContentType::Giveaway:
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
2023-11-09 18:28:27 +01:00
|
|
|
case MessageContentType::GiveawayResults:
|
2023-12-18 19:03:11 +01:00
|
|
|
case MessageContentType::GiveawayWinners:
|
2020-10-01 18:28:10 +02:00
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogAction DialogAction::get_uploading_action(MessageContentType message_content_type, int32 progress) {
|
|
|
|
switch (message_content_type) {
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
case MessageContentType::Audio:
|
|
|
|
case MessageContentType::Document:
|
|
|
|
return DialogAction(Type::UploadingDocument, progress);
|
|
|
|
case MessageContentType::Photo:
|
|
|
|
return DialogAction(Type::UploadingPhoto, progress);
|
|
|
|
case MessageContentType::Video:
|
|
|
|
return DialogAction(Type::UploadingVideo, progress);
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
return DialogAction(Type::UploadingVideoNote, progress);
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
return DialogAction(Type::UploadingVoiceNote, progress);
|
|
|
|
default:
|
|
|
|
return DialogAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-01 18:30:07 +02:00
|
|
|
DialogAction DialogAction::get_typing_action() {
|
|
|
|
return DialogAction(Type::Typing, 0);
|
|
|
|
}
|
|
|
|
|
2020-12-04 15:06:37 +01:00
|
|
|
DialogAction DialogAction::get_speaking_action() {
|
|
|
|
return DialogAction(Type::SpeakingInVoiceChat, 0);
|
|
|
|
}
|
|
|
|
|
2021-01-26 01:13:09 +01:00
|
|
|
int32 DialogAction::get_importing_messages_action_progress() const {
|
|
|
|
if (type_ != Type::ImportingMessages) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return progress_;
|
|
|
|
}
|
|
|
|
|
2021-09-19 20:40:07 +02:00
|
|
|
string DialogAction::get_watching_animations_emoji() const {
|
|
|
|
if (type_ == Type::WatchingAnimations) {
|
2021-09-19 00:52:56 +02:00
|
|
|
return emoji_;
|
|
|
|
}
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
2021-09-17 14:51:42 +02:00
|
|
|
DialogAction::ClickingAnimateEmojiInfo DialogAction::get_clicking_animated_emoji_action_info() const {
|
|
|
|
ClickingAnimateEmojiInfo result;
|
|
|
|
if (type_ == Type::ClickingAnimatedEmoji) {
|
|
|
|
auto pos = emoji_.find('\xFF');
|
|
|
|
CHECK(pos < emoji_.size());
|
|
|
|
result.message_id = progress_;
|
|
|
|
result.emoji = emoji_.substr(0, pos);
|
|
|
|
result.data = emoji_.substr(pos + 1);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-10-01 18:28:10 +02:00
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const DialogAction &action) {
|
|
|
|
string_builder << "ChatAction";
|
|
|
|
const char *type = [action_type = action.type_] {
|
|
|
|
switch (action_type) {
|
|
|
|
case DialogAction::Type::Cancel:
|
|
|
|
return "Cancel";
|
|
|
|
case DialogAction::Type::Typing:
|
|
|
|
return "Typing";
|
|
|
|
case DialogAction::Type::RecordingVideo:
|
|
|
|
return "RecordingVideo";
|
|
|
|
case DialogAction::Type::UploadingVideo:
|
|
|
|
return "UploadingVideo";
|
|
|
|
case DialogAction::Type::RecordingVoiceNote:
|
|
|
|
return "RecordingVoiceNote";
|
|
|
|
case DialogAction::Type::UploadingVoiceNote:
|
|
|
|
return "UploadingVoiceNote";
|
|
|
|
case DialogAction::Type::UploadingPhoto:
|
|
|
|
return "UploadingPhoto";
|
|
|
|
case DialogAction::Type::UploadingDocument:
|
|
|
|
return "UploadingDocument";
|
|
|
|
case DialogAction::Type::ChoosingLocation:
|
|
|
|
return "ChoosingLocation";
|
|
|
|
case DialogAction::Type::ChoosingContact:
|
|
|
|
return "ChoosingContact";
|
|
|
|
case DialogAction::Type::StartPlayingGame:
|
|
|
|
return "StartPlayingGame";
|
|
|
|
case DialogAction::Type::RecordingVideoNote:
|
|
|
|
return "RecordingVideoNote";
|
|
|
|
case DialogAction::Type::UploadingVideoNote:
|
|
|
|
return "UploadingVideoNote";
|
2020-12-04 15:06:37 +01:00
|
|
|
case DialogAction::Type::SpeakingInVoiceChat:
|
|
|
|
return "SpeakingInVoiceChat";
|
2021-01-20 23:50:21 +01:00
|
|
|
case DialogAction::Type::ImportingMessages:
|
|
|
|
return "ImportingMessages";
|
2021-08-19 21:43:38 +02:00
|
|
|
case DialogAction::Type::ChoosingSticker:
|
|
|
|
return "ChoosingSticker";
|
2021-09-19 20:40:07 +02:00
|
|
|
case DialogAction::Type::WatchingAnimations:
|
|
|
|
return "WatchingAnimations";
|
2021-09-17 14:51:42 +02:00
|
|
|
case DialogAction::Type::ClickingAnimatedEmoji:
|
|
|
|
return "ClickingAnimatedEmoji";
|
2020-10-01 18:28:10 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return "Cancel";
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
string_builder << type << "Action";
|
2021-09-17 14:51:42 +02:00
|
|
|
if (action.type_ == DialogAction::Type::ClickingAnimatedEmoji) {
|
|
|
|
auto pos = action.emoji_.find('\xFF');
|
|
|
|
CHECK(pos < action.emoji_.size());
|
|
|
|
string_builder << '(' << action.progress_ << ")(" << Slice(action.emoji_).substr(0, pos) << ")("
|
|
|
|
<< Slice(action.emoji_).substr(pos + 1) << ')';
|
|
|
|
} else {
|
|
|
|
if (action.progress_ != 0) {
|
|
|
|
string_builder << '(' << action.progress_ << "%)";
|
|
|
|
}
|
|
|
|
if (!action.emoji_.empty()) {
|
|
|
|
string_builder << '(' << action.emoji_ << ')';
|
|
|
|
}
|
2021-09-15 16:11:44 +02:00
|
|
|
}
|
2020-10-01 18:28:10 +02:00
|
|
|
return string_builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|