new media unsupported message and via @inlinebot are added to langs, links don't break on / now, cancel upload langs fixed

This commit is contained in:
John Preston 2016-01-07 17:49:54 +08:00
parent 709c18e6fc
commit 3078544892
6 changed files with 61 additions and 49 deletions

View File

@ -498,7 +498,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
"lng_sure_delete_group" = "Are you sure, you want to delete this group? All members will be removed and all messages will be lost."; "lng_sure_delete_group" = "Are you sure, you want to delete this group? All members will be removed and all messages will be lost.";
"lng_message_empty" = "Empty Message"; "lng_message_empty" = "Empty Message";
"lng_media_unsupported" = "Media Unsupported"; "lng_message_unsupported" = "This message is not supported by your version of Telegram Desktop. Please update to the last version in Settings or install it from {link}";
"lng_action_add_user" = "{from} added {user}"; "lng_action_add_user" = "{from} added {user}";
"lng_action_add_users_many" = "{from} added {users}"; "lng_action_add_users_many" = "{from} added {users}";
@ -600,6 +600,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
"lng_saved_gifs" = "Saved GIFs"; "lng_saved_gifs" = "Saved GIFs";
"lng_inline_bot_results" = "Results from {inline_bot}"; "lng_inline_bot_results" = "Results from {inline_bot}";
"lng_inline_bot_no_results" = "No results"; "lng_inline_bot_no_results" = "No results";
"lng_inline_bot_via" = "via {inline_bot}";
"lng_box_remove" = "Remove"; "lng_box_remove" = "Remove";
@ -793,7 +794,8 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
"lng_selected_delete" = "Delete"; "lng_selected_delete" = "Delete";
"lng_selected_forward" = "Forward"; "lng_selected_forward" = "Forward";
"lng_selected_count" = "{count:_not_used_|# message|# messages}"; "lng_selected_count" = "{count:_not_used_|# message|# messages}";
"lng_selected_cancel_sure_this" = "Do you want to cancel this upload?"; "lng_selected_cancel_sure_this" = "Cancel uploading?";
"lng_selected_upload_stop" = "Stop";
"lng_selected_delete_sure_this" = "Do you want to delete this message?"; "lng_selected_delete_sure_this" = "Do you want to delete this message?";
"lng_selected_delete_sure" = "Do you want to delete {count:_not_used_|# message|# messages}?"; "lng_selected_delete_sure" = "Do you want to delete {count:_not_used_|# message|# messages}?";
"lng_box_delete" = "Delete"; "lng_box_delete" = "Delete";

View File

@ -3156,7 +3156,8 @@ namespace {
class BlockParser { class BlockParser {
public: public:
BlockParser(QTextEngine *e, TextBlock *b, QFixed minResizeWidth, int32 blockFrom) : block(b), eng(e) { BlockParser(QTextEngine *e, TextBlock *b, QFixed minResizeWidth, int32 blockFrom, const QString &str)
: block(b), eng(e), str(str) {
parseWords(minResizeWidth, blockFrom); parseWords(minResizeWidth, blockFrom);
} }
@ -3234,7 +3235,7 @@ public:
if (lbh.currentPosition >= eng->layoutData->string.length() if (lbh.currentPosition >= eng->layoutData->string.length()
|| attributes[lbh.currentPosition].whiteSpace || attributes[lbh.currentPosition].whiteSpace
|| attributes[lbh.currentPosition].lineBreak) { || isLineBreak(attributes, lbh.currentPosition)) {
lbh.adjustRightBearing(); lbh.adjustRightBearing();
block->_words.push_back(TextWord(wordStart + blockFrom, lbh.tmpData.textWidth, qMin(QFixed(), lbh.rightBearing))); block->_words.push_back(TextWord(wordStart + blockFrom, lbh.tmpData.textWidth, qMin(QFixed(), lbh.rightBearing)));
block->_width += lbh.tmpData.textWidth; block->_width += lbh.tmpData.textWidth;
@ -3281,10 +3282,19 @@ public:
} }
} }
bool isLineBreak(const QCharAttributes *attributes, int32 index) {
bool lineBreak = attributes[index].lineBreak;
if (lineBreak && block->lnkIndex() > 0 && index > 0 && str.at(index - 1) == '/') {
return false; // don't break after / in links
}
return lineBreak;
}
private: private:
TextBlock *block; TextBlock *block;
QTextEngine *eng; QTextEngine *eng;
const QString &str;
}; };
@ -3318,14 +3328,15 @@ TextBlock::TextBlock(const style::font &font, const QString &str, QFixed minResi
} }
} }
QStackTextEngine engine(str.mid(_from, length), blockFont->f); QString part = str.mid(_from, length);
QStackTextEngine engine(part, blockFont->f);
engine.itemize(); engine.itemize();
QTextLayout layout(&engine); QTextLayout layout(&engine);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
BlockParser parser(&engine, this, minResizeWidth, _from); BlockParser parser(&engine, this, minResizeWidth, _from, part);
layout.endLayout(); layout.endLayout();
} }

