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
1=== modified file 'debian/control'
2--- debian/control 2015-06-10 13:17:17 +0000
3+++ debian/control 2015-08-14 14:34:24 +0000
4@@ -18,6 +18,11 @@
5 qtdeclarative5-ubuntu-ui-toolkit-plugin,
6 qtdeclarative5-ubuntu-history0.1,
7 qtdeclarative5-ubuntu-telephony-phonenumber0.1,
8+ qtdeclarative5-ubuntu-telephony0.1 | qtdeclarative5-ubuntu-telephony-plugin,
9+ qtdeclarative5-ubuntu-content1,
10+ qtdeclarative5-ubuntu-addressbook0.1,
11+ qtdeclarative5-qtcontacts-plugin,
12+ qml-module-qt-labs-settings,
13 qtpim5-dev,
14 xvfb,
15 Standards-Version: 3.9.4
16
17=== modified file 'src/qml/Messages.qml'
18--- src/qml/Messages.qml 2015-07-10 19:24:13 +0000
19+++ src/qml/Messages.qml 2015-08-14 14:34:24 +0000
20@@ -52,6 +52,7 @@
21 property string scrollToEventId: ""
22 property bool isSearching: scrollToEventId !== ""
23 property string latestEventId: ""
24+ property var pendingEventsToMarkAsRead: []
25 // to be used by tests as variant does not work with autopilot
26 property string firstParticipant: participants.length > 0 ? participants[0] : ""
27
28@@ -313,10 +314,28 @@
29 }
30
31 function markMessageAsRead(accountId, threadId, eventId, type) {
32+ if (!mainView.applicationActive) {
33+ var pendingEvent = {"accountId": accountId, "threadId": threadId, "eventId": eventId, "type": type}
34+ pendingEventsToMarkAsRead.push(pendingEvent)
35+ return false
36+ }
37 chatManager.acknowledgeMessage(participants, eventId, accountId)
38 return eventModel.markEventAsRead(accountId, threadId, eventId, type);
39 }
40
41+ Connections {
42+ target: mainView
43+ onApplicationActiveChanged: {
44+ if (mainView.applicationActive) {
45+ for (var i in pendingEventsToMarkAsRead) {
46+ var event = pendingEventsToMarkAsRead[i]
47+ markMessageAsRead(event.accountId, event.threadId, event.eventId, event.type)
48+ }
49+ pendingEventsToMarkAsRead = []
50+ }
51+ }
52+ }
53+
54 Component {
55 id: attachmentPopover
56
57
58=== modified file 'src/qml/messaging-app.qml'
59--- src/qml/messaging-app.qml 2015-05-13 19:37:01 +0000
60+++ src/qml/messaging-app.qml 2015-08-14 14:34:24 +0000
61@@ -30,6 +30,7 @@
62 property string newPhoneNumber
63 property bool multipleAccounts: telepathyHelper.activeAccounts.length > 1
64 property QtObject account: defaultAccount()
65+ property bool applicationActive: Qt.application.active
66
67 activeFocusOnPress: false
68
69
70=== modified file 'tests/qml/CMakeLists.txt'
71--- tests/qml/CMakeLists.txt 2014-08-01 14:12:20 +0000
72+++ tests/qml/CMakeLists.txt 2015-08-14 14:34:24 +0000
73@@ -17,6 +17,7 @@
74
75 if(QMLTESTRUNNER_BIN AND XVFB_RUN_BIN)
76 declare_qml_test("message_bubble" tst_MessageBubble.qml)
77+ declare_qml_test("messages_view" tst_MessagesView.qml)
78 else()
79 if (NOT QMLTESTRUNNER_BIN)
80 message(WARNING "Qml tests disabled: qmltestrunner not found")
81@@ -27,5 +28,6 @@
82
83 set(QML_TST_FILES
84 tst_MessageBubble.qml
85+ tst_MessagesView.qml
86 )
87 add_custom_target(tst_QmlFiles ALL SOURCES ${QML_TST_FILES})
88
89=== added file 'tests/qml/tst_MessagesView.qml'
90--- tests/qml/tst_MessagesView.qml 1970-01-01 00:00:00 +0000
91+++ tests/qml/tst_MessagesView.qml 2015-08-14 14:34:24 +0000
92@@ -0,0 +1,144 @@
93+/*
94+ * Copyright 2015 Canonical Ltd.
95+ *
96+ * This file is part of messaging-app.
97+ *
98+ * messaging-app is free software; you can redistribute it and/or modify
99+ * it under the terms of the GNU General Public License as published by
100+ * the Free Software Foundation; version 3.
101+ *
102+ * messaging-app is distributed in the hope that it will be useful,
103+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
104+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105+ * GNU General Public License for more details.
106+ *
107+ * You should have received a copy of the GNU General Public License
108+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
109+ */
110+
111+import QtQuick 2.2
112+import QtTest 1.0
113+import Ubuntu.Test 0.1
114+import Ubuntu.Telephony 0.1
115+import Ubuntu.History 0.1
116+
117+Item {
118+ id: root
119+
120+ width: units.gu(40)
121+ height: units.gu(70)
122+
123+
124+ ListModel {
125+ id: messagesModel
126+ ListElement {
127+ accountId: "ofono/ofono/account0"
128+ threadId: "1234567"
129+ participants: []
130+ type: HistoryThreadModel.EventTypeText
131+ properties: []
132+ eventId: "id1"
133+ senderId: "1234567"
134+ timestamp: 1439486685400
135+ date: ""
136+ newEvent: true
137+ textMessage: "test"
138+ textMessageType: HistoryThreadModel.MessageTypeText
139+ textMessageStatus: HistoryThreadModel.MessageStatusDelivered
140+ textMessageAttachments: []
141+ textReadTimestamp: 1439486685400
142+ textSubject: ""
143+ remoteParticipant: ""
144+ }
145+ ListElement {
146+ accountId: "ofono/ofono/account0"
147+ threadId: "1234567"
148+ participants: []
149+ type: HistoryThreadModel.EventTypeText
150+ properties: []
151+ eventId: "id2"
152+ senderId: "1234567"
153+ timestamp: 1439486685400
154+ date: ""
155+ newEvent: true
156+ textMessage: "test2"
157+ textMessageType: HistoryThreadModel.MessageTypeText
158+ textMessageStatus: HistoryThreadModel.MessageStatusDelivered
159+ textMessageAttachments: []
160+ textReadTimestamp: 1439486685400
161+ textSubject: ""
162+ remoteParticipant: ""
163+ }
164+ }
165+
166+ QtObject {
167+ id: testAccount
168+ property string accountId: "ofono/ofono/account0"
169+ property var emergencyNumbers: [ "444", "555"]
170+ property int type: AccountEntry.PhoneAccount
171+ property string displayName: "SIM 1"
172+ property bool connected: true
173+ property bool emergencyCallsAvailable: true
174+ property bool active: true
175+ property string networkName: "Network name"
176+ property bool simLocked: false
177+ property var addressableVCardFields: ["tel"]
178+ }
179+
180+ Item {
181+ id: telepathyHelper
182+ function registerChannelObserver() {}
183+ function unregisterChannelObserver() {}
184+ property var activeAccounts: [testAccount]
185+ property alias accounts: telepathyHelper.activeAccounts
186+ }
187+
188+ Item {
189+ id: chatManager
190+ signal messageAcknowledged
191+ function acknowledgeMessage(recipients, messageId, accountId) {
192+ chatManager.messageAcknowledged(recipients, messageId, accountId)
193+ }
194+ }
195+
196+ Loader {
197+ id: mainViewLoader
198+ property string i18nDirectory: ""
199+ source: '../../src/qml/messaging-app.qml'
200+ }
201+
202+ SignalSpy {
203+ id: messageAcknowledgeSpy
204+ target: chatManager
205+ signalName: "messageAcknowledged"
206+ }
207+
208+ UbuntuTestCase {
209+ id: swipeItemTestCase
210+ name: 'swipeItemTestCase'
211+
212+ when: windowShown
213+
214+ function init() {
215+ }
216+
217+ function cleanup() {
218+ }
219+
220+ function test_messagesViewAcknowledgeMessage() {
221+ var senderId = "1234567"
222+ var stack = findChild(mainViewLoader, "mainStack")
223+ tryCompare(mainViewLoader.item, 'applicationActive', true)
224+ tryCompare(stack, 'depth', 1)
225+ mainViewLoader.item.startChat(senderId, "")
226+ tryCompare(stack, 'depth', 2)
227+ mainViewLoader.item.applicationActive = false
228+ var messageList = findChild(mainViewLoader, "messageList")
229+ messageList.listModel = messagesModel
230+ tryCompare(messageList, 'count', 2)
231+ compare(messageAcknowledgeSpy.count, 0)
232+ mainViewLoader.item.applicationActive = true
233+ tryCompare(messageAcknowledgeSpy, 'count', 2)
234+ }
235+ }
236+}

Subscribers

People subscribed via source and target branches