mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Added ability to edit media in scheduled messages.
This commit is contained in:
parent
b02b690747
commit
5c097887ef
9 changed files with 73 additions and 19 deletions
|
@ -187,9 +187,10 @@ void EditMessageWithUploadedPhoto(
|
|||
mtpRequestId EditCaption(
|
||||
not_null<HistoryItem*> item,
|
||||
const TextWithEntities &caption,
|
||||
SendOptions options,
|
||||
Fn<void(const MTPUpdates &)> done,
|
||||
Fn<void(const RPCError &)> fail) {
|
||||
return EditMessage(item, caption, SendOptions(), done, fail);
|
||||
return EditMessage(item, caption, options, done, fail);
|
||||
}
|
||||
|
||||
mtpRequestId EditTextMessage(
|
||||
|
|
|
@ -38,6 +38,7 @@ void EditMessageWithUploadedPhoto(
|
|||
mtpRequestId EditCaption(
|
||||
not_null<HistoryItem*> item,
|
||||
const TextWithEntities &caption,
|
||||
SendOptions options,
|
||||
Fn<void(const MTPUpdates &)> done,
|
||||
Fn<void(const RPCError &)> fail);
|
||||
|
||||
|
|
|
@ -400,6 +400,8 @@ void SendConfirmedFile(
|
|||
}
|
||||
if (file->to.options.scheduled) {
|
||||
flags |= MTPDmessage::Flag::f_from_scheduled;
|
||||
// Scheduled messages have no the 'edited' badge.
|
||||
flags |= MTPDmessage::Flag::f_edit_hide;
|
||||
} else {
|
||||
clientFlags |= MTPDmessage_ClientFlag::f_local_history_entry;
|
||||
}
|
||||
|
|
|
@ -936,12 +936,18 @@ void EditCaptionBox::save() {
|
|||
TextUtilities::ConvertTextTagsToEntities(textWithTags.tags)
|
||||
};
|
||||
|
||||
auto options = Api::SendOptions();
|
||||
options.scheduled = item->isScheduled() ? item->date() : 0;
|
||||
|
||||
if (!_preparedList.files.empty()) {
|
||||
auto action = Api::SendAction(item->history());
|
||||
action.options = options;
|
||||
|
||||
_controller->session().api().editMedia(
|
||||
std::move(_preparedList),
|
||||
(!_asFile && _photo) ? SendMediaType::Photo : SendMediaType::File,
|
||||
_field->getTextWithAppliedMarkdown(),
|
||||
Api::SendAction(item->history()),
|
||||
action,
|
||||
item->fullId().msg);
|
||||
closeBox();
|
||||
return;
|
||||
|
@ -977,7 +983,7 @@ void EditCaptionBox::save() {
|
|||
}
|
||||
});
|
||||
|
||||
_saveRequestId = Api::EditCaption(item, sending, done, fail);
|
||||
_saveRequestId = Api::EditCaption(item, sending, options, done, fail);
|
||||
}
|
||||
|
||||
void EditCaptionBox::setName(QString nameString, qint64 size) {
|
||||
|
|
|
@ -71,7 +71,7 @@ void Groups::refreshMessage(
|
|||
unregisterMessage(item);
|
||||
return;
|
||||
}
|
||||
if (!IsServerMsgId(item->id)) {
|
||||
if (!IsServerMsgId(item->id) && !item->isScheduled()) {
|
||||
return;
|
||||
}
|
||||
const auto groupId = item->groupId();
|
||||
|
|
|
@ -774,11 +774,12 @@ bool HistoryMessage::allowsForward() const {
|
|||
}
|
||||
|
||||
bool HistoryMessage::allowsSendNow() const {
|
||||
return isScheduled() && !isSending() && !hasFailed();
|
||||
return isScheduled() && !isSending() && !hasFailed() && !isEditingMedia();
|
||||
}
|
||||
|
||||
bool HistoryMessage::isTooOldForEdit(TimeId now) const {
|
||||
return !_history->peer->canEditMessagesIndefinitely()
|
||||
&& !isScheduled()
|
||||
&& (now - date() >= _history->session().serverConfig().editTimeLimit);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/history_view_context_menu.h"
|
||||
|
||||
#include "api/api_editing.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "history/view/history_view_list_widget.h"
|
||||
#include "history/view/history_view_cursor_state.h"
|
||||
#include "history/history.h"
|
||||
|
@ -23,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/ui_utility.h"
|
||||
#include "chat_helpers/message_field.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "boxes/edit_caption_box.h"
|
||||
#include "boxes/sticker_set_box.h"
|
||||
#include "data/data_photo.h"
|
||||
#include "data/data_photo_media.h"
|
||||
|
@ -74,6 +76,23 @@ MsgId ItemIdAcrossData(not_null<HistoryItem*> item) {
|
|||
return session->data().scheduledMessages().lookupId(item);
|
||||
}
|
||||
|
||||
bool HasEditScheduledMessageAction(const ContextMenuRequest &request) {
|
||||
const auto item = request.item;
|
||||
if (!item
|
||||
|| item->isSending()
|
||||
|| item->isEditingMedia()
|
||||
|| !request.selectedItems.empty()) {
|
||||
return false;
|
||||
}
|
||||
const auto peer = item->history()->peer;
|
||||
if (const auto channel = peer->asChannel()) {
|
||||
if (!channel->canEditMessages()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SavePhotoToFile(not_null<PhotoData*> photo) {
|
||||
const auto media = photo->activeMediaView();
|
||||
if (photo->isNull() || !media || !media->loaded()) {
|
||||
|
@ -397,16 +416,10 @@ bool AddSendNowMessageAction(
|
|||
bool AddRescheduleMessageAction(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
const ContextMenuRequest &request) {
|
||||
const auto item = request.item;
|
||||
if (!item || item->isSending() || !request.selectedItems.empty()) {
|
||||
if (!HasEditScheduledMessageAction(request)) {
|
||||
return false;
|
||||
}
|
||||
const auto peer = item->history()->peer;
|
||||
if (const auto channel = peer->asChannel()) {
|
||||
if (!channel->canEditMessages()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const auto item = request.item;
|
||||
const auto owner = &item->history()->owner();
|
||||
const auto itemId = item->fullId();
|
||||
menu->addAction(tr::lng_context_reschedule(tr::now), [=] {
|
||||
|
@ -421,6 +434,7 @@ bool AddRescheduleMessageAction(
|
|||
Api::RescheduleMessage(item, options);
|
||||
};
|
||||
|
||||
const auto peer = item->history()->peer;
|
||||
const auto sendMenuType = !peer
|
||||
? SendMenuType::Disabled
|
||||
: peer->isSelf()
|
||||
|
@ -445,6 +459,33 @@ bool AddRescheduleMessageAction(
|
|||
return true;
|
||||
}
|
||||
|
||||
bool AddEditMessageAction(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
const ContextMenuRequest &request,
|
||||
not_null<ListWidget*> list) {
|
||||
if (!HasEditScheduledMessageAction(request)) {
|
||||
return false;
|
||||
}
|
||||
const auto item = request.item;
|
||||
if (!item->allowsEdit(base::unixtime::now())) {
|
||||
return false;
|
||||
}
|
||||
const auto owner = &item->history()->owner();
|
||||
const auto itemId = item->fullId();
|
||||
menu->addAction(tr::lng_context_edit_msg(tr::now), [=] {
|
||||
const auto item = owner->message(itemId);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
if (!item->media() || !item->media()->allowsEditCaption()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Ui::show(Box<EditCaptionBox>(App::wnd()->sessionController(), item));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
void AddSendNowAction(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
const ContextMenuRequest &request,
|
||||
|
@ -590,6 +631,7 @@ void AddMessageActions(
|
|||
not_null<Ui::PopupMenu*> menu,
|
||||
const ContextMenuRequest &request,
|
||||
not_null<ListWidget*> list) {
|
||||
AddEditMessageAction(menu, request, list);
|
||||
AddPostLinkAction(menu, request);
|
||||
AddForwardAction(menu, request, list);
|
||||
AddSendNowAction(menu, request, list);
|
||||
|
|
|
@ -706,16 +706,16 @@ void MainWidget::cancelUploadLayer(not_null<HistoryItem*> item) {
|
|||
session().uploader().pause(itemId);
|
||||
const auto stopUpload = [=] {
|
||||
Ui::hideLayer();
|
||||
if (const auto item = session().data().message(itemId)) {
|
||||
const auto history = item->history();
|
||||
if (!IsServerMsgId(itemId.msg)) {
|
||||
auto &data = session().data();
|
||||
if (const auto item = data.message(itemId)) {
|
||||
if (!item->isEditingMedia()) {
|
||||
item->destroy();
|
||||
history->requestChatListMessage();
|
||||
item->history()->requestChatListMessage();
|
||||
} else {
|
||||
item->returnSavedMedia();
|
||||
session().uploader().cancel(item->fullId());
|
||||
}
|
||||
session().data().sendHistoryChangeNotifications();
|
||||
data.sendHistoryChangeNotifications();
|
||||
}
|
||||
session().uploader().unpause();
|
||||
};
|
||||
|
|
|
@ -497,7 +497,8 @@ FileLoadTask::FileLoadTask(
|
|||
, _type(type)
|
||||
, _caption(caption)
|
||||
, _msgIdToEdit(msgIdToEdit) {
|
||||
Expects(_msgIdToEdit == 0 || IsServerMsgId(_msgIdToEdit));
|
||||
Expects(to.options.scheduled
|
||||
|| (_msgIdToEdit == 0 || IsServerMsgId(_msgIdToEdit)));
|
||||
}
|
||||
|
||||
FileLoadTask::FileLoadTask(
|
||||
|
|
Loading…
Add table
Reference in a new issue