session-ios/SessionMessagingKit/Messages/Signal/TSInfoMessage.m
Morgan Pretty 9db5083cc5 Built out the Message Request functionality
Added the MessageRequestsViewController
Added a 'Message Requests' button to the settings screen
Added accept/reject buttons for message requests to the ConversationVC
Added the ability to hide the message request item on the HomeVC (re-appears if you get a new message request)
Added code to handle an edge-case where the message request approval state wouldn't be returned to the sender due to the recipient running an old version of the app
Prevented contacts which aren't associated with an approved thread from appearing when creating a closed group
Disabled notifications for threads which aren't approved
Updated the app notification count to exclude unapproved messages
Updated the app to ignore closed group creation messages if the group has no admins which are approved contacts
Fixed up the keyboard avoidance behaviour in the ConversationVC
Fixed a couple of minor interaction issues which affected some devices
Fixed an issue where the database migrations would run on the 2nd launch when creating a new account (causing odd behaviours)
2022-02-02 16:59:56 +11:00

153 lines
3.9 KiB
Objective-C

//
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
#import "TSInfoMessage.h"
#import "SSKEnvironment.h"
#import <YapDatabase/YapDatabaseConnection.h>
#import <SessionUtilitiesKit/SessionUtilitiesKit.h>
NS_ASSUME_NONNULL_BEGIN
NSUInteger TSInfoMessageSchemaVersion = 1;
@interface TSInfoMessage ()
@property (nonatomic, getter=wasRead) BOOL read;
@property (nonatomic, readonly) NSUInteger infoMessageSchemaVersion;
@end
#pragma mark -
@implementation TSInfoMessage
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (!self) {
return self;
}
if (self.infoMessageSchemaVersion < 1) {
_read = YES;
}
_infoMessageSchemaVersion = TSInfoMessageSchemaVersion;
if (self.isDynamicInteraction) {
self.read = YES;
}
return self;
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(TSThread *)thread
messageType:(TSInfoMessageType)infoMessage
{
// MJK TODO - remove senderTimestamp
self = [super initMessageWithTimestamp:timestamp
inThread:thread
messageBody:nil
attachmentIds:@[]
expiresInSeconds:0
expireStartedAt:0
quotedMessage:nil
linkPreview:nil
openGroupInvitationName:nil
openGroupInvitationURL:nil
serverHash:nil];
if (!self) {
return self;
}
_messageType = infoMessage;
_infoMessageSchemaVersion = TSInfoMessageSchemaVersion;
if (self.isDynamicInteraction) {
self.read = YES;
}
return self;
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(TSThread *)thread
messageType:(TSInfoMessageType)infoMessage
customMessage:(NSString *)customMessage
{
self = [self initWithTimestamp:timestamp inThread:thread messageType:infoMessage];
if (self) {
_customMessage = customMessage;
}
return self;
}
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(TSThread *)thread
messageType:(TSInfoMessageType)infoMessage
unregisteredRecipientId:(NSString *)unregisteredRecipientId
{
self = [self initWithTimestamp:timestamp inThread:thread messageType:infoMessage];
if (self) {
_unregisteredRecipientId = unregisteredRecipientId;
}
return self;
}
- (OWSInteractionType)interactionType
{
return OWSInteractionType_Info;
}
- (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction
{
switch (_messageType) {
case TSInfoMessageTypeGroupCreated:
return NSLocalizedString(@"GROUP_CREATED", @"");
case TSInfoMessageTypeGroupCurrentUserLeft:
return NSLocalizedString(@"GROUP_YOU_LEFT", @"");
case TSInfoMessageTypeGroupUpdated:
return _customMessage != nil ? _customMessage : NSLocalizedString(@"GROUP_UPDATED", @"");
case TSInfoMessageTypeMessageRequestAccepted:
return NSLocalizedString(@"MESSAGE_REQUESTS_ACCEPTED", @"");
default:
break;
}
return @"Unknown Info Message Type";
}
#pragma mark - OWSReadTracking
- (BOOL)shouldAffectUnreadCounts
{
return NO;
}
- (uint64_t)expireStartedAt
{
return 0;
}
- (void)markAsReadAtTimestamp:(uint64_t)readTimestamp
sendReadReceipt:(BOOL)sendReadReceipt
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
if (_read) {
return;
}
_read = YES;
[self saveWithTransaction:transaction];
// Ignore sendReadReceipt, it doesn't apply to info messages.
}
@end
NS_ASSUME_NONNULL_END