Skip to content

Commit

Permalink
app setMemoryVisibility call
Browse files Browse the repository at this point in the history
  • Loading branch information
josancamon19 committed Aug 29, 2024
1 parent 3f0d872 commit 1319c3a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
18 changes: 15 additions & 3 deletions app/lib/backend/http/api/memories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -198,3 +198,15 @@ Future<bool> assignMemoryTranscriptSegment(
debugPrint('assignMemoryTranscriptSegment: ${response.body}');
return response.statusCode == 200;
}

Future<bool> 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;
}
30 changes: 30 additions & 0 deletions app/lib/pages/memory_detail/share.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions app/lib/providers/device_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backend/database/memories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions backend/routers/memories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 1319c3a

Please sign in to comment.