kopia lustrzana https://gitlab.com/mysocialportal/relatica
				
				
				
			Disable reshare button for own posts.
							rodzic
							
								
									4d7cf7fd98
								
							
						
					
					
						commit
						8bb8bd7cc8
					
				|  | @ -9,7 +9,10 @@ import '../../utils/snackbar_builder.dart'; | |||
| class InteractionsBarControl extends StatefulWidget { | ||||
|   final TimelineEntry entry; | ||||
| 
 | ||||
|   const InteractionsBarControl({super.key, required this.entry}); | ||||
|   final bool isMine; | ||||
| 
 | ||||
|   const InteractionsBarControl( | ||||
|       {super.key, required this.entry, required this.isMine}); | ||||
| 
 | ||||
|   @override | ||||
|   State<InteractionsBarControl> createState() => _InteractionsBarControlState(); | ||||
|  | @ -91,8 +94,11 @@ class _InteractionsBarControlState extends State<InteractionsBarControl> { | |||
|                   : Icon(Icons.thumb_up_outlined)), | ||||
|           if (isPost) | ||||
|             IconButton( | ||||
|                 onPressed: () async => | ||||
|                     isReshared ? await unResharePost() : await resharePost(), | ||||
|                 onPressed: widget.isMine | ||||
|                     ? null | ||||
|                     : () async => isReshared | ||||
|                         ? await unResharePost() | ||||
|                         : await resharePost(), | ||||
|                 icon: | ||||
|                     Icon(isReshared ? Icons.repeat_on_outlined : Icons.repeat)) | ||||
|         ]), | ||||
|  |  | |||
|  | @ -69,7 +69,10 @@ class _StatusControlState extends State<StatusControl> { | |||
|           const VerticalPadding( | ||||
|             height: 5, | ||||
|           ), | ||||
|           InteractionsBarControl(entry: entry), | ||||
|           InteractionsBarControl( | ||||
|             entry: entry, | ||||
|             isMine: item.isMine, | ||||
|           ), | ||||
|           const VerticalPadding( | ||||
|             height: 5, | ||||
|           ), | ||||
|  |  | |||
|  | @ -5,10 +5,12 @@ import 'package:logging/logging.dart'; | |||
| import 'package:result_monad/result_monad.dart'; | ||||
| 
 | ||||
| import 'models/TimelineIdentifiers.dart'; | ||||
| import 'models/connection.dart'; | ||||
| import 'models/credentials.dart'; | ||||
| import 'models/exec_error.dart'; | ||||
| import 'models/timeline_entry.dart'; | ||||
| import 'models/user_notification.dart'; | ||||
| import 'serializers/friendica/connection_friendica_extensions.dart'; | ||||
| import 'serializers/friendica/notification_friendica_extension.dart'; | ||||
| import 'serializers/mastodon/timeline_entry_mastodon_extensions.dart'; | ||||
| 
 | ||||
|  | @ -219,11 +221,12 @@ class FriendicaClient { | |||
|     }); | ||||
|   } | ||||
| 
 | ||||
