Skip to content

Commit

Permalink
Feature/communities (#212)
Browse files Browse the repository at this point in the history
* Add communities

* Add Join to a community

* fixing weird bug in gobot

* partially adding directory to onboardin

* commented out the directing to the directory

* pushing a build to test flight

* updating preloaded feeds

Co-authored-by: Martin Dutra <martindsq@hotmail.com>
  • Loading branch information
rabble and martindsq committed Feb 3, 2021
1 parent 22212dd commit b698b93
Show file tree
Hide file tree
Showing 26 changed files with 582 additions and 71 deletions.
16 changes: 14 additions & 2 deletions Planetary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
0A7C5D5224EEC21C005E5035 /* MissionControlCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7C5D5124EEC21C005E5035 /* MissionControlCenter.swift */; };
0A7C5D5324EEDD27005E5035 /* Star.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A56ABDC24E32F8000D30649 /* Star.swift */; };
0A7C5D5524EEDD4B005E5035 /* Star.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A56ABDC24E32F8000D30649 /* Star.swift */; };
0AAF8C4325C6444B00FD8D0F /* CommunityCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AAF8C4225C6444B00FD8D0F /* CommunityCellView.swift */; };
0AAF8C4725C704B500FD8D0F /* UnfollowOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AAF8C4625C704B500FD8D0F /* UnfollowOperation.swift */; };
0AB736B924577451000190F8 /* RefreshOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AB736B824577451000190F8 /* RefreshOperation.swift */; };
0AB736BC2457753F000190F8 /* AsynchronousOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AB736BB2457753F000190F8 /* AsynchronousOperation.swift */; };
0AB736BE2457772B000190F8 /* SyncOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AB736BD2457772B000190F8 /* SyncOperation.swift */; };
Expand Down Expand Up @@ -284,6 +286,7 @@
23EF5AAF249D185E00469977 /* BearerBlockedAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EF5AAC249D185E00469977 /* BearerBlockedAPI.swift */; };
23EF5AB0249D185E00469977 /* BearerBlockedAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EF5AAC249D185E00469977 /* BearerBlockedAPI.swift */; };
2D009BF924550868001351CB /* EveryoneViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D009BF824550868001351CB /* EveryoneViewController.swift */; };
2D16330E25C72D1B00E68CBE /* DirectoryOnboardingStep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D16330D25C72D1B00E68CBE /* DirectoryOnboardingStep.swift */; };
53033E9A237F682F004609F8 /* ResumeOnboardingStep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53033E99237F682F004609F8 /* ResumeOnboardingStep.swift */; };
53033E9C23831CD1004609F8 /* Onboarding+Status.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53033E9B23831CD1004609F8 /* Onboarding+Status.swift */; };
53033E9F2383322B004609F8 /* Onboarding+AppConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53033E9E2383322B004609F8 /* Onboarding+AppConfiguration.swift */; };
Expand Down Expand Up @@ -811,6 +814,8 @@
0A674A28253F3C4400698CF7 /* Draft.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Draft.swift; sourceTree = "<group>"; };
0A78CCBB2416ABC80058959B /* AppDelegate+Reset.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+Reset.swift"; sourceTree = "<group>"; };
0A7C5D5124EEC21C005E5035 /* MissionControlCenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MissionControlCenter.swift; sourceTree = "<group>"; };
0AAF8C4225C6444B00FD8D0F /* CommunityCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityCellView.swift; sourceTree = "<group>"; };
0AAF8C4625C704B500FD8D0F /* UnfollowOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnfollowOperation.swift; sourceTree = "<group>"; };
0AB736B824577451000190F8 /* RefreshOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshOperation.swift; sourceTree = "<group>"; };
0AB736BB2457753F000190F8 /* AsynchronousOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsynchronousOperation.swift; sourceTree = "<group>"; };
0AB736BD2457772B000190F8 /* SyncOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncOperation.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -909,6 +914,7 @@
23EF5AA7249D177F00469977 /* BlockedAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockedAPI.swift; sourceTree = "<group>"; };
23EF5AAC249D185E00469977 /* BearerBlockedAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BearerBlockedAPI.swift; sourceTree = "<group>"; };
2D009BF824550868001351CB /* EveryoneViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EveryoneViewController.swift; sourceTree = "<group>"; };
2D16330D25C72D1B00E68CBE /* DirectoryOnboardingStep.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectoryOnboardingStep.swift; sourceTree = "<group>"; };
316D716D251CC0B347E630DA /* Pods-Planetary.appstore.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Planetary.appstore.xcconfig"; path = "Pods/Target Support Files/Pods-Planetary/Pods-Planetary.appstore.xcconfig"; sourceTree = "<group>"; };
3C118088E10BAE1C911EDE02 /* Pods_FBTTUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FBTTUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4468B60D82AA8885DDD68F4A /* Pods-UnitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UnitTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-UnitTests/Pods-UnitTests.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1343,6 +1349,7 @@
0A56ABDE24E470A200D30649 /* RedeemInviteOperation.swift */,
0A1CA4C424E5D714006CAC43 /* FollowOperation.swift */,
0A1CA4C924EB2353006CAC43 /* SendMissionOperation.swift */,
0AAF8C4625C704B500FD8D0F /* UnfollowOperation.swift */,
);
path = Operations;
sourceTree = "<group>";
Expand Down Expand Up @@ -1534,6 +1541,7 @@
530F019722DE87EB007EBAE2 /* PhotoConfirmOnboardingStep.swift */,
530F019522DE87CD007EBAE2 /* PhotoOnboardingStep.swift */,
530F019B22DEAD70007EBAE2 /* SplashOnboardingStep.swift */,
2D16330D25C72D1B00E68CBE /* DirectoryOnboardingStep.swift */,
);
path = Steps;
sourceTree = "<group>";
Expand Down Expand Up @@ -1938,6 +1946,7 @@
0AF2DEEF247D9DB4003F457D /* FloatingRefreshButton.swift */,
0A487102249808E700BCD063 /* PinterestCollectionViewLayout.swift */,
1B32D377249AAA4700811DC9 /* SmallPostHeaderView.swift */,
0AAF8C4225C6444B00FD8D0F /* CommunityCellView.swift */,
);
path = UI;
sourceTree = "<group>";
Expand Down Expand Up @@ -2998,6 +3007,7 @@
53E26C5D23045D19009240B2 /* Data+Person.swift in Sources */,
532751D32224A0CD0026500F /* ContentViewController.swift in Sources */,
536255D323AAC8AD001007D0 /* AnalyticsService+AppDelegate.swift in Sources */,
0AAF8C4725C704B500FD8D0F /* UnfollowOperation.swift in Sources */,
0AF2DEEE247C3EE6003F457D /* Hashtag+Link.swift in Sources */,
5396A6232244356600C57A4B /* Layout+ContentView.swift in Sources */,
8D9143F7230C5F4E0075BC8A /* Text.swift in Sources */,
Expand Down Expand Up @@ -3088,6 +3098,7 @@
53EE01FF22051A1700DFDF16 /* Image.swift in Sources */,
53631EEF23A941A7009C6999 /* NSAttributedString+Mutable.swift in Sources */,
53E341FE224FF9EE002BB5F4 /* UIImage+Verse.swift in Sources */,
2D16330E25C72D1B00E68CBE /* DirectoryOnboardingStep.swift in Sources */,
53C9FA2C22FBBC3C00EAC35F /* NSAttributedString+FontColor.swift in Sources */,
53A4763B23A3385A003814DC /* AnalyticsService+Offboarding.swift in Sources */,
0AB736C024577CB4000190F8 /* LoginOperation.swift in Sources */,
Expand Down Expand Up @@ -3319,6 +3330,7 @@
53575509226A3113002A6989 /* KeyValueTableViewDataSource.swift in Sources */,
531B92B122CAC203005D5255 /* PostButtonsView.swift in Sources */,
531D0A1321EACC0A008E40A8 /* GoBotViewController.swift in Sources */,
0AAF8C4325C6444B00FD8D0F /* CommunityCellView.swift in Sources */,
53C2B12C2294E8A50018D0A8 /* AppConfiguration+Keychain.swift in Sources */,
5314EF8322EB713C0065D02A /* UIView+Shake.swift in Sources */,
530F019C22DEAD70007EBAE2 /* SplashOnboardingStep.swift in Sources */,
Expand Down Expand Up @@ -3755,7 +3767,7 @@
"@executable_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.0.2;
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
Expand Down Expand Up @@ -3800,7 +3812,7 @@
"@executable_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.0.2;
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
Expand Down
4 changes: 3 additions & 1 deletion Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>258</string>
<string>260</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>
Expand All @@ -40,6 +40,8 @@
<string>This app allows you to take photos to share with friends or use as your profile image.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app allows you to select photos to share with friends or use as your profile image.</string>
<key>PLCommunities</key>
<string>$(COMMUNITIES)</string>
<key>PLConstellation</key>
<string>$(CONSTELLATION)</string>
<key>PLDefaultNetworkKey</key>
Expand Down
2 changes: 1 addition & 1 deletion Resources/Preload.bundle/Feeds/consolidatedFeed.json

