com.hyphenate.chat.EMConversation Java Examples

The following examples show how to use com.hyphenate.chat.EMConversation. 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: MyEaseConversationList.java    From Social with Apache License 2.0 6 votes vote down vote up
/**
 * 根据最后一条消息的时间排序
 *
 * @param usernames
 */
private void sortConversationByLastChatTime(List<Pair<Long, EMConversation>> conversationList) {
    Collections.sort(conversationList, new Comparator<Pair<Long, EMConversation>>() {
        @Override
        public int compare(final Pair<Long, EMConversation> con1, final Pair<Long, EMConversation> con2) {

            if (con1.first == con2.first) {
                return 0;
            } else if (con2.first > con1.first) {
                return 1;
            } else {
                return -1;
            }
        }

    });
}
 
Example #3
Source File: MyEaseConversationListFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
/**
 * 根据最后一条消息的时间排序
 *
 * @param usernames
 */
private void sortConversationByLastChatTime(List<Pair<Long, EMConversation>> conversationList) {
    Collections.sort(conversationList, new Comparator<Pair<Long, EMConversation>>() {
        @Override
        public int compare(final Pair<Long, EMConversation> con1, final Pair<Long, EMConversation> con2) {

            if (con1.first == con2.first) {
                return 0;
            } else if (con2.first > con1.first) {
                return 1;
            } else {
                return -1;
            }
        }

    });
}
 
Example #4
Source File: ChatActivityTest.java    From Social with Apache License 2.0 6 votes vote down vote up
@Override
        public void onReceive(Context context, Intent intent) {
            abortBroadcast();

            //meseage id
            String message_id = intent.getStringExtra("msgid");
            String username = intent.getStringExtra("from");
            EMMessage emMessage = EMClient.getInstance().chatManager().getMessage(message_id);
            EMConversation conversation = EMClient.getInstance().chatManager().getConversation(username);
//            if(emMessage.getType() == EMMessage.ChatType.GroupChat){
//
//            }
            if(!username.equals(username)){
                return;
            }
            conversation.insertMessage(emMessage);
            chatItemBaseAdapter.notifyDataSetChanged();
            listView.setAdapter(chatItemBaseAdapter);
            listView.setSelection(listView.getCount() - 1);
        }
 
Example #5
Source File: EaseConversationListFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
/**
 * 根据最后一条消息的时间排序
 * 
 * @param usernames
 */
private void sortConversationByLastChatTime(List<Pair<Long, EMConversation>> conversationList) {
    Collections.sort(conversationList, new Comparator<Pair<Long, EMConversation>>() {
        @Override
        public int compare(final Pair<Long, EMConversation> con1, final Pair<Long, EMConversation> con2) {

            if (con1.first == con2.first) {
                return 0;
            } else if (con2.first > con1.first) {
                return 1;
            } else {
                return -1;
            }
        }

    });
}
 
Example #6
Source File: EaseConversationList.java    From Social with Apache License 2.0 6 votes vote down vote up
/**
 * 根据最后一条消息的时间排序
 * 
 * @param usernames
 */
private void sortConversationByLastChatTime(List<Pair<Long, EMConversation>> conversationList) {
    Collections.sort(conversationList, new Comparator<Pair<Long, EMConversation>>() {
        @Override
        public int compare(final Pair<Long, EMConversation> con1, final Pair<Long, EMConversation> con2) {

            if (con1.first == con2.first) {
                return 0;
            } else if (con2.first > con1.first) {
                return 1;
            } else {
                return -1;
            }
        }

    });
}
 
Example #7
Source File: EaseConversationListFragment.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * sort conversations according time stamp of last message
 * 
 * @param conversationList
 */
private void sortConversationByLastChatTime(List<Pair<Long, EMConversation>> conversationList) {
    Collections.sort(conversationList, new Comparator<Pair<Long, EMConversation>>() {
        @Override
        public int compare(final Pair<Long, EMConversation> con1, final Pair<Long, EMConversation> con2) {

            if (con1.first.equals(con2.first)) {
                return 0;
            } else if (con2.first.longValue() > con1.first.longValue()) {
                return 1;
            } else {
                return -1;
            }
        }

    });
}
 
Example #8
Source File: EaseConversationList.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 根据最后一条消息的时间排序
 * 
 * @param usernames
 */
