Try to tweak updates and list positioning

This commit is contained in:
Sebastian J. Wolf 2020-09-20 14:26:09 +02:00
parent 64b6c8607e
commit 32fce5b965
4 changed files with 18 additions and 6 deletions

View file

@ -189,7 +189,11 @@ Page {
onMessagesReceived: { onMessagesReceived: {
console.log("[ChatPage] Messages received, view has " + chatView.count + " messages, setting view to index " + modelIndex + ", own messages were read before index " + lastReadSentIndex); console.log("[ChatPage] Messages received, view has " + chatView.count + " messages, setting view to index " + modelIndex + ", own messages were read before index " + lastReadSentIndex);
chatView.lastReadSentIndex = lastReadSentIndex; chatView.lastReadSentIndex = lastReadSentIndex;
chatView.positionViewAtIndex(modelIndex, ListView.Contain); if (modelIndex === (chatView.count - 1)) {
chatView.positionViewAtEnd();
} else {
chatView.positionViewAtIndex(modelIndex, ListView.Beginning);
}
chatPage.loading = false; chatPage.loading = false;
if (chatView.height > chatView.contentHeight) { if (chatView.height > chatView.contentHeight) {
console.log("[ChatPage] Chat content quite small..."); console.log("[ChatPage] Chat content quite small...");
@ -602,7 +606,7 @@ Page {
if (index === modelIndex) { if (index === modelIndex) {
console.log("[ChatModel] This message was updated, index " + index + ", updating content..."); console.log("[ChatModel] This message was updated, index " + index + ", updating content...");
messageDateText.text = getMessageStatusText(display, index, chatView.lastReadSentIndex); messageDateText.text = getMessageStatusText(display, index, chatView.lastReadSentIndex);
messageText.text = Emoji.emojify(Functions.getMessageText(display, false), font.pixelSize); messageText.text = Emoji.emojify(Functions.getMessageText(display, false), messageText.font.pixelSize);
} }
} }
} }

View file

@ -255,7 +255,8 @@ Page {
chatListPictureThumbnail.photoData = (typeof display.photo !== "undefined") ? display.photo.small : ""; chatListPictureThumbnail.photoData = (typeof display.photo !== "undefined") ? display.photo.small : "";
chatUnreadMessagesCountBackground.visible = display.unread_count > 0; chatUnreadMessagesCountBackground.visible = display.unread_count > 0;
chatUnreadMessagesCount.text = display.unread_count > 99 ? "99+" : display.unread_count; chatUnreadMessagesCount.text = display.unread_count > 99 ? "99+" : display.unread_count;
chatListNameText.text = display.title !== "" ? Emoji.emojify(display.title, Theme.fontSizeMedium) + ( display.notification_settings.mute_for > 0 ? Emoji.emojify(" 🔇", Theme.fontSizeMedium) : "" ) : qsTr("Unknown") chatListNameText.text = display.title !== "" ? Emoji.emojify(display.title, Theme.fontSizeMedium) + ( display.notification_settings.mute_for > 0 ? Emoji.emojify(" 🔇", Theme.fontSizeMedium) : "" ) : qsTr("Unknown");
chatListLastUserText.text = (typeof display.last_message !== "undefined") ? ( display.last_message.sender_user_id !== overviewPage.ownUserId ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(display.last_message.sender_user_id)), Theme.fontSizeExtraSmall) : qsTr("You") ) : qsTr("Unknown");
chatListLastMessageText.text = (typeof display.last_message !== "undefined") ? Emoji.emojify(Functions.getMessageText(display.last_message, true), Theme.fontSizeExtraSmall) : qsTr("Unknown"); chatListLastMessageText.text = (typeof display.last_message !== "undefined") ? Emoji.emojify(Functions.getMessageText(display.last_message, true), Theme.fontSizeExtraSmall) : qsTr("Unknown");
messageContactTimeElapsedText.text = (typeof display.last_message !== "undefined") ? Functions.getDateTimeElapsed(display.last_message.date) : qsTr("Unknown"); messageContactTimeElapsedText.text = (typeof display.last_message !== "undefined") ? Functions.getDateTimeElapsed(display.last_message.date) : qsTr("Unknown");
} }
@ -386,6 +387,13 @@ Page {
onTriggered: { onTriggered: {
if (typeof display.last_message !== "undefined") { if (typeof display.last_message !== "undefined") {
messageContactTimeElapsedText.text = Functions.getDateTimeElapsed(display.last_message.date); messageContactTimeElapsedText.text = Functions.getDateTimeElapsed(display.last_message.date);
// Force update of all list item elements. dataChanged() doesn't seem to trigger them all :(
chatListPictureThumbnail.photoData = (typeof display.photo !== "undefined") ? display.photo.small : "";
chatUnreadMessagesCountBackground.visible = display.unread_count > 0;
chatUnreadMessagesCount.text = display.unread_count > 99 ? "99+" : display.unread_count;
chatListNameText.text = display.title !== "" ? Emoji.emojify(display.title, Theme.fontSizeMedium) + ( display.notification_settings.mute_for > 0 ? Emoji.emojify(" 🔇", Theme.fontSizeMedium) : "" ) : qsTr("Unknown");
chatListLastUserText.text = (typeof display.last_message !== "undefined") ? ( display.last_message.sender_user_id !== overviewPage.ownUserId ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(display.last_message.sender_user_id)), Theme.fontSizeExtraSmall) : qsTr("You") ) : qsTr("Unknown");
chatListLastMessageText.text = (typeof display.last_message !== "undefined") ? Emoji.emojify(Functions.getMessageText(display.last_message, true), Theme.fontSizeExtraSmall) : qsTr("Unknown");
} }
} }
} }

