Skip to content
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

Say "DM"/"direct message" instead of "PM"/"private message", in UI and code #152

Merged
merged 1 commit into from
Jun 6, 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
24 changes: 12 additions & 12 deletions lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ abstract class Message {
factory Message.fromJson(Map<String, dynamic> json) {
final type = json['type'] as String;
if (type == 'stream') return StreamMessage.fromJson(json);
if (type == 'private') return PmMessage.fromJson(json);
if (type == 'private') return DmMessage.fromJson(json);
throw Exception("Message.fromJson: unexpected message type $type");
}

Expand Down Expand Up @@ -344,31 +344,31 @@ class StreamMessage extends Message {
}

@JsonSerializable(fieldRename: FieldRename.snake)
class PmRecipient {
class DmRecipient {
final int id;
final String email;
final String fullName;

// final String? shortName; // obsolete, ignore
// final bool? isMirrorDummy; // obsolete, ignore

PmRecipient({required this.id, required this.email, required this.fullName});
DmRecipient({required this.id, required this.email, required this.fullName});

factory PmRecipient.fromJson(Map<String, dynamic> json) =>
_$PmRecipientFromJson(json);
factory DmRecipient.fromJson(Map<String, dynamic> json) =>
_$DmRecipientFromJson(json);

Map<String, dynamic> toJson() => _$PmRecipientToJson(this);
Map<String, dynamic> toJson() => _$DmRecipientToJson(this);
}

@JsonSerializable(fieldRename: FieldRename.snake)
class PmMessage extends Message {
class DmMessage extends Message {
@override
@JsonKey(includeToJson: true)
String get type => 'private';

final List<PmRecipient> displayRecipient;
final List<DmRecipient> displayRecipient;

PmMessage({
DmMessage({
super.avatarUrl,
required super.client,
required super.content,
Expand All @@ -389,9 +389,9 @@ class PmMessage extends Message {
required this.displayRecipient,
});

factory PmMessage.fromJson(Map<String, dynamic> json) =>
_$PmMessageFromJson(json);
factory DmMessage.fromJson(Map<String, dynamic> json) =>
_$DmMessageFromJson(json);

@override
Map<String, dynamic> toJson() => _$PmMessageToJson(this);
Map<String, dynamic> toJson() => _$DmMessageToJson(this);
}
10 changes: 5 additions & 5 deletions lib/api/model/model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions lib/api/model/narrow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ class ApiNarrowTopic extends ApiNarrowElement {
);
}

class ApiNarrowPmWith extends ApiNarrowElement {
@override String get operator => 'pm-with'; // TODO(server-7): use 'dm' where possible
/// An [ApiNarrowElement] with the 'dm', or legacy 'pm-with', operator.
class ApiNarrowDm extends ApiNarrowElement {
@override String get operator => 'pm-with'; // TODO(#146): use 'dm' where possible

@override final List<int> operand;

ApiNarrowPmWith(this.operand, {super.negated});
ApiNarrowDm(this.operand, {super.negated});

factory ApiNarrowPmWith.fromJson(Map<String, dynamic> json) => ApiNarrowPmWith(
factory ApiNarrowDm.fromJson(Map<String, dynamic> json) => ApiNarrowDm(
(json['operand'] as List<dynamic>).map((e) => e as int).toList(),
negated: json['negated'] as bool? ?? false,
);
Expand Down
12 changes: 6 additions & 6 deletions lib/api/route/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ Future<SendMessageResult> sendMessage(
'type': RawParameter('stream'),
'to': destination.streamId,
'topic': RawParameter(destination.topic),
} else if (destination is PmDestination) ...{
'type': RawParameter('private'), // TODO(server-7)
} else if (destination is DmDestination) ...{
'type': RawParameter('private'), // TODO(#146): use 'direct' where possible
'to': destination.userIds,
} else ...(
throw Exception('impossible destination') // TODO(dart-3) show this statically
Expand All @@ -118,7 +118,7 @@ Future<SendMessageResult> sendMessage(

/// Which conversation to send a message to, in [sendMessage].
///
/// This is either a [StreamDestination] or a [PmDestination].
/// This is either a [StreamDestination] or a [DmDestination].
sealed class MessageDestination {}

/// A conversation in a stream, for specifying to [sendMessage].
Expand All @@ -132,12 +132,12 @@ class StreamDestination extends MessageDestination {
final String topic;
}

/// A PM conversation, for specifying to [sendMessage].
/// A DM conversation, for specifying to [sendMessage].
///
/// The server accepts a list of Zulip API emails as an alternative to
/// a list of user IDs, but this binding currently doesn't.
class PmDestination extends MessageDestination {
PmDestination({required this.userIds});
class DmDestination extends MessageDestination {
DmDestination({required this.userIds});

final List<int> userIds;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/model/narrow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ class TopicNarrow extends Narrow {
int get hashCode => Object.hash('TopicNarrow', streamId, topic);
}

// TODO other narrow types: PMs/DMs; starred, mentioned; searches; arbitrary
// TODO other narrow types: DMs; starred, mentioned; searches; arbitrary
22 changes: 11 additions & 11 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ class MessageItem extends StatelessWidget {
restBorderColor = _kStreamMessageBorderColor;
recipientHeader = StreamTopicRecipientHeader(
message: msg, streamColor: highlightBorderColor);
} else if (message is PmMessage) {
final msg = (message as PmMessage);
highlightBorderColor = _kPmRecipientHeaderColor;
restBorderColor = _kPmRecipientHeaderColor;
recipientHeader = PmRecipientHeader(message: msg);
} else if (message is DmMessage) {
final msg = (message as DmMessage);
highlightBorderColor = _kDmRecipientHeaderColor;
restBorderColor = _kDmRecipientHeaderColor;
recipientHeader = DmRecipientHeader(message: msg);
} else {
throw Exception("impossible message type: ${message.runtimeType}");
}
Expand Down Expand Up @@ -299,23 +299,23 @@ class StreamTopicRecipientHeader extends StatelessWidget {

final _kStreamMessageBorderColor = const HSLColor.fromAHSL(1, 0, 0, 0.88).toColor();

class PmRecipientHeader extends StatelessWidget {
const PmRecipientHeader({super.key, required this.message});
class DmRecipientHeader extends StatelessWidget {
const DmRecipientHeader({super.key, required this.message});

final PmMessage message;
final DmMessage message;

@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.centerLeft,
child: RecipientHeaderChevronContainer(
color: _kPmRecipientHeaderColor,
child: const Text("Private message", // TODO PM recipient headers
color: _kDmRecipientHeaderColor,
child: const Text("Direct message", // TODO DM recipient headers
style: TextStyle(color: Colors.white))));
}
}

final _kPmRecipientHeaderColor =
final _kDmRecipientHeaderColor =
const HSLColor.fromAHSL(1, 0, 0, 0.27).toColor();

/// A widget with the distinctive chevron-tailed shape in Zulip recipient headers.
Expand Down
4 changes: 2 additions & 2 deletions test/api/route/messages_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ void main() {
});
});

test('sendMessage to PM conversation', () {
test('sendMessage to DM conversation', () {
return FakeApiConnection.with_((connection) async {
const userIds = [23, 34];
const content = 'hi there';
connection.prepare(json: SendMessageResult(id: 42).toJson());
final result = await sendMessage(connection,
destination: PmDestination(userIds: userIds), content: content);
destination: DmDestination(userIds: userIds), content: content);
check(result).id.equals(42);
check(connection.lastRequest).isNotNull().isA<http.Request>()
..method.equals('POST')
Expand Down