kopia lustrzana https://gitlab.com/mysocialportal/relatica
Add status visibility dialog box
rodzic
1d65ba2604
commit
8b99f73238
|
@ -5,7 +5,7 @@ import 'package:logging/logging.dart';
|
|||
import '../../globals.dart';
|
||||
import '../../models/connection.dart';
|
||||
import '../../models/timeline_entry.dart';
|
||||
import '../../models/visibility.dart';
|
||||
import '../../models/visibility.dart' as v;
|
||||
import '../../routes.dart';
|
||||
import '../../services/auth_service.dart';
|
||||
import '../../services/connections_manager.dart';
|
||||
|
@ -39,23 +39,23 @@ class StatusHeaderControl extends StatelessWidget {
|
|||
.getForProfile(activeProfile)
|
||||
.transform((s) => s.getForPost(entry.id)?.resharers.firstOrNull)
|
||||
.getValueOrElse(() => null);
|
||||
|
||||
getIt<ActiveProfileSelector<ConnectionsManager>>()
|
||||
final manager = getIt<ActiveProfileSelector<ConnectionsManager>>()
|
||||
.getForProfile(activeProfile)
|
||||
.match(
|
||||
onSuccess: (manager) {
|
||||
author =
|
||||
manager.getById(entry.authorId).getValueOrElse(() => Connection());
|
||||
reshareAuthor = reshareId == null
|
||||
? Connection()
|
||||
: manager.getById(reshareId).getValueOrElse(() => Connection());
|
||||
},
|
||||
onError: (error) {
|
||||
_logger.severe('Error getting connections manageR: $error');
|
||||
author = Connection();
|
||||
reshareAuthor = Connection();
|
||||
},
|
||||
);
|
||||
.fold(
|
||||
onSuccess: (m) => m,
|
||||
onError: (error) {
|
||||
_logger.severe('Error getting connection manager: $error');
|
||||
return null;
|
||||
});
|
||||
|
||||
author = manager!.getById(entry.authorId).getValueOrElse(
|
||||
() => Connection(),
|
||||
);
|
||||
reshareAuthor = reshareId == null
|
||||
? Connection()
|
||||
: manager.getById(reshareId).getValueOrElse(
|
||||
() => Connection(),
|
||||
);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
@ -122,13 +122,17 @@ class StatusHeaderControl extends StatelessWidget {
|
|||
ElapsedDateUtils.epochSecondsToString(entry.backdatedTimestamp),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
const HorizontalPadding(),
|
||||
Icon(
|
||||
entry.visibility.type == VisibilityType.public
|
||||
? Icons.public
|
||||
: Icons.lock,
|
||||
color: Theme.of(context).hintColor,
|
||||
size: Theme.of(context).textTheme.bodySmall?.fontSize,
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
await _showVisibilityDialog(context, manager, entry.visibility);
|
||||
},
|
||||
icon: Icon(
|
||||
entry.visibility.type == v.VisibilityType.public
|
||||
? Icons.public
|
||||
: Icons.lock,
|
||||
color: Theme.of(context).hintColor,
|
||||
size: Theme.of(context).textTheme.bodySmall?.fontSize,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -136,3 +140,141 @@ class StatusHeaderControl extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool?> _showVisibilityDialog(
|
||||
BuildContext context,
|
||||
ConnectionsManager cm,
|
||||
v.Visibility visibility,
|
||||
) async {
|
||||
final circlesMap = {for (var item in cm.getMyCircles()) item.id: item};
|
||||
|
||||
final allowedCircles = visibility.allowedCircleIds.map((c) {
|
||||
if (c == '~') {
|
||||
return 'Followers';
|
||||
}
|
||||
|
||||
return circlesMap[c]?.name ?? 'Circle #$c';
|
||||
});
|
||||
|
||||
final excludedCircles = visibility.excludedCircleIds.map((c) {
|
||||
if (c == '~') {
|
||||
return 'Followers';
|
||||
}
|
||||
|
||||
return circlesMap[c]?.name ?? 'Circle #$c';
|
||||
});
|
||||
|
||||
final allowedUsers = visibility.allowedUserIds.map(
|
||||
(u) => cm.getById(u).fold(
|
||||
onSuccess: (connection) => connection.handle,
|
||||
onError: (_) => 'User $u',
|
||||
),
|
||||
);
|
||||
|
||||
final excludedUsers = visibility.excludedUserIds.map(
|
||||
(u) => cm.getById(u).fold(
|
||||
onSuccess: (connection) => connection.handle,
|
||||
onError: (_) => 'User $u',
|
||||
),
|
||||
);
|
||||
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
content: SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.8,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Visibility Details',
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyLarge
|
||||
?.copyWith(decoration: TextDecoration.underline),
|
||||
),
|
||||
if (visibility.type == v.VisibilityType.public) ...[
|
||||
const Text('Public')
|
||||
],
|
||||
if (visibility.type != v.VisibilityType.public) ...[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Allowed Users: ',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
allowedUsers.isEmpty
|
||||
? 'Empty'
|
||||
: allowedUsers.join(', '),
|
||||
softWrap: true,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Allowed Circles: ',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text(
|
||||
allowedCircles.isEmpty
|
||||
? 'Empty'
|
||||
: allowedCircles.join(','),
|
||||
softWrap: true,
|
||||
)
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Excluded Users: ',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text(
|
||||
excludedUsers.isEmpty ? 'Empty' : excludedUsers.join(','),
|
||||
softWrap: true,
|
||||
)
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Excluded Circles: ',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text(
|
||||
excludedCircles.isEmpty
|
||||
? 'Empty'
|
||||
: excludedCircles.join(','),
|
||||
softWrap: true,
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
ElevatedButton(
|
||||
child: const Text('Dismiss'),
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true); // showDialog() returns true
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue