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