Skip to content

Commit

Permalink
Merge pull request #548 from StepicOrg/release/1.99
Browse files Browse the repository at this point in the history
Release 1.99
  • Loading branch information
ivan-magda authored Oct 30, 2019
2 parents 11f4c9e + bb09945 commit 8d4168a
Show file tree
Hide file tree
Showing 45 changed files with 1,884 additions and 439 deletions.
5 changes: 3 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def all_pods
pod 'SVProgressHUD', '2.2.5'
# TSMessages is no longer being maintained/updated, remove or migrate to RMessage/SwiftMessages
pod 'TSMessages', :git => 'https://github.com/KrauseFx/TSMessages.git'
pod 'YandexMobileMetrica/Dynamic', '3.8.2'

pod 'SnapKit', '4.2.0'

Expand All @@ -36,7 +35,9 @@ def all_pods
pod 'Firebase/Analytics' , '6.10.0'
pod 'Firebase/RemoteConfig', '6.10.0'

pod 'YandexMobileMetrica/Dynamic', '3.8.2'
pod 'Amplitude-iOS', '4.8.2'
pod 'Branch', '0.25.11'

pod 'BEMCheckBox', '1.4.1'

Expand Down Expand Up @@ -64,7 +65,7 @@ def all_pods
pod 'Nuke', '7.6.3'
pod 'STRegex', '2.1.0'
pod 'Tabman', '2.4.3'
pod 'Branch', '0.25.11'
pod 'SwiftDate', '6.1.0'
end

def testing_pods
Expand Down
6 changes: 5 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ PODS:
- SVGKit (2.1.0):
- CocoaLumberjack (~> 3.0)
- SVProgressHUD (2.2.5)
- SwiftDate (6.1.0)
- SwiftLint (0.35.0)
- SwiftyGif (5.1.1)
- SwiftyJSON (5.0.0)
Expand Down Expand Up @@ -227,6 +228,7 @@ DEPENDENCIES:
- STRegex (= 2.1.0)
- SVGKit (from `https://github.com/SVGKit/SVGKit.git`, branch `2.x`)
- SVProgressHUD (= 2.2.5)
- SwiftDate (= 6.1.0)
- SwiftLint (= 0.35.0)
- SwiftyJSON (= 5.0.0)
- Tabman (= 2.4.3)
Expand Down Expand Up @@ -291,6 +293,7 @@ SPEC REPOS:
- SnapKit
- STRegex
- SVProgressHUD
- SwiftDate
- SwiftLint
- SwiftyGif
- SwiftyJSON
Expand Down Expand Up @@ -378,6 +381,7 @@ SPEC CHECKSUMS:
STRegex: dfa420d93d8c1402956233b3879ec1fc14b45fbe
SVGKit: 8a2fc74258bdb2abb54d3b65f3dd68b0277a9c4d
SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6
SwiftDate: fa2bb3962056bb44047b4b85a30044e5eae30b03
SwiftLint: 5553187048b900c91aa03552807681bb6b027846
SwiftyGif: f7702483db93586a41f04f4927cd682852a2fa10
SwiftyJSON: 36413e04c44ee145039d332b4f4e2d3e8d6c4db7
Expand All @@ -389,6 +393,6 @@ SPEC CHECKSUMS:
VK-ios-sdk: 62a10b6571fbcda0657f455fedce7fedf55b4cd0
YandexMobileMetrica: edb00e8af2903290e142ba4c488adf8d394e828a

PODFILE CHECKSUM: dc63d7ff94795a04c64f1ed6339d1e679ac8adcd
PODFILE CHECKSUM: a301f6a0304d923e0bdf9c0ddf1212d1abee6fdb

COCOAPODS: 1.8.4
64 changes: 58 additions & 6 deletions Stepic.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Stepic/Analytics/AnalyticsEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct AnalyticsEvents {
static let liked = "discussion_liked"
static let unliked = "discussion_unliked"
static let abused = "discussion_abused"
static let unabused = "discussion_unabused"
}