private void sortConversationByLastChatTime(List<Pair<Long, EMConversation>> conversationList) {
    Collections.sort(conversationList, new Comparator<Pair<Long, EMConversation>>() {
        @Override
        public int compare(final Pair<Long, EMConversation> con1, final Pair<Long, EMConversation> con2) {

            if (con1.first == con2.first) {
                return 0;
            } else if (con2.first > con1.first) {
                return 1;
            } else {
                return -1;
            }
        }

    });
}
 
Example #9
Source File: ChatListFragment.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 根据最后一条消息的时间排序
 *
 * @param
 */
private void sortConversationByLastChatTime(List<Pair<Long, EMConversation>> conversationList) {
    Collections.sort(conversationList, new Comparator<Pair<Long, EMConversation>>() {
        @Override
        public int compare(final Pair<Long, EMConversation> con1, final Pair<Long, EMConversation> con2) {

            if (con1.first == con2.first) {
                return 0;
            } else if (con2.first > con1.first) {
                return 1;
            } else {
                return -1;
            }
        }

    });
}
 
Example #10
Source File: ChatListActivity.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 根据最后一条消息的时间排序
 *
 * @param
 */
private void sortConversationByLastChatTime(List<Pair<Long, EMConversation>> conversationList) {
    Collections.sort(conversationList, new Comparator<Pair<Long, EMConversation>>() {
        @Override
        public int compare(final Pair<Long, EMConversation> con1, final Pair<Long, EMConversation> con2) {

            if (con1.first == con2.first) {
                return 0;
            } else if (con2.first > con1.first) {
                return 1;
            } else {
                return -1;
            }
        }

    });
}
 
Example #11
Source File: SortConversationComparator.java    From FamilyChat with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(EMConversation con01, EMConversation con02)
{
    if (con01.getLastMessage() == null)
        return -1;
    else if (con02.getLastMessage() == null)
        return -1;

    long timeStamp01 = con01.getLastMessage().getMsgTime();
    long timeStamp02 = con02.getLastMessage().getMsgTime();
    if (timeStamp01 == timeStamp02)
        return 0;
    else if (timeStamp01 < timeStamp02)
        return 1;
    else
        return -1;
}
 
Example #12
Source File: ConversationModel.java    From FamilyChat with Apache License 2.0 6 votes vote down vote up
/**
 * 获取所有会话
 */
public List<HxConversation> getAllConversations()
{
    List<HxConversation> resultList = new ArrayList<>();

    //获取环信会话对象并排序
    List<EMConversation> allConversations = new ArrayList<>();
    Map<String, EMConversation> conversationMap = HxChatHelper.getInstance().getAllConversations();
    if (conversationMap != null && conversationMap.size() > 0)
    {
        allConversations.addAll(conversationMap.values());
        Collections.sort(allConversations, new SortConversationComparator());
    }
    //关联用户数据
    for (EMConversation conversation : allConversations)
    {
        HxConversation hxConversation = new HxConversation();
        hxConversation.setEmConversation(conversation);
        hxConversation.setUserBean(UserDao.getInstance().queryUserByPhone(conversation.conversationId()));
        resultList.add(hxConversation);
    }

    return resultList;
}
 
Example #13
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 #14
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 #15
Source File: HxChatHelper.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 获取所有未读消息总数
 */
public int getAllUnreadMsgCount()
{
    int count = 0;
    Map<String, EMConversation> conversationMap = getAllConversations();
    if (conversationMap != null && conversationMap.size() > 0)
    {
        for (EMConversation conversation : conversationMap.values())
        {
            count += conversation.getUnreadMsgCount();
        }
    }
    return count;
}
 
