diff --git a/app/lib/backend/http/api/memories.dart b/app/lib/backend/http/api/memories.dart index 08872dbe4..df60c27f2 100644 --- a/app/lib/backend/http/api/memories.dart +++ b/app/lib/backend/http/api/memories.dart @@ -2,12 +2,12 @@ import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:friend_private/backend/schema/geolocation.dart'; -import 'package:friend_private/backend/schema/structured.dart'; -import 'package:friend_private/backend/schema/transcript_segment.dart'; import 'package:friend_private/backend/http/shared.dart'; import 'package:friend_private/backend/preferences.dart'; +import 'package:friend_private/backend/schema/geolocation.dart'; import 'package:friend_private/backend/schema/memory.dart'; +import 'package:friend_private/backend/schema/structured.dart'; +import 'package:friend_private/backend/schema/transcript_segment.dart'; import 'package:friend_private/env/env.dart'; import 'package:http/http.dart' as http; import 'package:instabug_flutter/instabug_flutter.dart'; @@ -198,3 +198,15 @@ Future assignMemoryTranscriptSegment( debugPrint('assignMemoryTranscriptSegment: ${response.body}'); return response.statusCode == 200; } + +Future setMemoryVisibility(String memoryId, {String visibility = 'shared'}) async { + var response = await makeApiCall( + url: '${Env.apiBaseUrl}v1/memories/$memoryId/visibility?value=$visibility&visibility=$visibility', + headers: {}, + method: 'PATCH', + body: '', + ); + if (response == null) return false; + debugPrint('setMemoryVisibility: ${response.body}'); + return response.statusCode == 200; +} diff --git a/app/lib/pages/memory_detail/share.dart b/app/lib/pages/memory_detail/share.dart index 77edcdc4b..cd045d1ee 100644 --- a/app/lib/pages/memory_detail/share.dart +++ b/app/lib/pages/memory_detail/share.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:friend_private/backend/http/api/memories.dart'; import 'package:friend_private/backend/schema/memory.dart'; import 'package:path_provider/path_provider.dart'; import 'package:pdf/widgets.dart' as pw; @@ -174,6 +175,35 @@ void showShareBottomSheet( ), ), const SizedBox(height: 10), + Card( + shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8))), + child: Column( + children: [ + _buildListTile( + context, + title: 'Copy URL', + icon: Icons.link, + onTap: () async { + // TODO: include loading indicator + bool shared = await setMemoryVisibility(memory.id); + if (!shared) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Memory URL could not be shared.')), + ); + return; + } + Clipboard.setData(ClipboardData(text: 'https://omi.me/memories/${memory.id}')); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('URL Copied to Clipboard')), + ); + Navigator.pop(ctx); + HapticFeedback.lightImpact(); + }, + ), + ], + ), + ), + const SizedBox(height: 8), Card( shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8))), child: Column( diff --git a/app/lib/providers/device_provider.dart b/app/lib/providers/device_provider.dart index a9ab0ad55..b8b9c1e92 100644 --- a/app/lib/providers/device_provider.dart +++ b/app/lib/providers/device_provider.dart @@ -126,14 +126,14 @@ class DeviceProvider extends ChangeNotifier with WebSocketMixin { if (timer != null) return; timer = Timer.periodic(Duration(seconds: connectionCheckSeconds), (t) async { if (timer == null) return; - print(printer); - print('seconds: $connectionCheckSeconds'); - print('triggered timer at ${DateTime.now()}'); + // print(printer); + // print('seconds: $connectionCheckSeconds'); + // print('triggered timer at ${DateTime.now()}'); if (SharedPreferencesUtil().btDeviceStruct.id.isEmpty) { return; } - print("isConnected: $isConnected, isConnecting: $isConnecting, connectedDevice: $connectedDevice"); + // print("isConnected: $isConnected, isConnecting: $isConnecting, connectedDevice: $connectedDevice"); if ((!isConnected && connectedDevice == null)) { if (isConnecting) { return; diff --git a/backend/database/memories.py b/backend/database/memories.py index f2ff95978..755e92228 100644 --- a/backend/database/memories.py +++ b/backend/database/memories.py @@ -128,7 +128,7 @@ async def _get_public_memory(db: AsyncClient, uid: str, memory_id: str): memory_doc = await memory_ref.get() if memory_doc.exists: memory_data = memory_doc.to_dict() - if memory_data.get('visibility') in ['public']: + if memory_data.get('visibility') in ['public'] and not memory_data.get('deleted'): return memory_data return None diff --git a/backend/routers/memories.py b/backend/routers/memories.py index 529828430..b344bf461 100644 --- a/backend/routers/memories.py +++ b/backend/routers/memories.py @@ -169,12 +169,12 @@ def set_assignee_memory_segment( @router.patch('/v1/memories/{memory_id}/visibility', tags=['memories']) def set_memory_visibility( - memory_id: str, visibility: MemoryVisibility, uid: str = Depends(auth.get_current_user_uid) + memory_id: str, value: MemoryVisibility, uid: str = Depends(auth.get_current_user_uid) ): - print('update_memory_visibility', memory_id, visibility, uid) + print('update_memory_visibility', memory_id, value, uid) _get_memory_by_id(uid, memory_id) - memories_db.set_memory_visibility(uid, memory_id, visibility) - if visibility == MemoryVisibility.private: + memories_db.set_memory_visibility(uid, memory_id, value) + if value == MemoryVisibility.private: redis_db.remove_memory_to_uid(memory_id) redis_db.remove_public_memory(memory_id) else: @@ -190,6 +190,8 @@ def get_shared_memory_by_id(memory_id: str): if not uid: raise HTTPException(status_code=404, detail="Memory is private") + # TODO: include speakers and people matched? + # TODO: other fields that shouldn't be included? memory = _get_memory_by_id(uid, memory_id) visibility = memory.get('visibility', MemoryVisibility.private) if not visibility or visibility == MemoryVisibility.private: