Skip to content

Commit afb33df

Browse files
feat: support BR adding user consents (#573)
* feat: support BR adding user consents * feat: add change log * fix: android test * fix: use named parameters * fix: ios tests
1 parent fb344fd commit afb33df

File tree

10 files changed

+132
-3
lines changed

10 files changed

+132
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
### Added
6+
7+
- Add support for BugReporting user consents. ([#573](https://github.com/Instabug/Instabug-Flutter/pull/573))
8+
39
## [14.3.0](https://github.com/Instabug/Instabug-Flutter/compare/v14.1.0...14.3.0) (April 21, 2025)
410

511
### Added

android/src/main/java/com/instabug/flutter/modules/BugReportingApi.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,26 @@ public void setCommentMinimumCharacterCount(@NonNull Long limit, @Nullable List<
186186
}
187187
BugReporting.setCommentMinimumCharacterCount(limit.intValue(), reportTypesArray);
188188
}
189+
190+
@Override
191+
public void addUserConsents(String key, String description, Boolean mandatory, Boolean checked, String actionType) {
192+
ThreadManager.runOnMainThread(new Runnable() {
193+
@Override
194+
public void run() {
195+
String mappedActionType;
196+
try {
197+
if (actionType==null) {
198+
mappedActionType = null;
199+
}
200+
else {
201+
mappedActionType = ArgsRegistry.userConsentActionType.get(actionType);
202+
}
203+
204+
BugReporting.addUserConsent(key, description, mandatory, checked, mappedActionType);
205+
} catch (Exception e) {
206+
e.printStackTrace();
207+
}
208+
}
209+
});
210+
}
189211
}

android/src/main/java/com/instabug/flutter/util/ArgsRegistry.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ public T get(Object key) {
7575
put("Position.bottomRight", InstabugVideoRecordingButtonPosition.BOTTOM_RIGHT);
7676
}};
7777