struct DeepLink {
Expand Down
11 changes: 6 additions & 5 deletions Stepic/AttemptsAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ final class AttemptsAPI: APIEndpoint {
func create(stepName: String, stepId: Int) -> Promise<Attempt> {
let attempt = Attempt(step: stepId)
return Promise { seal in
create.request(requestEndpoint: "attempts", paramName: "attempt", creatingObject: attempt, withManager: manager).done { attempt, json in
guard let json = json else {
seal.fulfill(attempt)
return
}
self.create.request(
requestEndpoint: "attempts",
paramName: "attempt",
creatingObject: attempt,
withManager: manager
).done { attempt, json in
attempt.initDataset(json: json["attempts"].arrayValue[0]["dataset"], stepName: stepName)
seal.fulfill(attempt)
}.catch { error in
Expand Down
5 changes: 1 addition & 4 deletions Stepic/CardsStepsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ class CardsStepsViewController: UIViewController, CardsStepsView, ControllerWith
}

func presentDiscussions(stepId: Int, discussionProxyId: String) {
let assembly = DiscussionsLegacyAssembly(
discussionProxyID: discussionProxyId,
stepID: stepId
)
let assembly = NewDiscussionsAssembly(discussionProxyID: discussionProxyId, stepID: stepId)
self.push(module: assembly.makeModule())
}

Expand Down
52 changes: 31 additions & 21 deletions Stepic/CommentsAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,47 @@ final class CommentsAPI: APIEndpoint {

func create(_ comment: Comment) -> Promise<Comment> {
return Promise { seal in
create.request(requestEndpoint: "comments", paramName: "comment", creatingObject: comment, withManager: manager).done { comment, json in
guard let json = json else {
seal.fulfill(comment)
return
}
let userInfo = UserInfo(json: json["users"].arrayValue[0])
let vote = Vote(json: json["votes"].arrayValue[0])
self.create.request(
requestEndpoint: self.name,
paramName: "comment",
creatingObject: comment,
withManager: self.manager
).done { comment, json in
let userInfo = UserInfo(json: json[Comment.JSONKey.users.rawValue].arrayValue[0])
let vote = Vote(json: json[Comment.JSONKey.votes.rawValue].arrayValue[0])

comment.userInfo = userInfo
comment.vote = vote

seal.fulfill(comment)
}.catch { error in
seal.reject(error)
}
}
}
}

extension CommentsAPI {
@available(*, deprecated, message: "Legacy method with callbacks")
@discardableResult func create(_ comment: Comment, success: @escaping (Comment) -> Void, error errorHandler: @escaping (String) -> Void) -> Request? {
create(comment).done { success($0) }.catch { errorHandler($0.localizedDescription) }
return nil
}
func update(_ comment: Comment) -> Promise<Comment> {
return Promise { seal in
self.update.request(
requestEndpoint: self.name,
paramName: "comment",
updatingObject: comment,
withManager: self.manager
).done { comment, json in
let userInfo = UserInfo(json: json[Comment.JSONKey.users.rawValue].arrayValue[0])
let vote = Vote(json: json[Comment.JSONKey.votes.rawValue].arrayValue[0])

@available(*, deprecated, message: "Legacy method with callbacks")
@discardableResult func retrieve(_ ids: [Int], headers: [String: String] = AuthInfo.shared.initialHTTPHeaders, success: @escaping ([Comment]) -> Void, error errorHandler: @escaping (String) -> Void) -> Request? {
retrieve(ids: ids).done { comments in
success(comments)
}.catch { error in
errorHandler(error.localizedDescription)
comment.userInfo = userInfo
comment.vote = vote

seal.fulfill(comment)
}.catch { error in
seal.reject(error)
}
}
return nil
}

func delete(commentID: Comment.IdType) -> Promise<Void> {
return self.delete.request(requestEndpoint: self.name, deletingId: commentID, withManager: self.manager)
}
}
45 changes: 37 additions & 8 deletions Stepic/CreateRequestMaker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@ import PromiseKit
import SwiftyJSON

final class CreateRequestMaker {
func request<T: JSONSerializable>(requestEndpoint: String, paramName: String, creatingObject: T, withManager manager: Alamofire.SessionManager) -> Promise<(T, JSON?)> {
func request<T: JSONSerializable>(
requestEndpoint: String,
paramName: String,
creatingObject: T,
withManager manager: Alamofire.SessionManager
) -> Promise<(T, JSON)> {
return Promise { seal in
let params: Parameters? = [
paramName: creatingObject.json.dictionaryObject ?? ""
]

checkToken().done {
manager.request("\(StepicApplicationsInfo.apiURL)/\(requestEndpoint)", method: .post, parameters: params, encoding: JSONEncoding.default).validate().responseSwiftyJSON { response in
manager.request(
"\(StepicApplicationsInfo.apiURL)/\(requestEndpoint)",
method: .post,
parameters: params,
encoding: JSONEncoding.default
).validate().responseSwiftyJSON { response in
switch response.result {
case .failure(let error):
seal.reject(NetworkError(error: error))
Expand All @@ -28,26 +38,45 @@ final class CreateRequestMaker {
seal.fulfill((creatingObject, json))
}
}
}.catch {
error in
}.catch { error in
seal.reject(error)
}
}
}

func request<T: JSONSerializable>(requestEndpoint: String, paramName: String, creatingObject: T, withManager manager: Alamofire.SessionManager) -> Promise<T> {
func request<T: JSONSerializable>(
requestEndpoint: String,
paramName: String,
creatingObject: T,
withManager manager: Alamofire.SessionManager
) -> Promise<T> {
return Promise { seal in
request(requestEndpoint: requestEndpoint, paramName: paramName, creatingObject: creatingObject, withManager: manager).done { comment, _ in
self.request(
requestEndpoint: requestEndpoint,
paramName: paramName,
creatingObject: creatingObject,
withManager: manager
).done { comment, _ in
seal.fulfill(comment)
}.catch { error in
seal.reject(error)
}
}
}

func request<T: JSONSerializable>(requestEndpoint: String, paramName: String, creatingObject: T, withManager manager: Alamofire.SessionManager) -> Promise<Void> {
func request<T: JSONSerializable>(
requestEndpoint: String,
paramName: String,
creatingObject: T,
withManager manager: Alamofire.SessionManager
) -> Promise<Void> {
return Promise { seal in
request(requestEndpoint: requestEndpoint, paramName: paramName, creatingObject: creatingObject, withManager: manager).done { _, _ in
self.request(
requestEndpoint: requestEndpoint,
paramName: paramName,
creatingObject: creatingObject,
withManager: manager
).done { _, _ in
seal.fulfill(())
}.catch { error in
seal.reject(error)
Expand Down
15 changes: 11 additions & 4 deletions Stepic/DeleteRequestMaker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,26 @@ import Foundation
import PromiseKit

final class DeleteRequestMaker {
func request(requestEndpoint: String, deletingId: Int, withManager manager: Alamofire.SessionManager) -> Promise<Void> {
func request(
requestEndpoint: String,
deletingId: Int,
withManager manager: Alamofire.SessionManager
) -> Promise<Void> {
return Promise { seal in
checkToken().done {
manager.request("\(StepicApplicationsInfo.apiURL)/\(requestEndpoint)/\(deletingId)", method: .delete, encoding: JSONEncoding.default).validate().responseSwiftyJSON { response in
manager.request(
"\(StepicApplicationsInfo.apiURL)/\(requestEndpoint)/\(deletingId)",
method: .delete,
encoding: JSONEncoding.default
).validate().responseSwiftyJSON { response in
switch response.result {
case .failure(let error):
seal.reject(NetworkError(error: error))
case .success:
seal.fulfill(())
}
}
}.catch {
error in
}.catch { error in
seal.reject(error)
}
}
Expand Down
23 changes: 22 additions & 1 deletion Stepic/Discussions/Comment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum UserRole: String {
}

final class Comment: JSONSerializable {
var id: Int = 0
var id: Int = -1
var parentID: Comment.IdType?
var userID: User.IdType = 0
var userRole: UserRole = .student
Expand All @@ -31,6 +31,7 @@ final class Comment: JSONSerializable {
var voteID: String = ""
var epicCount: Int = 0
var abuseCount: Int = 0
var actions: [Action] = []

var userInfo: UserInfo!
var vote: Vote!
Expand Down Expand Up @@ -78,6 +79,25 @@ final class Comment: JSONSerializable {
self.voteID = json[JSONKey.vote.rawValue].stringValue
self.epicCount = json[JSONKey.epicCount.rawValue].intValue
self.abuseCount = json[JSONKey.abuseCount.rawValue].intValue

self.actions.removeAll(keepingCapacity: true)
for (actionKey, value) in json[JSONKey.actions.rawValue].dictionaryValue {
guard let action = Action(rawValue: actionKey) else {
continue
}

if value.boolValue {
self.actions.append(action)
}
}
}

enum Action: String {
case delete
case pin
case report
case vote
case edit
}

enum JSONKey: String {
Expand All @@ -96,6 +116,7 @@ final class Comment: JSONSerializable {
case vote
case epicCount = "epic_count"
case abuseCount = "abuse_count"
case actions
case users
case votes
}
Expand Down
8 changes: 4 additions & 4 deletions Stepic/DiscussionsStoryboard.storyboard
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Write Comment View Controller-->
<!--Legacy Write Comment View Controller-->
<scene sceneID="uQf-ld-I5H">
<objects>
<viewController storyboardIdentifier="WriteCommentViewController" id="4hM-YH-FAZ" customClass="WriteCommentViewController" customModule="Adaptive_1838" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="LegacyWriteCommentViewController" id="4hM-YH-FAZ" customClass="LegacyWriteCommentViewController" customModule="Stepic" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="PoY-wT-x23">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
10 changes: 1 addition & 9 deletions Stepic/DiscussionsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class DiscussionsLegacyAssembly: Assembly {
votesNetworkService: VotesNetworkService(votesAPI: VotesAPI()),
stepsPersistenceService: StepsPersistenceService()
)
viewController.title = NSLocalizedString("Discussions", comment: "")
viewController.title = NSLocalizedString("DiscussionsTitle", comment: "")
return viewController
}
}
Expand Down Expand Up @@ -189,8 +189,6 @@ final class DiscussionsViewController: UIViewController, DiscussionsView, Contro
}

func displayWriteComment(parentId: Comment.IdType?) {
let assembly = WriteCommentLegacyAssembly(target: self.target, parentId: parentId, delegate: self)
self.push(module: assembly.makeModule())
}

@objc
Expand All @@ -215,9 +213,3 @@ extension DiscussionsViewController: DiscussionsViewControllerDelegate {
self.push(module: assembly.makeModule())
}
}

extension DiscussionsViewController: WriteCommentViewControllerDelegate {
func writeCommentViewControllerDidWriteComment(_ controller: WriteCommentViewController, comment: Comment) {
self.presenter?.writeComment(comment)
}
}
Loading

0 comments on commit 8d4168a

Please sign in to comment.