@@ -128,59 +128,83 @@ protected function buildMailBody(
128
128
PhabricatorLiskDAO $ object ,
129
129
array $ xactions ) {
130
130
131
- $ body = new PhabricatorMetaMTAMailBody ();
132
- $ headers = array ();
133
- $ comments = array ();
134
- $ inline_comments = array ();
131
+ $ viewer = $ this ->requireActor ();
135
132
136
- foreach ($ xactions as $ xaction ) {
137
- if ($ xaction ->shouldHide ()) {
138
- continue ;
139
- }
140
- $ comment = $ xaction ->getComment ();
141
- switch ($ xaction ->getTransactionType ()) {
142
- case PholioMockInlineTransaction::TRANSACTIONTYPE :
143
- if ($ comment && strlen ($ comment ->getContent ())) {
144
- $ inline_comments [] = $ comment ;
145
- }
146
- break ;
147
- case PhabricatorTransactions::TYPE_COMMENT :
148
- if ($ comment && strlen ($ comment ->getContent ())) {
149
- $ comments [] = $ comment ->getContent ();
150
- }
151
- // fallthrough
152
- default :
153
- $ headers [] = id (clone $ xaction )
154
- ->setRenderingTarget ('text ' )
155
- ->getTitle ();
156
- break ;
157
- }
158
- }
133
+ $ body = id (new PhabricatorMetaMTAMailBody ())
134
+ ->setViewer ($ viewer );
159
135
160
- $ body ->addRawSection (implode ("\n" , $ headers ));
136
+ $ mock_uri = $ object ->getURI ();
137
+ $ mock_uri = PhabricatorEnv::getProductionURI ($ mock_uri );
161
138
162
- foreach ($ comments as $ comment ) {
163
- $ body ->addRawSection ($ comment );
164
- }
139
+ $ this ->addHeadersAndCommentsToMailBody (
140
+ $ body ,
141
+ $ xactions ,
142
+ pht ('View Mock ' ),
143
+ $ mock_uri );
165
144
166
- if ($ inline_comments ) {
167
- $ body ->addRawSection (pht ('INLINE COMMENTS ' ));
168
- foreach ($ inline_comments as $ comment ) {
169
- $ text = pht (
170
- 'Image %d: %s ' ,
171
- $ comment ->getImageID (),
172
- $ comment ->getContent ());
173
- $ body ->addRawSection ($ text );
145
+ $ type_inline = PholioMockInlineTransaction::TRANSACTIONTYPE ;
146
+
147
+ $ inlines = array ();
148
+ foreach ($ xactions as $ xaction ) {
149
+ if ($ xaction ->getTransactionType () == $ type_inline ) {
150
+ $ inlines [] = $ xaction ;
174
151
}
175
152
}
176
153
154
+ $ this ->appendInlineCommentsForMail ($ object , $ inlines , $ body );
155
+
177
156
$ body ->addLinkSection (
178
157
pht ('MOCK DETAIL ' ),
179
158
PhabricatorEnv::getProductionURI ('/M ' .$ object ->getID ()));
180
159
181
160
return $ body ;
182
161
}
183
162
163
+ private function appendInlineCommentsForMail (
164
+ $ object ,
165
+ array $ inlines ,
166
+ PhabricatorMetaMTAMailBody $ body ) {
167
+
168
+ if (!$ inlines ) {
169
+ return ;
170
+ }
171
+
172
+ $ viewer = $ this ->requireActor ();
173
+
174
+ $ header = pht ('INLINE COMMENTS ' );
175
+ $ body ->addRawPlaintextSection ($ header );
176
+ $ body ->addRawHTMLSection (phutil_tag ('strong ' , array (), $ header ));
177
+
178
+ $ image_ids = array ();
179
+ foreach ($ inlines as $ inline ) {
180
+ $ comment = $ inline ->getComment ();
181
+ $ image_id = $ comment ->getImageID ();
182
+ $ image_ids [$ image_id ] = $ image_id ;
183
+ }
184
+
185
+ $ images = id (new PholioImageQuery ())
186
+ ->setViewer ($ viewer )
187
+ ->withIDs ($ image_ids )
188
+ ->execute ();
189
+ $ images = mpull ($ images , null , 'getID ' );
190
+
191
+ foreach ($ inlines as $ inline ) {
192
+ $ comment = $ inline ->getComment ();
193
+ $ content = $ comment ->getContent ();
194
+ $ image_id = $ comment ->getImageID ();
195
+ $ image = idx ($ images , $ image_id );
196
+ if ($ image ) {
197
+ $ image_name = $ image ->getName ();
198
+ } else {
199
+ $ image_name = pht ('Unknown (ID %d) ' , $ image_id );
200
+ }
201
+
202
+ $ body ->addRemarkupSection (
203
+ pht ('Image "%s": ' , $ image_name ),
204
+ $ content );
205
+ }
206
+ }
207
+
184
208
protected function getMailSubjectPrefix () {
185
209
return PhabricatorEnv::getEnvConfig ('metamta.pholio.subject-prefix ' );
186
210
}
0 commit comments