Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahramMebashar committed Dec 3, 2024
1 parent 7ab73aa commit f0fd15e
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 544 deletions.
1 change: 0 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:io';

import 'package:chatwoot_sdk/chatwoot_sdk.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image/image.dart' as image;
import 'package:image_picker/image_picker.dart' as image_picker;
import 'package:path_provider/path_provider.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/data/remote/service/chatwoot_client_auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ChatwootClientAuthServiceImpl extends ChatwootClientAuthService {
createResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.CREATE_CONTACT_FAILED);
}
} on DioException catch (e) {
} on DioError catch (e) {
throw ChatwootClientException(
e.message ?? "", ChatwootClientExceptionType.CREATE_CONTACT_FAILED);
}
Expand All @@ -67,7 +67,7 @@ class ChatwootClientAuthServiceImpl extends ChatwootClientAuthService {
createResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.CREATE_CONVERSATION_FAILED);
}
} on DioException catch (e) {
} on DioError catch (e) {
throw ChatwootClientException(e.message ?? "",
ChatwootClientExceptionType.CREATE_CONVERSATION_FAILED);
}
Expand Down
16 changes: 8 additions & 8 deletions lib/data/remote/service/chatwoot_client_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
createResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.SEND_MESSAGE_FAILED);
}
} on DioException catch (e) {
} on DioError catch (e) {
throw ChatwootClientException(
e.message ?? "", ChatwootClientExceptionType.SEND_MESSAGE_FAILED);
}
Expand All @@ -107,7 +107,7 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
createResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.GET_MESSAGES_FAILED);
}
} on DioException catch (e) {
} on DioError catch (e) {
throw ChatwootClientException(
e.message ?? "", ChatwootClientExceptionType.GET_MESSAGES_FAILED);
}
Expand All @@ -126,7 +126,7 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
getResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.GET_CONTACT_FAILED);
}
} on DioException catch (e) {
} on DioError catch (e) {
throw ChatwootClientException(
e.message ?? "", ChatwootClientExceptionType.GET_CONTACT_FAILED);
}
Expand All @@ -147,7 +147,7 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
createResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.GET_CONVERSATION_FAILED);
}
} on DioException catch (e) {
} on DioError catch (e) {
throw ChatwootClientException(
e.message ?? "", ChatwootClientExceptionType.GET_CONVERSATION_FAILED);
}
Expand All @@ -167,7 +167,7 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
updateResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.UPDATE_CONTACT_FAILED);
}
} on DioException catch (e) {
} on DioError catch (e) {
throw ChatwootClientException(
e.message ?? "", ChatwootClientExceptionType.UPDATE_CONTACT_FAILED);
}
Expand All @@ -189,7 +189,7 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
updateResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.UPDATE_MESSAGE_FAILED);
}
} on DioException catch (e) {
} on DioError catch (e) {
throw ChatwootClientException(
e.message ?? "", ChatwootClientExceptionType.UPDATE_MESSAGE_FAILED);
}
Expand Down Expand Up @@ -242,7 +242,7 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
throw ChatwootClientException(response.statusMessage ?? "unknown error",
ChatwootClientExceptionType.GET_CSAT_FEEDBACK);
}
} on DioException catch (e) {
} on DioError catch (e) {
throw ChatwootClientException(
e.message ?? "", ChatwootClientExceptionType.GET_CSAT_FEEDBACK);
}
Expand All @@ -264,7 +264,7 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
throw ChatwootClientException(response.statusMessage ?? "unknown error",
ChatwootClientExceptionType.SEND_CSAT_FEEDBACK);
}
} on DioException catch (e) {
} on DioError catch (e) {
throw ChatwootClientException(
e.message ?? "", ChatwootClientExceptionType.SEND_CSAT_FEEDBACK);
}
Expand Down
66 changes: 0 additions & 66 deletions lib/ui/chatwoot_chat_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ import 'package:chatwoot_sdk/ui/chatwoot_chat_theme.dart';
import 'package:chatwoot_sdk/ui/chatwoot_l10n.dart';
import 'package:chatwoot_sdk/ui/link_preview.dart';
import 'package:chatwoot_sdk/ui/media_widgets.dart';
import 'package:chatwoot_sdk/ui/video_preview.dart';
import 'package:easy_image_viewer/easy_image_viewer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
import 'package:flutter_chat_ui/flutter_chat_ui.dart';
import 'package:intl/intl.dart';
import 'package:media_kit/media_kit.dart';
import 'package:media_kit_video/media_kit_video.dart';
import 'package:mime/mime.dart';
import 'package:path_provider/path_provider.dart';
import 'package:uuid/uuid.dart';
Expand Down Expand Up @@ -190,16 +187,10 @@ class _ChatwootChatState extends State<ChatwootChat>
ChatwootClient? chatwootClient;

late final ChatwootCallbacks chatwootCallbacks;
late VideoController controller;
late VideoPreviewLoader videoPreviewLoader;

@override
void initState() {
super.initState();
MediaKit.ensureInitialized();
controller = VideoController(Player());
videoPreviewLoader = VideoPreviewLoader(controller: controller);
videoPreviewLoader.listen(_handleVideoPreviewLoaded);
if (widget.user == null) {
_user = types.User(id: idGen.v4());
} else {
Expand Down Expand Up @@ -417,23 +408,6 @@ class _ChatwootChatState extends State<ChatwootChat>
status: messageStatus ?? types.Status.seen,
createdAt:
DateTime.parse(message.createdAt).millisecondsSinceEpoch);
} else if (message.attachments!.first.fileType == "video") {
final videoMessage = types.VideoMessage(
id: echoId ?? message.id.toString(),
author: author,
height: 500,
width: 500,
name: fileName,
metadata: metadata,
size: message.attachments!.first.fileSize ?? 0,
uri: message.attachments!.first.dataUrl!,
status: messageStatus ?? types.Status.seen,
createdAt:
DateTime.parse(message.createdAt).millisecondsSinceEpoch);

videoPreviewLoader.getPreview(
jobId: videoMessage.id, uri: videoMessage.uri);
return videoMessage;
} else if (message.attachments!.first.fileType == "audio") {
return types.AudioMessage(
id: echoId ?? message.id.toString(),
Expand Down Expand Up @@ -564,18 +538,6 @@ class _ChatwootChatState extends State<ChatwootChat>
});
}

void _handleVideoPreviewLoaded(VideoMessagePreviewResult result) {
final index = _messages.indexWhere((element) => element.id == result.jobId);
if (index > -1) {
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
_messages[index] =
_messages[index].copyWith(metadata: {"preview": result.preview});
});
});
}
}

void _handleSendPressed(String message) {
final textMessage = types.TextMessage(
author: _user,
Expand Down Expand Up @@ -604,18 +566,6 @@ class _ChatwootChatState extends State<ChatwootChat>
uri: attachment.path,
size: attachment.bytes.length,
status: types.Status.sending);
} else if (lookupMimeType(attachment.name)?.startsWith("video") ??
false) {
message = types.VideoMessage(
author: _user,
createdAt: DateTime.now().millisecondsSinceEpoch,
id: const Uuid().v4(),
name: attachment.name,
uri: attachment.path,
size: attachment.bytes.length,
status: types.Status.sending);

videoPreviewLoader.getPreview(jobId: message.id, uri: attachment.path);
} else if (lookupMimeType(attachment.name)?.startsWith("audio") ??
false) {
message = types.AudioMessage(
Expand Down Expand Up @@ -657,14 +607,6 @@ class _ChatwootChatState extends State<ChatwootChat>
body: Stack(
children: [
//offscreen video player used to fetch first frame of video messages. media_kit screenshot doesn't work without
//controller tied to the video widget
IgnorePointer(
child: Opacity(
opacity: 0,
child: Video(
controller: controller,
fit: BoxFit.contain,
))),
//actual chat
Column(
children: [
Expand Down Expand Up @@ -797,14 +739,6 @@ class _ChatwootChatState extends State<ChatwootChat>
void dispose() {
super.dispose();
chatwootClient?.dispose();
videoPreviewLoader.dispose();
LinkMetadata.dispose();
controller.player.dispose();
_messages.forEach((m) {
if (m is types.VideoMessage) {
final controller = m.metadata?["controller"] as VideoController?;
controller?.player.dispose();
}
});
}
}
Loading

0 comments on commit f0fd15e

Please sign in to comment.