package com.bc_chat.im.chat;

import com.bc_chat.im.adapter.ConversationListAdapterEx;

import io.rong.imkit.RongIM;
import io.rong.imkit.model.UIConversation;
import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Message;
import io.rong.message.GroupNotificationMessage;

public class ChatUtil {
    public static UIConversation getUIConversation(ConversationListAdapterEx conversationListAdapterEx, String groupId) {
        for (int index = 0; index < conversationListAdapterEx.getCount(); index++) {
            UIConversation uiConversation = conversationListAdapterEx.getItem(index);
            if (uiConversation != null
                    && uiConversation.getConversationType() == Conversation.ConversationType.GROUP
                    && uiConversation.getConversationTargetId().equals(groupId)) {
                return uiConversation;
            }
        }
        return null;
    }

    public static void removeMessage(Message message) {
        RongIM.getInstance().deleteMessages(new int[]{message.getMessageId()}, null);
    }

    public static boolean isGroupInvite(Message message) {
        if (message != null) {
            if (message.getContent() instanceof GroupNotificationMessage) {
                GroupNotificationMessage groupNotificationMessage = (GroupNotificationMessage) message.getContent();
                if (groupNotificationMessage != null && groupNotificationMessage.getOperation().equalsIgnoreCase("Add")) {
                    return true;
                }
            }
        }
        return false;
    }
}
