Java Code Examples for com.hyphenate.chat.EMConversation#EMConversationType

The following examples show how to use com.hyphenate.chat.EMConversation#EMConversationType . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HxChatPresenter.java    From FamilyChat with Apache License 2.0 6 votes vote down vote up
/**
 * 重新发送某条消息
 */
public void resendMessage(EMMessage message, int position)
{
    EMConversation.EMConversationType conType = mViewImpl.getConversationType();
    String conId = mViewImpl.getConversationId();
    //移除已有消息
    HxChatHelper.getInstance().deleteMessage(conType, conId, message);
    mViewImpl.removeMessage(message, position);
    //重发消息
    switch (message.getType())
    {
        case TXT:
            EMTextMessageBody textMessageBody = (EMTextMessageBody) message.getBody();
            sendTextMessage(conType, conId, textMessageBody.getMessage());
            break;
        case VOICE:
            EMVoiceMessageBody voiceMessageBody = (EMVoiceMessageBody) message.getBody();
            sendVoiceMessage(conType, conId, voiceMessageBody.getLocalUrl(), voiceMessageBody.getLength());
            break;
        case IMAGE:
            EMImageMessageBody imageMessageBody = (EMImageMessageBody) message.getBody();
            sendImageMessage(conType, conId, imageMessageBody.getLocalUrl(), imageMessageBody.isSendOriginalImage());
            break;
    }
}
 
Example 2
Source File: HxImageDetailModel.java    From FamilyChat with Apache License 2.0 6 votes vote down vote up
public Pair<List<EMMessage>, Integer> initData(EMConversation.EMConversationType conType, String conId, String firstVisiableMsgId)
{
    int startPosition = 0;
    List<EMMessage> messageList = HxChatHelper.getInstance().searchMsgsInConByMsgType(conType, conId, EMMessage.Type.IMAGE);
    if (StringUtil.isNotEmpty(firstVisiableMsgId))
    {
        for (int i = 0; i < messageList.size(); i++)
        {
            if (StringUtil.isEquals(messageList.get(i).getMsgId(), firstVisiableMsgId))
            {
                startPosition = i;
                break;
            }
        }
    }
    return new Pair<>(messageList, startPosition);
}
 
Example 3
Source File: HxChatPresenter.java    From FamilyChat with Apache License 2.0 6 votes vote down vote up
/**
 * 发送若干张图片消息
 */
public void sendImageMessages(final EMConversation.EMConversationType conType, final String conId, List<ImageBean> list)
{
    int delay = 0;
    for (final ImageBean imageBean : list)
    {
        mMainHandler.postDelayed(new Runnable()
        {
            @Override
            public void run()
            {
                sendImageMessage(conType, conId, imageBean.getImagePath(), false);
            }
        }, delay);
        delay += 400;
    }
}
 
Example 4
Source File: HxChatPresenter.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 发送语音消息
 */
public void sendVoiceMessage(EMConversation.EMConversationType conType, String conId, String filePath, int seconds)
{
    EMMessage emMessage = HxChatHelper.getInstance().createVoiceMessage(getChatTypeFromConType(conType), conId, filePath, seconds);
    emMessage.setMessageStatusCallback(new MessageStatusCallBack(emMessage));
    mViewImpl.addNewMessage(emMessage, true);
    HxChatHelper.getInstance().sendMessage(emMessage);
}
 
Example 5
Source File: HxChatHelper.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 搜索某条会话中某种类型的所有消息
 *
 * @param conType 会话类型
 * @param conId   会话id
 * @param type    消息类型
 */
public List<EMMessage> searchMsgsInConByMsgType(EMConversation.EMConversationType conType, String conId, EMMessage.Type type)
{
    List<EMMessage> list = new ArrayList<>();
    EMConversation conversation = getConversation(conId, conType);
    if (conversation != null)
        list.addAll(conversation.searchMsgFromDB(type, 0, Integer.MAX_VALUE, null, null));
    return list;
}
 
Example 6
Source File: HxChatPresenter.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 发送视频消息
 */