View file

@ -42,7 +42,7 @@ void TDLibReceiver::receiverLoop()
const char *result = td_json_client_receive(this->tdLibClient, WAIT_TIMEOUT); const char *result = td_json_client_receive(this->tdLibClient, WAIT_TIMEOUT);
if (result) { if (result) {
QJsonDocument receivedJsonDocument = QJsonDocument::fromJson(QByteArray(result)); QJsonDocument receivedJsonDocument = QJsonDocument::fromJson(QByteArray(result));
qDebug().noquote() << "[TDLibReceiver] Raw result: " << receivedJsonDocument.toJson(QJsonDocument::Indented); // Too much information... qDebug().noquote() << "[TDLibReceiver] Raw result: " << receivedJsonDocument.toJson(QJsonDocument::Indented);
processReceivedDocument(receivedJsonDocument); processReceivedDocument(receivedJsonDocument);
} }
} }
@ -281,6 +281,6 @@ void TDLibReceiver::processUpdateDeleteMessages(const QVariantMap &receivedInfor
{ {
QString chatId = receivedInformation.value("chat_id").toString(); QString chatId = receivedInformation.value("chat_id").toString();
QVariantList messageIds = receivedInformation.value("message_ids").toList(); QVariantList messageIds = receivedInformation.value("message_ids").toList();
qDebug() << "[TDLibReceiver] Some messages were deleted " << chatId << messageIds; qDebug() << "[TDLibReceiver] Some messages were deleted " << chatId;
emit messagesDeleted(chatId, messageIds); emit messagesDeleted(chatId, messageIds);
} }

View file

@ -93,7 +93,7 @@ void TDLibWrapper::sendRequest(const QVariantMap &requestObject)
{ {
qDebug() << "[TDLibWrapper] Sending request to TD Lib, object type name: " << requestObject.value("@type").toString(); qDebug() << "[TDLibWrapper] Sending request to TD Lib, object type name: " << requestObject.value("@type").toString();
QJsonDocument requestDocument = QJsonDocument::fromVariant(requestObject); QJsonDocument requestDocument = QJsonDocument::fromVariant(requestObject);
qDebug().noquote() << requestDocument.toJson(); // Too much information... qDebug().noquote() << requestDocument.toJson();
td_json_client_send(this->tdLibClient, requestDocument.toJson().constData()); td_json_client_send(this->tdLibClient, requestDocument.toJson().constData());
} }