Example #16
Source File: MyEaseConversationListFragment.java    From Social with Apache License 2.0 5 votes vote down vote up
/**
 * 获取会话列表
 *
 * @param context
 * @return
+    */
protected List<EMConversation> loadConversationList(){
    // 获取所有会话,包括陌生人
    Map<String, EMConversation> conversations = EMClient.getInstance().chatManager().getAllConversations();
    // 过滤掉messages size为0的conversation
    /**
     * 如果在排序过程中有新消息收到,lastMsgTime会发生变化
     * 影响排序过程,Collection.sort会产生异常
     * 保证Conversation在Sort过程中最后一条消息的时间不变
     * 避免并发问题
     */
    List<Pair<Long, EMConversation>> sortList = new ArrayList<Pair<Long, EMConversation>>();
    synchronized (conversations) {
        for (EMConversation conversation : conversations.values()) {
            if (conversation.getAllMessages().size() != 0) {
                //if(conversation.getType() != EMConversationType.ChatRoom){
                sortList.add(new Pair<Long, EMConversation>(conversation.getLastMessage().getMsgTime(), conversation));
                //}
            }
        }
    }
    try {
        // Internal is TimSort algorithm, has bug
        sortConversationByLastChatTime(sortList);
    } catch (Exception e) {
        e.printStackTrace();
    }
    List<EMConversation> list = new ArrayList<EMConversation>();
    for (Pair<Long, EMConversation> sortItem : sortList) {
        list.add(sortItem.second);
    }
    return list;
}
 
Example #17
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 #18
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 #19
Source File: MyEaseConversationList.java    From Social with Apache License 2.0 5 votes vote down vote up
/**
 * 获取所有会话
 *
 * @param context
 * @return
+    */
private List<EMConversation> loadConversationsWithRecentChat() {
    // 获取所有会话,包括陌生人
    Map<String, EMConversation> conversations = EMClient.getInstance().chatManager().getAllConversations();
    // 过滤掉messages size为0的conversation
    /**
     * 如果在排序过程中有新消息收到,lastMsgTime会发生变化
     * 影响排序过程,Collection.sort会产生异常
     * 保证Conversation在Sort过程中最后一条消息的时间不变
     * 避免并发问题
     */
    List<Pair<Long, EMConversation>> sortList = new ArrayList<Pair<Long, EMConversation>>();
    synchronized (conversations) {
        for (EMConversation conversation : conversations.values()) {
            if (conversation.getAllMessages().size() != 0) {
                sortList.add(new Pair<Long, EMConversation>(conversation.getLastMessage().getMsgTime(), conversation));
            }
        }
    }
    try {
        // Internal is TimSort algorithm, has bug
        sortConversationByLastChatTime(sortList);
    } catch (Exception e) {
        e.printStackTrace();
    }
    List<EMConversation> list = new ArrayList<EMConversation>();
    for (Pair<Long, EMConversation> sortItem : sortList) {
        list.add(sortItem.second);
    }
    return list;
}
 
Example #20
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 #21
Source File: ChatListActivity.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
protected List<EMConversation> loadConversationList(){
    // 获取所有会话,包括陌生人
    Map<String, EMConversation> conversations = EMClient.getInstance().chatManager().getAllConversations();
    // 过滤掉messages size为0的conversation
    /**
     * 如果在排序过程中有新消息收到,lastMsgTime会发生变化
     * 影响排序过程,Collection.sort会产生异常
     * 保证Conversation在Sort过程中最后一条消息的时间不变
     * 避免并发问题
     */
    List<Pair<Long, EMConversation>> sortList = new ArrayList<Pair<Long, EMConversation>>();
    synchronized (conversations) {
        for (EMConversation conversation : conversations.values()) {
            if (conversation.getAllMessages().size() != 0) {
                //if(conversation.getType() != EMConversationType.ChatRoom){
                sortList.add(new Pair<Long, EMConversation>(conversation.getLastMessage().getMsgTime(), conversation));
                //}
            }
        }
    }
    try {
        // Internal is TimSort algorithm, has bug
        sortConversationByLastChatTime(sortList);
    } catch (Exception e) {
        e.printStackTrace();
    }
    List<EMConversation> list = new ArrayList<EMConversation>();
    for (Pair<Long, EMConversation> sortItem : sortList) {
        list.add(sortItem.second);
    }
    return list;
}
 
Example #22
Source File: MainActivity.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取未读消息数
 *
 * @return
 */
public int getUnreadMsgCountTotal() {
    int unreadMsgCountTotal = 0;
    int chatroomUnreadMsgCount = 0;
    unreadMsgCountTotal = EMClient.getInstance().chatManager().getUnreadMsgsCount();
    for (EMConversation conversation : EMClient.getInstance().chatManager().getAllConversations().values()) {
        if (conversation.getType() == EMConversation.EMConversationType.ChatRoom)
            chatroomUnreadMsgCount = chatroomUnreadMsgCount + conversation.getUnreadMsgCount();
    }
    return unreadMsgCountTotal - chatroomUnreadMsgCount;
}
 
