TDLib 1.7: Sticker IDs, message sender IDs

This commit is contained in:
Sebastian Wolf 2020-12-07 21:43:09 +01:00
parent aafe7c1308
commit 63db26afc8
13 changed files with 64 additions and 30 deletions

View file

@ -36,8 +36,8 @@ Row {
onInReplyToMessageChanged: {
if (inReplyToMessage) {
inReplyToUserText.text = (inReplyToRow.inReplyToMessage.sender_user_id !== inReplyToRow.myUserId) ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(inReplyToRow.inReplyToMessage.sender_user_id)), inReplyToUserText.font.pixelSize) : qsTr("You");
inReplyToMessageText.text = Emoji.emojify(Functions.getMessageText(inReplyToRow.inReplyToMessage, true, inReplyToRow.inReplyToMessage.sender_user_id === inReplyToRow.myUserId, false), inReplyToMessageText.font.pixelSize);
inReplyToUserText.text = (inReplyToRow.inReplyToMessage.sender.user_id !== inReplyToRow.myUserId) ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(inReplyToRow.inReplyToMessage.sender.user_id)), inReplyToUserText.font.pixelSize) : qsTr("You");
inReplyToMessageText.text = Emoji.emojify(Functions.getMessageText(inReplyToRow.inReplyToMessage, true, inReplyToRow.inReplyToMessage.sender.user_id === inReplyToRow.myUserId, false), inReplyToMessageText.font.pixelSize);
}
}

View file

