Skip to content

Commit 2884160

Browse files
committed
Chatto inception
1 parent ab5b944 commit 2884160

File tree

244 files changed

+15967
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

244 files changed

+15967
-0
lines changed

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: objective-c
2+
osx_image: xcode7.1
3+
4+
script:
5+
- xcodebuild clean build test -project ./Chatto/Chatto.xcodeproj -scheme Chatto -sdk iphonesimulator -configuration Debug | xcpretty; (curl -s https://codecov.io/bash) | bash
6+
- rm -rf ~/Library/Developer/Xcode/DerivedData
7+
- xcodebuild clean build test -project ./ChattoAdditions/ChattoAdditions.xcodeproj -scheme ChattoAdditions -sdk iphonesimulator -configuration Debug | xcpretty; (curl -s https://codecov.io/bash) | bash

AUTHORS

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Names should be added to this file like so:
2+
# Name or Organization <email address>
3+
4+
Diego Sánchez <diego.sanchezr@gmail.com>
5+
Anton Schukin <a.p.schukin@gmail.com>
6+
7+
&yet LLC
8+
Badoo

Chatto.podspec

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Pod::Spec.new do |s|
2+
s.name = "Chatto"
3+
s.version = "1.0.0"
4+
s.summary = "Chat framework in Swift"
5+
s.description = <<-DESC
6+
Lightweight chat framework to build Chat apps
7+
DESC
8+
s.homepage = "https://github.com/badoo/Chatto"
9+
s.license = { :type => "MIT"}
10+
s.platform = :ios, "8.0"
11+
s.source = { :git => "https://github.com/badoo/Chatto.git", :tag => s.version.to_s }
12+
s.source_files = "Chatto/Source/**/*.{h,m,swift}"
13+
s.public_header_files = "Chatto/Source/**/*.h"
14+
s.requires_arc = true
15+
s.resources = ["Chatto/Source/**/*.xib", "Chatto/Source/**/*.storyboard", "Chatto/Source/**/*.xcassets"]
16+
end

Chatto/.swiftlint.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
disabled_rules: # rule identifiers to exclude from running
2+
- file_length
3+
- force_cast
4+
- function_body_length
5+
- line_length
6+
- todo
7+
- type_body_length
8+
- variable_name
9+
included: # paths to include during linting. `--path` is ignored if present. takes precendence over `excluded`.
10+
- Source
11+
excluded: # paths to ignore during linting. overridden by `included`.

Chatto/Chatto.xcodeproj/project.pbxproj

+525
Large diffs are not rendered by default.

Chatto/Chatto.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0720"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "C32BB71F1BE0504D0069EC50"
18+
BuildableName = "Chatto.framework"
19+
BlueprintName = "Chatto"
20+
ReferencedContainer = "container:Chatto.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
codeCoverageEnabled = "YES">
31+
<Testables>
32+
<TestableReference
33+
skipped = "NO">
34+
<BuildableReference
35+
BuildableIdentifier = "primary"
36+
BlueprintIdentifier = "C32BB7291BE0504D0069EC50"
37+
BuildableName = "ChattoTests.xctest"
38+
BlueprintName = "ChattoTests"
39+
ReferencedContainer = "container:Chatto.xcodeproj">
40+
</BuildableReference>
41+
</TestableReference>
42+
</Testables>
43+
<MacroExpansion>
44+
<BuildableReference
45+
BuildableIdentifier = "primary"
46+
BlueprintIdentifier = "C32BB71F1BE0504D0069EC50"
47+
BuildableName = "Chatto.framework"
48+
BlueprintName = "Chatto"
49+
ReferencedContainer = "container:Chatto.xcodeproj">
50+
</BuildableReference>
51+
</MacroExpansion>
52+
<AdditionalOptions>
53+
</AdditionalOptions>
54+
</TestAction>
55+
<LaunchAction
56+
buildConfiguration = "Debug"
57+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
58+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
59+
launchStyle = "0"
60+
useCustomWorkingDirectory = "NO"
61+
ignoresPersistentStateOnLaunch = "NO"
62+
debugDocumentVersioning = "YES"
63+
debugServiceExtension = "internal"
64+
allowLocationSimulation = "YES">
65+
<MacroExpansion>
66+
<BuildableReference
67+
BuildableIdentifier = "primary"
68+
BlueprintIdentifier = "C32BB71F1BE0504D0069EC50"
69+
BuildableName = "Chatto.framework"
70+
BlueprintName = "Chatto"
71+
ReferencedContainer = "container:Chatto.xcodeproj">
72+
</BuildableReference>
73+
</MacroExpansion>
74+
<AdditionalOptions>
75+
</AdditionalOptions>
76+
</LaunchAction>
77+
<ProfileAction
78+
buildConfiguration = "Release"
79+
shouldUseLaunchSchemeArgsEnv = "YES"
80+
savedToolIdentifier = ""
81+
useCustomWorkingDirectory = "NO"
82+
debugDocumentVersioning = "YES">
83+
<MacroExpansion>
84+
<BuildableReference
85+
BuildableIdentifier = "primary"
86+
BlueprintIdentifier = "C32BB71F1BE0504D0069EC50"
87+
BuildableName = "Chatto.framework"
88+
BlueprintName = "Chatto"
89+
ReferencedContainer = "container:Chatto.xcodeproj">
90+
</BuildableReference>
91+
</MacroExpansion>
92+
</ProfileAction>
93+
<AnalyzeAction
94+
buildConfiguration = "Debug">
95+
</AnalyzeAction>
96+
<ArchiveAction
97+
buildConfiguration = "Release"
98+
revealArchiveInOrganizer = "YES">
99+
</ArchiveAction>
100+
</Scheme>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2015-present Badoo Trading Limited.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
*/
24+
25+
import UIKit
26+
27+
public enum ChatItemVisibility {
28+
case Hidden
29+
case Appearing
30+
case Visible
31+
}
32+
33+
public class BaseChatItemPresenter<CellT: UICollectionViewCell>: ChatItemPresenterProtocol {
34+
public final weak var cell: CellT?
35+
36+
public init() { }
37+
38+
public class func registerCells(collectionView: UICollectionView) {
39+
assert(false, "Implement in subclass")
40+
}
41+
42+
public var canCalculateHeightInBackground: Bool {
43+
return false
44+
}
45+
46+
public func heightForCell(maximumWidth width: CGFloat, decorationAttributes: ChatItemDecorationAttributesProtocol?) -> CGFloat {
47+
assert(false, "Implement in subclass")
48+
return 0
49+
}
50+
51+
public func dequeueCell(collectionView collectionView: UICollectionView, indexPath: NSIndexPath) -> UICollectionViewCell {
52+
assert(false, "Implemenent in subclass")
53+
return UICollectionViewCell()
54+
}
55+
56+
public func configureCell(cell: UICollectionViewCell, decorationAttributes: ChatItemDecorationAttributesProtocol?) {
57+
assert(false, "Implemenent in subclass")
58+
}
59+
60+
final public private(set) var itemVisibility: ChatItemVisibility = .Hidden
61+
62+
// Need to override default implementatios. Otherwise subclasses's code won't be executed
63+
// http://stackoverflow.com/questions/31795158/swift-2-protocol-extension-not-calling-overriden-method-correctly
64+
public final func cellWillBeShown(cell: UICollectionViewCell) {
65+
if let cell = cell as? CellT {
66+
self.cell = cell
67+
self.itemVisibility = .Appearing
68+
self.cellWillBeShown()
69+
self.itemVisibility = .Visible
70+
} else {
71+
assert(false, "Invalid cell was given to presenter!")
72+
}
73+
}
74+
75+
public func cellWillBeShown() {
76+
// Hook for subclasses
77+
}
78+
79+
public func shouldShowMenu() -> Bool {
80+
return false
81+
}
82+
83+
public final func cellWasHidden(cell: UICollectionViewCell) {
84+
// Carefull!! This doesn't mean that this is no longer visible
85+
// If cell is replaced (due to a reload for instance) we can have the following sequence:
86+
// - New cell is taken from the pool and configured. We'll get cellWillBeShown
87+
// - Old cell is removed. We'll get cellWasHidden
88+
// --> We need to check that this cell is the last one made visible
89+
if let cell = cell as? CellT {
90+
if cell === self.cell {
91+
self.cell = nil
92+
self.itemVisibility = .Hidden
93+
self.cellWasHidden()
94+
}
95+
} else {
96+
assert(false, "Invalid cell was given to presenter!")
97+
}
98+
}
99+
100+
public func cellWasHidden() {
101+
// Hook for subclasses. Here we are not visible for real.
102+
}
103+
104+
public func canPerformMenuControllerAction(action: Selector) -> Bool {
105+
return false
106+
}
107+
108+
public func performMenuControllerAction(action: Selector) {
109+
assert(self.canPerformMenuControllerAction(action))
110+
}
111+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2015-present Badoo Trading Limited.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
*/
24+
25+
import Foundation
26+
27+
public typealias ChatItemType = String
28+
29+
public protocol ChatItemProtocol: class, UniqueIdentificable {
30+
var type: ChatItemType { get }
31+
}
32+
33+
public protocol ChatItemDecorationAttributesProtocol {
34+
var bottomMargin: CGFloat { get }
35+
}
36+
37+
public protocol ChatItemPresenterProtocol: class {
38+
static func registerCells(collectionView: UICollectionView)
39+
var canCalculateHeightInBackground: Bool { get } // Default is false
40+
func heightForCell(maximumWidth width: CGFloat, decorationAttributes: ChatItemDecorationAttributesProtocol?) -> CGFloat
41+
func dequeueCell(collectionView collectionView: UICollectionView, indexPath: NSIndexPath) -> UICollectionViewCell
42+
func configureCell(cell: UICollectionViewCell, decorationAttributes: ChatItemDecorationAttributesProtocol?)
43+
func cellWillBeShown(cell: UICollectionViewCell) // optional
44+
func cellWasHidden(cell: UICollectionViewCell) // optional
45+
func shouldShowMenu() -> Bool // optional. Default is false
46+
func canPerformMenuControllerAction(action: Selector) -> Bool // optional. Default is false
47+
func performMenuControllerAction(action: Selector) // optional
48+
}
49+
50+
public extension ChatItemPresenterProtocol { // Optionals
51+
var canCalculateHeightInBackground: Bool { return false }
52+
func cellWillBeShown(cell: UICollectionViewCell) {}
53+
func cellWasHidden(cell: UICollectionViewCell) {}
54+
func shouldShowMenu() -> Bool { return false }
55+
func canPerformMenuControllerAction(action: Selector) -> Bool { return false }
56+
func performMenuControllerAction(action: Selector) {}
57+
}
58+
59+
public protocol ChatItemPresenterBuilderProtocol {
60+
func canHandleChatItem(chatItem: ChatItemProtocol) -> Bool
61+
func createPresenterWithChatItem(chatItem: ChatItemProtocol) -> ChatItemPresenterProtocol
62+
var presenterType: ChatItemPresenterProtocol.Type { get }
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2015-present Badoo Trading Limited.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
*/
24+
25+
import Foundation
26+
27+
// Handles messages that aren't supported so they appear as invisible
28+
class DummyChatItemPresenter: ChatItemPresenterProtocol {
29+
30+
class func registerCells(collectionView: UICollectionView) {
31+
collectionView.registerClass(DummyCollectionViewCell.self, forCellWithReuseIdentifier: "cell-id-unhandled-message")
32+
}
33+
34+
var canCalculateHeightInBackground: Bool {
35+
return true
36+
}
37+
38+
func heightForCell(maximumWidth width: CGFloat, decorationAttributes: ChatItemDecorationAttributesProtocol?) -> CGFloat {
39+
return 0
40+
}
41+
42+
func dequeueCell(collectionView collectionView: UICollectionView, indexPath: NSIndexPath) -> UICollectionViewCell {
43+
return collectionView.dequeueReusableCellWithReuseIdentifier("cell-id-unhandled-message", forIndexPath: indexPath)
44+
}
45+
46+
func configureCell(cell: UICollectionViewCell, decorationAttributes: ChatItemDecorationAttributesProtocol?) {
47+
cell.hidden = true
48+
}
49+
}
50+
51+
52+
class DummyCollectionViewCell: UICollectionViewCell {}

0 commit comments

Comments
 (0)