This commit is contained in:
nielsandriesse 2021-05-05 14:22:29 +10:00
parent 06f795169b
commit e1ad33e832
13 changed files with 15 additions and 101 deletions

View File

@ -533,11 +533,8 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
let threadID = thread.uniqueId!
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in
let publicKey = message.authorId
if let openGroupV2 = Storage.shared.getV2OpenGroup(for: threadID) {
OpenGroupAPIV2.ban(publicKey, from: openGroupV2.room, on: openGroupV2.server).retainUntilComplete()
} else if let openGroup = Storage.shared.getOpenGroup(for: threadID) {
OpenGroupAPI.ban(publicKey, from: openGroup.server).retainUntilComplete()
}
guard let openGroupV2 = Storage.shared.getV2OpenGroup(for: threadID) else { return }
OpenGroupAPIV2.ban(publicKey, from: openGroupV2.room, on: openGroupV2.server).retainUntilComplete()
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
present(alert, animated: true, completion: nil)

View File

@ -988,7 +988,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
if (!message.isOpenGroupMessage) return;
// Get the open group
SNOpenGroup *openGroup = [LKStorage.shared getOpenGroupForThreadID:groupThread.uniqueId];
SNOpenGroupV2 *openGroupV2 = [LKStorage.shared getV2OpenGroupForThreadID:groupThread.uniqueId];
if (openGroup == nil && openGroupV2 == nil) return;
@ -997,8 +996,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
NSString *userPublicKey = [LKStorage.shared getUserPublicKey];
if (openGroupV2 != nil) {
if (![SNOpenGroupAPIV2 isUserModerator:userPublicKey forRoom:openGroupV2.room onServer:openGroupV2.server]) { return; }
} else if (openGroup != nil) {
if (![SNOpenGroupAPI isUserModerator:userPublicKey forChannel:openGroup.channel onServer:openGroup.server]) { return; }
}
}
@ -1009,11 +1006,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
// Roll back
[self.interaction save];
}) retainUntilComplete];
} else if (openGroup != nil) {
[[SNOpenGroupAPI deleteMessageWithID:message.openGroupServerMessageID forGroup:openGroup.channel onServer:openGroup.server isSentByUser:wasSentByUser].catch(^(NSError *error) {
// Roll back
[self.interaction save];
}) retainUntilComplete];
}
}
}
@ -1070,16 +1062,13 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
if (!message.isOpenGroupMessage) return true;
// Ensure we have the details needed to contact the server
SNOpenGroup *openGroup = [LKStorage.shared getOpenGroupForThreadID:groupThread.uniqueId];
SNOpenGroupV2 *openGroupV2 = [LKStorage.shared getV2OpenGroupForThreadID:groupThread.uniqueId];
if (openGroup == nil && openGroupV2 == nil) return true;
if (openGroupV2 == nil) return true;
if (interationType == OWSInteractionType_IncomingMessage) {
// Only allow deletion on incoming messages if the user has moderation permission
if (openGroupV2 != nil) {
return [SNOpenGroupAPIV2 isUserModerator:[SNGeneralUtilities getUserPublicKey] forRoom:openGroupV2.room onServer:openGroupV2.server];
} else {
return [SNOpenGroupAPI isUserModerator:[SNGeneralUtilities getUserPublicKey] forChannel:openGroup.channel onServer:openGroup.server];
}
} else {
return YES;
@ -1096,15 +1085,12 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
if (!message.isOpenGroupMessage) return false;
// Ensure we have the details needed to contact the server
SNOpenGroup *openGroup = [LKStorage.shared getOpenGroupForThreadID:groupThread.uniqueId];
SNOpenGroupV2 *openGroupV2 = [LKStorage.shared getV2OpenGroupForThreadID:groupThread.uniqueId];
if (openGroup == nil && openGroupV2 == nil) return false;
if (openGroupV2 == nil) return false;
// Check that we're a moderator
if (openGroupV2 != nil) {
return [SNOpenGroupAPIV2 isUserModerator:[SNGeneralUtilities getUserPublicKey] forRoom:openGroupV2.room onServer:openGroupV2.server];
} else {
return [SNOpenGroupAPI isUserModerator:[SNGeneralUtilities getUserPublicKey] forChannel:openGroup.channel onServer:openGroup.server];
}
}

