Subchannel unread count doesn't work for community channels

The unread count for community subchannels is always 0. I’m calling client.enableUnreadCount() after AmityClient is initialised. The total unread count is working fine:

.$totalUnreadCount
            .sink(receiveValue: {
                print("Total unread count \($0)")
            })
            .store(in: &cancellables)

and I’m getting real time updates, but when I try to read subchannel unread count then it’s always 0:

.getChannels(channelIds: channelIds)
            .observe { [weak self] liveCollection, _, error in
                    print("is unread enabled \(snapshot.isUnreadCountSupported)")
                    print("Subchannel unread count \(snapshot.subChannelsUnreadCount)")
}

the isUnreadCountSupported returns true

I’m using the open source version of amity for iOS, I’ve tested this on the latest version of the UIKit SDK as well as on the latest beta. My region is set to US

Hello @nadol, let us pass to the team to investigate this. Thank you.

@nadol Regarding the issue you encountered, we recommend that you review the sample project available at this link: Sample Project. For additional information, please refer to the SDK v6.26.0 Unread Count Migration Guide

@amitysupport Do you have any instructions on how to use this sample app? What api key should I use?

@amitysupport when I try to use the victimIOS then I’m getting warning printed in the console:

[Sample App] register device with userId 'victimIOS' failed
[Sample App] register device failed Invalid API key

Hello @nadol you should be able to use your own environment - your userid and apikey.

Please let us know if you still face the issue.

@amitysupport after investigating this issue it turns out that the unread counter works fine for channels created on iOS side, I pasted the code from the sample app for creating channels and then when I join the channels created on iOS side everything works. It doesn’t work for channels created on backend side. My colleague is going to share his code snippets today to show you how he creates the channels on backend side. We compared channels created on iOS and backend sides in admin panel and found no differences

@nadol Can I confirm that by “backend” you mean you created the channel from the console and the unread count did not work?

@amitysupport No, I have a backend service which is responsible for creating channels and it’s using Amity API api to do so. Here’s a snippet from my colleague who’s responsible for the backend service showing how he creates the channel:

const response = await axios.post(
        CREATE_CHANNEL_URL,
        {
          channelId,
          type: "community",
          displayName: channelName,
          metadata: {},
          tags: [],
          userIds: [],
          isMuted: false,
          messageAutoDeleteEnabled: true,
          autoDeleteMessageByFlagLimit: 100,
          isPublic: true,
          notificationMode: "default"
        },
        {
          headers: { Authorization: `Bearer ${config.adminToken}` }
        }
      )

then on the iOS side I’m observing the channels, joining them and the unread counter doesn’t work.

But when I was testing stuff using the sample app you provided then I found out that when I create some dummy channels on iOS side just for testing purposes then the unread counter works.

    var token: AmityNotificationToken?
    func createChannel() {
        if let user = AmityUIKitManager.client.user?.snapshot {
            let builder = AmityCommunityChannelBuilder()

            builder.setUserIds([user.userId])
            builder.setDisplayName("Test channel")
            token?.invalidate()
            token = channelRepository.getChannel("test-id").observe({ [weak self] (channel, error) in
                guard let weakSelf = self else { return }
                if error != nil {
                    weakSelf.createNewCommiunityChannel(builder: builder)
                }
            })
        }
    }

    private func createNewCommiunityChannel(builder: AmityCommunityChannelBuilder) {
        AmityAsyncAwaitTransformer.toCompletionHandler(asyncFunction: channelRepository.createChannel, parameters: builder) { [weak self] channelObject, error in
            guard let weakSelf = self else { return }
            if let error = error {
                print("FAILED \(error)")
            }
            if let channelId = channelObject?.channelId, let subChannelId = channelObject?.defaultSubChannelId {
                print("CHANNEL CREATED")
            }
        }
    }

Can this be caused by the fact that when creating channels on the backend the userIds is not set? Later on I’m joining these channels on iOS side and I verified that the members count is greater than 0 for these channels. Or can you spot any other differences?

1 Like

@nadol Let me pass this to check with my team.

@nadol Did you try setting the userid and reproducing the issue again?

@amitysupport I just checked and it’s still not working

1 Like

Hi @nadol our team is currently investigating this, we will keep you posted on any updates.

Hello @nadol , We have resolved the issue you encountered with the Subchannel Unreadcount. Please verify the fix at your earliest convenience and let us know if there are any further issues.

In the meantime I switched to open source version of amity GitHub - AmityCo/Amity-Social-Cloud-UIKit-iOS-OpenSource: Amity Social Cloud offers Chat and Social SDKs to streamline app development. Dive into our UI Kits and sample apps in our repositories to spark your creativity. To learn more, visit amity.co. How can I update the AmitySDK to latest version in such case? Or do I have to update something else?

Hello, to update SDK version, please follow these steps:

  1. Go to this link: Install iOS SDK | Amity Docs
  2. Download the latest SDK version.
  3. Replace the existing SDK in the UIKit at AmityUIKit/Frameworks/AmitySDK.

@amitysupport like I mentioned I’m using open source uikit version which is using SharedFrameworks to provide AmitySDK

@nadol Let me pass this on to my team to check, and I’ll get back to you.

@nadol After consulting with the team, we recommend updating to version 4.0.0 beta 11, as it already includes the updated SDK version. Updating the SDK separately is not advisable due to performance concerns and the potential for further issues.