Skip to content
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

Expose user agent information on MXDevice #1583

Merged
merged 2 commits into from
Sep 27, 2022
Merged
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
12 changes: 12 additions & 0 deletions MatrixSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,10 @@
EC60EE09265CFFF400B39A4E /* MXGroupSyncProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = EC60EE05265CFFF400B39A4E /* MXGroupSyncProfile.m */; };
EC619D9224DD834B00663A80 /* MXPushGatewayRestClient.m in Sources */ = {isa = PBXBuildFile; fileRef = EC619D9024DD834B00663A80 /* MXPushGatewayRestClient.m */; };
EC619D9324DD834B00663A80 /* MXPushGatewayRestClient.h in Headers */ = {isa = PBXBuildFile; fileRef = EC619D9124DD834B00663A80 /* MXPushGatewayRestClient.h */; settings = {ATTRIBUTES = (Public, ); }; };
EC6D007928E1F15400152144 /* MXDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = EC6D007728E1F15400152144 /* MXDevice.h */; settings = {ATTRIBUTES = (Public, ); }; };
EC6D007A28E1F15400152144 /* MXDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = EC6D007728E1F15400152144 /* MXDevice.h */; settings = {ATTRIBUTES = (Public, ); }; };
EC6D007B28E1F15400152144 /* MXDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = EC6D007828E1F15400152144 /* MXDevice.m */; };
EC6D007C28E1F15400152144 /* MXDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = EC6D007828E1F15400152144 /* MXDevice.m */; };
EC746C56274E5197002AD24C /* MXThreadingServiceUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC746C55274E5197002AD24C /* MXThreadingServiceUnitTests.swift */; };
EC746C57274E5197002AD24C /* MXThreadingServiceUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC746C55274E5197002AD24C /* MXThreadingServiceUnitTests.swift */; };
EC746C59274E61EF002AD24C /* MXThreadingServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC746C58274E61EF002AD24C /* MXThreadingServiceTests.swift */; };
Expand Down Expand Up @@ -2822,6 +2826,8 @@
EC60EE05265CFFF400B39A4E /* MXGroupSyncProfile.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXGroupSyncProfile.m; sourceTree = "<group>"; };
EC619D9024DD834B00663A80 /* MXPushGatewayRestClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXPushGatewayRestClient.m; sourceTree = "<group>"; };
EC619D9124DD834B00663A80 /* MXPushGatewayRestClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXPushGatewayRestClient.h; sourceTree = "<group>"; };
EC6D007728E1F15400152144 /* MXDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXDevice.h; sourceTree = "<group>"; };
EC6D007828E1F15400152144 /* MXDevice.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXDevice.m; sourceTree = "<group>"; };
EC746C55274E5197002AD24C /* MXThreadingServiceUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXThreadingServiceUnitTests.swift; sourceTree = "<group>"; };
EC746C58274E61EF002AD24C /* MXThreadingServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXThreadingServiceTests.swift; sourceTree = "<group>"; };
EC8A536C25B1BC77004E0802 /* MXCallCandidate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXCallCandidate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3806,6 +3812,8 @@
8EC51109256822B400EC4E5B /* MXTaggedEvents.m */,
EC05473225FF8A3C0047ECD7 /* MXVirtualRoomInfo.h */,
EC05473325FF8A3C0047ECD7 /* MXVirtualRoomInfo.m */,
EC6D007728E1F15400152144 /* MXDevice.h */,
EC6D007828E1F15400152144 /* MXDevice.m */,
);
path = JSONModels;
sourceTree = "<group>";
Expand Down Expand Up @@ -5549,6 +5557,7 @@
F08B8D5C1E014711006171A8 /* NSData+MatrixSDK.h in Headers */,
C60165381E3AA57900B92CFA /* MXSDKOptions.h in Headers */,
32CEEF4F23B0AB030039BA98 /* MXCrossSigning.h in Headers */,
EC6D007928E1F15400152144 /* MXDevice.h in Headers */,
EC619D9324DD834B00663A80 /* MXPushGatewayRestClient.h in Headers */,
32C78B68256CFC4D008130B1 /* MXCryptoVersion.h in Headers */,
320B3934239FA56900BE2C06 /* MXKeyVerificationByDMRequest.h in Headers */,
Expand Down Expand Up @@ -5864,6 +5873,7 @@
1838928927031D1D003F0C4F /* MXSendReplyEventStringLocalizerProtocol.h in Headers */,
EC60EDDB265CFF0600B39A4E /* MXInvitedRoomSync.h in Headers */,
B14EF2C82397E90400758AF0 /* MXCallManager.h in Headers */,
EC6D007A28E1F15400152144 /* MXDevice.h in Headers */,
EC40384B289A7F260067D5B8 /* MXAes256KeyBackupAlgorithm.h in Headers */,
B14EF2C92397E90400758AF0 /* MXRealmReactionRelation.h in Headers */,
91F0685E2767CA430079F8FA /* MXTaskProfileName.h in Headers */,
Expand Down Expand Up @@ -6799,6 +6809,7 @@
321CFDF92254E721004D31DF /* MXTransactionCancelCode.m in Sources */,
B19A30C22404268600FB6F35 /* MXVerifyingAnotherUserQRCodeData.m in Sources */,
EC8A53BD25B1BC77004E0802 /* MXCallRejectEventContent.m in Sources */,
EC6D007B28E1F15400152144 /* MXDevice.m in Sources */,
ECCA02BE27348FE300B6F34F /* MXThread.swift in Sources */,
ED7019E52886C32900FC31B9 /* MXSASTransactionV2.swift in Sources */,
EC1848C72686174E00865E16 /* MXiOSAudioOutputRouteType.swift in Sources */,
Expand Down Expand Up @@ -7398,6 +7409,7 @@
3229535425A5F7220012FCF0 /* MXBackgroundCryptoStore.m in Sources */,
B14EF2812397E90400758AF0 /* MXNotificationCenter.m in Sources */,
EC60ED60265CFC2C00B39A4E /* MXSyncResponse.m in Sources */,
EC6D007C28E1F15400152144 /* MXDevice.m in Sources */,
3A108AB825812995005EEBE9 /* MXKeyProvider.m in Sources */,
B14EF2822397E90400758AF0 /* MXDeviceList.m in Sources */,
ED7019E62886C32900FC31B9 /* MXSASTransactionV2.swift in Sources */,
Expand Down
53 changes: 53 additions & 0 deletions MatrixSDK/JSONModels/MXDevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Copyright 2022 The Matrix.org Foundation C.I.C
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <MatrixSDK/MatrixSDK.h>

