Skip to content

Commit

Permalink
Updated to new register api response. Updater loader messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
i5hi committed Dec 31, 2022
1 parent 89374b6 commit fe8acda
Show file tree
Hide file tree
Showing 40 changed files with 354 additions and 201 deletions.
Binary file added assets/3270-Medium.otf
Binary file not shown.
Binary file added assets/3270-Narrow.otf
Binary file not shown.
Binary file added assets/Aldrich/Aldrich-Regular.ttf
Binary file not shown.
Binary file added assets/Hurmit-Bold.otf
Binary file not shown.
Binary file added assets/Hurmit-Light.otf
Binary file not shown.
Binary file added assets/Hurmit-Medium.otf
Binary file not shown.
Binary file added assets/SpaceMono.ttf
Binary file not shown.
9 changes: 1 addition & 8 deletions lib/api/interface/libcp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,13 @@ abstract class ICypherpost {
required String inviteCode,
});

R<InvitationDetail> userInviteDetail({
required String hostname,
required int socks5,
required String socialRoot,
required String inviteCode,
});

R<List<MemberIdentity>> getMembers({
required String hostname,
required int socks5,
required String socialRoot,
});

R<ServerStatus> joinServer({
R<InvitationDetail> joinServer({
required String hostname,
required int socks5,
required String socialRoot,
Expand Down
23 changes: 2 additions & 21 deletions lib/api/libcp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,6 @@ class LibCypherpost implements ICypherpost {
return R(result: Invitation.fromJson(resp));
}

@override
R<InvitationDetail> userInviteDetail({
required String hostname,
required int socks5,
required String socialRoot,
required String inviteCode,
}) {
final resp = _libcp.userInviteDetail(
hostname: hostname,
socks5: socks5,
socialRoot: socialRoot,
inviteCode: inviteCode,
);
if (resp.contains('error')) {
return R(error: SMError.fromJson(resp).error);
} else
return R(result: InvitationDetail.fromJson(resp));
}

@override
R<List<MemberIdentity>> getMembers({
required String hostname,
Expand Down Expand Up @@ -149,7 +130,7 @@ class LibCypherpost implements ICypherpost {
}

@override
R<ServerStatus> joinServer({
R<InvitationDetail> joinServer({
required String hostname,
required int socks5,
required String socialRoot,
Expand All @@ -167,7 +148,7 @@ class LibCypherpost implements ICypherpost {
if (resp.contains('error')) {
return R(error: SMError.fromJson(resp).error);
} else
return R(result: ServerStatus.fromJson(resp));
return R(result: InvitationDetail.fromJson(resp));
}

@override
Expand Down
80 changes: 46 additions & 34 deletions lib/cubit/networks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import 'package:sats/api/libcp.dart';
import 'package:sats/cubit/logger.dart';
import 'package:sats/cubit/social-root.dart';
import 'package:sats/cubit/tor.dart';
import 'package:sats/model/master.dart';
import 'package:sats/model/network-server-identity.dart';
import 'package:sats/model/result.dart';
import 'package:sats/pkg/interface/clipboard.dart';
import 'package:sats/pkg/interface/storage.dart';
import 'package:sats/pkg/storage.dart';
import 'package:sats/api/interface/libcp.dart';

part 'networks.freezed.dart';

Expand All @@ -28,7 +26,8 @@ class NetworksState with _$NetworksState {
@Default('') String error,
String? name,
String? kind,
String? pubkey,
String? serverPubkey,
@Default('') String loading,
@Default(false) bool isLoading,
@Default(false) bool joined,
}) = _NetworksState;
Expand Down Expand Up @@ -56,11 +55,12 @@ class NetworksCubit extends Cubit<NetworksState> {
final storedNetworks =
_storage.getAll<NetworkServerIdentity>(StoreKeys.Networks.name);
if (storedNetworks.hasError) return;
await Future.delayed(const Duration(milliseconds: 500));
await Future.delayed(const Duration(milliseconds: 300));
final networks = storedNetworks.result!;
emit(
state.copyWith(
networks: networks,
loading: '',
),
);
} catch (e, s) {
Expand Down Expand Up @@ -102,7 +102,7 @@ class NetworksCubit extends Cubit<NetworksState> {
emit(
state.copyWith(
error: '',
isLoading: true,
loading: 'ping',
),
);
final socks5 = _torCubit.state.socks5Port;
Expand All @@ -117,17 +117,17 @@ class NetworksCubit extends Cubit<NetworksState> {
emit(
state.copyWith(
error: 'Could not find host!',
isLoading: false,
loading: '',
),
);
} else {
emit(
state.copyWith(
name: serverId.result!.name,
kind: serverId.result!.kind,
pubkey: serverId.result!.pubkey,
serverPubkey: serverId.result!.pubkey,
error: '',
isLoading: false,
loading: '',
),
);
}
Expand Down Expand Up @@ -164,7 +164,7 @@ class NetworksCubit extends Cubit<NetworksState> {
try {
emit(
state.copyWith(
isLoading: true,
loading: 'ping',
),
);

Expand All @@ -173,7 +173,7 @@ class NetworksCubit extends Cubit<NetworksState> {
emit(
state.copyWith(
error: 'Username must be 12 Alphanumeric Characters',
isLoading: false,
loading: '',
),
);
return;
Expand All @@ -182,7 +182,7 @@ class NetworksCubit extends Cubit<NetworksState> {
emit(
state.copyWith(
error: 'Invalid Invite Code Length.',
isLoading: false,
loading: '',
),
);
return;
Expand All @@ -203,44 +203,57 @@ class NetworksCubit extends Cubit<NetworksState> {
emit(
state.copyWith(
error: 'Could not find host!',
isLoading: false,
loading: '',
),
);
return;
}
}

final status = await compute(joinHostServer, {
emit(
state.copyWith(
loading: 'joining',
),
);

final inviteDetail = await compute(joinHostServer, {
'hostname': 'https://' + state.hostname!,
'socks5': socks5.toString(),
'socialRoot': socialRoot,
'username': state.username,
'inviteCode': state.inviteCode,
});

if (status.hasError) {
if (inviteDetail.hasError) {
emit(
state.copyWith(
error: serverId.error!,
isLoading: false,
error: inviteDetail.error!,
loading: '',
),
);
return;
} else {
final networkServerId = NetworkServerIdentity(
hostname: state.hostname!,
name: (state.name == null) ? serverId.result!.name : state.name!,
kind: (state.kind == null) ? serverId.result!.kind : state.kind!,
pubkey:
(state.pubkey == null) ? serverId.result!.pubkey : state.pubkey!,
);
await updateServerIdStorage(networkServerId);
emit(
state.copyWith(
joined: true,
),
);
}

final networkServerId = NetworkServerIdentity(
hostname: state.hostname!,
name: (state.name == null) ? serverId.result!.name : state.name!,
kind: (state.kind == null) ? serverId.result!.kind : state.kind!,
serverPubkey: (state.serverPubkey == null)
? serverId.result!.pubkey
: state.serverPubkey!,
username: state.username,
inviteCode: state.inviteCode,
inviteCount: inviteDetail.result!.count,
);

await updateServerIdStorage(networkServerId);
await load();

emit(
state.copyWith(
joined: true,
),
);
} catch (e, s) {
_logger.logException(e, 'NetworksCubit.join', s);
}
Expand All @@ -256,7 +269,7 @@ class NetworksCubit extends Cubit<NetworksState> {
emit(
state.copyWith(
error: couldNotSaveError,
isLoading: false,
loading: '',
),
);
return;
Expand All @@ -268,7 +281,6 @@ class NetworksCubit extends Cubit<NetworksState> {
id,
newId,
);
await load();
} catch (e, s) {
_logger.logException(e, 'NetworksCubit.updateServerIdStorage', s);
}
Expand All @@ -277,7 +289,7 @@ class NetworksCubit extends Cubit<NetworksState> {
void clear() => emit(
NetworksState(
networks: state.networks,
isLoading: false,
loading: '',
joined: false,
),
);
Expand All @@ -293,7 +305,7 @@ R<ServerIdentity> serverIdentity(dynamic data) {
return resp;
}

R<ServerStatus> joinHostServer(dynamic data) {
R<InvitationDetail> joinHostServer(dynamic data) {
final obj = data as Map<String, String?>;
final resp = LibCypherpost().joinServer(
hostname: obj['hostname']!,
Expand Down
Loading

0 comments on commit fe8acda

Please sign in to comment.