package com.aiosman.riderpro.utils

import com.tencent.imsdk.v2.V2TIMManager
import com.tencent.imsdk.v2.V2TIMValueCallback
import kotlin.coroutines.suspendCoroutine

object TrtcHelper {
    suspend fun loadUnreadCount(): Long {
        return suspendCoroutine { continuation ->
            V2TIMManager.getConversationManager()
                .getTotalUnreadMessageCount(object : V2TIMValueCallback<Long> {
                    override fun onSuccess(t: Long?) {
                        continuation.resumeWith(Result.success(t ?: 0))
                    }

                    override fun onError(code: Int, desc: String?) {
                        continuation.resumeWith(Result.failure(Exception("Error $code: $desc")))
                    }
                });
        }
    }
}