|   FutureResult<String, ExecError> getMyProfile() async { | ||||
|   FutureResult<Connection, ExecError> getMyProfile() async { | ||||
|     _logger.finest(() => 'Getting logged in user profile'); | ||||
|     final request = Uri.parse('https://$serverName/api/friendica/profile/show'); | ||||
|     return (await _getApiRequest(request)) | ||||
|         .mapValue((value) => value.toString()); | ||||
|     return (await _getApiRequest(request)).mapValue((json) => | ||||
|         ConnectionFriendicaExtensions.fromJson(json['friendica_owner']) | ||||
|             .copy(status: ConnectionStatus.you, network: 'friendica')); | ||||
|   } | ||||
| 
 | ||||
|   FutureResult<String, ExecError> _getUrl(Uri url) async { | ||||
|  |  | |||
|  | @ -21,6 +21,22 @@ class Connection { | |||
|       : profileUrl = profileUrl ?? Uri(), | ||||
|         avatarUrl = avatarUrl ?? Uri(); | ||||
| 
 | ||||
|   Connection copy( | ||||
|           {ConnectionStatus? status, | ||||
|           String? name, | ||||
|           String? id, | ||||
|           Uri? profileUrl, | ||||
|           String? network, | ||||
|           Uri? avatarUrl}) => | ||||
|       Connection( | ||||
|         status: status ?? this.status, | ||||
|         name: name ?? this.name, | ||||
|         id: id ?? this.id, | ||||
|         profileUrl: profileUrl ?? this.profileUrl, | ||||
|         network: network ?? this.network, | ||||
|         avatarUrl: avatarUrl ?? this.avatarUrl, | ||||
|       ); | ||||
| 
 | ||||
|   @override | ||||
|   String toString() { | ||||
|     return 'Connection{status: $status, name: $name, id: $id, profileUrl: $profileUrl, network: $network, avatar: $avatarUrl}'; | ||||
|  | @ -31,6 +47,7 @@ enum ConnectionStatus { | |||
|   youFollowThem, | ||||
|   theyFollowYou, | ||||
|   mutual, | ||||
|   you, | ||||
|   none, | ||||
| } | ||||
| 
 | ||||
|  | @ -45,6 +62,8 @@ extension FriendStatusWriter on ConnectionStatus { | |||
|         return "Follow each other"; | ||||
|       case ConnectionStatus.none: | ||||
|         return "Not connected"; | ||||
|       case ConnectionStatus.you: | ||||
|         return "You"; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -2,7 +2,7 @@ import '../../models/connection.dart'; | |||
| 
 | ||||
| extension ConnectionFriendicaExtensions on Connection { | ||||
|   static Connection fromJson(Map<String, dynamic> json) { | ||||
|     final status = (json['following'] ?? '') == 'true' | ||||
|     final status = json['following'] == 'true' | ||||
|         ? ConnectionStatus.youFollowThem | ||||
|         : ConnectionStatus.none; | ||||
|     final name = json['name'] ?? ''; | ||||
|  |  | |||
|  | @ -11,6 +11,8 @@ import 'timeline_manager.dart'; | |||
| 
 | ||||
| class AuthService extends ChangeNotifier { | ||||
|   FriendicaClient? _friendicaClient; | ||||
|   String _currentId = ''; | ||||
|   String _currentHandle = ''; | ||||
|   bool _loggedIn = false; | ||||
| 
 | ||||
|   Result<FriendicaClient, ExecError> get currentClient { | ||||
|  | @ -26,6 +28,10 @@ class AuthService extends ChangeNotifier { | |||
| 
 | ||||
|   bool get loggedIn => _loggedIn && _friendicaClient != null; | ||||
| 
 | ||||
|   String get currentId => _currentId; | ||||
| 
 | ||||
|   String get currentHandle => _currentHandle; | ||||
| 
 | ||||
|   Future<bool> getStoredLoginState() async { | ||||
|     final prefs = await SharedPreferences.getInstance(); | ||||
|     return prefs.getBool('logged-in') ?? false; | ||||
|  | @ -42,6 +48,8 @@ class AuthService extends ChangeNotifier { | |||
|     getIt<SecretsService>().storeCredentials(client.credentials); | ||||
|     await _setLoginState(true); | ||||
|     _friendicaClient = client; | ||||
|     _currentId = result.value.id; | ||||
|     _currentHandle = client.credentials.handle; | ||||
|     notifyListeners(); | ||||
|     return Result.ok(client); | ||||
|   } | ||||
|  | @ -51,6 +59,8 @@ class AuthService extends ChangeNotifier { | |||
|     await _setLoginState(false); | ||||
|     getIt<TimelineManager>().clear(); | ||||
|     _friendicaClient = null; | ||||
|     _currentId = ''; | ||||
|     _currentHandle = ''; | ||||
|     notifyListeners(); | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -44,7 +44,7 @@ class EntryManagerService extends ChangeNotifier { | |||
| 
 | ||||
|     return result.mapValue((post) { | ||||
|       _logger.finest('${post.id} post updated after reshare'); | ||||
|       return _nodeToTreeItem(_postNodes[post.id]!); | ||||
|       return _nodeToTreeItem(_postNodes[post.id]!, auth.currentId); | ||||
|     }).mapError( | ||||
|       (error) { | ||||
|         _logger.finest('Error creating post: $error'); | ||||
|  | @ -69,7 +69,6 @@ class EntryManagerService extends ChangeNotifier { | |||
|     final client = clientResult.value; | ||||
|     final itemsResult = | ||||
|         await client.getTimeline(type: type, maxId: maxId, sinceId: sinceId); | ||||
|     final myHandle = client.credentials.username; | ||||
|     if (itemsResult.isFailure) { | ||||
|       _logger.severe('Error getting timeline: ${itemsResult.error}'); | ||||
|       return itemsResult.errorCast(); | ||||
|  | @ -77,7 +76,7 @@ class EntryManagerService extends ChangeNotifier { | |||
| 
 | ||||
|     itemsResult.value.sort((t1, t2) => t1.id.compareTo(t2.id)); | ||||
|     final updatedPosts = | ||||
|         await processNewItems(itemsResult.value, myHandle, client); | ||||
|         await processNewItems(itemsResult.value, auth.currentId, client); | ||||
|     _logger.finest(() { | ||||
|       final postCount = _entries.values.where((e) => e.parentId.isEmpty).length; | ||||
|       final commentCount = _entries.length - postCount; | ||||
|  | @ -92,7 +91,7 @@ class EntryManagerService extends ChangeNotifier { | |||
| 
 | ||||
|   Future<List<EntryTreeItem>> processNewItems( | ||||
|     List<TimelineEntry> items, | ||||
|     String myHandle, | ||||
|     String currentId, | ||||
|     FriendicaClient? client, | ||||
|   ) async { | ||||
|     final allSeenItems = [...items]; | ||||
|  | @ -150,8 +149,9 @@ class EntryManagerService extends ChangeNotifier { | |||
|       } | ||||
|     } | ||||
| 
 | ||||
|     final updatedPosts = | ||||
|         postNodesToReturn.map((node) => _nodeToTreeItem(node)).toList(); | ||||
|     final updatedPosts = postNodesToReturn | ||||
|         .map((node) => _nodeToTreeItem(node, currentId)) | ||||
|         .toList(); | ||||
| 
 | ||||
|     _logger.finest( | ||||
|         'Completed processing new items ${client == null ? 'sub level' : 'top level'}'); | ||||
|  | @ -181,7 +181,7 @@ class EntryManagerService extends ChangeNotifier { | |||
| 
 | ||||
|     return result.mapValue((_) { | ||||
|       _logger.finest('$id post updated'); | ||||
|       return _nodeToTreeItem(_postNodes[id]!); | ||||
|       return _nodeToTreeItem(_postNodes[id]!, auth.currentId); | ||||
|     }).mapError( | ||||
|       (error) { | ||||
|         _logger.finest('$id error updating: $error'); | ||||
|  | @ -210,7 +210,7 @@ class EntryManagerService extends ChangeNotifier { | |||
| 
 | ||||
|     return result.mapValue((_) { | ||||
|       _logger.finest('$id post updated after reshare'); | ||||
|       return _nodeToTreeItem(_postNodes[id]!); | ||||
|       return _nodeToTreeItem(_postNodes[id]!, auth.currentId); | ||||
|     }).mapError( | ||||
|       (error) { | ||||
|         _logger.finest('$id error updating: $error'); | ||||
|  | @ -239,7 +239,7 @@ class EntryManagerService extends ChangeNotifier { | |||
| 
 | ||||
|     return result.mapValue((_) { | ||||
|       _logger.finest('$id post updated after unreshare'); | ||||
|       return _nodeToTreeItem(_postNodes[id]!); | ||||
|       return _nodeToTreeItem(_postNodes[id]!, auth.currentId); | ||||
|     }).mapError( | ||||
|       (error) { | ||||
|         _logger.finest('$id error updating: $error'); | ||||
|  | @ -272,15 +272,22 @@ class EntryManagerService extends ChangeNotifier { | |||
|         : _postNodes[update.parentId]!.getChildById(update.id)!; | ||||
| 
 | ||||
|     notifyListeners(); | ||||
|     return Result.ok(_nodeToTreeItem(node)); | ||||
|     return Result.ok(_nodeToTreeItem(node, auth.currentId)); | ||||
|   } | ||||
| 
 | ||||
|   EntryTreeItem _nodeToTreeItem(_Node node) { | ||||
|   EntryTreeItem _nodeToTreeItem(_Node node, String currentId) { | ||||
|     final childenEntries = <String, EntryTreeItem>{}; | ||||
|     for (final c in node.children) { | ||||
|       childenEntries[c.id] = _nodeToTreeItem(c); | ||||
|       childenEntries[c.id] = _nodeToTreeItem(c, currentId); | ||||
|     } | ||||
|     return EntryTreeItem(_entries[node.id]!, initialChildren: childenEntries); | ||||
|     final entry = _entries[node.id]!; | ||||
|     final isMine = entry.authorId == currentId; | ||||
|     print('Author: ${entry.authorId}, Mine: $currentId => IsMine? $isMine'); | ||||
|     return EntryTreeItem( | ||||
|       _entries[node.id]!, | ||||
|       isMine: isMine, | ||||
|       initialChildren: childenEntries, | ||||
|     ); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Hank Grabowski
						Hank Grabowski