@@ -262,6 +262,7 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
262
262
}
263
263
}
264
264
265
+ @Suppress(" ComplexMethod" )
265
266
private fun setUser (user : Map <String , Any ?>? , result : Result ) {
266
267
if (user == null ) {
267
268
Sentry .setUser(null )
@@ -270,30 +271,44 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
270
271
}
271
272
272
273
val userInstance = User ()
274
+ val userData = mutableMapOf<String , String >()
275
+ val unknown = mutableMapOf<String , Any >()
273
276
274
277
(user[" email" ] as ? String )?.let { userInstance.email = it }
275
278
(user[" id" ] as ? String )?.let { userInstance.id = it }
276
279
(user[" username" ] as ? String )?.let { userInstance.username = it }
277
280
(user[" ip_address" ] as ? String )?.let { userInstance.ipAddress = it }
278
281
(user[" segment" ] as ? String )?.let { userInstance.segment = it }
282
+
283
+ // Not mapped on Android yet, added to the unknown databag that gets serialized correctly anyway
284
+ // Should be solved by https://github.com/getsentry/team-mobile/issues/59
285
+ // or https://github.com/getsentry/team-mobile/issues/56
286
+ (user[" name" ] as ? String )?.let { unknown[" name" ] = it }
287
+ (user[" geo" ] as ? Map <String , Any ?>)?.let { unknown[" geo" ] = it }
288
+
279
289
(user[" extras" ] as ? Map <String , Any ?>)?.let { extras ->
280
- val others = mutableMapOf<String , String >()
281
290
for ((key, value) in extras.entries) {
282
291
if (value != null ) {
283
- others [key] = value.toString()
292
+ userData [key] = value.toString()
284
293
}
285
294
}
286
- userInstance.others = others
287
295
}
288
296
(user[" data" ] as ? Map <String , Any ?>)?.let { data ->
289
- val others = mutableMapOf<String , String >()
290
297
for ((key, value) in data.entries) {
291
298
if (value != null ) {
292
- others[key] = value.toString()
299
+ // data has precedence over extras
300
+ userData[key] = value.toString()
293
301
}
294
302
}
295
303
}
296
304
305
+ if (userData.isNotEmpty()) {
306
+ userInstance.data = userData
307
+ }
308
+ if (unknown.isNotEmpty()) {
309
+ userInstance.unknown = unknown
310
+ }
311
+
297
312
Sentry .setUser(userInstance)
298
313
299
314
result.success(" " )
0 commit comments