mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Hide login code with a spoiler in chats list.
This commit is contained in:
parent
11906297d8
commit
864959aee0
11 changed files with 61 additions and 4 deletions
|
@ -556,6 +556,11 @@ FnMut<void()> Instance::addAsyncWaiter() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Instance::isSharingScreen() const {
|
||||||
|
return (_currentCall && _currentCall->isSharingScreen())
|
||||||
|
|| (_currentGroupCall && _currentGroupCall->isSharingScreen());
|
||||||
|
}
|
||||||
|
|
||||||
bool Instance::isQuitPrevent() {
|
bool Instance::isQuitPrevent() {
|
||||||
if (!_currentCall || _currentCall->isIncomingWaiting()) {
|
if (!_currentCall || _currentCall->isIncomingWaiting()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -105,6 +105,7 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] FnMut<void()> addAsyncWaiter();
|
[[nodiscard]] FnMut<void()> addAsyncWaiter();
|
||||||
|
|
||||||
|
[[nodiscard]] bool isSharingScreen() const;
|
||||||
[[nodiscard]] bool isQuitPrevent();
|
[[nodiscard]] bool isQuitPrevent();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1573,6 +1573,10 @@ QPoint Application::getPointForCallPanelCenter() const {
|
||||||
return QGuiApplication::primaryScreen()->geometry().center();
|
return QGuiApplication::primaryScreen()->geometry().center();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Application::isSharingScreen() const {
|
||||||
|
return _calls->isSharingScreen();
|
||||||
|
}
|
||||||
|
|
||||||
// macOS Qt bug workaround, sometimes no leaveEvent() gets to the nested widgets.
|
// macOS Qt bug workaround, sometimes no leaveEvent() gets to the nested widgets.
|
||||||
void Application::registerLeaveSubscription(not_null<QWidget*> widget) {
|
void Application::registerLeaveSubscription(not_null<QWidget*> widget) {
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
|
|
|
@ -195,6 +195,7 @@ public:
|
||||||
bool hideMediaView();
|
bool hideMediaView();
|
||||||
|
|
||||||
[[nodiscard]] QPoint getPointForCallPanelCenter() const;
|
[[nodiscard]] QPoint getPointForCallPanelCenter() const;
|
||||||
|
[[nodiscard]] bool isSharingScreen() const;
|
||||||
|
|
||||||
void startSettingsAndBackground();
|
void startSettingsAndBackground();
|
||||||
[[nodiscard]] Settings &settings();
|
[[nodiscard]] Settings &settings();
|
||||||
|
|
|
@ -157,6 +157,7 @@ void MessageView::prepare(
|
||||||
}
|
}
|
||||||
options.existing = &_imagesCache;
|
options.existing = &_imagesCache;
|
||||||
options.ignoreTopic = true;
|
options.ignoreTopic = true;
|
||||||
|
options.spoilerLoginCode = true;
|
||||||
auto preview = item->toPreview(options);
|
auto preview = item->toPreview(options);
|
||||||
const auto hasImages = !preview.images.empty();
|
const auto hasImages = !preview.images.empty();
|
||||||
const auto history = item->history();
|
const auto history = item->history();
|
||||||
|
|
|
@ -80,6 +80,26 @@ constexpr auto kPinnedMessageTextLimit = 16;
|
||||||
|
|
||||||
using ItemPreview = HistoryView::ItemPreview;
|
using ItemPreview = HistoryView::ItemPreview;
|
||||||
|
|
||||||
|
[[nodiscard]] TextWithEntities SpoilerLoginCode(TextWithEntities text) {
|
||||||
|
const auto r = QRegularExpression(u"([\\d\\-]{5,7})"_q);
|
||||||
|
const auto m = r.match(text.text);
|
||||||
|
if (!m.hasMatch()) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
const auto codeStart = m.capturedStart(1);
|
||||||
|
const auto codeLength = m.capturedLength(1);
|
||||||
|
auto i = text.entities.begin();
|
||||||
|
const auto e = text.entities.end();
|
||||||
|
while (i != e && i->offset() < codeStart) {
|
||||||
|
if (i->offset() + i->length() > codeStart) {
|
||||||
|
return text; // Entities should not intersect code.
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
text.entities.insert(i, { EntityType::Spoiler, codeStart, codeLength });
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool HasNotEmojiAndSpaces(const QString &text) {
|
[[nodiscard]] bool HasNotEmojiAndSpaces(const QString &text) {
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -2770,8 +2790,9 @@ bool HistoryItem::isEmpty() const {
|
||||||
&& !Has<HistoryMessageLogEntryOriginal>();
|
&& !Has<HistoryMessageLogEntryOriginal>();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextWithEntities HistoryItem::notificationText() const {
|
TextWithEntities HistoryItem::notificationText(
|
||||||
const auto result = [&] {
|
NotificationTextOptions options) const {
|
||||||
|
auto result = [&] {
|
||||||
if (_media && !isService()) {
|
if (_media && !isService()) {
|
||||||
return _media->notificationText();
|
return _media->notificationText();
|
||||||
} else if (!emptyText()) {
|
} else if (!emptyText()) {
|
||||||
|
@ -2779,6 +2800,11 @@ TextWithEntities HistoryItem::notificationText() const {
|
||||||
}
|
}
|
||||||
return TextWithEntities();
|
return TextWithEntities();
|
||||||
}();
|
}();
|
||||||
|
if (options.spoilerLoginCode
|
||||||
|
&& !out()
|
||||||
|
&& history()->peer->isNotificationsUser()) {
|
||||||
|
result = SpoilerLoginCode(std::move(result));
|
||||||
|
}
|
||||||
if (result.text.size() <= kNotificationTextLimit) {
|
if (result.text.size() <= kNotificationTextLimit) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -2808,6 +2834,11 @@ ItemPreview HistoryItem::toPreview(ToPreviewOptions options) const {
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}();
|
}();
|
||||||
|
if (options.spoilerLoginCode
|
||||||
|
&& !out()
|
||||||
|
&& history()->peer->isNotificationsUser()) {
|
||||||
|
result.text = SpoilerLoginCode(std::move(result.text));
|
||||||
|
}
|
||||||
const auto fromSender = [](not_null<PeerData*> sender) {
|
const auto fromSender = [](not_null<PeerData*> sender) {
|
||||||
return sender->isSelf()
|
return sender->isSelf()
|
||||||
? tr::lng_from_you(tr::now)
|
? tr::lng_from_you(tr::now)
|
||||||
|
|
|
@ -82,6 +82,7 @@ class Element;
|
||||||
class Message;
|
class Message;
|
||||||
class Service;
|
class Service;
|
||||||
class ServiceMessagePainter;
|
class ServiceMessagePainter;
|
||||||
|
struct NotificationTextOptions;
|
||||||
} // namespace HistoryView
|
} // namespace HistoryView
|
||||||
|
|
||||||
class HistoryItem final : public RuntimeComposer<HistoryItem> {
|
class HistoryItem final : public RuntimeComposer<HistoryItem> {
|
||||||
|
@ -355,8 +356,12 @@ public:
|
||||||
void indexAsNewItem();
|
void indexAsNewItem();
|
||||||
void removeFromSharedMediaIndex();
|
void removeFromSharedMediaIndex();
|
||||||
|
|
||||||
|
struct NotificationTextOptions {
|
||||||
|
bool spoilerLoginCode = false;
|
||||||
|
};
|
||||||
[[nodiscard]] QString notificationHeader() const;
|
[[nodiscard]] QString notificationHeader() const;
|
||||||
[[nodiscard]] TextWithEntities notificationText() const;
|
[[nodiscard]] TextWithEntities notificationText(
|
||||||
|
NotificationTextOptions options = {}) const;
|
||||||
|
|
||||||
using ToPreviewOptions = HistoryView::ToPreviewOptions;
|
using ToPreviewOptions = HistoryView::ToPreviewOptions;
|
||||||
using ItemPreview = HistoryView::ItemPreview;
|
using ItemPreview = HistoryView::ItemPreview;
|
||||||
|
|
|
@ -37,6 +37,7 @@ struct ToPreviewOptions {
|
||||||
bool generateImages = true;
|
bool generateImages = true;
|
||||||
bool ignoreGroup = false;
|
bool ignoreGroup = false;
|
||||||
bool ignoreTopic = true;
|
bool ignoreTopic = true;
|
||||||
|
bool spoilerLoginCode = false;
|
||||||
bool translated = false;
|
bool translated = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -856,6 +856,10 @@ Manager::DisplayOptions Manager::getNotificationOptions(
|
||||||
&& (!topic || !Data::CanSendTexts(topic)))
|
&& (!topic || !Data::CanSendTexts(topic)))
|
||||||
|| peer->isBroadcast()
|
|| peer->isBroadcast()
|
||||||
|| (peer->slowmodeSecondsLeft() > 0);
|
|| (peer->slowmodeSecondsLeft() > 0);
|
||||||
|
result.spoilerLoginCode = item
|
||||||
|
&& !item->out()
|
||||||
|
&& peer->isNotificationsUser()
|
||||||
|
&& Core::App().isSharingScreen();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1167,7 +1171,9 @@ void NativeManager::doShowNotification(NotificationFields &&fields) {
|
||||||
? tr::lng_forward_messages(tr::now, lt_count, fields.forwardedCount)
|
? tr::lng_forward_messages(tr::now, lt_count, fields.forwardedCount)
|
||||||
: item->groupId()
|
: item->groupId()
|
||||||
? tr::lng_in_dlg_album(tr::now)
|
? tr::lng_in_dlg_album(tr::now)
|
||||||
: TextWithPermanentSpoiler(item->notificationText());
|
: TextWithPermanentSpoiler(item->notificationText({
|
||||||
|
.spoilerLoginCode = options.spoilerLoginCode,
|
||||||
|
}));
|
||||||
|
|
||||||
// #TODO optimize
|
// #TODO optimize
|
||||||
auto userpicView = item->history()->peer->createUserpicView();
|
auto userpicView = item->history()->peer->createUserpicView();
|
||||||
|
|
|
@ -316,6 +316,7 @@ public:
|
||||||
bool hideMessageText = false;
|
bool hideMessageText = false;
|
||||||
bool hideMarkAsRead = false;
|
bool hideMarkAsRead = false;
|
||||||
bool hideReplyButton = false;
|
bool hideReplyButton = false;
|
||||||
|
bool spoilerLoginCode = false;
|
||||||
};
|
};
|
||||||
[[nodiscard]] DisplayOptions getNotificationOptions(
|
[[nodiscard]] DisplayOptions getNotificationOptions(
|
||||||
HistoryItem *item,
|
HistoryItem *item,
|
||||||
|
|
|
@ -932,6 +932,7 @@ void Notification::updateNotifyDisplay() {
|
||||||
? _item->toPreview({
|
? _item->toPreview({
|
||||||
.hideSender = reminder,
|
.hideSender = reminder,
|
||||||
.generateImages = false,
|
.generateImages = false,
|
||||||
|
.spoilerLoginCode = options.spoilerLoginCode,
|
||||||
}).text
|
}).text
|
||||||
: ((!_author.isEmpty()
|
: ((!_author.isEmpty()
|
||||||
? Ui::Text::PlainLink(_author)
|
? Ui::Text::PlainLink(_author)
|
||||||
|
|
Loading…
Add table
Reference in a new issue