Skip to content

get and show friend capabilities. #129

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

Merged
merged 1 commit into from
Sep 19, 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
36 changes: 36 additions & 0 deletions Antidote/FriendCardController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FriendCardController: StaticTableController {
fileprivate let nameModel: StaticTableDefaultCellModel
fileprivate let statusMessageModel: StaticTableDefaultCellModel
fileprivate let publicKeyModel: StaticTableDefaultCellModel
fileprivate let capabilitiesModel: StaticTableDefaultCellModel
fileprivate let pushurlModel: StaticTableDefaultCellModel

init(theme: Theme, friend: OCTFriend, submanagerObjects: OCTSubmanagerObjects) {
Expand All @@ -41,6 +42,7 @@ class FriendCardController: StaticTableController {
nameModel = StaticTableDefaultCellModel()
statusMessageModel = StaticTableDefaultCellModel()
publicKeyModel = StaticTableDefaultCellModel()
capabilitiesModel = StaticTableDefaultCellModel()
pushurlModel = StaticTableDefaultCellModel()

super.init(theme: theme, style: .plain, model: [
Expand All @@ -56,6 +58,9 @@ class FriendCardController: StaticTableController {
[
publicKeyModel,
],
[
capabilitiesModel,
],
[
pushurlModel,
],
Expand Down Expand Up @@ -138,6 +143,16 @@ private extension FriendCardController {
publicKeyModel.userInteractionEnabled = false
publicKeyModel.canCopyValue = true

capabilitiesModel.title = "Tox Capabilities"
let capabilities = friend.capabilities2 ?? ""
if (capabilities.count > 0) {
let caps = NSNumber(value: UInt64(capabilities) ?? 0)
capabilitiesModel.value = capabilitiesToString(caps)
} else {
capabilitiesModel.value = "BASIC"
}
capabilitiesModel.userInteractionEnabled = false

pushurlModel.title = "Push URL"
let pushtoken = friend.pushToken ?? ""
if (pushtoken.count > 0) {
Expand All @@ -147,4 +162,25 @@ private extension FriendCardController {
}
pushurlModel.userInteractionEnabled = false
}

func capabilitiesToString(_ cap: NSNumber) -> String {
var ret: String = "BASIC"
if ((UInt(cap) & 1) > 0) {
ret = ret + " CAPABILITIES"
}
if ((UInt(cap) & 2) > 0) {
ret = ret + " MSGV2"
}
if ((UInt(cap) & 4) > 0) {
ret = ret + " H264"
}
if ((UInt(cap) & 8) > 0) {
ret = ret + " MSGV3"
}
if ((UInt(cap) & 16) > 0) {
ret = ret + " FTV2"
}
return ret;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#import "OCTSettingsStorageObject.h"
#import "OCTLogging.h"

static const uint64_t kCurrentSchemeVersion = 14;
static const uint64_t kCurrentSchemeVersion = 16;
static NSString *kSettingsStorageObjectPrimaryKey = @"kSettingsStorageObjectPrimaryKey";

@interface OCTRealmManager ()
Expand Down Expand Up @@ -498,6 +498,10 @@ + (RLMMigrationBlock)realmMigrationBlock
if (oldSchemaVersion < 14) {
[self doMigrationVersion14:migration];
}

if (oldSchemaVersion < 16) {
[self doMigrationVersion16:migration];
}
};
}

Expand Down Expand Up @@ -595,6 +599,13 @@ + (void)doMigrationVersion14:(RLMMigration *)migration
}];
}

+ (void)doMigrationVersion16:(RLMMigration *)migration
{
[migration enumerateObjects:OCTFriend.className block:^(RLMObject *oldObject, RLMObject *newObject) {
newObject[@"capabilities2"] = nil;
}];
}

/**
* Only one of messageText, messageFile or messageCall can be non-nil.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#import "OCTSubmanagerFriendsImpl.h"
#import "OCTLogging.h"
#import "OCTTox.h"
#import "OCTFriend.h"
#import "OCTFriendRequest.h"
Expand Down Expand Up @@ -252,6 +253,13 @@ - (void)tox:(OCTTox *)tox friendConnectionStatusChanged:(OCTToxConnectionStatus)
if ((status != OCTToxConnectionStatusNone)
&& (theFriend.connectionStatus == OCTToxConnectionStatusNone))
{
// Friend is coming online now

OCTToxCapabilities f_caps = [tox friendGetCapabilitiesWithFriendNumber:friendNumber];
OCTLogVerbose(@"f_caps=%lu", f_caps);
NSString* cap_string = [NSString stringWithFormat:@"%lu", f_caps];
theFriend.capabilities2 = cap_string;

NSString *token = [FIRMessaging messaging].FCMToken;
if (token.length > 0)
{
Expand All @@ -272,6 +280,7 @@ - (void)tox:(OCTTox *)tox friendConnectionStatusChanged:(OCTToxConnectionStatus)
theFriend.connectionStatus = status;

if (! theFriend.isConnected) {
// Friend is offline now
NSDate *dateOffline = [tox friendGetLastOnlineWithFriendNumber:friendNumber error:nil];
NSTimeInterval timeSince = [dateOffline timeIntervalSince1970];
theFriend.lastSeenOnlineInterval = timeSince;
Expand Down
6 changes: 6 additions & 0 deletions local_pod_repo/objcTox/Classes/Private/Wrapper/OCTTox.m
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,12 @@ - (NSDate *)friendGetLastOnlineWithFriendNumber:(OCTToxFriendNumber)friendNumber
return [NSDate dateWithTimeIntervalSince1970:timestamp];
}


- (OCTToxCapabilities)friendGetCapabilitiesWithFriendNumber:(OCTToxFriendNumber)friendNumber
{
return tox_friend_get_capabilities(self.tox, friendNumber);
}

- (OCTToxUserStatus)friendStatusWithFriendNumber:(OCTToxFriendNumber)friendNumber error:(NSError **)error
{
TOX_ERR_FRIEND_QUERY cError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
*/
@property BOOL msgv3Capability;

/**
* Friend's capabilities. A 64 bit unsigned integer.
*/
@property (nonnull) NSString *capabilities2;

@end

RLM_ARRAY_TYPE(OCTFriend)
5 changes: 5 additions & 0 deletions local_pod_repo/objcTox/Classes/Public/Wrapper/OCTTox.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@
*/
- (NSDate *)friendGetLastOnlineWithFriendNumber:(OCTToxFriendNumber)friendNumber error:(NSError **)error;

/**
* Return Friend's capabilities. A 64 bit unsigned integer.
*/
- (OCTToxCapabilities)friendGetCapabilitiesWithFriendNumber:(OCTToxFriendNumber)friendNumber;

/**
* Return the friend's user status (away/busy/...). If the friend number is
* invalid, the return value is unspecified.
Expand Down