Merge branch 'main' into karthi/fix-hangup-timeout

This commit is contained in:
td 2023-11-03 19:22:01 +05:30 committed by GitHub
commit 579b8aa944
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 119 additions and 104 deletions

View File

@ -1205,8 +1205,7 @@ const knownHashes = ['sha256'];
const knownHashesAuthentificationCodes = ['hkdf-hmac-sha256']; const knownHashesAuthentificationCodes = ['hkdf-hmac-sha256'];
class _KeyVerificationMethodSas extends _KeyVerificationMethod { class _KeyVerificationMethodSas extends _KeyVerificationMethod {
_KeyVerificationMethodSas({required KeyVerification request}) _KeyVerificationMethodSas({required super.request});
: super(request: request);
@override @override
// ignore: overridden_fields // ignore: overridden_fields

View File

@ -261,7 +261,7 @@ class Client extends MatrixApi {
bool enableDehydratedDevices = false; bool enableDehydratedDevices = false;
/// Wether read receipts are sent as public receipts by default or just as private receipts. /// Whether read receipts are sent as public receipts by default or just as private receipts.
bool receiptsPublicByDefault = true; bool receiptsPublicByDefault = true;
/// Whether this client supports end-to-end encryption using olm. /// Whether this client supports end-to-end encryption using olm.
@ -940,58 +940,74 @@ class Client extends MatrixApi {
final leave = syncResp.rooms?.leave; final leave = syncResp.rooms?.leave;
if (leave != null) { if (leave != null) {
for (final entry in leave.entries) { for (final entry in leave.entries) {
final id = entry.key; await _storeArchivedRoom(entry.key, entry.value);
final room = entry.value; }
final leftRoom = Room( }
return _archivedRooms;
}
/// [_storeArchivedRoom]
/// @leftRoom we can pass a room which was left so that we don't loose states
Future<void> _storeArchivedRoom(
String id,
LeftRoomUpdate update, {
Room? leftRoom,
}) async {
final roomUpdate = update;
final archivedRoom = leftRoom ??
Room(
id: id, id: id,
membership: Membership.leave, membership: Membership.leave,
client: this, client: this,
roomAccountData: roomAccountData: roomUpdate.accountData
room.accountData?.asMap().map((k, v) => MapEntry(v.type, v)) ?? ?.asMap()
.map((k, v) => MapEntry(v.type, v)) ??
<String, BasicRoomEvent>{}, <String, BasicRoomEvent>{},
); );
// Set membership of room to leave, in the case we got a left room passed, otherwise
// the left room would have still membership join, which would be wrong for the setState later
archivedRoom.membership = Membership.leave;
final timeline = Timeline( final timeline = Timeline(
room: leftRoom, room: archivedRoom,
chunk: TimelineChunk( chunk: TimelineChunk(
events: room.timeline?.events?.reversed events: roomUpdate.timeline?.events?.reversed
.toList() // we display the event in the other sence .toList() // we display the event in the other sence
.map((e) => Event.fromMatrixEvent(e, leftRoom)) .map((e) => Event.fromMatrixEvent(e, archivedRoom))
.toList() ?? .toList() ??
[])); []));
leftRoom.prev_batch = room.timeline?.prevBatch; archivedRoom.prev_batch = update.timeline?.prevBatch;
room.state?.forEach((event) { update.state?.forEach((event) {
leftRoom.setState(Event.fromMatrixEvent( archivedRoom.setState(Event.fromMatrixEvent(
event, event,
leftRoom, archivedRoom,
)); ));
}); });
room.timeline?.events?.forEach((event) { update.timeline?.events?.forEach((event) {
leftRoom.setState(Event.fromMatrixEvent( archivedRoom.setState(Event.fromMatrixEvent(
event, event,
leftRoom, archivedRoom,
)); ));
}); });
for (var i = 0; i < timeline.events.length; i++) { for (var i = 0; i < timeline.events.length; i++) {
// Try to decrypt encrypted events but don't update the database. // Try to decrypt encrypted events but don't update the database.
if (leftRoom.encrypted && leftRoom.client.encryptionEnabled) { if (archivedRoom.encrypted && archivedRoom.client.encryptionEnabled) {
if (timeline.events[i].type == EventTypes.Encrypted) { if (timeline.events[i].type == EventTypes.Encrypted) {
timeline.events[i] = await archivedRoom.client.encryption!
await leftRoom.client.encryption!.decryptRoomEvent( .decryptRoomEvent(
leftRoom.id, archivedRoom.id,
timeline.events[i], timeline.events[i],
)
.then(
(decrypted) => timeline.events[i] = decrypted,
); );
} }
} }
} }
_archivedRooms.add(ArchivedRoom(room: leftRoom, timeline: timeline)); _archivedRooms.add(ArchivedRoom(room: archivedRoom, timeline: timeline));
}
}
return _archivedRooms;
} }
/// Uploads a file and automatically caches it in the database, if it is small enough /// Uploads a file and automatically caches it in the database, if it is small enough
@ -1892,7 +1908,7 @@ class Client extends MatrixApi {
final syncRoomUpdate = entry.value; final syncRoomUpdate = entry.value;
await database?.storeRoomUpdate(id, syncRoomUpdate, this); await database?.storeRoomUpdate(id, syncRoomUpdate, this);
final room = _updateRoomsByRoomUpdate(id, syncRoomUpdate); final room = await _updateRoomsByRoomUpdate(id, syncRoomUpdate);
final timelineUpdateType = direction != null final timelineUpdateType = direction != null
? (direction == Direction.b ? (direction == Direction.b
@ -2132,7 +2148,8 @@ class Client extends MatrixApi {
} }
} }
Room _updateRoomsByRoomUpdate(String roomId, SyncRoomUpdate chatUpdate) { Future<Room> _updateRoomsByRoomUpdate(
String roomId, SyncRoomUpdate chatUpdate) async {
// Update the chat list item. // Update the chat list item.
// Search the room in the rooms // Search the room in the rooms
final roomIndex = rooms.indexWhere((r) => r.id == roomId); final roomIndex = rooms.indexWhere((r) => r.id == roomId);
@ -2175,8 +2192,13 @@ class Client extends MatrixApi {
room.stopStaleCallsChecker(room.id); room.stopStaleCallsChecker(room.id);
rooms.removeAt(roomIndex); rooms.removeAt(roomIndex);
// in order to keep the archive in sync, add left room to archive
if (chatUpdate is LeftRoomUpdate) {
await _storeArchivedRoom(room.id, chatUpdate, leftRoom: room);
} }
// Update notification, highlight count and/or additional informations }
// Update notification, highlight count and/or additional information
else if (found && else if (found &&
chatUpdate is JoinedRoomUpdate && chatUpdate is JoinedRoomUpdate &&
(rooms[roomIndex].membership != membership || (rooms[roomIndex].membership != membership ||
@ -2206,7 +2228,7 @@ class Client extends MatrixApi {
requestHistoryOnLimitedTimeline) { requestHistoryOnLimitedTimeline) {
Logs().v( Logs().v(
'Limited timeline for ${rooms[roomIndex].id} request history now'); 'Limited timeline for ${rooms[roomIndex].id} request history now');
runInRoot(rooms[roomIndex].requestHistory); unawaited(runInRoot(rooms[roomIndex].requestHistory));
} }
} }
return room; return room;

View File

@ -79,10 +79,10 @@ class Event extends MatrixEvent {
Event({ Event({
this.status = defaultStatus, this.status = defaultStatus,
required Map<String, dynamic> content, required Map<String, dynamic> super.content,
required String type, required super.type,
required String eventId, required String eventId,
required String senderId, required super.senderId,
required DateTime originServerTs, required DateTime originServerTs,
Map<String, dynamic>? unsigned, Map<String, dynamic>? unsigned,
Map<String, dynamic>? prevContent, Map<String, dynamic>? prevContent,
@ -91,10 +91,7 @@ class Event extends MatrixEvent {
MatrixEvent? originalSource, MatrixEvent? originalSource,
}) : _originalSource = originalSource, }) : _originalSource = originalSource,
super( super(
content: content,
type: type,
eventId: eventId, eventId: eventId,
senderId: senderId,
originServerTs: originServerTs, originServerTs: originServerTs,
roomId: room.id, roomId: room.id,
) { ) {

View File

@ -1187,6 +1187,12 @@ class Room {
Future<void> forget() async { Future<void> forget() async {
await client.database?.forgetRoom(id); await client.database?.forgetRoom(id);
await client.forgetRoom(id); await client.forgetRoom(id);
// Update archived rooms, otherwise an archived room may still be in the
// list after a forget room call
final roomIndex = client.archivedRooms.indexWhere((r) => r.room.id == id);
if (roomIndex != -1) {
client.archivedRooms.removeAt(roomIndex);
}
return; return;
} }
@ -1375,7 +1381,7 @@ class Room {
); );
final events = [ final events = [
if (resp.eventsAfter != null) ...resp.eventsAfter!.reversed.toList(), if (resp.eventsAfter != null) ...resp.eventsAfter!.reversed,
if (resp.event != null) resp.event!, if (resp.event != null) resp.event!,
if (resp.eventsBefore != null) ...resp.eventsBefore! if (resp.eventsBefore != null) ...resp.eventsBefore!
].map((e) => Event.fromMatrixEvent(e, this)).toList(); ].map((e) => Event.fromMatrixEvent(e, this)).toList();

View File

@ -43,25 +43,17 @@ class User extends Event {
} }
User.fromState({ User.fromState({
Map<String, dynamic>? prevContent, super.prevContent,
required String stateKey, required String super.stateKey,
Map<String, dynamic> content = const {}, super.content = const {},
required String typeKey, required String typeKey,
required String eventId, required super.eventId,
required String senderId, required super.senderId,
required DateTime originServerTs, required super.originServerTs,
dynamic unsigned, super.unsigned,
required Room room, required super.room,
}) : super( }) : super(
stateKey: stateKey,
prevContent: prevContent,
content: content,
type: typeKey, type: typeKey,
eventId: eventId,
senderId: senderId,
originServerTs: originServerTs,
unsigned: unsigned,
room: room,
); );
/// The full qualified Matrix ID in the format @username:server.abc. /// The full qualified Matrix ID in the format @username:server.abc.

View File

@ -135,7 +135,8 @@ class SimpleSignableKey extends MatrixSignableKey {
@override @override
String? identifier; String? identifier;
SimpleSignableKey.fromJson(Map<String, dynamic> json) : super.fromJson(json); SimpleSignableKey.fromJson(Map<String, dynamic> super.json)
: super.fromJson();
} }
abstract class SignableKey extends MatrixSignableKey { abstract class SignableKey extends MatrixSignableKey {
@ -166,8 +167,8 @@ abstract class SignableKey extends MatrixSignableKey {
bool get crossVerified => hasValidSignatureChain(); bool get crossVerified => hasValidSignatureChain();
bool get signed => hasValidSignatureChain(verifiedOnly: false); bool get signed => hasValidSignatureChain(verifiedOnly: false);
SignableKey.fromJson(Map<String, dynamic> json, this.client) SignableKey.fromJson(Map<String, dynamic> super.json, this.client)
: super.fromJson(json) { : super.fromJson() {
_verified = false; _verified = false;
_blocked = false; _blocked = false;
} }

View File

@ -50,7 +50,7 @@ abstract class TimeoutHttpClient extends http.BaseClient {
} }
class FixedTimeoutHttpClient extends TimeoutHttpClient { class FixedTimeoutHttpClient extends TimeoutHttpClient {
FixedTimeoutHttpClient(http.Client inner, this.timeout) : super(inner); FixedTimeoutHttpClient(super.inner, this.timeout);
@override @override
Duration timeout; Duration timeout;
} }

View File

@ -17,6 +17,7 @@
*/ */
/// Workaround until [File] in dart:io and dart:html is unified /// Workaround until [File] in dart:io and dart:html is unified
library;
import 'dart:async'; import 'dart:async';
import 'dart:typed_data'; import 'dart:typed_data';
@ -91,15 +92,14 @@ class MatrixFile {
class MatrixImageFile extends MatrixFile { class MatrixImageFile extends MatrixFile {
MatrixImageFile({ MatrixImageFile({
required Uint8List bytes, required super.bytes,
required String name, required super.name,
String? mimeType, super.mimeType,
int? width, int? width,
int? height, int? height,
this.blurhash, this.blurhash,
}) : _width = width, }) : _width = width,
_height = height, _height = height;
super(bytes: bytes, name: name, mimeType: mimeType);
/// Creates a new image file and calculates the width, height and blurhash. /// Creates a new image file and calculates the width, height and blurhash.
static Future<MatrixImageFile> create({ static Future<MatrixImageFile> create({
@ -355,13 +355,12 @@ class MatrixVideoFile extends MatrixFile {
final int? duration; final int? duration;
MatrixVideoFile( MatrixVideoFile(
{required Uint8List bytes, {required super.bytes,
required String name, required super.name,
String? mimeType, super.mimeType,
this.width, this.width,
this.height, this.height,
this.duration}) this.duration});
: super(bytes: bytes, name: name, mimeType: mimeType);
@override @override
String get msgType => 'm.video'; String get msgType => 'm.video';
@ -379,11 +378,10 @@ class MatrixAudioFile extends MatrixFile {
final int? duration; final int? duration;
MatrixAudioFile( MatrixAudioFile(
{required Uint8List bytes, {required super.bytes,
required String name, required super.name,
String? mimeType, super.mimeType,
this.duration}) this.duration});
: super(bytes: bytes, name: name, mimeType: mimeType);
@override @override
String get msgType => 'm.audio'; String get msgType => 'm.audio';

View File

@ -26,10 +26,10 @@ class ToDeviceEvent extends BasicEventWithSender {
ToDeviceEvent({ ToDeviceEvent({
required String sender, required String sender,
required String type, required super.type,
required Map<String, dynamic> content, required Map<String, dynamic> super.content,
this.encryptedContent, this.encryptedContent,
}) : super(senderId: sender, type: type, content: content); }) : super(senderId: sender);
factory ToDeviceEvent.fromJson(Map<String, dynamic> json) { factory ToDeviceEvent.fromJson(Map<String, dynamic> json) {
final event = BasicEventWithSender.fromJson(json); final event = BasicEventWithSender.fromJson(json);

View File

@ -33,9 +33,9 @@ dependencies:
dev_dependencies: dev_dependencies:
coverage: ">=0.15.0 <2.0.0" coverage: ">=0.15.0 <2.0.0"
file: ^6.1.1 file: ">=6.1.1 <8.0.0"
import_sorter: ^4.6.0 import_sorter: ^4.6.0
lints: ^2.0.0 lints: ^3.0.0
test: ^1.15.7 test: ^1.15.7
#flutter_test: {sdk: flutter} #flutter_test: {sdk: flutter}
#dependency_overrides: #dependency_overrides:

View File

@ -36,7 +36,7 @@ Uint8List secureRandomBytes(int len) {
} }
class MockSSSS extends SSSS { class MockSSSS extends SSSS {
MockSSSS(Encryption encryption) : super(encryption); MockSSSS(super.encryption);
bool requestedSecrets = false; bool requestedSecrets = false;
@override @override