2017-12-18 15:44:50 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-12-18 15:44:50 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-12-18 15:44:50 +00:00
|
|
|
*/
|
|
|
|
#include "history/history_item_components.h"
|
|
|
|
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "ui/effects/ripple_animation.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2019-03-15 15:15:56 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2017-12-28 13:06:06 +00:00
|
|
|
#include "ui/text_options.h"
|
2019-01-03 12:36:01 +00:00
|
|
|
#include "history/history.h"
|
2017-12-18 15:44:50 +00:00
|
|
|
#include "history/history_message.h"
|
2018-01-09 17:08:31 +00:00
|
|
|
#include "history/view/history_view_service_message.h"
|
2019-08-02 13:21:09 +00:00
|
|
|
#include "history/view/media/history_view_document.h"
|
2019-07-12 07:57:04 +00:00
|
|
|
#include "mainwindow.h"
|
2019-02-13 12:36:59 +00:00
|
|
|
#include "media/audio/media_audio.h"
|
2017-12-18 15:44:50 +00:00
|
|
|
#include "media/player/media_player_instance.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "data/data_media_types.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
|
|
|
#include "data/data_file_origin.h"
|
2019-12-27 12:15:16 +00:00
|
|
|
#include "data/data_document.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "window/window_session_controller.h"
|
|
|
|
#include "facades.h"
|
2017-12-18 15:44:50 +00:00
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
#include "styles/style_history.h"
|
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtGui/QGuiApplication>
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
void HistoryMessageVia::create(UserId userId) {
|
2019-01-18 12:27:37 +00:00
|
|
|
bot = Auth().data().user(userId);
|
2017-12-18 15:44:50 +00:00
|
|
|
maxWidth = st::msgServiceNameFont->width(
|
2019-06-19 16:39:25 +00:00
|
|
|
tr::lng_inline_bot_via(tr::now, lt_inline_bot, '@' + bot->username));
|
2017-12-18 15:44:50 +00:00
|
|
|
link = std::make_shared<LambdaClickHandler>([bot = this->bot] {
|
2019-07-12 07:57:04 +00:00
|
|
|
if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier) {
|
|
|
|
if (const auto window = App::wnd()) {
|
|
|
|
if (const auto controller = window->sessionController()) {
|
|
|
|
controller->showPeerInfo(bot);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-18 15:44:50 +00:00
|
|
|
App::insertBotCommand('@' + bot->username);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessageVia::resize(int32 availw) const {
|
|
|
|
if (availw < 0) {
|
|
|
|
text = QString();
|
|
|
|
width = 0;
|
|
|
|
} else {
|
2019-06-19 16:39:25 +00:00
|
|
|
text = tr::lng_inline_bot_via(tr::now, lt_inline_bot, '@' + bot->username);
|
2017-12-18 15:44:50 +00:00
|
|
|
if (availw < maxWidth) {
|
|
|
|
text = st::msgServiceNameFont->elided(text, availw);
|
|
|
|
width = st::msgServiceNameFont->width(text);
|
|
|
|
} else if (width < maxWidth) {
|
|
|
|
width = maxWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessageSigned::refresh(const QString &date) {
|
|
|
|
auto name = author;
|
2019-03-09 10:14:50 +00:00
|
|
|
const auto time = qsl(", ") + date;
|
|
|
|
const auto timew = st::msgDateFont->width(time);
|
|
|
|
const auto namew = st::msgDateFont->width(name);
|
|
|
|
isElided = (timew + namew > st::maxSignatureSize);
|
|
|
|
if (isElided) {
|
2017-12-18 15:44:50 +00:00
|
|
|
name = st::msgDateFont->elided(author, st::maxSignatureSize - timew);
|
|
|
|
}
|
2017-12-28 13:06:06 +00:00
|
|
|
signature.setText(
|
|
|
|
st::msgDateTextStyle,
|
|
|
|
name + time,
|
|
|
|
Ui::NameTextOptions());
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryMessageSigned::maxWidth() const {
|
|
|
|
return signature.maxWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessageEdited::refresh(const QString &date, bool displayed) {
|
2019-08-30 15:00:32 +00:00
|
|
|
const auto prefix = displayed
|
|
|
|
? (tr::lng_edited(tr::now) + ' ')
|
|
|
|
: QString();
|
2017-12-28 13:06:06 +00:00
|
|
|
text.setText(st::msgDateTextStyle, prefix + date, Ui::NameTextOptions());
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryMessageEdited::maxWidth() const {
|
|
|
|
return text.maxWidth();
|
|
|
|
}
|
|
|
|
|
2019-03-15 15:15:56 +00:00
|
|
|
HiddenSenderInfo::HiddenSenderInfo(const QString &name)
|
|
|
|
: name(name)
|
|
|
|
, colorPeerId(Data::FakePeerIdForJustName(name))
|
|
|
|
, userpic(Data::PeerUserpicColor(colorPeerId), name) {
|
|
|
|
nameText.setText(st::msgNameStyle, name, Ui::NameTextOptions());
|
|
|
|
const auto parts = name.trimmed().split(' ', QString::SkipEmptyParts);
|
|
|
|
firstName = parts[0];
|
|
|
|
for (const auto &part : parts.mid(1)) {
|
|
|
|
if (!lastName.isEmpty()) {
|
|
|
|
lastName.append(' ');
|
|
|
|
}
|
|
|
|
lastName.append(part);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
|
|
|
|
auto phrase = QString();
|
2019-03-15 15:15:56 +00:00
|
|
|
const auto fromChannel = originalSender
|
|
|
|
&& originalSender->isChannel()
|
|
|
|
&& !originalSender->isMegagroup();
|
|
|
|
const auto name = originalSender
|
2019-09-13 06:06:02 +00:00
|
|
|
? originalSender->name
|
2019-03-15 15:15:56 +00:00
|
|
|
: hiddenSenderInfo->name;
|
2017-12-18 15:44:50 +00:00
|
|
|
if (!originalAuthor.isEmpty()) {
|
2019-06-19 16:39:25 +00:00
|
|
|
phrase = tr::lng_forwarded_signed(
|
|
|
|
tr::now,
|
2017-12-18 15:44:50 +00:00
|
|
|
lt_channel,
|
2019-03-15 15:15:56 +00:00
|
|
|
name,
|
2017-12-18 15:44:50 +00:00
|
|
|
lt_user,
|
|
|
|
originalAuthor);
|
|
|
|
} else {
|
2019-03-15 15:15:56 +00:00
|
|
|
phrase = name;
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
if (via) {
|
|
|
|
if (fromChannel) {
|
2019-06-19 16:39:25 +00:00
|
|
|
phrase = tr::lng_forwarded_channel_via(
|
|
|
|
tr::now,
|
2017-12-18 15:44:50 +00:00
|
|
|
lt_channel,
|
|
|
|
textcmdLink(1, phrase),
|
|
|
|
lt_inline_bot,
|
|
|
|
textcmdLink(2, '@' + via->bot->username));
|
|
|
|
} else {
|
2019-06-19 16:39:25 +00:00
|
|
|
phrase = tr::lng_forwarded_via(
|
|
|
|
tr::now,
|
2017-12-18 15:44:50 +00:00
|
|
|
lt_user,
|
|
|
|
textcmdLink(1, phrase),
|
|
|
|
lt_inline_bot,
|
|
|
|
textcmdLink(2, '@' + via->bot->username));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (fromChannel) {
|
2019-06-19 16:39:25 +00:00
|
|
|
phrase = tr::lng_forwarded_channel(
|
|
|
|
tr::now,
|
2017-12-18 15:44:50 +00:00
|
|
|
lt_channel,
|
|
|
|
textcmdLink(1, phrase));
|
|
|
|
} else {
|
2019-06-19 16:39:25 +00:00
|
|
|
phrase = tr::lng_forwarded(
|
|
|
|
tr::now,
|
2017-12-18 15:44:50 +00:00
|
|
|
lt_user,
|
|
|
|
textcmdLink(1, phrase));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TextParseOptions opts = {
|
|
|
|
TextParseRichText,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
Qt::LayoutDirectionAuto
|
|
|
|
};
|
|
|
|
text.setText(st::fwdTextStyle, phrase, opts);
|
2019-03-15 15:15:56 +00:00
|
|
|
static const auto hidden = std::make_shared<LambdaClickHandler>([] {
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::Toast::Show(tr::lng_forwarded_hidden(tr::now));
|
2019-03-15 15:15:56 +00:00
|
|
|
});
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
text.setLink(1, fromChannel
|
|
|
|
? goToMessageClickHandler(originalSender, originalId)
|
2019-03-15 15:15:56 +00:00
|
|
|
: originalSender
|
|
|
|
? originalSender->openLink()
|
|
|
|
: hidden);
|
2017-12-18 15:44:50 +00:00
|
|
|
if (via) {
|
|
|
|
text.setLink(2, via->link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
bool HistoryMessageReply::updateData(
|
|
|
|
not_null<HistoryMessage*> holder,
|
|
|
|
bool force) {
|
2019-12-27 12:15:16 +00:00
|
|
|
const auto guard = gsl::finally([&] { refreshReplyToDocument(); });
|
2017-12-18 15:44:50 +00:00
|
|
|
if (!force) {
|
|
|
|
if (replyToMsg || !replyToMsgId) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!replyToMsg) {
|
2019-04-25 12:45:15 +00:00
|
|
|
replyToMsg = holder->history()->owner().message(
|
|
|
|
holder->channelId(),
|
|
|
|
replyToMsgId);
|
2017-12-18 15:44:50 +00:00
|
|
|
if (replyToMsg) {
|
|
|
|
if (replyToMsg->isEmpty()) {
|
|
|
|
// Really it is deleted.
|
|
|
|
replyToMsg = nullptr;
|
|
|
|
force = true;
|
|
|
|
} else {
|
2019-04-25 12:45:15 +00:00
|
|
|
holder->history()->owner().registerDependentMessage(
|
|
|
|
holder,
|
|
|
|
replyToMsg);
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (replyToMsg) {
|
2017-12-28 13:06:06 +00:00
|
|
|
replyToText.setText(
|
|
|
|
st::messageTextStyle,
|
2018-05-31 11:13:11 +00:00
|
|
|
replyToMsg->inReplyText(),
|
2017-12-28 13:06:06 +00:00
|
|
|
Ui::DialogTextOptions());
|
2017-12-18 15:44:50 +00:00
|
|
|
|
|
|
|
updateName();
|
|
|
|
|
2018-06-04 16:58:35 +00:00
|
|
|
setReplyToLinkFrom(holder);
|
2017-12-18 15:44:50 +00:00
|
|
|
if (!replyToMsg->Has<HistoryMessageForwarded>()) {
|
|
|
|
if (auto bot = replyToMsg->viaBot()) {
|
|
|
|
replyToVia = std::make_unique<HistoryMessageVia>();
|
|
|
|
replyToVia->create(peerToUser(bot->id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (force) {
|
|
|
|
replyToMsgId = 0;
|
|
|
|
}
|
|
|
|
if (force) {
|
2019-01-03 12:36:01 +00:00
|
|
|
holder->history()->owner().requestItemResize(holder);
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
return (replyToMsg || !replyToMsgId);
|
|
|
|
}
|
|
|
|
|
2018-06-04 16:58:35 +00:00
|
|
|
void HistoryMessageReply::setReplyToLinkFrom(
|
|
|
|
not_null<HistoryMessage*> holder) {
|
|
|
|
replyToLnk = replyToMsg
|
|
|
|
? goToMessageClickHandler(replyToMsg, holder->fullId())
|
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
void HistoryMessageReply::clearData(not_null<HistoryMessage*> holder) {
|
2017-12-18 15:44:50 +00:00
|
|
|
replyToVia = nullptr;
|
|
|
|
if (replyToMsg) {
|
2019-04-25 12:45:15 +00:00
|
|
|
holder->history()->owner().unregisterDependentMessage(
|
|
|
|
holder,
|
|
|
|
replyToMsg);
|
2017-12-18 15:44:50 +00:00
|
|
|
replyToMsg = nullptr;
|
|
|
|
}
|
|
|
|
replyToMsgId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryMessageReply::isNameUpdated() const {
|
|
|
|
if (replyToMsg && replyToMsg->author()->nameVersion > replyToVersion) {
|
|
|
|
updateName();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessageReply::updateName() const {
|
|
|
|
if (replyToMsg) {
|
2019-05-24 07:55:16 +00:00
|
|
|
const auto from = [&] {
|
2019-05-25 15:05:57 +00:00
|
|
|
if (const auto from = replyToMsg->displayFrom()) {
|
|
|
|
return from;
|
2019-05-24 07:55:16 +00:00
|
|
|
}
|
|
|
|
return replyToMsg->author().get();
|
|
|
|
}();
|
2019-09-13 06:06:02 +00:00
|
|
|
const auto name = (replyToVia && from->isUser())
|
|
|
|
? from->asUser()->firstName
|
|
|
|
: from->name;
|
2017-12-28 13:06:06 +00:00
|
|
|
replyToName.setText(st::fwdTextStyle, name, Ui::NameTextOptions());
|
2017-12-18 15:44:50 +00:00
|
|
|
replyToVersion = replyToMsg->author()->nameVersion;
|
2018-01-14 16:02:25 +00:00
|
|
|
bool hasPreview = replyToMsg->media() ? replyToMsg->media()->hasReplyPreview() : false;
|
2017-12-18 15:44:50 +00:00
|
|
|
int32 previewSkip = hasPreview ? (st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x()) : 0;
|
|
|
|
int32 w = replyToName.maxWidth();
|
|
|
|
if (replyToVia) {
|
|
|
|
w += st::msgServiceFont->spacew + replyToVia->maxWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
maxReplyWidth = previewSkip + qMax(w, qMin(replyToText.maxWidth(), int32(st::maxSignatureSize)));
|
|
|
|
} else {
|
2019-06-19 15:09:03 +00:00
|
|
|
maxReplyWidth = st::msgDateFont->width(replyToMsgId ? tr::lng_profile_loading(tr::now) : tr::lng_deleted_message(tr::now));
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
maxReplyWidth = st::msgReplyPadding.left() + st::msgReplyBarSkip + maxReplyWidth + st::msgReplyPadding.right();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessageReply::resize(int width) const {
|
|
|
|
if (replyToVia) {
|
2018-01-14 16:02:25 +00:00
|
|
|
bool hasPreview = replyToMsg->media() ? replyToMsg->media()->hasReplyPreview() : false;
|
2017-12-18 15:44:50 +00:00
|
|
|
int previewSkip = hasPreview ? (st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x()) : 0;
|
|
|
|
replyToVia->resize(width - st::msgReplyBarSkip - previewSkip - replyToName.maxWidth() - st::msgServiceFont->spacew);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
void HistoryMessageReply::itemRemoved(
|
|
|
|
HistoryMessage *holder,
|
|
|
|
HistoryItem *removed) {
|
2017-12-18 15:44:50 +00:00
|
|
|
if (replyToMsg == removed) {
|
|
|
|
clearData(holder);
|
2019-01-03 12:36:01 +00:00
|
|
|
holder->history()->owner().requestItemResize(holder);
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
void HistoryMessageReply::paint(
|
|
|
|
Painter &p,
|
|
|
|
not_null<const HistoryView::Element*> holder,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int w,
|
|
|
|
PaintFlags flags) const {
|
2017-12-18 15:44:50 +00:00
|
|
|
bool selected = (flags & PaintFlag::Selected), outbg = holder->hasOutLayout();
|
|
|
|
|
|
|
|
style::color bar = st::msgImgReplyBarColor;
|
|
|
|
if (flags & PaintFlag::InBubble) {
|
|
|
|
bar = (flags & PaintFlag::Selected) ? (outbg ? st::msgOutReplyBarSelColor : st::msgInReplyBarSelColor) : (outbg ? st::msgOutReplyBarColor : st::msgInReplyBarColor);
|
|
|
|
}
|
2019-09-13 12:22:54 +00:00
|
|
|
QRect rbar(style::rtlrect(x + st::msgReplyBarPos.x(), y + st::msgReplyPadding.top() + st::msgReplyBarPos.y(), st::msgReplyBarSize.width(), st::msgReplyBarSize.height(), w + 2 * x));
|
2017-12-18 15:44:50 +00:00
|
|
|
p.fillRect(rbar, bar);
|
|
|
|
|
|
|
|
if (w > st::msgReplyBarSkip) {
|
|
|
|
if (replyToMsg) {
|
2018-01-14 16:02:25 +00:00
|
|
|
auto hasPreview = replyToMsg->media() ? replyToMsg->media()->hasReplyPreview() : false;
|
2017-12-18 15:44:50 +00:00
|
|
|
if (hasPreview && w < st::msgReplyBarSkip + st::msgReplyBarSize.height()) {
|
|
|
|
hasPreview = false;
|
|
|
|
}
|
|
|
|
auto previewSkip = hasPreview ? (st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x()) : 0;
|
|
|
|
|
|
|
|
if (hasPreview) {
|
2018-11-09 15:03:38 +00:00
|
|
|
if (const auto image = replyToMsg->media()->replyPreview()) {
|
2019-09-13 12:22:54 +00:00
|
|
|
auto to = style::rtlrect(x + st::msgReplyBarSkip, y + st::msgReplyPadding.top() + st::msgReplyBarPos.y(), st::msgReplyBarSize.height(), st::msgReplyBarSize.height(), w + 2 * x);
|
2018-11-09 15:03:38 +00:00
|
|
|
auto previewWidth = image->width() / cIntRetinaFactor();
|
|
|
|
auto previewHeight = image->height() / cIntRetinaFactor();
|
|
|
|
auto preview = image->pixSingle(replyToMsg->fullId(), previewWidth, previewHeight, to.width(), to.height(), ImageRoundRadius::Small, RectPart::AllCorners, selected ? &st::msgStickerOverlay : nullptr);
|
2017-12-18 15:44:50 +00:00
|
|
|
p.drawPixmap(to.x(), to.y(), preview);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (w > st::msgReplyBarSkip + previewSkip) {
|
|
|
|
if (flags & PaintFlag::InBubble) {
|
|
|
|
p.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg));
|
|
|
|
} else {
|
|
|
|
p.setPen(st::msgImgReplyBarColor);
|
|
|
|
}
|
|
|
|
replyToName.drawLeftElided(p, x + st::msgReplyBarSkip + previewSkip, y + st::msgReplyPadding.top(), w - st::msgReplyBarSkip - previewSkip, w + 2 * x);
|
|
|
|
if (replyToVia && w > st::msgReplyBarSkip + previewSkip + replyToName.maxWidth() + st::msgServiceFont->spacew) {
|
|
|
|
p.setFont(st::msgServiceFont);
|
|
|
|
p.drawText(x + st::msgReplyBarSkip + previewSkip + replyToName.maxWidth() + st::msgServiceFont->spacew, y + st::msgReplyPadding.top() + st::msgServiceFont->ascent, replyToVia->text);
|
|
|
|
}
|
|
|
|
|
2018-05-31 11:13:11 +00:00
|
|
|
if (flags & PaintFlag::InBubble) {
|
2017-12-18 15:44:50 +00:00
|
|
|
p.setPen(outbg ? (selected ? st::historyTextOutFgSelected : st::historyTextOutFg) : (selected ? st::historyTextInFgSelected : st::historyTextInFg));
|
2018-05-31 11:13:11 +00:00
|
|
|
p.setTextPalette(outbg ? (selected ? st::outReplyTextPaletteSelected : st::outReplyTextPalette) : (selected ? st::inReplyTextPaletteSelected : st::inReplyTextPalette));
|
|
|
|
} else {
|
|
|
|
p.setTextPalette(st::imgReplyTextPalette);
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
replyToText.drawLeftElided(p, x + st::msgReplyBarSkip + previewSkip, y + st::msgReplyPadding.top() + st::msgServiceNameFont->height, w - st::msgReplyBarSkip - previewSkip, w + 2 * x);
|
2018-05-31 11:13:11 +00:00
|
|
|
p.setTextPalette(selected ? (outbg ? st::outTextPaletteSelected : st::inTextPaletteSelected) : (outbg ? st::outTextPalette : st::inTextPalette));
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
p.setFont(st::msgDateFont);
|
|
|
|
auto &date = outbg ? (selected ? st::msgOutDateFgSelected : st::msgOutDateFg) : (selected ? st::msgInDateFgSelected : st::msgInDateFg);
|
|
|
|
p.setPen((flags & PaintFlag::InBubble) ? date : st::msgDateImgFg);
|
2019-06-19 15:09:03 +00:00
|
|
|
p.drawTextLeft(x + st::msgReplyBarSkip, y + st::msgReplyPadding.top() + (st::msgReplyBarSize.height() - st::msgDateFont->height) / 2, w + 2 * x, st::msgDateFont->elided(replyToMsgId ? tr::lng_profile_loading(tr::now) : tr::lng_deleted_message(tr::now), w - st::msgReplyBarSkip));
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-27 12:15:16 +00:00
|
|
|
void HistoryMessageReply::refreshReplyToDocument() {
|
|
|
|
replyToDocumentId = 0;
|
2019-12-27 10:41:30 +00:00
|
|
|
if (const auto media = replyToMsg ? replyToMsg->media() : nullptr) {
|
2019-12-27 12:15:16 +00:00
|
|
|
if (const auto document = media->document()) {
|
|
|
|
replyToDocumentId = document->id;
|
|
|
|
}
|
2019-12-27 10:41:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
ReplyMarkupClickHandler::ReplyMarkupClickHandler(
|
|
|
|
int row,
|
|
|
|
int column,
|
|
|
|
FullMsgId context)
|
|
|
|
: _itemId(context)
|
|
|
|
, _row(row)
|
|
|
|
, _column(column) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy to clipboard support.
|
2018-01-25 10:10:52 +00:00
|
|
|
QString ReplyMarkupClickHandler::copyToClipboardText() const {
|
2019-06-05 17:42:10 +00:00
|
|
|
if (const auto button = getButton()) {
|
|
|
|
using Type = HistoryMessageMarkupButton::Type;
|
|
|
|
if (button->type == Type::Url || button->type == Type::Auth) {
|
2018-01-25 10:10:52 +00:00
|
|
|
return QString::fromUtf8(button->data);
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-25 10:10:52 +00:00
|
|
|
return QString();
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ReplyMarkupClickHandler::copyToClipboardContextItemText() const {
|
2019-06-05 17:42:10 +00:00
|
|
|
if (const auto button = getButton()) {
|
|
|
|
using Type = HistoryMessageMarkupButton::Type;
|
|
|
|
if (button->type == Type::Url || button->type == Type::Auth) {
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_context_copy_link(tr::now);
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finds the corresponding button in the items markup struct.
|
|
|
|
// If the button is not found it returns nullptr.
|
|
|
|
// Note: it is possible that we will point to the different button
|
|
|
|
// than the one was used when constructing the handler, but not a big deal.
|
|
|
|
const HistoryMessageMarkupButton *ReplyMarkupClickHandler::getButton() const {
|
2019-05-22 14:29:02 +00:00
|
|
|
return HistoryMessageMarkupButton::Get(_itemId, _row, _column);
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReplyMarkupClickHandler::onClickImpl() const {
|
2019-04-25 12:45:15 +00:00
|
|
|
if (const auto item = Auth().data().message(_itemId)) {
|
2017-12-18 15:44:50 +00:00
|
|
|
App::activateBotCommand(item, _row, _column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the full text of the corresponding button.
|
|
|
|
QString ReplyMarkupClickHandler::buttonText() const {
|
|
|
|
if (const auto button = getButton()) {
|
|
|
|
return button->text;
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
ReplyKeyboard::Button::Button() = default;
|
|
|
|
ReplyKeyboard::Button::Button(Button &&other) = default;
|
|
|
|
ReplyKeyboard::Button &ReplyKeyboard::Button::operator=(
|
|
|
|
Button &&other) = default;
|
|
|
|
ReplyKeyboard::Button::~Button() = default;
|
|
|
|
|
|
|
|
ReplyKeyboard::ReplyKeyboard(
|
|
|
|
not_null<const HistoryItem*> item,
|
|
|
|
std::unique_ptr<Style> &&s)
|
|
|
|
: _item(item)
|
2019-04-01 17:44:54 +00:00
|
|
|
, _selectedAnimation([=](crl::time now) {
|
|
|
|
return selectedAnimationCallback(now);
|
|
|
|
})
|
2017-12-18 15:44:50 +00:00
|
|
|
, _st(std::move(s)) {
|
|
|
|
if (const auto markup = _item->Get<HistoryMessageReplyMarkup>()) {
|
|
|
|
const auto context = _item->fullId();
|
|
|
|
const auto rowCount = int(markup->rows.size());
|
|
|
|
_rows.reserve(rowCount);
|
|
|
|
for (auto i = 0; i != rowCount; ++i) {
|
|
|
|
const auto &row = markup->rows.at(i);
|
|
|
|
const auto rowSize = int(row.size());
|
|
|
|
auto newRow = std::vector<Button>();
|
|
|
|
newRow.reserve(rowSize);
|
|
|
|
for (auto j = 0; j != rowSize; ++j) {
|
|
|
|
auto button = Button();
|
|
|
|
const auto text = row[j].text;
|
|
|
|
button.type = row.at(j).type;
|
|
|
|
button.link = std::make_shared<ReplyMarkupClickHandler>(
|
|
|
|
i,
|
|
|
|
j,
|
|
|
|
context);
|
|
|
|
button.text.setText(
|
|
|
|
_st->textStyle(),
|
|
|
|
TextUtilities::SingleLine(text),
|
|
|
|
_textPlainOptions);
|
|
|
|
button.characters = text.isEmpty() ? 1 : text.size();
|
|
|
|
newRow.push_back(std::move(button));
|
|
|
|
}
|
|
|
|
_rows.push_back(std::move(newRow));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReplyKeyboard::updateMessageId() {
|
|
|
|
const auto msgId = _item->fullId();
|
|
|
|
for (const auto &row : _rows) {
|
|
|
|
for (const auto &button : row) {
|
|
|
|
button.link->setMessageId(msgId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReplyKeyboard::resize(int width, int height) {
|
|
|
|
_width = width;
|
|
|
|
|
|
|
|
auto markup = _item->Get<HistoryMessageReplyMarkup>();
|
|
|
|
auto y = 0.;
|
|
|
|
auto buttonHeight = _rows.empty()
|
|
|
|
? float64(_st->buttonHeight())
|
|
|
|
: (float64(height + _st->buttonSkip()) / _rows.size());
|
|
|
|
for (auto &row : _rows) {
|
|
|
|
int s = row.size();
|
|
|
|
|
|
|
|
int widthForButtons = _width - ((s - 1) * _st->buttonSkip());
|
|
|
|
int widthForText = widthForButtons;
|
|
|
|
int widthOfText = 0;
|
|
|
|
int maxMinButtonWidth = 0;
|
|
|
|
for_const (auto &button, row) {
|
|
|
|
widthOfText += qMax(button.text.maxWidth(), 1);
|
|
|
|
int minButtonWidth = _st->minButtonWidth(button.type);
|
|
|
|
widthForText -= minButtonWidth;
|
|
|
|
accumulate_max(maxMinButtonWidth, minButtonWidth);
|
|
|
|
}
|
|
|
|
bool exact = (widthForText == widthOfText);
|
|
|
|
bool enough = (widthForButtons - s * maxMinButtonWidth) >= widthOfText;
|
|
|
|
|
|
|
|
float64 x = 0;
|
|
|
|
for (Button &button : row) {
|
|
|
|
int buttonw = qMax(button.text.maxWidth(), 1);
|
|
|
|
float64 textw = buttonw, minw = _st->minButtonWidth(button.type);
|
|
|
|
float64 w = textw;
|
|
|
|
if (exact) {
|
|
|
|
w += minw;
|
|
|
|
} else if (enough) {
|
|
|
|
w = (widthForButtons / float64(s));
|
|
|
|
textw = w - minw;
|
|
|
|
} else {
|
|
|
|
textw = (widthForText / float64(s));
|
|
|
|
w = minw + textw;
|
|
|
|
accumulate_max(w, 2 * float64(_st->buttonPadding()));
|
|
|
|
}
|
|
|
|
|
|
|
|
int rectx = static_cast<int>(std::floor(x));
|
|
|
|
int rectw = static_cast<int>(std::floor(x + w)) - rectx;
|
|
|
|
button.rect = QRect(rectx, qRound(y), rectw, qRound(buttonHeight - _st->buttonSkip()));
|
|
|
|
if (rtl()) button.rect.setX(_width - button.rect.x() - button.rect.width());
|
|
|
|
x += w + _st->buttonSkip();
|
|
|
|
|
|
|
|
button.link->setFullDisplayed(textw >= buttonw);
|
|
|
|
}
|
|
|
|
y += buttonHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReplyKeyboard::isEnoughSpace(int width, const style::BotKeyboardButton &st) const {
|
|
|
|
for_const (auto &row, _rows) {
|
|
|
|
int s = row.size();
|
|
|
|
int widthLeft = width - ((s - 1) * st.margin + s * 2 * st.padding);
|
|
|
|
for_const (auto &button, row) {
|
|
|
|
widthLeft -= qMax(button.text.maxWidth(), 1);
|
|
|
|
if (widthLeft < 0) {
|
|
|
|
if (row.size() > 3) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReplyKeyboard::setStyle(std::unique_ptr<Style> &&st) {
|
|
|
|
_st = std::move(st);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ReplyKeyboard::naturalWidth() const {
|
|
|
|
auto result = 0;
|
|
|
|
for (const auto &row : _rows) {
|
|
|
|
auto maxMinButtonWidth = 0;
|
|
|
|
for (const auto &button : row) {
|
|
|
|
accumulate_max(
|
|
|
|
maxMinButtonWidth,
|
|
|
|
_st->minButtonWidth(button.type));
|
|
|
|
}
|
|
|
|
auto rowMaxButtonWidth = 0;
|
|
|
|
for (const auto &button : row) {
|
|
|
|
accumulate_max(
|
|
|
|
rowMaxButtonWidth,
|
|
|
|
qMax(button.text.maxWidth(), 1) + maxMinButtonWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto rowSize = int(row.size());
|
|
|
|
accumulate_max(
|
|
|
|
result,
|
|
|
|
rowSize * rowMaxButtonWidth + (rowSize - 1) * _st->buttonSkip());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ReplyKeyboard::naturalHeight() const {
|
|
|
|
return (_rows.size() - 1) * _st->buttonSkip() + _rows.size() * _st->buttonHeight();
|
|
|
|
}
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
void ReplyKeyboard::paint(Painter &p, int outerWidth, const QRect &clip) const {
|
2017-12-18 15:44:50 +00:00
|
|
|
Assert(_st != nullptr);
|
|
|
|
Assert(_width > 0);
|
|
|
|
|
|
|
|
_st->startPaint(p);
|
2019-04-02 09:13:30 +00:00
|
|
|
for (const auto &row : _rows) {
|
|
|
|
for (const auto &button : row) {
|
|
|
|
const auto rect = button.rect;
|
2017-12-18 15:44:50 +00:00
|
|
|
if (rect.y() >= clip.y() + clip.height()) return;
|
|
|
|
if (rect.y() + rect.height() < clip.y()) continue;
|
|
|
|
|
|
|
|
// just ignore the buttons that didn't layout well
|
|
|
|
if (rect.x() + rect.width() > _width) break;
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
_st->paintButton(p, outerWidth, button);
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
ClickHandlerPtr ReplyKeyboard::getLink(QPoint point) const {
|
2017-12-18 15:44:50 +00:00
|
|
|
Assert(_width > 0);
|
|
|
|
|
|
|
|
for_const (auto &row, _rows) {
|
|
|
|
for_const (auto &button, row) {
|
|
|
|
QRect rect(button.rect);
|
|
|
|
|
|
|
|
// just ignore the buttons that didn't layout well
|
|
|
|
if (rect.x() + rect.width() > _width) break;
|
|
|
|
|
|
|
|
if (rect.contains(point)) {
|
|
|
|
_savedCoords = point;
|
|
|
|
return button.link;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ClickHandlerPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReplyKeyboard::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
|
|
|
|
if (!p) return;
|
|
|
|
|
|
|
|
_savedActive = active ? p : ClickHandlerPtr();
|
|
|
|
auto coords = findButtonCoordsByClickHandler(p);
|
|
|
|
if (coords.i >= 0 && _savedPressed != p) {
|
|
|
|
startAnimation(coords.i, coords.j, active ? 1 : -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReplyKeyboard::ButtonCoords ReplyKeyboard::findButtonCoordsByClickHandler(const ClickHandlerPtr &p) {
|
|
|
|
for (int i = 0, rows = _rows.size(); i != rows; ++i) {
|
|
|
|
auto &row = _rows[i];
|
|
|
|
for (int j = 0, cols = row.size(); j != cols; ++j) {
|
|
|
|
if (row[j].link == p) {
|
|
|
|
return { i, j };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return { -1, -1 };
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
void ReplyKeyboard::clickHandlerPressedChanged(
|
|
|
|
const ClickHandlerPtr &handler,
|
|
|
|
bool pressed) {
|
|
|
|
if (!handler) return;
|
2017-12-18 15:44:50 +00:00
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
_savedPressed = pressed ? handler : ClickHandlerPtr();
|
|
|
|
auto coords = findButtonCoordsByClickHandler(handler);
|
2017-12-18 15:44:50 +00:00
|
|
|
if (coords.i >= 0) {
|
|
|
|
auto &button = _rows[coords.i][coords.j];
|
|
|
|
if (pressed) {
|
|
|
|
if (!button.ripple) {
|
|
|
|
auto mask = Ui::RippleAnimation::roundRectMask(
|
|
|
|
button.rect.size(),
|
|
|
|
_st->buttonRadius());
|
|
|
|
button.ripple = std::make_unique<Ui::RippleAnimation>(
|
|
|
|
_st->_st->ripple,
|
|
|
|
std::move(mask),
|
|
|
|
[this] { _st->repaint(_item); });
|
|
|
|
}
|
|
|
|
button.ripple->add(_savedCoords - button.rect.topLeft());
|
|
|
|
} else {
|
|
|
|
if (button.ripple) {
|
|
|
|
button.ripple->lastStop();
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
if (_savedActive != handler) {
|
2017-12-18 15:44:50 +00:00
|
|
|
startAnimation(coords.i, coords.j, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReplyKeyboard::startAnimation(int i, int j, int direction) {
|
|
|
|
auto notStarted = _animations.empty();
|
|
|
|
|
|
|
|
int indexForAnimation = (i * MatrixRowShift + j + 1) * direction;
|
|
|
|
|
|
|
|
_animations.remove(-indexForAnimation);
|
|
|
|
if (!_animations.contains(indexForAnimation)) {
|
2019-02-19 06:57:53 +00:00
|
|
|
_animations.emplace(indexForAnimation, crl::now());
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
if (notStarted && !_selectedAnimation.animating()) {
|
|
|
|
_selectedAnimation.start();
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
bool ReplyKeyboard::selectedAnimationCallback(crl::time now) {
|
2018-09-20 16:39:59 +00:00
|
|
|
if (anim::Disabled()) {
|
2019-04-01 17:44:54 +00:00
|
|
|
now += st::botKbDuration;
|
2018-09-20 16:39:59 +00:00
|
|
|
}
|
2017-12-18 15:44:50 +00:00
|
|
|
for (auto i = _animations.begin(); i != _animations.end();) {
|
|
|
|
const auto index = std::abs(i->first) - 1;
|
|
|
|
const auto row = (index / MatrixRowShift);
|
|
|
|
const auto col = index % MatrixRowShift;
|
2019-04-01 17:44:54 +00:00
|
|
|
const auto dt = float64(now - i->second) / st::botKbDuration;
|
2017-12-18 15:44:50 +00:00
|
|
|
if (dt >= 1) {
|
|
|
|
_rows[row][col].howMuchOver = (i->first > 0) ? 1 : 0;
|
|
|
|
i = _animations.erase(i);
|
|
|
|
} else {
|
|
|
|
_rows[row][col].howMuchOver = (i->first > 0) ? dt : (1 - dt);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2019-04-01 17:44:54 +00:00
|
|
|
_st->repaint(_item);
|
|
|
|
return !_animations.empty();
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReplyKeyboard::clearSelection() {
|
|
|
|
for (const auto [relativeIndex, time] : _animations) {
|
|
|
|
const auto index = std::abs(relativeIndex) - 1;
|
|
|
|
const auto row = (index / MatrixRowShift);
|
|
|
|
const auto col = index % MatrixRowShift;
|
|
|
|
_rows[row][col].howMuchOver = 0;
|
|
|
|
}
|
|
|
|
_animations.clear();
|
2019-04-01 17:44:54 +00:00
|
|
|
_selectedAnimation.stop();
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ReplyKeyboard::Style::buttonSkip() const {
|
|
|
|
return _st->margin;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ReplyKeyboard::Style::buttonPadding() const {
|
|
|
|
return _st->padding;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ReplyKeyboard::Style::buttonHeight() const {
|
|
|
|
return _st->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReplyKeyboard::Style::paintButton(
|
|
|
|
Painter &p,
|
|
|
|
int outerWidth,
|
2019-04-02 09:13:30 +00:00
|
|
|
const ReplyKeyboard::Button &button) const {
|
2017-12-18 15:44:50 +00:00
|
|
|
const QRect &rect = button.rect;
|
|
|
|
paintButtonBg(p, rect, button.howMuchOver);
|
|
|
|
if (button.ripple) {
|
2019-04-02 09:13:30 +00:00
|
|
|
button.ripple->paint(p, rect.x(), rect.y(), outerWidth);
|
2017-12-18 15:44:50 +00:00
|
|
|
if (button.ripple->empty()) {
|
|
|
|
button.ripple.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
paintButtonIcon(p, rect, outerWidth, button.type);
|
|
|
|
if (button.type == HistoryMessageMarkupButton::Type::Callback
|
|
|
|
|| button.type == HistoryMessageMarkupButton::Type::Game) {
|
|
|
|
if (auto data = button.link->getButton()) {
|
|
|
|
if (data->requestId) {
|
|
|
|
paintButtonLoading(p, rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int tx = rect.x(), tw = rect.width();
|
|
|
|
if (tw >= st::botKbStyle.font->elidew + _st->padding * 2) {
|
|
|
|
tx += _st->padding;
|
|
|
|
tw -= _st->padding * 2;
|
|
|
|
} else if (tw > st::botKbStyle.font->elidew) {
|
|
|
|
tx += (tw - st::botKbStyle.font->elidew) / 2;
|
|
|
|
tw = st::botKbStyle.font->elidew;
|
|
|
|
}
|
|
|
|
button.text.drawElided(p, tx, rect.y() + _st->textTop + ((rect.height() - _st->height) / 2), tw, 1, style::al_top);
|
|
|
|
}
|
|
|
|
|
2019-05-22 14:29:02 +00:00
|
|
|
HistoryMessageMarkupButton::HistoryMessageMarkupButton(
|
|
|
|
Type type,
|
|
|
|
const QString &text,
|
|
|
|
const QByteArray &data,
|
2019-05-27 13:26:12 +00:00
|
|
|
const QString &forwardText,
|
2019-05-22 14:29:02 +00:00
|
|
|
int32 buttonId)
|
|
|
|
: type(type)
|
|
|
|
, text(text)
|
2019-05-27 13:26:12 +00:00
|
|
|
, forwardText(forwardText)
|
2019-05-22 14:29:02 +00:00
|
|
|
, data(data)
|
|
|
|
, buttonId(buttonId) {
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryMessageMarkupButton *HistoryMessageMarkupButton::Get(
|
|
|
|
FullMsgId itemId,
|
|
|
|
int row,
|
|
|
|
int column) {
|
|
|
|
if (const auto item = Auth().data().message(itemId)) {
|
|
|
|
if (const auto markup = item->Get<HistoryMessageReplyMarkup>()) {
|
|
|
|
if (row < markup->rows.size()) {
|
|
|
|
auto &buttons = markup->rows[row];
|
|
|
|
if (column < buttons.size()) {
|
|
|
|
return &buttons[column];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessageReplyMarkup::createFromButtonRows(
|
|
|
|
const QVector<MTPKeyboardButtonRow> &list) {
|
|
|
|
rows.clear();
|
|
|
|
if (list.isEmpty()) {
|
2017-12-18 15:44:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-22 14:29:02 +00:00
|
|
|
rows.reserve(list.size());
|
|
|
|
for (const auto &row : list) {
|
|
|
|
row.match([&](const MTPDkeyboardButtonRow &data) {
|
|
|
|
auto row = std::vector<Button>();
|
2019-07-05 13:38:38 +00:00
|
|
|
row.reserve(data.vbuttons().v.size());
|
|
|
|
for (const auto &button : data.vbuttons().v) {
|
2019-05-22 14:29:02 +00:00
|
|
|
using Type = Button::Type;
|
|
|
|
button.match([&](const MTPDkeyboardButton &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
row.emplace_back(Type::Default, qs(data.vtext()));
|
2019-05-22 14:29:02 +00:00
|
|
|
}, [&](const MTPDkeyboardButtonCallback &data) {
|
|
|
|
row.emplace_back(
|
|
|
|
Type::Callback,
|
2019-07-05 13:38:38 +00:00
|
|
|
qs(data.vtext()),
|
|
|
|
qba(data.vdata()));
|
2019-05-22 14:29:02 +00:00
|
|
|
}, [&](const MTPDkeyboardButtonRequestGeoLocation &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
row.emplace_back(Type::RequestLocation, qs(data.vtext()));
|
2019-05-22 14:29:02 +00:00
|
|
|
}, [&](const MTPDkeyboardButtonRequestPhone &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
row.emplace_back(Type::RequestPhone, qs(data.vtext()));
|
2019-05-22 14:29:02 +00:00
|
|
|
}, [&](const MTPDkeyboardButtonUrl &data) {
|
|
|
|
row.emplace_back(
|
|
|
|
Type::Url,
|
2019-07-05 13:38:38 +00:00
|
|
|
qs(data.vtext()),
|
|
|
|
qba(data.vurl()));
|
2019-05-22 14:29:02 +00:00
|
|
|
}, [&](const MTPDkeyboardButtonSwitchInline &data) {
|
|
|
|
const auto type = data.is_same_peer()
|
|
|
|
? Type::SwitchInlineSame
|
|
|
|
: Type::SwitchInline;
|
2019-07-05 13:38:38 +00:00
|
|
|
row.emplace_back(type, qs(data.vtext()), qba(data.vquery()));
|
2019-05-22 14:29:02 +00:00
|
|
|
if (type == Type::SwitchInline) {
|
|
|
|
// Optimization flag.
|
|
|
|
// Fast check on all new messages if there is a switch button to auto-click it.
|
|
|
|
flags |= MTPDreplyKeyboardMarkup_ClientFlag::f_has_switch_inline_button;
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
2019-05-22 14:29:02 +00:00
|
|
|
}, [&](const MTPDkeyboardButtonGame &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
row.emplace_back(Type::Game, qs(data.vtext()));
|
2019-05-22 14:29:02 +00:00
|
|
|
}, [&](const MTPDkeyboardButtonBuy &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
row.emplace_back(Type::Buy, qs(data.vtext()));
|
2019-05-22 14:29:02 +00:00
|
|
|
}, [&](const MTPDkeyboardButtonUrlAuth &data) {
|
|
|
|
row.emplace_back(
|
|
|
|
Type::Auth,
|
2019-07-05 13:38:38 +00:00
|
|
|
qs(data.vtext()),
|
|
|
|
qba(data.vurl()),
|
|
|
|
qs(data.vfwd_text().value_or_empty()),
|
|
|
|
data.vbutton_id().v);
|
2019-05-22 14:29:02 +00:00
|
|
|
}, [&](const MTPDinputKeyboardButtonUrlAuth &data) {
|
|
|
|
LOG(("API Error: inputKeyboardButtonUrlAuth received."));
|
|
|
|
// Should not get those for the users.
|
|
|
|
});
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
2019-05-22 14:29:02 +00:00
|
|
|
if (!row.empty()) {
|
|
|
|
rows.push_back(std::move(row));
|
|
|
|
}
|
|
|
|
});
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessageReplyMarkup::create(const MTPReplyMarkup &markup) {
|
|
|
|
flags = 0;
|
|
|
|
rows.clear();
|
|
|
|
inlineKeyboard = nullptr;
|
|
|
|
|
|
|
|
switch (markup.type()) {
|
|
|
|
case mtpc_replyKeyboardMarkup: {
|
|
|
|
auto &d = markup.c_replyKeyboardMarkup();
|
2019-07-05 13:38:38 +00:00
|
|
|
flags = d.vflags().v;
|
2017-12-18 15:44:50 +00:00
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
createFromButtonRows(d.vrows().v);
|
2017-12-18 15:44:50 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_replyInlineMarkup: {
|
|
|
|
auto &d = markup.c_replyInlineMarkup();
|
|
|
|
flags = MTPDreplyKeyboardMarkup::Flags(0) | MTPDreplyKeyboardMarkup_ClientFlag::f_inline;
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
createFromButtonRows(d.vrows().v);
|
2017-12-18 15:44:50 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_replyKeyboardHide: {
|
|
|
|
auto &d = markup.c_replyKeyboardHide();
|
2019-07-05 13:38:38 +00:00
|
|
|
flags = mtpCastFlags(d.vflags()) | MTPDreplyKeyboardMarkup_ClientFlag::f_zero;
|
2017-12-18 15:44:50 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_replyKeyboardForceReply: {
|
|
|
|
auto &d = markup.c_replyKeyboardForceReply();
|
2019-07-05 13:38:38 +00:00
|
|
|
flags = mtpCastFlags(d.vflags()) | MTPDreplyKeyboardMarkup_ClientFlag::f_force_reply;
|
2017-12-18 15:44:50 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessageReplyMarkup::create(
|
|
|
|
const HistoryMessageReplyMarkup &markup) {
|
|
|
|
flags = markup.flags;
|
|
|
|
inlineKeyboard = nullptr;
|
|
|
|
|
|
|
|
rows.clear();
|
2019-05-22 14:29:02 +00:00
|
|
|
rows.reserve(markup.rows.size());
|
2019-05-25 14:42:01 +00:00
|
|
|
using Type = HistoryMessageMarkupButton::Type;
|
2019-05-22 14:29:02 +00:00
|
|
|
for (const auto &existing : markup.rows) {
|
|
|
|
auto row = std::vector<Button>();
|
|
|
|
row.reserve(existing.size());
|
|
|
|
for (const auto &button : existing) {
|
2019-05-25 14:42:01 +00:00
|
|
|
const auto newType = (button.type != Type::SwitchInlineSame)
|
|
|
|
? button.type
|
|
|
|
: Type::SwitchInline;
|
2019-05-27 13:26:12 +00:00
|
|
|
const auto text = button.forwardText.isEmpty()
|
|
|
|
? button.text
|
|
|
|
: button.forwardText;
|
2019-05-22 14:29:02 +00:00
|
|
|
row.emplace_back(
|
2019-05-25 14:42:01 +00:00
|
|
|
newType,
|
2019-05-27 13:26:12 +00:00
|
|
|
text,
|
2019-05-22 14:29:02 +00:00
|
|
|
button.data,
|
2019-05-27 13:26:12 +00:00
|
|
|
QString(),
|
2019-05-22 14:29:02 +00:00
|
|
|
button.buttonId);
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
2019-05-22 14:29:02 +00:00
|
|
|
if (!row.empty()) {
|
|
|
|
rows.push_back(std::move(row));
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryMessageLogEntryOriginal::HistoryMessageLogEntryOriginal() = default;
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
HistoryMessageLogEntryOriginal::HistoryMessageLogEntryOriginal(
|
|
|
|
HistoryMessageLogEntryOriginal &&other)
|
|
|
|
: page(std::move(other.page)) {
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
HistoryMessageLogEntryOriginal &HistoryMessageLogEntryOriginal::operator=(
|
|
|
|
HistoryMessageLogEntryOriginal &&other) {
|
|
|
|
page = std::move(other.page);
|
2017-12-18 15:44:50 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryMessageLogEntryOriginal::~HistoryMessageLogEntryOriginal() = default;
|
|
|
|
|
|
|
|
HistoryDocumentCaptioned::HistoryDocumentCaptioned()
|
|
|
|
: _caption(st::msgFileMinWidth - st::msgPadding.left() - st::msgPadding.right()) {
|
|
|
|
}
|
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
HistoryDocumentVoicePlayback::HistoryDocumentVoicePlayback(
|
2019-08-02 13:21:09 +00:00
|
|
|
const HistoryView::Document *that)
|
2019-04-01 17:44:54 +00:00
|
|
|
: progress(0., 0.)
|
|
|
|
, progressAnimation([=](crl::time now) {
|
2019-08-02 13:21:09 +00:00
|
|
|
const auto nonconst = const_cast<HistoryView::Document*>(that);
|
2019-04-01 17:44:54 +00:00
|
|
|
return nonconst->voiceProgressAnimationCallback(now);
|
|
|
|
}) {
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
void HistoryDocumentVoice::ensurePlayback(
|
2019-08-02 13:21:09 +00:00
|
|
|
const HistoryView::Document *that) const {
|
2017-12-18 15:44:50 +00:00
|
|
|
if (!_playback) {
|
|
|
|
_playback = std::make_unique<HistoryDocumentVoicePlayback>(that);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryDocumentVoice::checkPlaybackFinished() const {
|
2019-04-01 17:44:54 +00:00
|
|
|
if (_playback && !_playback->progressAnimation.animating()) {
|
2017-12-18 15:44:50 +00:00
|
|
|
_playback.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryDocumentVoice::startSeeking() {
|
|
|
|
_seeking = true;
|
|
|
|
_seekingCurrent = _seekingStart;
|
|
|
|
Media::Player::instance()->startSeeking(AudioMsgId::Type::Voice);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryDocumentVoice::stopSeeking() {
|
|
|
|
_seeking = false;
|
2019-02-28 21:03:25 +00:00
|
|
|
Media::Player::instance()->cancelSeeking(AudioMsgId::Type::Voice);
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|