public void sendVideoMessage(final EMConversation.EMConversationType conType, final String conId, final String filePath, final long duration)
{
    mViewImpl.showHandlingDialog(R.string.dialog_chat_pgb_video);
    //获取缩略图并保存
    ThreadManager.getInstance().addNewRunnable(new Runnable()
    {
        @Override
        public void run()
        {
            Bitmap thumb = createVideoThumbBitmap(filePath, 240, 300, MediaStore.Images.Thumbnails.MINI_KIND);
            final String thumbPath = BmpUtils.saveBmp(thumb, FCCache.getInstance().getImageCachePath(), createVideoThumbName());
            //发送消息
            mMainHandler.post(new Runnable()
            {
                @Override
                public void run()
                {
                    mViewImpl.closeHandlingDialog();
                    EMMessage emMessage = HxChatHelper.getInstance().createVideoMessage(getChatTypeFromConType(conType)
                            , conId, filePath, thumbPath, (int) (duration / 1000));
                    emMessage.setMessageStatusCallback(new MessageStatusCallBack(emMessage));
                    mViewImpl.addNewMessage(emMessage, true);
                    HxChatHelper.getInstance().sendMessage(emMessage);
                }
            });
        }
    });
}
 
Example 7
Source File: HxChatPresenter.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 发送图片消息
 */
public void sendImageMessage(EMConversation.EMConversationType conType, String conId, String filePath, boolean sendOriginFile)
{
    EMMessage emMessage = HxChatHelper.getInstance().createImageMessage(getChatTypeFromConType(conType), conId, filePath, sendOriginFile);
    emMessage.setMessageStatusCallback(new MessageStatusCallBack(emMessage));
    mViewImpl.addNewMessage(emMessage, true);
    HxChatHelper.getInstance().sendMessage(emMessage);
}
 
Example 8
Source File: HxChatPresenter.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 发送文本消息
 */
public void sendTextMessage(EMConversation.EMConversationType conType, String conId, String message)
{
    EMMessage emMessage = HxChatHelper.getInstance().createTextMessage(getChatTypeFromConType(conType), conId, message);
    emMessage.setAttribute(HxMsgAttrConstant.TXT_ATTR_KEY, HxMsgAttrConstant.NORMAL_TEXT_MSG);
    emMessage.setMessageStatusCallback(new MessageStatusCallBack(emMessage));
    mViewImpl.addNewMessage(emMessage, true);
    HxChatHelper.getInstance().sendMessage(emMessage);
}
 
Example 9
Source File: HxChatPresenter.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 根据EMConversationType获取ChatType
 */
private EMMessage.ChatType getChatTypeFromConType(EMConversation.EMConversationType conType)
{
    if (conType == EMConversation.EMConversationType.Chat)
        return EMMessage.ChatType.Chat;
    else if (conType == EMConversation.EMConversationType.GroupChat)
        return EMMessage.ChatType.GroupChat;
    else if (conType == EMConversation.EMConversationType.ChatRoom)
        return EMMessage.ChatType.ChatRoom;
    else
        return EMMessage.ChatType.Chat;
}
 
Example 10
Source File: HxImageDetailPresenter.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 扫描数据获取全部图片消息
 */
public void scanImageData(final EMConversation.EMConversationType conType, final String conId, final String firstVisiableMsgId)
{
    ThreadManager.getInstance().addNewRunnable(new Runnable()
    {
        @Override
        public void run()
        {
            Pair<List<EMMessage>, Integer> resultPair = mModel.initData(conType, conId, firstVisiableMsgId);
            onScanDataSuccess(resultPair.first, resultPair.second);
        }
    });
}
 
Example 11
Source File: HxImageDetailActivity.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
private static int emConType2IntConType(EMConversation.EMConversationType type)
{
    if (type == EMConversation.EMConversationType.Chat)
        return CON_TYPE_CHAT;
    else if (type == EMConversation.EMConversationType.GroupChat)
        return CON_TYPE_GROUP_CHAT;
    else if (type == EMConversation.EMConversationType.ChatRoom)
        return CON_TYPE_CHAT_ROOM;
    else if (type == EMConversation.EMConversationType.DiscussionGroup)
        return CON_TYPE_DISCUSS_GROUP;
    else if (type == EMConversation.EMConversationType.HelpDesk)
        return CON_TYPE_HELP_DESK;
    return CON_TYPE_CHAT;
}
 
Example 12
Source File: HxImageDetailActivity.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 跳转到大图消息界面的公共方法
 *
 * @param conType    会话类型
 * @param conId      会话id
 * @param firstMsgId 第一张图的消息id
 */
