Merge pull request #245 from RyanRory/bug-fix

Bug Fixes Part 1/2
pull/247/head
Niels Andriesse 4 years ago committed by GitHub
commit 9f82603026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -62,24 +62,26 @@ final class NotificationServiceExtension : UNNotificationServiceExtension {
var thread: TSThread
var newNotificationBody = ""
let masterPublicKey = OWSPrimaryStorage.shared().getMasterHexEncodedPublicKey(for: result.source, in: transaction) ?? result.source
var displayName = masterPublicKey
var displayName = OWSUserProfile.fetch(uniqueId: masterPublicKey, transaction: transaction)?.profileName ?? SSKEnvironment.shared.contactsManager.displayName(forPhoneIdentifier: masterPublicKey)
if let groupID = contentProto?.dataMessage?.group?.id {
thread = TSGroupThread.getOrCreateThread(withGroupId: groupID, groupType: .closedGroup, transaction: transaction)
displayName = thread.name()
if displayName.count < 1 {
displayName = MessageStrings.newGroupDefaultTitle
var groupName = thread.name()
if groupName.count < 1 {
groupName = MessageStrings.newGroupDefaultTitle
}
let senderName = OWSUserProfile.fetch(uniqueId: masterPublicKey, transaction: transaction)?.profileName ?? SSKEnvironment.shared.contactsManager.displayName(forPhoneIdentifier: masterPublicKey)
displayName = String(format: NotificationStrings.incomingGroupMessageTitleFormat, senderName, groupName)
let group: SSKProtoGroupContext = contentProto!.dataMessage!.group!
let oldGroupModel = (thread as! TSGroupThread).groupModel
var removedMembers = Set(arrayLiteral: oldGroupModel.groupMemberIds)
let removedMembers = NSMutableSet(array: oldGroupModel.groupMemberIds)
let newGroupModel = TSGroupModel.init(title: group.name,
memberIds:group.members,
image: oldGroupModel.groupImage,
groupId: group.id,
groupType: oldGroupModel.groupType,
adminIds: group.admins)
removedMembers.subtract(Set(arrayLiteral: newGroupModel.groupMemberIds))
newGroupModel.removedMembers = NSMutableSet(set: removedMembers)
removedMembers.minus(Set(newGroupModel.groupMemberIds))
newGroupModel.removedMembers = removedMembers
switch contentProto?.dataMessage?.group?.type {
case .update:
newNotificationBody = oldGroupModel.getInfoStringAboutUpdate(to: newGroupModel, contactsManager: SSKEnvironment.shared.contactsManager)
@ -93,15 +95,21 @@ final class NotificationServiceExtension : UNNotificationServiceExtension {
}
} else {
thread = TSContactThread.getOrCreateThread(withContactId: result.source, transaction: transaction)
displayName = contentProto?.dataMessage?.profile?.displayName ?? displayName
}
let userInfo: [String:Any] = [ NotificationServiceExtension.threadIdKey : thread.uniqueId!, NotificationServiceExtension.isFromRemoteKey : true ]
notificationContent.title = displayName
notificationContent.userInfo = userInfo
notificationContent.badge = 1
if let attachment = contentProto?.dataMessage?.attachments.last {
newNotificationBody = TSAttachment.emoji(forMimeType: attachment.contentType!) + "Attachment"
if let rawMessageBody = contentProto?.dataMessage?.body, rawMessageBody.count > 0 {
newNotificationBody += ": \(rawMessageBody)"
}
}
if newNotificationBody.count < 1 {
newNotificationBody = contentProto?.dataMessage?.body ?? "You've got a new message"
}
newNotificationBody = handleMentionIfNecessary(rawMessageBody: newNotificationBody, threadID: thread.uniqueId!, transaction: transaction)
notificationContent.body = newNotificationBody
if notificationContent.body.count < 1 {
self.completeWithFailure(content: notificationContent)
@ -109,6 +117,25 @@ final class NotificationServiceExtension : UNNotificationServiceExtension {
self.contentHandler!(notificationContent)
}
}
func handleMentionIfNecessary(rawMessageBody: String, threadID: String, transaction: YapDatabaseReadWriteTransaction) -> String {
var string = rawMessageBody
let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]*", options: [])
var outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: string.count))
while let match = outerMatch {
let hexEncodedPublicKey = String((string as NSString).substring(with: match.range).dropFirst()) // Drop the @
let matchEnd: Int
let displayName: String? = OWSProfileManager.shared().profileNameForRecipient(withID: hexEncodedPublicKey, transaction: transaction)
if let displayName = displayName {
string = (string as NSString).replacingCharacters(in: match.range, with: "@\(displayName)")
matchEnd = match.range.location + displayName.count
} else {
matchEnd = match.range.location + match.range.length
}
outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: matchEnd, length: string.count - matchEnd))
}
return string
}
func setUpIfNecessary(completion: @escaping () -> Void) {
AssertIsOnMainThread()

@ -13,6 +13,7 @@ public final class MentionUtilities : NSObject {
var publicChat: PublicChat?
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
publicChat = LokiDatabaseUtilities.getPublicChat(for: threadID, in: transaction)
MentionsManager.populateUserPublicKeyCacheIfNeeded(for: threadID, in: transaction)
}
var string = string
let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]*", options: [])

