mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
serverside links parsing used
This commit is contained in:
@@ -110,15 +110,17 @@ namespace {
|
||||
return item ? item->toHistoryForwarded() : 0;
|
||||
}
|
||||
inline const TextParseOptions &itemTextParseOptions(HistoryItem *item) {
|
||||
History *h = item->history();
|
||||
UserData *f = item->from();
|
||||
if ((!h->peer->chat && h->peer->asUser()->botInfo) || (!f->chat && f->asUser()->botInfo) || (h->peer->chat && h->peer->asChat()->botStatus >= 0)) {
|
||||
return _historyBotOptions;
|
||||
}
|
||||
return _historyTextOptions;
|
||||
return itemTextParseOptions(item->history(), item->from());
|
||||
}
|
||||
}
|
||||
|
||||
const TextParseOptions &itemTextParseOptions(History *h, UserData *f) {
|
||||
if ((!h->peer->chat && h->peer->asUser()->botInfo) || (!f->chat && f->asUser()->botInfo) || (h->peer->chat && h->peer->asChat()->botStatus >= 0)) {
|
||||
return _historyBotOptions;
|
||||
}
|
||||
return _historyTextOptions;
|
||||
}
|
||||
|
||||
void historyInit() {
|
||||
_initTextOptions();
|
||||
}
|
||||
@@ -1035,7 +1037,7 @@ void History::addToFront(const QVector<MTPMessage> &slice) {
|
||||
|
||||
int32 addToH = 0, skip = 0;
|
||||
if (!isEmpty()) {
|
||||
addToH = -front()->height;
|
||||
if (width) addToH = -front()->height;
|
||||
pop_front(); // remove date block
|
||||
}
|
||||
HistoryItem *till = isEmpty() ? 0 : front()->front(), *prev = 0;
|
||||
@@ -1049,12 +1051,16 @@ void History::addToFront(const QVector<MTPMessage> &slice) {
|
||||
if (prev && prev->date.date() != adding->date.date()) {
|
||||
HistoryItem *dayItem = createDayServiceMsg(this, block, adding->date);
|
||||
block->push_back(dayItem);
|
||||
dayItem->y = block->height;
|
||||
block->height += dayItem->resize(width);
|
||||
if (width) {
|
||||
dayItem->y = block->height;
|
||||
block->height += dayItem->resize(width);
|
||||
}
|
||||
}
|
||||
block->push_back(adding);
|
||||
adding->y = block->height;
|
||||
block->height += adding->resize(width);
|
||||
if (width) {
|
||||
adding->y = block->height;
|
||||
block->height += adding->resize(width);
|
||||
}
|
||||
setMsgCount(msgCount + 1);
|
||||
prev = adding;
|
||||
}
|
||||
@@ -1063,8 +1069,10 @@ void History::addToFront(const QVector<MTPMessage> &slice) {
|
||||
if (till && prev && prev->date.date() != till->date.date()) {
|
||||
HistoryItem *dayItem = createDayServiceMsg(this, block, till->date);
|
||||
block->push_back(dayItem);
|
||||
dayItem->y = block->height;
|
||||
block->height += dayItem->resize(width);
|
||||
if (width) {
|
||||
dayItem->y = block->height;
|
||||
block->height += dayItem->resize(width);
|
||||
}
|
||||
}
|
||||
if (block->size()) {
|
||||
if (loadedAtBottom() && wasMsgCount < unreadCount && msgCount >= unreadCount) {
|
||||
@@ -1079,8 +1087,10 @@ void History::addToFront(const QVector<MTPMessage> &slice) {
|
||||
}
|
||||
}
|
||||
push_front(block);
|
||||
addToH += block->height;
|
||||
++skip;
|
||||
if (width) {
|
||||
addToH += block->height;
|
||||
++skip;
|
||||
}
|
||||
|
||||
if (loadedAtBottom()) { // add photos to overview and authors to lastAuthors
|
||||
int32 mask = 0;
|
||||
@@ -1167,16 +1177,18 @@ void History::addToFront(const QVector<MTPMessage> &slice) {
|
||||
HistoryBlock *dateBlock = new HistoryBlock(this);
|
||||
HistoryItem *dayItem = createDayServiceMsg(this, dateBlock, front()->front()->date);
|
||||
dateBlock->push_back(dayItem);
|
||||
int32 dh = dayItem->resize(width);
|
||||
dateBlock->height = dh;
|
||||
if (skip) {
|
||||
front()->y += dh;
|
||||
if (width) {
|
||||
int32 dh = dayItem->resize(width);
|
||||
dateBlock->height = dh;
|
||||
if (skip) {
|
||||
front()->y += dh;
|
||||
}
|
||||
addToH += dh;
|
||||
++skip;
|
||||
}
|
||||
push_front(dateBlock); // date block
|
||||
addToH += dh;
|
||||
++skip;
|
||||
}
|
||||
if (addToH) {
|
||||
if (width && addToH) {
|
||||
for (iterator i = begin(), e = end(); i != e; ++i) {
|
||||
if (skip) {
|
||||
--skip;
|
||||
@@ -5026,7 +5038,7 @@ HistoryMessage::HistoryMessage(History *history, HistoryBlock *block, const MTPD
|
||||
QString text(textClean(qs(msg.vmessage)));
|
||||
initTime();
|
||||
initMedia(msg.vmedia, text);
|
||||
initDimensions(text, msg.has_entities() ? linksFromMTP(msg.ventities.c_vector().v) : LinksInText());
|
||||
setText(text, msg.has_entities() ? linksFromMTP(msg.ventities.c_vector().v) : LinksInText());
|
||||
}
|
||||
|
||||
HistoryMessage::HistoryMessage(History *history, HistoryBlock *block, MsgId msgId, int32 flags, QDateTime date, int32 from, const QString &msg, const LinksInText &links, const MTPMessageMedia &media) :
|
||||
@@ -5039,7 +5051,7 @@ HistoryItem(history, block, msgId, flags, date, from)
|
||||
QString text(msg);
|
||||
initTime();
|
||||
initMedia(media, text);
|
||||
initDimensions(text, links);
|
||||
setText(text, links);
|
||||
}
|
||||
|
||||
HistoryMessage::HistoryMessage(History *history, HistoryBlock *block, MsgId msgId, int32 flags, QDateTime date, int32 from, const QString &msg, const LinksInText &links, HistoryMedia *fromMedia) :
|
||||
@@ -5054,7 +5066,7 @@ HistoryItem(history, block, msgId, flags, date, from)
|
||||
_media = fromMedia->clone();
|
||||
_media->regItem(this);
|
||||
}
|
||||
initDimensions(msg, links);
|
||||
setText(msg, links);
|
||||
}
|
||||
|
||||
HistoryMessage::HistoryMessage(History *history, HistoryBlock *block, MsgId msgId, int32 flags, QDateTime date, int32 from, DocumentData *doc) :
|
||||
@@ -5066,7 +5078,7 @@ HistoryItem(history, block, msgId, flags, date, from)
|
||||
{
|
||||
initTime();
|
||||
initMediaFromDocument(doc);
|
||||
initDimensions(QString(), LinksInText());
|
||||
setText(QString(), LinksInText());
|
||||
}
|
||||
|
||||
void HistoryMessage::initTime() {
|
||||
@@ -5154,22 +5166,6 @@ void HistoryMessage::initMediaFromDocument(DocumentData *doc) {
|
||||
_media->regItem(this);
|
||||
}
|
||||
|
||||
void HistoryMessage::initDimensions(const QString &text, const LinksInText &links) {
|
||||
if (!_media || !text.isEmpty()) { // !justMedia()
|
||||
if (_media && _media->isDisplayed()) {
|
||||
_text.setMarkedText(st::msgFont, text, links, itemTextParseOptions(this));
|
||||
} else {
|
||||
_text.setMarkedText(st::msgFont, text + textcmdSkipBlock(timeWidth(true), st::msgDateFont->height - st::msgDateDelta.y()), links, itemTextParseOptions(this));
|
||||
}
|
||||
for (int32 i = 0, l = links.size(); i != l; ++i) {
|
||||
if (links.at(i).type == LinkInTextUrl || links.at(i).type == LinkInTextCustomUrl || links.at(i).type == LinkInTextEmail) {
|
||||
_flags |= MTPDmessage_flag_HAS_TEXT_LINKS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryMessage::initDimensions(const HistoryItem *parent) {
|
||||
if (justMedia()) {
|
||||
_media->initDimensions(this);
|
||||
@@ -5182,19 +5178,13 @@ void HistoryMessage::initDimensions(const HistoryItem *parent) {
|
||||
if (_media) {
|
||||
_media->initDimensions(this);
|
||||
if (_media->isDisplayed() && _text.hasSkipBlock()) {
|
||||
QString was = HistoryMessage::selectedText(FullItemSel);
|
||||
if (!was.isEmpty()) {
|
||||
_text.setText(st::msgFont, was, itemTextParseOptions(this)); // without date skip
|
||||
_textWidth = 0;
|
||||
_textHeight = 0;
|
||||
}
|
||||
_text.removeSkipBlock();
|
||||
_textWidth = 0;
|
||||
_textHeight = 0;
|
||||
} else if (!_media->isDisplayed() && !_text.hasSkipBlock()) {
|
||||
QString was = HistoryMessage::selectedText(FullItemSel);
|
||||
if (!was.isEmpty()) {
|
||||
_text.setText(st::msgFont, was + textcmdSkipBlock(timeWidth(true), st::msgDateFont->height - st::msgDateDelta.y()), itemTextParseOptions(this)); // without date skip
|
||||
_textWidth = 0;
|
||||
_textHeight = 0;
|
||||
}
|
||||
_text.setSkipBlock(timeWidth(true), st::msgDateFont->height - st::msgDateDelta.y());
|
||||
_textWidth = 0;
|
||||
_textHeight = 0;
|
||||
}
|
||||
if (_media->isDisplayed()) {
|
||||
int32 maxw = _media->maxWidth() + st::msgPadding.left() + st::msgPadding.right();
|
||||
@@ -5226,6 +5216,10 @@ QString HistoryMessage::selectedText(uint32 selection) const {
|
||||
return _text.original(selectedFrom, selectedTo);
|
||||
}
|
||||
|
||||
LinksInText HistoryMessage::textLinks() const {
|
||||
return _text.calcLinksInText();
|
||||
}
|
||||
|
||||
QString HistoryMessage::inDialogsText() const {
|
||||
QString result = _media ? _media->inDialogsText() : QString();
|
||||
return result.isEmpty() ? _text.original(0, 0xFFFF, false) : result;
|
||||
@@ -5237,6 +5231,7 @@ HistoryMedia *HistoryMessage::getMedia(bool inOverview) const {
|
||||
|
||||
void HistoryMessage::setMedia(const MTPmessageMedia &media) {
|
||||
if ((!_media || _media->isImageLink()) && media.type() == mtpc_messageMediaEmpty) return;
|
||||
|
||||
bool mediaWasDisplayed = false;
|
||||
if (_media) {
|
||||
mediaWasDisplayed = _media->isDisplayed();
|
||||
@@ -5246,24 +5241,38 @@ void HistoryMessage::setMedia(const MTPmessageMedia &media) {
|
||||
QString t;
|
||||
initMedia(media, t);
|
||||
if (_media && _media->isDisplayed() && !mediaWasDisplayed) {
|
||||
QString was = HistoryMessage::selectedText(FullItemSel);
|
||||
if (!was.isEmpty()) {
|
||||
_text.setText(st::msgFont, was, itemTextParseOptions(this)); // without date skip
|
||||
_textWidth = 0;
|
||||
_textHeight = 0;
|
||||
}
|
||||
_text.removeSkipBlock();
|
||||
_textWidth = 0;
|
||||
_textHeight = 0;
|
||||
} else if (mediaWasDisplayed && (!_media || !_media->isDisplayed())) {
|
||||
QString was = HistoryMessage::selectedText(FullItemSel);
|
||||
if (!was.isEmpty()) {
|
||||
_text.setText(st::msgFont, was + textcmdSkipBlock(timeWidth(true), st::msgDateFont->height - st::msgDateDelta.y()), itemTextParseOptions(this)); // without date skip
|
||||
_textWidth = 0;
|
||||
_textHeight = 0;
|
||||
}
|
||||
_text.setSkipBlock(timeWidth(true), st::msgDateFont->height - st::msgDateDelta.y());
|
||||
_textWidth = 0;
|
||||
_textHeight = 0;
|
||||
}
|
||||
initDimensions(0);
|
||||
if (App::main()) App::main()->itemResized(this);
|
||||
}
|
||||
|
||||
void HistoryMessage::setText(const QString &text, const LinksInText &links) {
|
||||
if (!_media || !text.isEmpty()) { // !justMedia()
|
||||
if (_media && _media->isDisplayed()) {
|
||||
_text.setMarkedText(st::msgFont, text, links, itemTextParseOptions(this));
|
||||
} else {
|
||||
_text.setMarkedText(st::msgFont, text + textcmdSkipBlock(timeWidth(true), st::msgDateFont->height - st::msgDateDelta.y()), links, itemTextParseOptions(this));
|
||||
}
|
||||
if (id > 0) {
|
||||
for (int32 i = 0, l = links.size(); i != l; ++i) {
|
||||
if (links.at(i).type == LinkInTextUrl || links.at(i).type == LinkInTextCustomUrl || links.at(i).type == LinkInTextEmail) {
|
||||
_flags |= MTPDmessage_flag_HAS_TEXT_LINKS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
_textWidth = 0;
|
||||
_textHeight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryMessage::draw(QPainter &p, uint32 selection) const {
|
||||
textstyleSet(&(out() ? st::outTextStyle : st::inTextStyle));
|
||||
|
||||
@@ -5368,6 +5377,8 @@ void HistoryMessage::drawMessageText(QPainter &p, const QRect &trect, uint32 sel
|
||||
}
|
||||
|
||||
int32 HistoryMessage::resize(int32 width, bool dontRecountText, const HistoryItem *parent) {
|
||||
if (width < st::msgMinWidth) return _height;
|
||||
|
||||
width -= st::msgMargin.left() + st::msgMargin.right();
|
||||
if (justMedia()) {
|
||||
_height = _media->resize(width, dontRecountText, this);
|
||||
@@ -5573,7 +5584,7 @@ HistoryMessage::~HistoryMessage() {
|
||||
}
|
||||
}
|
||||
|
||||
HistoryForwarded::HistoryForwarded(History *history, HistoryBlock *block, const MTPDmessage &msg) : HistoryMessage(history, block, msg.vid.v, msg.vflags.v, ::date(msg.vdate), msg.vfrom_id.v, textClean(qs(msg.vmessage)), msg.vmedia)
|
||||
HistoryForwarded::HistoryForwarded(History *history, HistoryBlock *block, const MTPDmessage &msg) : HistoryMessage(history, block, msg.vid.v, msg.vflags.v, ::date(msg.vdate), msg.vfrom_id.v, textClean(qs(msg.vmessage)), msg.has_entities() ? linksFromMTP(msg.ventities.c_vector().v) : LinksInText(), msg.vmedia)
|
||||
, fwdDate(::date(msg.vfwd_date))
|
||||
, fwdFrom(App::user(msg.vfwd_from_id.v))
|
||||
, fwdFromVersion(fwdFrom->nameVersion)
|
||||
@@ -5582,7 +5593,7 @@ HistoryForwarded::HistoryForwarded(History *history, HistoryBlock *block, const
|
||||
fwdNameUpdated();
|
||||
}
|
||||
|
||||
HistoryForwarded::HistoryForwarded(History *history, HistoryBlock *block, MsgId id, HistoryMessage *msg) : HistoryMessage(history, block, id, ((history->peer->input.type() != mtpc_inputPeerSelf) ? (MTPDmessage_flag_out | MTPDmessage_flag_unread) : 0) | (msg->getMedia() && (msg->getMedia()->type() == MediaTypeAudio/* || msg->getMedia()->type() == MediaTypeVideo*/) ? MTPDmessage_flag_media_unread : 0), ::date(unixtime()), MTP::authedId(), msg->justMedia() ? QString() : msg->HistoryMessage::selectedText(FullItemSel), msg->getMedia())
|
||||
HistoryForwarded::HistoryForwarded(History *history, HistoryBlock *block, MsgId id, HistoryMessage *msg) : HistoryMessage(history, block, id, ((history->peer->input.type() != mtpc_inputPeerSelf) ? (MTPDmessage_flag_out | MTPDmessage_flag_unread) : 0) | (msg->getMedia() && (msg->getMedia()->type() == MediaTypeAudio/* || msg->getMedia()->type() == MediaTypeVideo*/) ? MTPDmessage_flag_media_unread : 0), ::date(unixtime()), MTP::authedId(), msg->justMedia() ? QString() : msg->HistoryMessage::selectedText(FullItemSel), msg->HistoryMessage::textLinks(), msg->getMedia())
|
||||
, fwdDate(msg->dateForwarded())
|
||||
, fwdFrom(msg->fromForwarded())
|
||||
, fwdFromVersion(fwdFrom->nameVersion)
|
||||
@@ -5769,7 +5780,7 @@ void HistoryForwarded::getSymbol(uint16 &symbol, bool &after, bool &upon, int32
|
||||
return HistoryMessage::getSymbol(symbol, after, upon, x, y);
|
||||
}
|
||||
|
||||
HistoryReply::HistoryReply(History *history, HistoryBlock *block, const MTPDmessage &msg) : HistoryMessage(history, block, msg.vid.v, msg.vflags.v, ::date(msg.vdate), msg.vfrom_id.v, textClean(qs(msg.vmessage)), msg.vmedia)
|
||||
HistoryReply::HistoryReply(History *history, HistoryBlock *block, const MTPDmessage &msg) : HistoryMessage(history, block, msg.vid.v, msg.vflags.v, ::date(msg.vdate), msg.vfrom_id.v, textClean(qs(msg.vmessage)), msg.has_entities() ? linksFromMTP(msg.ventities.c_vector().v) : LinksInText(), msg.vmedia)
|
||||
, replyToMsgId(msg.vreply_to_msg_id.v)
|
||||
, replyToMsg(0)
|
||||
, replyToVersion(0)
|
||||
|
Reference in New Issue
Block a user