Merge pull request #246 from RyanRory/bug-fix-2.0

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

@ -1 +1 @@
Subproject commit 71f54b041ff9b9a77fecea805aa42ac536392c40
Subproject commit d626be8f621bad9ed9d04d4370cbbb23cc438746

@ -167,7 +167,7 @@ final class ConversationTitleView : UIView {
case .messageFailed: self.subtitleLabel.text = NSLocalizedString("Message failed to send", comment: "")
case nil:
let subtitle = NSMutableAttributedString()
if let muteEndDate = self.thread.mutedUntilDate {
if let muteEndDate = self.thread.mutedUntilDate, self.thread.isMuted {
subtitle.append(NSAttributedString(string: "\u{e067} ", attributes: [ .font : UIFont.ows_elegantIconsFont(10), .foregroundColor : Colors.unimportant ]))
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale.current

@ -383,6 +383,9 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol
@objc func show(_ thread: TSThread, with action: ConversationViewAction, highlightedMessageID: String?, animated: Bool) {
DispatchMainThreadSafe {
if let presentedVC = self.presentedViewController {
presentedVC.dismiss(animated: false, completion: nil)
}
let conversationVC = ConversationViewController()
conversationVC.configure(for: thread, action: action, focusMessageId: highlightedMessageID)
self.navigationController?.setViewControllers([ self, conversationVC ], animated: true)

@ -156,7 +156,7 @@ final class JoinPublicChatVC : BaseVC, UIPageViewControllerDataSource, UIPageVie
self?.dismiss(animated: true, completion: nil) // Dismiss the loader
var title = "Couldn't Join"
var message = ""
if case HTTP.Error.httpRequestFailed(let statusCode, _) = error, statusCode == 401 || statusCode == 403 {
if case OnionRequestAPI.Error.httpRequestFailedAtTargetSnode(statusCode: let statusCode, json: _) = error, statusCode == 401 || statusCode == 403 {
title = "Unauthorized"
message = "Please ask the open group operator to add you to the group."
}

@ -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 = MentionUtilities.highlightMentions(in: DisplayableText.filterNotificationText(rawMessageText)!, threadID: thread.uniqueId!)
let messageText = DisplayableText.filterNotificationText(rawMessageText)
let senderName = OWSUserProfile.fetch(uniqueId: incomingMessage.authorId, transaction: transaction)?.profileName ?? contactsManager.displayName(forPhoneIdentifier: incomingMessage.authorId)
@ -383,7 +383,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
}
}
let notificationBody: String?
var notificationBody: String?
switch previewType {
case .noNameNoPreview, .nameNoPreview:
notificationBody = NotificationStrings.incomingMessageBody
@ -413,6 +413,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
]
DispatchQueue.main.async {
notificationBody = MentionUtilities.highlightMentions(in: notificationBody!, threadID: thread.uniqueId!)
let sound = self.requestSound(thread: thread)
self.adaptee.notify(category: category,
title: notificationTitle,

@ -185,6 +185,11 @@ const CGFloat kIconViewLength = 24;
return [self.thread isKindOfClass:[TSGroupThread class]];
}
- (BOOL)isOpenGroupChat
{
return [self isGroupThread] && ![self isPrivateGroupChat];
}
-(BOOL)isPrivateGroupChat
{
if (self.isGroupThread) {
@ -500,7 +505,7 @@ const CGFloat kIconViewLength = 24;
* =======
*/
if (!self.thread.isGroupThread) {
if (![self isOpenGroupChat]) {
[mainSection addItem:[OWSTableItem
itemWithCustomCellBlock:^{
UITableViewCell *cell = [OWSTableItem newCell];
@ -536,7 +541,14 @@ const CGFloat kIconViewLength = 24;
[topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom];
UILabel *subtitleLabel = [UILabel new];
subtitleLabel.text = [NSString stringWithFormat:NSLocalizedString(@"When enabled, messages between you and %@ will disappear after they have been seen.", ""), [LKUserDisplayNameUtilities getPrivateChatDisplayNameFor:self.thread.contactIdentifier]];
NSString *threadName;
// TODO: Modify the text content
if (self.thread.isGroupThread) {
threadName = @"the group";
} else {
threadName = [LKUserDisplayNameUtilities getPrivateChatDisplayNameFor:self.thread.contactIdentifier];
}
subtitleLabel.text = [NSString stringWithFormat:NSLocalizedString(@"When enabled, messages between you and %@ will disappear after they have been seen.", ""), threadName];
subtitleLabel.textColor = LKColors.text;
subtitleLabel.font = [UIFont systemFontOfSize:LKValues.smallFontSize];
subtitleLabel.numberOfLines = 0;

@ -27,13 +27,13 @@ public class CaptionContainerView: UIView {
}
func updatePagerTransition(ratioComplete: CGFloat) {
if let currentText = self.currentText, currentText.count > 1 {
if let currentText = self.currentText, currentText.count > 0 {
currentCaptionView.alpha = 1 - ratioComplete
} else {
currentCaptionView.alpha = 0
}
if let pendingText = self.pendingText, pendingText.count > 1 {
if let pendingText = self.pendingText, pendingText.count > 0 {
pendingCaptionView.alpha = ratioComplete
} else {
pendingCaptionView.alpha = 0
@ -48,6 +48,8 @@ public class CaptionContainerView: UIView {
self.currentCaptionView = self.pendingCaptionView
self.pendingCaptionView = oldCaptionView
self.pendingText = nil
self.currentCaptionView.alpha = 1
self.pendingCaptionView.alpha = 0
}
// MARK: Initializers

@ -935,8 +935,9 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
NSData *groupId = groupThread.groupModel.groupId;
return [self isGroupIdInProfileWhitelist:groupId];
} else {
NSString *recipientId = thread.contactIdentifier;
return [self isUserInProfileWhitelist:recipientId];
// NSString *recipientId = thread.contactIdentifier;
// return [self isUserInProfileWhitelist:recipientId];
return true;
}
}

@ -187,17 +187,3 @@ public class DotNetAPI : NSObject {
}
}
}
// MARK: Error Handling
internal extension Promise {
internal func handlingInvalidAuthTokenIfNeeded(for server: String) -> Promise<T> {
return recover2 { error -> Promise<T> in
if case HTTP.Error.httpRequestFailed(let statusCode, _) = error, statusCode == 401 || statusCode == 403 {
print("[Loki] Auth token for: \(server) expired; dropping it.")
DotNetAPI.removeAuthToken(for: server)
}
throw error
}
}
}

@ -26,7 +26,7 @@ public enum OnionRequestAPI {
}
// MARK: Error
internal enum Error : LocalizedError {
public enum Error : LocalizedError {
case httpRequestFailedAtTargetSnode(statusCode: UInt, json: JSON)
case insufficientSnodes
case invalidURL
@ -35,7 +35,7 @@ public enum OnionRequestAPI {
case snodePublicKeySetMissing
case unsupportedSnodeVersion(String)
internal var errorDescription: String? {
public var errorDescription: String? {
switch self {
case .httpRequestFailedAtTargetSnode(let statusCode): return "HTTP request failed at target snode with status code: \(statusCode)."
case .insufficientSnodes: return "Couldn't find enough snodes to build a path."

@ -523,3 +523,17 @@ public final class PublicChatAPI : DotNetAPI {
return moderators[server]?[channel]?.contains(hexEncodedPublicString) ?? false
}
}
// MARK: Error Handling
internal extension Promise {
internal func handlingInvalidAuthTokenIfNeeded(for server: String) -> Promise<T> {
return recover2 { error -> Promise<T> in
if case OnionRequestAPI.Error.httpRequestFailedAtTargetSnode(let statusCode, _) = error, statusCode == 401 || statusCode == 403 {
print("[Loki] Auth token for: \(server) expired; dropping it.")
PublicChatAPI.removeAuthToken(for: server)
}
throw error
}
}
}

@ -8,6 +8,7 @@ public final class PublicChatPoller : NSObject {
private var pollForModeratorsTimer: Timer? = nil
private var pollForDisplayNamesTimer: Timer? = nil
private var hasStarted = false
private var isPolling = false
// MARK: Settings
private let pollForNewMessagesInterval: TimeInterval = 4
@ -54,9 +55,12 @@ public final class PublicChatPoller : NSObject {
}
public func pollForNewMessages() -> Promise<Void> {
guard !self.isPolling else { return Promise.value(()) }
self.isPolling = true
let publicChat = self.publicChat
let userPublicKey = getUserHexEncodedPublicKey()
return PublicChatAPI.getMessages(for: publicChat.channel, on: publicChat.server).done(on: DispatchQueue.global(qos: .default)) { messages in
self.isPolling = false
let uniquePublicKeys = Set(messages.map { $0.senderPublicKey })
func proceed() {
let storage = OWSPrimaryStorage.shared()

@ -47,10 +47,6 @@ public class LokiSessionResetImplementation : NSObject, SessionResetProtocol {
Logger.debug("[Loki] A new session was adopted but the thread couldn't be found for: \(recipientID).")
return
}
// If the current user initiated the reset then send back a null message to acknowledge the completion of the session reset
if thread.sessionResetStatus == .initiated {
SessionManagementProtocol.sendNullMessage(to: recipientID, in: transaction)
}
// Notify the user
let infoMessage = TSInfoMessage(timestamp: NSDate.ows_millisecondTimeStamp(), in: thread, messageType: .typeLokiSessionResetDone)
infoMessage.save(with: transaction)

@ -1061,7 +1061,7 @@ NS_ASSUME_NONNULL_BEGIN
}
OWSAssertDebug(disappearingMessagesConfiguration);
[disappearingMessagesConfiguration saveWithTransaction:transaction];
NSString *name = [dataMessage.profile displayName] ?: [self.contactsManager displayNameForPhoneIdentifier:envelope.source transaction:transaction];
NSString *name = [dataMessage.profile displayName] ?: [SSKEnvironment.shared.profileManager profileNameForRecipientWithID:envelope.source transaction:transaction] ?: envelope.source;
// MJK TODO - safe to remove senderTimestamp
OWSDisappearingConfigurationUpdateInfoMessage *message =
@ -1352,7 +1352,7 @@ NS_ASSUME_NONNULL_BEGIN
oldGroupThread.groupModel.groupMemberIds = [newMemberIds.allObjects mutableCopy];
[oldGroupThread saveWithTransaction:transaction];
NSString *nameString =
NSString *nameString = [SSKEnvironment.shared.profileManager profileNameForRecipientWithID:senderMasterPublicKey transaction:transaction] ?:
[self.contactsManager displayNameForPhoneIdentifier:senderMasterPublicKey transaction:transaction];
NSString *updateGroupInfo =
[NSString stringWithFormat:NSLocalizedString(@"GROUP_MEMBER_LEFT", @""), nameString];

@ -377,7 +377,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
//
// So we're using YDB behavior to ensure this invariant, which is a bit
// unorthodox.
if (message.attachmentIds.count > 0) {
if (message.allAttachmentIds.count > 0) {
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[allAttachmentIds addObjectsFromArray:[OutgoingMessagePreparer prepareMessageForSending:message transaction:transaction]];
} error:nil];

Loading…
Cancel
Save