Skip to content

Commit

Permalink
Fix telegram patches.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurnevsky committed Dec 9, 2024
1 parent e712b2b commit 63f8f17
Show file tree
Hide file tree
Showing 5 changed files with 270 additions and 30 deletions.
42 changes: 12 additions & 30 deletions modules/overlays.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,17 @@
bloop = wrap super.bloop "bloop";
})
(self: super: { wine-ge = super.callPackage ./wine-ge.nix { }; })
# TODO:
# (_self: super: {
# telegram-desktop = super.telegram-desktop.overrideAttrs (old: {
# patches = let
# baseUrl =
# "https://raw.githubusercontent.com/kurnevsky/telegram-desktop-patches/03c1041f13ffbbae18d25bef65de6040318fc4a2/";
# in (old.patches or [ ]) ++ [
# (super.fetchpatch {
# url = baseUrl + "0001-Disable-sponsored-messages.patch";
# sha256 = "sha256-HeDH6tkkGx2XYTtzfo+gRee4BYxRiPKXQuftycl8Kvo=";
# })
# (super.fetchpatch {
# url = baseUrl + "0002-Disable-saving-restrictions.patch";
# sha256 = "sha256-YarWT2rDNoOpLt0jGuT5BAe662GG9TMWF/F7KGa3I0E=";
# })
# (super.fetchpatch {
# url = baseUrl + "0003-Disable-invite-peeking-restrictions.patch";
# sha256 = "sha256-8mJD6LOjz11yfAdY4QPK/AUz9o5W3XdupXxy7kRrbC8=";
# })
# (super.fetchpatch {
# url = baseUrl + "0004-Disable-accounts-limit.patch";
# sha256 = "sha256-PZWCFdGE/TTJ1auG1JXNpnTUko2rCWla6dYKaQNzreg=";
# })
# (super.fetchpatch {
# url = baseUrl + "0005-Option-to-disable-stories.patch";
# sha256 = "sha256-aSAjyFiOg8JLgYA3voijVvkGIgK93kNMx40vqHsvW8Y=";
# })
# ];
# });
# })
(_self: super: {
telegram-desktop = super.telegram-desktop.override {
unwrapped = super.telegram-desktop.unwrapped.overrideAttrs (old: {
patches = (old.patches or [ ]) ++ [
./telegram/0001-Disable-sponsored-messages.patch
./telegram/0002-Disable-saving-restrictions.patch
./telegram/0003-Disable-invite-peeking-restrictions.patch
./telegram/0004-Disable-accounts-limit.patch
];
});
};
})
];
}
16 changes: 16 additions & 0 deletions modules/telegram/0001-Disable-sponsored-messages.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/Telegram/SourceFiles/data/components/sponsored_messages.cpp b/Telegram/SourceFiles/data/components/sponsored_messages.cpp
index 61e36d1c5..803905047 100644
--- a/Telegram/SourceFiles/data/components/sponsored_messages.cpp
+++ b/Telegram/SourceFiles/data/components/sponsored_messages.cpp
@@ -198,11 +198,6 @@ void SponsoredMessages::inject(
}

bool SponsoredMessages::canHaveFor(not_null<History*> history) const {
- if (history->peer->isChannel()) {
- return true;
- } else if (const auto user = history->peer->asUser()) {
- return user->isBot();
- }
return false;
}

214 changes: 214 additions & 0 deletions modules/telegram/0002-Disable-saving-restrictions.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
diff --git a/Telegram/SourceFiles/data/data_story.cpp b/Telegram/SourceFiles/data/data_story.cpp
index 9adcad015..9750d5a4b 100644
--- a/Telegram/SourceFiles/data/data_story.cpp
+++ b/Telegram/SourceFiles/data/data_story.cpp
@@ -390,12 +390,11 @@ bool Story::out() const {
}

bool Story::canDownloadIfPremium() const {
- return !forbidsForward() || _peer->isSelf();
+ return true;
}

bool Story::canDownloadChecked() const {
- return _peer->isSelf()
- || (canDownloadIfPremium() && _peer->session().premium());
+ return true;
}

