@@ -194,11 +194,33 @@ class GleanPlumbMessageManager: GleanPlumbMessageManagerProtocol {
194194 func onMessagePressed( _ message: GleanPlumbMessage , window: WindowUUID ? , shouldExpire: Bool = true ) {
195195 messagingStore. onMessagePressed ( message, shouldExpire: shouldExpire)
196196
197- guard let helper = createMessagingHelper. createNimbusMessagingHelper ( ) else { return }
197+ var extras = baseTelemetryExtras ( using: message)
198+ if let action = message. action {
199+ if let uuid = handleLinkAction ( for: message, action: action, window: window) {
200+ extras [ MessagingKey . actionUUID. rawValue] = uuid
201+ }
202+ }
203+
204+ TelemetryWrapper . recordEvent ( category: . action,
205+ method: . tap,
206+ object: . messaging,
207+ value: . messageInteracted,
208+ extras: extras)
209+ }
198210
199- guard let ( uuid, urlToOpen) = try ? self . generateUuidAndFormatAction ( for: message, with: helper) else {
211+ private func handleLinkAction(
212+ for message: GleanPlumbMessage ,
213+ action: String ,
214+ window: WindowUUID ?
215+ ) -> String ? {
216+ guard let helper = createMessagingHelper. createNimbusMessagingHelper ( ) else { return nil }
217+ guard let ( uuid, urlToOpen) = try ? self . generateUuidAndFormatAction (
218+ for: action,
219+ with: message. data. actionParams,
220+ with: helper
221+ ) else {
200222 self . onMalformedMessage ( id: message. id, surface: message. surface)
201- return
223+ return nil
202224 }
203225
204226 // With our well-formed URL, we can handle the action here.
@@ -207,25 +229,16 @@ class GleanPlumbMessageManager: GleanPlumbMessageManagerProtocol {
207229 } else {
208230 applicationHelper. open ( urlToOpen)
209231 }
210-
211- var extras = baseTelemetryExtras ( using: message)
212- if let uuid = uuid {
213- extras [ MessagingKey . actionUUID. rawValue] = uuid
214- }
215- TelemetryWrapper . recordEvent ( category: . action,
216- method: . tap,
217- object: . messaging,
218- value: . messageInteracted,
219- extras: extras)
232+ return uuid
220233 }
221234
222- private func generateUuidAndFormatAction( for message: GleanPlumbMessage ,
235+ private func generateUuidAndFormatAction( for action: String ,
236+ with actionParams: [ String : String ] ,
223237 with helper: NimbusMessagingHelperProtocol ) throws -> ( String ? , URL ) {
224238 // Make substitutions where they're needed.
225- let actionTemplate = message . action
239+ let actionTemplate = action
226240 var uuid = helper. getUuid ( template: actionTemplate)
227241 let action = helper. stringFormat ( template: actionTemplate, uuid: uuid)
228- let actionParams = message. data. actionParams
229242
230243 let urlString : String = action. hasPrefix ( " :// " ) ? deepLinkScheme + action : action
231244 guard var components = URLComponents ( string: urlString) else {
@@ -325,16 +338,19 @@ class GleanPlumbMessageManager: GleanPlumbMessageManagerProtocol {
325338 message: MessageData ,
326339 lookupTables: Messaging
327340 ) -> Result < GleanPlumbMessage , CreateMessageError > {
328- var action : String
341+ var action : String ?
329342 if !message. isControl {
330343 // Guard against a message with a blank `text` property.
331344 guard !message. text. isEmpty else { return . failure( . malformed) }
332345
333- // The message action should be either from the lookup table OR a URL.
334- guard let safeAction = sanitizeAction ( message. action, table: lookupTables. actions) else {
335- return . failure( . malformed)
346+ // Message action can be null. If not null,
347+ // the message action should be either from the lookup table OR a URL.
348+ if let messageAction = message. action {
349+ guard let safeAction = sanitizeAction ( messageAction, table: lookupTables. actions) else {
350+ return . failure( . malformed)
351+ }
352+ action = safeAction
336353 }
337- action = safeAction
338354 } else {
339355 action = " CONTROL_ACTION "
340356 }
0 commit comments