Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion commet/lib/ui/atoms/drag_drop_file_target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class _DragDropFileTargetState extends State<DragDropFileTarget> {
Widget build(BuildContext context) {
return IgnorePointer(
child: DropTarget(
onDragEntered: (_) {
onDragEntered: (ev) {
print(ev);
setState(() {
isFileHovered = true;
});
Expand Down
73 changes: 73 additions & 0 deletions commet/lib/ui/organisms/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import 'package:commet/client/components/gif/gif_search_result.dart';
import 'package:commet/client/components/read_receipts/read_receipt_component.dart';
import 'package:commet/client/components/threads/thread_component.dart';
import 'package:commet/client/components/typing_indicators/typing_indicator_component.dart';
import 'package:commet/client/matrix/matrix_client.dart';
import 'package:commet/client/matrix/matrix_mxc_image_provider.dart';
import 'package:commet/client/timeline_events/timeline_event.dart';
import 'package:commet/client/timeline_events/timeline_event_message.dart';
import 'package:commet/client/timeline_events/timeline_event_sticker.dart';
Expand All @@ -21,6 +23,7 @@ import 'package:commet/main.dart';
import 'package:commet/ui/organisms/attachment_processor/attachment_processor.dart';
import 'package:commet/ui/navigation/adaptive_dialog.dart';
import 'package:commet/ui/organisms/chat/chat_view.dart';
import 'package:commet/utils/custom_uri.dart';
import 'package:commet/utils/debounce.dart';
import 'package:commet/utils/error_utils.dart';
import 'package:commet/utils/event_bus.dart';
Expand Down Expand Up @@ -399,6 +402,76 @@ class ChatState extends State<Chat> {
}

void onFileDropped(DropDoneDetails event) async {
var path = event.rawText;

print(path);
if (path != null) {
var custom = CustomURI.parse(path);

if (custom case AddWidgetURI widgetUri) {
AdaptiveDialog.show(context, builder: (dialogContext) {
return SizedBox(
width: 500,
child: Column(
spacing: 8,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.all(4.0),
child: Row(
spacing: 8,
children: [
if (widgetUri.widgetAvatarMxc != null)
SizedBox(
width: 30,
height: 30,
child: Image(
fit: BoxFit.cover,
image: MatrixMxcImage(
Uri.parse(widgetUri.widgetAvatarMxc!),
doThumbnail: false,
doFullres: true,
(widget.room.client as MatrixClient)
.matrixClient)),
),
tiamat.Text.label(
"Add the widget '${widgetUri.widgetName ?? "Custom"}' to ${widget.room.displayName}?"),
],
),
),

tiamat.Text.labelLow(
"Host: ${Uri.parse(widgetUri.widgetUrl).host}"),

if (widgetUri.previewMxc != null)
Padding(
padding: const EdgeInsets.all(8.0),
child: ClipRRect(
borderRadius: BorderRadiusGeometry.circular(20),
child: SizedBox(
height: 300,
child: Image(
fit: BoxFit.cover,
image: MatrixMxcImage(
Uri.parse(widgetUri.previewMxc!),
doThumbnail: false,
doFullres: true,
(widget.room.client as MatrixClient)
.matrixClient)),
),
),
),
tiamat.Button(text: "Add Widget",),
tiamat.Button.secondary(text: "Cancel",),
tiamat.Text.error(
"Widgets are hosted on external websites, and the code can be changed without notice. Do not use the widget if you do not trust the host.")
],
),
);
}, title: 'Add "${widgetUri.widgetName ?? "Widget"}"?');
}
}

for (var file in event.files) {
var size = await file.length();
Uint8List? data;
Expand Down
21 changes: 21 additions & 0 deletions commet/lib/ui/organisms/room_widgets/room_widgets_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:commet/client/components/widgets/widget_component.dart';
import 'package:commet/client/room.dart';
import 'package:commet/main.dart';
import 'package:commet/ui/atoms/adaptive_context_menu.dart';
import 'package:commet/utils/links/link_utils.dart';
import 'package:flutter/material.dart';

import 'package:tiamat/tiamat.dart' as tiamat;
Expand Down Expand Up @@ -57,6 +58,11 @@ class _RoomWidgetsViewState extends State<RoomWidgetsView> {
return tiamat.Tile.low(
child: Column(
children: [
if (widgets.isEmpty)
Padding(
padding: const EdgeInsets.all(8.0),
child: tiamat.Text.labelLow("No widgets have been added to this room"),
),
Flexible(
child: ListView.builder(
padding: EdgeInsets.all(0),
Expand Down Expand Up @@ -108,6 +114,21 @@ class _RoomWidgetsViewState extends State<RoomWidgetsView> {
},
),
),
Padding(
padding: const EdgeInsets.all(4.0),
child: SizedBox(
height: 50,
child: tiamat.TextButton(
"Browse Widgets",
icon: Icons.open_in_browser,
onTap: () {
LinkUtils.open(
Uri.parse("https://commet.chat/widgets"),
context: context,
);
},
)),
),
],
),
);
Expand Down
42 changes: 42 additions & 0 deletions commet/lib/utils/custom_uri.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:commet/config/build_config.dart';
import 'package:tiamat/config/style/theme_json_converter.dart';

class CustomURI {
static CustomURI? parse(String text) {
Expand Down Expand Up @@ -26,6 +27,24 @@ class CustomURI {
clientId: uri.queryParameters["client_id"]!);
}

if (uri.host == "add_widget") {
var url = uri.queryParameters.tryGet<String>("url");
var avatar = uri.queryParameters.tryGet<String>("avatar");
var widgetType = uri.queryParameters.tryGet<String>("type");
var widgetName = uri.queryParameters.tryGet<String>("name");
var preview = uri.queryParameters.tryGet<String>("preview");
if (url != null) {
return AddWidgetURI(
widgetUrl: Uri.decodeComponent(url),
widgetAvatarMxc:
avatar != null ? Uri.decodeComponent(avatar) : null,
widgetName: widgetName != null ? Uri.decodeComponent(widgetName) : null,
previewMxc: preview != null && preview.startsWith("mxc") == true ? Uri.decodeComponent(preview) : null,
widgetType:
widgetType != null ? Uri.decodeComponent(widgetType) : null);
}
}

if (uri.host == "accept_call") {
if ([
"room_id",
Expand Down Expand Up @@ -75,6 +94,29 @@ class OpenRoomURI implements CustomURI {
}
}

class AddWidgetURI implements CustomURI {
final String widgetUrl;
final String? widgetType;
final String? widgetAvatarMxc;
final String? widgetName;
final String? previewMxc;

AddWidgetURI(
{required this.widgetUrl, this.previewMxc, this.widgetName, this.widgetType, this.widgetAvatarMxc});

@override
String toString() {
return Uri(
scheme: BuildConfig.appSchema,
host: "add_widget",
queryParameters: {
"url": widgetUrl,
if (widgetType != null) "type": widgetType,
if (widgetAvatarMxc != null) "avatar": widgetAvatarMxc!,
}).toString();
}
}

class AcceptCallUri implements CustomURI {
final String roomId;
final String clientId;
Expand Down
2 changes: 1 addition & 1 deletion commet/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
matrix_widget_api:
path: ../widgets/matrix_widget_api
crypto: ^3.0.2
desktop_drop: ^0.4.1
desktop_drop: ^0.8.4
desktop_notifications: ^0.6.3
device_info_plus: ^12.2.0
flutter_background_service: ^5.0.5
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,10 @@ packages:
dependency: transitive
description:
name: desktop_drop
sha256: d55a010fe46c8e8fcff4ea4b451a9ff84a162217bdb3b2a0aa1479776205e15d
sha256: "47ded09c85909edfed644fd4cbb5051b040d0aed5c79e7e062ea4b3b7156dbe4"
url: "https://pub.dev"
source: hosted
version: "0.4.4"
version: "0.8.4"
desktop_notifications:
dependency: transitive
description:
Expand Down
Loading