2016-09-27 14:20:49 +00:00
/*
This file is part of Telegram Desktop ,
the official desktop version of Telegram messaging app , see https : //telegram.org
Telegram Desktop is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
It is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
In addition , as a special exception , the copyright holders give permission
to link the code of portions of this program with the OpenSSL library .
Full license : https : //github.com/telegramdesktop/tdesktop/blob/master/LICENSE
2017-01-11 18:31:31 +00:00
Copyright ( c ) 2014 - 2017 John Preston , https : //desktop.telegram.org
2016-09-27 14:20:49 +00:00
*/
# pragma once
2017-06-22 15:11:41 +00:00
void HistoryInitMessages ( ) ;
base : : lambda < void ( ChannelData * , MsgId ) > HistoryDependentItemCallback ( const FullMsgId & msgId ) ;
2017-08-17 08:31:24 +00:00
MTPDmessage : : Flags NewMessageFlags ( not_null < PeerData * > peer ) ;
QString GetErrorTextForForward ( not_null < PeerData * > peer , const SelectedItemSet & items ) ;
void FastShareMessage ( not_null < HistoryItem * > item ) ;
2016-09-27 14:20:49 +00:00
class HistoryMessage : public HistoryItem , private HistoryItemInstantiated < HistoryMessage > {
public :
2017-08-17 08:31:24 +00:00
static not_null < HistoryMessage * > create ( not_null < History * > history , const MTPDmessage & msg ) {
2016-09-27 14:20:49 +00:00
return _create ( history , msg ) ;
}
2017-08-17 08:31:24 +00:00
static not_null < HistoryMessage * > create ( not_null < History * > history , const MTPDmessageService & msg ) {
2017-04-27 21:17:00 +00:00
return _create ( history , msg ) ;
}
2017-08-17 08:31:24 +00:00
static not_null < HistoryMessage * > create ( not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , QDateTime date , UserId from , const QString & postAuthor , not_null < HistoryMessage * > fwd ) {
2017-07-12 19:14:20 +00:00
return _create ( history , msgId , flags , date , from , postAuthor , fwd ) ;
2016-09-27 14:20:49 +00:00
}
2017-08-17 08:31:24 +00:00
static not_null < HistoryMessage * > create ( not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , UserId viaBotId , QDateTime date , UserId from , const QString & postAuthor , const TextWithEntities & textWithEntities ) {
2017-07-12 19:14:20 +00:00
return _create ( history , msgId , flags , replyTo , viaBotId , date , from , postAuthor , textWithEntities ) ;
2016-09-27 14:20:49 +00:00
}
2017-08-17 08:31:24 +00:00
static not_null < HistoryMessage * > create ( not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , UserId viaBotId , QDateTime date , UserId from , const QString & postAuthor , DocumentData * doc , const QString & caption , const MTPReplyMarkup & markup ) {
2017-07-12 19:14:20 +00:00
return _create ( history , msgId , flags , replyTo , viaBotId , date , from , postAuthor , doc , caption , markup ) ;
2016-09-27 14:20:49 +00:00
}
2017-08-17 08:31:24 +00:00
static not_null < HistoryMessage * > create ( not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , UserId viaBotId , QDateTime date , UserId from , const QString & postAuthor , PhotoData * photo , const QString & caption , const MTPReplyMarkup & markup ) {
2017-07-12 19:14:20 +00:00
return _create ( history , msgId , flags , replyTo , viaBotId , date , from , postAuthor , photo , caption , markup ) ;
2016-09-27 14:20:49 +00:00
}
2017-08-17 08:31:24 +00:00
static not_null < HistoryMessage * > create ( not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , UserId viaBotId , QDateTime date , UserId from , const QString & postAuthor , GameData * game , const MTPReplyMarkup & markup ) {
2017-07-12 19:14:20 +00:00
return _create ( history , msgId , flags , replyTo , viaBotId , date , from , postAuthor , game , markup ) ;
2016-09-28 16:23:25 +00:00
}
2016-09-27 14:20:49 +00:00
void initTime ( ) ;
2016-09-28 11:38:35 +00:00
void initMedia ( const MTPMessageMedia * media ) ;
2016-09-27 14:20:49 +00:00
void initMediaFromDocument ( DocumentData * doc , const QString & caption ) ;
void fromNameUpdated ( int32 width ) const ;
int32 plainMaxWidth ( ) const ;
2017-06-21 08:53:14 +00:00
QRect countGeometry ( ) const ;
2016-09-27 14:20:49 +00:00
2017-06-20 19:48:53 +00:00
bool drawBubble ( ) const ;
2016-09-27 14:20:49 +00:00
bool hasBubble ( ) const override {
return drawBubble ( ) ;
}
bool displayFromName ( ) const {
if ( ! hasFromName ( ) ) return false ;
if ( isAttachedToPrevious ( ) ) return false ;
2017-02-09 14:34:19 +00:00
return true ;
2016-09-27 14:20:49 +00:00
}
2016-10-07 07:58:34 +00:00
bool displayEditedBadge ( bool hasViaBotOrInlineMarkup ) const ;
2017-06-22 15:11:41 +00:00
bool uploading ( ) const ;
2017-07-11 17:11:06 +00:00
bool displayFastShare ( ) const override ;
2016-09-27 14:20:49 +00:00
void drawInfo ( Painter & p , int32 right , int32 bottom , int32 width , bool selected , InfoDisplayType type ) const override ;
2017-07-11 17:11:06 +00:00
void drawFastShare ( Painter & p , int left , int top , int outerWidth ) const override ;
2016-09-27 14:20:49 +00:00
void setViewsCount ( int32 count ) override ;
void setId ( MsgId newId ) override ;
2017-06-21 08:53:14 +00:00
void draw ( Painter & p , QRect clip , TextSelection selection , TimeMs ms ) const override ;
2017-07-11 17:11:06 +00:00
ClickHandlerPtr fastShareLink ( ) const override ;
2016-09-27 14:20:49 +00:00
void dependencyItemRemoved ( HistoryItem * dependency ) override ;
2017-06-21 21:38:31 +00:00
bool hasPoint ( QPoint point ) const override ;
bool pointInTime ( int right , int bottom , QPoint point , InfoDisplayType type ) const override ;
2016-09-27 14:20:49 +00:00
2017-06-21 21:38:31 +00:00
HistoryTextState getState ( QPoint point , HistoryStateRequest request ) const override ;
void updatePressed ( QPoint point ) override ;
2016-09-27 14:20:49 +00:00
TextSelection adjustSelection ( TextSelection selection , TextSelectType type ) const override ;
// ClickHandlerHost interface
2017-06-22 15:11:41 +00:00
void clickHandlerActiveChanged ( const ClickHandlerPtr & p , bool active ) override ;
void clickHandlerPressedChanged ( const ClickHandlerPtr & p , bool pressed ) override ;
2016-09-27 14:20:49 +00:00
QString notificationHeader ( ) const override ;
void applyEdition ( const MTPDmessage & message ) override ;
void applyEdition ( const MTPDmessageService & message ) override ;
void updateMedia ( const MTPMessageMedia * media ) override ;
2016-10-20 15:26:55 +00:00
void updateReplyMarkup ( const MTPReplyMarkup * markup ) override {
setReplyMarkup ( markup ) ;
}
2017-09-04 11:40:02 +00:00
2016-09-27 14:20:49 +00:00
int32 addToOverview ( AddToOverviewMethod method ) override ;
void eraseFromOverview ( ) override ;
2017-09-04 11:40:02 +00:00
Storage : : SharedMediaTypesMask sharedMediaTypes ( ) const override ;
2016-09-27 14:20:49 +00:00
TextWithEntities selectedText ( TextSelection selection ) const override ;
void setText ( const TextWithEntities & textWithEntities ) override ;
TextWithEntities originalText ( ) const override ;
bool textHasLinks ( ) const override ;
2016-09-30 12:52:03 +00:00
int infoWidth ( ) const override ;
int timeLeft ( ) const override ;
int timeWidth ( ) const override {
2016-09-27 14:20:49 +00:00
return _timeWidth ;
}
2016-09-30 12:52:03 +00:00
int viewsCount ( ) const override {
if ( auto views = Get < HistoryMessageViews > ( ) ) {
2016-09-27 14:20:49 +00:00
return views - > _views ;
}
return HistoryItem : : viewsCount ( ) ;
}
bool updateDependencyItem ( ) override {
if ( auto reply = Get < HistoryMessageReply > ( ) ) {
return reply - > updateData ( this , true ) ;
}
return true ;
}
MsgId dependencyMsgId ( ) const override {
return replyToId ( ) ;
}
HistoryMessage * toHistoryMessage ( ) override { // dynamic_cast optimize
return this ;
}
const HistoryMessage * toHistoryMessage ( ) const override { // dynamic_cast optimize
return this ;
}
// hasFromPhoto() returns true even if we don't display the photo
// but we need to skip a place at the left side for this photo
bool displayFromPhoto ( ) const ;
bool hasFromPhoto ( ) const ;
~ HistoryMessage ( ) ;
private :
2017-08-17 08:31:24 +00:00
HistoryMessage ( not_null < History * > history , const MTPDmessage & msg ) ;
HistoryMessage ( not_null < History * > history , const MTPDmessageService & msg ) ;
HistoryMessage ( not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , QDateTime date , UserId from , const QString & postAuthor , not_null < HistoryMessage * > fwd ) ; // local forwarded
HistoryMessage ( not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , UserId viaBotId , QDateTime date , UserId from , const QString & postAuthor , const TextWithEntities & textWithEntities ) ; // local message
HistoryMessage ( not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , UserId viaBotId , QDateTime date , UserId from , const QString & postAuthor , DocumentData * doc , const QString & caption , const MTPReplyMarkup & markup ) ; // local document
HistoryMessage ( not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , UserId viaBotId , QDateTime date , UserId from , const QString & postAuthor , PhotoData * photo , const QString & caption , const MTPReplyMarkup & markup ) ; // local photo
HistoryMessage ( not_null < History * > history , MsgId msgId , MTPDmessage : : Flags flags , MsgId replyTo , UserId viaBotId , QDateTime date , UserId from , const QString & postAuthor , GameData * game , const MTPReplyMarkup & markup ) ; // local game
2016-09-27 14:20:49 +00:00
friend class HistoryItemInstantiated < HistoryMessage > ;
void setEmptyText ( ) ;
2017-03-06 15:00:59 +00:00
// For an invoice button we replace the button text with a "Receipt" key.
// It should show the receipt for the payed invoice. Still let mobile apps do that.
void replaceBuyWithReceiptInMarkup ( ) ;
2016-09-27 14:20:49 +00:00
void initDimensions ( ) override ;
2017-06-21 08:53:14 +00:00
int resizeContentGetHeight ( ) override ;
int performResizeGetHeight ( ) ;
2016-09-27 14:20:49 +00:00
void applyEditionToEmpty ( ) ;
2017-06-22 15:11:41 +00:00
bool displayForwardedFrom ( ) const ;
2016-09-27 14:20:49 +00:00
void paintFromName ( Painter & p , QRect & trect , bool selected ) const ;
void paintForwardedInfo ( Painter & p , QRect & trect , bool selected ) const ;
void paintReplyInfo ( Painter & p , QRect & trect , bool selected ) const ;
// this method draws "via @bot" if it is not painted in forwarded info or in from name
void paintViaBotIdInfo ( Painter & p , QRect & trect , bool selected ) const ;
void paintText ( Painter & p , QRect & trect , TextSelection selection ) const ;
2017-06-21 21:38:31 +00:00
bool getStateFromName ( QPoint point , QRect & trect , HistoryTextState * outResult ) const ;
bool getStateForwardedInfo ( QPoint point , QRect & trect , HistoryTextState * outResult , const HistoryStateRequest & request ) const ;
bool getStateReplyInfo ( QPoint point , QRect & trect , HistoryTextState * outResult ) const ;
bool getStateViaBotIdInfo ( QPoint point , QRect & trect , HistoryTextState * outResult ) const ;
bool getStateText ( QPoint point , QRect & trect , HistoryTextState * outResult , const HistoryStateRequest & request ) const ;
2016-09-28 10:15:03 +00:00
2016-09-27 14:20:49 +00:00
void setMedia ( const MTPMessageMedia * media ) ;
void setReplyMarkup ( const MTPReplyMarkup * markup ) ;
QString _timeText ;
int _timeWidth = 0 ;
2017-07-11 17:11:06 +00:00
mutable ClickHandlerPtr _fastShareLink ;
2016-09-27 14:20:49 +00:00
struct CreateConfig {
MsgId replyTo = 0 ;
UserId viaBotId = 0 ;
int viewsCount = - 1 ;
2017-07-12 19:14:20 +00:00
QString author ;
2017-07-26 06:05:06 +00:00
PeerId senderOriginal = 0 ;
2016-09-27 14:20:49 +00:00
MsgId originalId = 0 ;
2017-07-12 19:14:20 +00:00
QString authorOriginal ;
2017-06-20 22:05:38 +00:00
QDateTime originalDate ;
2016-09-27 14:20:49 +00:00
QDateTime editDate ;
2016-10-07 07:58:34 +00:00
// For messages created from MTP structs.
const MTPReplyMarkup * mtpMarkup = nullptr ;
// For messages created from existing messages (forwarded).
const HistoryMessageReplyMarkup * inlineMarkup = nullptr ;
2016-09-27 14:20:49 +00:00
} ;
2017-07-12 19:14:20 +00:00
void createComponentsHelper ( MTPDmessage : : Flags flags , MsgId replyTo , UserId viaBotId , const QString & postAuthor , const MTPReplyMarkup & markup ) ;
2016-09-27 14:20:49 +00:00
void createComponents ( const CreateConfig & config ) ;
class KeyboardStyle : public ReplyKeyboard : : Style {
public :
using ReplyKeyboard : : Style : : Style ;
2016-11-16 16:04:25 +00:00
int buttonRadius ( ) const override ;
2016-09-27 14:20:49 +00:00
void startPaint ( Painter & p ) const override ;
2016-12-23 13:21:01 +00:00
const style : : TextStyle & textStyle ( ) const override ;
2017-08-17 08:31:24 +00:00
void repaint ( not_null < const HistoryItem * > item ) const override ;
2016-09-27 14:20:49 +00:00
protected :
2016-11-16 16:04:25 +00:00
void paintButtonBg ( Painter & p , const QRect & rect , float64 howMuchOver ) const override ;
2016-10-26 12:24:21 +00:00
void paintButtonIcon ( Painter & p , const QRect & rect , int outerWidth , HistoryMessageReplyMarkup : : Button : : Type type ) const override ;
2016-09-27 14:20:49 +00:00
void paintButtonLoading ( Painter & p , const QRect & rect ) const override ;
int minButtonWidth ( HistoryMessageReplyMarkup : : Button : : Type type ) const override ;
} ;
2016-09-28 10:15:03 +00:00
void updateMediaInBubbleState ( ) ;
2016-09-27 14:20:49 +00:00
} ;