Skip to content

Commit 734fab2

Browse files
committed
Example project updated for user login/logout.
1 parent 1cd4796 commit 734fab2

File tree

3 files changed

+56
-28
lines changed

3 files changed

+56
-28
lines changed

Example/ChatExample/AppDelegate.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
2525
database: TestDatabase(),
2626
logOptions: .all)
2727

28-
Client.shared.set(user: .user2, token: .token2)
28+
setupUser()
2929
setupNotifications()
3030

3131
return true
3232
}
3333

34+
func setupUser() {
35+
Client.shared.set(user: .user2, token: .token2)
36+
}
37+
3438
private func setupNotifications() {
3539
Notifications.shared.logsEnabled = true
3640

Example/ChatExample/Base.lproj/Main.storyboard

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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" initialViewController="wm7-Ii-BZP">
3-
<device id="retina4_7" orientation="portrait">
4-
<adaptation id="fullscreen"/>
5-
</device>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="wm7-Ii-BZP">
3+
<device id="retina4_7" orientation="portrait" appearance="light"/>
64
<dependencies>
75
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
97
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
108
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
119
</dependencies>
@@ -15,7 +13,7 @@
1513
<objects>
1614
<viewController id="BYZ-38-t0r" customClass="ChannelsViewController" customModule="StreamChat" sceneMemberID="viewController">
1715
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
18-
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
16+
<rect key="frame" x="0.0" y="0.0" width="375" height="647"/>
1917
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2018
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2119
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
@@ -48,12 +46,22 @@
4846
<action selector="addChannel:" destination="cor-4m-0UN" id="RDJ-f0-p0g"/>
4947
</connections>
5048
</barButtonItem>
51-
<barButtonItem key="rightBarButtonItem" systemItem="stop" id="xsm-do-D8r">
52-
<connections>
53-
<segue destination="Jpg-eB-15H" kind="custom" customClass="DismissSegue" customModule="StreamChat" id="a5b-Jp-cN7"/>
54-
</connections>
55-
</barButtonItem>
49+
<rightBarButtonItems>
50+
<barButtonItem systemItem="stop" id="xsm-do-D8r">
51+
<connections>
52+
<segue destination="Jpg-eB-15H" kind="custom" customClass="DismissSegue" customModule="StreamChat" id="a5b-Jp-cN7"/>
53+
</connections>
54+
</barButtonItem>
55+
<barButtonItem title="Logout" id="mJn-gs-i29">
56+
<connections>
57+
<action selector="logout:" destination="cor-4m-0UN" id="Mvb-hZ-55D"/>
58+
</connections>
59+
</barButtonItem>
60+
</rightBarButtonItems>
5661
</navigationItem>
62+
<connections>
63+
<outlet property="logoutButton" destination="mJn-gs-i29" id="bao-Vn-4mA"/>
64+
</connections>
5765
</viewController>
5866
<placeholder placeholderIdentifier="IBFirstResponder" id="qob-9V-kbc" userLabel="First Responder" sceneMemberID="firstResponder"/>
5967
</objects>
@@ -68,7 +76,7 @@
6876
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
6977
<subviews>
7078
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" spacing="15" translatesAutoresizingMaskIntoConstraints="NO" id="fQM-5J-VyU">
71-
<rect key="frame" x="16" y="84" width="343" height="250"/>
79+
<rect key="frame" x="16" y="64" width="343" height="250"/>
7280
<subviews>
7381
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="lMz-sX-zDG">
7482
<rect key="frame" x="0.0" y="0.0" width="128" height="30"/>
@@ -143,7 +151,7 @@
143151
</constraints>
144152
</stackView>
145153
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eTn-JY-iPB">
146-
<rect key="frame" x="158" y="208" width="16" height="16"/>
154+
<rect key="frame" x="158" y="188" width="16" height="16"/>
147155
<color key="backgroundColor" name="systemRedColor" catalog="System" colorSpace="catalog"/>
148156
<constraints>
149157
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="16" id="Jsh-lg-vjv"/>
@@ -159,7 +167,7 @@
159167
</userDefinedRuntimeAttributes>
160168
</label>
161169
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="DARK MODE" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="11f-PJ-qcd">
162-
<rect key="frame" x="241" y="152" width="72" height="16"/>
170+
<rect key="frame" x="241" y="132" width="72" height="16"/>
163171
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
164172
<constraints>
165173
<constraint firstAttribute="width" constant="72" id="i8J-3r-nDA"/>
@@ -175,30 +183,30 @@
175183
</userDefinedRuntimeAttributes>
176184
</label>
177185
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="jQp-EN-Voh">
178-
<rect key="frame" x="310" y="205.5" width="51" height="31"/>
186+
<rect key="frame" x="310" y="185.5" width="51" height="31"/>
179187
</switch>
180188
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="right" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OkG-5O-emD">
181-
<rect key="frame" x="265.5" y="206.5" width="39.5" height="29"/>
189+
<rect key="frame" x="265.5" y="186.5" width="39.5" height="29"/>
182190
<string key="text">unread
183191
badge</string>
184192
<fontDescription key="fontDescription" type="system" pointSize="12"/>
185193
<color key="textColor" white="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
186194
<nil key="highlightedColor"/>
187195
</label>
188196
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="jrn-MT-IQv">
189-
<rect key="frame" x="310" y="260.5" width="51" height="31"/>
197+
<rect key="frame" x="310" y="240.5" width="51" height="31"/>
190198
</switch>
191199
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="H0k-lx-tmL">
192-
<rect key="frame" x="310" y="309.5" width="51" height="31"/>
200+
<rect key="frame" x="310" y="289.5" width="51" height="31"/>
193201
</switch>
194202
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="It doesn't hold the state and to disable Push notifications you need to toggle it twice." textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="B0u-JV-sSq">
195-
<rect key="frame" x="16" y="339" width="283" height="29"/>
203+
<rect key="frame" x="16" y="319" width="283" height="29"/>
196204
<fontDescription key="fontDescription" type="system" pointSize="12"/>
197205
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
198206
<nil key="highlightedColor"/>
199207
</label>
200208
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="7rg-Xd-yMa">
201-
<rect key="frame" x="0.0" y="383" width="375" height="1"/>
209+
<rect key="frame" x="0.0" y="363" width="375" height="1"/>
202210
<color key="backgroundColor" red="0.83741801979999997" green="0.83743780850000005" blue="0.83742713930000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
203211
<constraints>
204212
<constraint firstAttribute="height" constant="1" id="b5l-qn-iGf"/>
@@ -261,7 +269,7 @@ badge</string>
261269
<tabBarItem key="tabBarItem" systemItem="contacts" id="d2I-aW-uJk"/>
262270
<toolbarItems/>
263271
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="rGP-f5-wYZ">
264-
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
272+
<rect key="frame" x="0.0" y="0.0" width="375" height="56"/>
265273
<autoresizingMask key="autoresizingMask"/>
266274
</navigationBar>
267275
<nil name="viewControllers"/>
@@ -278,7 +286,7 @@ badge</string>
278286
<objects>
279287
<viewController id="e0G-IG-Gxn" customClass="CustomChatViewController" customModule="ChatExample" customModuleProvider="target" sceneMemberID="viewController">
280288
<view key="view" contentMode="scaleToFill" id="p7A-Vg-wGQ">
281-
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
289+
<rect key="frame" x="0.0" y="0.0" width="375" height="647"/>
282290
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
283291
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
284292
<viewLayoutGuide key="safeArea" id="AC2-xq-vHg"/>
@@ -302,7 +310,7 @@ badge</string>
302310
<tabBarItem key="tabBarItem" systemItem="mostViewed" id="Uhp-Gu-8p3"/>
303311
<toolbarItems/>
304312
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Fap-uP-7Ox">
305-
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
313+
<rect key="frame" x="0.0" y="0.0" width="375" height="56"/>
306314
<autoresizingMask key="autoresizingMask"/>
307315
</navigationBar>
308316
<nil name="viewControllers"/>
@@ -321,7 +329,7 @@ badge</string>
321329
<toolbarItems/>
322330
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" barStyle="black" prompted="NO"/>
323331
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" barStyle="black" id="fub-QL-sHd">
324-
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
332+
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
325333
<autoresizingMask key="autoresizingMask"/>
326334
</navigationBar>
327335
<nil name="viewControllers"/>
@@ -339,7 +347,7 @@ badge</string>
339347
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="wm7-Ii-BZP" sceneMemberID="viewController">
340348
<toolbarItems/>
341349
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="KhY-db-khs">
342-
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
350+
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
343351
<autoresizingMask key="autoresizingMask"/>
344352
</navigationBar>
345353
<nil name="viewControllers"/>
@@ -353,7 +361,7 @@ badge</string>
353361
</scene>
354362
</scenes>
355363
<inferredMetricsTieBreakers>
356-
<segue reference="elX-bx-MbU"/>
364+
<segue reference="a5b-Jp-cN7"/>
357365
<segue reference="Z6X-IU-Iab"/>
358366
<segue reference="seW-P6-fEX"/>
359367
</inferredMetricsTieBreakers>

Example/ChatExample/DarkChannelsViewController.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import StreamChat
1212

1313
final class DarkChannelsViewController: ChannelsViewController {
1414

15+
@IBOutlet weak var logoutButton: UIBarButtonItem!
16+
1517
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
1618
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
1719
setup()
@@ -26,7 +28,10 @@ final class DarkChannelsViewController: ChannelsViewController {
2628
deleteChannelBySwipe = true
2729
style = .dark
2830
title = "My channels"
29-
31+
setupPresenter()
32+
}
33+
34+
func setupPresenter() {
3035
if let currentUser = User.current {
3136
channelsPresenter = ChannelsPresenter(channelType: .messaging, filter: .key("members", .in([currentUser.id])))
3237
}
@@ -45,4 +50,15 @@ final class DarkChannelsViewController: ChannelsViewController {
4550
})
4651
.disposed(by: disposeBag)
4752
}
53+
54+
@IBAction func logout(_ sender: Any) {
55+
if logoutButton.title == "Logout" {
56+
Client.shared.disconnect()
57+
logoutButton.title = "Login"
58+
} else if let delegate = UIApplication.shared.delegate as? AppDelegate {
59+
delegate.setupUser()
60+
setupPresenter()
61+
logoutButton.title = "Logout"
62+
}
63+
}
4864
}

0 commit comments

Comments
 (0)