Example #23
Source File: MyEaseConversationAdapter.java    From Social with Apache License 2.0 5 votes vote down vote up
public MyEaseConversationAdapter(Context context, int resource,
                                List<EMConversation> objects) {
    super(context, resource, objects);
    conversationList = objects;
    copyConversationList = new ArrayList<EMConversation>();
    copyConversationList.addAll(objects);
}
 
Example #24
Source File: ChatListFragment.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
protected List<EMConversation> loadConversationList(){
    // 获取所有会话,包括陌生人
    Map<String, EMConversation> conversations = EMClient.getInstance().chatManager().getAllConversations();
    // 过滤掉messages size为0的conversation
    /**
     * 如果在排序过程中有新消息收到,lastMsgTime会发生变化
     * 影响排序过程,Collection.sort会产生异常
     * 保证Conversation在Sort过程中最后一条消息的时间不变
     * 避免并发问题
     */
    List<Pair<Long, EMConversation>> sortList = new ArrayList<Pair<Long, EMConversation>>();
    synchronized (conversations) {
        for (EMConversation conversation : conversations.values()) {
            if (conversation.getAllMessages().size() != 0) {
                //if(conversation.getType() != EMConversationType.ChatRoom){
                sortList.add(new Pair<Long, EMConversation>(conversation.getLastMessage().getMsgTime(), conversation));
                //}
            }
        }
    }
    try {
        // Internal is TimSort algorithm, has bug
        sortConversationByLastChatTime(sortList);
    } catch (Exception e) {
        e.printStackTrace();
    }
    List<EMConversation> list = new ArrayList<EMConversation>();
    for (Pair<Long, EMConversation> sortItem : sortList) {
        list.add(sortItem.second);
    }
    return list;
}
 
Example #25
Source File: EaseConversationAdapater.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
    conversationList.clear();
    conversationList.addAll((List<EMConversation>) results.values);
    if (results.count > 0) {
        notiyfyByFilter = true;
        notifyDataSetChanged();
    } else {
        notifyDataSetInvalidated();
    }

}
 
Example #26
Source File: EaseConversationAdapater.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public EMConversation getItem(int arg0) {
    if (arg0 < conversationList.size()) {
        return conversationList.get(arg0);
    }
    return null;
}
 
Example #27
Source File: EaseConversationAdapater.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
public EaseConversationAdapater(Context context, int resource,
        List<EMConversation> objects) {
    super(context, resource, objects);
    conversationList = objects;
    copyConversationList = new ArrayList<EMConversation>();
    copyConversationList.addAll(objects);
}
 
Example #28
Source File: MyEaseConversationAdapter.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
public EMConversation getItem(int arg0) {
    if (arg0 < conversationList.size()) {
        return conversationList.get(arg0);
    }
    return null;
}
 
Example #29
Source File: EaseConversationList.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取所有会话
 * 
 * @param context
 * @return
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    +    */
private List<EMConversation> loadConversationsWithRecentChat() {
    // 获取所有会话,包括陌生人
    Map<String, EMConversation> conversations = EMClient.getInstance().chatManager().getAllConversations();
    // 过滤掉messages size为0的conversation
    /**
     * 如果在排序过程中有新消息收到,lastMsgTime会发生变化
     * 影响排序过程,Collection.sort会产生异常
     * 保证Conversation在Sort过程中最后一条消息的时间不变 
     * 避免并发问题
     */
    List<Pair<Long, EMConversation>> sortList = new ArrayList<Pair<Long, EMConversation>>();
    synchronized (conversations) {
        for (EMConversation conversation : conversations.values()) {
            if (conversation.getAllMessages().size() != 0) {
                sortList.add(new Pair<Long, EMConversation>(conversation.getLastMessage().getMsgTime(), conversation));
            }
        }
    }
    try {
        // Internal is TimSort algorithm, has bug
        sortConversationByLastChatTime(sortList);
    } catch (Exception e) {
        e.printStackTrace();
    }
    List<EMConversation> list = new ArrayList<EMConversation>();
    for (Pair<Long, EMConversation> sortItem : sortList) {
        list.add(sortItem.second);
    }
    return list;
}
 
Example #30
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;
}