package com.swago.room.util

import android.util.Log
import com.swago.baseswago.util.IMUtil
import com.swago.baseswago.util.LogUtil
import com.swago.baseswago.util.UserInfo
import com.tencent.imsdk.v2.V2TIMManager
import com.tencent.imsdk.v2.V2TIMMessage
import com.tencent.imsdk.v2.V2TIMValueCallback
import com.tencent.qcloud.tim.uikit.TUIKit
import com.tencent.qcloud.tim.uikit.base.IUIKitCallBack

/**
 *@date 2021/10/23 14:05
 *description:
 */
object IMSender {

    /**
     * 直播间发送公聊消息
     */
    fun sendGroupCusMessage(
        customData: ByteArray,
        groupId: String,
        callback: V2TIMValueCallback<V2TIMMessage>?,
        priority: Int = V2TIMMessage.V2TIM_PRIORITY_HIGH
    ) {
        if (IMUtil.checkIsLogin()){
            V2TIMManager.getInstance().sendGroupCustomMessage(
                customData,
                groupId,
                priority,
                callback
            )
        }else{
            TUIKit.login(UserInfo.getLoginModel()?.user_account,UserInfo.getLoginModel()?.user_sig,object:
                IUIKitCallBack {
                override fun onSuccess(data: Any?) {
                    V2TIMManager.getInstance().sendGroupCustomMessage(
                        customData,
                        groupId,
                        priority,
                        callback
                    )
                }

                override fun onError(module: String?, errCode: Int, errMsg: String?) {
                    LogUtil.d("ddd","$errCode")
                }

            })
        }
    }


}