package com.bc_chat.im.module;

import com.jrmf360.rylib.modules.JrmfExtensionModule;
import com.jrmf360.rylib.rp.extend.TransferAccountPlugin;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import io.rong.imkit.RongExtension;
import io.rong.imkit.plugin.IPluginModule;
import io.rong.imlib.model.Conversation;

/**
 * author：Created by zhaohaoting on 2018/11/14
 * email：526309416@qq.com
 * desc：
 */
public class RedPackgeExtensionModule extends JrmfExtensionModule {

    private String mTargetId;

    @Override
    public void onAttachedToExtension(RongExtension extension) {
        super.onAttachedToExtension(extension);
        mTargetId = extension.getTargetId();
    }

    @Override
    public List<IPluginModule> getPluginModules(Conversation.ConversationType conversationType) {
        List<IPluginModule> pluginModuleList = new ArrayList<>();
//        if (!(conversationType == Conversation.ConversationType.SYSTEM || (conversationType == Conversation.ConversationType.PRIVATE && Const.SERVICE_ID.equals(mTargetId)))) {
        if (conversationType != Conversation.ConversationType.SYSTEM) {
            List<IPluginModule> pluginModules = super.getPluginModules(conversationType);
            Iterator<IPluginModule> iterator = pluginModules.iterator();
            while (iterator.hasNext()) {
                IPluginModule pluginModule = iterator.next();
                if (pluginModule instanceof TransferAccountPlugin) {
                    iterator.remove();
                } else {
                    pluginModuleList.add(pluginModule);
                }
            }
        }
        return pluginModuleList;
    }
}
