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
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class _SendAnimationState
],
);
_message.generateTempGuid();
outq.queue(OutgoingItem(
await outq.queue(OutgoingItem(
type: QueueType.sendMessage,
chat: controller.chat,
message: _message,
Expand Down Expand Up @@ -253,4 +253,4 @@ class _SendAnimationState
),
);
}
}
}
6 changes: 5 additions & 1 deletion lib/services/ui/chat/conversation_view_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@ class ConversationViewController extends StatefulController with GetSingleTicker
}

Future<void> send(List<PlatformFile> attachments, AttributedBody text, String subject, String? replyGuid, int? replyPart, String? effectId, PayloadData? payload, bool isAudioMessage, DateTime? scheduledDate) async {
sendFunc?.call(Tuple7(attachments, text, subject, replyGuid, replyPart, effectId, payload), isAudioMessage, scheduledDate);
final callback = sendFunc;
if (callback == null) {
throw StateError("Conversation send handler is not ready");
}
await callback(Tuple7(attachments, text, subject, replyGuid, replyPart, effectId, payload), isAudioMessage, scheduledDate);
}

void queueImage(Tuple4<Attachment, PlatformFile, BuildContext, Completer<Uint8List>> item) {
Expand Down
57 changes: 57 additions & 0 deletions test/services/conversation_view_controller_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'dart:async';

import 'package:bluebubbles/database/models.dart';
import 'package:bluebubbles/services/services.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
test('send waits for the composer handler to finish', () async {
final controller =
ConversationViewController(Chat(guid: 'iMessage;-;send-await-test'));
final handler = Completer<void>();
controller.sendFunc = (_, __, ___) => handler.future;

var completed = false;
final sending = controller
.send(
[],
AttributedBody.raw('message'),
'',
null,
null,
null,
null,
false,
null,
)
.then((_) => completed = true);

await Future<void>.delayed(Duration.zero);
expect(completed, isFalse);

handler.complete();
await sending;
expect(completed, isTrue);
});

test('send fails when the composer handler is not ready', () async {
final controller =
ConversationViewController(Chat(guid: 'iMessage;-;send-missing-test'));

await expectLater(
controller.send(
[],
AttributedBody.raw('message'),
'',
null,
null,
null,
null,
false,
null,
),
throwsStateError,
);
});
}