diff --git a/Sources/Sentry/SentryKSCrashReportConverter.m b/Sources/Sentry/SentryKSCrashReportConverter.m index d682b5f7653..3ef9a44793a 100644 --- a/Sources/Sentry/SentryKSCrashReportConverter.m +++ b/Sources/Sentry/SentryKSCrashReportConverter.m @@ -107,7 +107,8 @@ - (SentryEvent *)convertReportToEvent { - (SentryUser *_Nullable)convertUser { SentryUser *user = nil; if (nil != self.userContext[@"user"]) { - user = [[SentryUser alloc] initWithUserId:self.userContext[@"user"][@"id"]]; + user = [[SentryUser alloc] init]; + user.userId = self.userContext[@"user"][@"id"]; user.email = self.userContext[@"user"][@"email"]; user.username = self.userContext[@"user"][@"username"]; user.extra = self.userContext[@"user"][@"extra"]; diff --git a/Sources/Sentry/SentryUser.m b/Sources/Sentry/SentryUser.m index ff087de922a..2ac5a070e68 100644 --- a/Sources/Sentry/SentryUser.m +++ b/Sources/Sentry/SentryUser.m @@ -20,19 +20,14 @@ @implementation SentryUser -- (instancetype)initWithUserId:(NSString *)userId { - self = [super init]; - if (self) { - self.userId = userId; - } - return self; +- (instancetype)init { + return [super init]; } - (NSDictionary *)serialize { - NSMutableDictionary *serializedData = @{ - @"id": self.userId - }.mutableCopy; + NSMutableDictionary *serializedData = [[NSMutableDictionary alloc] init]; + [serializedData setValue:self.userId forKey:@"id"]; [serializedData setValue:self.email forKey:@"email"]; [serializedData setValue:self.username forKey:@"username"]; [serializedData setValue:[self.extra sentry_sanitize] forKey:@"extra"]; diff --git a/Sources/Sentry/include/SentryUser.h b/Sources/Sentry/include/SentryUser.h index d032fdbf685..e789e3e66b6 100644 --- a/Sources/Sentry/include/SentryUser.h +++ b/Sources/Sentry/include/SentryUser.h @@ -20,10 +20,9 @@ NS_ASSUME_NONNULL_BEGIN NS_SWIFT_NAME(User) @interface SentryUser : NSObject -SENTRY_NO_INIT /** - * Id of the user + * Optional: Id of the user */ @property(nonatomic, copy) NSString *userId; @@ -42,12 +41,8 @@ SENTRY_NO_INIT */ @property(nonatomic, strong) NSDictionary *_Nullable extra; -/** - * Initializes a SentryUser with the id - * @param userId NSString - * @return SentryUser - */ -- (instancetype)initWithUserId:(NSString *)userId; +- (instancetype)init; ++ (instancetype)new NS_UNAVAILABLE; @end diff --git a/Tests/SentryTests/SentryInterfacesTests.m b/Tests/SentryTests/SentryInterfacesTests.m index 8102c81de50..63b26cf1cb7 100644 --- a/Tests/SentryTests/SentryInterfacesTests.m +++ b/Tests/SentryTests/SentryInterfacesTests.m @@ -176,12 +176,14 @@ - (void)testThread { } - (void)testUser { - SentryUser *user = [[SentryUser alloc] initWithUserId:@"1"]; + SentryUser *user = [[SentryUser alloc] init]; + user.userId = @"1"; XCTAssertNotNil(user.userId); NSDictionary *serialized = @{@"id": @"1"}; XCTAssertEqualObjects([user serialize], serialized); - SentryUser *user2 = [[SentryUser alloc] initWithUserId:@"1"]; + SentryUser *user2 = [[SentryUser alloc] init]; + user2.userId = @"1"; XCTAssertNotNil(user2.userId); user2.email = @"a@b.com"; user2.username = @"tony"; diff --git a/Tests/SentryTests/SentryRequestTests.m b/Tests/SentryTests/SentryRequestTests.m index 327282d2b5b..77d681dbea3 100644 --- a/Tests/SentryTests/SentryRequestTests.m +++ b/Tests/SentryTests/SentryRequestTests.m @@ -398,7 +398,9 @@ - (void)testRequestQueueMultipleEvents { - (void)testUseClientProperties { self.client.tags = @{@"a": @"b"}; self.client.extra = @{@"c": @"d"}; - self.client.user = [[SentryUser alloc] initWithUserId:@"XXXXXX"]; + SentryUser *user = [[SentryUser alloc] init]; + user.userId = @"XXXXXX"; + self.client.user = user; NSDate *date = [NSDate date]; SentryBreadcrumb *crumb = [[SentryBreadcrumb alloc] initWithLevel:kSentrySeverityInfo category:@"you"]; crumb.timestamp = date; diff --git a/Tests/SentryTests/SentrySwiftTests.swift b/Tests/SentryTests/SentrySwiftTests.swift index dbdc9eda353..8e2f0db23bf 100644 --- a/Tests/SentryTests/SentrySwiftTests.swift +++ b/Tests/SentryTests/SentrySwiftTests.swift @@ -74,7 +74,8 @@ class SentrySwiftTests: XCTestCase { Client.shared?.breadcrumbs.add(Breadcrumb(level: .info, category: "test")) XCTAssertEqual(Client.shared?.breadcrumbs.count(), 1) Client.shared?.enableAutomaticBreadcrumbTracking() - let user = User(userId: "1234") + let user = User() + user.userId = "1234" user.email = "hello@sentry.io" user.extra = ["is_admin": true] Client.shared?.user = user