public static void start(Activity activity, EMConversation.EMConversationType conType, String conId, String firstMsgId)
{
    Intent intent = new Intent(activity, HxImageDetailActivity.class);
    intent.putExtra(INTENT_KEY_CON_TYPE, emConType2IntConType(conType));
    intent.putExtra(INTENT_KEY_CON_ID, conId);
    intent.putExtra(INTENT_KEY_FIRST_MSGID, firstMsgId);
    activity.startActivity(intent);
}
 
Example 13
Source File: HxChatPresenter.java    From FamilyChat with Apache License 2.0 4 votes vote down vote up
/**
 * 加载一页消息记录
 *
 * @param conId       会话id
 * @param conType     会话类型
 * @param isFirstLoad 是否为第一次加载
 */
public void loadOnePageData(EMConversation.EMConversationType conType, String conId, final boolean isFirstLoad)
{
    String startMsgId = null;
    EMConversation conversation = HxChatHelper.getInstance().getConversation(conId, conType);

    //会话不存在时
    if (conversation == null)
    {
        if (isFirstLoad)
        {
            mViewImpl.loadOnePageMessagesSuccess(null, isFirstLoad);
        } else
        {
            mViewImpl.showNoMoreMessageWarning();
            mViewImpl.onPtrFail();
        }
        return;
    }

    //获取适配器里第一条消息,以便获取起始msgId
    EMMessage firstMessage = mViewImpl.getAdapterFirstMsg();
    if (firstMessage != null)
        startMsgId = firstMessage.getMsgId();

    int cacheMsgCount = mViewImpl.getAdapterMsgCount();//适配器里所有消息的数量
    //当适配器消息数量小于该会话所有消息数量就去数据库拉取
    if (cacheMsgCount < conversation.getAllMsgCount())
    {
        final List<EMMessage> messages = HxChatHelper.getInstance().loadMessageFromDB(conType, conId, startMsgId, EACH_PAGE_SIZE);
        //第一次加载直接拉到底部
        if (isFirstLoad)
        {
            mViewImpl.loadOnePageMessagesSuccess(messages, isFirstLoad);
            mViewImpl.scrollToBottom();
        }
        //下拉刷新加载
        else
        {
            mViewImpl.onPtrSuccess();
            //延迟一会儿再将数据传过去,不然太快了
            mMainHandler.postDelayed(new Runnable()
            {
                @Override
                public void run()
                {
                    mViewImpl.loadOnePageMessagesSuccess(messages, isFirstLoad);
                }
            }, 500);
        }
    } else if (!isFirstLoad)
    {
        mViewImpl.showNoMoreMessageWarning();
        mViewImpl.onPtrFail();
    }
}
 
Example 14
Source File: HxChatActivity.java    From FamilyChat with Apache License 2.0 4 votes vote down vote up
@Override
public EMConversation.EMConversationType getConversationType()
{
    return mConType;
}
 
Example 15
Source File: HxChatHelper.java    From FamilyChat with Apache License 2.0 3 votes vote down vote up
/**
 * 删除某条消息
 *
 * @param conType 会话类型
 * @param conId   会话id
 * @param message 消息
 */
public void deleteMessage(EMConversation.EMConversationType conType, String conId, EMMessage message)
{
    EMConversation conversation = getConversation(conId, conType);
    if (conversation != null)
        conversation.removeMessage(message.getMsgId());
}
 
Example 16
Source File: HxChatView.java    From FamilyChat with Apache License 2.0 2 votes vote down vote up
/**
 * 获取会话类型
 */
EMConversation.EMConversationType getConversationType();
 
Example 17
Source File: HxChatHelper.java    From FamilyChat with Apache License 2.0 2 votes vote down vote up
/**
 * 获取某条会话
 *
 * @param conId   会话id
 * @param conType 会话类型
 * @return 会话对象
 */
public EMConversation getConversation(String conId, EMConversation.EMConversationType conType)
{
    return EMClient.getInstance().chatManager().getConversation(conId, conType, false);
}
 
Example 18
Source File: HxChatHelper.java    From FamilyChat with Apache License 2.0 2 votes vote down vote up
/**
 * 从数据库中加载若干条历史消息
 *
 * @param conType    会话类型
 * @param conId      会话id
 * @param startMsgId 起始消息id
 * @param size       消息数量
 */
public List<EMMessage> loadMessageFromDB(EMConversation.EMConversationType conType, String conId, String startMsgId, int size)
{
    EMConversation conversation = getConversation(conId, conType);
    return conversation != null ? conversation.loadMoreMsgFromDB(startMsgId, size) : null;
}