View File

@ -1390,10 +1390,13 @@ HistoryItem *History::createItem(HistoryBlock *block, const MTPMessage &msg, boo
case mtpc_messageMediaUnsupported: case mtpc_messageMediaUnsupported:
default: badMedia = 1; break; default: badMedia = 1; break;
} }
if (false && badMedia == 1) { if (badMedia == 1) {
// QString text(lng_message_unsupported(lt_link, qsl("https://desktop.telegram.org"))); QString text(lng_message_unsupported(lt_link, qsl("https://desktop.telegram.org")));
EntitiesInText entities = textParseEntities(text, _historyTextNoMonoOptions.flags);
entities.push_front(EntityInText(EntityInTextItalic, 0, text.size()));
result = new HistoryMessage(this, block, m.vid.v, m.vflags.v, m.vvia_bot_id.v, date(m.vdate), m.vfrom_id.v, text, entities, 0);
} else if (badMedia) { } else if (badMedia) {
result = new HistoryServiceMsg(this, block, m.vid.v, date(m.vdate), lang((badMedia == 2) ? lng_message_empty : lng_media_unsupported), m.vflags.v, 0, m.has_from_id() ? m.vfrom_id.v : 0); result = new HistoryServiceMsg(this, block, m.vid.v, date(m.vdate), lang(lng_message_empty), m.vflags.v, 0, m.has_from_id() ? m.vfrom_id.v : 0);
} else { } else {
if ((m.has_fwd_date() && m.vfwd_date.v > 0) || (m.has_fwd_from_id() && peerFromMTP(m.vfwd_from_id) != 0)) { if ((m.has_fwd_date() && m.vfwd_date.v > 0) || (m.has_fwd_from_id() && peerFromMTP(m.vfwd_from_id) != 0)) {
result = new HistoryForwarded(this, block, m); result = new HistoryForwarded(this, block, m);
@ -5979,10 +5982,10 @@ void ViaInlineBotLink::onClick(Qt::MouseButton button) const {
} }
HistoryMessageVia::HistoryMessageVia(int32 userId) HistoryMessageVia::HistoryMessageVia(int32 userId)
: bot(App::userLoaded(peerFromUser(userId))) : bot(App::userLoaded(peerFromUser(userId)))
, width(0) , width(0)
, maxWidth(st::msgServiceNameFont->width(qsl("via @") + bot->username)) , maxWidth(bot ? st::msgServiceNameFont->width(lng_inline_bot_via(lt_inline_bot, '@' + bot->username)) : 0)
, lnk(new ViaInlineBotLink(bot)) { , lnk(new ViaInlineBotLink(bot)) {
} }
bool HistoryMessageVia::isNull() const { bool HistoryMessageVia::isNull() const {
@ -5990,21 +5993,16 @@ bool HistoryMessageVia::isNull() const {
} }
void HistoryMessageVia::resize(int32 availw) { void HistoryMessageVia::resize(int32 availw) {
if (width < maxWidth && availw > width) { if (availw < 0) {
if (availw < maxWidth) {
text = st::msgServiceNameFont->elided(qsl("via @") + bot->username, availw);
width = st::msgServiceNameFont->width(text);
} else {
text = qsl("via @") + bot->username;
width = maxWidth;
}
} else if (availw < width) {
if (availw > 0) {
text = st::msgServiceNameFont->elided(qsl("via @") + bot->username, availw);
width = st::msgServiceNameFont->width(text);
} else {
text = QString(); text = QString();
width = 0; width = 0;
} else {
text = lng_inline_bot_via(lt_inline_bot, '@' + bot->username);
if (availw < maxWidth) {
text = st::msgServiceNameFont->elided(text, availw);
width = st::msgServiceNameFont->width(text);
} else if (width < maxWidth) {
width = maxWidth;
} }
} }
} }
@ -6024,11 +6022,11 @@ HistoryMessage::HistoryMessage(History *history, HistoryBlock *block, const MTPD
} }
HistoryMessage::HistoryMessage(History *history, HistoryBlock *block, MsgId msgId, int32 flags, int32 viaBotId, QDateTime date, int32 from, const QString &msg, const EntitiesInText &entities, HistoryMedia *fromMedia) : HistoryMessage::HistoryMessage(History *history, HistoryBlock *block, MsgId msgId, int32 flags, int32 viaBotId, QDateTime date, int32 from, const QString &msg, const EntitiesInText &entities, HistoryMedia *fromMedia) :
HistoryItem(history, block, msgId, flags, date, from) HistoryItem(history, block, msgId, flags, date, (flags & MTPDmessage::flag_from_id) ? from : 0)
, _text(st::msgMinWidth) , _text(st::msgMinWidth)
, _textWidth(0) , _textWidth(0)
, _textHeight(0) , _textHeight(0)
, _via(viaBotId ? new HistoryMessageVia(viaBotId) : 0) , _via((flags & MTPDmessage::flag_via_bot_id) ? new HistoryMessageVia(viaBotId) : 0)
, _media(0) , _media(0)
, _views(fromChannel() ? 1 : -1) { , _views(fromChannel() ? 1 : -1) {
initTime(); initTime();
@ -6040,11 +6038,11 @@ HistoryItem(history, block, msgId, flags, date, from)
} }
HistoryMessage::HistoryMessage(History *history, HistoryBlock *block, MsgId msgId, int32 flags, int32 viaBotId, QDateTime date, int32 from, DocumentData *doc, const QString &caption) : HistoryMessage::HistoryMessage(History *history, HistoryBlock *block, MsgId msgId, int32 flags, int32 viaBotId, QDateTime date, int32 from, DocumentData *doc, const QString &caption) :
HistoryItem(history, block, msgId, flags, date, from) HistoryItem(history, block, msgId, flags, date, (flags & MTPDmessage::flag_from_id) ? from : 0)
, _text(st::msgMinWidth) , _text(st::msgMinWidth)
, _textWidth(0) , _textWidth(0)
, _textHeight(0) , _textHeight(0)
, _via(viaBotId ? new HistoryMessageVia(viaBotId) : 0) , _via((flags & MTPDmessage::flag_via_bot_id) ? new HistoryMessageVia(viaBotId) : 0)
, _media(0) , _media(0)
, _views(fromChannel() ? 1 : -1) { , _views(fromChannel() ? 1 : -1) {
initTime(); initTime();
@ -6053,11 +6051,11 @@ HistoryItem(history, block, msgId, flags, date, from)
} }
HistoryMessage::HistoryMessage(History *history, HistoryBlock *block, MsgId msgId, int32 flags, int32 viaBotId, QDateTime date, int32 from, PhotoData *photo, const QString &caption) : HistoryMessage::HistoryMessage(History *history, HistoryBlock *block, MsgId msgId, int32 flags, int32 viaBotId, QDateTime date, int32 from, PhotoData *photo, const QString &caption) :
HistoryItem(history, block, msgId, flags, date, from) HistoryItem(history, block, msgId, flags, date, (flags & MTPDmessage::flag_from_id) ? from : 0)
, _text(st::msgMinWidth) , _text(st::msgMinWidth)
, _textWidth(0) , _textWidth(0)
, _textHeight(0) , _textHeight(0)
, _via(viaBotId ? new HistoryMessageVia(viaBotId) : 0) , _via((flags & MTPDmessage::flag_via_bot_id) ? new HistoryMessageVia(viaBotId) : 0)
, _media(0) , _media(0)
, _views(fromChannel() ? 1 : -1) { , _views(fromChannel() ? 1 : -1) {
initTime(); initTime();

View File

@ -6368,11 +6368,11 @@ void HistoryWidget::onFieldTabbed() {
} }
void HistoryWidget::onStickerSend(DocumentData *sticker) { void HistoryWidget::onStickerSend(DocumentData *sticker) {
sendExistingDocument(sticker, QString(), 0); sendExistingDocument(sticker, QString());
} }
void HistoryWidget::onPhotoSend(PhotoData *photo) { void HistoryWidget::onPhotoSend(PhotoData *photo) {
sendExistingPhoto(photo, QString(), 0); sendExistingPhoto(photo, QString());
} }
void HistoryWidget::onInlineResultSend(InlineResult *result, UserData *bot) { void HistoryWidget::onInlineResultSend(InlineResult *result, UserData *bot) {
@ -6495,7 +6495,7 @@ void HistoryWidget::onInlineResultSend(InlineResult *result, UserData *bot) {
_field.setFocus(); _field.setFocus();
} }
void HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &caption, UserData *bot) { void HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &caption) {
if (!_history || !doc || !canSendMessages(_peer)) return; if (!_history || !doc || !canSendMessages(_peer)) return;
App::main()->readServerHistory(_history, false); App::main()->readServerHistory(_history, false);
@ -6519,7 +6519,7 @@ void HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &capti
} else { } else {
flags |= MTPDmessage::flag_from_id; flags |= MTPDmessage::flag_from_id;
} }
_history->addNewDocument(newId.msg, flags, bot ? peerToUser(bot->id) : 0, replyToId(), date(MTP_int(unixtime())), fromChannelName ? 0 : MTP::authedId(), doc, caption); _history->addNewDocument(newId.msg, flags, 0, replyToId(), date(MTP_int(unixtime())), fromChannelName ? 0 : MTP::authedId(), doc, caption);
_history->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_int(sendFlags), _peer->input, MTP_int(replyToId()), MTP_inputMediaDocument(MTP_inputDocument(MTP_long(doc->id), MTP_long(doc->access)), MTP_string(caption)), MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, _history->sendRequestId); _history->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_int(sendFlags), _peer->input, MTP_int(replyToId()), MTP_inputMediaDocument(MTP_inputDocument(MTP_long(doc->id), MTP_long(doc->access)), MTP_string(caption)), MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, _history->sendRequestId);
App::main()->finishForwarding(_history, _broadcast.checked()); App::main()->finishForwarding(_history, _broadcast.checked());
@ -6536,7 +6536,7 @@ void HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &capti
_field.setFocus(); _field.setFocus();
} }
void HistoryWidget::sendExistingPhoto(PhotoData *photo, const QString &caption, UserData *bot) { void HistoryWidget::sendExistingPhoto(PhotoData *photo, const QString &caption) {
if (!_history || !photo || !canSendMessages(_peer)) return; if (!_history || !photo || !canSendMessages(_peer)) return;
App::main()->readServerHistory(_history, false); App::main()->readServerHistory(_history, false);
@ -6560,7 +6560,7 @@ void HistoryWidget::sendExistingPhoto(PhotoData *photo, const QString &caption,
} else { } else {
flags |= MTPDmessage::flag_from_id; flags |= MTPDmessage::flag_from_id;
} }
_history->addNewPhoto(newId.msg, flags, bot ? peerToUser(bot->id) : 0, replyToId(), date(MTP_int(unixtime())), fromChannelName ? 0 : MTP::authedId(), photo, caption); _history->addNewPhoto(newId.msg, flags, 0, replyToId(), date(MTP_int(unixtime())), fromChannelName ? 0 : MTP::authedId(), photo, caption);
_history->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_int(sendFlags), _peer->input, MTP_int(replyToId()), MTP_inputMediaPhoto(MTP_inputPhoto(MTP_long(photo->id), MTP_long(photo->access)), MTP_string(caption)), MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, _history->sendRequestId); _history->sendRequestId = MTP::send(MTPmessages_SendMedia(MTP_int(sendFlags), _peer->input, MTP_int(replyToId()), MTP_inputMediaPhoto(MTP_inputPhoto(MTP_long(photo->id), MTP_long(photo->access)), MTP_string(caption)), MTP_long(randomId), MTPnullMarkup), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::sendMessageFail), 0, 0, _history->sendRequestId);
App::main()->finishForwarding(_history, _broadcast.checked()); App::main()->finishForwarding(_history, _broadcast.checked());

