Merge branch 'room-enhance-performance' into 'master'
[Room] enhance performance See merge request famedly/famedlysdk!108
This commit is contained in:
commit
d48e98d7e6
|
@ -27,6 +27,7 @@ import 'package:famedlysdk/src/RoomAccountData.dart';
|
|||
import 'package:famedlysdk/src/RoomState.dart';
|
||||
import 'package:famedlysdk/src/responses/ErrorResponse.dart';
|
||||
import 'package:famedlysdk/src/sync/EventUpdate.dart';
|
||||
import 'package:famedlysdk/src/sync/RoomUpdate.dart';
|
||||
import 'package:famedlysdk/src/utils/ChatTime.dart';
|
||||
import 'package:famedlysdk/src/utils/MatrixFile.dart';
|
||||
import 'package:famedlysdk/src/utils/MxContent.dart';
|
||||
|
@ -532,6 +533,15 @@ class Room {
|
|||
client.connection.onEvent.add(eventUpdate);
|
||||
}
|
||||
}
|
||||
client.connection.onRoomUpdate.add(
|
||||
RoomUpdate(
|
||||
id: id,
|
||||
membership: membership,
|
||||
prev_batch: resp["end"],
|
||||
notification_count: notificationCount,
|
||||
highlight_count: highlightCount,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Sets this room as a direct chat for this user.
|
||||
|
|
|
@ -59,6 +59,7 @@ class RoomList {
|
|||
|
||||
StreamSubscription<EventUpdate> eventSub;
|
||||
StreamSubscription<RoomUpdate> roomSub;
|
||||
StreamSubscription<bool> firstSyncSub;
|
||||
|
||||
RoomList(
|
||||
{this.client,
|
||||
|
@ -69,6 +70,8 @@ class RoomList {
|
|||
this.onlyLeft = false}) {
|
||||
eventSub ??= client.connection.onEvent.stream.listen(_handleEventUpdate);
|
||||
roomSub ??= client.connection.onRoomUpdate.stream.listen(_handleRoomUpdate);
|
||||
firstSyncSub ??=
|
||||
client.connection.onFirstSync.stream.listen((b) => sortAndUpdate());
|
||||
sort();
|
||||
}
|
||||
|
||||
|
@ -148,6 +151,7 @@ class RoomList {
|
|||
}
|
||||
|
||||
void _handleEventUpdate(EventUpdate eventUpdate) {
|
||||
if (eventUpdate.type == "history") return;
|
||||
// Search the room in the rooms
|
||||
num j = 0;
|
||||
for (j = 0; j < rooms.length; j++) {
|
||||
|
@ -170,7 +174,7 @@ class RoomList {
|
|||
RoomAccountData.fromJson(eventUpdate.content, rooms[j]);
|
||||
}
|
||||
if (rooms[j].onUpdate != null) rooms[j].onUpdate();
|
||||
sortAndUpdate();
|
||||
if (eventUpdate.type == "timeline") sortAndUpdate();
|
||||
}
|
||||
|
||||
bool sortLock = false;
|
||||
|
@ -184,6 +188,7 @@ class RoomList {
|
|||
}
|
||||
|
||||
sortAndUpdate() {
|
||||
if (client.prevBatch == null) return;
|
||||
sort();
|
||||
if (onUpdate != null) onUpdate();
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ void main() {
|
|||
test("Create and insert one room", () async {
|
||||
final Client client = Client("testclient");
|
||||
client.homeserver = "https://testserver.abc";
|
||||
client.prevBatch = "1234";
|
||||
|
||||
int updateCount = 0;
|
||||
List<int> insertList = [];
|
||||
|
@ -85,6 +86,7 @@ void main() {
|
|||
test("Restort", () async {
|
||||
final Client client = Client("testclient");
|
||||
client.homeserver = "https://testserver.abc";
|
||||
client.prevBatch = "1234";
|
||||
|
||||
int updateCount = 0;
|
||||
List<int> insertList = [];
|
||||
|
@ -198,6 +200,7 @@ void main() {
|
|||
test("onlyLeft", () async {
|
||||
final Client client = Client("testclient");
|
||||
client.homeserver = "https://testserver.abc";
|
||||
client.prevBatch = "1234";
|
||||
|
||||
int updateCount = 0;
|
||||
List<int> insertList = [];
|
||||
|
|
Loading…
Reference in a new issue