Hi,
We are using IOS UI KIT, and we are facing an issue regarding unread message count on comuuniyt type channles.
issue is when a user send a message in to a community group, then an unread count display 1 on sender message chat home page.
below is the screen shot:
@vibhorMaheshwari From your issue, could I request the full code that you’ve implemented for review?
@SocialPlus_Support
Code Snap:
func display(with channel: AmityChannelModel) {
//print(channel.object.messagePreview)
let tokenChannel = channelRepository?.getChannel(channel.object.channelId).observe { liveObject, error in
guard let channel = liveObject.snapshot else { return }
if let previewMessage = channel.messagePreview {
// You can access data of preview message in same way as AmityMessage
let text = previewMessage.data?["text"] as? String ?? "-"
let type = previewMessage.dataType
self.previewMessageLabel.text = "\(text)"
self.previewMessageLabel.alpha = 1
}
}
print("START")
print(channel.metadata)
print("END")
badgeView.badge = channel.unreadCount
memberLabel.text = ""
dateTimeLabel.text = AmityDateFormatter.Chat.getDate(date: channel.lastActivity)
titleLabel.text = channel.displayName
avatarView.placeholder = AmityIconSet.defaultAvatar
switch channel.channelType {
case .standard:
avatarView.setImage(withImageURL: channel.avatarURL, placeholder: AmityIconSet.defaultGroupChat)
memberLabel.text = "(\(channel.memberCount))"
case .conversation:
//avatarView.setImage(withImageURL: channel.avatarURL, placeholder: AmityIconSet.defaultAvatar)
memberLabel.text = nil
titleLabel.text = channel.displayName
token?.invalidate()
if !channel.getOtherUserId().isEmpty {
token = repository?.getUser(channel.getOtherUserId()).observeOnce { [weak self] user, error in
guard let userObject = user.snapshot else { return }
self?.titleLabel.text = userObject.displayName
//print("avatarCustomUrl = \(userObject.avatarCustomUrl ?? "")")
self?.avatarView.setImage(withImageURL: "\(userObject.avatarCustomUrl ?? "")", placeholder: AmityIconSet.defaultAvatar)
}
}
else{
avatarView.setImage(withImageURL: channel.avatarURL, placeholder: AmityIconSet.defaultAvatar)
}
case .community:
avatarView.setImage(withImageURL: channel.avatarURL, placeholder: AmityIconSet.defaultGroupChat)
memberLabel.text = "(\(channel.memberCount))"
case .private, .live, .broadcast, .unknown:
break
@unknown default:
break
}
}
@vibhorMaheshwari Thanks for the info; I will report back to my team with your details.
@vibhorMaheshwari Following consultation with our team, we would like you to try calling the function to mark the channel as read after successfully sending a message. You can find more details on this process in the following link: https://docs.amity.co/amity-sdk/chat/channels/unread-count/mark-channel-as-read.
@SocialPlus_Support
markAsRead method is not working for community channles,
below is our code snap:
let tokenChannel = channelRepository?.getChannel(screenViewModel.getChannelId()).observe { liveObject, error in
guard let channel = liveObject.snapshot else { return }
Task {
print(channel.displayName ?? "")
try await channel.markAsRead()
}
}
Hello, could you provide more context, please? What’s the behaviour? Are there any errors appear?
@SocialPlus_Support
not there is no error occurs, but count is still on channels after using this method.
@vibhorMaheshwari Thank you for providing the information. I will pass this along to check with my team, and I will get back to you.