View File

@ -693,8 +693,8 @@ private:
IconedButton _replyForwardPreviewCancel; IconedButton _replyForwardPreviewCancel;
void updateReplyToName(); void updateReplyToName();
void sendExistingDocument(DocumentData *doc, const QString &caption, UserData *bot); void sendExistingDocument(DocumentData *doc, const QString &caption);
void sendExistingPhoto(PhotoData *photo, const QString &caption, UserData *bot); void sendExistingPhoto(PhotoData *photo, const QString &caption);
void drawField(Painter &p); void drawField(Painter &p);
void drawRecordButton(Painter &p); void drawRecordButton(Painter &p);

View File

@ -907,7 +907,8 @@ void MainWidget::forwardLayer(int32 forwardSelected) {
void MainWidget::deleteLayer(int32 selectedCount) { void MainWidget::deleteLayer(int32 selectedCount) {
QString str((selectedCount < 0) ? lang(selectedCount < -1 ? lng_selected_cancel_sure_this : lng_selected_delete_sure_this) : lng_selected_delete_sure(lt_count, selectedCount)); QString str((selectedCount < 0) ? lang(selectedCount < -1 ? lng_selected_cancel_sure_this : lng_selected_delete_sure_this) : lng_selected_delete_sure(lt_count, selectedCount));
ConfirmBox *box = new ConfirmBox((selectedCount < 0) ? str : str.arg(selectedCount), lang(lng_box_delete)); QString btn(lang((selectedCount < -1) ? lng_selected_upload_stop : lng_box_delete)), cancel(lang((selectedCount < -1) ? lng_continue : lng_cancel));
ConfirmBox *box = new ConfirmBox(str, btn, st::defaultBoxButton, cancel);
if (selectedCount < 0) { if (selectedCount < 0) {
if (selectedCount < -1) { if (selectedCount < -1) {
if (HistoryItem *item = App::contextItem()) { if (HistoryItem *item = App::contextItem()) {