Skip to content

Commit

Permalink
feat: send attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasn committed Feb 4, 2024
1 parent c2bab99 commit 765dea9
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 7 deletions.
3 changes: 0 additions & 3 deletions lib/blocs/sync/sync_config_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:lotti/database/logging_db.dart';
import 'package:lotti/get_it.dart';
import 'package:lotti/services/sync_config_service.dart';
import 'package:lotti/sync/inbox/inbox_service.dart';
import 'package:lotti/sync/matrix/matrix_service.dart';
import 'package:lotti/sync/outbox/outbox_service.dart';

class SyncConfigCubit extends Cubit<SyncConfigState> {
Expand Down Expand Up @@ -46,8 +45,6 @@ class SyncConfigCubit extends Cubit<SyncConfigState> {

await testConnection();

await getIt<MatrixService>().sendMatrixMsg('Hello world');

if (imapConfig != null && sharedSecret != null) {
await getIt<InboxService>().init();
await getIt<OutboxService>().init();
Expand Down
40 changes: 39 additions & 1 deletion lib/sync/matrix/matrix_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:lotti/classes/entity_definitions.dart';
Expand All @@ -10,7 +11,9 @@ import 'package:lotti/classes/tag_type_definitions.dart';
import 'package:lotti/database/database.dart';
import 'package:lotti/database/logging_db.dart';
import 'package:lotti/get_it.dart';
import 'package:lotti/utils/audio_utils.dart';
import 'package:lotti/utils/file_utils.dart';
import 'package:lotti/utils/image_utils.dart';
import 'package:matrix/matrix.dart';
import 'package:path_provider/path_provider.dart';

Expand Down Expand Up @@ -149,11 +152,46 @@ class MatrixService {
}
}

Future<void> sendMatrixMsg(String msg) async {
Future<void> sendMatrixMsg(SyncMessage syncMessage) async {
try {
final msg = json.encode(syncMessage);
const roomId = String.fromEnvironment('MATRIX_ROOM_ID');
final room = client.getRoomById(roomId);
await room?.sendTextEvent(base64.encode(utf8.encode(msg)));

final docDir = getDocumentsDirectory();

if (syncMessage is SyncJournalEntity) {
final journalEntity = syncMessage.journalEntity;

await journalEntity.maybeMap(
journalAudio: (JournalAudio journalAudio) async {
if (syncMessage.status == SyncEntryStatus.initial) {
final path = AudioUtils.getAudioPath(journalAudio, docDir);
final bytes = await File(path).readAsBytes();
await room?.sendFileEvent(
MatrixFile(
bytes: bytes,
name: path,
),
);
}
},
journalImage: (JournalImage journalImage) async {
if (syncMessage.status == SyncEntryStatus.initial) {
final path = getFullImagePath(journalImage);
final bytes = await File(path).readAsBytes();
await room?.sendFileEvent(
MatrixFile(
bytes: bytes,
name: path,
),
);
}
},
orElse: () {},
);
}
} catch (e, stackTrace) {
debugPrint('MATRIX: Error sending message: $e');
_loggingDb.captureException(
Expand Down
2 changes: 1 addition & 1 deletion lib/sync/outbox/outbox_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class OutboxService {
Future<void> enqueueMessage(SyncMessage syncMessage) async {
try {
unawaited(
getIt<MatrixService>().sendMatrixMsg(json.encode(syncMessage)),
getIt<MatrixService>().sendMatrixMsg(syncMessage),
);

return;
Expand Down
1 change: 1 addition & 0 deletions macos/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ target 'Runner' do
use_modular_headers!

flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
pod 'OpenSSL-Universal'
end

post_install do |installer|
Expand Down
8 changes: 6 additions & 2 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ PODS:
- FlutterMacOS
- media_kit_native_event_loop (1.0.0):
- FlutterMacOS
- OpenSSL-Universal (3.1.4000)
- package_info_plus (0.0.1):
- FlutterMacOS
- path_provider_foundation (0.0.1):
Expand Down Expand Up @@ -92,6 +93,7 @@ DEPENDENCIES:
- location (from `Flutter/ephemeral/.symlinks/plugins/location/macos`)
- media_kit_libs_macos_audio (from `Flutter/ephemeral/.symlinks/plugins/media_kit_libs_macos_audio/macos`)
- media_kit_native_event_loop (from `Flutter/ephemeral/.symlinks/plugins/media_kit_native_event_loop/macos`)
- OpenSSL-Universal
- package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`)
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
- photo_manager (from `Flutter/ephemeral/.symlinks/plugins/photo_manager/macos`)
Expand All @@ -110,6 +112,7 @@ SPEC REPOS:
trunk:
- ffmpeg-kit-macos-https
- HotKey
- OpenSSL-Universal
- ReachabilitySwift
- sqlite3

Expand Down Expand Up @@ -183,6 +186,7 @@ SPEC CHECKSUMS:
location: 7cdb0665bd6577d382b0a343acdadbcb7f964775
media_kit_libs_macos_audio: 3871782a4f3f84c77f04d7666c87800a781c24da
media_kit_native_event_loop: 7321675377cb9ae8596a29bddf3a3d2b5e8792c5
OpenSSL-Universal: 0adf92f748c570f9911fdb3c11fd5f1cf304e8d1
package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce
path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c
photo_manager: 4f6810b7dfc4feb03b461ac1a70dacf91fba7604
Expand All @@ -199,6 +203,6 @@ SPEC CHECKSUMS:
video_player_avfoundation: 02011213dab73ae3687df27ce441fbbcc82b5579
window_manager: 3a1844359a6295ab1e47659b1a777e36773cd6e8

PODFILE CHECKSUM: 0d353b18ff12f5d7cf17ff0e726ed751fc815029
PODFILE CHECKSUM: 2ac34291407b655c7f9b7e15bcc9e13760f1605d

COCOAPODS: 1.14.3
COCOAPODS: 1.15.0
9 changes: 9 additions & 0 deletions macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; };
33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; };
7E2335674AA28E31A7EEBE87 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BAE814E2540AB2A5F49FEB9F /* Pods_Runner.framework */; };
AD222ED52B6F1352003661C2 /* libcrypto.1.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = AD222ED42B6F1352003661C2 /* libcrypto.1.1.dylib */; settings = {ATTRIBUTES = (Weak, ); }; };
AD222ED62B6F135D003661C2 /* libcrypto.1.1.dylib in Bundle Framework */ = {isa = PBXBuildFile; fileRef = AD222ED42B6F1352003661C2 /* libcrypto.1.1.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
AD2C9ED72B50DEE90023FFD8 /* libolm.3.dylib in Resources */ = {isa = PBXBuildFile; fileRef = AD2C9ED62B50DEE90023FFD8 /* libolm.3.dylib */; };
AD2C9ED82B50E0240023FFD8 /* libolm.3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = AD2C9ED62B50DEE90023FFD8 /* libolm.3.dylib */; settings = {ATTRIBUTES = (Weak, ); }; };
AD2C9ED92B50E0EA0023FFD8 /* libolm.3.dylib in Bundle Framework */ = {isa = PBXBuildFile; fileRef = AD2C9ED62B50DEE90023FFD8 /* libolm.3.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
Expand All @@ -53,6 +55,7 @@
dstSubfolderSpec = 10;
files = (
AD2C9ED92B50E0EA0023FFD8 /* libolm.3.dylib in Bundle Framework */,
AD222ED62B6F135D003661C2 /* libcrypto.1.1.dylib in Bundle Framework */,
);
name = "Bundle Framework";
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -78,6 +81,7 @@
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
A87512A16BAFE7C799AAEE04 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
AD222ED42B6F1352003661C2 /* libcrypto.1.1.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcrypto.1.1.dylib; path = Runner/libcrypto.1.1.dylib; sourceTree = "<group>"; };
AD2C9ED22B50D5E00023FFD8 /* OLMKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = OLMKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
AD2C9ED42B50D9490023FFD8 /* libolm.dylib.3.2.16 */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libolm.dylib.3.2.16; path = ../../olm/build/libolm.dylib.3.2.16; sourceTree = "<group>"; };
AD2C9ED62B50DEE90023FFD8 /* libolm.3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libolm.3.dylib; path = Runner/libolm.3.dylib; sourceTree = "<group>"; };
Expand All @@ -100,6 +104,7 @@
files = (
AD2C9ED82B50E0240023FFD8 /* libolm.3.dylib in Frameworks */,
7E2335674AA28E31A7EEBE87 /* Pods_Runner.framework in Frameworks */,
AD222ED52B6F1352003661C2 /* libcrypto.1.1.dylib in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -121,6 +126,7 @@
isa = PBXGroup;
children = (
AD2C9ED62B50DEE90023FFD8 /* libolm.3.dylib */,
AD222ED42B6F1352003661C2 /* libcrypto.1.1.dylib */,
ADAC39812A06D91900E07F8F /* whisper.cpp */,
33FAB671232836740065AC1E /* Runner */,
33CEB47122A05771004F2AC0 /* Flutter */,
Expand Down Expand Up @@ -471,6 +477,7 @@
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Runner",
"$(PROJECT_DIR)",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
OTHER_CFLAGS = (
Expand Down Expand Up @@ -611,6 +618,7 @@
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Runner",
"$(PROJECT_DIR)",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
OTHER_CFLAGS = (
Expand Down Expand Up @@ -645,6 +653,7 @@
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Runner",
"$(PROJECT_DIR)",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
OTHER_CFLAGS = (
Expand Down
Binary file added macos/Runner/libcrypto.1.1.dylib
Binary file not shown.

0 comments on commit 765dea9

Please sign in to comment.