78+
public static final ArgsMap<String> userConsentActionType = new ArgsMap<String>() {{
79+
put("UserConsentActionType.dropAutoCapturedMedia", com.instabug.bug.userConsent.ActionType.DROP_AUTO_CAPTURED_MEDIA);
80+
put("UserConsentActionType.dropLogs", com.instabug.bug.userConsent.ActionType.DROP_LOGS);
81+
put("UserConsentActionType.noChat", com.instabug.bug.userConsent.ActionType.NO_CHAT);
82+
}};
83+
7884
public static ArgsMap<WelcomeMessage.State> welcomeMessageStates = new ArgsMap<WelcomeMessage.State>() {{
7985
put("WelcomeMessageMode.live", WelcomeMessage.State.LIVE);
8086
put("WelcomeMessageMode.beta", WelcomeMessage.State.BETA);

android/src/test/java/com/instabug/flutter/BugReportingApiTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.util.List;
2828

2929
import io.flutter.plugin.common.BinaryMessenger;
30-
30+
import com.instabug.bug.userConsent.ActionType;
3131

3232
public class BugReportingApiTest {
3333
private final BinaryMessenger mMessenger = mock(BinaryMessenger.class);
@@ -194,4 +194,19 @@ public void testSetCommentMinimumCharacterCount() {
194194

195195
mBugReporting.verify(() -> BugReporting.setCommentMinimumCharacterCount(limit.intValue(), BugReporting.ReportType.BUG, BugReporting.ReportType.QUESTION));
196196
}
197+
198+
@Test
199+
public void TestAddUserConsents() {
200+
201+
final String key = "testKey";
202+
final String description = "Consent description";
203+
final boolean mandatory = true;
204+
final boolean checked = true;
205+
final String actionType = "UserConsentActionType.dropAutoCapturedMedia";
206+
207+
208+
api.addUserConsents(key, description, mandatory, checked, actionType);
209+
210+
mBugReporting.verify(()->BugReporting.addUserConsent(key, description, mandatory, checked,"drop_auto_captured_media"));
211+
}
197212
}

example/ios/InstabugTests/BugReportingApiTests.m

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,26 @@ - (void)testSetCommentMinimumCharacterCountGivenNoReportTypes {
174174

175175
OCMVerify([self.mBugReporting setCommentMinimumCharacterCountForReportTypes:IBGBugReportingReportTypeBug | IBGBugReportingReportTypeFeedback | IBGBugReportingReportTypeQuestion withLimit:limit.intValue]);
176176
}
177-
177+
- (void)testAddUserConsentWithKey {
178+
NSString *key = @"testKey";
179+
NSString *description = @"Consent description";
180+
NSNumber *mandatory = @1;
181+
NSNumber *checked = @0;
182+
NSString *actionType= @"UserConsentActionType.dropAutoCapturedMedia";
183+
FlutterError *error;
184+
IBGActionType mappedActionType = IBGActionTypeDropAutoCapturedMedia;
185+
186+
[self.api addUserConsentsKey:key
187+
description:description
188+
mandatory:mandatory
189+
checked:checked
190+
actionType:actionType
191+
error: &error
192+
];
193+
OCMVerify([self.mBugReporting addUserConsentWithKey:key
194+
description:description
195+
mandatory:[mandatory boolValue]
196+
checked:[checked boolValue]
197+
actionType:mappedActionType]);
198+
}
178199
@end

ios/Classes/Modules/BugReportingApi.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,21 @@ - (void)setCommentMinimumCharacterCountLimit:(NSNumber *)limit reportTypes:(null
165165
[IBGBugReporting setCommentMinimumCharacterCountForReportTypes:resolvedTypes withLimit:limit.intValue];
166166
}
167167

168+
- (void)addUserConsentsKey:(NSString *)key
169+
description:(NSString *)description
170+
mandatory:(NSNumber *)mandatory
171+
checked:(NSNumber *)checked
172+
actionType:(nullable NSString *)actionType
173+
error:(FlutterError *_Nullable *_Nonnull)error {
174+
175+
IBGActionType mappedActionType = (ArgsRegistry.userConsentActionTypes[actionType]).integerValue;
176+
177+
[IBGBugReporting addUserConsentWithKey:key
178+
description:description
179+
mandatory:[mandatory boolValue]
180+
checked:[checked boolValue]
181+
actionType:mappedActionType];
182+
}
183+
184+
168185
@end

ios/Classes/Util/ArgsRegistry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ typedef NSDictionary<NSString *, NSNumber *> ArgsDictionary;
2121

2222
+ (ArgsDictionary *)locales;
2323
+ (NSDictionary<NSString *, NSString *> *)placeholders;
24+
+ (ArgsDictionary *) userConsentActionTypes;
2425

2526
@end

ios/Classes/Util/ArgsRegistry.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,11 @@ + (ArgsDictionary *)locales {
211211
@"CustomTextPlaceHolderKey.insufficientContentMessage" : kIBGInsufficientContentMessageStringName,
212212
};
213213
}
214-
214+
+ (ArgsDictionary *) userConsentActionTypes {
215+
return @{
216+
@"UserConsentActionType.dropAutoCapturedMedia": @(IBGActionTypeDropAutoCapturedMedia),
217+
@"UserConsentActionType.dropLogs": @(IBGActionTypeDropLogs),
218+
@"UserConsentActionType.noChat": @(IBGActionTypeNoChat)
219+
};
220+
}
215221
@end

lib/src/modules/bug_reporting.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ enum InvocationOption {
1515
emailFieldOptional
1616
}
1717

18+
enum UserConsentActionType {
19+
dropAutoCapturedMedia,
20+
dropLogs,
21+
noChat,
22+
}
23+
1824
enum DismissType { cancel, submit, addAttachment }
1925

2026
enum ReportType { bug, feedback, question, other }
@@ -255,4 +261,26 @@ class BugReporting implements BugReportingFlutterApi {
255261
reportTypes?.mapToString(),
256262
);
257263
}
264+
265+
/// Adds a user consent item to the bug reporting form.
266+
/// [key] A unique identifier string for the consent item.
267+
/// [description] The text shown to the user describing the consent item.
268+
/// [mandatory] Whether the user must agree to this item before submitting a report.
269+
/// [checked] Whether the consent checkbox is pre-selected.
270+
/// [actionType] A string representing the action type to map to SDK behavior.
271+
static Future<void> addUserConsents({
272+
required String key,
273+
required String description,
274+
required bool mandatory,
275+
required bool checked,
276+
UserConsentActionType? actionType,
277+
}) async {
278+
return _host.addUserConsents(
279+
key,
280+
description,
281+
mandatory,
282+
checked,
283+
actionType?.toString(),
284+
);
285+
}
258286
}

pigeons/bug_reporting.api.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,11 @@ abstract class BugReportingHostApi {
3232
int limit,
3333
List<String>? reportTypes,
3434
);
35+
void addUserConsents(
36+
String key,
37+
String description,
38+
bool mandatory,
39+
bool checked,
40+
String? actionType,
41+
);
3542
}

0 commit comments

Comments
 (0)