Merge remote-tracking branch 'upstream/dev' into dev

This commit is contained in:
Morgan Pretty 2022-03-11 09:41:23 +11:00
commit 3e711811c3
8 changed files with 32 additions and 16 deletions

View File

@ -161,21 +161,22 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
public func notifyUser(for incomingMessage: TSIncomingMessage, in thread: TSThread, transaction: YapDatabaseReadTransaction) {
guard !thread.isMuted else { return }
guard let threadId = thread.uniqueId else { return }
let isMessageRequest = thread.isMessageRequest(using: transaction)
// If the thread is a message request and the user hasn't hidden message requests then we need
// to check if this is the only message request thread (group threads can't be message requests
// so just ignore those and if the user has hidden message requests then we want to show the
// notification regardless of how many message requests there are)
if !thread.isGroupThread() && thread.isMessageRequest() && !CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] {
if !thread.isGroupThread() && isMessageRequest && !CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] {
let threads = transaction.ext(TSThreadDatabaseViewExtensionName) as! YapDatabaseViewTransaction
let numMessageRequests = threads.numberOfItems(inGroup: TSMessageRequestGroup)
// Allow this to show a notification if there are no message requests (ie. this is the first one)
guard numMessageRequests == 0 else { return }
}
else if thread.isMessageRequest() && CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] {
else if isMessageRequest && CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] {
// If there are other interactions on this thread already then don't show the notification
if thread.numberOfInteractions() > 1 { return }
if thread.numberOfInteractions(with: transaction) > 1 { return }
CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] = false
}
@ -214,7 +215,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
case .nameNoPreview, .namePreview:
switch thread {
case is TSContactThread:
notificationTitle = (thread.isMessageRequest() ? "Session" : senderName)
notificationTitle = (isMessageRequest ? "Session" : senderName)
case is TSGroupThread:
var groupName = thread.name(with: transaction)
@ -240,7 +241,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
// If it's a message request then overwrite the body to be something generic (only show a notification
// when receiving a new message request if there aren't any others or the user had hidden them)
if thread.isMessageRequest() {
if isMessageRequest {
notificationBody = NSLocalizedString("MESSAGE_REQUESTS_NOTIFICATION", comment: "")
}

View File

@ -287,7 +287,7 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup"
}
TSThread *thread = (TSThread *)object;
if (thread.isMessageRequest) {
if ([thread isMessageRequestUsingTransaction:transaction]) {
return nil;
}
else {

View File

@ -55,17 +55,16 @@ extension ConfigurationMessage {
return (
// Skip the current user
contact.sessionID != currentUserPublicKey && (
contact.sessionID != currentUserPublicKey &&
// Contacts which have visible threads
TSContactThread.fetch(uniqueId: threadID, transaction: transaction)?.shouldBeVisible == true && (
// Include already approved contacts
contact.isApproved ||
contact.didApproveMe ||
// Sync blocked contacts
SSKEnvironment.shared.blockingManager.isRecipientIdBlocked(contact.sessionID) ||
// Contacts which have visible threads (sanity check - should be included as already approved)
TSContactThread.fetch(uniqueId: threadID, transaction: transaction)?.shouldBeVisible == true
SSKEnvironment.shared.blockingManager.isRecipientIdBlocked(contact.sessionID)
)
)
}

View File

@ -67,6 +67,8 @@ BOOL IsNoteToSelfEnabled(void);
*/
- (NSUInteger)numberOfInteractions;
- (NSUInteger)numberOfInteractionsWithTransaction:(YapDatabaseReadTransaction *)transaction;
- (NSUInteger)unreadMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction
NS_SWIFT_NAME(unreadMessageCount(transaction:));

View File

@ -233,12 +233,17 @@ BOOL IsNoteToSelfEnabled(void)
{
__block NSUInteger count;
[[self dbReadConnection] readWithBlock:^(YapDatabaseReadTransaction *transaction) {
YapDatabaseViewTransaction *interactionsByThread = [transaction ext:TSMessageDatabaseViewExtensionName];
count = [interactionsByThread numberOfItemsInGroup:self.uniqueId];
count = [self numberOfInteractionsWithTransaction:transaction];
}];
return count;
}
- (NSUInteger)numberOfInteractionsWithTransaction:(YapDatabaseReadTransaction *)transaction
{
YapDatabaseViewTransaction *interactionsByThread = [transaction ext:TSMessageDatabaseViewExtensionName];
return [interactionsByThread numberOfItemsInGroup:self.uniqueId];
}
- (NSArray<id<OWSReadTracking>> *)unseenMessagesWithTransaction:(YapDatabaseReadTransaction *)transaction
{
NSMutableArray<id<OWSReadTracking>> *messages = [NSMutableArray new];

View File

@ -22,7 +22,7 @@ public class NSENotificationPresenter: NSObject, NotificationsProtocol {
}
else if thread.isMessageRequest() && CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] {
// If there are other interactions on this thread already then don't show the notification
if thread.numberOfInteractions() > 1 { return }
if thread.numberOfInteractions(with: transaction) > 1 { return }
CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] = false
}

View File

@ -8,7 +8,17 @@ public final class Identicon : NSObject {
if content.count > 2 && content.hasPrefix("05") {
content.removeFirst(2)
}
let layer = icon.generateLayer(with: size, text: content.substring(to: 1))
let initials: String = content
.split(separator: " ")
.compactMap { word in word.first.map { String($0) } }
.joined()
let layer = icon.generateLayer(
with: size,
text: (initials.count >= 2 ?
initials.substring(to: 2).uppercased() :
content.substring(to: 2).uppercased()
)
)
let rect = CGRect(origin: CGPoint.zero, size: layer.frame.size)
let renderer = UIGraphicsImageRenderer(size: rect.size)
return renderer.image { layer.render(in: $0.cgContext) }

View File

@ -37,7 +37,6 @@ public class PlaceholderIcon {
}
private func getTextLayer(with diameter: CGFloat, colour: CGColor? = nil, text: String) -> CALayer {
let text = text.capitalized
let font = UIFont.boldSystemFont(ofSize: diameter / 2)
let height = NSString(string: text).boundingRect(with: CGSize(width: diameter, height: CGFloat.greatestFiniteMagnitude),
options: .usesLineFragmentOrigin, attributes: [ NSAttributedString.Key.font : font ], context: nil).height