bool Story::canShare() const {
diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp
index 2753b0dc0..36b870836 100644
--- a/Telegram/SourceFiles/history/history_inner_widget.cpp
+++ b/Telegram/SourceFiles/history/history_inner_widget.cpp
@@ -600,14 +600,7 @@ void HistoryInner::setupSwipeReply() {
}

bool HistoryInner::hasSelectRestriction() const {
- if (!_sharingDisallowed.current()) {
- return false;
- } else if (const auto chat = _peer->asChat()) {
- return !chat->canDeleteMessages();
- } else if (const auto channel = _peer->asChannel()) {
- return !channel->canDeleteMessages();
- }
- return true;
+ return false;
}

void HistoryInner::messagesReceived(
@@ -2979,12 +2972,12 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
}

bool HistoryInner::hasCopyRestriction(HistoryItem *item) const {
- return !_peer->allowsForwarding() || (item && item->forbidsForward());
+ return false;
}

bool HistoryInner::hasCopyMediaRestriction(
not_null<HistoryItem*> item) const {
- return hasCopyRestriction(item) || item->forbidsSaving();
+ return false;
}

bool HistoryInner::showCopyRestriction(HistoryItem *item) {
@@ -3008,14 +3001,6 @@ bool HistoryInner::showCopyMediaRestriction(not_null<HistoryItem*> item) {
}

bool HistoryInner::hasCopyRestrictionForSelected() const {
- if (hasCopyRestriction()) {
- return true;
- }
- for (const auto &[item, selection] : _selected) {
- if (item && item->forbidsForward()) {
- return true;
- }
- }
return false;
}

diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp
index c8f21a423..bc56ffac4 100644
--- a/Telegram/SourceFiles/history/history_item.cpp
+++ b/Telegram/SourceFiles/history/history_item.cpp
@@ -2284,11 +2284,6 @@ bool HistoryItem::forbidsForward() const {
}

bool HistoryItem::forbidsSaving() const {
- if (forbidsForward()) {
- return true;
- } else if (const auto invoice = _media ? _media->invoice() : nullptr) {
- return HasExtendedMedia(*invoice);
- }
return false;
}

diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp
index 1a67af4ec..094493b90 100644
--- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp
+++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp
@@ -1554,13 +1554,11 @@ bool ListWidget::isEmpty() const {
}

bool ListWidget::hasCopyRestriction(HistoryItem *item) const {
- return _delegate->listCopyRestrictionType(item)
- != CopyRestrictionType::None;
+ return false;
}

bool ListWidget::hasCopyMediaRestriction(not_null<HistoryItem*> item) const {
- return _delegate->listCopyMediaRestrictionType(item)
- != CopyRestrictionType::None;
+ return false;
}

bool ListWidget::showCopyRestriction(HistoryItem *item) {
@@ -1586,21 +1584,6 @@ bool ListWidget::showCopyMediaRestriction(not_null<HistoryItem*> item) {
}

bool ListWidget::hasCopyRestrictionForSelected() const {
- if (hasCopyRestriction()) {
- return true;
- }
- if (_selected.empty()) {
- if (_selectedTextItem && _selectedTextItem->forbidsForward()) {
- return true;
- }
- }
- for (const auto &[itemId, selection] : _selected) {
- if (const auto item = session().data().message(itemId)) {
- if (item->forbidsForward()) {
- return true;
- }
- }
- }
return false;
}

@@ -1619,8 +1602,7 @@ bool ListWidget::showCopyRestrictionForSelected() {
}

bool ListWidget::hasSelectRestriction() const {
- return _delegate->listSelectRestrictionType()
- != CopyRestrictionType::None;
+ return false;
}

Element *ListWidget::lookupItemByY(int y) const {
diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp
index 93c0e1ac2..87d6c83e0 100644
--- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp
+++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp
@@ -1226,15 +1226,14 @@ void TopBarWidget::updateMembersShowArea() {
}

bool TopBarWidget::showSelectedState() const {
- return (_selectedCount > 0)
- && (_canDelete || _canForward || _canSendNow);
+ return _selectedCount > 0;
}

void TopBarWidget::showSelected(SelectedState state) {
auto canDelete = (state.count > 0 && state.count == state.canDeleteCount);
auto canForward = (state.count > 0 && state.count == state.canForwardCount);
auto canSendNow = (state.count > 0 && state.count == state.canSendNowCount);
- auto count = (!canDelete && !canForward && !canSendNow) ? 0 : state.count;
+ auto count = state.count;
if (_selectedCount == count
&& _canDelete == canDelete
&& _canForward == canForward
diff --git a/Telegram/SourceFiles/info/media/info_media_provider.cpp b/Telegram/SourceFiles/info/media/info_media_provider.cpp
index 2fc69733e..2e830b73e 100644
--- a/Telegram/SourceFiles/info/media/info_media_provider.cpp
+++ b/Telegram/SourceFiles/info/media/info_media_provider.cpp
@@ -88,14 +88,7 @@ Type Provider::type() {
}

bool Provider::hasSelectRestriction() {
- if (_peer->allowsForwarding()) {
- return false;
- } else if (const auto chat = _peer->asChat()) {
- return !chat->canDeleteMessages();
- } else if (const auto channel = _peer->asChannel()) {
- return !channel->canDeleteMessages();
- }
- return true;
+ return false;
}

rpl::producer<bool> Provider::hasSelectRestrictionChanges() {
diff --git a/Telegram/SourceFiles/info/stories/info_stories_provider.cpp b/Telegram/SourceFiles/info/stories/info_stories_provider.cpp
index 6c9a7dabb..76906bf22 100644
--- a/Telegram/SourceFiles/info/stories/info_stories_provider.cpp
+++ b/Telegram/SourceFiles/info/stories/info_stories_provider.cpp
@@ -75,10 +75,7 @@ Type Provider::type() {
}

bool Provider::hasSelectRestriction() {
- if (const auto channel = _peer->asChannel()) {
- return !channel->canEditStories() && !channel->canDeleteStories();
- }
- return !_peer->isSelf();
+ return false;
}

rpl::producer<bool> Provider::hasSelectRestrictionChanges() {
diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp
index 921c39313..348995542 100644
--- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp
+++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp
@@ -1102,13 +1102,7 @@ QSize OverlayWidget::flipSizeByRotation(QSize size) const {
}

bool OverlayWidget::hasCopyMediaRestriction(bool skipPremiumCheck) const {
- if (const auto story = _stories ? _stories->story() : nullptr) {
- return skipPremiumCheck
- ? !story->canDownloadIfPremium()
- : !story->canDownloadChecked();
- }
- return (_history && !_history->peer->allowsForwarding())
- || (_message && _message->forbidsSaving());
+ return false;
}

bool OverlayWidget::showCopyMediaRestriction(bool skipPRemiumCheck) {
13 changes: 13 additions & 0 deletions modules/telegram/0003-Disable-invite-peeking-restrictions.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp
index 157a16b39..8d998a1da 100644
--- a/Telegram/SourceFiles/data/data_channel.cpp
+++ b/Telegram/SourceFiles/data/data_channel.cpp
@@ -892,7 +892,7 @@ void ChannelData::clearInvitePeek() {
}

TimeId ChannelData::invitePeekExpires() const {
- return _invitePeek ? _invitePeek->expires : 0;
+ return 0;
}

QString ChannelData::invitePeekHash() const {
15 changes: 15 additions & 0 deletions modules/telegram/0004-Disable-accounts-limit.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/Telegram/SourceFiles/main/main_domain.h b/Telegram/SourceFiles/main/main_domain.h
index 2e69222b9..b3e08fd66 100644
--- a/Telegram/SourceFiles/main/main_domain.h
+++ b/Telegram/SourceFiles/main/main_domain.h
@@ -31,8 +31,8 @@ public:
std::unique_ptr<Account> account;
};

- static constexpr auto kMaxAccounts = 3;
- static constexpr auto kPremiumMaxAccounts = 6;
+ static constexpr auto kMaxAccounts = 255;
+ static constexpr auto kPremiumMaxAccounts = 255;

explicit Domain(const QString &dataName);
~Domain();

0 comments on commit 63f8f17

Please sign in to comment.