Skip to content

Commit

Permalink
TW-1149: Handle received and send multiple files external
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Dec 26, 2023
1 parent 0e64c0e commit f2b0a20
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 49 deletions.
21 changes: 0 additions & 21 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,6 @@
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="video/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="video/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down
2 changes: 1 addition & 1 deletion lib/config/go_routes/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ abstract class AppRoutes {
child: ChatAdaptiveScaffold(
roomId: state.pathParameters['roomid']!,
key: Key(state.pathParameters['roomid']!),
shareFile: extra.data as MatrixFile?,
shareFiles: extra.data as List<MatrixFile?>?,
),
);
}
Expand Down
35 changes: 20 additions & 15 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ import 'sticker_picker_dialog.dart';

class Chat extends StatefulWidget {
final String roomId;
final MatrixFile? shareFile;
final List<MatrixFile?>? shareFiles;
final String? roomName;
final void Function(RightColumnType)? onChangeRightColumnType;

const Chat({
Key? key,
required this.roomId,
this.shareFile,
this.shareFiles,
this.roomName,
this.onChangeRightColumnType,
}) : super(key: key);
Expand Down Expand Up @@ -111,7 +111,7 @@ class ChatController extends State<Chat>

String? unreadReceivedMessageLocation;

MatrixFile? get shareFile => widget.shareFile;
List<MatrixFile?>? get shareFiles => widget.shareFiles;

String? get roomName => widget.roomName;

Expand Down Expand Up @@ -324,6 +324,19 @@ class ChatController extends State<Chat>
}
}

void _handleReceivedShareFiles() {
if (shareFiles != null && room != null) {
final sendFileInteractor = getIt.get<SendFileInteractor>();
final filesIsNotNull = shareFiles!.where((file) => file != null);
sendFileInteractor.execute(
room: room!,
fileInfos: filesIsNotNull
.map((file) => FileInfo.fromMatrixFile(file!))
.toList(),
);
}
}

@override
void initState() {
keyboardVisibilityController.onChange.listen(_keyboardListener);
Expand All @@ -336,18 +349,8 @@ class ChatController extends State<Chat>
if (room == null) {
return context.go("/error");
}
_handleReceivedShareFiles();

if (shareFile != null && room != null && shareFile!.filePath != null) {
final sendFileInteractor = getIt.get<SendFileInteractor>();
sendFileInteractor.execute(
room: room!,
fileInfos: [
FileInfo.fromMatrixFile(
shareFile!,
),
],
);
}
pinnedEventsController.getPinnedMessageAction(
room: room!,
isInitial: true,
Expand Down Expand Up @@ -380,7 +383,9 @@ class ChatController extends State<Chat>
setReadMarker();
return;
}
_initUnreadLocation(fullyRead);
if (room?.hasNewMessages == true) {
_initUnreadLocation(fullyRead);
}
if (!mounted) return;
} catch (e, s) {
Logs().e('Failed to load timeline', e, s);
Expand Down
6 changes: 3 additions & 3 deletions lib/pages/chat_adaptive_scaffold/chat_adaptive_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import 'package:matrix/matrix.dart';

class ChatAdaptiveScaffold extends StatefulWidget {
final String roomId;
final MatrixFile? shareFile;
final List<MatrixFile?>? shareFiles;
final String? roomName;

const ChatAdaptiveScaffold({
Key? key,
required this.roomId,
this.shareFile,
this.shareFiles,
this.roomName,
}) : super(key: key);

Expand All @@ -29,7 +29,7 @@ class ChatAdaptiveScaffoldController extends State<ChatAdaptiveScaffold> {
return ChatAdaptiveScaffoldBuilder(
bodyBuilder: (controller) => Chat(
roomId: widget.roomId,
shareFile: widget.shareFile,
shareFiles: widget.shareFiles,
roomName: widget.roomName,
onChangeRightColumnType: controller.setRightColumnType,
),
Expand Down
47 changes: 38 additions & 9 deletions lib/pages/share/share.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,52 @@ class ShareController extends State<Share>
id: selectedRoomsNotifier.value.first,
client: Matrix.of(context).client,
);
final shareContentList = Matrix.of(context).shareContentList;
final shareContent = Matrix.of(context).shareContent;
if (shareContent != null) {
final shareFile = shareContent.tryGet<MatrixFile>('file');
if (shareContent.tryGet<String>('msgtype') ==
TwakeEventTypes.shareFileEventType) {

if (shareContentList.isNotEmpty) {
_handleShareFilesContent(
room: room,
shareContentList: shareContentList,
);
} else if (shareContent != null) {
_handleShareTextContent(
room: room,
textContent: shareContent,
);
}
}

void _handleShareTextContent({
required Room room,
Map<String, dynamic>? textContent,
}) {
if (textContent == null) return;
room.sendEvent(textContent);
context.go('/rooms/${room.id}');
}

void _handleShareFilesContent({
required Room room,
required List<Map<String, dynamic>?> shareContentList,
}) {
if (shareContentList.isNotEmpty) {
if (shareContentList.every(
(content) =>
content?.tryGet<String>('msgtype') ==
TwakeEventTypes.shareFileEventType,
)) {
context.go(
'/rooms/${room.id}',
extra: ChatRouterInputArgument(
type: ChatRouterInputArgumentType.share,
data: shareFile,
data: shareContentList
.map((content) => content?.tryGet<MatrixFile>('file'))
.toList(),
),
);
} else {
room.sendEvent(shareContent);
context.go('/rooms/${room.id}');
}
Matrix.of(context).shareContent = null;
Matrix.of(context).shareContentList = null;
}
}

Expand Down

0 comments on commit f2b0a20

Please sign in to comment.