Hello, I try to get user heartBeat but it always nil
here login
func login(sessionHandler: SessionHandler, id: String, name: String?, token: String?, imageUrl: String) {
Task { @MainActor in
do {
let client = AmityUIKitManager.client
try await client.login(userId: id,
displayName: name,
authToken: .empty,
sessionHandler: sessionHandler)
try await client.presence.enable()
try await client.presence.startHeartbeat()
let builder = AmityUserUpdateBuilder()
builder.setAvatarCustomUrl(imageUrl)
builder.setDisplayName(name)
client.updateUser(builder) { success, _ in
}
} catch {
print("Login error: \(error)")
}
}
}
func display(with channel: AmityChannelModel) {
badgeView.badge = channel.unreadCount
dateTimeLabel.text = AmityDateFormatter.Chat.getDate(date: channel.lastActivity)
switch channel.channelType {
case .standard:
avatarView.setImage(withImageURL: channel.avatarURL, placeholder: AmityIconSet.defaultGroupChat)
case .conversation:
var currentUser = channel.object.currentMembership?.user
let membershipParticipation = AmityChannelParticipation(client: AmityUIKitManager.client, andChannel: channel.channelId)
token = membershipParticipation
.getMembers(filter: .all, sortBy: .firstCreated, roles: [])
.observeOnce({ members, change, error in
for i in members.snapshots {
if i.userId != currentUser?.userId && !i.userId.hasPrefix("_admin") {
self.titleLabel.text = i.user?.displayName
let imageUrl = i.user?.avatarCustomUrl ?? ""
self.avatarView.loadImage(url: imageUrl)
print( i.user?.lastHeartbeat ) <<< here nil
if let lastHeartbeat = i.user?.lastHeartbeat {
let timeInterval = Date().timeIntervalSince(lastHeartbeat)
if timeInterval > 60 {
self.isOnlineImage.backgroundColor = UIColor(named: "secondUnderlineColor")
} else {
self.isOnlineImage.backgroundColor = .clear
}
} else {
print("No lastHeartbeat available")
}
let text = channel.object.messagePreview?.data?["text"] as? String ?? ""
if !text.isEmpty {
self.previewMessageLabel.font = UIFont(name: "Inter-Regular", size: 14)
self.previewMessageLabel.text = text
} else {
if channel.object.messagePreview?.dataType == .audio {
self.crownImage.isHidden = true
self.previewLeadingConstraint.constant = 0
self.previewMessageLabel.font = UIFont(name: "Inter-Regular", size: 14)
self.previewMessageLabel.textColor = AmityColorSet.base.blend(.shade2)
self.previewMessageLabel.text = "Audio"
} else if channel.object.messagePreview?.dataType == .video {
self.crownImage.isHidden = true
self.previewLeadingConstraint.constant = 0
self.previewMessageLabel.font = UIFont(name: "Inter-Regular", size: 14)
self.previewMessageLabel.textColor = AmityColorSet.base.blend(.shade2)
self.previewMessageLabel.text = "Video"
} else if channel.object.messagePreview?.dataType == .image {
self.crownImage.isHidden = true
self.previewLeadingConstraint.constant = 0
self.previewMessageLabel.font = UIFont(name: "Inter-Regular", size: 14)
self.previewMessageLabel.textColor = AmityColorSet.base.blend(.shade2)
self.previewMessageLabel.text = "Image"
} else {
self.crownImage.isHidden = true
self.previewLeadingConstraint.constant = 0
self.previewMessageLabel.font = UIFont(name: "Fraunces9pt-SemiBold", size: 14)
self.previewMessageLabel.textColor = .black
let name = i.user?.displayName ?? ""
self.previewMessageLabel.text = "Start conversation with \(name)"
}
}
}
}
})
case .community:
avatarView.setImage(withImageURL: channel.avatarURL, placeholder: AmityIconSet.defaultGroupChat)
case .private, .live, .broadcast, .unknown:
break
@unknown default:
break
}
}