Initial commit
This commit is contained in:
@ -0,0 +1,11 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTCall.h"
|
||||
|
||||
@interface OCTCall (Utilities)
|
||||
|
||||
- (BOOL)isPaused;
|
||||
|
||||
@end
|
@ -0,0 +1,14 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTCall+Utilities.h"
|
||||
|
||||
@implementation OCTCall (Utilities)
|
||||
|
||||
- (BOOL)isPaused
|
||||
{
|
||||
return (self.pausedStatus != OCTCallPausedStatusNone);
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,28 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTCall+Utilities.h"
|
||||
#import "OCTToxAVConstants.h"
|
||||
|
||||
@interface OCTCall ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation OCTCall
|
||||
|
||||
- (BOOL)isOutgoing
|
||||
{
|
||||
return (self.caller == nil);
|
||||
}
|
||||
|
||||
- (NSDate *)onHoldDate
|
||||
{
|
||||
if (self.onHoldStartInterval <= 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [NSDate dateWithTimeIntervalSince1970:self.onHoldStartInterval];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,25 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
@class OCTRealmManager;
|
||||
@class OCTCall;
|
||||
|
||||
@interface OCTCallTimer : NSObject
|
||||
|
||||
- (instancetype)initWithRealmManager:(OCTRealmManager *)realmManager;
|
||||
|
||||
/**
|
||||
* Starts the timer for the specified call.
|
||||
* Note that there can only be one active call.
|
||||
* @param call Call to update.
|
||||
*/
|
||||
- (void)startTimerForCall:(OCTCall *)call;
|
||||
|
||||
/**
|
||||
* Stops the timer for the current call in session.
|
||||
*/
|
||||
- (void)stopTimer;
|
||||
|
||||
@end
|
@ -0,0 +1,87 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTCallTimer.h"
|
||||
#import "OCTRealmManager.h"
|
||||
#import "OCTCall.h"
|
||||
#import "OCTLogging.h"
|
||||
|
||||
@interface OCTCallTimer ()
|
||||
|
||||
@property (strong, nonatomic) dispatch_source_t timer;
|
||||
@property (strong, nonatomic) OCTRealmManager *realmManager;
|
||||
@property (strong, nonatomic) OCTCall *call;
|
||||
|
||||
@end
|
||||
|
||||
@implementation OCTCallTimer
|
||||
|
||||
- (instancetype)initWithRealmManager:(OCTRealmManager *)realmManager
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (! self) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
_realmManager = realmManager;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)startTimerForCall:(OCTCall *)call
|
||||
{
|
||||
@synchronized(self) {
|
||||
if (self.timer) {
|
||||
NSAssert(! self.timer, @"There is already a timer in progress!");
|
||||
}
|
||||
|
||||
self.call = call;
|
||||
|
||||
// dispatch_queue_t queue = dispatch_queue_create("me.dvor.objcTox.OCTCallQueue", DISPATCH_QUEUE_SERIAL);
|
||||
// Main queue is used temporarily for now since we are getting 'Realm accessed from incorrect thread'.
|
||||
// Should really be using the queue above..
|
||||
|
||||
self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
|
||||
uint64_t interval = NSEC_PER_SEC;
|
||||
uint64_t leeway = NSEC_PER_SEC / 1000;
|
||||
dispatch_source_set_timer(self.timer, DISPATCH_TIME_NOW, interval, leeway);
|
||||
|
||||
__weak OCTCallTimer *weakSelf = self;
|
||||
|
||||
dispatch_source_set_event_handler(self.timer, ^{
|
||||
OCTCallTimer *strongSelf = weakSelf;
|
||||
if (! strongSelf) {
|
||||
dispatch_source_cancel(self.timer);
|
||||
OCTLogError(@"Error: Attempt to update timer with no strong pointer to OCTCallTimer");
|
||||
return;
|
||||
}
|
||||
|
||||
[strongSelf.realmManager updateObject:strongSelf.call withBlock:^(OCTCall *callToUpdate) {
|
||||
callToUpdate.callDuration += 1.0;
|
||||
}];
|
||||
|
||||
OCTLogInfo(@"Call: %@ duration at %f seconds", strongSelf.call, strongSelf.call.callDuration);
|
||||
});
|
||||
|
||||
dispatch_resume(self.timer);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)stopTimer
|
||||
{
|
||||
@synchronized(self) {
|
||||
if (! self.timer) {
|
||||
return;
|
||||
}
|
||||
|
||||
OCTLogInfo(@"Timer for call %@ has stopped at duration %f", self.call, self.call.callDuration);
|
||||
|
||||
dispatch_source_cancel(self.timer);
|
||||
self.timer = nil;
|
||||
self.call = nil;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,39 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTChat.h"
|
||||
#import "OCTMessageAbstract.h"
|
||||
|
||||
@interface OCTChat ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation OCTChat
|
||||
|
||||
#pragma mark - Public
|
||||
|
||||
- (NSDate *)lastReadDate
|
||||
{
|
||||
if (self.lastReadDateInterval <= 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [NSDate dateWithTimeIntervalSince1970:self.lastReadDateInterval];
|
||||
}
|
||||
|
||||
- (NSDate *)lastActivityDate
|
||||
{
|
||||
if (self.lastActivityDateInterval <= 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [NSDate dateWithTimeIntervalSince1970:self.lastActivityDateInterval];
|
||||
}
|
||||
|
||||
- (BOOL)hasUnreadMessages
|
||||
{
|
||||
return (self.lastMessage.dateInterval > self.lastReadDateInterval);
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,41 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTFriend.h"
|
||||
|
||||
@interface OCTFriend ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation OCTFriend
|
||||
|
||||
#pragma mark - Class methods
|
||||
|
||||
+ (NSArray *)requiredProperties
|
||||
{
|
||||
NSMutableArray *properties = [NSMutableArray arrayWithArray:[super requiredProperties]];
|
||||
|
||||
[properties addObject:NSStringFromSelector(@selector(nickname))];
|
||||
[properties addObject:NSStringFromSelector(@selector(publicKey))];
|
||||
|
||||
return [properties copy];
|
||||
}
|
||||
|
||||
#pragma mark - Public
|
||||
|
||||
- (NSDate *)lastSeenOnline
|
||||
{
|
||||
if (self.lastSeenOnlineInterval <= 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [NSDate dateWithTimeIntervalSince1970:self.lastSeenOnlineInterval];
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"OCTFriend with friendNumber %u, name %@", self.friendNumber, self.name];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,33 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTFriendRequest.h"
|
||||
|
||||
@implementation OCTFriendRequest
|
||||
|
||||
#pragma mark - Class methods
|
||||
|
||||
+ (NSArray *)requiredProperties
|
||||
{
|
||||
NSMutableArray *properties = [NSMutableArray arrayWithArray:[super requiredProperties]];
|
||||
|
||||
[properties addObject:NSStringFromSelector(@selector(publicKey))];
|
||||
|
||||
return [properties copy];
|
||||
}
|
||||
|
||||
#pragma mark - Public
|
||||
|
||||
- (NSDate *)date
|
||||
{
|
||||
return [NSDate dateWithTimeIntervalSince1970:self.dateInterval];
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"OCTFriendRequest with publicKey %@...\nmessage length %lu",
|
||||
[self.publicKey substringToIndex:5], (unsigned long)self.message.length];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,49 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTMessageAbstract.h"
|
||||
#import "OCTMessageText.h"
|
||||
#import "OCTMessageFile.h"
|
||||
#import "OCTMessageCall.h"
|
||||
|
||||
@interface OCTMessageAbstract ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation OCTMessageAbstract
|
||||
|
||||
#pragma mark - Public
|
||||
|
||||
- (NSDate *)date
|
||||
{
|
||||
if (self.dateInterval <= 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [NSDate dateWithTimeIntervalSince1970:self.dateInterval];
|
||||
}
|
||||
|
||||
- (BOOL)isOutgoing
|
||||
{
|
||||
return (self.senderUniqueIdentifier == nil);
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
NSString *string = nil;
|
||||
|
||||
if (self.messageText) {
|
||||
string = [self.messageText description];
|
||||
}
|
||||
else if (self.messageFile) {
|
||||
string = [self.messageFile description];
|
||||
}
|
||||
else if (self.messageCall) {
|
||||
string = [self.messageCall description];
|
||||
}
|
||||
|
||||
return [NSString stringWithFormat:@"OCTMessageAbstract with date %@, %@", self.date, string];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,34 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTMessageCall.h"
|
||||
|
||||
@implementation OCTMessageCall
|
||||
|
||||
#pragma mark - Public
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
NSString *description = [super description];
|
||||
|
||||
return [description stringByAppendingString:[self typeDescription]];
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
- (NSString *)typeDescription
|
||||
{
|
||||
NSString *description;
|
||||
switch (self.callEvent) {
|
||||
case OCTMessageCallEventAnswered:
|
||||
description = [[NSString alloc] initWithFormat:@"Call lasted %f seconds", self.callDuration];
|
||||
break;
|
||||
case OCTMessageCallEventUnanswered:
|
||||
description = @"Call unanswered";
|
||||
break;
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,36 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTMessageFile.h"
|
||||
|
||||
@interface OCTMessageFile ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation OCTMessageFile
|
||||
|
||||
#pragma mark - Public
|
||||
|
||||
- (nullable NSString *)filePath
|
||||
{
|
||||
return [self.internalFilePath stringByExpandingTildeInPath];
|
||||
}
|
||||
|
||||
- (void)internalSetFilePath:(NSString *)path
|
||||
{
|
||||
self.internalFilePath = [path stringByAbbreviatingWithTildeInPath];
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
NSString *description = [super description];
|
||||
|
||||
const NSUInteger maxSymbols = 3;
|
||||
NSString *fileName = self.fileName.length > maxSymbols ? ([self.fileName substringToIndex:maxSymbols]) : @"";
|
||||
|
||||
return [description stringByAppendingFormat:@"OCTMessageFile with fileName = %@..., fileSize = %llu",
|
||||
fileName, self.fileSize];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,31 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTMessageText.h"
|
||||
|
||||
@interface OCTMessageText ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation OCTMessageText
|
||||
|
||||
#pragma mark - Class methods
|
||||
|
||||
+ (NSArray *)indexedProperties {
|
||||
return @[@"msgv3HashHex", @"isDelivered", @"sentPush"];
|
||||
}
|
||||
|
||||
#pragma mark - Public
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
NSString *description = [super description];
|
||||
|
||||
const NSUInteger maxSymbols = 3;
|
||||
NSString *text = self.text.length > maxSymbols ? ([self.text substringToIndex:maxSymbols]) : @"";
|
||||
|
||||
return [description stringByAppendingFormat:@"OCTMessageText %@..., length %lu", text, (unsigned long)self.text.length];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,30 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "OCTToxConstants.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OCTNode : NSObject
|
||||
|
||||
@property (copy, nonatomic, readonly, nullable) NSString *ipv4Host;
|
||||
@property (copy, nonatomic, readonly, nullable) NSString *ipv6Host;
|
||||
@property (assign, nonatomic, readonly) OCTToxPort udpPort;
|
||||
@property (copy, nonatomic, readonly) NSArray<NSNumber *> *tcpPorts;
|
||||
@property (copy, nonatomic, readonly) NSString *publicKey;
|
||||
|
||||
- (instancetype)initWithIpv4Host:(nullable NSString *)ipv4Host
|
||||
ipv6Host:(nullable NSString *)ipv6Host
|
||||
udpPort:(OCTToxPort)udpPort
|
||||
tcpPorts:(NSArray<NSNumber *> *)tcpPorts
|
||||
publicKey:(NSString *)publicKey;
|
||||
|
||||
- (BOOL)isEqual:(id)object;
|
||||
- (NSUInteger)hash;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,71 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTNode.h"
|
||||
|
||||
@implementation OCTNode
|
||||
|
||||
#pragma mark - Lifecycle
|
||||
|
||||
- (instancetype)initWithIpv4Host:(nullable NSString *)ipv4Host
|
||||
ipv6Host:(nullable NSString *)ipv6Host
|
||||
udpPort:(OCTToxPort)udpPort
|
||||
tcpPorts:(NSArray<NSNumber *> *)tcpPorts
|
||||
publicKey:(NSString *)publicKey
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (! self) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
_ipv4Host = [ipv4Host copy];
|
||||
_ipv6Host = [ipv6Host copy];
|
||||
_udpPort = udpPort;
|
||||
_tcpPorts = [tcpPorts copy];
|
||||
_publicKey = [publicKey copy];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)isEqual:(id)object
|
||||
{
|
||||
if (! [object isKindOfClass:[OCTNode class]]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
OCTNode *another = object;
|
||||
|
||||
return [self compareString:self.ipv4Host with:another.ipv4Host] &&
|
||||
[self compareString:self.ipv6Host with:another.ipv6Host] &&
|
||||
(self.udpPort == another.udpPort) &&
|
||||
[self.tcpPorts isEqual:another.tcpPorts] &&
|
||||
[self.publicKey isEqual:another.publicKey];
|
||||
}
|
||||
|
||||
- (NSUInteger)hash
|
||||
{
|
||||
const NSUInteger prime = 31;
|
||||
NSUInteger result = 1;
|
||||
|
||||
result = prime * result + [self.ipv4Host hash];
|
||||
result = prime * result + [self.ipv6Host hash];
|
||||
result = prime * result + self.udpPort;
|
||||
result = prime * result + [self.tcpPorts hash];
|
||||
result = prime * result + [self.publicKey hash];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (BOOL)compareString:(NSString *)first with:(NSString *)second
|
||||
{
|
||||
if (first && second) {
|
||||
return [first isEqual:second];
|
||||
}
|
||||
|
||||
BOOL bothNil = ! first && ! second;
|
||||
return bothNil;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,55 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTObject.h"
|
||||
|
||||
@implementation OCTObject
|
||||
|
||||
#pragma mark - Class methods
|
||||
|
||||
+ (NSString *)primaryKey
|
||||
{
|
||||
return NSStringFromSelector(@selector(uniqueIdentifier));
|
||||
}
|
||||
|
||||
+ (NSDictionary *)defaultPropertyValues
|
||||
{
|
||||
return @{
|
||||
NSStringFromSelector(@selector(uniqueIdentifier)) : [[NSUUID UUID] UUIDString],
|
||||
};
|
||||
}
|
||||
|
||||
+ (NSArray *)requiredProperties
|
||||
{
|
||||
return @[NSStringFromSelector(@selector(uniqueIdentifier))];
|
||||
}
|
||||
|
||||
#pragma mark - Public
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"%@ with uniqueIdentifier %@", [self class], self.uniqueIdentifier];
|
||||
}
|
||||
|
||||
- (BOOL)isEqual:(id)object
|
||||
{
|
||||
if (object == self) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
if (! [object isKindOfClass:[self class]]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
OCTObject *o = object;
|
||||
|
||||
return [self.uniqueIdentifier isEqualToString:o.uniqueIdentifier];
|
||||
}
|
||||
|
||||
- (NSUInteger)hash
|
||||
{
|
||||
return [self.uniqueIdentifier hash];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,22 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTObject.h"
|
||||
|
||||
@interface OCTSettingsStorageObject : OCTObject
|
||||
|
||||
@property BOOL bootstrapDidConnect;
|
||||
|
||||
/**
|
||||
* UIImage with avatar of user.
|
||||
*/
|
||||
@property NSData *userAvatarData;
|
||||
|
||||
/**
|
||||
* Generic data to be used by user of the library.
|
||||
* It shouldn't be used by objcTox itself.
|
||||
*/
|
||||
@property NSData *genericSettingsData;
|
||||
|
||||
@end
|
@ -0,0 +1,17 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#import "OCTSettingsStorageObject.h"
|
||||
|
||||
@implementation OCTSettingsStorageObject
|
||||
|
||||
+ (NSDictionary *)defaultPropertyValues
|
||||
{
|
||||
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:[super defaultPropertyValues]];
|
||||
|
||||
dict[@"bootstrapDidConnect"] = @NO;
|
||||
return [dict copy];
|
||||
}
|
||||
|
||||
@end
|
Reference in New Issue
Block a user