mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-17 04:20:00 +03:00
Fix / if listener is not removed messages could be duplicated
This commit is contained in:
parent
5bd448405b
commit
668967546c
1 changed files with 3 additions and 2 deletions
|
@ -117,6 +117,7 @@ class CommonTestHelper(context: Context) {
|
||||||
* @param nbOfMessages the number of time the message will be sent
|
* @param nbOfMessages the number of time the message will be sent
|
||||||
*/
|
*/
|
||||||
fun sendTextMessage(room: Room, message: String, nbOfMessages: Int): List<TimelineEvent> {
|
fun sendTextMessage(room: Room, message: String, nbOfMessages: Int): List<TimelineEvent> {
|
||||||
|
val timeline = room.createTimeline(null, TimelineSettings(10))
|
||||||
val sentEvents = ArrayList<TimelineEvent>(nbOfMessages)
|
val sentEvents = ArrayList<TimelineEvent>(nbOfMessages)
|
||||||
val latch = CountDownLatch(1)
|
val latch = CountDownLatch(1)
|
||||||
val timelineListener = object : Timeline.Listener {
|
val timelineListener = object : Timeline.Listener {
|
||||||
|
@ -135,11 +136,12 @@ class CommonTestHelper(context: Context) {
|
||||||
|
|
||||||
if (newMessages.size == nbOfMessages) {
|
if (newMessages.size == nbOfMessages) {
|
||||||
sentEvents.addAll(newMessages)
|
sentEvents.addAll(newMessages)
|
||||||
|
// Remove listener now, if not at the next update sendEvents could change
|
||||||
|
timeline.removeListener(this)
|
||||||
latch.countDown()
|
latch.countDown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val timeline = room.createTimeline(null, TimelineSettings(10))
|
|
||||||
timeline.start()
|
timeline.start()
|
||||||
timeline.addListener(timelineListener)
|
timeline.addListener(timelineListener)
|
||||||
for (i in 0 until nbOfMessages) {
|
for (i in 0 until nbOfMessages) {
|
||||||
|
@ -147,7 +149,6 @@ class CommonTestHelper(context: Context) {
|
||||||
}
|
}
|
||||||
// Wait 3 second more per message
|
// Wait 3 second more per message
|
||||||
await(latch, timeout = TestConstants.timeOutMillis + 3_000L * nbOfMessages)
|
await(latch, timeout = TestConstants.timeOutMillis + 3_000L * nbOfMessages)
|
||||||
timeline.removeListener(timelineListener)
|
|
||||||
timeline.dispose()
|
timeline.dispose()
|
||||||
|
|
||||||
// Check that all events has been created
|
// Check that all events has been created
|
||||||
|
|
Loading…
Add table
Reference in a new issue