Merge branch 'main' into reza/send-reaction-on-only-admin-can-send-message-room
This commit is contained in:
commit
ba9c3e7fc9
|
|
@ -2283,16 +2283,18 @@ class Client extends MatrixApi {
|
||||||
// The timeout we send to the server for the sync loop. It says to the
|
// The timeout we send to the server for the sync loop. It says to the
|
||||||
// server that we want to receive an empty sync response after this
|
// server that we want to receive an empty sync response after this
|
||||||
// amount of time if nothing happens.
|
// amount of time if nothing happens.
|
||||||
timeout ??= const Duration(seconds: 30);
|
if (prevBatch != null) timeout ??= const Duration(seconds: 30);
|
||||||
|
|
||||||
await ensureNotSoftLoggedOut(timeout * 2);
|
await ensureNotSoftLoggedOut(
|
||||||
|
timeout == null ? const Duration(minutes: 1) : (timeout * 2),
|
||||||
|
);
|
||||||
|
|
||||||
await _checkSyncFilter();
|
await _checkSyncFilter();
|
||||||
|
|
||||||
final syncRequest = sync(
|
final syncRequest = sync(
|
||||||
filter: syncFilterId,
|
filter: syncFilterId,
|
||||||
since: prevBatch,
|
since: prevBatch,
|
||||||
timeout: timeout.inMilliseconds,
|
timeout: timeout?.inMilliseconds,
|
||||||
setPresence: syncPresence,
|
setPresence: syncPresence,
|
||||||
).then((v) => Future<SyncUpdate?>.value(v)).catchError((e) {
|
).then((v) => Future<SyncUpdate?>.value(v)).catchError((e) {
|
||||||
if (e is MatrixException) {
|
if (e is MatrixException) {
|
||||||
|
|
@ -2308,11 +2310,13 @@ class Client extends MatrixApi {
|
||||||
// The timeout for the response from the server. If we do not set a sync
|
// The timeout for the response from the server. If we do not set a sync
|
||||||
// timeout (for initial sync) we give the server a longer time to
|
// timeout (for initial sync) we give the server a longer time to
|
||||||
// responde.
|
// responde.
|
||||||
final responseTimeout = timeout == Duration.zero
|
final responseTimeout =
|
||||||
? const Duration(minutes: 2)
|
timeout == null ? null : timeout + const Duration(seconds: 10);
|
||||||
: timeout + const Duration(seconds: 10);
|
|
||||||
|
final syncResp = responseTimeout == null
|
||||||
|
? await syncRequest
|
||||||
|
: await syncRequest.timeout(responseTimeout);
|
||||||
|
|
||||||
final syncResp = await syncRequest.timeout(responseTimeout);
|
|
||||||
onSyncStatus.add(SyncStatusUpdate(SyncStatus.processing));
|
onSyncStatus.add(SyncStatusUpdate(SyncStatus.processing));
|
||||||
if (syncResp == null) throw syncError ?? 'Unknown sync error';
|
if (syncResp == null) throw syncError ?? 'Unknown sync error';
|
||||||
if (_currentSyncId != syncRequest.hashCode) {
|
if (_currentSyncId != syncRequest.hashCode) {
|
||||||
|
|
|
||||||
|
|
@ -1264,19 +1264,27 @@ class Room {
|
||||||
reason: reason,
|
reason: reason,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Request more previous events from the server. [historyCount] defines how much events should
|
/// Request more previous events from the server. [historyCount] defines how many events should
|
||||||
/// be received maximum. When the request is answered, [onHistoryReceived] will be triggered **before**
|
/// be received maximum. When the request is answered, [onHistoryReceived] will be triggered **before**
|
||||||
/// the historical events will be published in the onEvent stream.
|
/// the historical events will be published in the onEvent stream. [filter] allows you to specify a
|
||||||
|
/// [StateFilter] object to filter the events, which can include various criteria such as event types
|
||||||
|
/// (e.g., [EventTypes.Message]) and other state-related filters. The [StateFilter] object will have
|
||||||
|
/// [lazyLoadMembers] set to true by default, but this can be overridden.
|
||||||
/// Returns the actual count of received timeline events.
|
/// Returns the actual count of received timeline events.
|
||||||
Future<int> requestHistory({
|
Future<int> requestHistory({
|
||||||
int historyCount = defaultHistoryCount,
|
int historyCount = defaultHistoryCount,
|
||||||
void Function()? onHistoryReceived,
|
void Function()? onHistoryReceived,
|
||||||
direction = Direction.b,
|
direction = Direction.b,
|
||||||
|
StateFilter? filter,
|
||||||
}) async {
|
}) async {
|
||||||
final prev_batch = this.prev_batch;
|
final prev_batch = this.prev_batch;
|
||||||
|
|
||||||
final storeInDatabase = !isArchived;
|
final storeInDatabase = !isArchived;
|
||||||
|
|
||||||
|
// Ensure stateFilter is not null and set lazyLoadMembers to true if not already set
|
||||||
|
filter ??= StateFilter(lazyLoadMembers: true);
|
||||||
|
filter.lazyLoadMembers ??= true;
|
||||||
|
|
||||||
if (prev_batch == null) {
|
if (prev_batch == null) {
|
||||||
throw 'Tried to request history without a prev_batch token';
|
throw 'Tried to request history without a prev_batch token';
|
||||||
}
|
}
|
||||||
|
|
@ -1285,7 +1293,7 @@ class Room {
|
||||||
direction,
|
direction,
|
||||||
from: prev_batch,
|
from: prev_batch,
|
||||||
limit: historyCount,
|
limit: historyCount,
|
||||||
filter: jsonEncode(StateFilter(lazyLoadMembers: true).toJson()),
|
filter: jsonEncode(filter.toJson()),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (onHistoryReceived != null) onHistoryReceived();
|
if (onHistoryReceived != null) onHistoryReceived();
|
||||||
|
|
@ -2093,16 +2101,22 @@ class Room {
|
||||||
/// Returns the [PushRuleState] for this room, based on the m.push_rules stored in
|
/// Returns the [PushRuleState] for this room, based on the m.push_rules stored in
|
||||||
/// the account_data.
|
/// the account_data.
|
||||||
PushRuleState get pushRuleState {
|
PushRuleState get pushRuleState {
|
||||||
final globalPushRules =
|
final globalPushRules = client.globalPushRules;
|
||||||
client.accountData['m.push_rules']?.content['global'];
|
if (globalPushRules == null) {
|
||||||
if (globalPushRules is! Map) {
|
// We have no push rules specified at all so we fallback to just notify:
|
||||||
return PushRuleState.notify;
|
return PushRuleState.notify;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (globalPushRules['override'] is List) {
|
final overridePushRules = globalPushRules.override;
|
||||||
for (final pushRule in globalPushRules['override']) {
|
if (overridePushRules != null) {
|
||||||
if (pushRule['rule_id'] == id) {
|
for (final pushRule in overridePushRules) {
|
||||||
if (pushRule['actions'].indexOf('dont_notify') != -1) {
|
if (pushRule.ruleId == id) {
|
||||||
|
// "dont_notify" and "coalesce" should be ignored in actions since
|
||||||
|
// https://spec.matrix.org/v1.7/client-server-api/#actions
|
||||||
|
pushRule.actions
|
||||||
|
..remove('dont_notify')
|
||||||
|
..remove('coalesce');
|
||||||
|
if (pushRule.actions.isEmpty) {
|
||||||
return PushRuleState.dontNotify;
|
return PushRuleState.dontNotify;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -2110,10 +2124,16 @@ class Room {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (globalPushRules['room'] is List) {
|
final roomPushRules = globalPushRules.room;
|
||||||
for (final pushRule in globalPushRules['room']) {
|
if (roomPushRules != null) {
|
||||||
if (pushRule['rule_id'] == id) {
|
for (final pushRule in roomPushRules) {
|
||||||
if (pushRule['actions'].indexOf('dont_notify') != -1) {
|
if (pushRule.ruleId == id) {
|
||||||
|
// "dont_notify" and "coalesce" should be ignored in actions since
|
||||||
|
// https://spec.matrix.org/v1.7/client-server-api/#actions
|
||||||
|
pushRule.actions
|
||||||
|
..remove('dont_notify')
|
||||||
|
..remove('coalesce');
|
||||||
|
if (pushRule.actions.isEmpty) {
|
||||||
return PushRuleState.mentionsOnly;
|
return PushRuleState.mentionsOnly;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -2145,13 +2165,13 @@ class Room {
|
||||||
await client.setPushRule(
|
await client.setPushRule(
|
||||||
PushRuleKind.room,
|
PushRuleKind.room,
|
||||||
id,
|
id,
|
||||||
[PushRuleAction.dontNotify],
|
[],
|
||||||
);
|
);
|
||||||
} else if (pushRuleState == PushRuleState.notify) {
|
} else if (pushRuleState == PushRuleState.notify) {
|
||||||
await client.setPushRule(
|
await client.setPushRule(
|
||||||
PushRuleKind.room,
|
PushRuleKind.room,
|
||||||
id,
|
id,
|
||||||
[PushRuleAction.dontNotify],
|
[],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -2163,7 +2183,7 @@ class Room {
|
||||||
await client.setPushRule(
|
await client.setPushRule(
|
||||||
PushRuleKind.override,
|
PushRuleKind.override,
|
||||||
id,
|
id,
|
||||||
[PushRuleAction.dontNotify],
|
[],
|
||||||
conditions: [
|
conditions: [
|
||||||
PushCondition(kind: 'event_match', key: 'room_id', pattern: id),
|
PushCondition(kind: 'event_match', key: 'room_id', pattern: id),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -84,22 +84,40 @@ class Timeline {
|
||||||
(room.prev_batch != null && events.last.type != EventTypes.RoomCreate);
|
(room.prev_batch != null && events.last.type != EventTypes.RoomCreate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Request more previous events from the server. [historyCount] defines how many events should
|
||||||
|
/// be received maximum. [filter] allows you to specify a [StateFilter] object to filter the
|
||||||
|
/// events, which can include various criteria such as event types (e.g., [EventTypes.Message])
|
||||||
|
/// and other state-related filters. The [StateFilter] object will have [lazyLoadMembers] set to
|
||||||
|
/// true by default, but this can be overridden.
|
||||||
|
/// This method does not return a value.
|
||||||
Future<void> requestHistory({
|
Future<void> requestHistory({
|
||||||
int historyCount = Room.defaultHistoryCount,
|
int historyCount = Room.defaultHistoryCount,
|
||||||
|
StateFilter? filter,
|
||||||
}) async {
|
}) async {
|
||||||
if (isRequestingHistory) {
|
if (isRequestingHistory) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isRequestingHistory = true;
|
isRequestingHistory = true;
|
||||||
await _requestEvents(direction: Direction.b, historyCount: historyCount);
|
await _requestEvents(
|
||||||
|
direction: Direction.b,
|
||||||
|
historyCount: historyCount,
|
||||||
|
filter: filter,
|
||||||
|
);
|
||||||
isRequestingHistory = false;
|
isRequestingHistory = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get canRequestFuture => !allowNewEvent;
|
bool get canRequestFuture => !allowNewEvent;
|
||||||
|
|
||||||
|
/// Request more future events from the server. [historyCount] defines how many events should
|
||||||
|
/// be received maximum. [filter] allows you to specify a [StateFilter] object to filter the
|
||||||
|
/// events, which can include various criteria such as event types (e.g., [EventTypes.Message])
|
||||||
|
/// and other state-related filters. The [StateFilter] object will have [lazyLoadMembers] set to
|
||||||
|
/// true by default, but this can be overridden.
|
||||||
|
/// This method does not return a value.
|
||||||
Future<void> requestFuture({
|
Future<void> requestFuture({
|
||||||
int historyCount = Room.defaultHistoryCount,
|
int historyCount = Room.defaultHistoryCount,
|
||||||
|
StateFilter? filter,
|
||||||
}) async {
|
}) async {
|
||||||
if (allowNewEvent) {
|
if (allowNewEvent) {
|
||||||
return; // we shouldn't force to add new events if they will autatically be added
|
return; // we shouldn't force to add new events if they will autatically be added
|
||||||
|
|
@ -107,13 +125,18 @@ class Timeline {
|
||||||
|
|
||||||
if (isRequestingFuture) return;
|
if (isRequestingFuture) return;
|
||||||
isRequestingFuture = true;
|
isRequestingFuture = true;
|
||||||
await _requestEvents(direction: Direction.f, historyCount: historyCount);
|
await _requestEvents(
|
||||||
|
direction: Direction.f,
|
||||||
|
historyCount: historyCount,
|
||||||
|
filter: filter,
|
||||||
|
);
|
||||||
isRequestingFuture = false;
|
isRequestingFuture = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _requestEvents({
|
Future<void> _requestEvents({
|
||||||
int historyCount = Room.defaultHistoryCount,
|
int historyCount = Room.defaultHistoryCount,
|
||||||
required Direction direction,
|
required Direction direction,
|
||||||
|
StateFilter? filter,
|
||||||
}) async {
|
}) async {
|
||||||
onUpdate?.call();
|
onUpdate?.call();
|
||||||
|
|
||||||
|
|
@ -161,6 +184,7 @@ class Timeline {
|
||||||
await getRoomEvents(
|
await getRoomEvents(
|
||||||
historyCount: historyCount,
|
historyCount: historyCount,
|
||||||
direction: direction,
|
direction: direction,
|
||||||
|
filter: filter,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (room.prev_batch == null) {
|
if (room.prev_batch == null) {
|
||||||
|
|
@ -172,6 +196,7 @@ class Timeline {
|
||||||
onHistoryReceived: () {
|
onHistoryReceived: () {
|
||||||
_collectHistoryUpdates = true;
|
_collectHistoryUpdates = true;
|
||||||
},
|
},
|
||||||
|
filter: filter,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -185,18 +210,26 @@ class Timeline {
|
||||||
|
|
||||||
/// Request more previous events from the server. [historyCount] defines how much events should
|
/// Request more previous events from the server. [historyCount] defines how much events should
|
||||||
/// be received maximum. When the request is answered, [onHistoryReceived] will be triggered **before**
|
/// be received maximum. When the request is answered, [onHistoryReceived] will be triggered **before**
|
||||||
/// the historical events will be published in the onEvent stream.
|
/// the historical events will be published in the onEvent stream. [filter] allows you to specify a
|
||||||
|
/// [StateFilter] object to filter the events, which can include various criteria such as
|
||||||
|
/// event types (e.g., [EventTypes.Message]) and other state-related filters.
|
||||||
|
/// The [StateFilter] object will have [lazyLoadMembers] set to true by default, but this can be overridden.
|
||||||
/// Returns the actual count of received timeline events.
|
/// Returns the actual count of received timeline events.
|
||||||
Future<int> getRoomEvents({
|
Future<int> getRoomEvents({
|
||||||
int historyCount = Room.defaultHistoryCount,
|
int historyCount = Room.defaultHistoryCount,
|
||||||
direction = Direction.b,
|
direction = Direction.b,
|
||||||
|
StateFilter? filter,
|
||||||
}) async {
|
}) async {
|
||||||
|
// Ensure stateFilter is not null and set lazyLoadMembers to true if not already set
|
||||||
|
filter ??= StateFilter(lazyLoadMembers: true);
|
||||||
|
filter.lazyLoadMembers ??= true;
|
||||||
|
|
||||||
final resp = await room.client.getRoomEvents(
|
final resp = await room.client.getRoomEvents(
|
||||||
room.id,
|
room.id,
|
||||||
direction,
|
direction,
|
||||||
from: direction == Direction.b ? chunk.prevBatch : chunk.nextBatch,
|
from: direction == Direction.b ? chunk.prevBatch : chunk.nextBatch,
|
||||||
limit: historyCount,
|
limit: historyCount,
|
||||||
filter: jsonEncode(StateFilter(lazyLoadMembers: true).toJson()),
|
filter: jsonEncode(filter.toJson()),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (resp.end == null) {
|
if (resp.end == null) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue