fix(chat): change sendChatMessage method

This commit is contained in:
mso7nueh
2025-06-22 18:27:25 +03:00
parent 2a705fdb66
commit 85d67ba9c4
9 changed files with 116 additions and 45 deletions

View File

@@ -176,9 +176,19 @@ class ChatRoomCubit extends Cubit<ChatRoomState> {
});
}
Future<bool> sendMessage({required String chatId, String? data, List<File>? files}) async {
Future<bool> sendMessage({
required String chatId,
String? data,
List<File>? files,
required String userSlug,
}) async {
try {
await chatRepository.sendMessage(chatId: chatId, data: data, files: files != null ? await ImageCompressUtility.compressFilesList(files) : null);
await chatRepository.sendMessage(
chatId: chatId,
data: data,
files: files != null ? await ImageCompressUtility.compressFilesList(files) : null,
slug: userSlug,
);
AudioPlayer().play((AssetSource('audio/send_message.wav')));
return true;
} catch (e, st) {

View File

@@ -341,7 +341,7 @@ class _ChatScreenState extends State<ChatScreen> {
children: [
const SizedBox(width: 8),
InkWell(
onTap: () => showImagePicker(),
onTap: () => showImagePicker(state.chatRoom.users.receiver.slug),
customBorder: const CircleBorder(),
child: Ink(
height: 40,
@@ -386,7 +386,11 @@ class _ChatScreenState extends State<ChatScreen> {
customBorder: const CircleBorder(),
onTap: () {
if (textEditingController.text.isNotEmpty) {
chatRoomCubit.sendMessage(chatId: widget.chatId, data: textEditingController.text.trim());
chatRoomCubit.sendMessage(
chatId: widget.chatId,
data: textEditingController.text.trim(),
userSlug: state.chatRoom.users.receiver.slug,
);
setState(() {
textEditingController.clear();
});
@@ -421,7 +425,7 @@ class _ChatScreenState extends State<ChatScreen> {
);
}
showImagePicker() {
showImagePicker(String slug) {
showCupertinoModalPopup<void>(
context: context,
builder: (context) => CupertinoActionSheet(
@@ -432,7 +436,7 @@ class _ChatScreenState extends State<ChatScreen> {
final picker = ImagePicker();
XFile? image = await picker.pickImage(source: ImageSource.camera);
if (image != null) {
await chatRoomCubit.sendMessage(chatId: widget.chatId, files: [File(image.path)]);
await chatRoomCubit.sendMessage(chatId: widget.chatId, files: [File(image.path)], userSlug: slug);
}
},
child: const Row(
@@ -472,7 +476,7 @@ class _ChatScreenState extends State<ChatScreen> {
);
if (result != null) {
List<File> files = result.paths.map((path) => File(path!)).toList();
await chatRoomCubit.sendMessage(chatId: widget.chatId, files: files);
await chatRoomCubit.sendMessage(chatId: widget.chatId, files: files, userSlug: slug);
}
},
child: const Row(