Large diffs are not rendered by default.

56 changes: 53 additions & 3 deletions Source/App/AppController+URL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ extension AppController {

func open(url: URL, completion: ((Bool) -> Void)? = nil) {
Log.info("open(url): \(url.absoluteString)")
if url.absoluteString.isHashtag { self.pushChannelViewController(for: url.absoluteString) }
else if let identifier = url.identifier { self.open(identifier: identifier) }
else { UIApplication.shared.open(url, options: [:], completionHandler: completion) }
if url.absoluteString.isHashtag {
self.pushChannelViewController(for: url.absoluteString)
} else if let identifier = url.identifier {
self.open(identifier: identifier)
} else if Star.isValid(invite: url.absoluteString) {
self.redeem(invite: url.absoluteString)
} else {
UIApplication.shared.open(url, options: [:], completionHandler: completion)
}
}

func open(string: String) {
Expand Down Expand Up @@ -58,6 +64,50 @@ extension AppController {
func open(identity: Identity) {
self.pushViewController(for: .about, with: identity)
}

func redeem(invite: String) {
guard let featureController = self.mainViewController?.selectedViewController as? UINavigationController else {
Log.unexpected(.missingValue, "Selected view controller is not a navigation controller")
return
}
let controller = UIAlertController(title: "This is an invite to a Pub",
message: "Are you sure you want to redeem this invite?",
preferredStyle: .alert)
var action = UIAlertAction(title: Text.cancel.text, style: .cancel) {
action in
controller.dismiss(animated: true, completion: nil)
}
controller.addAction(action)

action = UIAlertAction(title: Text.yes.text, style: .default) { [weak self] _ in
controller.dismiss(animated: false, completion: nil)
self?.showProgress()
let star = Star(invite: invite)
let operation = RedeemInviteOperation(star: star, shouldFollow: true)
operation.completionBlock = { [weak self] in
switch operation.result {
case .success:
DispatchQueue.main.async {
self?.hideProgress()
}
case .failure(let error):
Log.optional(error)
CrashReporting.shared.reportIfNeeded(error: error)
DispatchQueue.main.async {
self?.hideProgress()
self?.alert(error: error)
}
case .none:
DispatchQueue.main.async {
self?.hideProgress()
}
}
}
self?.operationQueue.addOperation(operation)
}
controller.addAction(action)
featureController.present(alertController: controller, animated: true)
}

// TODO this is incorrectly scoped, push to the app controller should
// reset the root controller, not push into a child feature controller
Expand Down
12 changes: 12 additions & 0 deletions Source/App/AppController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,19 @@ class AppController: UIViewController {
var mainViewController: MainViewController? {
return self.children.first as? MainViewController
}

// MARK: Directory tab view controller
// this doesn't seem to work correctly...
func showDirectoryViewController(with controller: UIViewController? = nil, animated: Bool = true) {
let controller = DirectoryViewController()
self.setRootViewController(controller, animated: animated)
self.missionControlCenter.start()
}

var directoryViewController: DirectoryViewController? {
return self.children.first as? DirectoryViewController
}

// MARK: Onboarding view controller

func showOnboardingViewController(_ status: Onboarding.Status = .notStarted,
Expand Down
35 changes: 23 additions & 12 deletions Source/Bot/Operations/RedeemInviteOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ import Foundation

class RedeemInviteOperation: AsynchronousOperation {

/// Star that you want to redeem invitation to
var star: Star

/// If true, it will automatically follow the star
var shouldFollow: Bool

/// Result of the operation
private(set) var result: Result<Void, Error>?

init(star: Star) {
init(star: Star, shouldFollow: Bool) {
self.star = star
self.shouldFollow = shouldFollow
super.init()
}

Expand All @@ -30,27 +37,27 @@ class RedeemInviteOperation: AsynchronousOperation {
}
Log.debug("Redeeming invite to star \(self.star.feed)...")
let queue = OperationQueue.current?.underlyingQueue ?? DispatchQueue.global(qos: .background)
Bots.current.inviteRedeem(queue: queue, token: self.star.invite) { [weak self, star] (error) in
Bots.current.inviteRedeem(queue: queue, token: self.star.invite) { [weak self, star, shouldFollow] (error) in
Log.optional(error)
CrashReporting.shared.reportIfNeeded(error: error)
if let error = error {
Log.info("RedeemInviteOperation to \(star.feed) finished with error \(error).")
self?.result = .failure(error)
self?.finish()
} else {
Log.debug("Publishing Contact (\(star.feed)) message...")
let contact = Contact(contact: star.feed, following: true)
Bots.current.publish(content: contact) { (_, error) in
Log.debug("Publishing Pub (\(star.feed)) message...")
let pub = star.toPub()
Bots.current.publish(content: pub) { (_, error) in
Log.optional(error)
CrashReporting.shared.reportIfNeeded(error: error)
if let error = error {
Log.info("RedeemInviteOperation to \(star.feed) finished with error \(error).")
self?.result = .failure(error)
self?.finish()
} else {
Log.debug("Publishing Pub (\(star.feed)) message...")
let pub = star.toPub()
Bots.current.publish(content: pub) { (_, error) in
Log.info("Publishing Pub \(star.feed) message finished with error \(error).")
// We don't care the result, move on
}
if shouldFollow {
Log.debug("Publishing Contact (\(star.feed)) message...")
let contact = Contact(contact: star.feed, following: true)
Bots.current.publish(content: contact) { (_, error) in
Log.optional(error)
CrashReporting.shared.reportIfNeeded(error: error)
if let error = error {
Expand All @@ -63,6 +70,10 @@ class RedeemInviteOperation: AsynchronousOperation {
self?.finish()
}
}
} else {
Log.info("RedeemInviteOperation to \(star.feed) finished.")
self?.result = .success(())
self?.finish()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Bot/Operations/SendMissionOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SendMissionOperation: AsynchronousOperation {
let missingStars = knownStars.subtracting(availableStars)
let randomSampleOfStars = missingStars.randomSample(UInt(numberOfMissingStars))
redeemInviteOperations = randomSampleOfStars.map {
return RedeemInviteOperation(star: $0)
return RedeemInviteOperation(star: $0, shouldFollow: false)
}

// Lets sync to available stars and newly redeemed stars
Expand Down
42 changes: 42 additions & 0 deletions Source/Bot/Operations/UnfollowOperation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// UnfollowOperation.swift
// Planetary
//
// Created by Martin Dutra on 1/31/21.
// Copyright © 2021 Verse Communications Inc. All rights reserved.
//

import Foundation

class UnfollowOperation: AsynchronousOperation {

var identity: Identity
private(set) var error: Error?

init(identity: Identity) {
self.identity = identity
super.init()
}

override func main() {
Log.info("UnfollowOperation started.")

let configuredIdentity = AppConfiguration.current?.identity
let loggedInIdentity = Bots.current.identity
guard loggedInIdentity != nil, loggedInIdentity == configuredIdentity else {
Log.info("Not logged in. UnfollowOperation finished.")
self.error = BotError.notLoggedIn
self.finish()
return
}

Bots.current.unfollow(self.identity) { [weak self] (contact, error) in
Log.optional(error)
CrashReporting.shared.reportIfNeeded(error: error)
self?.error = error
Log.info("UnfollowOperation finished.")
self?.finish()
}
}

}
9 changes: 9 additions & 0 deletions Source/Controller/Configs/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ enum Environment {
}()
}

enum Communities {
private enum Keys {
static let communities = "PLCommunities"
}
static let stars: [Star] = {
return Environment.value(for: Keys.communities).split(separator: " ").map{Star(invite: String($0))}
}()
}

enum Constellation {
private enum Keys {
static let constellation = "PLConstellation"
Expand Down
4 changes: 4 additions & 0 deletions Source/Controller/Configs/Planetary.debug.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@ RIGEL = 35.222.71.220:8008:@6OK6Z0x5hIVR4yHKFjqwMejlfQUDQUTBW513pn4INIM=.ed25519
PLEIADES = 34.68.66.228:8008:@CCX4V0cOscQU4mMz0PbbB7IIJQDcZc1XFCQaQMHUDsI=.ed25519~92RD5VdmAjthKYK0yXfSpE2yJMwp0JUjeBSLtxiIzn0=
CONSTELLATION = ${PUB_ONE} ${PUB_TWO} ${PUB_THREE} ${PUB_FOUR}

CRYPTO = crypto.planetary.pub:8008:@CBaNGA3MPZHPKo4gvrZsTCCV3DUgydmPnwK0UDRRbqQ=.ed25519~ZxTzJfeVrffCJG7A9byZpD4pOlhCo5E68vB/qcmjyF8=
FLOSS = floss.planetary.pub:8008:@uHqyTLo/JwapDh+ryXKe0VyBMS7eqt0YEKwvUathiS8=.ed25519~l8EciukRuVREcV4hvQLlnIu3tBJtAYV2mbjxzBXEkBQ=
COMMUNITIES = ${CRYPTO} ${FLOSS}

PLANETARY = @oeNoy1RIArVdMdk8ndeoKbAKuU8b56VgxlYP5y8b9Ic=.ed25519
PLANETARY_SYSTEM = ${PLANETARY}
4 changes: 4 additions & 0 deletions Source/Controller/Configs/Planetary.release.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ RIGEL = 35.222.71.220:8008:@6OK6Z0x5hIVR4yHKFjqwMejlfQUDQUTBW513pn4INIM=.ed25519
PLEIADES = 34.68.66.228:8008:@CCX4V0cOscQU4mMz0PbbB7IIJQDcZc1XFCQaQMHUDsI=.ed25519~92RD5VdmAjthKYK0yXfSpE2yJMwp0JUjeBSLtxiIzn0=
CONSTELLATION = ${PUB_ONE} ${PUB_TWO} ${PUB_THREE} ${PUB_FOUR}

CRYPTO = crypto.planetary.pub:8008:@CBaNGA3MPZHPKo4gvrZsTCCV3DUgydmPnwK0UDRRbqQ=.ed25519~ZxTzJfeVrffCJG7A9byZpD4pOlhCo5E68vB/qcmjyF8=
FLOSS = floss.planetary.pub:8008:@uHqyTLo/JwapDh+ryXKe0VyBMS7eqt0YEKwvUathiS8=.ed25519~l8EciukRuVREcV4hvQLlnIu3tBJtAYV2mbjxzBXEkBQ=
COMMUNITIES = ${CRYPTO} ${FLOSS}

PLANETARY = @oeNoy1RIArVdMdk8ndeoKbAKuU8b56VgxlYP5y8b9Ic=.ed25519
PLANETARY_SYSTEM = ${PLANETARY}
Loading

0 comments on commit b698b93

Please sign in to comment.