mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-09-05 19:43:24 +02:00
Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
|
1dfe68e9f3 | ||
|
64b824671a | ||
|
4940d85b29 |
6 changed files with 80 additions and 22 deletions
|
@ -15,6 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/history_item.h"
|
||||
#include "main/main_session.h"
|
||||
|
||||
// AyuGram includes
|
||||
#include "ayu/ayu_settings.h"
|
||||
|
||||
|
||||
namespace Api {
|
||||
namespace {
|
||||
|
||||
|
@ -83,6 +87,8 @@ void ViewsManager::pollExtendedMedia(
|
|||
}
|
||||
|
||||
void ViewsManager::viewsIncrement() {
|
||||
const auto &settings = AyuSettings::getInstance();
|
||||
|
||||
for (auto i = _toIncrement.begin(); i != _toIncrement.cend();) {
|
||||
if (_incrementRequests.contains(i->first)) {
|
||||
++i;
|
||||
|
@ -97,7 +103,7 @@ void ViewsManager::viewsIncrement() {
|
|||
const auto requestId = _api.request(MTPmessages_GetMessagesViews(
|
||||
i->first->input,
|
||||
MTP_vector<MTPint>(ids),
|
||||
MTP_bool(true)
|
||||
MTP_bool(settings.sendReadMessages)
|
||||
)).done([=](
|
||||
const MTPmessages_MessageViews &result,
|
||||
mtpRequestId requestId) {
|
||||
|
|
|
@ -213,12 +213,11 @@ void sendMedia(
|
|||
}
|
||||
|
||||
bool isAyuForwardNeeded(const std::vector<not_null<HistoryItem*>> &items) {
|
||||
for (const auto &item : items) {
|
||||
if (isAyuForwardNeeded(item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
const auto needAyuForward = [&](const auto &item)
|
||||
{
|
||||
return isAyuForwardNeeded(item);
|
||||
};
|
||||
return std::ranges::any_of(items, needAyuForward);
|
||||
}
|
||||
|
||||
bool isAyuForwardNeeded(not_null<HistoryItem*> item) {
|
||||
|
@ -243,7 +242,10 @@ void intelligentForward(
|
|||
const Api::SendAction &action,
|
||||
const Data::ResolvedForwardDraft &draft) {
|
||||
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 peer = history->peer;
|
||||
|
@ -302,7 +304,7 @@ void forwardMessages(
|
|||
not_null<Main::Session*> session,
|
||||
const Api::SendAction &action,
|
||||
bool forwardState,
|
||||
Data::ResolvedForwardDraft draft) {
|
||||
const Data::ResolvedForwardDraft &draft) {
|
||||
const auto items = draft.items;
|
||||
const auto history = action.history;
|
||||
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(
|
||||
std::move(preparedMedia),
|
||||
way,
|
||||
|
|
|
@ -47,6 +47,6 @@ void forwardMessages(
|
|||
not_null<Main::Session*> session,
|
||||
const Api::SendAction &action,
|
||||
bool forwardState,
|
||||
Data::ResolvedForwardDraft draft);
|
||||
const Data::ResolvedForwardDraft &draft);
|
||||
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ private:
|
|||
namespace AyuSync {
|
||||
|
||||
QString pathForSave(not_null<Main::Session*> session) {
|
||||
const auto path = Core::App().settings().downloadPath();
|
||||
auto path = Core::App().settings().downloadPath();
|
||||
if (path.isEmpty()) {
|
||||
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) {
|
||||
if (!media) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (const auto document = media->document()) {
|
||||
if (!document->filename().isEmpty()) {
|
||||
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 QString();
|
||||
return {};
|
||||
}
|
||||
|
||||
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 lifetime = std::make_shared<rpl::lifetime>();
|
||||
|
||||
auto path = filePath(session, item->media());
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
crl::on_main([&]
|
||||
{
|
||||
data->save(Data::FileOriginMessage(item->fullId()), filePath(session, item->media()));
|
||||
data->save(Data::FileOriginMessage(item->fullId()), path);
|
||||
|
||||
rpl::single() | rpl::then(
|
||||
session->downloaderTaskFinished()
|
||||
|
@ -140,12 +148,26 @@ void loadDocumentSync(not_null<Main::Session*> session, DocumentData *data, not_
|
|||
}) | rpl::start_with_next([&]() mutable
|
||||
{
|
||||
latch->countDown();
|
||||
base::take(lifetime)->destroy();
|
||||
},
|
||||
*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,
|
||||
|
@ -220,11 +242,11 @@ void loadPhotoSync(not_null<Main::Session*> session, const std::pair<not_null<Ph
|
|||
{
|
||||
saveToFiles();
|
||||
latch->countDown();
|
||||
base::take(lifetime)->destroy();
|
||||
},
|
||||
*lifetime);
|
||||
});
|
||||
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([&]
|
||||
{
|
||||
latch->countDown();
|
||||
base::take(lifetime)->destroy();
|
||||
},
|
||||
*lifetime);
|
||||
});
|
||||
|
||||
latch->await(std::chrono::minutes(2));
|
||||
latch->await(std::chrono::minutes(5));
|
||||
base::take(lifetime)->destroy();
|
||||
}
|
||||
|
||||
void sendDocumentSync(not_null<Main::Session*> session,
|
||||
|
|
|
@ -37,6 +37,7 @@ const QVector<QString> icons{
|
|||
AyuAssets::CHIBI2_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);
|
||||
|
||||
|
@ -83,6 +84,9 @@ IconPicker::IconPicker(QWidget *parent)
|
|||
setMinimumSize(st::boxWidth, (st::cpIconSize + st::cpPadding) * rows - st::cpPadding);
|
||||
}
|
||||
|
||||
IconPicker::~IconPicker() {
|
||||
cachedIcons.clear();
|
||||
}
|
||||
void IconPicker::paintEvent(QPaintEvent *e) {
|
||||
Painter p(this);
|
||||
PainterHighQualityEnabler hq(p);
|
||||
|
@ -98,10 +102,16 @@ void IconPicker::paintEvent(QPaintEvent *e) {
|
|||
if (iconName.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto icon = AyuAssets::loadPreview(iconName)
|
||||
.scaled(st::cpIconSize, st::cpIconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
|
||||
QImage icon;
|
||||
if (const auto cached = cachedIcons.find(iconName); cached != cachedIcons.end()) {
|
||||
icon = cached->second;
|
||||
} else {
|
||||
icon = cachedIcons[iconName] = AyuAssets::loadPreview(iconName).scaled(
|
||||
st::cpIconSize,
|
||||
st::cpIconSize,
|
||||
Qt::KeepAspectRatio,
|
||||
Qt::SmoothTransformation);
|
||||
}
|
||||
auto opacity = 0.0f;
|
||||
if (iconName == wasSelected) {
|
||||
opacity = 1.0f - animation.value(1.0f);
|
||||
|
|
|
@ -13,6 +13,7 @@ class IconPicker : public Ui::RpWidget
|
|||
{
|
||||
public:
|
||||
IconPicker(QWidget *parent);
|
||||
~IconPicker();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
|
Loading…
Add table
Reference in a new issue