add room directory support
This commit is contained in:
parent
033c7f9c05
commit
e382499a2a
4 changed files with 868 additions and 245 deletions
|
|
@ -2,6 +2,7 @@ import "package:collection/collection.dart";
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/helpers/extensions/get_link_info.dart";
|
||||
import "package:nexus/helpers/extensions/get_localpart.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
|
||||
part "bot_command_description.freezed.dart";
|
||||
|
|
@ -181,10 +182,6 @@ enum BotPrimitiveType(final String label, final String expected) {
|
|||
@JsonValue("event_id")
|
||||
eventId("event", r"a message link or event ID like $abc");
|
||||
|
||||
static final serverNamePattern = RegExp(
|
||||
r"^(\[[0-9A-Fa-f:.]+\]|[A-Za-z0-9.-]+)(:\d{1,5})?$",
|
||||
);
|
||||
|
||||
Object? parse(String text, {required String roomId}) {
|
||||
final (:identifier, :eventId, :via) =
|
||||
text.linkInfo ??
|
||||
|
|
@ -206,7 +203,7 @@ enum BotPrimitiveType(final String label, final String expected) {
|
|||
identifier,
|
||||
.roomAlias when identifier.startsWith("#") && identifier.contains(":") =>
|
||||
identifier,
|
||||
.serverName when serverNamePattern.hasMatch(text) => text,
|
||||
.serverName when text.isValidServerName => text,
|
||||
.roomId when identifier.startsWith("!") && eventId == null => {
|
||||
"type": "room_id",
|
||||
"id": identifier,
|
||||
|
|
|
|||
28
lib/models/requests/get_room_directory.dart
Normal file
28
lib/models/requests/get_room_directory.dart
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
|
||||
part "get_room_directory.freezed.dart";
|
||||
part "get_room_directory.g.dart";
|
||||
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable(includeIfNull: false, explicitToJson: true)
|
||||
class const GetRoomDirectoryRequest({
|
||||
final String? server,
|
||||
final int limit = 48,
|
||||
final String? since,
|
||||
final PublicRoomsFilter? filter,
|
||||
}) with _$GetRoomDirectoryRequest {
|
||||
Map<String, Object?> toJson() => _$GetRoomDirectoryRequestToJson(this);
|
||||
|
||||
factory GetRoomDirectoryRequest.fromJson(Map<String, Object?> json) =>
|
||||
_$GetRoomDirectoryRequestFromJson(json);
|
||||
}
|
||||
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable(includeIfNull: false)
|
||||
class const PublicRoomsFilter({final String? genericSearchTerm})
|
||||
with _$PublicRoomsFilter {
|
||||
Map<String, Object?> toJson() => _$PublicRoomsFilterToJson(this);
|
||||
|
||||
factory PublicRoomsFilter.fromJson(Map<String, Object?> json) =>
|
||||
_$PublicRoomsFilterFromJson(json);
|
||||
}
|
||||
17
lib/models/room_directory.dart
Normal file
17
lib/models/room_directory.dart
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/room_summary.dart";
|
||||
|
||||
part "room_directory.freezed.dart";
|
||||
part "room_directory.g.dart";
|
||||
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable(createToJson: false)
|
||||
class const RoomDirectory({
|
||||
@JsonKey(name: "chunk") final IList<RoomSummary> rooms = const .empty(),
|
||||
final String? nextBatch,
|
||||
final int? totalRoomCountEstimate,
|
||||
}) with _$RoomDirectory {
|
||||
factory RoomDirectory.fromJson(Map<String, Object?> json) =>
|
||||
_$RoomDirectoryFromJson(json);
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/name_color.dart";
|
||||
|
|
@ -25,6 +26,10 @@ class const Settings({
|
|||
/// When not sending, read receipts are still sent privately, so that the
|
||||
/// user's other devices know what has been read.
|
||||
final ShowAndSend readReceipts = .showAndSend,
|
||||
final IList<String> directoryServers = const IListConst([
|
||||
"matrix.org",
|
||||
"matrixrooms.info",
|
||||
]),
|
||||
}) with _$Settings {
|
||||
Map<String, Object?> toJson() => _$SettingsToJson(this);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue