mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-10-18 08:25:30 +02:00
Allow forward / delete saved music.
This commit is contained in:
parent
6211b7733d
commit
dbaa7b5e67
10 changed files with 102 additions and 53 deletions
|
@ -4814,6 +4814,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_selected_delete_sure_this" = "Do you want to delete this message?";
|
||||
"lng_selected_delete_sure#one" = "Do you want to delete {count} message?";
|
||||
"lng_selected_delete_sure#other" = "Do you want to delete {count} messages?";
|
||||
"lng_selected_remove_saved_music" = "Do you want to remove this file from your profile?";
|
||||
"lng_delete_photo_sure" = "Do you want to delete this photo?";
|
||||
"lng_delete_for_everyone_hint#one" = "This will delete it for everyone in this chat.";
|
||||
"lng_delete_for_everyone_hint#other" = "This will delete them for everyone in this chat.";
|
||||
|
|
|
@ -3350,8 +3350,8 @@ void ApiWrap::finishForwarding(const SendAction &action) {
|
|||
return;
|
||||
}
|
||||
|
||||
forwardMessages(std::move(toForward), action);
|
||||
history->setForwardDraft(topicRootId, monoforumPeerId, {});
|
||||
forwardMessages(std::move(toForward), action);
|
||||
}
|
||||
|
||||
_session->data().sendHistoryChangeNotifications();
|
||||
|
@ -3372,6 +3372,22 @@ void ApiWrap::forwardMessages(
|
|||
|
||||
auto &histories = _session->data().histories();
|
||||
|
||||
for (auto i = begin(draft.items); i != end(draft.items);) {
|
||||
const auto item = *i;
|
||||
if (item->isSavedMusicItem()) {
|
||||
SendExistingDocument(MessageToSend(action), item->media()->document());
|
||||
i = draft.items.erase(i);
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
if (draft.items.empty()) {
|
||||
if (successCallback) {
|
||||
successCallback();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
struct SharedCallback {
|
||||
int requestsLeft = 0;
|
||||
FnMut<void()> callback;
|
||||
|
|
|
@ -224,12 +224,14 @@ void DeleteMessagesBox::prepare() {
|
|||
search->searchMessages({ .from = _moderateFrom });
|
||||
}
|
||||
} else {
|
||||
details.text = (_ids.size() == 1)
|
||||
details.text = hasSavedMusicMessages()
|
||||
? tr::lng_selected_remove_saved_music(tr::now)
|
||||
: (_ids.size() == 1)
|
||||
? tr::lng_selected_delete_sure_this(tr::now)
|
||||
: tr::lng_selected_delete_sure(tr::now, lt_count, _ids.size());
|
||||
if (const auto peer = checkFromSinglePeer()) {
|
||||
auto count = int(_ids.size());
|
||||
if (hasScheduledMessages()) {
|
||||
if (hasScheduledMessages() || hasSavedMusicMessages()) {
|
||||
} else if (auto revoke = revokeText(peer)) {
|
||||
const auto &settings = Core::App().settings();
|
||||
const auto revokeByDefault
|
||||
|
@ -313,28 +315,36 @@ void DeleteMessagesBox::prepare() {
|
|||
addButton(tr::lng_about_done(), [=] { closeBox(); });
|
||||
}
|
||||
|
||||
auto fullHeight = st::boxPadding.top()
|
||||
+ _text->height()
|
||||
+ st::boxPadding.bottom();
|
||||
if (_moderateFrom) {
|
||||
fullHeight += st::boxMediumSkip;
|
||||
if (_banUser) {
|
||||
fullHeight += _banUser->heightNoMargins() + st::boxLittleSkip;
|
||||
const auto &padding = st::boxPadding;
|
||||
rpl::combine(
|
||||
widthValue(),
|
||||
_text->naturalWidthValue()
|
||||
) | rpl::start_with_next([=](int full, int) {
|
||||
_text->resizeToNaturalWidth(full - padding.left() - padding.right());
|
||||
|
||||
auto fullHeight = st::boxPadding.top()
|
||||
+ _text->height()
|
||||
+ st::boxPadding.bottom();
|
||||
if (_moderateFrom) {
|
||||
fullHeight += st::boxMediumSkip;
|
||||
if (_banUser) {
|
||||
fullHeight += _banUser->heightNoMargins() + st::boxLittleSkip;
|
||||
}
|
||||
fullHeight += _reportSpam->heightNoMargins();
|
||||
if (_deleteAll) {
|
||||
fullHeight += st::boxLittleSkip + _deleteAll->heightNoMargins();
|
||||
}
|
||||
} else if (_revoke) {
|
||||
fullHeight += st::boxMediumSkip + _revoke->heightNoMargins();
|
||||
}
|
||||
fullHeight += _reportSpam->heightNoMargins();
|
||||
if (_deleteAll) {
|
||||
fullHeight += st::boxLittleSkip + _deleteAll->heightNoMargins();
|
||||
if (_autoDeleteSettings) {
|
||||
fullHeight += st::boxMediumSkip
|
||||
+ _autoDeleteSettings->height()
|
||||
+ st::boxLittleSkip;
|
||||
}
|
||||
} else if (_revoke) {
|
||||
fullHeight += st::boxMediumSkip + _revoke->heightNoMargins();
|
||||
}
|
||||
if (_autoDeleteSettings) {
|
||||
fullHeight += st::boxMediumSkip
|
||||
+ _autoDeleteSettings->height()
|
||||
+ st::boxLittleSkip;
|
||||
}
|
||||
setDimensions(st::boxWidth, fullHeight);
|
||||
_fullHeight = fullHeight;
|
||||
setDimensions(st::boxWidth, fullHeight);
|
||||
_fullHeight = fullHeight;
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
bool DeleteMessagesBox::hasScheduledMessages() const {
|
||||
|
@ -348,6 +358,17 @@ bool DeleteMessagesBox::hasScheduledMessages() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool DeleteMessagesBox::hasSavedMusicMessages() const {
|
||||
for (const auto &fullId : _ids) {
|
||||
if (const auto item = _session->data().message(fullId)) {
|
||||
if (item->isSavedMusicItem()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
PeerData *DeleteMessagesBox::checkFromSinglePeer() const {
|
||||
auto result = (PeerData*)nullptr;
|
||||
for (const auto &fullId : _ids) {
|
||||
|
|
|
@ -58,6 +58,7 @@ private:
|
|||
void deleteAndClear();
|
||||
[[nodiscard]] PeerData *checkFromSinglePeer() const;
|
||||
[[nodiscard]] bool hasScheduledMessages() const;
|
||||
[[nodiscard]] bool hasSavedMusicMessages() const;
|
||||
[[nodiscard]] std::optional<RevokeConfig> revokeText(
|
||||
not_null<PeerData*> peer) const;
|
||||
[[nodiscard]] PaidPostType paidPostType() const;
|
||||
|
|
|
@ -10,13 +10,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "api/api_text_entities.h"
|
||||
#include "data/business/data_shortcut_messages.h"
|
||||
#include "data/components/scheduled_messages.h"
|
||||
#include "data/data_saved_sublist.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_chat.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_folder.h"
|
||||
#include "data/data_forum.h"
|
||||
#include "data/data_forum_topic.h"
|
||||
#include "data/data_saved_music.h"
|
||||
#include "data/data_saved_sublist.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "base/random.h"
|
||||
|
@ -885,10 +887,10 @@ void Histories::deleteMessagesByDates(
|
|||
}
|
||||
|
||||
void Histories::deleteMessagesByDates(
|
||||
not_null<History*> history,
|
||||
TimeId minDate,
|
||||
TimeId maxDate,
|
||||
bool revoke) {
|
||||
not_null<History*> history,
|
||||
TimeId minDate,
|
||||
TimeId maxDate,
|
||||
bool revoke) {
|
||||
sendRequest(history, RequestType::Delete, [=](Fn<void()> finish) {
|
||||
const auto peer = history->peer;
|
||||
using Flag = MTPmessages_DeleteHistory::Flag;
|
||||
|
@ -921,10 +923,14 @@ void Histories::deleteMessages(const MessageIdsList &ids, bool revoke) {
|
|||
base::flat_map<not_null<History*>, QVector<MTPint>> idsByPeer;
|
||||
base::flat_map<not_null<PeerData*>, QVector<MTPint>> scheduledIdsByPeer;
|
||||
base::flat_map<BusinessShortcutId, QVector<MTPint>> quickIdsByShortcut;
|
||||
base::flat_set<not_null<DocumentData*>> savedMusic;
|
||||
for (const auto &itemId : ids) {
|
||||
if (const auto item = _owner->message(itemId)) {
|
||||
const auto history = item->history();
|
||||
if (item->isScheduled()) {
|
||||
if (item->isSavedMusicItem()) {
|
||||
savedMusic.emplace(item->media()->document());
|
||||
continue;
|
||||
} else if (item->isScheduled()) {
|
||||
const auto wasOnServer = !item->isSending()
|
||||
&& !item->hasFailed();
|
||||
auto &scheduled = _owner->session().scheduledMessages();
|
||||
|
@ -973,6 +979,9 @@ void Histories::deleteMessages(const MessageIdsList &ids, bool revoke) {
|
|||
api->applyUpdates(result);
|
||||
}).send();
|
||||
}
|
||||
for (const auto &document : savedMusic) {
|
||||
document->owner().savedMusic().remove(document);
|
||||
}
|
||||
|
||||
for (const auto item : remove) {
|
||||
const auto history = item->history();
|
||||
|
|
|
@ -949,7 +949,7 @@ void DraftOptionsBox(
|
|||
AddFilledSkip(bottom);
|
||||
|
||||
if (!hasOnlyForcedForwardedInfo
|
||||
&& !HasOnlyDroppedForwardedInfo(items)) {
|
||||
&& HasDropForwardedInfoSetting(items)) {
|
||||
Settings::AddButtonWithIcon(
|
||||
bottom,
|
||||
(dropNames
|
||||
|
|
|
@ -463,11 +463,20 @@ bool HasOnlyForcedForwardedInfo(const HistoryItemsList &list) {
|
|||
|
||||
bool HasOnlyDroppedForwardedInfo(const HistoryItemsList &list) {
|
||||
for (const auto &item : list) {
|
||||
if (!item->computeDropForwardedInfo()) {
|
||||
if (item->isSavedMusicItem() || !item->computeDropForwardedInfo()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HasDropForwardedInfoSetting(const HistoryItemsList &list) {
|
||||
for (const auto &item : list) {
|
||||
if (!item->computeDropForwardedInfo()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace HistoryView::Controls
|
||||
|
|
|
@ -87,5 +87,6 @@ void EditWebPageOptions(
|
|||
|
||||
[[nodiscard]] bool HasOnlyForcedForwardedInfo(const HistoryItemsList &list);
|
||||
[[nodiscard]] bool HasOnlyDroppedForwardedInfo(const HistoryItemsList &list);
|
||||
[[nodiscard]] bool HasDropForwardedInfoSetting(const HistoryItemsList &list);
|
||||
|
||||
} // namespace HistoryView::Controls
|
||||
|
|
|
@ -1308,6 +1308,10 @@ void ListWidget::showContextMenu(
|
|||
}
|
||||
}
|
||||
|
||||
if (_contextMenu->empty()) {
|
||||
_contextMenu = nullptr;
|
||||
return;
|
||||
}
|
||||
_contextMenu->setDestroyedCallback(crl::guard(
|
||||
this,
|
||||
[=] {
|
||||
|
|
|
@ -67,10 +67,10 @@ Type MusicProvider::type() {
|
|||
}
|
||||
|
||||
bool MusicProvider::hasSelectRestriction() {
|
||||
if (_peer->session().frozen()) {
|
||||
return true;
|
||||
}
|
||||
return !_peer->isSelf();
|
||||
//if (_peer->session().frozen()) {
|
||||
// return true;
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
|
||||
rpl::producer<bool> MusicProvider::hasSelectRestrictionChanges() {
|
||||
|
@ -295,21 +295,8 @@ ListItemSelectionData MusicProvider::computeSelectionData(
|
|||
not_null<const HistoryItem*> item,
|
||||
TextSelection selection) {
|
||||
auto result = ListItemSelectionData(selection);
|
||||
AssertIsDebug();
|
||||
//const auto id = item->id;
|
||||
//const auto peer = item->history()->peer;
|
||||
//const auto channel = peer->asChannel();
|
||||
//const auto maybeStory = peer->owner().stories().lookup(
|
||||
// { peer->id, StoryIdFromMsgId(id) });
|
||||
//if (maybeStory) {
|
||||
// const auto story = *maybeStory;
|
||||
// result.canForward = peer->isSelf() && story->canShare();
|
||||
// result.canDelete = story->canDelete();
|
||||
// result.canUnpinStory = story->pinnedToTop();
|
||||
// result.storyInProfile = story->inProfile();
|
||||
//}
|
||||
//result.canToggleStoryPin = peer->isSelf()
|
||||
// || (channel && channel->canEditStories());
|
||||
result.canDelete = item->history()->peer->isSelf();
|
||||
result.canForward = true;// item->allowsForward();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -343,13 +330,13 @@ void MusicProvider::applyDragSelection(
|
|||
bool MusicProvider::allowSaveFileAs(
|
||||
not_null<const HistoryItem*> item,
|
||||
not_null<DocumentData*> document) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
QString MusicProvider::showInFolderPath(
|
||||
not_null<const HistoryItem*> item,
|
||||
not_null<DocumentData*> document) {
|
||||
return QString();
|
||||
return document->filepath(true);
|
||||
}
|
||||
|
||||
int64 MusicProvider::scrollTopStatePosition(not_null<HistoryItem*> item) {
|
||||
|
|
Loading…
Add table
Reference in a new issue