@@ -120,17 +120,27 @@ public class NotificationActionHandler {
120
120
private class func reply( userInfo: [ AnyHashable : Any ] , replyText: String ) throws -> Promise < Void > {
121
121
return firstly { ( ) -> Promise < NotificationMessage > in
122
122
self . notificationMessage ( forUserInfo: userInfo)
123
- } . then ( on: DispatchQueue . global ( ) ) { ( notificationMessage: NotificationMessage ) -> Promise < ( DraftQuotedReplyModel ? , NotificationMessage ) > in
124
- return getDraftQuotedReplyModelTupleFromIncomingMessage ( notificationMessage: notificationMessage)
125
- } . then ( on: DispatchQueue . global ( ) ) { ( informationTuple: ( draft: DraftQuotedReplyModel ? , notificationMessage: NotificationMessage ) ) -> Promise < ( DraftQuotedReplyModel . ForSending ? , NotificationMessage ) > in
126
- return getDraftQuotedReplyModelForSendingTupleFromDraftAndIncomingMessage ( optionalDraftModel: informationTuple. draft, notificationMessage: informationTuple. notificationMessage)
127
- } . then ( on: DispatchQueue . global ( ) ) { ( informationTuple: ( draft: DraftQuotedReplyModel . ForSending ? , notificationMessage: NotificationMessage ) ) -> Promise < Void > in
128
- let thread = informationTuple. notificationMessage. thread
129
- let interaction = informationTuple. notificationMessage. interaction
123
+ } . then ( on: DispatchQueue . global ( ) ) { ( notificationMessage: NotificationMessage ) -> Promise < Void > in
124
+ let thread = notificationMessage. thread
125
+ let interaction = notificationMessage. interaction
126
+ var draftModelForSending : DraftQuotedReplyModel . ForSending ?
130
127
guard ( interaction is TSOutgoingMessage ) || ( interaction is TSIncomingMessage ) else {
131
128
throw OWSAssertionError ( " Unexpected interaction type. " )
132
129
}
133
-
130
+
131
+ let optionalDraftModel : DraftQuotedReplyModel ? = SSKEnvironment . shared. databaseStorageRef. read { transaction in
132
+ if
133
+ let incomingMessage = notificationMessage. interaction as? TSIncomingMessage ,
134
+ let draftQuotedReplyModel = DependenciesBridge . shared. quotedReplyManager. buildDraftQuotedReply ( originalMessage: incomingMessage, tx: transaction. asV2Read) {
135
+ return draftQuotedReplyModel
136
+ }
137
+ return nil
138
+ }
139
+
140
+ if let draftModel = optionalDraftModel {
141
+ draftModelForSending = try ? DependenciesBridge . shared. quotedReplyManager. prepareDraftForSending ( draftModel)
142
+ }
143
+
134
144
return firstly ( on: DispatchQueue . global ( ) ) { ( ) -> Promise < Void > in
135
145
SSKEnvironment . shared. databaseStorageRef. write { transaction in
136
146
let builder : TSOutgoingMessageBuilder = . withDefaultValues( thread: thread)
@@ -139,7 +149,7 @@ public class NotificationActionHandler {
139
149
// If we're replying to a group story reply, keep the reply within that context.
140
150
if
141
151
let incomingMessage = interaction as? TSIncomingMessage ,
142
- informationTuple . notificationMessage. isGroupStoryReply,
152
+ notificationMessage. isGroupStoryReply,
143
153
let storyTimestamp = incomingMessage. storyTimestamp,
144
154
let storyAuthorAci = incomingMessage. storyAuthorAci
145
155
{
@@ -160,7 +170,7 @@ public class NotificationActionHandler {
160
170
explicitRecipients: [ ] ,
161
171
skippedRecipients: [ ] ,
162
172
transaction: transaction
163
- ) , quotedReplyDraft: informationTuple . draft )
173
+ ) , quotedReplyDraft: draftModelForSending )
164
174
do {
165
175
let preparedMessage = try unpreparedMessage. prepare ( tx: transaction)
166
176
return ThreadUtil . enqueueMessagePromise ( message: preparedMessage, transaction: transaction)
@@ -173,78 +183,11 @@ public class NotificationActionHandler {
173
183
SSKEnvironment . shared. notificationPresenterRef. notifyUserOfFailedSend ( inThread: thread)
174
184
throw error
175
185
} . then ( on: DispatchQueue . global ( ) ) { ( ) -> Promise < Void > in
176
- self . markMessageAsRead ( notificationMessage: informationTuple. notificationMessage)
177
- }
178
- }
179
- }
180
-
181
- private class func getDraftQuotedReplyModelTupleFromIncomingMessage( notificationMessage: NotificationMessage ) -> Promise < ( DraftQuotedReplyModel ? , NotificationMessage ) > {
182
- let ( promise, future) = Promise< ( DraftQuotedReplyModel? , NotificationMessage) > . pending( )
183
- SSKEnvironment . shared. databaseStorageRef. read { readTransaction in
184
- if
185
- let incomingMessage = notificationMessage. interaction as? TSIncomingMessage ,
186
- let draftQuotedReplyModel = DependenciesBridge . shared. quotedReplyManager. buildDraftQuotedReply ( originalMessage: incomingMessage, tx: readTransaction. asV2Read) {
187
- future. resolve ( ( draftQuotedReplyModel, notificationMessage) )
188
- }
189
- return future. resolve ( ( nil , notificationMessage) )
190
- }
191
- return promise
192
- }
193
-
194
- private class func getDraftQuotedReplyModelForSendingTupleFromDraftAndIncomingMessage( optionalDraftModel: DraftQuotedReplyModel ? , notificationMessage: NotificationMessage ) -> Promise < ( DraftQuotedReplyModel . ForSending ? , NotificationMessage ) > {
195
- guard let draftModel = optionalDraftModel else {
196
- return Promise . value ( ( nil , notificationMessage) )
197
- }
198
-
199
- do {
200
- let draftForSending = try DependenciesBridge . shared. quotedReplyManager. prepareDraftForSending ( draftModel)
201
- return Promise . value ( ( draftForSending, notificationMessage) )
202
- } catch {
203
- return Promise . value ( ( nil , notificationMessage) )
204
- }
205
- }
206
-
207
- private class func sendReplyToNoficationMessageWithMessageToReplyTo( replyText: String , messageBeingRespondedTo: DraftQuotedReplyModel . ForSending ? , notificationMessage: NotificationMessage ) throws -> Promise < Void > {
208
- return SSKEnvironment . shared. databaseStorageRef. write { transaction in
209
- let builder : TSOutgoingMessageBuilder = . withDefaultValues( thread: notificationMessage. thread)
210
- builder. messageBody = replyText
211
-
212
- // If we're replying to a group story reply, keep the reply within that context.
213
- if
214
- let incomingMessage = notificationMessage. interaction as? TSIncomingMessage ,
215
- notificationMessage. isGroupStoryReply,
216
- let storyTimestamp = incomingMessage. storyTimestamp,
217
- let storyAuthorAci = incomingMessage. storyAuthorAci
218
- {
219
- builder. storyTimestamp = storyTimestamp
220
- builder. storyAuthorAci = storyAuthorAci
221
- } else {
222
- // We only use the thread's DM timer for normal messages & 1:1 story
223
- // replies -- group story replies last for the lifetime of the story.
224
- let dmConfigurationStore = DependenciesBridge . shared. disappearingMessagesConfigurationStore
225
- let dmConfig = dmConfigurationStore. fetchOrBuildDefault ( for: . thread( notificationMessage. thread) , tx: transaction. asV2Read)
226
- builder. expiresInSeconds = dmConfig. durationSeconds
227
- builder. expireTimerVersion = NSNumber ( value: dmConfig. timerVersion)
228
- }
229
-
230
- let outgoingMessage = TSOutgoingMessage (
231
- outgoingMessageWith: builder,
232
- additionalRecipients: [ ] ,
233
- explicitRecipients: [ ] ,
234
- skippedRecipients: [ ] ,
235
- transaction: transaction
236
- )
237
-
238
- let unpreparedMessage = UnpreparedOutgoingMessage . forMessage ( outgoingMessage, quotedReplyDraft: messageBeingRespondedTo)
239
- do {
240
- let preparedMessage = try unpreparedMessage. prepare ( tx: transaction)
241
- return ThreadUtil . enqueueMessagePromise ( message: preparedMessage, transaction: transaction)
242
- } catch {
243
- return Promise ( error: error)
186
+ self . markMessageAsRead ( notificationMessage: notificationMessage)
244
187
}
245
188
}
246
189
}
247
-
190
+
248
191
private class func showThread( userInfo: [ AnyHashable : Any ] ) throws -> Promise < Void > {
249
192
return firstly { ( ) -> Promise < NotificationMessage > in
250
193
self . notificationMessage ( forUserInfo: userInfo)
0 commit comments