mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-09-01 17:43:03 +02:00
fix: send image as photo & cleanup
This commit is contained in:
parent
1f00161bf0
commit
41e46e4924
14 changed files with 80 additions and 58 deletions
|
@ -90,6 +90,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ayu/ayu_settings.h"
|
#include "ayu/ayu_settings.h"
|
||||||
#include "ayu/ayu_worker.h"
|
#include "ayu/ayu_worker.h"
|
||||||
#include "ayu/utils/telegram_helpers.h"
|
#include "ayu/utils/telegram_helpers.h"
|
||||||
|
#include "ayu/features/forward/ayu_forward.h"
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -3286,6 +3287,7 @@ void ApiWrap::forwardMessages(
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto ayuIntelligentForwardNeeded = AyuForward::isAyuForwardNeeded(draft.items);
|
const auto ayuIntelligentForwardNeeded = AyuForward::isAyuForwardNeeded(draft.items);
|
||||||
if (ayuIntelligentForwardNeeded) {
|
if (ayuIntelligentForwardNeeded) {
|
||||||
crl::async([=] {
|
crl::async([=] {
|
||||||
|
@ -3782,12 +3784,11 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
|
||||||
: Data::ForumTopic::kGeneralId;
|
: Data::ForumTopic::kGeneralId;
|
||||||
const auto topic = peer->forumTopicFor(topicRootId);
|
const auto topic = peer->forumTopicFor(topicRootId);
|
||||||
|
|
||||||
const bool canTexts = topic
|
const bool canSendTexts = topic
|
||||||
? Data::CanSendTexts(topic)
|
? Data::CanSendTexts(topic)
|
||||||
: Data::CanSendTexts(peer);
|
: Data::CanSendTexts(peer);
|
||||||
|
|
||||||
if (!(canTexts || AyuForward::isForwarding((peer->id)))
|
if (!canSendTexts || AyuForward::isForwarding(peer->id) || Api::SendDice(message)) {
|
||||||
|| Api::SendDice(message)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
local().saveRecentSentHashtags(textWithTags.text);
|
local().saveRecentSentHashtags(textWithTags.text);
|
||||||
|
|
|
@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "mtproto/sender.h"
|
#include "mtproto/sender.h"
|
||||||
#include "data/stickers/data_stickers_set.h"
|
#include "data/stickers/data_stickers_set.h"
|
||||||
#include "data/data_messages.h"
|
#include "data/data_messages.h"
|
||||||
#include "ayu/features/forward/ayu_forward.h"
|
|
||||||
|
|
||||||
class TaskQueue;
|
class TaskQueue;
|
||||||
struct MessageGroupId;
|
struct MessageGroupId;
|
||||||
|
|
|
@ -1,25 +1,28 @@
|
||||||
|
// This is the source code of AyuGram for Desktop.
|
||||||
|
//
|
||||||
|
// We do not and cannot prevent the use of our code,
|
||||||
|
// but be respectful and credit the original author.
|
||||||
|
//
|
||||||
|
// Copyright @Radolyn, 2025
|
||||||
#include "ayu_forward.h"
|
#include "ayu_forward.h"
|
||||||
#include <lang_auto.h>
|
|
||||||
#include <base/random.h>
|
|
||||||
#include <data/data_peer.h>
|
|
||||||
#include <history/history_item.h>
|
|
||||||
#include <styles/style_boxes.h>
|
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "ayu_sync.h"
|
#include "ayu_sync.h"
|
||||||
|
#include "lang_auto.h"
|
||||||
#include "ayu/utils/telegram_helpers.h"
|
#include "ayu/utils/telegram_helpers.h"
|
||||||
|
#include "base/random.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "data/data_changes.h"
|
#include "data/data_changes.h"
|
||||||
#include "data/data_channel.h"
|
|
||||||
#include "data/data_chat.h"
|
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
|
#include "data/data_peer.h"
|
||||||
#include "data/data_photo.h"
|
#include "data/data_photo.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_user.h"
|
#include "history/history_item.h"
|
||||||
#include "storage/file_download.h"
|
#include "storage/file_download.h"
|
||||||
#include "storage/localimageloader.h"
|
#include "storage/localimageloader.h"
|
||||||
#include "storage/storage_account.h"
|
#include "storage/storage_account.h"
|
||||||
#include "storage/storage_media_prepare.h"
|
#include "storage/storage_media_prepare.h"
|
||||||
|
#include "styles/style_boxes.h"
|
||||||
#include "ui/chat/attach/attach_prepare.h"
|
#include "ui/chat/attach/attach_prepare.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
|
|
||||||
|
@ -93,20 +96,22 @@ std::pair<QString, QString> stateName(const PeerId &id) {
|
||||||
|
|
||||||
return std::make_pair(status, partString);
|
return std::make_pair(status, partString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ForwardState::updateBottomBar(const Main::Session &session, const PeerId *peer, const State &st) {
|
void ForwardState::updateBottomBar(const Main::Session &session, const PeerId *peer, const State &st) {
|
||||||
state = st;
|
state = st;
|
||||||
|
|
||||||
session.changes().peerUpdated(session.data().peer(*peer), Data::PeerUpdate::Flag::Rights);
|
session.changes().peerUpdated(session.data().peer(*peer), Data::PeerUpdate::Flag::Rights);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Ui::PreparedList prepareMedia(not_null<Main::Session*> session,
|
static Ui::PreparedList prepareMedia(not_null<Main::Session*> session,
|
||||||
const std::vector<not_null<HistoryItem*>> &items,
|
const std::vector<not_null<HistoryItem*>> &items,
|
||||||
int &i) {
|
int &i,
|
||||||
|
std::vector<not_null<Data::Media*>> &groupMedia) {
|
||||||
const auto prepare = [&](not_null<Data::Media*> media)
|
const auto prepare = [&](not_null<Data::Media*> media)
|
||||||
{
|
{
|
||||||
|
groupMedia.emplace_back(media);
|
||||||
auto prepared = Ui::PreparedFile(AyuSync::filePath(session, media));
|
auto prepared = Ui::PreparedFile(AyuSync::filePath(session, media));
|
||||||
Storage::PrepareDetails(prepared, st::sendMediaPreviewSize, 1280);
|
Storage::PrepareDetails(prepared, st::sendMediaPreviewSize, PhotoSideLimit());
|
||||||
return prepared;
|
return prepared;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -138,7 +143,8 @@ void sendMedia(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
std::shared_ptr<Ui::PreparedBundle> bundle,
|
std::shared_ptr<Ui::PreparedBundle> bundle,
|
||||||
not_null<Data::Media*> primaryMedia,
|
not_null<Data::Media*> primaryMedia,
|
||||||
Api::MessageToSend &&message) {
|
Api::MessageToSend &&message,
|
||||||
|
bool sendImagesAsPhotos) {
|
||||||
if (const auto document = primaryMedia->document(); document && document->sticker()) {
|
if (const auto document = primaryMedia->document(); document && document->sticker()) {
|
||||||
AyuSync::sendStickerSync(session, message, document);
|
AyuSync::sendStickerSync(session, message, document);
|
||||||
return;
|
return;
|
||||||
|
@ -151,9 +157,8 @@ void sendMedia(
|
||||||
return SendMediaType::Audio;
|
return SendMediaType::Audio;
|
||||||
} else if (document->isVideoMessage()) {
|
} else if (document->isVideoMessage()) {
|
||||||
return SendMediaType::Round;
|
return SendMediaType::Round;
|
||||||
} else {
|
|
||||||
return SendMediaType::File;
|
|
||||||
}
|
}
|
||||||
|
return SendMediaType::File;
|
||||||
}
|
}
|
||||||
return SendMediaType::Photo;
|
return SendMediaType::Photo;
|
||||||
}();
|
}();
|
||||||
|
@ -181,17 +186,8 @@ void sendMedia(
|
||||||
// at least try to send it as squared-video
|
// at least try to send it as squared-video
|
||||||
}
|
}
|
||||||
|
|
||||||
// workaround
|
// workaround for media albums consisting of video and photos
|
||||||
auto isTherePhotos = false;
|
if (sendImagesAsPhotos) {
|
||||||
for (auto &group : bundle->groups) {
|
|
||||||
for (Ui::PreparedFile &file : group.list.files) {
|
|
||||||
if (file.type == Ui::PreparedFile::Type::Photo) {
|
|
||||||
isTherePhotos = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mediaType == SendMediaType::File && isTherePhotos) {
|
|
||||||
mediaType = SendMediaType::Photo;
|
mediaType = SendMediaType::Photo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,7 +327,7 @@ void forwardMessages(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state->totalMessages = items.size();
|
state->totalMessages = items.size();
|
||||||
if (toBeDownloaded.size()) {
|
if (!toBeDownloaded.empty()) {
|
||||||
state->state = ForwardState::State::Downloading;
|
state->state = ForwardState::State::Downloading;
|
||||||
state->updateBottomBar(*session, &peer->id, ForwardState::State::Downloading);
|
state->updateBottomBar(*session, &peer->id, ForwardState::State::Downloading);
|
||||||
AyuSync::loadDocuments(session, toBeDownloaded);
|
AyuSync::loadDocuments(session, toBeDownloaded);
|
||||||
|
@ -369,11 +365,18 @@ void forwardMessages(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto preparedMedia = prepareMedia(session, items, i);
|
std::vector<not_null<Data::Media*>> groupMedia;
|
||||||
|
auto preparedMedia = prepareMedia(session, items, i, groupMedia);
|
||||||
|
|
||||||
Ui::SendFilesWay way;
|
Ui::SendFilesWay way;
|
||||||
way.setGroupFiles(true);
|
way.setGroupFiles(true);
|
||||||
way.setSendImagesAsPhotos(true);
|
way.setSendImagesAsPhotos(false);
|
||||||
|
for (const auto &media2 : groupMedia) {
|
||||||
|
if (media2->photo()) {
|
||||||
|
way.setSendImagesAsPhotos(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto groups = Ui::DivideByGroups(
|
auto groups = Ui::DivideByGroups(
|
||||||
std::move(preparedMedia),
|
std::move(preparedMedia),
|
||||||
|
@ -385,7 +388,7 @@ void forwardMessages(
|
||||||
way,
|
way,
|
||||||
message.textWithTags,
|
message.textWithTags,
|
||||||
false);
|
false);
|
||||||
sendMedia(session, bundle, media, std::move(message));
|
sendMedia(session, bundle, media, std::move(message), way.sendImagesAsPhotos());
|
||||||
}
|
}
|
||||||
// if there are grouped messages
|
// if there are grouped messages
|
||||||
// "i" is incremented in prepareMedia
|
// "i" is incremented in prepareMedia
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
|
// This is the source code of AyuGram for Desktop.
|
||||||
|
//
|
||||||
|
// We do not and cannot prevent the use of our code,
|
||||||
|
// but be respectful and credit the original author.
|
||||||
|
//
|
||||||
|
// Copyright @Radolyn, 2025
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <main/main_session.h>
|
|
||||||
|
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
|
|
||||||
namespace AyuForward {
|
namespace AyuForward {
|
||||||
bool isForwarding(const PeerId &id);
|
bool isForwarding(const PeerId &id);
|
||||||
|
|
|
@ -1,16 +1,24 @@
|
||||||
|
// This is the source code of AyuGram for Desktop.
|
||||||
|
//
|
||||||
|
// We do not and cannot prevent the use of our code,
|
||||||
|
// but be respectful and credit the original author.
|
||||||
|
//
|
||||||
|
// Copyright @Radolyn, 2025
|
||||||
#include "ayu_sync.h"
|
#include "ayu_sync.h"
|
||||||
|
|
||||||
#include "api/api_sending.h"
|
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
#include "api/api_sending.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "data/data_changes.h"
|
#include "core/core_settings.h"
|
||||||
|
#include "core/file_utilities.h"
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
#include "data/data_photo.h"
|
#include "data/data_photo.h"
|
||||||
#include "data/data_photo_media.h"
|
#include "data/data_photo_media.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
#include "history/history.h"
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "storage/file_download_mtproto.h"
|
#include "storage/file_download_mtproto.h"
|
||||||
|
#include "storage/localimageloader.h"
|
||||||
|
|
||||||
class TimedCountDownLatch
|
class TimedCountDownLatch
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,28 +1,21 @@
|
||||||
|
// This is the source code of AyuGram for Desktop.
|
||||||
|
//
|
||||||
|
// We do not and cannot prevent the use of our code,
|
||||||
|
// but be respectful and credit the original author.
|
||||||
|
//
|
||||||
|
// Copyright @Radolyn, 2025
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "data/data_media_types.h"
|
|
||||||
#include "data/data_session.h"
|
|
||||||
#include <base/random.h>
|
|
||||||
#include <data/data_histories.h>
|
|
||||||
#include <data/data_peer.h>
|
|
||||||
#include <history/history_item.h>
|
|
||||||
|
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/random.h"
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
|
#include "data/data_media_types.h"
|
||||||
#include "data/data_photo.h"
|
#include "data/data_photo.h"
|
||||||
#include "data/data_session.h"
|
#include "history/history_item.h"
|
||||||
#include "storage/file_download_mtproto.h"
|
|
||||||
#include "storage/file_upload.h"
|
|
||||||
#include "api/api_peer_photo.h"
|
|
||||||
#include "core/application.h"
|
|
||||||
#include "core/core_settings.h"
|
|
||||||
#include "data/data_channel.h"
|
|
||||||
#include "data/data_chat.h"
|
|
||||||
#include "storage/localimageloader.h"
|
|
||||||
#include "storage/storage_media_prepare.h"
|
|
||||||
#include "ui/chat/attach/attach_prepare.h"
|
|
||||||
#include "storage/file_download.h"
|
#include "storage/file_download.h"
|
||||||
|
#include "storage/file_upload.h"
|
||||||
#include "storage/storage_account.h"
|
#include "storage/storage_account.h"
|
||||||
|
#include "ui/chat/attach/attach_prepare.h"
|
||||||
|
|
||||||
namespace AyuSync {
|
namespace AyuSync {
|
||||||
|
|
||||||
|
|
|
@ -619,9 +619,11 @@ bool ChannelData::canAddAdmins() const {
|
||||||
return amCreator()
|
return amCreator()
|
||||||
|| (adminRights() & AdminRight::AddAdmins);
|
|| (adminRights() & AdminRight::AddAdmins);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChannelData::isAyuNoForwards() const {
|
bool ChannelData::isAyuNoForwards() const {
|
||||||
return flags() & Flag::AyuNoForwards;
|
return flags() & Flag::AyuNoForwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChannelData::allowsForwarding() const {
|
bool ChannelData::allowsForwarding() const {
|
||||||
return !(flags() & Flag::NoForwards);
|
return !(flags() & Flag::NoForwards);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@ ChatAdminRightsInfo ChatData::defaultAdminRights(not_null<UserData*> user) {
|
||||||
| Flag::ManageCall
|
| Flag::ManageCall
|
||||||
| (isCreator ? Flag::AddAdmins : Flag(0)));
|
| (isCreator ? Flag::AddAdmins : Flag(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatData::isAyuNoForwards() const {
|
bool ChatData::isAyuNoForwards() const {
|
||||||
return flags() & Flag::AyuNoForwards;
|
return flags() & Flag::AyuNoForwards;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "data/data_chat_participant_status.h"
|
#include "data/data_chat_participant_status.h"
|
||||||
|
|
||||||
#include "ayu/features/forward/ayu_forward.h"
|
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "boxes/peers/edit_peer_permissions_box.h"
|
#include "boxes/peers/edit_peer_permissions_box.h"
|
||||||
#include "chat_helpers/compose/compose_show.h"
|
#include "chat_helpers/compose/compose_show.h"
|
||||||
|
@ -26,6 +25,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "styles/style_widgets.h"
|
#include "styles/style_widgets.h"
|
||||||
|
|
||||||
|
// AyuGram includes
|
||||||
|
#include "ayu/features/forward/ayu_forward.h"
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
[[nodiscard]] ChatAdminRights ChatAdminRightsFlags(
|
[[nodiscard]] ChatAdminRights ChatAdminRightsFlags(
|
||||||
|
|
|
@ -1385,6 +1385,7 @@ Data::ForumTopic *PeerData::forumTopicFor(MsgId rootId) const {
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerData::isAyuNoForwards() const {
|
bool PeerData::isAyuNoForwards() const {
|
||||||
if (const auto user = asUser()) {
|
if (const auto user = asUser()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -353,7 +353,7 @@ enum class MessageFlag : uint64 {
|
||||||
HideDisplayDate = (1ULL << 51),
|
HideDisplayDate = (1ULL << 51),
|
||||||
|
|
||||||
|
|
||||||
AyuNoForwards = (1ULL << 63),
|
AyuNoForwards = (1ULL << 63),
|
||||||
};
|
};
|
||||||
inline constexpr bool is_flag_type(MessageFlag) { return true; }
|
inline constexpr bool is_flag_type(MessageFlag) { return true; }
|
||||||
using MessageFlags = base::flags<MessageFlag>;
|
using MessageFlags = base::flags<MessageFlag>;
|
||||||
|
|
|
@ -1766,6 +1766,7 @@ bool HistoryItem::isScheduled() const {
|
||||||
bool HistoryItem::isSponsored() const {
|
bool HistoryItem::isSponsored() const {
|
||||||
return _flags & MessageFlag::Sponsored;
|
return _flags & MessageFlag::Sponsored;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HistoryItem::isAyuNoForwards() const {
|
bool HistoryItem::isAyuNoForwards() const {
|
||||||
return _flags & MessageFlag::AyuNoForwards;
|
return _flags & MessageFlag::AyuNoForwards;
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,6 +187,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ayu/ayu_settings.h"
|
#include "ayu/ayu_settings.h"
|
||||||
#include "ayu/utils/telegram_helpers.h"
|
#include "ayu/utils/telegram_helpers.h"
|
||||||
#include "ayu/features/messageshot/message_shot.h"
|
#include "ayu/features/messageshot/message_shot.h"
|
||||||
|
#include "ayu/features/forward/ayu_forward.h"
|
||||||
#include "ayu/ui/boxes/message_shot_box.h"
|
#include "ayu/ui/boxes/message_shot_box.h"
|
||||||
#include "boxes/abstract_box.h"
|
#include "boxes/abstract_box.h"
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
#include <QtCore/QMimeData>
|
#include <QtCore/QMimeData>
|
||||||
|
|
||||||
|
// AyuGram includes
|
||||||
|
#include "ayu/features/forward/ayu_forward.h"
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void ClearBotStartToken(PeerData *peer) {
|
void ClearBotStartToken(PeerData *peer) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue