diff --git a/lib/api/model/model.dart b/lib/api/model/model.dart index a4320a28eb..67770a6b73 100644 --- a/lib/api/model/model.dart +++ b/lib/api/model/model.dart @@ -298,7 +298,7 @@ abstract class Message { factory Message.fromJson(Map 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"); } @@ -344,7 +344,7 @@ class StreamMessage extends Message { } @JsonSerializable(fieldRename: FieldRename.snake) -class PmRecipient { +class DmRecipient { final int id; final String email; final String fullName; @@ -352,23 +352,23 @@ class PmRecipient { // 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 json) => - _$PmRecipientFromJson(json); + factory DmRecipient.fromJson(Map json) => + _$DmRecipientFromJson(json); - Map toJson() => _$PmRecipientToJson(this); + Map 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 displayRecipient; + final List displayRecipient; - PmMessage({ + DmMessage({ super.avatarUrl, required super.client, required super.content, @@ -389,9 +389,9 @@ class PmMessage extends Message { required this.displayRecipient, }); - factory PmMessage.fromJson(Map json) => - _$PmMessageFromJson(json); + factory DmMessage.fromJson(Map json) => + _$DmMessageFromJson(json); @override - Map toJson() => _$PmMessageToJson(this); + Map toJson() => _$DmMessageToJson(this); } diff --git a/lib/api/model/model.g.dart b/lib/api/model/model.g.dart index 4550158172..61aee44cf2 100644 --- a/lib/api/model/model.g.dart +++ b/lib/api/model/model.g.dart @@ -225,20 +225,20 @@ Map _$StreamMessageToJson(StreamMessage instance) => 'stream_id': instance.streamId, }; -PmRecipient _$PmRecipientFromJson(Map json) => PmRecipient( +DmRecipient _$DmRecipientFromJson(Map json) => DmRecipient( id: json['id'] as int, email: json['email'] as String, fullName: json['full_name'] as String, ); -Map _$PmRecipientToJson(PmRecipient instance) => +Map _$DmRecipientToJson(DmRecipient instance) => { 'id': instance.id, 'email': instance.email, 'full_name': instance.fullName, }; -PmMessage _$PmMessageFromJson(Map json) => PmMessage( +DmMessage _$DmMessageFromJson(Map json) => DmMessage( avatarUrl: json['avatar_url'] as String?, client: json['client'] as String, content: json['content'] as String, @@ -257,11 +257,11 @@ PmMessage _$PmMessageFromJson(Map json) => PmMessage( matchContent: json['match_content'] as String?, matchSubject: json['match_subject'] as String?, displayRecipient: (json['display_recipient'] as List) - .map((e) => PmRecipient.fromJson(e as Map)) + .map((e) => DmRecipient.fromJson(e as Map)) .toList(), ); -Map _$PmMessageToJson(PmMessage instance) => { +Map _$DmMessageToJson(DmMessage instance) => { 'avatar_url': instance.avatarUrl, 'client': instance.client, 'content': instance.content, diff --git a/lib/api/model/narrow.dart b/lib/api/model/narrow.dart index b944936549..2ff19fd865 100644 --- a/lib/api/model/narrow.dart +++ b/lib/api/model/narrow.dart @@ -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 operand; - ApiNarrowPmWith(this.operand, {super.negated}); + ApiNarrowDm(this.operand, {super.negated}); - factory ApiNarrowPmWith.fromJson(Map json) => ApiNarrowPmWith( + factory ApiNarrowDm.fromJson(Map json) => ApiNarrowDm( (json['operand'] as List).map((e) => e as int).toList(), negated: json['negated'] as bool? ?? false, ); diff --git a/lib/api/route/messages.dart b/lib/api/route/messages.dart index 20461891c1..31b293d299 100644 --- a/lib/api/route/messages.dart +++ b/lib/api/route/messages.dart @@ -104,8 +104,8 @@ Future 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 @@ -118,7 +118,7 @@ Future 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]. @@ -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 userIds; } diff --git a/lib/model/narrow.dart b/lib/model/narrow.dart index 508e843b02..0a5fc36846 100644 --- a/lib/model/narrow.dart +++ b/lib/model/narrow.dart @@ -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 diff --git a/lib/widgets/message_list.dart b/lib/widgets/message_list.dart index 765f04adbd..11c6401e43 100644 --- a/lib/widgets/message_list.dart +++ b/lib/widgets/message_list.dart @@ -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}"); } @@ -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. diff --git a/test/api/route/messages_test.dart b/test/api/route/messages_test.dart index 7e571c7275..f1c608ae95 100644 --- a/test/api/route/messages_test.dart +++ b/test/api/route/messages_test.dart @@ -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() ..method.equals('POST')