Skip to content

Commit 06c8774

Browse files
authored
Ensure URL have secure scheme + Add view info on channel options (#76)
1 parent 77e3e21 commit 06c8774

File tree

14 files changed

+219
-14
lines changed

14 files changed

+219
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
33

44
# Upcoming
55

6-
### 🔄 Changed
6+
### ✅ Added
7+
- Possibility to view channel info on channel options
8+
9+
### 🐞 Fixed
10+
- Bug about link attachments not opening when the URL was missing the scheme
711

812
# [4.15.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.15.0)
913
_May 17, 2022_

Sources/StreamChatSwiftUI/ChatChannel/MessageList/LinkAttachmentView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ public struct LinkAttachmentView: View {
122122
}
123123
.padding(.horizontal, padding)
124124
.onTapGesture {
125-
if UIApplication.shared.canOpenURL(linkAttachment.originalURL) {
126-
UIApplication.shared.open(linkAttachment.originalURL, options: [:])
125+
if let url = linkAttachment.originalURL.secureURL, UIApplication.shared.canOpenURL(url) {
126+
UIApplication.shared.open(url, options: [:])
127127
}
128128
}
129129
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Copyright © 2022 Stream.io Inc. All rights reserved.
3+
//
4+
5+
import Foundation
6+
7+
extension URL {
8+
var secureURL: URL? {
9+
let secureScheme = "https"
10+
11+
guard
12+
scheme != secureScheme,
13+
var components = URLComponents(url: self, resolvingAgainstBaseURL: true)
14+
else {
15+
return self
16+
}
17+
18+
components.scheme = secureScheme
19+
20+
return components.url
21+
}
22+
}

Sources/StreamChatSwiftUI/ChatChannelList/DefaultChannelActions.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//
44

55
import StreamChat
6+
import SwiftUI
67

78
extension ChannelAction {
89
/// Returns the default channel actions.
@@ -20,6 +21,10 @@ extension ChannelAction {
2021
) -> [ChannelAction] {
2122
var actions = [ChannelAction]()
2223

24+
let viewInfo = viewInfo(for: channel)
25+
26+
actions.append(viewInfo)
27+
2328
if !channel.isDirectMessageChannel, let userId = chatClient.currentUserId {
2429
let leaveGroup = leaveGroup(
2530
for: channel,
@@ -201,6 +206,20 @@ extension ChannelAction {
201206
return leaveConversation
202207
}
203208

209+
private static func viewInfo(for channel: ChatChannel) -> ChannelAction {
210+
var viewInfo = ChannelAction(
211+
title: L10n.Alert.Actions.viewInfoTitle,
212+
iconName: "person.fill",
213+
action: { /* no-op */ },
214+
confirmationPopup: nil,
215+
isDestructive: false
216+
)
217+
218+
viewInfo.navigationDestination = AnyView(ChatChannelInfoView(channel: channel))
219+
220+
return viewInfo
221+
}
222+
204223
private static func naming(for channel: ChatChannel) -> String {
205224
channel.isDirectMessageChannel ? L10n.Channel.Name.directMessage : L10n.Channel.Name.group
206225
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Copyright © 2022 Stream.io Inc. All rights reserved.
3+
//
4+
5+
import StreamChat
6+
import SwiftUI
7+
8+
/// Default wrapping view for the channel more actions full screen presented view.
9+
struct MoreChannelActionsFullScreenWrappingView: View {
10+
@Injected(\.images) private var images
11+
12+
let presentedView: AnyView
13+
let onDismiss: () -> Void
14+
15+
public var body: some View {
16+
NavigationView {
17+
presentedView
18+
.navigationBarTitleDisplayMode(.inline)
19+
.toolbar {
20+
ToolbarItem(placement: .navigationBarLeading) {
21+
Button {
22+
onDismiss()
23+
} label: {
24+
Image(uiImage: images.close)
25+
.customizable()
26+
.frame(height: 16)
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}

Sources/StreamChatSwiftUI/ChatChannelList/MoreChannelActionsView.swift

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ public struct MoreChannelActionsView: View {
1313

1414
@StateObject var viewModel: MoreChannelActionsViewModel
1515
@Binding var swipedChannelId: String?
16+
@State private var isPresented = false
1617
var onDismiss: () -> Void
1718

19+
@State private var presentedView: AnyView? {
20+
didSet {
21+
isPresented = presentedView != nil
22+
}
23+
}
24+
1825
public init(
1926
channel: ChatChannel,
2027
channelActions: [ChannelAction],
@@ -49,18 +56,30 @@ public struct MoreChannelActionsView: View {
4956
Divider()
5057
.padding(.horizontal, -16)
5158

52-
Button {
53-
if action.confirmationPopup != nil {
54-
viewModel.alertAction = action
55-
} else {
56-
action.action()
59+
if let destination = action.navigationDestination {
60+
Button {
61+
presentedView = destination
62+
} label: {
63+
ActionItemView(
64+
title: action.title,
65+
iconName: action.iconName,
66+
isDestructive: action.isDestructive
67+
)
68+
}
69+
} else {
70+
Button {
71+
if action.confirmationPopup != nil {
72+
viewModel.alertAction = action
73+
} else {
74+
action.action()
75+
}
76+
} label: {
77+
ActionItemView(
78+
title: action.title,
79+
iconName: action.iconName,
80+
isDestructive: action.isDestructive
81+
)
5782
}
58-
} label: {
59-
ActionItemView(
60-
title: action.title,
61-
iconName: action.iconName,
62-
isDestructive: action.isDestructive
63-
)
6483
}
6584
}
6685
}
@@ -91,6 +110,13 @@ public struct MoreChannelActionsView: View {
91110
.onTapGesture {
92111
onDismiss()
93112
}
113+
.fullScreenCover(isPresented: $isPresented) {
114+
if let fullScreenView = presentedView {
115+
MoreChannelActionsFullScreenWrappingView(presentedView: fullScreenView) {
116+
presentedView = nil
117+
}
118+
}
119+
}
94120
}
95121

96122
private var memberList: some View {

Sources/StreamChatSwiftUI/ChatChannelList/MoreChannelActionsViewModel.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import Foundation
66
import StreamChat
7+
import SwiftUI
78
import UIKit
89

910
/// View model for the more channel actions.
@@ -102,6 +103,7 @@ public struct ChannelAction: Identifiable {
102103
public let action: () -> Void
103104
public let confirmationPopup: ConfirmationPopup?
104105
public let isDestructive: Bool
106+
public var navigationDestination: AnyView?
105107

106108
public init(
107109
title: String,

Sources/StreamChatSwiftUI/Generated/L10n.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ internal enum L10n {
3333
internal static var ok: String { L10n.tr("Localizable", "alert.actions.ok") }
3434
/// Are you sure you want to unmute this
3535
internal static var unmuteChannelTitle: String { L10n.tr("Localizable", "alert.actions.unmute-channel-title") }
36+
/// View info
37+
internal static var viewInfoTitle: String { L10n.tr("Localizable", "alert.actions.view-info-title") }
3638
}
3739
internal enum Error {
3840
/// The operation couldn't be completed.

Sources/StreamChatSwiftUI/Resources/en.lproj/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"alert.actions.leave-group-title" = "Leave group";
6161
"alert.actions.leave-group-message" = "Are you sure you want to leave this group?";
6262
"alert.actions.leave-group-button" = "Leave";
63+
"alert.actions.view-info-title" = "View info";
6364

6465
"message.only-visible-to-you" = "Only visible to you";
6566
"message.deleted-message-placeholder" = "Message deleted";

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@
327327
84F2908E276B92A40045472D /* GalleryHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F2908D276B92A40045472D /* GalleryHeaderView.swift */; };
328328
84F29090276CC1280045472D /* ShareButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F2908F276CC1280045472D /* ShareButtonView.swift */; };
329329
84FF723F2782FB2E006E26C8 /* iMessagePocView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84FF723E2782FB2E006E26C8 /* iMessagePocView.swift */; };
330+
91B763A4283EB19900B458A9 /* MoreChannelActionsFullScreenWrappingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91B763A3283EB19800B458A9 /* MoreChannelActionsFullScreenWrappingView.swift */; };
331+
91B763A6283EB39600B458A9 /* MoreChannelActionsFullScreenWrappingView_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91B763A5283EB39600B458A9 /* MoreChannelActionsFullScreenWrappingView_Tests.swift */; };
332+
91CC203A283C3E7F0049A146 /* URLExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CC2039283C3E7F0049A146 /* URLExtensions.swift */; };
333+
91CC203C283C4C250049A146 /* URLUtils_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CC203B283C4C250049A146 /* URLUtils_Tests.swift */; };
330334
E3A1C01C282BAC66002D1E26 /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = E3A1C01B282BAC66002D1E26 /* Sentry */; };
331335
/* End PBXBuildFile section */
332336

@@ -692,6 +696,10 @@
692696
84F2908D276B92A40045472D /* GalleryHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryHeaderView.swift; sourceTree = "<group>"; };
693697
84F2908F276CC1280045472D /* ShareButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareButtonView.swift; sourceTree = "<group>"; };
694698
84FF723E2782FB2E006E26C8 /* iMessagePocView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iMessagePocView.swift; sourceTree = "<group>"; };
699+
91B763A3283EB19800B458A9 /* MoreChannelActionsFullScreenWrappingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoreChannelActionsFullScreenWrappingView.swift; sourceTree = "<group>"; };
700+
91B763A5283EB39600B458A9 /* MoreChannelActionsFullScreenWrappingView_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoreChannelActionsFullScreenWrappingView_Tests.swift; sourceTree = "<group>"; };
701+
91CC2039283C3E7F0049A146 /* URLExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLExtensions.swift; sourceTree = "<group>"; };
702+
91CC203B283C4C250049A146 /* URLUtils_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLUtils_Tests.swift; sourceTree = "<group>"; };
695703
/* End PBXFileReference section */
696704

697705
/* Begin PBXFrameworksBuildPhase section */
@@ -1031,6 +1039,7 @@
10311039
children = (
10321040
8465FD2B2746A95600AF091E /* ChatChannelHelpers.swift */,
10331041
8465FD2C2746A95600AF091E /* ChatChannelExtensions.swift */,
1042+
91CC2039283C3E7F0049A146 /* URLExtensions.swift */,
10341043
);
10351044
path = Utils;
10361045
sourceTree = "<group>";
@@ -1106,6 +1115,7 @@
11061115
8465FD572746A95700AF091E /* ChannelHeaderLoader.swift */,
11071116
8465FD4F2746A95600AF091E /* MoreChannelActionsView.swift */,
11081117
8465FD5B2746A95700AF091E /* MoreChannelActionsViewModel.swift */,
1118+
91B763A3283EB19800B458A9 /* MoreChannelActionsFullScreenWrappingView.swift */,
11091119
8421BCEF27A44EAE000F977D /* SearchResultsView.swift */,
11101120
);
11111121
path = ChatChannelList;
@@ -1151,6 +1161,7 @@
11511161
84C94D412757C16D007FE2B9 /* ChatChannelListTestHelpers.swift */,
11521162
848399EB275FB41B003075E4 /* ChatChannelListView_Tests.swift */,
11531163
84DEC8DA27609FA200172876 /* MoreChannelActionsView_Tests.swift */,
1164+
91B763A5283EB39600B458A9 /* MoreChannelActionsFullScreenWrappingView_Tests.swift */,
11541165
84DEC8DC2760A10500172876 /* NoChannelsView_Tests.swift */,
11551166
8413D90127A9654600A89432 /* SearchResultsView_Tests.swift */,
11561167
84D6B55927DF6EC7009C6D07 /* LoadingView_Tests.swift */,
@@ -1359,6 +1370,7 @@
13591370
84C94D52275A135F007FE2B9 /* Utils */ = {
13601371
isa = PBXGroup;
13611372
children = (
1373+
91CC203B283C4C250049A146 /* URLUtils_Tests.swift */,
13621374
84C94D53275A1380007FE2B9 /* DateUtils_Tests.swift */,
13631375
84C94D55275A1AE1007FE2B9 /* StringExtensions_Tests.swift */,
13641376
84C94D59275A2E43007FE2B9 /* StreamChat_Utils_Tests.swift */,
@@ -1661,6 +1673,7 @@
16611673
84DEC8E82760EABC00172876 /* ChatChannelDataSource.swift in Sources */,
16621674
8465FDC62746A95700AF091E /* ChannelHeaderLoader.swift in Sources */,
16631675
8465FD872746A95700AF091E /* AttachmentPickerTypeView.swift in Sources */,
1676+
91CC203A283C3E7F0049A146 /* URLExtensions.swift in Sources */,
16641677
8465FD892746A95700AF091E /* ComposerTextInputView.swift in Sources */,
16651678
8465FDBC2746A95700AF091E /* ChannelAvatarsMerger.swift in Sources */,
16661679
8465FDB82746A95700AF091E /* ImageMerger.swift in Sources */,
@@ -1706,6 +1719,7 @@
17061719
8465FD942746A95700AF091E /* AddedFileAttachmentsView.swift in Sources */,
17071720
84F29090276CC1280045472D /* ShareButtonView.swift in Sources */,
17081721
84AB7B282773D4FE00631A10 /* TypingSuggester.swift in Sources */,
1722+
91B763A4283EB19900B458A9 /* MoreChannelActionsFullScreenWrappingView.swift in Sources */,
17091723
8465FD852746A95700AF091E /* MessageView.swift in Sources */,
17101724
8465FDCA2746A95700AF091E /* MoreChannelActionsViewModel.swift in Sources */,
17111725
8465FDD12746A95700AF091E /* Images.swift in Sources */,
@@ -1756,6 +1770,7 @@
17561770
84B2B5D02819629400479CEE /* PinnedMessagesView_Tests.swift in Sources */,
17571771
84C94D1427578BF3007FE2B9 /* TemporaryData.swift in Sources */,
17581772
84C94D4F2758FE59007FE2B9 /* ChatChannelTestHelpers.swift in Sources */,
1773+
91CC203C283C4C250049A146 /* URLUtils_Tests.swift in Sources */,
17591774
84C94CCC27578B92007FE2B9 /* ChatClientUpdater_Mock.swift in Sources */,
17601775
84B2B5DA281985DA00479CEE /* FileAttachmentsView_Tests.swift in Sources */,
17611776
848399F227601231003075E4 /* ReactionsOverlayView_Tests.swift in Sources */,
@@ -1827,6 +1842,7 @@
18271842
84DEC8DF2760A1D100172876 /* MessageView_Tests.swift in Sources */,
18281843
84C94CDA27578B92007FE2B9 /* ChatUser_Mock.swift in Sources */,
18291844
847F7949282A91AD0009F74C /* ChatChannelView_Tests.swift in Sources */,
1845+
91B763A6283EB39600B458A9 /* MoreChannelActionsFullScreenWrappingView_Tests.swift in Sources */,
18301846
84C94D2C275796F7007FE2B9 /* RequestRecorderURLProtocol.swift in Sources */,
18311847
84C94CD627578B92007FE2B9 /* AttachmentUploadingState_Mock.swift in Sources */,
18321848
84C94D20275792EA007FE2B9 /* MockBackgroundTaskScheduler.swift in Sources */,

0 commit comments

Comments
 (0)