Fix friend request display logic

pull/63/head
Niels Andriesse 6 years ago
parent 4258e6d68e
commit c23b6782e8

@ -213,7 +213,7 @@ NS_ASSUME_NONNULL_BEGIN
}
}
if (self.message.isFriendRequest) {
if ([self shouldShowFriendRequestUIForMessage:self.message]) {
self.friendRequestView = [[LKFriendRequestView alloc] initWithMessage:self.message];
self.friendRequestView.delegate = self.friendRequestViewDelegate;
[self.contentView addSubview:self.friendRequestView];
@ -383,7 +383,7 @@ NS_ASSUME_NONNULL_BEGIN
cellSize.width += self.sendFailureBadgeSize + self.sendFailureBadgeSpacing;
}
if (self.message.isFriendRequest) {
if ([self shouldShowFriendRequestUIForMessage:self.message]) {
cellSize.height += [LKFriendRequestView calculateHeightWithMessage:self.message conversationStyle:self.conversationStyle];
}
@ -468,7 +468,7 @@ NS_ASSUME_NONNULL_BEGIN
{
OWSAssertDebug(self.delegate);
if (self.message.isFriendRequest) {
if ([self shouldShowFriendRequestUIForMessage:self.message]) {
return;
}
@ -530,6 +530,35 @@ NS_ASSUME_NONNULL_BEGIN
return location.y <= headerBottom.y;
}
#pragma mark - Convenience
- (BOOL)shouldShowFriendRequestUIForMessage:(TSMessage *)message
{
if ([message isKindOfClass:TSOutgoingMessage.class]) {
return message.isFriendRequest;
} else {
if (message.isFriendRequest) {
// Only show an incoming friend request if the user isn't yet friends with any of the other user's devices
NSString *senderID = ((TSIncomingMessage *)message).authorId;
NSMutableSet<TSContactThread *> *threads = [NSMutableSet new];
[OWSPrimaryStorage.sharedManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
NSSet<LKDeviceLink *> *deviceLinks = [LKDatabaseUtilities getDeviceLinksFor:senderID in:transaction];
for (LKDeviceLink *deviceLink in deviceLinks) {
[threads addObject:[TSContactThread getThreadWithContactId:deviceLink.master.hexEncodedPublicKey transaction:transaction]];
[threads addObject:[TSContactThread getThreadWithContactId:deviceLink.slave.hexEncodedPublicKey transaction:transaction]];
}
}];
BOOL isFriend = [threads contains:^BOOL(NSObject *object) {
TSContactThread *thread = (TSContactThread *)object;
return thread.isContactFriend;
}];
return !isFriend;
} else {
return NO;
}
}
}
@end
NS_ASSUME_NONNULL_END

@ -27,6 +27,11 @@ public final class LokiDatabaseUtilities : NSObject {
return OWSPrimaryStorage.shared().getMasterHexEncodedPublicKey(for: slaveHexEncodedPublicKey, in: transaction)
}
@objc(getDeviceLinksFor:in:)
public static func objc_getDeviceLinks(for masterHexEncodedPublicKey: String, in transaction: YapDatabaseReadTransaction) -> Set<DeviceLink> {
return OWSPrimaryStorage.shared().getDeviceLinks(for: masterHexEncodedPublicKey, in: transaction)
}
// MARK: Public Chats
private static let publicChatCollection = "LokiPublicChatCollection"

@ -3,5 +3,6 @@
- (BOOL)contains:(BOOL (^)(NSObject *))predicate;
- (NSSet *)filtered:(BOOL (^)(NSObject *))isIncluded;
- (NSSet *)map:(NSObject *(^)(NSObject *))transform;
@end

@ -20,4 +20,13 @@
return result;
}
- (NSSet *)map:(NSObject *(^)(NSObject *))transform {
NSMutableSet *result = [NSMutableSet new];
for (NSObject *object in self) {
NSObject *transformedObject = transform(object);
[result addObject:transformedObject];
}
return result;
}
@end

Loading…
Cancel
Save