@ -357,7 +357,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
// it must be escaped.
// see https://developer.apple.com/documentation/uikit/uilocalnotification/1616646-alertbody
// for more details.
let messageText = DisplayableText.filterNotificationText(rawMessageText)
let messageText = MentionUtilities.highlightMentions(in: DisplayableText.filterNotificationText(rawMessageText)!, threadID: thread.uniqueId!)
let senderName = OWSUserProfile.fetch(uniqueId: incomingMessage.authorId, transaction: transaction)?.profileName ?? contactsManager.displayName(forPhoneIdentifier: incomingMessage.authorId)

@ -3617,6 +3617,10 @@ typedef enum : NSUInteger {
self.scrollDownButton.hidden = YES;
self.hasUnreadMessages = NO;
if (lastVisibleViewItem != NULL && self.lastVisibleSortId > 0) {
[OWSReadReceiptManager.sharedManager markAsReadLocallyBeforeSortId:self.lastVisibleSortId thread:self.thread];
}
}
- (void)updateLastVisibleSortId

@ -797,12 +797,14 @@ class MediaGallery: NSObject, MediaGalleryDataSource, MediaTileViewControllerDel
func buildGalleryItem(attachment: TSAttachment, transaction: YapDatabaseReadTransaction) -> MediaGalleryItem? {
guard let attachmentStream = attachment as? TSAttachmentStream else {
owsFailDebug("gallery doesn't yet support showing undownloaded attachments")
// Avoid crash on dev mode
// owsFailDebug("gallery doesn't yet support showing undownloaded attachments")
return nil
}
guard let message = attachmentStream.fetchAlbumMessage(with: transaction) else {
owsFailDebug("message was unexpectedly nil")
// Avoid crash on dev mode
// owsFailDebug("message was unexpectedly nil")
return nil
}

@ -50,7 +50,7 @@ public final class ProfilePictureView : UIView {
return OWSProfileManager.shared().profileAvatar(forRecipientId: hexEncodedPublicKey) ?? Identicon.generateIcon(string: hexEncodedPublicKey, size: size)
}
let size: CGFloat
if let additionalHexEncodedPublicKey = additionalHexEncodedPublicKey, !isRSSFeed {
if let additionalHexEncodedPublicKey = additionalHexEncodedPublicKey, !isRSSFeed, openGroupProfilePicture == nil {
size = Values.smallProfilePictureSize
imageViewWidthConstraint.constant = size
imageViewHeightConstraint.constant = size

@ -75,8 +75,8 @@ public final class MentionsManager : NSObject {
guard let message = object as? TSIncomingMessage, index < userIDScanLimit else { return }
result.insert(message.authorId)
}
result.insert(getUserHexEncodedPublicKey())
}
result.insert(getUserHexEncodedPublicKey())
}
if let transaction = transaction {
populate(in: transaction)

@ -264,8 +264,6 @@ typedef void (^AttachmentDownloadFailure)(NSError *error);
- (void)startDownloadIfPossible
{
if (CurrentAppContext().wasWokenUpByPushNotification) { return; }
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
OWSAttachmentDownloadJob *_Nullable job;

@ -502,7 +502,8 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail);
- (CGSize)imageSize
{
OWSAssertDebug(self.shouldHaveImageSize);
// Avoid crash in dev mode
// OWSAssertDebug(self.shouldHaveImageSize);
@synchronized(self)
{

Loading…
Cancel
Save