Merge lp:~tiagosh/messaging-app/fix-1394971 into lp:messaging-app

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 404
Merged at revision: 421
Proposed branch: lp:~tiagosh/messaging-app/fix-1394971
Merge into: lp:messaging-app
Diff against target: 236 lines (+171/-0)
5 files modified
debian/control (+5/-0)
src/qml/Messages.qml (+19/-0)
src/qml/messaging-app.qml (+1/-0)
tests/qml/CMakeLists.txt (+2/-0)
tests/qml/tst_MessagesView.qml (+144/-0)
To merge this branch: bzr merge lp:~tiagosh/messaging-app/fix-1394971
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+264936@code.launchpad.net

Commit message

Only mark messages as read when the application is active, and add a QML test to prevent regressions. The QML tests need some QML modules available at build time in order to run properly, so those were added as build deps.

Description of the change

Only mark messages as read when the application is active.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Looks good and works as expected!

review: Approve
405. By Tiago Salem Herrmann

add test for marking messages as read

406. By Tiago Salem Herrmann

invert logic

407. By Tiago Salem Herrmann

add missing dependency

408. By Tiago Salem Herrmann

add missing build deps

409. By Tiago Salem Herrmann

add missing build deps

410. By Tiago Salem Herrmann

add missing build deps

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2015-06-10 13:17:17 +0000
+++ debian/control 2015-08-14 14:34:24 +0000
@@ -18,6 +18,11 @@
18 qtdeclarative5-ubuntu-ui-toolkit-plugin,18 qtdeclarative5-ubuntu-ui-toolkit-plugin,
19 qtdeclarative5-ubuntu-history0.1,19 qtdeclarative5-ubuntu-history0.1,
20 qtdeclarative5-ubuntu-telephony-phonenumber0.1,20 qtdeclarative5-ubuntu-telephony-phonenumber0.1,
21 qtdeclarative5-ubuntu-telephony0.1 | qtdeclarative5-ubuntu-telephony-plugin,
22 qtdeclarative5-ubuntu-content1,
23 qtdeclarative5-ubuntu-addressbook0.1,
24 qtdeclarative5-qtcontacts-plugin,
25 qml-module-qt-labs-settings,
21 qtpim5-dev,26 qtpim5-dev,
22 xvfb,27 xvfb,
23Standards-Version: 3.9.428Standards-Version: 3.9.4
2429
=== modified file 'src/qml/Messages.qml'
--- src/qml/Messages.qml 2015-07-10 19:24:13 +0000
+++ src/qml/Messages.qml 2015-08-14 14:34:24 +0000
@@ -52,6 +52,7 @@
52 property string scrollToEventId: ""52 property string scrollToEventId: ""
53 property bool isSearching: scrollToEventId !== ""53 property bool isSearching: scrollToEventId !== ""
54 property string latestEventId: ""54 property string latestEventId: ""
55 property var pendingEventsToMarkAsRead: []
55 // to be used by tests as variant does not work with autopilot56 // to be used by tests as variant does not work with autopilot
56 property string firstParticipant: participants.length > 0 ? participants[0] : ""57 property string firstParticipant: participants.length > 0 ? participants[0] : ""
5758
@@ -313,10 +314,28 @@
313 }314 }
314315
315 function markMessageAsRead(accountId, threadId, eventId, type) {316 function markMessageAsRead(accountId, threadId, eventId, type) {
317 if (!mainView.applicationActive) {
318 var pendingEvent = {"accountId": accountId, "threadId": threadId, "eventId": eventId, "type": type}
319 pendingEventsToMarkAsRead.push(pendingEvent)
320 return false
321 }
316 chatManager.acknowledgeMessage(participants, eventId, accountId)322 chatManager.acknowledgeMessage(participants, eventId, accountId)
317 return eventModel.markEventAsRead(accountId, threadId, eventId, type);323 return eventModel.markEventAsRead(accountId, threadId, eventId, type);
318 }324 }
319325
326 Connections {
327 target: mainView
328 onApplicationActiveChanged: {
329 if (mainView.applicationActive) {
330 for (var i in pendingEventsToMarkAsRead) {
331 var event = pendingEventsToMarkAsRead[i]
332 markMessageAsRead(event.accountId, event.threadId, event.eventId, event.type)
333 }
334 pendingEventsToMarkAsRead = []
335 }
336 }
337 }
338
320 Component {339 Component {
321 id: attachmentPopover340 id: attachmentPopover
322341
323342
=== modified file 'src/qml/messaging-app.qml'
--- src/qml/messaging-app.qml 2015-05-13 19:37:01 +0000
+++ src/qml/messaging-app.qml 2015-08-14 14:34:24 +0000
@@ -30,6 +30,7 @@
30 property string newPhoneNumber30 property string newPhoneNumber
31 property bool multipleAccounts: telepathyHelper.activeAccounts.length > 131 property bool multipleAccounts: telepathyHelper.activeAccounts.length > 1
32 property QtObject account: defaultAccount()32 property QtObject account: defaultAccount()
33 property bool applicationActive: Qt.application.active
3334
34 activeFocusOnPress: false35 activeFocusOnPress: false
3536
3637
=== modified file 'tests/qml/CMakeLists.txt'
--- tests/qml/CMakeLists.txt 2014-08-01 14:12:20 +0000
+++ tests/qml/CMakeLists.txt 2015-08-14 14:34:24 +0000
@@ -17,6 +17,7 @@
1717
18if(QMLTESTRUNNER_BIN AND XVFB_RUN_BIN)18if(QMLTESTRUNNER_BIN AND XVFB_RUN_BIN)
19 declare_qml_test("message_bubble" tst_MessageBubble.qml)19 declare_qml_test("message_bubble" tst_MessageBubble.qml)
20 declare_qml_test("messages_view" tst_MessagesView.qml)
20else()21else()
21 if (NOT QMLTESTRUNNER_BIN)22 if (NOT QMLTESTRUNNER_BIN)
22 message(WARNING "Qml tests disabled: qmltestrunner not found")23 message(WARNING "Qml tests disabled: qmltestrunner not found")
@@ -27,5 +28,6 @@
2728
28set(QML_TST_FILES29set(QML_TST_FILES
29 tst_MessageBubble.qml30 tst_MessageBubble.qml
31 tst_MessagesView.qml
30)32)
31add_custom_target(tst_QmlFiles ALL SOURCES ${QML_TST_FILES})33add_custom_target(tst_QmlFiles ALL SOURCES ${QML_TST_FILES})
3234
=== added file 'tests/qml/tst_MessagesView.qml'
--- tests/qml/tst_MessagesView.qml 1970-01-01 00:00:00 +0000
+++ tests/qml/tst_MessagesView.qml 2015-08-14 14:34:24 +0000
@@ -0,0 +1,144 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This file is part of messaging-app.
5 *
6 * messaging-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * messaging-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.2
20import QtTest 1.0
21import Ubuntu.Test 0.1
22import Ubuntu.Telephony 0.1
23import Ubuntu.History 0.1
24
25Item {
26 id: root
27
28 width: units.gu(40)
29 height: units.gu(70)
30
31
32 ListModel {
33 id: messagesModel
34 ListElement {
35 accountId: "ofono/ofono/account0"
36 threadId: "1234567"
37 participants: []
38 type: HistoryThreadModel.EventTypeText
39 properties: []
40 eventId: "id1"
41 senderId: "1234567"
42 timestamp: 1439486685400
43 date: ""
44 newEvent: true
45 textMessage: "test"
46 textMessageType: HistoryThreadModel.MessageTypeText
47 textMessageStatus: HistoryThreadModel.MessageStatusDelivered
48 textMessageAttachments: []
49 textReadTimestamp: 1439486685400
50 textSubject: ""
51 remoteParticipant: ""
52 }
53 ListElement {
54 accountId: "ofono/ofono/account0"
55 threadId: "1234567"
56 participants: []
57 type: HistoryThreadModel.EventTypeText
58 properties: []
59 eventId: "id2"
60 senderId: "1234567"
61 timestamp: 1439486685400
62 date: ""
63 newEvent: true
64 textMessage: "test2"
65 textMessageType: HistoryThreadModel.MessageTypeText
66 textMessageStatus: HistoryThreadModel.MessageStatusDelivered
67 textMessageAttachments: []
68 textReadTimestamp: 1439486685400
69 textSubject: ""
70 remoteParticipant: ""
71 }
72 }
73
74 QtObject {
75 id: testAccount
76 property string accountId: "ofono/ofono/account0"
77 property var emergencyNumbers: [ "444", "555"]
78 property int type: AccountEntry.PhoneAccount
79 property string displayName: "SIM 1"
80 property bool connected: true
81 property bool emergencyCallsAvailable: true
82 property bool active: true
83 property string networkName: "Network name"
84 property bool simLocked: false
85 property var addressableVCardFields: ["tel"]
86 }
87
88 Item {
89 id: telepathyHelper
90 function registerChannelObserver() {}
91 function unregisterChannelObserver() {}
92 property var activeAccounts: [testAccount]
93 property alias accounts: telepathyHelper.activeAccounts
94 }
95
96 Item {
97 id: chatManager
98 signal messageAcknowledged
99 function acknowledgeMessage(recipients, messageId, accountId) {
100 chatManager.messageAcknowledged(recipients, messageId, accountId)
101 }
102 }
103
104 Loader {
105 id: mainViewLoader
106 property string i18nDirectory: ""
107 source: '../../src/qml/messaging-app.qml'
108 }
109
110 SignalSpy {
111 id: messageAcknowledgeSpy
112 target: chatManager
113 signalName: "messageAcknowledged"
114 }
115
116 UbuntuTestCase {
117 id: swipeItemTestCase
118 name: 'swipeItemTestCase'
119
120 when: windowShown
121
122 function init() {
123 }
124
125 function cleanup() {
126 }
127
128 function test_messagesViewAcknowledgeMessage() {
129 var senderId = "1234567"
130 var stack = findChild(mainViewLoader, "mainStack")
131 tryCompare(mainViewLoader.item, 'applicationActive', true)
132 tryCompare(stack, 'depth', 1)
133 mainViewLoader.item.startChat(senderId, "")
134 tryCompare(stack, 'depth', 2)
135 mainViewLoader.item.applicationActive = false
136 var messageList = findChild(mainViewLoader, "messageList")
137 messageList.listModel = messagesModel
138 tryCompare(messageList, 'count', 2)
139 compare(messageAcknowledgeSpy.count, 0)
140 mainViewLoader.item.applicationActive = true
141 tryCompare(messageAcknowledgeSpy, 'count', 2)
142 }
143 }
144}

Subscribers

People subscribed via source and target branches