View File

@ -312,9 +312,6 @@ final class InputView : UIView, InputViewButtonDelegate, InputTextViewDelegate,
if let openGroupV2 = Storage.shared.getV2OpenGroup(for: thread.uniqueId!) {
mentionsView.openGroupServer = openGroupV2.server
mentionsView.openGroupRoom = openGroupV2.room
} else if let openGroup = Storage.shared.getOpenGroup(for: thread.uniqueId!) {
mentionsView.openGroupServer = openGroup.server
mentionsView.openGroupChannel = openGroup.channel
}
mentionsView.candidates = candidates
let mentionCellHeight = Values.smallProfilePictureSize + 2 * Values.smallSpacing

View File

@ -165,9 +165,6 @@ private extension MentionSelectionView {
if let server = openGroupServer, let room = openGroupRoom {
let isUserModerator = OpenGroupAPIV2.isUserModerator(mentionCandidate.publicKey, for: room, on: server)
moderatorIconImageView.isHidden = !isUserModerator
} else if let server = openGroupServer, let channel = openGroupChannel {
let isUserModerator = OpenGroupAPI.isUserModerator(mentionCandidate.publicKey, for: channel, on: server)
moderatorIconImageView.isHidden = !isUserModerator
} else {
moderatorIconImageView.isHidden = true
}

View File

@ -222,9 +222,6 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
if let openGroupV2 = Storage.shared.getV2OpenGroup(for: thread.uniqueId!) {
let isUserModerator = OpenGroupAPIV2.isUserModerator(senderSessionID, for: openGroupV2.room, on: openGroupV2.server)
moderatorIconImageView.isHidden = !isUserModerator || profilePictureView.isHidden
} else if let openGroup = Storage.shared.getOpenGroup(for: thread.uniqueId!) {
let isUserModerator = OpenGroupAPI.isUserModerator(senderSessionID, for: openGroup.channel, on: openGroup.server)
moderatorIconImageView.isHidden = !isUserModerator || profilePictureView.isHidden
} else {
moderatorIconImageView.isHidden = true
}

View File

@ -100,11 +100,8 @@ final class ConversationTitleView : UIView {
switch thread.groupModel.groupType {
case .closedGroup: userCount = UInt64(thread.groupModel.groupMemberIds.count)
case .openGroup:
if let openGroupV2 = Storage.shared.getV2OpenGroup(for: self.thread.uniqueId!) {
userCount = Storage.shared.getUserCount(forV2OpenGroupWithID: openGroupV2.id)
} else if let openGroup = Storage.shared.getOpenGroup(for: self.thread.uniqueId!) {
userCount = given(Storage.shared.getUserCount(forOpenGroupWithID: openGroup.id)) { UInt64($0) }
}
guard let openGroupV2 = Storage.shared.getV2OpenGroup(for: self.thread.uniqueId!) else { return nil }
userCount = Storage.shared.getUserCount(forV2OpenGroupWithID: openGroupV2.id)
default: break
}
if let userCount = userCount {

View File

@ -156,9 +156,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
let _ = IP2Country.shared.populateCacheIfNeeded()
}
// Get default open group rooms if needed
if Features.useV2OpenGroups {
OpenGroupAPIV2.getDefaultRoomsIfNeeded()
}
OpenGroupAPIV2.getDefaultRoomsIfNeeded()
}
override func viewDidAppear(_ animated: Bool) {
@ -359,13 +357,10 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
private func delete(_ thread: TSThread) {
let openGroupV2 = Storage.shared.getV2OpenGroup(for: thread.uniqueId!)
let openGroup = Storage.shared.getOpenGroup(for: thread.uniqueId!)
Storage.write { transaction in
Storage.shared.cancelPendingMessageSendJobs(for: thread.uniqueId!, using: transaction)
if let openGroupV2 = openGroupV2 {
OpenGroupManagerV2.shared.delete(openGroupV2, associatedWith: thread, using: transaction)
} else if let openGroup = openGroup {
OpenGroupManager.shared.delete(openGroup, associatedWith: thread, using: transaction)
} else if let thread = thread as? TSGroupThread, thread.isClosedGroup == true {
let groupID = thread.groupModel.groupId
let groupPublicKey = LKGroupUtilities.getDecodedGroupID(groupID)

View File

@ -152,10 +152,9 @@ static NSTimeInterval launchStartedAt;
[LKAppModeManager configureWithDelegate:self];
// OWSLinkPreview and OpenGroup are now in SessionMessagingKit, so to still be able to deserialize them we
// OWSLinkPreview is now in SessionMessagingKit, so to still be able to deserialize them we
// need to tell NSKeyedUnarchiver about the changes.
[NSKeyedUnarchiver setClass:OWSLinkPreview.class forClassName:@"SessionServiceKit.OWSLinkPreview"];
[NSKeyedUnarchiver setClass:SNOpenGroup.class forClassName:@"LKPublicChat"];
BOOL isLoggingEnabled;
#ifdef DEBUG
@ -411,7 +410,7 @@ static NSTimeInterval launchStartedAt;
} requiresSync:YES];
}
if (CurrentAppContext().isMainApp && SNFeatures.useV2OpenGroups) {
if (CurrentAppContext().isMainApp) {
[SNOpenGroupAPIV2 getDefaultRoomsIfNeeded];
}
@ -742,12 +741,10 @@ static NSTimeInterval launchStartedAt;
- (void)startOpenGroupPollersIfNeeded
{
[SNOpenGroupManager.shared startPolling];
[SNOpenGroupManagerV2.shared startPolling];
}
- (void)stopOpenGroupPollers {
[SNOpenGroupManager.shared stopPolling];
[SNOpenGroupManagerV2.shared stopPolling];
}

View File

@ -125,19 +125,10 @@ final class JoinOpenGroupVC : BaseVC, UIPageViewControllerDataSource, UIPageView
}
fileprivate func joinOpenGroup(with string: String) {
// A V1 open group URL will look like: https:// + <host>
// A V2 open group URL will look like: <optional scheme> + <host> + <optional port> + <room> + <public key>
// The host doesn't parse if no explicit scheme is provided
if let url = URL(string: string), let host = url.host ?? given(string.split(separator: "/").first, { String($0) }) {
if let (room, server, publicKey) = OpenGroupManagerV2.parseV2OpenGroup(from: string), Features.useV2OpenGroups {
joinV2OpenGroup(room: room, server: server, publicKey: publicKey)
} else {
// Inputs that should work:
// loki.opensession.id
// https://loki.opensession.id
// http://loki.opensession.id (still goes to HTTPS)
joinV1OpenGroup("https://" + host)
}
if let (room, server, publicKey) = OpenGroupManagerV2.parseV2OpenGroup(from: string) {
joinV2OpenGroup(room: room, server: server, publicKey: publicKey)
} else {
let title = NSLocalizedString("invalid_url", comment: "")
let message = "Please check the URL you entered and try again."
@ -145,32 +136,6 @@ final class JoinOpenGroupVC : BaseVC, UIPageViewControllerDataSource, UIPageView
}
}
private func joinV1OpenGroup(_ string: String) {
guard !isJoining else { return }
isJoining = true
ModalActivityIndicatorViewController.present(fromViewController: navigationController!, canCancel: false) { [weak self] _ in
Storage.shared.write { transaction in
OpenGroupManager.shared.add(with: string, using: transaction)
.done(on: DispatchQueue.main) { [weak self] _ in
self?.presentingViewController!.dismiss(animated: true, completion: nil)
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.forceSyncConfigurationNowIfNeeded().retainUntilComplete() // FIXME: It's probably cleaner to do this inside addOpenGroup(...)
}
.catch(on: DispatchQueue.main) { [weak self] error in
self?.dismiss(animated: true, completion: nil) // Dismiss the loader
var title = "Couldn't Join"
var message = ""
if case OnionRequestAPI.Error.httpRequestFailedAtDestination(let statusCode, _) = error, statusCode == 401 || statusCode == 403 {
title = "Unauthorized"
message = "Please ask the open group operator to add you to the group."
}
self?.isJoining = false
self?.showError(title: title, message: message)
}
}
}
}
fileprivate func joinV2OpenGroup(room: String, server: String, publicKey: String) {
guard !isJoining else { return }
isJoining = true
@ -242,13 +207,8 @@ private final class EnterURLVC : UIViewController, UIGestureRecognizerDelegate,
nextButtonContainer.pin(.trailing, to: .trailing, of: nextButton, withInset: 80)
nextButtonContainer.pin(.bottom, to: .bottom, of: nextButton)
// Stack view
let stackView: UIStackView
if Features.useV2OpenGroups {
stackView = UIStackView(arrangedSubviews: [ urlTextField, UIView.spacer(withHeight: Values.mediumSpacing), suggestionGridTitleLabel,
UIView.spacer(withHeight: Values.mediumSpacing), suggestionGrid, UIView.vStretchingSpacer(), nextButtonContainer ])
} else {
stackView = UIStackView(arrangedSubviews: [ urlTextField, UIView.vStretchingSpacer(), nextButtonContainer ])
}
let stackView = UIStackView(arrangedSubviews: [ urlTextField, UIView.spacer(withHeight: Values.mediumSpacing), suggestionGridTitleLabel,
UIView.spacer(withHeight: Values.mediumSpacing), suggestionGrid, UIView.vStretchingSpacer(), nextButtonContainer ])
stackView.axis = .vertical
stackView.alignment = .fill
stackView.layoutMargins = UIEdgeInsets(uniform: Values.largeSpacing)

View File

@ -337,7 +337,7 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate {
DispatchQueue.main.async {
modalActivityIndicator.dismiss {
var isMaxFileSizeExceeded = false
if let error = error as? DotNetAPI.Error {
if let error = error as? FileServerAPIV2.Error {
isMaxFileSizeExceeded = (error == .maxFileSizeExceeded)
}
let title = isMaxFileSizeExceeded ? "Maximum File Size Exceeded" : "Couldn't Update Profile"

View File

@ -13,12 +13,6 @@ public final class BackgroundPoller : NSObject {
promises = []
promises.append(pollForMessages())
promises.append(contentsOf: pollForClosedGroupMessages())
let openGroups: [String:OpenGroup] = Storage.shared.getAllUserOpenGroups()
openGroups.values.forEach { openGroup in
let poller = OpenGroupPoller(for: openGroup)
poller.stop()
promises.append(poller.pollForNewMessages(isBackgroundPoll: true))
}
let v2OpenGroupServers = Set(Storage.shared.getAllV2OpenGroups().values.map { $0.server })
v2OpenGroupServers.forEach { server in
let poller = OpenGroupPollerV2(for: server)

View File

@ -9,7 +9,6 @@ public final class MentionUtilities : NSObject {
}
@objc public static func highlightMentions(in string: String, isOutgoingMessage: Bool, threadID: String, attributes: [NSAttributedString.Key:Any]) -> NSAttributedString {
let openGroup = Storage.shared.getOpenGroup(for: threadID)
let openGroupV2 = Storage.shared.getV2OpenGroup(for: threadID)
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
MentionsManager.populateUserPublicKeyCacheIfNeeded(for: threadID, in: transaction)
@ -23,7 +22,7 @@ public final class MentionUtilities : NSObject {
let publicKey = String((string as NSString).substring(with: match.range).dropFirst()) // Drop the @
let matchEnd: Int
if knownPublicKeys.contains(publicKey) {
let context: Contact.Context = (openGroupV2 != nil || openGroup != nil) ? .openGroup : .regular
let context: Contact.Context = (openGroupV2 != nil) ? .openGroup : .regular
let displayName = Storage.shared.getContact(with: publicKey)?.displayName(for: context)
if let displayName = displayName {
string = (string as NSString).replacingCharacters(in: match.range, with: "@\(displayName)")

View File

@ -10,8 +10,6 @@ public enum SNUserDefaults {
}
public enum Date : Swift.String {
/// Deprecated. Remove with removal of v1 open groups.
case lastProfilePictureUpload
case lastConfigurationSync
case lastDisplayNameUpdate
case lastProfilePictureUpdate