NS_ASSUME_NONNULL_BEGIN

/**
`MXDevice` represents a device of the current user.
*/
@interface MXDevice : MXJSONModel

/**
A unique identifier of the device.
*/
@property (nonatomic) NSString *deviceId;

/**
The display name set by the user for this device. Absent if no name has been set.
*/
@property (nonatomic, nullable) NSString *displayName;

/**
The IP address where this device was last seen. (May be a few minutes out of date, for efficiency reasons).
*/
@property (nonatomic, nullable) NSString *lastSeenIp;

/**
The timestamp (in milliseconds since the unix epoch) when this devices was last seen. (May be a few minutes out of date, for efficiency reasons).
*/
@property (nonatomic) uint64_t lastSeenTs;

/**
The latest recorded usr agent for the device.
*/
@property (nonatomic, nullable) NSString *lastSeenUserAgent;

@end

NS_ASSUME_NONNULL_END
65 changes: 65 additions & 0 deletions MatrixSDK/JSONModels/MXDevice.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// Copyright 2022 The Matrix.org Foundation C.I.C
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "MXDevice.h"

NSString* const kDeviceIdJSONKey = @"device_id";
NSString* const kDisplayNameJSONKey = @"display_name";
NSString* const kLastSeenIPJSONKey = @"last_seen_ip";
NSString* const kLastSeenTimestampJSONKey = @"last_seen_ts";
NSString* const kLastSeenUserAgentJSONKey = @"org.matrix.msc3852.last_seen_user_agent";

@implementation MXDevice

