Hi, there is an issue while getting unread count for a user in IOS UI KIT,
there is not unread count on channel list, but getting total unread count is 4
below is snap shot of chat list and also code:
var disposeBag: Set<AnyCancellable> = []
appDelegate.client?.getUserUnread().sink(receiveValue: { userUnread in
print("User's total unread count: \(userUnread.unreadCount)")
print("User's mentioned status: \(userUnread.isMentioned)")
CustomUserDefaultManager.setUnReadMessageCount(count: (userUnread.unreadCount))
DispatchQueue.main.async {
self.updateUnreadCount()
}
}).store(in: &disposeBag)
1 Like
Hello, may I know your current uikit version, please?
@SocialPlus_Support
we are using latest uikit, version 3.19.0
we have download code from this git repo:
committed 09:57AM - 23 Feb 24 UTC
@vibhorMaheshwari Thank you for the information you’ve provided. Let me pass this to our team for further review.
@vibhorMaheshwari For your issue, we recommend updating your UIKit to the latest version. You can do this by checking the following link: https://docs.amity.co/amity-uikit/changelogs/changelog#version-3.20.0-2024-03-06
@SocialPlus_Support
after updating UIKIT to latest version (3.20.0) issue hi same, here you can see below on chat list there is 1 count, but on total count unread we are getting 7.
Below is snap shot when we update UIKIT version:
@vibhorMaheshwari Let me pass this along to check with my team.
Hello @vibhorMaheshwari , please refer to this migration guide for updating unread count functionality: SDK v6.26.0 Unread Count Migration Guide | Amity Docs
@SocialPlus_Support
still not working, now count for each channel does not show any count.
for displaying unread count for each channel we are using this code:
badgeView.badge = channel.object.subChannelsUnreadCount
@vibhorMaheshwari Let me pass this on to check with my team.
Hello, could you please verify that the following steps have been fully executed?
Follow the documentation:
Initialization steps:
Initialize AmityClient and call enableUnreadCount()
Execute syncUnreadCount()
Upon entering the message list screen, invoke AmitySubChannelRepository.startMessageReceiptSync()
Use message.markRead() to mark messages as read
Note : Please ensure to remove all the previous code.
@SocialPlus_Support
We follow your steps but still not getting unread counts on channel list, please see below step wise code.
1- Initialize AmityClient and call enableUnreadCount()
do {
client = try AmityClient(apiKey: Constants.amitAppKey, region: .US)
client?.enableUnreadCount()
}
catch {
}
2- then after login user we called this method
let client : AmityClient? = appDelegate.client
client?.syncUnreadCount()
3- In AmityMessageListViewController
public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
AmityKeyboardService.shared.delegate = self
screenViewModel.startReading() // highlight this line
markChannelRead()
bottomConstraint.constant = .zero
view.endEditing(true)
}
func startReading() {
//membershipParticipation?.startReading(subChannelId: subChannelId)
// Start message receipt sync when user enters chat screen
Task {
do {
try await subChannelRepository?.startMessageReceiptSync(subChannelId: subChannelId)
} catch {
// Handle error
}
}
}
4- for mark message as read we called
func send(withText text: String?) {
let textMessage = text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
guard !textMessage.isEmpty else {
return
}
let createOptioins = AmityTextMessageCreateOptions(subChannelId: subChannelId, text: textMessage)
messageRepository.createTextMessage(options: createOptioins) { [weak self] message,_ in
self?.text = ""
message?.markRead() // highlight this line
self?.delegate?.screenViewModelEvents(for: .didSendText)
}
}
1 Like
@vibhorMaheshwari Thank you for the information provided. I will pass this on to the team for review.
@vibhorMaheshwari From the investigation, we recommend changing Step 3 and 4 as follows:
For Step 3, try this instead.
AmityMessageListScreenViewModel.swift:87|
init(channelId: String, subChannelId: String) {
self.channelId = channelId
self.subChannelId = subChannelId
membershipParticipation = AmityChannelParticipation(client: AmityUIKitManagerInternal.shared.client, andChannel: channelId)
channelRepository = AmityChannelRepository(client: AmityUIKitManagerInternal.shared.client)
messageRepository = AmityMessageRepository(client: AmityUIKitManagerInternal.shared.client)
subChannelRepository = AmitySubChannelRepository(client: AmityUIKitManagerInternal.shared.client)
Task {
do {
try await subChannelRepository.startMessageReceiptSync(subChannelId: subChannelId)
print("startMessageReceiptSync:\(subChannelId)")
} catch {
// Handle error
}
}
}
And for Step 4, try this instead.
func startReading() {
guard let latestMessage = messagesCollection?.object(at: 0) else { return }
latestMessage.markRead()
print(">>>>>>markRead: \(latestMessage.data!["text"])")
// membershipParticipation?.startReading(subChannelId: subChannelId)
}
@amitysupport
we changed according to you but its same , not getting channel list count , its printing
>>>>>>markRead: Optional(Test again)
startMessageReceiptSync:6606c49626e081398a75af35
for point 3 updated code is below
init(channelId: String, subChannelId: String) {
self.channelId = channelId
self.subChannelId = subChannelId
membershipParticipation = AmityChannelParticipation(client: AmityUIKitManagerInternal.shared.client, andChannel: channelId)
channelRepository = AmityChannelRepository(client: AmityUIKitManagerInternal.shared.client)
messageRepository = AmityMessageRepository(client: AmityUIKitManagerInternal.shared.client)
subChannelRepository = AmitySubChannelRepository(client: AmityUIKitManagerInternal.shared.client)
Task {
do {
try await subChannelRepository?.startMessageReceiptSync(subChannelId: subChannelId)
print("startMessageReceiptSync:\(subChannelId)")
} catch {
// Handle error
}
}
}
and for point 4 :
func startReading() {
guard let latestMessage = messagesCollection?.object(at: 0) else { return }
latestMessage.markRead()
print(">>>>>>markRead: \(latestMessage.data!["text"])")
}
Could you kindly check the code below and compare to your current code:
public struct AmityChannelModel {
let channelId: String
let displayName: String
let memberCount: Int
let unreadCount: Int
let avatarURL: String
let lastActivity: Date
let channelType: AmityChannelType
let avatarFileId: String?
let participation: AmityChannelParticipation
let metadata: [String:Any]
let object: AmityChannel
init(object: AmityChannel) {
self.channelId = object.channelId
self.avatarURL = object.getAvatarInfo()?.fileURL ?? ""
self.displayName = (object.displayName ?? "") == "" ? AmityLocalizedStringSet.General.anonymous.localizedString : object.displayName!
self.memberCount = object.memberCount
>>>>>>>PLEASE USE THIS
self.unreadCount = object.subChannelsUnreadCount
self.lastActivity = object.lastActivity ?? Date()
self.participation = object.participation
self.channelType = object.channelType
self.avatarFileId = object.getAvatarInfo()?.fileURL
self.metadata = object.metadata ?? [:]
self.object = object
}
@SocialPlus_Support
all this code is already in our code, please check code snap below:
is that possible to fix this issue by accessing our system remotely? if yes then please schedule a session for this, actually we are ready to make our app live and we are stuck on this.
@vibhorMaheshwari
After reviewing your code snippet, we recommend that you update the code on line 30 with the following:
self.unreadCount = object.subChannelsUnreadCount
@vibhorMaheshwari Please refer to the sample project provided by our team, where the unread count feature is functional. You can use it as a guide for implementation.