mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 05:07:10 +02:00
Show correct signature in send-as channel posts.
This commit is contained in:
parent
dc1df14a71
commit
f3dca6efb7
7 changed files with 60 additions and 109 deletions
|
@ -165,25 +165,15 @@ void SendExistingMedia(
|
|||
flags |= MessageFlag::HasReplyInfo;
|
||||
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to;
|
||||
}
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
const auto silentPost = ShouldSendSilent(peer, action.options);
|
||||
InnerFillMessagePostFlags(action.options, peer, flags);
|
||||
if (silentPost) {
|
||||
sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
|
||||
}
|
||||
const auto sendAs = action.options.sendAs;
|
||||
const auto messageFromId = sendAs
|
||||
? sendAs->id
|
||||
: anonymousPost
|
||||
? 0
|
||||
: session->userPeerId();
|
||||
if (sendAs) {
|
||||
sendFlags |= MTPmessages_SendMedia::Flag::f_send_as;
|
||||
}
|
||||
const auto messagePostAuthor = peer->isBroadcast()
|
||||
? session->user()->name()
|
||||
: QString();
|
||||
|
||||
auto caption = TextWithEntities{
|
||||
message.textWithTags.text,
|
||||
TextUtilities::ConvertTextTagsToEntities(message.textWithTags.tags)
|
||||
|
@ -219,11 +209,11 @@ void SendExistingMedia(
|
|||
history->addNewLocalMessage({
|
||||
.id = newId.msg,
|
||||
.flags = flags,
|
||||
.from = messageFromId,
|
||||
.from = NewMessageFromId(action),
|
||||
.replyTo = action.replyTo,
|
||||
.date = HistoryItem::NewMessageDate(action.options),
|
||||
.date = NewMessageDate(action.options),
|
||||
.shortcutId = action.options.shortcutId,
|
||||
.postAuthor = messagePostAuthor,
|
||||
.postAuthor = NewMessagePostAuthor(action),
|
||||
.effectId = action.options.effectId,
|
||||
}, media, caption);
|
||||
|
||||
|
@ -361,25 +351,15 @@ bool SendDice(MessageToSend &message) {
|
|||
flags |= MessageFlag::HasReplyInfo;
|
||||
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to;
|
||||
}
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
const auto silentPost = ShouldSendSilent(peer, action.options);
|
||||
InnerFillMessagePostFlags(action.options, peer, flags);
|
||||
if (silentPost) {
|
||||
sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
|
||||
}
|
||||
const auto sendAs = action.options.sendAs;
|
||||
const auto messageFromId = sendAs
|
||||
? sendAs->id
|
||||
: anonymousPost
|
||||
? 0
|
||||
: session->userPeerId();
|
||||
if (sendAs) {
|
||||
sendFlags |= MTPmessages_SendMedia::Flag::f_send_as;
|
||||
}
|
||||
const auto messagePostAuthor = peer->isBroadcast()
|
||||
? session->user()->name()
|
||||
: QString();
|
||||
|
||||
if (action.options.scheduled) {
|
||||
flags |= MessageFlag::IsOrWasScheduled;
|
||||
sendFlags |= MTPmessages_SendMedia::Flag::f_schedule_date;
|
||||
|
@ -401,11 +381,11 @@ bool SendDice(MessageToSend &message) {
|
|||
history->addNewLocalMessage({
|
||||
.id = newId.msg,
|
||||
.flags = flags,
|
||||
.from = messageFromId,
|
||||
.from = NewMessageFromId(action),
|
||||
.replyTo = action.replyTo,
|
||||
.date = HistoryItem::NewMessageDate(action.options),
|
||||
.date = NewMessageDate(action.options),
|
||||
.shortcutId = action.options.shortcutId,
|
||||
.postAuthor = messagePostAuthor,
|
||||
.postAuthor = NewMessagePostAuthor(action),
|
||||
.effectId = action.options.effectId,
|
||||
}, TextWithEntities(), MTP_messageMediaDice(
|
||||
MTP_int(0),
|
||||
|
@ -529,7 +509,6 @@ void SendConfirmedFile(
|
|||
if (file->to.replyTo) {
|
||||
flags |= MessageFlag::HasReplyInfo;
|
||||
}
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
FillMessagePostFlags(action, peer, flags);
|
||||
if (file->to.options.scheduled) {
|
||||
flags |= MessageFlag::IsOrWasScheduled;
|
||||
|
@ -551,16 +530,6 @@ void SendConfirmedFile(
|
|||
if (file->to.options.invertCaption) {
|
||||
flags |= MessageFlag::InvertMedia;
|
||||
}
|
||||
|
||||
const auto messageFromId = file->to.options.sendAs
|
||||
? file->to.options.sendAs->id
|
||||
: anonymousPost
|
||||
? PeerId()
|
||||
: session->userPeerId();
|
||||
const auto messagePostAuthor = peer->isBroadcast()
|
||||
? session->user()->name()
|
||||
: QString();
|
||||
|
||||
const auto media = MTPMessageMedia([&] {
|
||||
if (file->type == SendMediaType::Photo) {
|
||||
using Flag = MTPDmessageMediaPhoto::Flag;
|
||||
|
@ -626,11 +595,11 @@ void SendConfirmedFile(
|
|||
history->addNewLocalMessage({
|
||||
.id = newId.msg,
|
||||
.flags = flags,
|
||||
.from = messageFromId,
|
||||
.from = NewMessageFromId(action),
|
||||
.replyTo = file->to.replyTo,
|
||||
.date = HistoryItem::NewMessageDate(file->to.options),
|
||||
.date = NewMessageDate(file->to.options),
|
||||
.shortcutId = file->to.options.shortcutId,
|
||||
.postAuthor = messagePostAuthor,
|
||||
.postAuthor = NewMessagePostAuthor(action),
|
||||
.groupedId = groupId,
|
||||
.effectId = file->to.options.effectId,
|
||||
}, caption, media);
|
||||
|
|
|
@ -3283,7 +3283,6 @@ void ApiWrap::forwardMessages(
|
|||
histories.readInbox(history);
|
||||
}
|
||||
const auto sendAs = action.options.sendAs;
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
const auto silentPost = ShouldSendSilent(peer, action.options);
|
||||
|
||||
using SendFlag = MTPmessages_ForwardMessages::Flag;
|
||||
|
@ -3376,22 +3375,14 @@ void ApiWrap::forwardMessages(
|
|||
peer->id,
|
||||
_session->data().nextLocalMessageId());
|
||||
const auto self = _session->user();
|
||||
const auto messageFromId = sendAs
|
||||
? sendAs->id
|
||||
: anonymousPost
|
||||
? PeerId(0)
|
||||
: self->id;
|
||||
const auto messagePostAuthor = peer->isBroadcast()
|
||||
? self->name()
|
||||
: QString();
|
||||
history->addNewLocalMessage({
|
||||
.id = newId.msg,
|
||||
.flags = flags,
|
||||
.from = messageFromId,
|
||||
.from = NewMessageFromId(action),
|
||||
.replyTo = { .topicRootId = topMsgId },
|
||||
.date = HistoryItem::NewMessageDate(action.options),
|
||||
.date = NewMessageDate(action.options),
|
||||
.shortcutId = action.options.shortcutId,
|
||||
.postAuthor = messagePostAuthor,
|
||||
.postAuthor = NewMessagePostAuthor(action),
|
||||
|
||||
// forwarded messages don't have effects
|
||||
//.effectId = action.options.effectId,
|
||||
|
@ -3466,8 +3457,6 @@ void ApiWrap::sendSharedContact(
|
|||
const auto newId = FullMsgId(
|
||||
peer->id,
|
||||
_session->data().nextLocalMessageId());
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
|
||||
auto flags = NewMessageFlags(peer);
|
||||
if (action.replyTo) {
|
||||
flags |= MessageFlag::HasReplyInfo;
|
||||
|
@ -3479,22 +3468,14 @@ void ApiWrap::sendSharedContact(
|
|||
if (action.options.shortcutId) {
|
||||
flags |= MessageFlag::ShortcutMessage;
|
||||
}
|
||||
const auto messageFromId = action.options.sendAs
|
||||
? action.options.sendAs->id
|
||||
: anonymousPost
|
||||
? PeerId()
|
||||
: _session->userPeerId();
|
||||
const auto messagePostAuthor = peer->isBroadcast()
|
||||
? _session->user()->name()
|
||||
: QString();
|
||||
const auto item = history->addNewLocalMessage({
|
||||
.id = newId.msg,
|
||||
.flags = flags,
|
||||
.from = messageFromId,
|
||||
.from = NewMessageFromId(action),
|
||||
.replyTo = action.replyTo,
|
||||
.date = HistoryItem::NewMessageDate(action.options),
|
||||
.date = NewMessageDate(action.options),
|
||||
.shortcutId = action.options.shortcutId,
|
||||
.postAuthor = messagePostAuthor,
|
||||
.postAuthor = NewMessagePostAuthor(action),
|
||||
.effectId = action.options.effectId,
|
||||
}, TextWithEntities(), MTP_messageMediaContact(
|
||||
MTP_string(phone),
|
||||
|
@ -3780,7 +3761,6 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
|
|||
MTP_string(fields.url),
|
||||
MTP_int(page->pendingTill)));
|
||||
}
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
const auto silentPost = ShouldSendSilent(peer, action.options);
|
||||
FillMessagePostFlags(action, peer, flags);
|
||||
if ((exactWebPage && !ignoreWebPage && message.webPage.invert)
|
||||
|
@ -3808,18 +3788,10 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
|
|||
history->startSavingCloudDraft(draftTopicRootId);
|
||||
}
|
||||
const auto sendAs = action.options.sendAs;
|
||||
const auto messageFromId = sendAs
|
||||
? sendAs->id
|
||||
: anonymousPost
|
||||
? PeerId()
|
||||
: _session->userPeerId();
|
||||
if (sendAs) {
|
||||
sendFlags |= MTPmessages_SendMessage::Flag::f_send_as;
|
||||
mediaFlags |= MTPmessages_SendMedia::Flag::f_send_as;
|
||||
}
|
||||
const auto messagePostAuthor = peer->isBroadcast()
|
||||
? _session->user()->name()
|
||||
: QString();
|
||||
if (action.options.scheduled) {
|
||||
flags |= MessageFlag::IsOrWasScheduled;
|
||||
sendFlags |= MTPmessages_SendMessage::Flag::f_schedule_date;
|
||||
|
@ -3837,11 +3809,11 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
|
|||
lastMessage = history->addNewLocalMessage({
|
||||
.id = newId.msg,
|
||||
.flags = flags,
|
||||
.from = messageFromId,
|
||||
.from = NewMessageFromId(action),
|
||||
.replyTo = action.replyTo,
|
||||
.date = HistoryItem::NewMessageDate(action.options),
|
||||
.date = NewMessageDate(action.options),
|
||||
.shortcutId = action.options.shortcutId,
|
||||
.postAuthor = messagePostAuthor,
|
||||
.postAuthor = NewMessagePostAuthor(action),
|
||||
.effectId = action.options.effectId,
|
||||
}, sending, media);
|
||||
const auto done = [=](
|
||||
|
@ -3987,7 +3959,6 @@ void ApiWrap::sendInlineResult(
|
|||
flags |= MessageFlag::HasReplyInfo;
|
||||
sendFlags |= SendFlag::f_reply_to;
|
||||
}
|
||||
const auto anonymousPost = peer->amAnonymous();
|
||||
const auto silentPost = ShouldSendSilent(peer, action.options);
|
||||
FillMessagePostFlags(action, peer, flags);
|
||||
if (silentPost) {
|
||||
|
@ -4006,30 +3977,22 @@ void ApiWrap::sendInlineResult(
|
|||
}
|
||||
|
||||
const auto sendAs = action.options.sendAs;
|
||||
const auto messageFromId = sendAs
|
||||
? sendAs->id
|
||||
: anonymousPost ? PeerId()
|
||||
: _session->userPeerId();
|
||||
if (sendAs) {
|
||||
sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_send_as;
|
||||
}
|
||||
const auto messagePostAuthor = peer->isBroadcast()
|
||||
? _session->user()->name()
|
||||
: QString();
|
||||
|
||||
_session->data().registerMessageRandomId(randomId, newId);
|
||||
|
||||
data->addToHistory(history, {
|
||||
.id = newId.msg,
|
||||
.flags = flags,
|
||||
.from = messageFromId,
|
||||
.from = NewMessageFromId(action),
|
||||
.replyTo = action.replyTo,
|
||||
.date = HistoryItem::NewMessageDate(action.options),
|
||||
.date = NewMessageDate(action.options),
|
||||
.shortcutId = action.options.shortcutId,
|
||||
.viaBotId = ((bot && !action.options.hideViaBot)
|
||||
? peerToUser(bot->id)
|
||||
: UserId()),
|
||||
.postAuthor = messagePostAuthor,
|
||||
.postAuthor = NewMessagePostAuthor(action),
|
||||
});
|
||||
|
||||
history->clearCloudDraft(topicRootId);
|
||||
|
|
|
@ -671,9 +671,7 @@ HistoryItem::HistoryItem(
|
|||
.flags = (MessageFlag::Local
|
||||
| MessageFlag::Sponsored
|
||||
| (history->peer->isChannel() ? MessageFlag::Post : MessageFlag(0))),
|
||||
.date = HistoryItem::NewMessageDate(injectedAfter
|
||||
? injectedAfter->date()
|
||||
: 0),
|
||||
.date = NewMessageDate(injectedAfter ? injectedAfter->date() : 0),
|
||||
}) {
|
||||
const auto webpage = history->peer->owner().webpage(
|
||||
history->peer->owner().nextLocalMessageId().bare,
|
||||
|
@ -761,15 +759,6 @@ TimeId HistoryItem::date() const {
|
|||
return _date;
|
||||
}
|
||||
|
||||
TimeId HistoryItem::NewMessageDate(TimeId scheduled) {
|
||||
return scheduled ? scheduled : base::unixtime::now();
|
||||
}
|
||||
|
||||
TimeId HistoryItem::NewMessageDate(
|
||||
const Api::SendOptions &options) {
|
||||
return options.shortcutId ? 1 : NewMessageDate(options.scheduled);
|
||||
}
|
||||
|
||||
HistoryServiceDependentData *HistoryItem::GetServiceDependentData() {
|
||||
if (const auto pinned = Get<HistoryServicePinned>()) {
|
||||
return pinned;
|
||||
|
|
|
@ -482,10 +482,6 @@ public:
|
|||
[[nodiscard]] Data::MessagePosition position() const;
|
||||
[[nodiscard]] TimeId date() const;
|
||||
|
||||
[[nodiscard]] static TimeId NewMessageDate(TimeId scheduled);
|
||||
[[nodiscard]] static TimeId NewMessageDate(
|
||||
const Api::SendOptions &options);
|
||||
|
||||
[[nodiscard]] Data::Media *media() const {
|
||||
return _media.get();
|
||||
}
|
||||
|
|
|
@ -187,6 +187,32 @@ MessageFlags NewMessageFlags(not_null<PeerData*> peer) {
|
|||
| (peer->isSelf() ? MessageFlag() : MessageFlag::Outgoing);
|
||||
}
|
||||
|
||||
TimeId NewMessageDate(TimeId scheduled) {
|
||||
return scheduled ? scheduled : base::unixtime::now();
|
||||
}
|
||||
|
||||
TimeId NewMessageDate(const Api::SendOptions &options) {
|
||||
return options.shortcutId ? 1 : NewMessageDate(options.scheduled);
|
||||
}
|
||||
|
||||
PeerId NewMessageFromId(const Api::SendAction &action) {
|
||||
return action.options.sendAs
|
||||
? action.options.sendAs->id
|
||||
: action.history->peer->amAnonymous()
|
||||
? PeerId()
|
||||
: action.history->session().userPeerId();
|
||||
}
|
||||
|
||||
QString NewMessagePostAuthor(const Api::SendAction &action) {
|
||||
return !action.history->peer->isBroadcast()
|
||||
? QString()
|
||||
: (action.options.sendAs == action.history->peer)
|
||||
? QString()
|
||||
: action.options.sendAs
|
||||
? action.options.sendAs->name()
|
||||
: action.history->session().user()->name();
|
||||
}
|
||||
|
||||
bool ShouldSendSilent(
|
||||
not_null<PeerData*> peer,
|
||||
const Api::SendOptions &options) {
|
||||
|
@ -320,7 +346,7 @@ ClickHandlerPtr JumpToMessageClickHandler(
|
|||
const auto separate = Core::App().separateWindowFor(peer);
|
||||
const auto controller = separate
|
||||
? separate->sessionController()
|
||||
: peer->session().tryResolveWindow();
|
||||
: peer->session().tryResolveWindow(peer);
|
||||
if (controller) {
|
||||
auto params = Window::SectionShow{
|
||||
Window::SectionShow::Way::Forward
|
||||
|
|
|
@ -83,6 +83,10 @@ void RequestDependentMessageStory(
|
|||
PeerId peerId,
|
||||
StoryId storyId);
|
||||
[[nodiscard]] MessageFlags NewMessageFlags(not_null<PeerData*> peer);
|
||||
[[nodiscard]] TimeId NewMessageDate(TimeId scheduled);
|
||||
[[nodiscard]] TimeId NewMessageDate(const Api::SendOptions &options);
|
||||
[[nodiscard]] PeerId NewMessageFromId(const Api::SendAction &action);
|
||||
[[nodiscard]] QString NewMessagePostAuthor(const Api::SendAction &action);
|
||||
[[nodiscard]] bool ShouldSendSilent(
|
||||
not_null<PeerData*> peer,
|
||||
const Api::SendOptions &options);
|
||||
|
|
|
@ -117,6 +117,12 @@ not_null<PeerData*> SendAsPeers::ResolveChosen(
|
|||
not_null<PeerData*> peer,
|
||||
const std::vector<SendAsPeer> &list,
|
||||
PeerId chosen) {
|
||||
const auto fallback = peer->amAnonymous()
|
||||
? peer
|
||||
: peer->session().user();
|
||||
if (!chosen) {
|
||||
chosen = fallback->id;
|
||||
}
|
||||
const auto i = ranges::find(list, chosen, [](const SendAsPeer &as) {
|
||||
return as.peer->id;
|
||||
});
|
||||
|
@ -124,9 +130,7 @@ not_null<PeerData*> SendAsPeers::ResolveChosen(
|
|||
? i->peer
|
||||
: !list.empty()
|
||||
? list.front().peer
|
||||
: peer->amAnonymous()
|
||||
? peer
|
||||
: peer->session().user();
|
||||
: fallback;
|
||||
}
|
||||
|
||||
void SendAsPeers::request(not_null<PeerData*> peer) {
|
||||
|
|
Loading…
Add table
Reference in a new issue