+ (id)modelFromJSON:(NSDictionary *)JSONDictionary
{
MXDevice *device = [[MXDevice alloc] init];
if (device)
{
MXJSONModelSetString(device.deviceId, JSONDictionary[kDeviceIdJSONKey]);
MXJSONModelSetString(device.displayName, JSONDictionary[kDisplayNameJSONKey]);
MXJSONModelSetString(device.lastSeenIp, JSONDictionary[kLastSeenIPJSONKey]);
MXJSONModelSetUInt64(device.lastSeenTs, JSONDictionary[kLastSeenTimestampJSONKey]);
MXJSONModelSetString(device.lastSeenUserAgent, JSONDictionary[kLastSeenUserAgentJSONKey]);
}

return device;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self)
{
_deviceId = [aDecoder decodeObjectForKey:kDeviceIdJSONKey];
_displayName = [aDecoder decodeObjectForKey:kDisplayNameJSONKey];
_lastSeenIp = [aDecoder decodeObjectForKey:kLastSeenIPJSONKey];
_lastSeenTs = [((NSNumber*)[aDecoder decodeObjectForKey:kLastSeenTimestampJSONKey]) unsignedLongLongValue];
_lastSeenUserAgent = [aDecoder decodeObjectForKey:kLastSeenUserAgentJSONKey];
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_deviceId forKey:kDeviceIdJSONKey];
[aCoder encodeObject:_displayName forKey:kDisplayNameJSONKey];
[aCoder encodeObject:_lastSeenIp forKey:kLastSeenIPJSONKey];
[aCoder encodeObject:@(_lastSeenTs) forKey:kLastSeenTimestampJSONKey];
[aCoder encodeObject:_lastSeenUserAgent forKey:kLastSeenUserAgentJSONKey];
}

@end
28 changes: 0 additions & 28 deletions MatrixSDK/JSONModels/MXJSONModels.h
Original file line number Diff line number Diff line change
Expand Up @@ -1143,34 +1143,6 @@ FOUNDATION_EXPORT NSString *const kMXPushRuleScopeStringDevice;

@end

#pragma mark - Device Management
/**
`MXDevice` represents a device of the current user.
*/
@interface MXDevice : MXJSONModel

/**
A unique identifier of the device.
*/
@property (nonatomic) NSString *deviceId;

/**
The display name set by the user for this device. Absent if no name has been set.
*/
@property (nonatomic) NSString *displayName;

/**
The IP address where this device was last seen. (May be a few minutes out of date, for efficiency reasons).
*/
@property (nonatomic) NSString *lastSeenIp;

/**
The timestamp (in milliseconds since the unix epoch) when this devices was last seen. (May be a few minutes out of date, for efficiency reasons).
*/
@property (nonatomic) uint64_t lastSeenTs;

@end

#pragma mark - Groups (Communities)

/**
Expand Down
44 changes: 0 additions & 44 deletions MatrixSDK/JSONModels/MXJSONModels.m
Original file line number Diff line number Diff line change
Expand Up @@ -1259,50 +1259,6 @@ - (NSDictionary *)JSONDictionary

@end

#pragma mark - Device Management

@implementation MXDevice

+ (id)modelFromJSON:(NSDictionary *)JSONDictionary
{
MXDevice *device = [[MXDevice alloc] init];
if (device)
{
MXJSONModelSetString(device.deviceId, JSONDictionary[@"device_id"]);
MXJSONModelSetString(device.displayName, JSONDictionary[@"display_name"]);
MXJSONModelSetString(device.lastSeenIp, JSONDictionary[@"last_seen_ip"]);
MXJSONModelSetUInt64(device.lastSeenTs, JSONDictionary[@"last_seen_ts"]);
}

return device;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self)
{
_deviceId = [aDecoder decodeObjectForKey:@"device_id"];
_displayName = [aDecoder decodeObjectForKey:@"display_name"];
_lastSeenIp = [aDecoder decodeObjectForKey:@"last_seen_ip"];
_lastSeenTs = [((NSNumber*)[aDecoder decodeObjectForKey:@"last_seen_ts"]) unsignedLongLongValue];
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_deviceId forKey:@"device_id"];
if (_displayName)
{
[aCoder encodeObject:_displayName forKey:@"display_name"];
}
[aCoder encodeObject:_lastSeenIp forKey:@"last_seen_ip"];
[aCoder encodeObject:@(_lastSeenTs) forKey:@"last_seen_ts"];
}

@end

#pragma mark - Groups (Communities)

@implementation MXGroupProfile
Expand Down
1 change: 1 addition & 0 deletions MatrixSDK/MXRestClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
@class MXDeviceListResponse;
@class MXSpaceChildrenRequestParameters;
@class MXCapabilities;
@class MXDevice;

#pragma mark - Constants definitions
/**
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/MatrixSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,4 @@ FOUNDATION_EXPORT NSString *MatrixSDKVersion;
#import "MXBeaconInfo.h"
#import "MXBeacon.h"
#import "MXEventAssetType.h"

#import "MXDevice.h"
1 change: 1 addition & 0 deletions changelog.d/pr-1583.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MXDevice: Move to dedicated file and implement MSC-3852.