Skip to content

Commit 7bbff94

Browse files
id3adeyeeerimoq
authored andcommitted
Add support for Kick show view count setting.
Add support for Kick show view count setting. Kick added a channel setting to toggle whether the live view count is shown on the channel. This adds a matching On/Off toggle in the Kick moderation panel
1 parent 573bb87 commit 7bbff94

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

Moblin/StreamingPlatforms/Kick/KickApi.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,13 @@ class KickApi {
351351
onComplete: onComplete)
352352
}
353353

354+
func setShowViewCount(channelId: String, enabled: Bool, onComplete: @escaping (OperationResult) -> Void) {
355+
doWebV1Request(method: "PATCH",
356+
subPath: "channels/\(channelId)/settings",
357+
body: ["show_view_count": enabled],
358+
onComplete: onComplete)
359+
}
360+
354361
func setSubscribersOnlyMode(enabled: Bool, onComplete: @escaping (OperationResult) -> Void) {
355362
doV2Request(method: "PUT",
356363
subPath: "channels/\(slug)/chatroom",
@@ -530,12 +537,25 @@ class KickApi {
530537
doRequest(method: method, subPath: "internal/v1/\(subPath)", body: body, onComplete: onComplete)
531538
}
532539

540+
private func doWebV1Request(method: String,
541+
subPath: String,
542+
body: [String: Any]? = nil,
543+
onComplete: @escaping (OperationResult) -> Void)
544+
{
545+
doRequest(method: method,
546+
subPath: "v1/\(subPath)",
547+
body: body,
548+
baseUrl: "https://web.kick.com/api/",
549+
onComplete: onComplete)
550+
}
551+
533552
private func doRequest(method: String,
534553
subPath: String,
535554
body: [String: Any]? = nil,
555+
baseUrl: String = "https://kick.com/api/",
536556
onComplete: @escaping (OperationResult) -> Void)
537557
{
538-
guard let url = URL(string: "https://kick.com/api/\(subPath)") else {
558+
guard let url = URL(string: "\(baseUrl)\(subPath)") else {
539559
return
540560
}
541561
var request = URLRequest(url: url)

Moblin/Various/Model/ModelKick.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ extension Model {
206206
createKickApi(stream: stream).setSubscribersOnlyMode(enabled: enabled, onComplete: onComplete)
207207
}
208208

209+
func setKickShowViewCount(enabled: Bool, onComplete: @escaping (OperationResult) -> Void) {
210+
createKickApi(stream: stream).setShowViewCount(
211+
channelId: stream.kickChatroomChannelId ?? "",
212+
enabled: enabled,
213+
onComplete: onComplete
214+
)
215+
}
216+
209217
func createKickPoll(title: String,
210218
options: [String],
211219
duration: Int,

Moblin/View/ControlBar/QuickButton/Chat/QuickButtonChatModerationView.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,14 @@ private struct EmotesOnlyView: View {
827827
}
828828
}
829829

830+
private struct ShowViewCountView: View {
831+
let action: (Bool, @escaping (OperationResult) -> Void) -> Void
832+
833+
var body: some View {
834+
ToggleActionView(text: "Show view count on channel", image: "eye", action: action)
835+
}
836+
}
837+
830838
private struct NavigationLinkView<Content: View>: View {
831839
let text: LocalizedStringKey
832840
let image: String
@@ -922,6 +930,7 @@ private struct KickView: View {
922930
FollowersOnlyView(durations: [60, 300, 600, 3600], action: followersOnlyAction)
923931
SubscribersOnlyView(action: model.setKickSubscribersOnlyMode)
924932
EmotesOnlyView(action: model.setKickEmoteOnlyMode)
933+
ShowViewCountView(action: model.setKickShowViewCount)
925934
}
926935
Section {
927936
ForEach(ModActionType.allCases, id: \.self) {

0 commit comments

Comments
 (0)