Skip to content

Commit

Permalink
core: allow registration as a bot
Browse files Browse the repository at this point in the history
  • Loading branch information
jjanku committed May 3, 2024
1 parent b31822d commit db63826
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/ui/device_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DevicePage extends StatelessWidget {
pinned: true,
flexibleSpace: FlexibleAvatarAppBar(
avatar: Text(device.name.initials),
title: DeviceName(device.name),
title: DeviceName(device.name, kind: device.kind),
),
),
SliverList.list(
Expand Down
5 changes: 4 additions & 1 deletion meesign_core/example/time_policy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ void main(List<String> args) async {
final challengeRepository =
ChallengeRepository(dispatcher, taskSource, taskDao);

final device = await deviceRepository.register(options['name']);
final device = await deviceRepository.register(
options['name'],
kind: DeviceKind.bot,
);
print('Registered as ${device.name}');

await groupRepository.subscribe(device.id);
Expand Down
5 changes: 3 additions & 2 deletions meesign_core/lib/src/data/device_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ class DeviceRepository {

DeviceRepository(this._dispatcher, this._keyStore, this._deviceDao);

Future<Device> register(String name) async {
Future<Device> register(String name,
{DeviceKind kind = DeviceKind.user}) async {
final key = AuthWrapper.keygen(name);

final resp = await _dispatcher.unauth.register(
rpc.RegistrationRequest()
..name = name
..kind = rpc.DeviceKind.USER
..kind = kind.toNetwork()
..csr = key.csr,
);

Expand Down
5 changes: 5 additions & 0 deletions meesign_core/lib/src/model/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ extension DeviceKindConversion on DeviceKind {
rpc.DeviceKind.BOT => DeviceKind.bot,
_ => throw ArgumentError('Unknown device kind'),
};

rpc.DeviceKind toNetwork() => switch (this) {
DeviceKind.user => rpc.DeviceKind.USER,
DeviceKind.bot => rpc.DeviceKind.BOT,
};
}

@immutable
Expand Down

0 comments on commit db63826

Please sign in to comment.