Skip to content

Add compose box for topic and DM narrows #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 13, 2023
Merged
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
2 changes: 1 addition & 1 deletion lib/model/autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '../widgets/compose_box.dart';
import 'narrow.dart';
import 'store.dart';

extension Autocomplete on ContentTextEditingController {
extension Autocomplete on ComposeContentController {
AutocompleteIntent? autocompleteIntent() {
if (!selection.isValid || !selection.isNormalized) {
// We don't require [isCollapsed] to be true because we've seen that
Expand Down
19 changes: 17 additions & 2 deletions lib/model/narrow.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import '../api/model/model.dart';
import '../api/model/narrow.dart';
import '../api/route/messages.dart';

/// A Zulip narrow.
sealed class Narrow {
Expand All @@ -15,6 +16,11 @@ sealed class Narrow {
ApiNarrow apiEncode();
}

/// A non-interleaved narrow, completely specifying a place to send a message.
sealed class SendableNarrow extends Narrow {
MessageDestination get destination;
}

/// The narrow called "All messages" in the UI.
///
/// This does not literally mean all messages, or even all messages
Expand Down Expand Up @@ -65,7 +71,7 @@ class StreamNarrow extends Narrow {
int get hashCode => Object.hash('StreamNarrow', streamId);
}

class TopicNarrow extends Narrow {
class TopicNarrow extends Narrow implements SendableNarrow {
const TopicNarrow(this.streamId, this.topic);

final int streamId;
Expand All @@ -80,6 +86,9 @@ class TopicNarrow extends Narrow {
@override
ApiNarrow apiEncode() => [ApiNarrowStream(streamId), ApiNarrowTopic(topic)];

@override
StreamDestination get destination => StreamDestination(streamId, topic);

@override
bool operator ==(Object other) {
if (other is! TopicNarrow) return false;
Expand Down Expand Up @@ -111,7 +120,7 @@ bool _isSortedWithoutDuplicates(List<int> items) {
// handling many of them, see zulip-mobile:src/utils/recipient.js .
// Please add more constructors and getters here to handle any of those
// as we turn out to need them.
class DmNarrow extends Narrow {
class DmNarrow extends Narrow implements SendableNarrow {
DmNarrow({required this.allRecipientIds, required int selfUserId})
: assert(_isSortedWithoutDuplicates(allRecipientIds)),
assert(allRecipientIds.contains(selfUserId)),
Expand Down Expand Up @@ -166,9 +175,15 @@ class DmNarrow extends Narrow {
return true;
}

// Not [otherRecipientIds], because for the self-1:1 thread the server rejects
// that as of Zulip Server 7 (2023-06), with BAD_REQUEST.
@override
DmDestination get destination => DmDestination(userIds: allRecipientIds);

// Not [otherRecipientIds], because for the self-1:1 thread that triggers
// a server bug as of Zulip Server 7 (2023-05): an empty list here
// causes a 5xx response from the server.
// TODO(server): fix bug on empty operand to dm/pm-with narrow operator
@override
ApiNarrow apiEncode() => [ApiNarrowDm(allRecipientIds)];

Expand Down
Loading