Skip to content

feat: support BR adding user consents #573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Added

- Add support for BugReporting user consents. ([#573](https://github.com/Instabug/Instabug-Flutter/pull/573))

## [14.3.0](https://github.com/Instabug/Instabug-Flutter/compare/v14.1.0...14.3.0) (April 21, 2025)

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,26 @@ public void setCommentMinimumCharacterCount(@NonNull Long limit, @Nullable List<
}
BugReporting.setCommentMinimumCharacterCount(limit.intValue(), reportTypesArray);
}

@Override
public void addUserConsents(String key, String description, Boolean mandatory, Boolean checked, String actionType) {
ThreadManager.runOnMainThread(new Runnable() {
@Override
public void run() {
String mappedActionType;
try {
if (actionType==null) {
mappedActionType = null;
}
else {
mappedActionType = ArgsRegistry.userConsentActionType.get(actionType);
}

BugReporting.addUserConsent(key, description, mandatory, checked, mappedActionType);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public T get(Object key) {
put("Position.bottomRight", InstabugVideoRecordingButtonPosition.BOTTOM_RIGHT);
}};

public static final ArgsMap<String> userConsentActionType = new ArgsMap<String>() {{
put("UserConsentActionType.dropAutoCapturedMedia", com.instabug.bug.userConsent.ActionType.DROP_AUTO_CAPTURED_MEDIA);
put("UserConsentActionType.dropLogs", com.instabug.bug.userConsent.ActionType.DROP_LOGS);
put("UserConsentActionType.noChat", com.instabug.bug.userConsent.ActionType.NO_CHAT);
}};

public static ArgsMap<WelcomeMessage.State> welcomeMessageStates = new ArgsMap<WelcomeMessage.State>() {{
put("WelcomeMessageMode.live", WelcomeMessage.State.LIVE);
put("WelcomeMessageMode.beta", WelcomeMessage.State.BETA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.List;

import io.flutter.plugin.common.BinaryMessenger;

import com.instabug.bug.userConsent.ActionType;

public class BugReportingApiTest {
private final BinaryMessenger mMessenger = mock(BinaryMessenger.class);
Expand Down Expand Up @@ -194,4 +194,19 @@ public void testSetCommentMinimumCharacterCount() {

mBugReporting.verify(() -> BugReporting.setCommentMinimumCharacterCount(limit.intValue(), BugReporting.ReportType.BUG, BugReporting.ReportType.QUESTION));
}

@Test
public void TestAddUserConsents() {

final String key = "testKey";
final String description = "Consent description";
final boolean mandatory = true;
final boolean checked = true;
final String actionType = "UserConsentActionType.dropAutoCapturedMedia";


api.addUserConsents(key, description, mandatory, checked, actionType);

mBugReporting.verify(()->BugReporting.addUserConsent(key, description, mandatory, checked,"drop_auto_captured_media"));
}
}
23 changes: 22 additions & 1 deletion example/ios/InstabugTests/BugReportingApiTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,26 @@ - (void)testSetCommentMinimumCharacterCountGivenNoReportTypes {

OCMVerify([self.mBugReporting setCommentMinimumCharacterCountForReportTypes:IBGBugReportingReportTypeBug | IBGBugReportingReportTypeFeedback | IBGBugReportingReportTypeQuestion withLimit:limit.intValue]);
}

- (void)testAddUserConsentWithKey {
NSString *key = @"testKey";
NSString *description = @"Consent description";
NSNumber *mandatory = @1;
NSNumber *checked = @0;
NSString *actionType= @"UserConsentActionType.dropAutoCapturedMedia";
FlutterError *error;
IBGActionType mappedActionType = IBGActionTypeDropAutoCapturedMedia;

[self.api addUserConsentsKey:key
description:description
mandatory:mandatory
checked:checked
actionType:actionType
error: &error
];
OCMVerify([self.mBugReporting addUserConsentWithKey:key
description:description
mandatory:[mandatory boolValue]
checked:[checked boolValue]
actionType:mappedActionType]);
}
@end
17 changes: 17 additions & 0 deletions ios/Classes/Modules/BugReportingApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,21 @@ - (void)setCommentMinimumCharacterCountLimit:(NSNumber *)limit reportTypes:(null
[IBGBugReporting setCommentMinimumCharacterCountForReportTypes:resolvedTypes withLimit:limit.intValue];
}

- (void)addUserConsentsKey:(NSString *)key
description:(NSString *)description
mandatory:(NSNumber *)mandatory
checked:(NSNumber *)checked
actionType:(nullable NSString *)actionType
error:(FlutterError *_Nullable *_Nonnull)error {

IBGActionType mappedActionType = (ArgsRegistry.userConsentActionTypes[actionType]).integerValue;

[IBGBugReporting addUserConsentWithKey:key
description:description
mandatory:[mandatory boolValue]
checked:[checked boolValue]
actionType:mappedActionType];
}


@end
1 change: 1 addition & 0 deletions ios/Classes/Util/ArgsRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ typedef NSDictionary<NSString *, NSNumber *> ArgsDictionary;

+ (ArgsDictionary *)locales;
+ (NSDictionary<NSString *, NSString *> *)placeholders;
+ (ArgsDictionary *) userConsentActionTypes;

@end
8 changes: 7 additions & 1 deletion ios/Classes/Util/ArgsRegistry.m
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,11 @@ + (ArgsDictionary *)locales {
@"CustomTextPlaceHolderKey.insufficientContentMessage" : kIBGInsufficientContentMessageStringName,
};
}

+ (ArgsDictionary *) userConsentActionTypes {
return @{
@"UserConsentActionType.dropAutoCapturedMedia": @(IBGActionTypeDropAutoCapturedMedia),
@"UserConsentActionType.dropLogs": @(IBGActionTypeDropLogs),
@"UserConsentActionType.noChat": @(IBGActionTypeNoChat)
};
}
@end
28 changes: 28 additions & 0 deletions lib/src/modules/bug_reporting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ enum InvocationOption {
emailFieldOptional
}

enum UserConsentActionType {
dropAutoCapturedMedia,
dropLogs,
noChat,
}

enum DismissType { cancel, submit, addAttachment }

enum ReportType { bug, feedback, question, other }
Expand Down Expand Up @@ -255,4 +261,26 @@ class BugReporting implements BugReportingFlutterApi {
reportTypes?.mapToString(),
);
}

/// Adds a user consent item to the bug reporting form.
/// [key] A unique identifier string for the consent item.
/// [description] The text shown to the user describing the consent item.
/// [mandatory] Whether the user must agree to this item before submitting a report.
/// [checked] Whether the consent checkbox is pre-selected.
/// [actionType] A string representing the action type to map to SDK behavior.
static Future<void> addUserConsents({
required String key,
required String description,
required bool mandatory,
required bool checked,
UserConsentActionType? actionType,
}) async {
return _host.addUserConsents(
key,
description,
mandatory,
checked,
actionType?.toString(),
);
}
}
7 changes: 7 additions & 0 deletions pigeons/bug_reporting.api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ abstract class BugReportingHostApi {
int limit,
List<String>? reportTypes,
);
void addUserConsents(
String key,
String description,
bool mandatory,
bool checked,
String? actionType,
);
}