2019-06-21 10:18:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Zender & Kurtz GbR.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Christian Pauly <krille@famedly.com>
|
|
|
|
* Marcel Radzio <mtrnord@famedly.com>
|
|
|
|
*
|
|
|
|
* This file is part of famedlysdk.
|
|
|
|
*
|
|
|
|
* famedlysdk is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* famedlysdk is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
Update lib/src/client.dart, lib/src/user.dart, lib/src/timeline.dart, lib/src/room.dart, lib/src/presence.dart, lib/src/event.dart, lib/src/utils/profile.dart, lib/src/utils/receipt.dart, test/client_test.dart, test/event_test.dart, test/presence_test.dart, test/room_test.dart, test/timeline_test.dart, test/user_test.dart files
2020-01-04 17:56:17 +00:00
|
|
|
import 'package:famedlysdk/src/room_account_data.dart';
|
2019-10-04 09:44:32 +00:00
|
|
|
import 'package:test/test.dart';
|
Update lib/src/client.dart, lib/src/user.dart, lib/src/timeline.dart, lib/src/room.dart, lib/src/presence.dart, lib/src/event.dart, lib/src/utils/profile.dart, lib/src/utils/receipt.dart, test/client_test.dart, test/event_test.dart, test/presence_test.dart, test/room_test.dart, test/timeline_test.dart, test/user_test.dart files
2020-01-04 17:56:17 +00:00
|
|
|
import 'package:famedlysdk/src/client.dart';
|
|
|
|
import 'package:famedlysdk/src/room.dart';
|
|
|
|
import 'package:famedlysdk/src/timeline.dart';
|
2020-05-21 14:52:14 +00:00
|
|
|
import 'package:famedlysdk/src/user.dart';
|
Update lib/src/client.dart, lib/src/user.dart, lib/src/timeline.dart, lib/src/room.dart, lib/src/presence.dart, lib/src/event.dart, lib/src/utils/profile.dart, lib/src/utils/receipt.dart, test/client_test.dart, test/event_test.dart, test/presence_test.dart, test/room_test.dart, test/timeline_test.dart, test/user_test.dart files
2020-01-04 17:56:17 +00:00
|
|
|
import 'package:famedlysdk/src/sync/event_update.dart';
|
2020-05-21 14:52:14 +00:00
|
|
|
import 'package:famedlysdk/src/sync/room_update.dart';
|
Update lib/src/client.dart, lib/src/user.dart, lib/src/timeline.dart, lib/src/room.dart, lib/src/presence.dart, lib/src/event.dart, lib/src/utils/profile.dart, lib/src/utils/receipt.dart, test/client_test.dart, test/event_test.dart, test/presence_test.dart, test/room_test.dart, test/timeline_test.dart, test/user_test.dart files
2020-01-04 17:56:17 +00:00
|
|
|
import 'fake_matrix_api.dart';
|
2019-06-21 10:18:54 +00:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
/// All Tests related to the MxContent
|
2020-03-30 09:08:38 +00:00
|
|
|
group('Timeline', () {
|
|
|
|
final roomID = '!1234:example.com';
|
2020-01-02 14:09:49 +00:00
|
|
|
final testTimeStamp = DateTime.now().millisecondsSinceEpoch;
|
2020-03-30 09:08:38 +00:00
|
|
|
var updateCount = 0;
|
|
|
|
var insertList = <int>[];
|
2019-06-21 10:18:54 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
var client = Client('testclient', debug: true);
|
2020-01-02 14:09:49 +00:00
|
|
|
client.httpClient = FakeMatrixApi();
|
2019-06-21 10:18:54 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
var room = Room(
|
|
|
|
id: roomID, client: client, prev_batch: '1234', roomAccountData: {});
|
|
|
|
var timeline = Timeline(
|
2019-06-26 14:36:34 +00:00
|
|
|
room: room,
|
|
|
|
events: [],
|
|
|
|
onUpdate: () {
|
|
|
|
updateCount++;
|
|
|
|
},
|
|
|
|
onInsert: (int insertID) {
|
|
|
|
insertList.add(insertID);
|
|
|
|
});
|
2019-06-21 10:18:54 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('Create', () async {
|
|
|
|
await client.checkServer('https://fakeServer.notExisting');
|
2020-01-02 14:09:49 +00:00
|
|
|
client.onEvent.add(EventUpdate(
|
2020-03-30 09:08:38 +00:00
|
|
|
type: 'timeline',
|
2019-06-21 10:18:54 +00:00
|
|
|
roomID: roomID,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventType: 'm.room.message',
|
2019-06-21 10:18:54 +00:00
|
|
|
content: {
|
2020-03-30 09:08:38 +00:00
|
|
|
'type': 'm.room.message',
|
|
|
|
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
|
|
|
|
'sender': '@alice:example.com',
|
|
|
|
'status': 2,
|
|
|
|
'event_id': '1',
|
|
|
|
'origin_server_ts': testTimeStamp
|
2020-05-15 18:40:17 +00:00
|
|
|
},
|
|
|
|
sortOrder: room.newSortOrder));
|
2019-06-21 10:18:54 +00:00
|
|
|
|
2020-01-02 14:09:49 +00:00
|
|
|
client.onEvent.add(EventUpdate(
|
2020-03-30 09:08:38 +00:00
|
|
|
type: 'timeline',
|
2019-06-21 11:30:39 +00:00
|
|
|
roomID: roomID,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventType: 'm.room.message',
|
2019-06-21 11:30:39 +00:00
|
|
|
content: {
|
2020-03-30 09:08:38 +00:00
|
|
|
'type': 'm.room.message',
|
|
|
|
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
|
|
|
|
'sender': '@alice:example.com',
|
|
|
|
'status': 2,
|
|
|
|
'event_id': '2',
|
|
|
|
'origin_server_ts': testTimeStamp - 1000
|
2020-05-15 18:40:17 +00:00
|
|
|
},
|
|
|
|
sortOrder: room.oldSortOrder));
|
2019-06-21 11:30:39 +00:00
|
|
|
|
2019-06-21 10:18:54 +00:00
|
|
|
expect(timeline.sub != null, true);
|
|
|
|
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2019-06-21 10:18:54 +00:00
|
|
|
|
2019-06-21 11:30:39 +00:00
|
|
|
expect(updateCount, 2);
|
|
|
|
expect(insertList, [0, 0]);
|
2019-06-26 18:03:20 +00:00
|
|
|
expect(insertList.length, timeline.events.length);
|
2019-06-21 11:30:39 +00:00
|
|
|
expect(timeline.events.length, 2);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(timeline.events[0].eventId, '1');
|
|
|
|
expect(timeline.events[0].sender.id, '@alice:example.com');
|
2020-01-02 14:09:49 +00:00
|
|
|
expect(timeline.events[0].time.millisecondsSinceEpoch, testTimeStamp);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(timeline.events[0].body, 'Testcase');
|
2020-01-02 14:09:49 +00:00
|
|
|
expect(
|
|
|
|
timeline.events[0].time.millisecondsSinceEpoch >
|
|
|
|
timeline.events[1].time.millisecondsSinceEpoch,
|
|
|
|
true);
|
2019-10-20 09:44:14 +00:00
|
|
|
expect(timeline.events[0].receipts, []);
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
room.roomAccountData['m.receipt'] = RoomAccountData.fromJson({
|
|
|
|
'type': 'm.receipt',
|
|
|
|
'content': {
|
|
|
|
'@alice:example.com': {
|
|
|
|
'event_id': '1',
|
|
|
|
'ts': 1436451550453,
|
2019-10-20 09:44:14 +00:00
|
|
|
}
|
|
|
|
},
|
2020-03-30 09:08:38 +00:00
|
|
|
'room_id': roomID,
|
2019-10-20 09:44:14 +00:00
|
|
|
}, room);
|
|
|
|
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2019-10-20 09:44:14 +00:00
|
|
|
|
|
|
|
expect(timeline.events[0].receipts.length, 1);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(timeline.events[0].receipts[0].user.id, '@alice:example.com');
|
2019-12-12 12:19:18 +00:00
|
|
|
|
2020-01-02 14:09:49 +00:00
|
|
|
client.onEvent.add(EventUpdate(
|
2020-03-30 09:08:38 +00:00
|
|
|
type: 'timeline',
|
2019-12-12 12:19:18 +00:00
|
|
|
roomID: roomID,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventType: 'm.room.redaction',
|
2019-12-12 12:19:18 +00:00
|
|
|
content: {
|
2020-03-30 09:08:38 +00:00
|
|
|
'type': 'm.room.redaction',
|
|
|
|
'content': {'reason': 'spamming'},
|
|
|
|
'sender': '@alice:example.com',
|
|
|
|
'redacts': '2',
|
|
|
|
'event_id': '3',
|
|
|
|
'origin_server_ts': testTimeStamp + 1000
|
2020-05-15 18:40:17 +00:00
|
|
|
},
|
|
|
|
sortOrder: room.newSortOrder));
|
2019-12-12 12:19:18 +00:00
|
|
|
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2019-12-12 12:19:18 +00:00
|
|
|
|
|
|
|
expect(updateCount, 3);
|
|
|
|
expect(insertList, [0, 0]);
|
|
|
|
expect(insertList.length, timeline.events.length);
|
|
|
|
expect(timeline.events.length, 2);
|
|
|
|
expect(timeline.events[1].redacted, true);
|
2019-06-21 10:18:54 +00:00
|
|
|
});
|
2019-06-26 14:36:34 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('Send message', () async {
|
|
|
|
await room.sendTextEvent('test', txid: '1234');
|
2019-06-26 14:36:34 +00:00
|
|
|
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2019-06-26 14:36:34 +00:00
|
|
|
|
2019-12-12 12:19:18 +00:00
|
|
|
expect(updateCount, 5);
|
2019-06-26 14:36:34 +00:00
|
|
|
expect(insertList, [0, 0, 0]);
|
2019-06-26 18:03:20 +00:00
|
|
|
expect(insertList.length, timeline.events.length);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(timeline.events[0].eventId, '42');
|
2019-06-26 14:36:34 +00:00
|
|
|
expect(timeline.events[0].status, 1);
|
|
|
|
|
2020-01-02 14:09:49 +00:00
|
|
|
client.onEvent.add(EventUpdate(
|
2020-03-30 09:08:38 +00:00
|
|
|
type: 'timeline',
|
2019-06-26 14:36:34 +00:00
|
|
|
roomID: roomID,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventType: 'm.room.message',
|
2019-06-26 14:36:34 +00:00
|
|
|
content: {
|
2020-03-30 09:08:38 +00:00
|
|
|
'type': 'm.room.message',
|
|
|
|
'content': {'msgtype': 'm.text', 'body': 'test'},
|
|
|
|
'sender': '@alice:example.com',
|
|
|
|
'status': 2,
|
|
|
|
'event_id': '42',
|
|
|
|
'unsigned': {'transaction_id': '1234'},
|
|
|
|
'origin_server_ts': DateTime.now().millisecondsSinceEpoch
|
2020-05-15 18:40:17 +00:00
|
|
|
},
|
|
|
|
sortOrder: room.newSortOrder));
|
2019-06-26 14:36:34 +00:00
|
|
|
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2019-06-26 14:36:34 +00:00
|
|
|
|
2019-12-12 12:19:18 +00:00
|
|
|
expect(updateCount, 6);
|
2019-06-26 14:36:34 +00:00
|
|
|
expect(insertList, [0, 0, 0]);
|
2019-06-26 18:03:20 +00:00
|
|
|
expect(insertList.length, timeline.events.length);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(timeline.events[0].eventId, '42');
|
2019-06-26 14:36:34 +00:00
|
|
|
expect(timeline.events[0].status, 2);
|
|
|
|
});
|
2019-06-26 14:37:49 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('Send message with error', () async {
|
2020-01-02 14:09:49 +00:00
|
|
|
client.onEvent.add(EventUpdate(
|
2020-03-30 09:08:38 +00:00
|
|
|
type: 'timeline',
|
2019-06-26 18:03:20 +00:00
|
|
|
roomID: roomID,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventType: 'm.room.message',
|
2019-06-26 18:03:20 +00:00
|
|
|
content: {
|
2020-03-30 09:08:38 +00:00
|
|
|
'type': 'm.room.message',
|
|
|
|
'content': {'msgtype': 'm.text', 'body': 'Testcase'},
|
|
|
|
'sender': '@alice:example.com',
|
|
|
|
'status': 0,
|
|
|
|
'event_id': 'abc',
|
|
|
|
'origin_server_ts': testTimeStamp
|
2020-05-15 18:40:17 +00:00
|
|
|
},
|
|
|
|
sortOrder: room.newSortOrder));
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2020-03-30 09:08:38 +00:00
|
|
|
await room.sendTextEvent('test', txid: 'errortxid');
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2020-03-30 09:08:38 +00:00
|
|
|
await room.sendTextEvent('test', txid: 'errortxid2');
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2020-03-30 09:08:38 +00:00
|
|
|
await room.sendTextEvent('test', txid: 'errortxid3');
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2019-06-26 14:37:49 +00:00
|
|
|
|
2019-12-12 12:19:18 +00:00
|
|
|
expect(updateCount, 13);
|
2019-06-26 18:03:20 +00:00
|
|
|
expect(insertList, [0, 0, 0, 0, 0, 0, 0]);
|
|
|
|
expect(insertList.length, timeline.events.length);
|
2019-06-26 14:37:49 +00:00
|
|
|
expect(timeline.events[0].status, -1);
|
2019-06-26 18:03:20 +00:00
|
|
|
expect(timeline.events[1].status, -1);
|
|
|
|
expect(timeline.events[2].status, -1);
|
2019-06-26 14:37:49 +00:00
|
|
|
});
|
2019-06-27 08:12:39 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('Remove message', () async {
|
2020-01-02 14:33:26 +00:00
|
|
|
await timeline.events[0].remove();
|
2019-06-27 08:12:39 +00:00
|
|
|
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2019-06-27 08:12:39 +00:00
|
|
|
|
2019-12-12 12:19:18 +00:00
|
|
|
expect(updateCount, 14);
|
2019-06-27 08:12:39 +00:00
|
|
|
|
|
|
|
expect(insertList, [0, 0, 0, 0, 0, 0, 0]);
|
|
|
|
expect(timeline.events.length, 6);
|
|
|
|
expect(timeline.events[0].status, -1);
|
|
|
|
});
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('Resend message', () async {
|
|
|
|
await timeline.events[0].sendAgain(txid: '1234');
|
2019-06-27 08:12:39 +00:00
|
|
|
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2019-06-27 08:12:39 +00:00
|
|
|
|
2019-12-12 12:19:18 +00:00
|
|
|
expect(updateCount, 17);
|
2019-06-27 08:12:39 +00:00
|
|
|
|
|
|
|
expect(insertList, [0, 0, 0, 0, 0, 0, 0, 0]);
|
|
|
|
expect(timeline.events.length, 6);
|
|
|
|
expect(timeline.events[0].status, 1);
|
|
|
|
});
|
2019-06-28 06:39:43 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('Request history', () async {
|
2019-06-28 06:39:43 +00:00
|
|
|
await room.requestHistory();
|
|
|
|
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2019-06-28 06:39:43 +00:00
|
|
|
|
2019-12-12 12:19:18 +00:00
|
|
|
expect(updateCount, 20);
|
2019-06-28 06:39:43 +00:00
|
|
|
expect(timeline.events.length, 9);
|
2020-05-15 18:40:17 +00:00
|
|
|
expect(timeline.events[6].eventId, '3143273582443PhrSn:example.org');
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(timeline.events[7].eventId, '2143273582443PhrSn:example.org');
|
2020-05-15 18:40:17 +00:00
|
|
|
expect(timeline.events[8].eventId, '1143273582443PhrSn:example.org');
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(room.prev_batch, 't47409-4357353_219380_26003_2265');
|
2019-06-28 06:39:43 +00:00
|
|
|
});
|
2020-05-21 14:52:14 +00:00
|
|
|
|
|
|
|
test('Clear cache on limited timeline', () async {
|
|
|
|
client.onRoomUpdate.add(RoomUpdate(
|
|
|
|
id: roomID,
|
|
|
|
membership: Membership.join,
|
|
|
|
notification_count: 0,
|
|
|
|
highlight_count: 0,
|
|
|
|
limitedTimeline: true,
|
|
|
|
prev_batch: 'blah',
|
|
|
|
));
|
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
|
|
|
expect(timeline.events.isEmpty, true);
|
|
|
|
});
|
2019-06-21 10:18:54 +00:00
|
|
|
});
|
|
|
|
}
|