@@ -103,10 +103,25 @@ Map<String, dynamic> _messagePropertiesFromSender(User? sender) {
103
103
};
104
104
}
105
105
106
+ Map <String , dynamic > _messagePropertiesFromContent (String ? content, String ? contentMarkdown) {
107
+ if (contentMarkdown != null ) {
108
+ assert (content == null );
109
+ return {
110
+ 'content' : contentMarkdown,
111
+ 'content_type' : 'text/x-markdown' ,
112
+ };
113
+ } else {
114
+ return {
115
+ 'content' : content ?? '<p>This is an example message.</p>' ,
116
+ 'content_type' : 'text/html' ,
117
+ };
118
+ }
119
+ }
120
+
106
121
const _stream = stream;
107
122
108
123
StreamMessage streamMessage (
109
- {User ? sender, ZulipStream ? stream, String ? topic}) {
124
+ {User ? sender, ZulipStream ? stream, String ? topic, String ? content, String ? contentMarkdown }) {
110
125
final effectiveStream = stream ?? _stream ();
111
126
// The use of JSON here is convenient in order to delegate parts of the data
112
127
// to helper functions. The main downside is that it loses static typing
@@ -116,11 +131,9 @@ StreamMessage streamMessage(
116
131
return StreamMessage .fromJson ({
117
132
..._messagePropertiesBase,
118
133
..._messagePropertiesFromSender (sender),
134
+ ..._messagePropertiesFromContent (content, contentMarkdown),
119
135
'display_recipient' : effectiveStream.name,
120
136
'stream_id' : effectiveStream.streamId,
121
-
122
- 'content' : '<p>This is an example stream message.</p>' ,
123
- 'content_type' : 'text/html' ,
124
137
'flags' : [],
125
138
'id' : 1234567 , // TODO generate example IDs
126
139
'subject' : topic ?? 'example topic' ,
@@ -133,17 +146,17 @@ StreamMessage streamMessage(
133
146
///
134
147
/// See also:
135
148
/// * [streamMessage] , to construct an example stream message.
136
- DmMessage dmMessage ({required User from, required List <User > to}) {
149
+ DmMessage dmMessage (
150
+ {required User from, required List <User > to, String ? content, String ? contentMarkdown}) {
137
151
assert (! to.any ((user) => user.userId == from.userId));
138
152
return DmMessage .fromJson ({
139
153
..._messagePropertiesBase,
140
154
..._messagePropertiesFromSender (from),
155
+ ..._messagePropertiesFromContent (content, contentMarkdown),
141
156
'display_recipient' : [from, ...to]
142
157
.map ((u) => {'id' : u.userId, 'email' : u.email, 'full_name' : u.fullName})
143
158
.toList (growable: false ),
144
159
145
- 'content' : '<p>This is an example DM.</p>' ,
146
- 'content_type' : 'text/html' ,
147
160
'flags' : [],
148
161
'id' : 1234567 , // TODO generate example IDs
149
162
'subject' : '' ,
0 commit comments