Repository: firebase/firebase-ios-sdk (language: cpp)

Issue:
InAppMessagingDisplayMessage shows incorrect type for imageOnly 
<!-- DO NOT DELETE
validate_template=true
template_path=.github/ISSUE_TEMPLATE/bug_report.md
-->
### [REQUIRED] Step 1: Describe your environment

  * Xcode version: 12.4
  * Firebase SDK version: 7.3.0
  * Installation method: `Carthage`
  * Firebase Component: InAppMessaging

### [REQUIRED] Step 2: Describe the problem

ImageOnly message shows incorrect message type. It may be a bug of parsing passing data.

#### Steps to reproduce:

1. add new message as `Image Only` message at Firebase Console
2. send test message
3. open app with following code

#### Relevant Code:

```swift
class Sample: InAppMessagingDisplay {
    func displayMessage(_ messageForDisplay: InAppMessagingDisplayMessage, displayDelegate: InAppMessagingDisplayDelegate) {
        switch messageForDisplay.type {
        case .banner, .card:
            break
        case .modal:
            print("When set `imageOnly` message at firebase console, message will be received with `modal` type")
        case .imageOnly:
            print("This line will be never called.")
        @unknown default:
            break
        }
    }
}

// at AppDelegate
InAppMessaging.inAppMessaging().messageDisplayComponent = Sample()
```



Discussion / hints:
I found a few problems with this issue:
  * I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  * This issue does not seem to follow the issue template. Make sure you provide all the required information.
There’s this issue indeed. I’ve faced it myself, and I think I’ll look into it.

@fumito-ito As a quick fix, you can determine message type by type-casting the `messageForDisplay` instance, like that:

```swift
switch messageForDisplay {
    case let bannerMessage as InAppMessagingBannerDisplay:
        print(bannerMessage)
    case let cardMessage as InAppMessagingCardDisplay:
        print(cardMessage)
    case let imageOnlyMessage as InAppMessagingImageOnlyDisplay:
        print(imageOnlyMessage)
    case let modalMessage as InAppMessagingModalDisplay:
        print(modalMessage)
    default:
        break
}
```

In fact, that’s the way message type is determined in the original implementation of IAM.
This is a one-liner fix that will go out with the next release.

Bug is [here](https://github.com/firebase/firebase-ios-sdk/blob/e789676eaee39adfeb0ddb19abb2b72bb03c93d8/FirebaseInAppMessaging/Sources/RenderingObjects/FIRInAppMessagingRenderingDataClasses.m#L272).
Thanks for the report @fumito-ito.

Fix patch:
diff --git a/FirebaseInAppMessaging/CHANGELOG.md b/FirebaseInAppMessaging/CHANGELOG.md
index dbbf760ca03..a7521cc397e 100644
--- a/FirebaseInAppMessaging/CHANGELOG.md
+++ b/FirebaseInAppMessaging/CHANGELOG.md
@@ -1,3 +1,6 @@
+# 2021-6 -- v.8.1.0
+- [fixed] Fixed bug where image-only messages had the wrong message type in message callbacks (#8081).
+
 # 2021-4 -- v.7.11.0
 - [fixed] Fixed SPM resource inclusion for in-app messages (#7715).
 
diff --git a/FirebaseInAppMessaging/Sources/RenderingObjects/FIRInAppMessagingRenderingDataClasses.m b/FirebaseInAppMessaging/Sources/RenderingObjects/FIRInAppMessagingRenderingDataClasses.m
index 5679a02bd6b..17bc66325e9 100644
--- a/FirebaseInAppMessaging/Sources/RenderingObjects/FIRInAppMessagingRenderingDataClasses.m
+++ b/FirebaseInAppMessaging/Sources/RenderingObjects/FIRInAppMessagingRenderingDataClasses.m
@@ -269,7 +269,7 @@ - (instancetype)initWithMessageID:(NSString *)messageID
                          campaignName:campaignName
                     experimentPayload:experimentPayload
                   renderAsTestMessage:renderAsTestMessage
-                          messageType:FIRInAppMessagingDisplayMessageTypeModal
+                          messageType:FIRInAppMessagingDisplayMessageTypeImageOnly
                           triggerType:triggerType
                               appData:appData]) {
     _imageData = imageData;
diff --git a/FirebaseInAppMessaging/Tests/Unit/FIRIAMDisplayExecutorTests.m b/FirebaseInAppMessaging/Tests/Unit/FIRIAMDisplayExecutorTests.m
index a118400debd..47d4c803b78 100644
--- a/FirebaseInAppMessaging/Tests/Unit/FIRIAMDisplayExecutorTests.m
+++ b/FirebaseInAppMessaging/Tests/Unit/FIRIAMDisplayExecutorTests.m
@@ -423,7 +423,7 @@ - (void)setupMessageTexture {
 
   FIRIAMRenderingEffectSetting *renderSetting6 =
       [FIRIAMRenderingEffectSetting getDefaultRenderingEffectSetting];
-  renderSetting6.viewMode = FIRIAMRenderAsBannerView;
+  renderSetting6.viewMode = FIRIAMRenderAsCardView;
 
   FIRIAMMessageRenderData *renderData6 =
       [[FIRIAMMessageRenderData alloc] initWithMessageID:@"m6"
@@ -1153,4 +1153,41 @@ - (void)testMessageWithExperimentPayload {
                               triggerType:FIRInAppMessagingDisplayTriggerTypeOnAppForeground];
   XCTAssertNotNil(displayMessage.campaignInfo.experimentPayload);
 }
+
+- (void)testMessageDisplayTypes {
+  FIRInAppMessagingImageData *imageData =
+      [[FIRInAppMessagingImageData alloc] initWithImageURL:@"https://www.google.com"
+                                                 imageData:[NSData data]];
+  FIRInAppMessagingDisplayTriggerType analyticsTriggerType =
+      FIRInAppMessagingDisplayTriggerTypeOnAnalyticsEvent;
+
+  FIRInAppMessagingDisplayMessage *bannerMessage =
+      [self.displayExecutor displayMessageWithMessageDefinition:self.m1
+                                                      imageData:imageData
+                                             landscapeImageData:nil
+                                                    triggerType:analyticsTriggerType];
+
+  FIRInAppMessagingDisplayMessage *imageOnlyMessage =
+      [self.displayExecutor displayMessageWithMessageDefinition:self.m3
+                                                      imageData:imageData
+                                             landscapeImageData:nil
+                                                    triggerType:analyticsTriggerType];
+
+  FIRInAppMessagingDisplayMessage *modalMessage =
+      [self.displayExecutor displayMessageWithMessageDefinition:self.m2
+                                                      imageData:imageData
+                                             landscapeImageData:nil
+                                                    triggerType:analyticsTriggerType];
+
+  FIRInAppMessagingDisplayMessage *cardMessage =
+      [self.displayExecutor displayMessageWithMessageDefinition:self.m6
+                                                      imageData:imageData
+                                             landscapeImageData:nil
+                                                    triggerType:analyticsTriggerType];
+
+  XCTAssertEqual(bannerMessage.type, FIRInAppMessagingDisplayMessageTypeBanner);
+  XCTAssertEqual(imageOnlyMessage.type, FIRInAppMessagingDisplayMessageTypeImageOnly);
+  XCTAssertEqual(modalMessage.type, FIRInAppMessagingDisplayMessageTypeModal);
+  XCTAssertEqual(cardMessage.type, FIRInAppMessagingDisplayMessageTypeCard);
+}
 @end


Test patch: