[READ ONLY MIRROR] Open Source TikTok alternative built on AT Protocol github.com/sprksocial/client
flutter atproto video dart
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix handle on profile

+21 -16
+21 -16
lib/services/profile_service.dart
··· 1 + import 'dart:convert'; 2 + 1 3 import 'package:flutter/foundation.dart'; 2 4 import 'package:atproto/core.dart'; 5 + import 'package:http/http.dart' as http; 3 6 import 'auth_service.dart'; 4 7 5 8 class ProfileService extends ChangeNotifier { ··· 42 45 43 46 // Try to resolve the handle using the DID 44 47 try { 45 - final handleResponse = await atProto.identity.resolveHandle( 46 - handle: did, 48 + final didDocResponse = await http.get( 49 + Uri.parse('https://plc.directory/$did/data'), 47 50 ); 48 - if (handleResponse.data != null && handleResponse.data.did == did) { 49 - profileData['handle'] = did; 51 + 52 + if (didDocResponse.statusCode != 200) { 53 + throw Exception( 54 + 'Failed to fetch DID document: ${didDocResponse.statusCode}', 55 + ); 50 56 } 57 + 58 + final didDoc = json.decode(didDocResponse.body); 59 + 60 + final handle = didDoc['alsoKnownAs'].first.replaceFirst('at://', ''); 61 + profileData['handle'] = handle; 51 62 } catch (e) { 52 63 // If handle lookup fails, use DID as fallback 53 64 profileData['handle'] = did; ··· 61 72 final recordData = response.data.toJson(); 62 73 63 74 if (recordData.containsKey('value')) { 64 - final value = recordData['value']; 65 - if (value is Map<String, dynamic>) { 66 - profileData['displayName'] = value['displayName'] ?? ''; 67 - profileData['description'] = value['description'] ?? ''; 75 + final value = recordData['value'] as Map<String, dynamic>; 76 + profileData['displayName'] = value['displayName'] ?? profileData['handle']; 77 + profileData['description'] = value['description'] ?? ''; 68 78 69 - if (value['avatar'] != null && 70 - value['avatar']['ref'] != null && 71 - value['avatar']['ref']['\$link'] != null) { 72 - final avatarLink = value['avatar']['ref']['\$link']; 73 - profileData['avatar'] = 74 - 'https://cdn.bsky.app/img/feed_fullsize/plain/$did/$avatarLink@jpeg'; 75 - } 79 + final avatarRef = value['avatar']?['ref']?['\$link']; 80 + if (avatarRef != null) { 81 + profileData['avatar'] = 'https://cdn.bsky.app/img/feed_fullsize/plain/$did/$avatarRef@jpeg'; 76 82 } 77 83 } 78 - 79 84 _profile = profileData; 80 85 _isLoading = false; 81 86 notifyListeners();