Merge lp:~libqtelegram-team/telegram-app/bugfix-1348724 into lp:~libqtelegram-team/telegram-app/qml-plugin

Proposed by Roberto Mier Escandon
Status: Rejected
Rejected by: Roberto Mier Escandon
Proposed branch: lp:~libqtelegram-team/telegram-app/bugfix-1348724
Merge into: lp:~libqtelegram-team/telegram-app/qml-plugin
Diff against target: 102 lines (+25/-16)
4 files modified
qmlplugin/models/messagesmodel.cpp (+22/-5)
qmlplugin/telegramclient.cpp (+1/-8)
qmlplugin/telegramclient.h (+0/-1)
uitest/uitest.qml (+2/-2)
To merge this branch: bzr merge lp:~libqtelegram-team/telegram-app/bugfix-1348724
Reviewer Review Type Date Requested Status
Michał Karnicki (community) Approve
Review via email: mp+229791@code.launchpad.net

Description of the change

Received messages in a list are sorted from most to less recent and should be always added at the end or inserted at beginning. This change evaluates if needed to append or prepend them and does the operation.
This way is not needed to have a proxy for sorting messages because list will remain always sorted.

Anyway, this change must be considered "under observation" for every new operation involving the messages model because it could happen that is not always valid or should it be completed with any special case.

To post a comment you must log in.
Revision history for this message
Michał Karnicki (karni) wrote :

inline comments, then +1

review: Approve

Unmerged revisions

182. By Roberto Mier Escandon

BUGFIX for 1348724; dialog history messages not well sorted

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qmlplugin/models/messagesmodel.cpp'
2--- qmlplugin/models/messagesmodel.cpp 2014-07-25 16:45:31 +0000
3+++ qmlplugin/models/messagesmodel.cpp 2014-08-06 13:38:34 +0000
4@@ -108,7 +108,7 @@
5 if (m_messages.isEmpty()) {
6 return MessageItem();
7 }
8- return m_messages.first();
9+ return m_messages.last();
10 }
11
12 void MessagesModel::append(const MessageItem &newMessage) {
13@@ -124,16 +124,33 @@
14 return;
15 }
16
17- beginInsertRows(QModelIndex(), m_messages.count(), m_messages.count() + messages.count() - 1);
18- Q_FOREACH (MessageItem newMessage, messages) {
19- m_keysMap.insert(newMessage.id(), m_messages.count());
20- m_messages.append(newMessage);
21+ // check if most recent received message (first in the list) has lower date than first one in model
22+ // to prepending instead of appending
23+ if (m_messages.count() > 0 && (m_messages.at(0).date() > messages.at(0).date())) {
24+
25+ // when prepending, the first message to prepend should be the most recent
26+ beginInsertRows(QModelIndex(), 0, messages.count() - 1);
27+ for (int i = 0; i < messages.count(); i++) {
28+ const MessageItem &msg = messages.at(i);
29+ m_keysMap.insert(msg.id(), messages.count() - i - 1);
30+ m_messages.prepend(msg);
31+ }
32+ } else {
33+
34+ // when appending, the last message to append should be the most recent
35+ beginInsertRows(QModelIndex(), m_messages.count(), m_messages.count() + messages.count() - 1);
36+ for (int i = messages.count()-1; i >= 0; i--) {
37+ const MessageItem &msg = messages.at(i);
38+ m_keysMap.insert(msg.id(), m_messages.count());
39+ m_messages.append(msg);
40+ }
41 }
42 endInsertRows();
43
44 m_canFetchMore = totalCount > m_messages.count();
45 }
46
47+
48 void MessagesModel::update(qint32 msgId, const MessageItem &message) {
49
50 qint32 pos = m_keysMap.take(msgId);
51
52=== modified file 'qmlplugin/telegramclient.cpp'
53--- qmlplugin/telegramclient.cpp 2014-07-30 16:09:13 +0000
54+++ qmlplugin/telegramclient.cpp 2014-08-06 13:38:34 +0000
55@@ -102,14 +102,7 @@
56 m_telegram->messagesGetHistory(peer);
57
58 MessagesModel &messagesModel = ModelsManager::instance()->messagesModel(dialogId);
59-
60- // build messages model and proxy
61- m_messagesModelProxy.setSourceModel(&messagesModel);
62- m_messagesModelProxy.setSortRole(MessagesModel::DateRole);
63- m_messagesModelProxy.sort(0, Qt::AscendingOrder);
64- m_messagesModelProxy.setDynamicSortFilter(true);
65-
66- return QVariant::fromValue(&m_messagesModelProxy);
67+ return QVariant::fromValue(&messagesModel);
68 }
69
70 QVariant TelegramClient::getDialog(qint32 dialogId) {
71
72=== modified file 'qmlplugin/telegramclient.h'
73--- qmlplugin/telegramclient.h 2014-07-30 16:09:13 +0000
74+++ qmlplugin/telegramclient.h 2014-08-06 13:38:34 +0000
75@@ -48,7 +48,6 @@
76 private:
77 DialogsProxy m_dialogsModelProxy;
78 ContactsProxy m_contactsModelProxy;
79- QSortFilterProxyModel m_messagesModelProxy;
80
81 // updates state
82 ClientState m_state;
83
84=== modified file 'uitest/uitest.qml'
85--- uitest/uitest.qml 2014-08-06 10:59:18 +0000
86+++ uitest/uitest.qml 2014-08-06 13:38:34 +0000
87@@ -119,13 +119,13 @@
88
89 onMessagesGetDialogsAnswer: {
90 // *Uncomment to render dialogsPage
91- //pageStack.showPage(dialogsPage);
92+ pageStack.showPage(dialogsPage);
93
94 // *Uncomment to render contactsPage
95 //pageStack.showPage(contactsPage);
96
97 // *Uncomment to render settingsPage
98- pageStack.showPage(settingsPage);
99+ //pageStack.showPage(settingsPage);
100 }
101
102 }

Subscribers

People subscribed via source and target branches

to all changes: