Compare commits

..

3 commits
v5.16.4 ... dev

Author SHA1 Message Date
bleizix
1dfe68e9f3 fix: cache icons in settings 2025-07-29 01:55:47 +03:00
bleizix
64b824671a fix: don't increment channel views 2025-07-29 01:55:46 +03:00
bleizix
4940d85b29 fix: AyuForward crashes & improvements 2025-07-29 01:55:43 +03:00
6 changed files with 80 additions and 22 deletions

View file

@ -15,6 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_item.h" #include "history/history_item.h"
#include "main/main_session.h" #include "main/main_session.h"
// AyuGram includes
#include "ayu/ayu_settings.h"
namespace Api { namespace Api {
namespace { namespace {
@ -83,6 +87,8 @@ void ViewsManager::pollExtendedMedia(
} }
void ViewsManager::viewsIncrement() { void ViewsManager::viewsIncrement() {
const auto &settings = AyuSettings::getInstance();
for (auto i = _toIncrement.begin(); i != _toIncrement.cend();) { for (auto i = _toIncrement.begin(); i != _toIncrement.cend();) {
if (_incrementRequests.contains(i->first)) { if (_incrementRequests.contains(i->first)) {
++i; ++i;
@ -97,7 +103,7 @@ void ViewsManager::viewsIncrement() {
const auto requestId = _api.request(MTPmessages_GetMessagesViews( const auto requestId = _api.request(MTPmessages_GetMessagesViews(
i->first->input, i->first->input,
MTP_vector<MTPint>(ids), MTP_vector<MTPint>(ids),
MTP_bool(true) MTP_bool(settings.sendReadMessages)
)).done([=]( )).done([=](
const MTPmessages_MessageViews &result, const MTPmessages_MessageViews &result,
mtpRequestId requestId) { mtpRequestId requestId) {

View file

@ -213,12 +213,11 @@ void sendMedia(
} }
bool isAyuForwardNeeded(const std::vector<not_null<HistoryItem*>> &items) { bool isAyuForwardNeeded(const std::vector<not_null<HistoryItem*>> &items) {
for (const auto &item : items) { const auto needAyuForward = [&](const auto &item)
if (isAyuForwardNeeded(item)) { {
return true; return isAyuForwardNeeded(item);
} };
} return std::ranges::any_of(items, needAyuForward);
return false;
} }
bool isAyuForwardNeeded(not_null<HistoryItem*> item) { bool isAyuForwardNeeded(not_null<HistoryItem*> item) {
@ -243,7 +242,10 @@ void intelligentForward(
const Api::SendAction &action, const Api::SendAction &action,
const Data::ResolvedForwardDraft &draft) { const Data::ResolvedForwardDraft &draft) {
const auto history = action.history; const auto history = action.history;
history->setForwardDraft(action.replyTo.topicRootId, action.replyTo.monoforumPeerId, {}); crl::on_main([&]
{
history->setForwardDraft(action.replyTo.topicRootId, action.replyTo.monoforumPeerId, {});
});
const auto items = draft.items; const auto items = draft.items;
const auto peer = history->peer; const auto peer = history->peer;
@ -302,7 +304,7 @@ void forwardMessages(
not_null<Main::Session*> session, not_null<Main::Session*> session,
const Api::SendAction &action, const Api::SendAction &action,
bool forwardState, bool forwardState,
Data::ResolvedForwardDraft draft) { const Data::ResolvedForwardDraft &draft) {
const auto items = draft.items; const auto items = draft.items;
const auto history = action.history; const auto history = action.history;
const auto peer = history->peer; const auto peer = history->peer;
@ -392,6 +394,23 @@ void forwardMessages(
} }
} }
// remove not finished files
for (int j = preparedMedia.files.size() - 1; j >= 0; j--) {
auto &file = preparedMedia.files[j];
QFile f(file.path);
if (groupMedia[j]->photo() && f.size() < groupMedia[j]->photo()->imageByteSize(Data::PhotoSize::Large)
||
groupMedia[j]->document() && f.size() < groupMedia[j]->document()->size
) {
preparedMedia.files.erase(preparedMedia.files.begin() + j);
}
}
if (preparedMedia.files.empty()) {
continue;
}
auto groups = Ui::DivideByGroups( auto groups = Ui::DivideByGroups(
std::move(preparedMedia), std::move(preparedMedia),
way, way,

View file

@ -47,6 +47,6 @@ void forwardMessages(
not_null<Main::Session*> session, not_null<Main::Session*> session,
const Api::SendAction &action, const Api::SendAction &action,
bool forwardState, bool forwardState,
Data::ResolvedForwardDraft draft); const Data::ResolvedForwardDraft &draft);
} }

View file

@ -55,7 +55,7 @@ private:
namespace AyuSync { namespace AyuSync {
QString pathForSave(not_null<Main::Session*> session) { QString pathForSave(not_null<Main::Session*> session) {
const auto path = Core::App().settings().downloadPath(); auto path = Core::App().settings().downloadPath();
if (path.isEmpty()) { if (path.isEmpty()) {
return File::DefaultDownloadPath(session); return File::DefaultDownloadPath(session);
} }
@ -66,6 +66,10 @@ QString pathForSave(not_null<Main::Session*> session) {
} }
QString filePath(not_null<Main::Session*> session, const Data::Media *media) { QString filePath(not_null<Main::Session*> session, const Data::Media *media) {
if (!media) {
return {};
}
if (const auto document = media->document()) { if (const auto document = media->document()) {
if (!document->filename().isEmpty()) { if (!document->filename().isEmpty()) {
return pathForSave(session) + media->document()->filename(); return pathForSave(session) + media->document()->filename();
@ -85,7 +89,7 @@ QString filePath(not_null<Main::Session*> session, const Data::Media *media) {
return pathForSave(session) + QString::number(photo->getDC()) + "_" + QString::number(photo->id) + ".jpg"; return pathForSave(session) + QString::number(photo->getDC()) + "_" + QString::number(photo->id) + ".jpg";
} }
return QString(); return {};
} }
qint64 fileSize(not_null<HistoryItem*> item) { qint64 fileSize(not_null<HistoryItem*> item) {
@ -128,9 +132,13 @@ void loadDocumentSync(not_null<Main::Session*> session, DocumentData *data, not_
auto latch = std::make_shared<TimedCountDownLatch>(1); auto latch = std::make_shared<TimedCountDownLatch>(1);
auto lifetime = std::make_shared<rpl::lifetime>(); auto lifetime = std::make_shared<rpl::lifetime>();
auto path = filePath(session, item->media());
if (path.isEmpty()) {
return;
}
crl::on_main([&] crl::on_main([&]
{ {
data->save(Data::FileOriginMessage(item->fullId()), filePath(session, item->media())); data->save(Data::FileOriginMessage(item->fullId()), path);
rpl::single() | rpl::then( rpl::single() | rpl::then(
session->downloaderTaskFinished() session->downloaderTaskFinished()
@ -140,12 +148,26 @@ void loadDocumentSync(not_null<Main::Session*> session, DocumentData *data, not_
}) | rpl::start_with_next([&]() mutable }) | rpl::start_with_next([&]() mutable
{ {
latch->countDown(); latch->countDown();
base::take(lifetime)->destroy();
}, },
*lifetime); *lifetime);
}); });
latch->await(std::chrono::minutes(5));
constexpr auto overall = std::chrono::minutes(15);
const auto startTime = std::chrono::steady_clock::now();
while (std::chrono::steady_clock::now() - startTime < overall) {
if (latch->await(std::chrono::minutes(5))) {
break;
}
if (!data->loading()) {
break;
}
}
base::take(lifetime)->destroy();
} }
void forwardMessagesSync(not_null<Main::Session*> session, void forwardMessagesSync(not_null<Main::Session*> session,
@ -220,11 +242,11 @@ void loadPhotoSync(not_null<Main::Session*> session, const std::pair<not_null<Ph
{ {
saveToFiles(); saveToFiles();
latch->countDown(); latch->countDown();
base::take(lifetime)->destroy();
}, },
*lifetime); *lifetime);
}); });
latch->await(std::chrono::minutes(5)); latch->await(std::chrono::minutes(5));
base::take(lifetime)->destroy();
} }
} }
@ -255,12 +277,12 @@ void waitForMsgSync(not_null<Main::Session*> session, const Api::SendAction &act
}) | rpl::start_with_next([&] }) | rpl::start_with_next([&]
{ {
latch->countDown(); latch->countDown();
base::take(lifetime)->destroy();
}, },
*lifetime); *lifetime);
}); });
latch->await(std::chrono::minutes(2)); latch->await(std::chrono::minutes(5));
base::take(lifetime)->destroy();
} }
void sendDocumentSync(not_null<Main::Session*> session, void sendDocumentSync(not_null<Main::Session*> session,

View file

@ -37,6 +37,7 @@ const QVector<QString> icons{
AyuAssets::CHIBI2_ICON, AyuAssets::CHIBI2_ICON,
AyuAssets::EXTERA2_ICON, AyuAssets::EXTERA2_ICON,
}; };
std::unordered_map<QString, QImage> cachedIcons;
const auto rows = static_cast<int>(icons.size()) / 4 + std::min(1, static_cast<int>(icons.size()) % 4); const auto rows = static_cast<int>(icons.size()) / 4 + std::min(1, static_cast<int>(icons.size()) % 4);
@ -83,6 +84,9 @@ IconPicker::IconPicker(QWidget *parent)
setMinimumSize(st::boxWidth, (st::cpIconSize + st::cpPadding) * rows - st::cpPadding); setMinimumSize(st::boxWidth, (st::cpIconSize + st::cpPadding) * rows - st::cpPadding);
} }
IconPicker::~IconPicker() {
cachedIcons.clear();
}
void IconPicker::paintEvent(QPaintEvent *e) { void IconPicker::paintEvent(QPaintEvent *e) {
Painter p(this); Painter p(this);
PainterHighQualityEnabler hq(p); PainterHighQualityEnabler hq(p);
@ -98,10 +102,16 @@ void IconPicker::paintEvent(QPaintEvent *e) {
if (iconName.isEmpty()) { if (iconName.isEmpty()) {
continue; continue;
} }
QImage icon;
auto icon = AyuAssets::loadPreview(iconName) if (const auto cached = cachedIcons.find(iconName); cached != cachedIcons.end()) {
.scaled(st::cpIconSize, st::cpIconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); icon = cached->second;
} else {
icon = cachedIcons[iconName] = AyuAssets::loadPreview(iconName).scaled(
st::cpIconSize,
st::cpIconSize,
Qt::KeepAspectRatio,
Qt::SmoothTransformation);
}
auto opacity = 0.0f; auto opacity = 0.0f;
if (iconName == wasSelected) { if (iconName == wasSelected) {
opacity = 1.0f - animation.value(1.0f); opacity = 1.0f - animation.value(1.0f);

View file

@ -13,6 +13,7 @@ class IconPicker : public Ui::RpWidget
{ {
public: public:
IconPicker(QWidget *parent); IconPicker(QWidget *parent);
~IconPicker();
protected: protected:
void paintEvent(QPaintEvent *e) override; void paintEvent(QPaintEvent *e) override;