Follow Anchor

Description of the Feature

In Voice Chat Scenarios, the Follow the host feature is an important Interactive Mode. It allows viewers to follow specific hosts, thereby establishing long-term interaction and attention relationships on the Live streaming platform. The Follow the host feature in TUILiveKit has been implemented Via Chat.
Follow feature allows users to choose other users they are interested in so that they can get the latest updates, posts, or event information promptly. You can provide personalized content recommendations based on the user's Follow list.
Fans feature refers to the status of a user being followed by others. When User A follows User B, A becomes a Fan of B.
Through the Follow and Fans features, social applications and websites can create an active and interconnected user network, promoting the dissemination of information and the building of communities.

Use Instructions

Note:
TUILiveKit's Follow the host feature relies on the Chat Follow & Fan APIs, so you need to activate the related Package bundles for Chat. For details, please refer to the Follow&Fan documentation.
Unfollowed Status
Followed Status
Broadcaster Info Panel









Follow the host: You can click the

button in the live room information area at the top left corner of the live streaming interface to follow the host
Unfollow: You can click the

button in the live room information area at the top left corner of the live streaming interface to unfollow the host
View the host's fan count: You can click the live room information area at the top left corner of the live streaming interface to pop up the live room details panel, which will display the host's fan count.

feature customization

If the current UI does not meet your needs, you can achieve your desired UI effects by modifying the source code in the directory TUILiveKit/iOS/TUILiveKit/Source/Common/View. For easier UI customization, an introduction to the files related to the follow feature is provided here.
// File location: TUILiveKit/iOS/TUILiveKit/Source/Common/View/

View // Implementation directory of Live Room Information UI Component
├── RoomInfoPanelView.swift // Detailed implementation of Live Room Information Panel View
└── RoomInfoView.swift // Detailed implementation of Live Room Information View, clicking this view will display the detailed panel view

Key code

Follow anchor

Swift
// File location: TUILiveKit/iOS/TUILiveKit/Source/Service/UserService.swift

func followUser(userId: String) -> AnyPublisher<Bool, InternalError> {
return Future<Bool, InternalError> { [weak self] promise in
guard let self = self else { return }
self.imManager?.followUser([userId]) { result in
promise(.success(true))
} fail: { err, message in
let error = InternalError(error: TIMError.invalidUserId, message: TIMError.invalidUserId.description)
promise(.failure(error))
}
}.eraseToAnyPublisher()
}

Unfollow anchor

Swift
// File location: TUILiveKit/iOS/TUILiveKit/Source/Service/UserService.swift

func unfollowUser(userId: String) -> AnyPublisher<Bool, InternalError> {
return Future<Bool, InternalError> { [weak self] promise in
guard let self = self, let imManager = self.imManager else { return }
imManager.unfollowUser([userId]) { result in
promise(.success(true))
} fail: { err, message in
let error = InternalError(error: TIMError.invalidUserId, message: TIMError.invalidUserId.description)
promise(.failure(error))
}
}.eraseToAnyPublisher()
}

View anchor's follow status

Swift
// File location: TUILiveKit/iOS/TUILiveKit/Source/Service/UserService.swift

func checkFollowType(userId: String) -> AnyPublisher<V2TIMFollowType, InternalError> {
return Future<V2TIMFollowType, InternalError> { [weak self] promise in
guard let self = self, let imManager = self.imManager else { return }
imManager.checkFollowType([userId], succ: { result in
guard let followType = result?.first?.followType else { return }
promise(.success(followType))
}, fail: { err, message in
let error = InternalError(error: TIMError.invalidUserId, message: TIMError.invalidUserId.description)
promise(.failure(error))
})
}.eraseToAnyPublisher()
}

Get number of followers

Swift
// File location: TUILiveKit/iOS/TUILiveKit/Source/Service/UserService.swift

func fetchFollowersCount(userId: String) -> AnyPublisher<Int, InternalError> {
return Future<Int, InternalError> { [weak self] promise in
guard let self = self, let imManager = self.imManager else { return }
imManager.getUserFollowInfo([userId], succ: { followInfo in
let followersCount = Int(followInfo?.first?.followersCount ?? 0)
promise(.success(followersCount))
}, fail: { err, message in
let error = InternalError(error: TIMError.invalidUserId, message: TIMError.invalidUserId.description)
promise(.failure(error))
})
}.eraseToAnyPublisher()
}