package com.bc_chat.im.plug

import com.bc_chat.bc_base.utils.Const
import io.rong.callkit.AudioPlugin
import io.rong.imkit.IExtensionModule
import io.rong.imkit.RongExtension
import io.rong.imkit.RongIM
import io.rong.imkit.emoticon.IEmoticonTab
import io.rong.imkit.plugin.IPluginModule
import io.rong.imkit.plugin.ImagePlugin
import io.rong.imkit.widget.provider.ImageMessageItemProvider
import io.rong.imlib.model.Conversation
import io.rong.imlib.model.Message
import io.rong.message.ImageMessage

/**
 * author：Created by zhaohaoting on 2019/3/15
 * email：526309416@qq.com
 * desc：
 */
class AudioExtensioModule : IExtensionModule {
    private var mTargetId: String? = null

    override fun onAttachedToExtension(extension: RongExtension) {
        mTargetId = extension.targetId
    }

    override fun onInit(appKey: String) {
        //自定义震动消息
        RongIM.registerMessageType(ImageMessage::class.java)
        RongIM.registerMessageTemplate(ImageMessageItemProvider())
    }

    override fun onConnect(token: String) {}


    override fun onDetachedFromExtension() {}

    override fun onReceivedMessage(message: Message) {}

    override fun getPluginModules(conversationType: Conversation.ConversationType): List<IPluginModule> {
        val pluginModules = arrayListOf<IPluginModule>()
//        if (!(conversationType == Conversation.ConversationType.SYSTEM || conversationType == Conversation.ConversationType.PRIVATE && Const.SERVICE_ID == mTargetId)) {
//            pluginModules.add(AudioPlugin())
//        }
        if (conversationType != Conversation.ConversationType.SYSTEM) {
            pluginModules.add(AudioPlugin())
        }
        return pluginModules
    }

    override fun getEmoticonTabs(): List<IEmoticonTab>? {
        return null
    }

    override fun onDisconnect() {}
}