@ -28,7 +28,7 @@ ListItem {
property var chatId
property var messageId
property var myMessage
readonly property var userInformation: tdLibWrapper.getUserInformation(myMessage.sender_user_id)
readonly property var userInformation: tdLibWrapper.getUserInformation(myMessage.sender.user_id)
property QtObject precalculatedValues: ListView.view.precalculatedValues
readonly property color textColor: isOwnMessage ? Theme.highlightColor : Theme.primaryColor
readonly property int textAlign: isOwnMessage ? Text.AlignRight : Text.AlignLeft
@ -36,7 +36,7 @@ ListItem {
readonly property bool isSelected: messageListItem.precalculatedValues.pageIsSelecting && page.selectedMessages.some(function(existingMessage) {
return existingMessage.id === messageId
});
readonly property bool isOwnMessage: page.myUserId === myMessage.sender_user_id
readonly property bool isOwnMessage: page.myUserId === myMessage.sender.user_id
property string extraContentComponentName
highlighted: (down || isSelected) && !menuOpen
@ -336,7 +336,7 @@ ListItem {
forwardedThumbnail.photoData = (typeof otherChatInformation.photo !== "undefined") ? otherChatInformation.photo.small : {};
forwardedChannelText.text = Emoji.emojify(otherChatInformation.title, Theme.fontSizeExtraSmall);
} else if (myMessage.forward_info.origin["@type"] === "messageForwardOriginUser") {
var otherUserInformation = tdLibWrapper.getUserInformation(myMessage.forward_info.origin.sender_user_id);
var otherUserInformation = tdLibWrapper.getUserInformation(myMessage.forward_info.origin.sender.user_id);
forwardedThumbnail.photoData = (typeof otherUserInformation.profile_photo !== "undefined") ? otherUserInformation.profile_photo.small : {};
forwardedChannelText.text = Emoji.emojify(Functions.getUserName(otherUserInformation), Theme.fontSizeExtraSmall);
} else {

View file

@ -24,8 +24,8 @@ import "../js/functions.js" as Functions
Item {
id: messageListItem
property var myMessage: display
property var userInformation: tdLibWrapper.getUserInformation(myMessage.sender_user_id)
property bool isOwnMessage: chatPage.myUserId === myMessage.sender_user_id
property var userInformation: tdLibWrapper.getUserInformation(myMessage.sender.user_id)
property bool isOwnMessage: chatPage.myUserId === myMessage.sender.user_id
height: backgroundRectangle.height + Theme.paddingMedium
Rectangle {

View file

@ -31,8 +31,8 @@ Flickable {
property var overlayMessage;
property bool showHeader: true
readonly property var userInformation: tdLibWrapper.getUserInformation(overlayMessage.sender_user_id);
readonly property bool isOwnMessage: tdLibWrapper.getUserInformation().id === overlayMessage.sender_user_id;
readonly property var userInformation: tdLibWrapper.getUserInformation(overlayMessage.sender.user_id);
readonly property bool isOwnMessage: tdLibWrapper.getUserInformation().id === overlayMessage.sender.user_id;
readonly property string extraContentComponentName: (typeof overlayMessage.content !== "undefined" && typeof chatView.contentComponentNames[overlayMessage.content['@type']] !== "undefined" )
? chatView.contentComponentNames[overlayMessage.content['@type']] : ""
signal requestClose;
@ -43,7 +43,7 @@ Flickable {
var otherChatInformation = tdLibWrapper.getChat(forwardInformation.origin.chat_id);
return Emoji.emojify(otherChatInformation.title, fontSize);
case "messageForwardOriginUser":
var otherUserInformation = tdLibWrapper.getUserInformation(forwardInformation.origin.sender_user_id);
var otherUserInformation = tdLibWrapper.getUserInformation(forwardInformation.origin.sender.user_id);
return Emoji.emojify(Functions.getUserName(otherUserInformation), fontSize);
default:
return Emoji.emojify(forwardInformation.origin.sender_name, fontSize);

View file

@ -33,9 +33,9 @@ Item {
onPinnedMessageChanged: {
if (pinnedMessage) {
Debug.log("[ChatPage] Activating pinned message");
var messageUserText = (pinnedMessage.sender_user_id !== chatPage.myUserId) ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(pinnedMessage.sender_user_id)), pinnedMessageUserText.font.pixelSize) : qsTr("You");
var messageUserText = (pinnedMessage.sender.user_id !== chatPage.myUserId) ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(pinnedMessage.sender.user_id)), pinnedMessageUserText.font.pixelSize) : qsTr("You");
pinnedMessageUserText.text = (messageUserText === "" ? qsTr("Pinned Message") : messageUserText );
pinnedMessageText.text = Emoji.emojify(Functions.getMessageText(pinnedMessage, true, pinnedMessage.sender_user_id === chatPage.myUserId, false), pinnedMessageText.font.pixelSize);
pinnedMessageText.text = Emoji.emojify(Functions.getMessageText(pinnedMessage, true, pinnedMessage.sender.user_id === chatPage.myUserId, false), pinnedMessageText.font.pixelSize);
pinnedMessageItem.visible = true;
} else {
pinnedMessageItem.visible = false;

View file

@ -91,7 +91,7 @@ Item {
height: recentStickersGridView.cellHeight
Image {
source: modelData.thumbnail.photo.local.path
source: modelData.thumbnail.file.local.path
anchors.fill: parent
asynchronous: true
onStatusChanged: {
@ -144,9 +144,9 @@ Item {
Image {
id: singleStickerImage
source: modelData.thumbnail.photo.local.is_downloading_completed ? modelData.thumbnail.photo.local.path : ""
source: modelData.thumbnail.file.local.is_downloading_completed ? modelData.thumbnail.file.local.path : ""
anchors.fill: parent
visible: modelData.thumbnail.photo.local.is_downloading_completed
visible: modelData.thumbnail.file.local.is_downloading_completed
asynchronous: true
onStatusChanged: {
if (status === Image.Ready) {
@ -160,7 +160,7 @@ Item {
maximumLineCount: 1
truncationMode: TruncationMode.Fade
text: Emoji.emojify(modelData.emoji, font.pixelSize)
visible: !modelData.thumbnail.photo.local.is_downloading_completed
visible: !modelData.thumbnail.file.local.is_downloading_completed
}
MouseArea {

View file

@ -401,7 +401,7 @@ function getMessagesArrayText(messages) {
var lastSenderName = "";
var lines = [];
for(var i = 0; i < messages.length; i += 1) {
var senderName = getUserName(tdLibWrapper.getUserInformation(messages[i].sender_user_id));
var senderName = getUserName(tdLibWrapper.getUserInformation(messages[i].sender.user_id));
if(senderName !== lastSenderName) {
lines.push(senderName);
}

View file

@ -183,7 +183,7 @@ Page {
messageStatusSuffix += " - " + qsTr("edited");
}
if (chatPage.myUserId === message.sender_user_id) {
if (chatPage.myUserId === message.sender.user_id) {
messageStatusSuffix += "&nbsp;&nbsp;"
if (listItemIndex <= lastReadSentIndex) {
// Read by other party
@ -472,7 +472,7 @@ Page {
}
}
onNewMessageReceived: {
if (chatView.manuallyScrolledToBottom || message.sender_user_id === chatPage.myUserId) {
if (chatView.manuallyScrolledToBottom || message.sender.user_id === chatPage.myUserId) {
Debug.log("[ChatPage] Own message received or was scrolled to bottom, scrolling down to see it...");
chatView.scrollToIndex(chatView.count - 1);
}

View file

@ -33,7 +33,7 @@ Page {
property var pollData: message.content.poll
property var userInformation: tdLibWrapper.getUserInformation(message.sender_user_id)
property var userInformation: tdLibWrapper.getUserInformation(message.sender.user_id)
property bool isQuiz: pollData.type['@type'] === "pollTypeQuiz"

View file

@ -35,7 +35,8 @@ namespace {
const QString CHAT_ID("chat_id");
const QString CONTENT("content");
const QString LAST_MESSAGE("last_message");
const QString SENDER_USER_ID("sender_user_id");
const QString SENDER("sender");
const QString USER_ID("user_id");
const QString BASIC_GROUP_ID("basic_group_id");
const QString SUPERGROUP_ID("supergroup_id");
const QString UNREAD_COUNT("unread_count");
@ -81,6 +82,8 @@ public:
QVariant photoSmall() const;
qlonglong lastReadInboxMessageId() const;
qlonglong senderUserId() const;
qlonglong senderChatId() const;
bool senderIsChat() const;
qlonglong senderMessageDate() const;
QString senderMessageText() const;
QString senderMessageStatus() const;
@ -176,7 +179,17 @@ qlonglong ChatListModel::ChatData::lastReadInboxMessageId() const
qlonglong ChatListModel::ChatData::senderUserId() const
{
return lastMessage(SENDER_USER_ID).toLongLong();
return lastMessage(SENDER).toMap().value(USER_ID).toLongLong();
}
qlonglong ChatListModel::ChatData::senderChatId() const
{
return lastMessage(SENDER).toMap().value(CHAT_ID).toLongLong();
}
bool ChatListModel::ChatData::senderIsChat() const
{
return lastMessage(SENDER).toMap().value(_TYPE).toString() == "messageSenderChat";
}
qlonglong ChatListModel::ChatData::senderMessageDate() const

View file

@ -35,7 +35,8 @@ namespace {
const QString UNREAD_COUNT("unread_count");
const QString LAST_READ_INBOX_MESSAGE_ID("last_read_inbox_message_id");
const QString LAST_READ_OUTBOX_MESSAGE_ID("last_read_outbox_message_id");
const QString SENDER_USER_ID("sender_user_id");
const QString SENDER("sender");
const QString USER_ID("user_id");
const QString PINNED_MESSAGE_ID("pinned_message_id");
const QString _TYPE("@type");
}
@ -54,6 +55,8 @@ public:
static bool lessThan(const MessageData *message1, const MessageData *message2);
void setContent(const QVariantMap &content);
int senderUserId() const;
qlonglong senderChatId() const;
bool senderIsChat() const;
public:
QVariantMap messageData;
@ -70,7 +73,17 @@ ChatModel::MessageData::MessageData(const QVariantMap &data, qlonglong msgid) :
int ChatModel::MessageData::senderUserId() const
{
return messageData.value(SENDER_USER_ID).toInt();
return messageData.value(SENDER).toMap().value(USER_ID).toInt();
}
qlonglong ChatModel::MessageData::senderChatId() const
{
return messageData.value(SENDER).toMap().value(CHAT_ID).toLongLong();
}
bool ChatModel::MessageData::senderIsChat() const
{
return messageData.value(SENDER).toMap().value(_TYPE).toString() == "messageSenderChat";
}
void ChatModel::MessageData::setContent(const QVariantMap &content)

View file

@ -43,7 +43,8 @@ namespace {
const QString MESSAGE("message");
const QString FIRST_NAME("first_name");
const QString LAST_NAME("last_name");
const QString SENDER_USER_ID("sender_user_id");
const QString SENDER("sender");
const QString USER_ID("user_id");
const QString NOTIFICATIONS("notifications");
const QString NOTIFICATION_GROUP_ID("notification_group_id");
const QString ADDED_NOTIFICATIONS("added_notifications");
@ -336,10 +337,17 @@ void NotificationManager::publishNotification(const NotificationGroup *notificat
if (chatInformation && (chatInformation->type == TDLibWrapper::ChatTypeBasicGroup ||
(chatInformation->type == TDLibWrapper::ChatTypeSupergroup && !chatInformation->isChannel))) {
// Add author
const QVariantMap authorInformation = tdLibWrapper->getUserInformation(messageMap.value(SENDER_USER_ID).toString());
const QString firstName = authorInformation.value(FIRST_NAME).toString();
const QString lastName = authorInformation.value(LAST_NAME).toString();
const QString fullName = firstName + " " + lastName;
const QVariantMap senderInformation = messageMap.value(SENDER).toMap();
QString fullName;
if (senderInformation.value(_TYPE).toString() == "messageSenderChat") {
fullName = tdLibWrapper->getChat(senderInformation.value(CHAT_ID).toString()).value(TITLE).toString();
} else {
const QVariantMap authorInformation = tdLibWrapper->getUserInformation(senderInformation.value(USER_ID).toString());
const QString firstName = authorInformation.value(FIRST_NAME).toString();
const QString lastName = authorInformation.value(LAST_NAME).toString();
fullName = firstName + " " + lastName;
}
notificationBody = notificationBody + fullName.trimmed() + ": ";
}
notificationBody += getNotificationText(messageMap.value(CONTENT).toMap());

View file

@ -121,7 +121,7 @@ void StickerManager::handleStickerSetReceived(const QVariantMap &stickerSet)
QListIterator<QVariant> stickerIterator(stickerList);
while (stickerIterator.hasNext()) {
QVariantMap singleSticker = stickerIterator.next().toMap();
QVariantMap thumbnailFile = singleSticker.value("thumbnail").toMap().value("photo").toMap();
QVariantMap thumbnailFile = singleSticker.value("thumbnail").toMap().value("file").toMap();
QVariantMap thumbnailLocalFile = thumbnailFile.value("local").toMap();
if (!thumbnailLocalFile.value("is_downloading_completed").toBool()) {
tdLibWrapper->downloadFile(thumbnailFile.value("id").toInt());