2020-10-03 23:58:45 +03:00
# include "fernschreiberutils.h"
# include <QMap>
# include <QVariant>
FernschreiberUtils : : FernschreiberUtils ( QObject * parent ) : QObject ( parent )
{
}
2020-12-29 18:32:39 +03:00
QString FernschreiberUtils : : getMessageShortText ( TDLibWrapper * tdLibWrapper , const QVariantMap & messageContent , const bool isChannel , const qlonglong currentUserId , const QVariantMap & messageSender )
2020-10-03 23:58:45 +03:00
{
2020-11-25 02:23:38 +03:00
if ( messageContent . isEmpty ( ) ) {
return QString ( ) ;
}
2020-12-29 18:32:39 +03:00
const bool myself = ! isChannel & & ( messageSender . value ( " @type " ) . toString ( ) = = " messageSenderUser " & & messageSender . value ( " user_id " ) . toLongLong ( ) = = currentUserId ) ;
2020-10-03 23:58:45 +03:00
QString contentType = messageContent . value ( " @type " ) . toString ( ) ;
if ( contentType = = " messageText " ) {
return messageContent . value ( " text " ) . toMap ( ) . value ( " text " ) . toString ( ) ;
}
if ( contentType = = " messageSticker " ) {
return tr ( " Sticker: %1 " ) . arg ( messageContent . value ( " sticker " ) . toMap ( ) . value ( " emoji " ) . toString ( ) ) ;
}
if ( contentType = = " messagePhoto " ) {
return myself ? tr ( " sent a picture " , " myself " ) : tr ( " sent a picture " ) ;
}
if ( contentType = = " messageVideo " ) {
return myself ? tr ( " sent a video " , " myself " ) : tr ( " sent a video " ) ;
}
if ( contentType = = " messageAnimation " ) {
return myself ? tr ( " sent an animation " , " myself " ) : tr ( " sent an animation " ) ;
}
2020-11-27 23:13:55 +03:00
if ( contentType = = " messageAudio " ) {
return myself ? tr ( " sent an audio " , " myself " ) : tr ( " sent an audio " ) ;
}
2020-10-03 23:58:45 +03:00
if ( contentType = = " messageVoiceNote " ) {
return myself ? tr ( " sent a voice note " , " myself " ) : tr ( " sent a voice note " ) ;
}
if ( contentType = = " messageDocument " ) {
return myself ? tr ( " sent a document " , " myself " ) : tr ( " sent a document " ) ;
}
if ( contentType = = " messageLocation " ) {
return myself ? tr ( " sent a location " , " myself " ) : tr ( " sent a location " ) ;
}
if ( contentType = = " messageVenue " ) {
return myself ? tr ( " sent a venue " , " myself " ) : tr ( " sent a venue " ) ;
}
if ( contentType = = " messageContactRegistered " ) {
return myself ? tr ( " have registered with Telegram " , " myself " ) : tr ( " has registered with Telegram " ) ;
}
if ( contentType = = " messageChatJoinByLink " ) {
return myself ? tr ( " joined this chat " , " myself " ) : tr ( " joined this chat " ) ;
}
if ( contentType = = " messageChatAddMembers " ) {
2020-12-29 18:32:39 +03:00
if ( messageSender . value ( " @type " ) . toString ( ) = = " messageSenderUser " & & messageSender . value ( " user_id " ) . toLongLong ( ) = = messageContent . value ( " member_user_ids " ) . toList ( ) . at ( 0 ) . toLongLong ( ) ) {
return myself ? tr ( " were added to this chat " , " myself " ) : tr ( " was added to this chat " ) ;
} else {
QVariantList memberUserIds = messageContent . value ( " member_user_ids " ) . toList ( ) ;
QString addedUserNames ;
for ( int i = 0 ; i < memberUserIds . size ( ) ; i + + ) {
if ( i > 0 ) {
addedUserNames + = " , " ;
}
addedUserNames + = getUserName ( tdLibWrapper - > getUserInformation ( memberUserIds . at ( i ) . toString ( ) ) ) ;
}
return myself ? tr ( " have added %1 to the chat " , " myself " ) . arg ( addedUserNames ) : tr ( " has added %1 to the chat " ) . arg ( addedUserNames ) ;
}
2020-10-03 23:58:45 +03:00
}
if ( contentType = = " messageChatDeleteMember " ) {
2020-12-29 18:32:39 +03:00
if ( messageSender . value ( " @type " ) . toString ( ) = = " messageSenderUser " & & messageSender . value ( " user_id " ) . toLongLong ( ) = = messageContent . value ( " user_id " ) . toLongLong ( ) ) {
return myself ? tr ( " left this chat " , " myself " ) : tr ( " left this chat " ) ;
} else {
return myself ? tr ( " have removed %1 from the chat " , " myself " ) . arg ( getUserName ( tdLibWrapper - > getUserInformation ( messageContent . value ( " user_id " ) . toString ( ) ) ) ) : tr ( " has removed %1 from the chat " ) . arg ( getUserName ( tdLibWrapper - > getUserInformation ( messageContent . value ( " user_id " ) . toString ( ) ) ) ) ;
}
2020-10-03 23:58:45 +03:00
}
2020-10-19 13:20:02 +03:00
if ( contentType = = " messageChatChangeTitle " ) {
return myself ? tr ( " changed the chat title " , " myself " ) : tr ( " changed the chat title " ) ;
}
2020-10-23 11:29:50 +03:00
if ( contentType = = " messagePoll " ) {
if ( messageContent . value ( " poll " ) . toMap ( ) . value ( " type " ) . toMap ( ) . value ( " @type " ) . toString ( ) = = " pollTypeQuiz " ) {
return myself ? tr ( " sent a quiz " , " myself " ) : tr ( " sent a quiz " ) ;
}
return myself ? tr ( " sent a poll " , " myself " ) : tr ( " sent a poll " ) ;
}
2020-11-05 16:06:41 +03:00
if ( contentType = = " messageBasicGroupChatCreate " | | contentType = = " messageSupergroupChatCreate " ) {
return myself ? tr ( " created this group " , " myself " ) : tr ( " created this group " ) ;
}
if ( contentType = = " messageChatChangePhoto " ) {
return myself ? tr ( " changed the chat photo " , " myself " ) : tr ( " changed the chat photo " ) ;
}
if ( contentType = = " messageChatDeletePhoto " ) {
return myself ? tr ( " deleted the chat photo " , " myself " ) : tr ( " deleted the chat photo " ) ;
}
if ( contentType = = " messageChatSetTtl " ) {
return myself ? tr ( " changed the secret chat TTL setting " , " myself " ) : tr ( " changed the secret chat TTL setting " ) ;
}
if ( contentType = = " messageChatUpgradeFrom " | | contentType = = " messageChatUpgradeTo " ) {
return myself ? tr ( " upgraded this group to a supergroup " , " myself " ) : tr ( " upgraded this group to a supergroup " ) ;
}
if ( contentType = = " messageCustomServiceAction " ) {
return messageContent . value ( " text " ) . toString ( ) ;
}
if ( contentType = = " messagePinMessage " ) {
return myself ? tr ( " changed the pinned message " , " myself " ) : tr ( " changed the pinned message " ) ;
}
if ( contentType = = " messageExpiredPhoto " ) {
return myself ? tr ( " sent a self-destructing photo that is expired " , " myself " ) : tr ( " sent a self-destructing photo that is expired " ) ;
}
if ( contentType = = " messageExpiredVideo " ) {
return myself ? tr ( " sent a self-destructing video that is expired " , " myself " ) : tr ( " sent a self-destructing video that is expired " ) ;
}
if ( contentType = = " messageScreenshotTaken " ) {
return myself ? tr ( " created a screenshot in this chat " , " myself " ) : tr ( " created a screenshot in this chat " ) ;
}
if ( contentType = = " messageUnsupported " ) {
return myself ? tr ( " sent an unsupported message " , " myself " ) : tr ( " sent an unsupported message " ) ;
}
return myself ? tr ( " sent an unsupported message: %1 " , " myself " ) . arg ( contentType . mid ( 7 ) ) : tr ( " sent an unsupported message: %1 " ) . arg ( contentType . mid ( 7 ) ) ;
2020-10-03 23:58:45 +03:00
}
2020-12-29 18:32:39 +03:00
QString FernschreiberUtils : : getUserName ( const QVariantMap & userInformation )
{
const QString firstName = userInformation . value ( " first_name " ) . toString ( ) ;
const QString lastName = userInformation . value ( " last_name " ) . toString ( ) ;
return QString ( firstName + " " + lastName ) . trimmed ( ) ;
}