mirror of https://github.com/procxx/kepka.git
Allow revoking only sent messages.
This commit is contained in:
parent
b972da059a
commit
2701e63406
|
@ -1391,7 +1391,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_delete_for_me_hint#one" = "This will delete it just for you.";
|
"lng_delete_for_me_hint#one" = "This will delete it just for you.";
|
||||||
"lng_delete_for_me_hint#other" = "This will delete them just for you.";
|
"lng_delete_for_me_hint#other" = "This will delete them just for you.";
|
||||||
"lng_delete_for_everyone_check" = "Delete for everyone";
|
"lng_delete_for_everyone_check" = "Delete for everyone";
|
||||||
"lng_delete_for_other_check" = "Delete for {user}";
|
"lng_delete_for_other_check" = "Also delete for {user}";
|
||||||
|
"lng_delete_for_other_my" = "Unsend my messages";
|
||||||
"lng_box_delete" = "Delete";
|
"lng_box_delete" = "Delete";
|
||||||
"lng_box_leave" = "Leave";
|
"lng_box_leave" = "Leave";
|
||||||
|
|
||||||
|
|
|
@ -455,8 +455,7 @@ DeleteMessagesBox::DeleteMessagesBox(
|
||||||
QWidget*,
|
QWidget*,
|
||||||
not_null<HistoryItem*> item,
|
not_null<HistoryItem*> item,
|
||||||
bool suggestModerateActions)
|
bool suggestModerateActions)
|
||||||
: _ids(1, item->fullId())
|
: _ids(1, item->fullId()) {
|
||||||
, _singleItem(true) {
|
|
||||||
if (suggestModerateActions) {
|
if (suggestModerateActions) {
|
||||||
_moderateBan = item->suggestBanReport();
|
_moderateBan = item->suggestBanReport();
|
||||||
_moderateDeleteAll = item->suggestDeleteAllReport();
|
_moderateDeleteAll = item->suggestDeleteAllReport();
|
||||||
|
@ -487,44 +486,23 @@ void DeleteMessagesBox::prepare() {
|
||||||
_deleteAll.create(this, lang(lng_delete_all_from), false, st::defaultBoxCheckbox);
|
_deleteAll.create(this, lang(lng_delete_all_from), false, st::defaultBoxCheckbox);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
text = _singleItem ? lang(lng_selected_delete_sure_this) : lng_selected_delete_sure(lt_count, _ids.size());
|
text = (_ids.size() == 1)
|
||||||
auto canDeleteAllForEveryone = true;
|
? lang(lng_selected_delete_sure_this)
|
||||||
auto now = unixtime();
|
: lng_selected_delete_sure(lt_count, _ids.size());
|
||||||
auto deleteForUser = (UserData*)nullptr;
|
if (const auto peer = checkFromSinglePeer()) {
|
||||||
auto peer = (PeerData*)nullptr;
|
auto count = int(_ids.size());
|
||||||
auto forEveryoneText = lang(lng_delete_for_everyone_check);
|
if (const auto revoke = revokeText(peer); !revoke.isEmpty()) {
|
||||||
for (const auto fullId : std::as_const(_ids)) {
|
_revoke.create(this, revoke, false, st::defaultBoxCheckbox);
|
||||||
if (const auto item = App::histItemById(fullId)) {
|
} else if (peer && peer->isChannel()) {
|
||||||
peer = item->history()->peer;
|
if (peer->isMegagroup()) {
|
||||||
if (!item->canDeleteForEveryone(now)) {
|
text += qsl("\n\n") + lng_delete_for_everyone_hint(lt_count, count);
|
||||||
canDeleteAllForEveryone = false;
|
|
||||||
break;
|
|
||||||
} else if (auto user = item->history()->peer->asUser()) {
|
|
||||||
if (!deleteForUser || deleteForUser == user) {
|
|
||||||
deleteForUser = user;
|
|
||||||
forEveryoneText = lng_delete_for_other_check(
|
|
||||||
lt_user,
|
|
||||||
user->firstName);
|
|
||||||
} else {
|
|
||||||
forEveryoneText = lang(lng_delete_for_everyone_check);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else if (peer->isChat()) {
|
||||||
canDeleteAllForEveryone = false;
|
text += qsl("\n\n") + lng_delete_for_me_chat_hint(lt_count, count);
|
||||||
|
} else if (!peer->isSelf()) {
|
||||||
|
text += qsl("\n\n") + lng_delete_for_me_hint(lt_count, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto count = int(_ids.size());
|
|
||||||
if (canDeleteAllForEveryone) {
|
|
||||||
_forEveryone.create(this, forEveryoneText, false, st::defaultBoxCheckbox);
|
|
||||||
} else if (peer && peer->isChannel()) {
|
|
||||||
if (peer->isMegagroup()) {
|
|
||||||
text += qsl("\n\n") + lng_delete_for_everyone_hint(lt_count, count);
|
|
||||||
}
|
|
||||||
} else if (peer->isChat()) {
|
|
||||||
text += qsl("\n\n") + lng_delete_for_me_chat_hint(lt_count, count);
|
|
||||||
} else if (!peer->isSelf()) {
|
|
||||||
text += qsl("\n\n") + lng_delete_for_me_hint(lt_count, count);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_text.create(this, text, Ui::FlatLabel::InitType::Simple, st::boxLabel);
|
_text.create(this, text, Ui::FlatLabel::InitType::Simple, st::boxLabel);
|
||||||
|
|
||||||
|
@ -541,12 +519,65 @@ void DeleteMessagesBox::prepare() {
|
||||||
if (_deleteAll) {
|
if (_deleteAll) {
|
||||||
fullHeight += st::boxLittleSkip + _deleteAll->heightNoMargins();
|
fullHeight += st::boxLittleSkip + _deleteAll->heightNoMargins();
|
||||||
}
|
}
|
||||||
} else if (_forEveryone) {
|
} else if (_revoke) {
|
||||||
fullHeight += st::boxMediumSkip + _forEveryone->heightNoMargins();
|
fullHeight += st::boxMediumSkip + _revoke->heightNoMargins();
|
||||||
}
|
}
|
||||||
setDimensions(st::boxWidth, fullHeight);
|
setDimensions(st::boxWidth, fullHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PeerData *DeleteMessagesBox::checkFromSinglePeer() const {
|
||||||
|
auto result = (PeerData*)nullptr;
|
||||||
|
for (const auto fullId : std::as_const(_ids)) {
|
||||||
|
if (const auto item = App::histItemById(fullId)) {
|
||||||
|
const auto peer = item->history()->peer;
|
||||||
|
if (!result) {
|
||||||
|
result = peer;
|
||||||
|
} else if (result != peer) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeleteMessagesBox::revokeText(not_null<PeerData*> peer) const {
|
||||||
|
const auto items = ranges::view::all(
|
||||||
|
_ids
|
||||||
|
) | ranges::view::transform([](FullMsgId id) {
|
||||||
|
return App::histItemById(id);
|
||||||
|
}) | ranges::view::filter([](HistoryItem *item) {
|
||||||
|
return (item != nullptr);
|
||||||
|
}) | ranges::to_vector;
|
||||||
|
if (items.size() != _ids.size()) {
|
||||||
|
// We don't have information about all messages.
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto now = unixtime();
|
||||||
|
const auto cannotRevoke = [&](HistoryItem *item) {
|
||||||
|
return !item->canDeleteForEveryone(now);
|
||||||
|
};
|
||||||
|
const auto canRevokeAll = ranges::find_if(
|
||||||
|
items,
|
||||||
|
cannotRevoke
|
||||||
|
) == end(items);
|
||||||
|
auto outgoing = items | ranges::view::filter(&HistoryItem::out);
|
||||||
|
const auto canRevokeAllOutgoing = canRevokeAll ? true : ranges::find_if(
|
||||||
|
outgoing,
|
||||||
|
cannotRevoke
|
||||||
|
) == end(outgoing);
|
||||||
|
|
||||||
|
return canRevokeAll
|
||||||
|
? (peer->isUser()
|
||||||
|
? lng_delete_for_other_check(
|
||||||
|
lt_user,
|
||||||
|
peer->asUser()->firstName)
|
||||||
|
: lang(lng_delete_for_everyone_check))
|
||||||
|
: (canRevokeAllOutgoing && (begin(outgoing) != end(outgoing)))
|
||||||
|
? lang(lng_delete_for_other_my)
|
||||||
|
: QString();
|
||||||
|
}
|
||||||
|
|
||||||
void DeleteMessagesBox::resizeEvent(QResizeEvent *e) {
|
void DeleteMessagesBox::resizeEvent(QResizeEvent *e) {
|
||||||
BoxContent::resizeEvent(e);
|
BoxContent::resizeEvent(e);
|
||||||
|
|
||||||
|
@ -562,10 +593,10 @@ void DeleteMessagesBox::resizeEvent(QResizeEvent *e) {
|
||||||
if (_deleteAll) {
|
if (_deleteAll) {
|
||||||
_deleteAll->moveToLeft(st::boxPadding.left(), top);
|
_deleteAll->moveToLeft(st::boxPadding.left(), top);
|
||||||
}
|
}
|
||||||
} else if (_forEveryone) {
|
} else if (_revoke) {
|
||||||
auto availableWidth = width() - 2 * st::boxPadding.left();
|
const auto availableWidth = width() - 2 * st::boxPadding.left();
|
||||||
_forEveryone->resizeToNaturalWidth(availableWidth);
|
_revoke->resizeToNaturalWidth(availableWidth);
|
||||||
_forEveryone->moveToLeft(st::boxPadding.left(), _text->bottomNoMargins() + st::boxMediumSkip);
|
_revoke->moveToLeft(st::boxPadding.left(), _text->bottomNoMargins() + st::boxMediumSkip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,7 +652,7 @@ void DeleteMessagesBox::deleteAndClear() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto revoke = _forEveryone ? _forEveryone->checked() : false;
|
const auto revoke = _revoke ? _revoke->checked() : false;
|
||||||
for (const auto &[peer, ids] : idsByPeer) {
|
for (const auto &[peer, ids] : idsByPeer) {
|
||||||
App::main()->deleteMessages(peer, ids, revoke);
|
App::main()->deleteMessages(peer, ids, revoke);
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,16 +164,17 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void deleteAndClear();
|
void deleteAndClear();
|
||||||
|
PeerData *checkFromSinglePeer() const;
|
||||||
|
QString revokeText(not_null<PeerData*> peer) const;
|
||||||
|
|
||||||
const MessageIdsList _ids;
|
const MessageIdsList _ids;
|
||||||
const bool _singleItem = false;
|
|
||||||
UserData *_moderateFrom = nullptr;
|
UserData *_moderateFrom = nullptr;
|
||||||
ChannelData *_moderateInChannel = nullptr;
|
ChannelData *_moderateInChannel = nullptr;
|
||||||
bool _moderateBan = false;
|
bool _moderateBan = false;
|
||||||
bool _moderateDeleteAll = false;
|
bool _moderateDeleteAll = false;
|
||||||
|
|
||||||
object_ptr<Ui::FlatLabel> _text = { nullptr };
|
object_ptr<Ui::FlatLabel> _text = { nullptr };
|
||||||
object_ptr<Ui::Checkbox> _forEveryone = { nullptr };
|
object_ptr<Ui::Checkbox> _revoke = { nullptr };
|
||||||
object_ptr<Ui::Checkbox> _banUser = { nullptr };
|
object_ptr<Ui::Checkbox> _banUser = { nullptr };
|
||||||
object_ptr<Ui::Checkbox> _reportSpam = { nullptr };
|
object_ptr<Ui::Checkbox> _reportSpam = { nullptr };
|
||||||
object_ptr<Ui::Checkbox> _deleteAll = { nullptr };
|
object_ptr<Ui::Checkbox> _deleteAll = { nullptr };
|
||||||
|
|
|
@ -835,13 +835,6 @@ void MainWidget::showSendPathsLayer() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::deleteLayer(FullMsgId itemId) {
|
|
||||||
if (const auto item = App::histItemById(itemId)) {
|
|
||||||
const auto suggestModerateActions = true;
|
|
||||||
Ui::show(Box<DeleteMessagesBox>(item, suggestModerateActions));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWidget::cancelUploadLayer(not_null<HistoryItem*> item) {
|
void MainWidget::cancelUploadLayer(not_null<HistoryItem*> item) {
|
||||||
const auto itemId = item->fullId();
|
const auto itemId = item->fullId();
|
||||||
session().uploader().pause(itemId);
|
session().uploader().pause(itemId);
|
||||||
|
|
|
@ -177,7 +177,6 @@ public:
|
||||||
|
|
||||||
void showForwardLayer(MessageIdsList &&items);
|
void showForwardLayer(MessageIdsList &&items);
|
||||||
void showSendPathsLayer();
|
void showSendPathsLayer();
|
||||||
void deleteLayer(FullMsgId itemId);
|
|
||||||
void cancelUploadLayer(not_null<HistoryItem*> item);
|
void cancelUploadLayer(not_null<HistoryItem*> item);
|
||||||
void shareUrlLayer(const QString &url, const QString &text);
|
void shareUrlLayer(const QString &url, const QString &text);
|
||||||
void inlineSwitchLayer(const QString &botAndQuery);
|
void inlineSwitchLayer(const QString &botAndQuery);
|
||||||
|
|
|
@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/image/image.h"
|
#include "ui/image/image.h"
|
||||||
#include "ui/text_options.h"
|
#include "ui/text_options.h"
|
||||||
|
#include "boxes/confirm_box.h"
|
||||||
#include "media/audio/media_audio.h"
|
#include "media/audio/media_audio.h"
|
||||||
#include "media/view/media_view_playback_controls.h"
|
#include "media/view/media_view_playback_controls.h"
|
||||||
#include "media/view/media_view_group_thumbs.h"
|
#include "media/view/media_view_group_thumbs.h"
|
||||||
|
@ -1227,8 +1228,9 @@ void OverlayWidget::onDelete() {
|
||||||
|
|
||||||
if (deletingPeerPhoto()) {
|
if (deletingPeerPhoto()) {
|
||||||
App::main()->deletePhotoLayer(_photo);
|
App::main()->deletePhotoLayer(_photo);
|
||||||
} else {
|
} else if (const auto item = App::histItemById(_msgid)) {
|
||||||
App::main()->deleteLayer(_msgid);
|
const auto suggestModerateActions = true;
|
||||||
|
Ui::show(Box<DeleteMessagesBox>(item, suggestModerateActions));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue