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