Skip to content

Commit ddbb34d

Browse files
committed
store: Expose sendMessage for general destinations
1 parent d990d33 commit ddbb34d

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

lib/model/store.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,15 @@ class PerAccountStore extends ChangeNotifier {
248248
}
249249
}
250250

251-
Future<void> sendStreamMessage({required String topic, required String content}) {
251+
Future<void> sendMessage({required MessageDestination destination, required String content}) {
252252
// TODO implement outbox; see design at
253253
// https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/.23M3881.20Sending.20outbox.20messages.20is.20fraught.20with.20issues/near/1405739
254-
255-
if (connection.realmUrl.origin != 'https://chat.zulip.org') {
256-
throw Exception('This method can currently only be used on https://chat.zulip.org.');
257-
}
258-
final destination = StreamDestination(7, topic); // TODO parametrize; this is `#test here`
259-
260-
return sendMessage(connection, destination: destination, content: content);
254+
return _apiSendMessage(connection, destination: destination, content: content);
261255
}
262256
}
263257

258+
const _apiSendMessage = sendMessage; // Bit ugly; for alternatives, see: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/flutter.3A.20PerAccountStore.20methods/near/1545809
259+
264260
/// A [GlobalStore] that uses a live server and live, persistent local database.
265261
///
266262
/// The underlying data store is an [AppDatabase] corresponding to a SQLite

lib/widgets/compose_box.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,12 @@ class _StreamSendButtonState extends State<_StreamSendButton> {
517517
}
518518

519519
final store = PerAccountStoreWidget.of(context);
520-
store.sendStreamMessage(
521-
topic: widget.topicController.textNormalized(),
522-
content: widget.contentController.textNormalized(),
523-
);
520+
if (store.connection.realmUrl.origin != 'https://chat.zulip.org') {
521+
throw Exception('This method can currently only be used on https://chat.zulip.org.');
522+
}
523+
final destination = StreamDestination(7, widget.topicController.textNormalized()); // TODO parametrize; this is `#test here`
524+
final content = widget.contentController.textNormalized();
525+
store.sendMessage(destination: destination, content: content);
524526

525527
widget.contentController.clear();
526528
}

0 commit comments

Comments
 (0)