mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
4.0 KiB
Matlab
139 lines
4.0 KiB
Matlab
9 years ago
|
// Created by Dylan Bourgeois on 20/11/14.
|
||
9 years ago
|
// Portions Copyright (c) 2016 Open Whisper Systems. All rights reserved.
|
||
9 years ago
|
|
||
9 years ago
|
#import "OWSCall.h"
|
||
|
#import <JSQMessagesViewController/JSQMessagesTimestampFormatter.h>
|
||
|
#import <JSQMessagesViewController/UIImage+JSQMessages.h>
|
||
9 years ago
|
|
||
9 years ago
|
@implementation OWSCall
|
||
9 years ago
|
|
||
|
#pragma mark - Initialzation
|
||
|
|
||
9 years ago
|
- (instancetype)initWithCallerId:(NSString *)senderId
|
||
|
callerDisplayName:(NSString *)senderDisplayName
|
||
|
date:(NSDate *)date
|
||
|
status:(CallStatus)status
|
||
|
displayString:(NSString *)detailString
|
||
9 years ago
|
{
|
||
|
NSParameterAssert(senderId != nil);
|
||
|
NSParameterAssert(senderDisplayName != nil);
|
||
9 years ago
|
|
||
9 years ago
|
self = [super init];
|
||
|
if (self) {
|
||
|
_senderId = [senderId copy];
|
||
|
_senderDisplayName = [senderDisplayName copy];
|
||
|
_date = [date copy];
|
||
|
_status = status;
|
||
|
_messageType = TSCallAdapter;
|
||
|
_detailString = [detailString stringByAppendingFormat:@" "];
|
||
|
}
|
||
|
return self;
|
||
|
}
|
||
|
|
||
9 years ago
|
- (id)init
|
||
9 years ago
|
{
|
||
9 years ago
|
NSAssert(NO,
|
||
|
@"%s is not a valid initializer for %@. Use %@ instead",
|
||
|
__PRETTY_FUNCTION__,
|
||
|
[self class],
|
||
|
NSStringFromSelector(@selector(initWithCallerId:callerDisplayName:date:status:displayString:)));
|
||
9 years ago
|
return nil;
|
||
|
}
|
||
|
|
||
9 years ago
|
- (void)dealloc
|
||
9 years ago
|
{
|
||
|
_senderId = nil;
|
||
|
_senderDisplayName = nil;
|
||
|
_date = nil;
|
||
|
}
|
||
|
|
||
9 years ago
|
- (NSString *)dateText
|
||
9 years ago
|
{
|
||
|
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
||
|
dateFormatter.timeStyle = NSDateFormatterShortStyle;
|
||
|
dateFormatter.dateStyle = NSDateFormatterMediumStyle;
|
||
|
dateFormatter.doesRelativeDateFormatting = YES;
|
||
|
return [dateFormatter stringFromDate:_date];
|
||
|
}
|
||
|
|
||
|
#pragma mark - NSObject
|
||
|
|
||
9 years ago
|
- (BOOL)isEqual:(id)object
|
||
9 years ago
|
{
|
||
9 years ago
|
if (self == object) {
|
||
9 years ago
|
return YES;
|
||
|
}
|
||
9 years ago
|
|
||
|
if (![object isKindOfClass:[self class]]) {
|
||
9 years ago
|
return NO;
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
OWSCall *aCall = (OWSCall *)object;
|
||
9 years ago
|
|
||
|
return [self.senderId isEqualToString:aCall.senderId] &&
|
||
|
[self.senderDisplayName isEqualToString:aCall.senderDisplayName]
|
||
|
&& ([self.date compare:aCall.date] == NSOrderedSame) && self.status == aCall.status;
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
- (NSUInteger)hash
|
||
9 years ago
|
{
|
||
|
return self.senderId.hash ^ self.date.hash;
|
||
|
}
|
||
9 years ago
|
- (NSString *)description
|
||
9 years ago
|
{
|
||
|
return [NSString stringWithFormat:@"<%@: senderId=%@, senderDisplayName=%@, date=%@>",
|
||
9 years ago
|
[self class],
|
||
|
self.senderId,
|
||
|
self.senderDisplayName,
|
||
|
self.date];
|
||
9 years ago
|
}
|
||
|
#pragma mark - JSQMessageData
|
||
|
|
||
9 years ago
|
// TODO I'm not sure this is right. It affects bubble rendering.
|
||
|
- (BOOL)isMediaMessage
|
||
|
{
|
||
9 years ago
|
return NO;
|
||
|
}
|
||
|
#pragma mark - NSCoding
|
||
|
|
||
9 years ago
|
- (instancetype)initWithCoder:(NSCoder *)aDecoder
|
||
9 years ago
|
{
|
||
|
self = [super init];
|
||
|
if (self) {
|
||
|
_senderId = [aDecoder decodeObjectForKey:NSStringFromSelector(@selector(senderId))];
|
||
|
_senderDisplayName = [aDecoder decodeObjectForKey:NSStringFromSelector(@selector(senderDisplayName))];
|
||
|
_date = [aDecoder decodeObjectForKey:NSStringFromSelector(@selector(date))];
|
||
|
_status = (CallStatus)[aDecoder decodeIntegerForKey:NSStringFromSelector(@selector(status))];
|
||
|
}
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)encodeWithCoder:(NSCoder *)aCoder
|
||
|
{
|
||
|
[aCoder encodeObject:self.senderId forKey:NSStringFromSelector(@selector(senderId))];
|
||
|
[aCoder encodeObject:self.senderDisplayName forKey:NSStringFromSelector(@selector(senderDisplayName))];
|
||
|
[aCoder encodeObject:self.date forKey:NSStringFromSelector(@selector(date))];
|
||
|
[aCoder encodeDouble:self.status forKey:NSStringFromSelector(@selector(status))];
|
||
|
}
|
||
|
|
||
|
#pragma mark - NSCopying
|
||
|
|
||
9 years ago
|
- (instancetype)copyWithZone:(NSZone *)zone
|
||
9 years ago
|
{
|
||
9 years ago
|
return [[[self class] allocWithZone:zone] initWithCallerId:self.senderId
|
||
|
callerDisplayName:self.senderDisplayName
|
||
|
date:self.date
|
||
|
status:self.status
|
||
|
displayString:self.detailString];
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
- (NSUInteger)messageHash
|
||
|
{
|
||
9 years ago
|
return self.hash;
|
||
|
}
|
||
9 years ago
|
- (NSString *)text
|
||
|
{
|
||
9 years ago
|
return _detailString;
|
||
|
}
|
||
|
@end
|