WIP
This commit is contained in:
parent
c3582f3d06
commit
49c6611d9d
|
@ -3,14 +3,16 @@
|
|||
@objc var message: TSMessage! { didSet { handleMessageChanged() } }
|
||||
@objc weak var delegate: FriendRequestViewDelegate?
|
||||
private let kind: Kind
|
||||
|
||||
|
||||
private var didDeclineRequest: Bool {
|
||||
guard let message = message as? TSIncomingMessage else { preconditionFailure() }
|
||||
return message.thread.friendRequestStatus == .none
|
||||
}
|
||||
|
||||
// MARK: Types
|
||||
enum Kind : String { case incoming, outgoing }
|
||||
|
||||
// MARK: Components
|
||||
private lazy var buttonFont = UIFont.ows_dynamicTypeBodyClamped.ows_mediumWeight()
|
||||
private lazy var buttonHeight = buttonFont.pointSize * 48 / 17
|
||||
|
||||
private lazy var label: UILabel = {
|
||||
let result = UILabel()
|
||||
result.textColor = Theme.secondaryColor
|
||||
|
@ -20,6 +22,16 @@
|
|||
result.lineBreakMode = .byWordWrapping
|
||||
return result
|
||||
}()
|
||||
|
||||
private lazy var buttonStackView: UIStackView = {
|
||||
let result = UIStackView()
|
||||
result.axis = .horizontal
|
||||
result.distribution = .fillEqually
|
||||
return result
|
||||
}()
|
||||
|
||||
private lazy var buttonFont = UIFont.ows_dynamicTypeBodyClamped.ows_mediumWeight()
|
||||
private lazy var buttonHeight = buttonFont.pointSize * 48 / 17
|
||||
|
||||
// MARK: Initialization
|
||||
init(kind: Kind) {
|
||||
|
@ -48,9 +60,6 @@
|
|||
mainStackView.addArrangedSubview(label)
|
||||
switch kind {
|
||||
case .incoming:
|
||||
let buttonStackView = UIStackView()
|
||||
buttonStackView.axis = .horizontal
|
||||
buttonStackView.distribution = .fillEqually
|
||||
mainStackView.addArrangedSubview(buttonStackView)
|
||||
let acceptButton = OWSFlatButton.button(title: NSLocalizedString("Accept", comment: ""), font: buttonFont, titleColor: .ows_materialBlue, backgroundColor: .white, target: self, selector: #selector(accept))
|
||||
acceptButton.autoSetDimension(.height, toSize: buttonHeight)
|
||||
|
@ -70,7 +79,15 @@
|
|||
switch kind {
|
||||
case .incoming:
|
||||
guard let message = message as? TSIncomingMessage else { preconditionFailure() }
|
||||
label.text = String(format: NSLocalizedString("%@ sent you a friend request", comment: ""), message.authorId)
|
||||
buttonStackView.isHidden = didDeclineRequest
|
||||
let text: String = {
|
||||
if didDeclineRequest {
|
||||
return String(format: NSLocalizedString("You've declined %@'s friend request", comment: ""), message.authorId)
|
||||
} else {
|
||||
return String(format: NSLocalizedString("%@ sent you a friend request", comment: ""), message.authorId)
|
||||
}
|
||||
}()
|
||||
label.text = text
|
||||
case .outgoing:
|
||||
guard let message = message as? TSOutgoingMessage else { preconditionFailure() }
|
||||
label.text = String(format: NSLocalizedString("You've sent %@ a friend request", comment: ""), message.thread.contactIdentifier()!)
|
||||
|
@ -86,6 +103,7 @@
|
|||
@objc private func decline() {
|
||||
guard let message = message as? TSIncomingMessage else { preconditionFailure() }
|
||||
delegate?.declineFriendRequest(message)
|
||||
handleMessageChanged() // Update UI
|
||||
}
|
||||
|
||||
// MARK: Measuring
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
#import <SignalServiceKit/OWSMessageSender.h>
|
||||
#import <SignalServiceKit/OWSMessageUtils.h>
|
||||
#import <SignalServiceKit/OWSPrimaryStorage.h>
|
||||
#import <SignalServiceKit/OWSPrimaryStorage+Loki.h>
|
||||
#import <SignalServiceKit/OWSReadReceiptManager.h>
|
||||
#import <SignalServiceKit/OWSVerificationStateChangeMessage.h>
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
|
@ -4303,7 +4304,14 @@ typedef enum : NSUInteger {
|
|||
|
||||
- (void)declineFriendRequest:(TSIncomingMessage *)friendRequest
|
||||
{
|
||||
OWSLogDebug(@"decline friend request button pressed"); // TODO: Implement
|
||||
// Reset friend request status
|
||||
self.thread.friendRequestStatus = TSThreadFriendRequestStatusNone;
|
||||
// Delete prekeys
|
||||
NSString *contactID = self.thread.recipientIdentifiers.firstObject;
|
||||
OWSPrimaryStorage *primaryStorage = SSKEnvironment.shared.primaryStorage;
|
||||
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[primaryStorage removePreKeyBundleForContact:contactID transaction:transaction];
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - ConversationViewLayoutDelegate
|
||||
|
|
|
@ -2577,3 +2577,4 @@
|
|||
"Pending Friend Request..." = "Pending Friend Request...";
|
||||
"New Message" = "New Message";
|
||||
"Signal" = "Signal";
|
||||
"You've declined %@'s friend request" = "You've declined %@'s friend request"
|
||||
|
|
|
@ -53,6 +53,7 @@ typedef NS_ENUM(NSInteger, TSThreadFriendRequestStatus) {
|
|||
@property (nonatomic) BOOL shouldThreadBeVisible;
|
||||
@property (nonatomic, readonly) NSDate *creationDate;
|
||||
@property (nonatomic, readonly) BOOL isArchivedByLegacyTimestampForSorting;
|
||||
@property (nonatomic, readonly) TSThreadFriendRequestStatus friendRequestStatus;
|
||||
|
||||
/**
|
||||
* Whether the object is a group thread or not.
|
||||
|
@ -186,12 +187,6 @@ typedef NS_ENUM(NSInteger, TSThreadFriendRequestStatus) {
|
|||
|
||||
- (void)updateWithMutedUntilDate:(NSDate *)mutedUntilDate transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
#pragma mark - Loki Friend Request Handling
|
||||
|
||||
- (TSThreadFriendRequestStatus)getFriendRequestStatus;
|
||||
|
||||
- (TSThreadFriendRequestStatus)getFriendRequestStatusWithTransaction:(YapDatabaseReadTransaction *)transaction;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
|
|
@ -92,6 +92,8 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
|
|||
} else {
|
||||
_conversationColorName = [self.class stableColorNameForNewConversationWithString:self.uniqueId];
|
||||
}
|
||||
|
||||
_friendRequestStatus = TSThreadFriendRequestStatusNone;
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -694,26 +696,11 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
|
|||
}];
|
||||
}
|
||||
|
||||
# pragma mark - Loki Friend Request Handling
|
||||
|
||||
- (TSThreadFriendRequestStatus)getFriendRequestStatus
|
||||
- (void)setFriendRequestStatus:(TSThreadFriendRequestStatus)friendRequestStatus
|
||||
{
|
||||
__block TSThreadFriendRequestStatus friendRequestStatus;
|
||||
[self.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
friendRequestStatus = [self getFriendRequestStatusWithTransaction:transaction];
|
||||
_friendRequestStatus = friendRequestStatus;
|
||||
}];
|
||||
return friendRequestStatus;
|
||||
}
|
||||
|
||||
- (TSThreadFriendRequestStatus)getFriendRequestStatusWithTransaction:(YapDatabaseReadTransaction *)transaction
|
||||
{
|
||||
YapDatabaseViewTransaction *interactions = [transaction ext:TSMessageDatabaseViewExtensionName];
|
||||
NSUInteger interactionCount = [interactions numberOfItemsInGroup:self.uniqueId];
|
||||
if (interactionCount == 0) { return TSThreadFriendRequestStatusNone; }
|
||||
if (interactionCount >= 2) { return TSThreadFriendRequestStatusFriends; }
|
||||
TSInteraction *interaction = [interactions firstObjectInGroup:self.uniqueId];
|
||||
BOOL isIncomingMessage = interaction.interactionType == OWSInteractionType_IncomingMessage;
|
||||
return isIncomingMessage ? TSThreadFriendRequestStatusRequestReceived : TSThreadFriendRequestStatusRequestSent;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1102,7 +1102,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
[error setIsRetryable:NO];
|
||||
return messageSend.failure(error);
|
||||
}
|
||||
|
||||
|
||||
// Update the thread's friend request status if needed
|
||||
if (messageType == TSFriendRequestMessageType) {
|
||||
message.thread.friendRequestStatus = TSThreadFriendRequestStatusPendingSend;
|
||||
}
|
||||
|
||||
// Update the state to show that proof of work is being calculated
|
||||
[self setIsCalculatingProofOfWorkForMessage:messageSend];
|
||||
|
||||
|
@ -1111,6 +1116,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
BOOL isPoWRequired = YES; // TODO: Base on message type
|
||||
[[LokiAPI objc_sendSignalMessage:signalMessage to:recipient.recipientId timestamp:message.timestamp requiringPoW:isPoWRequired]
|
||||
.thenOn(OWSDispatch.sendingQueue, ^(id result) {
|
||||
|
||||
// Update the thread's friend request status if needed
|
||||
if (messageType == TSFriendRequestMessageType) {
|
||||
message.thread.friendRequestStatus = TSThreadFriendRequestStatusSent;
|
||||
}
|
||||
|
||||
[self messageSendDidSucceed:messageSend
|
||||
deviceMessages:deviceMessages
|
||||
wasSentByUD:false
|
||||
|
|
Loading…
Reference in New Issue