Community channel events
Use ChannelHandler to receive community channel events, including community channel list sync, subchannel type changes, user kicks, and subchannel deletion. The same protocol also covers general channel sync events such as pinned status, do-not-disturb level, translation strategy, and typing status.
Register the handler through NCEngine with a unique identifier string:
- Swift
- Objective-C
swift
import NexconnChatSDK
NCEngine.addChannelHandler(identifier: "MY_CHANNEL_HANDLER", handler: self)
NCEngine.removeChannelHandler(forIdentifier: "MY_CHANNEL_HANDLER")
Objective C
[NCEngine addChannelHandlerWithIdentifier:@"MY_CHANNEL_HANDLER" handler:self];
[NCEngine removeChannelHandlerForIdentifier:@"MY_CHANNEL_HANDLER"];
Community subchannel events
- Swift
- Objective-C
swift
import NexconnChatSDK
final class CommunityEventService: NSObject, ChannelHandler {
func onCommunityChannelsSyncCompleted(_ event: CommunityChannelsSyncCompletedEvent) {
print("Community channel list synced.")
}
func onCommunitySubChannelTypeChanged(_ event: CommunitySubChannelTypeChangedEvent) {
for info in event.info {
print("Subchannel type changed: \(info.changeType.rawValue)")
}
}
func onCommunitySubChannelUserKicked(_ event: CommunitySubChannelUserKickedEvent) {
for info in event.info {
print("User \(info.userId) kicked from subchannel \(info.channelIdentifier?.channelId ?? "").")
}
}
func onCommunitySubChannelDeleted(_ event: CommunitySubChannelDeletedEvent) {
for info in event.info {
print("Subchannel deleted at \(info.operationTime)")
}
}
}
Objective C
@interface MyViewController () <NCChannelHandler>
@end
@implementation MyViewController
- (void)onCommunityChannelsSyncCompleted:(NCCommunityChannelsSyncCompletedEvent *)event {
NSLog(@"Community channel list synced.");
}
- (void)onCommunitySubChannelTypeChanged:(NCCommunitySubChannelTypeChangedEvent *)event {
for (NCCommunitySubChannelTypeChangedInfo *info in event.info) {
NSLog(@"Sub-channel type changed: %ld", (long)info.changeType);
}
}
- (void)onCommunitySubChannelUserKicked:(NCCommunitySubChannelUserKickedEvent *)event {
for (NCCommunitySubChannelUserKickedInfo *info in event.info) {
NSLog(@"User %@ kicked from sub-channel.", info.userId);
}
}
- (void)onCommunitySubChannelDeleted:(NCCommunitySubChannelDeletedEvent *)event {
for (NCCommunitySubChannelDeletedInfo *info in event.info) {
NSLog(@"Sub-channel deleted at %lld", (long long)info.operationTime);
}
}
@end
General channel sync events
ChannelHandler also delivers sync events for all channel types. Implement these callbacks to keep UI state aligned with changes from other devices.
- Swift
- Objective-C
swift
import NexconnChatSDK
final class SharedChannelSyncService: NSObject, ChannelHandler {
func onRemoteChannelsSyncCompleted(_ event: RemoteChannelsSyncCompletedEvent) {
if event.error == nil {
print("Remote channel list synced.")
}
}
func onChannelStatusSyncCompleted(_ event: ChannelStatusSyncCompletedEvent) {
if event.error == nil {
print("Channel status synced.")
}
}
func onChannelPinnedSync(_ event: ChannelPinnedSyncEvent) {
print("Channel \(event.channelIdentifier.channelId) pinned: \(event.isPinned)")
}
func onChannelNoDisturbLevelSync(_ event: ChannelNoDisturbLevelSyncEvent) {
print("Channel \(event.channelIdentifier.channelId) DND level: \(event.level.rawValue)")
}
func onChannelTranslateStrategySync(_ event: ChannelTranslateStrategySyncEvent) {
print("Channel \(event.channelIdentifier.channelId) translate strategy: \(event.strategy.rawValue)")
}
func onTypingStatusChanged(_ event: TypingStatusChangedEvent) {
for info in event.userTypingStatus {
print("User \(info.userId) is typing in channel \(event.channelIdentifier.channelId)")
}
}
}
Objective C
- (void)onRemoteChannelsSyncCompleted:(NCRemoteChannelsSyncCompletedEvent *)event {
if (event.error == nil) {
NSLog(@"Remote channel list synced.");
}
}
- (void)onChannelStatusSyncCompleted:(NCChannelStatusSyncCompletedEvent *)event {
if (event.error == nil) {
NSLog(@"Channel status synced.");
}
}
- (void)onChannelPinnedSync:(NCChannelPinnedSyncEvent *)event {
NSLog(@"Channel %@ pinned: %d", event.channelIdentifier.channelId, event.isPinned);
}
- (void)onChannelNoDisturbLevelSync:(NCChannelNoDisturbLevelSyncEvent *)event {
NSLog(@"Channel %@ DND level: %ld", event.channelIdentifier.channelId, (long)event.level);
}
- (void)onChannelTranslateStrategySync:(NCChannelTranslateStrategySyncEvent *)event {
NSLog(@"Channel %@ translate strategy: %ld", event.channelIdentifier.channelId, (long)event.strategy);
}
- (void)onTypingStatusChanged:(NCTypingStatusChangedEvent *)event {
for (NCChannelUserTypingStatusInfo *info in event.userTypingStatus) {
NSLog(@"User %@ is typing in channel %@", info.userId, event.channelIdentifier.channelId);
}
}