Search in sources :

Example 1 with AVIMConversation

use of com.avos.avoscloud.im.v2.AVIMConversation in project ride-read-android by Ride-Read.

the class ChatActivity method getConservation.

public void getConservation(final String menberId) {
    final AVIMClient client = AVImClientManager.getInstance().getClient();
    AVIMConversationQuery conversationQuery = client.getQuery();
    conversationQuery.withMembers(Arrays.asList(menberId), true);
    conversationQuery.whereEqualTo("customConversationType", 1);
    conversationQuery.findInBackground(new AVIMConversationQueryCallback() {

        @Override
        public void done(List<AVIMConversation> list, AVIMException e) {
            if (filterException(e)) {
                //注意:此处仍有漏洞,如果获取了多个 conversation,默认取第一个
                if (null != list && list.size() > 0) {
                    imConversation = list.get(0);
                } else {
                    HashMap<String, Object> attributes = new HashMap<String, Object>();
                    attributes.put("customConversationType", 1);
                    client.createConversation(Arrays.asList(menberId), null, attributes, false, new AVIMConversationCreatedCallback() {

                        @Override
                        public void done(AVIMConversation avimConversation, AVIMException e) {
                            imConversation = avimConversation;
                        }
                    });
                }
            }
        }
    });
}
Also used : AVIMConversationCreatedCallback(com.avos.avoscloud.im.v2.callback.AVIMConversationCreatedCallback) AVIMConversation(com.avos.avoscloud.im.v2.AVIMConversation) AVIMClient(com.avos.avoscloud.im.v2.AVIMClient) AVIMException(com.avos.avoscloud.im.v2.AVIMException) HashMap(java.util.HashMap) AVIMConversationQueryCallback(com.avos.avoscloud.im.v2.callback.AVIMConversationQueryCallback) AVIMConversationQuery(com.avos.avoscloud.im.v2.AVIMConversationQuery)

Example 2 with AVIMConversation

use of com.avos.avoscloud.im.v2.AVIMConversation in project ride-read-android by Ride-Read.

the class ChatSingleActivity method getConversation.

private void getConversation(final String memberId) {
    final AVIMClient client = AVImClientManager.getInstance().getClient();
    if (null == client)
        return;
    AVIMConversationQuery conversationQuery = client.getQuery();
    conversationQuery.withMembers(Arrays.asList(memberId), true);
    conversationQuery.whereEqualTo("customConversationType", 1);
    conversationQuery.findInBackground(new AVIMConversationQueryCallback() {

        @Override
        public void done(List<AVIMConversation> list, AVIMException e) {
            if (filterException(e)) {
                //注意:此处仍有漏洞,如果获取了多个 conversation,默认取第一个
                if (null != list && list.size() > 0) {
                    setConversation(list.get(0));
                } else {
                    HashMap<String, Object> attributes = new HashMap<String, Object>();
                    attributes.put("customConversationType", 1);
                    client.createConversation(Arrays.asList(memberId), null, attributes, false, new AVIMConversationCreatedCallback() {

                        @Override
                        public void done(AVIMConversation avimConversation, AVIMException e) {
                            setConversation(avimConversation);
                        }
                    });
                }
            }
        }
    });
}
Also used : AVIMConversationCreatedCallback(com.avos.avoscloud.im.v2.callback.AVIMConversationCreatedCallback) AVIMConversation(com.avos.avoscloud.im.v2.AVIMConversation) AVIMClient(com.avos.avoscloud.im.v2.AVIMClient) AVIMException(com.avos.avoscloud.im.v2.AVIMException) HashMap(java.util.HashMap) AVIMConversationQueryCallback(com.avos.avoscloud.im.v2.callback.AVIMConversationQueryCallback) AVIMConversationQuery(com.avos.avoscloud.im.v2.AVIMConversationQuery)

Example 3 with AVIMConversation

use of com.avos.avoscloud.im.v2.AVIMConversation in project ride-read-android by Ride-Read.

the class MessageHandler method sendNotification.

private void sendNotification(AVIMTypedMessage message, AVIMConversation conversation) {
    String notificationContent = message instanceof AVIMTextMessage ? ((AVIMTextMessage) message).getText() : context.getString(R.string.unspport_message_type);
    Intent intent = new Intent(context, NotificationBroadcastReceiver.class);
    intent.putExtra(Constants.CONVERSATION_ID, conversation.getConversationId());
    intent.putExtra(Constants.MEMBER_ID, message.getFrom());
    NotificationUtils.showNotification(context, "", notificationContent, null, intent);
}
Also used : AVIMTextMessage(com.avos.avoscloud.im.v2.messages.AVIMTextMessage) Intent(android.content.Intent)

Example 4 with AVIMConversation

use of com.avos.avoscloud.im.v2.AVIMConversation in project ride-read-android by Ride-Read.

the class MessageHandler method sendNotification.

private void sendNotification(AVIMTypedMessage message, AVIMConversation conversation) {
    String notificationContent = message instanceof AVIMTextMessage ? ((AVIMTextMessage) message).getText() : context.getString(R.string.nonsupport_message_type);
    Intent intent = new Intent(context, NotificationBroadcastReceiver.class);
    intent.putExtra(Constants.CONVERSATION_ID, conversation.getConversationId());
    intent.putExtra(Constants.MEMBER_ID, message.getFrom());
    NotificationUtils.showNotification(context, "", notificationContent, null, intent);
}
Also used : AVIMTextMessage(com.avos.avoscloud.im.v2.messages.AVIMTextMessage) Intent(android.content.Intent)

Aggregations

Intent (android.content.Intent)2 AVIMClient (com.avos.avoscloud.im.v2.AVIMClient)2 AVIMConversation (com.avos.avoscloud.im.v2.AVIMConversation)2 AVIMConversationQuery (com.avos.avoscloud.im.v2.AVIMConversationQuery)2 AVIMException (com.avos.avoscloud.im.v2.AVIMException)2 AVIMConversationCreatedCallback (com.avos.avoscloud.im.v2.callback.AVIMConversationCreatedCallback)2 AVIMConversationQueryCallback (com.avos.avoscloud.im.v2.callback.AVIMConversationQueryCallback)2 AVIMTextMessage (com.avos.avoscloud.im.v2.messages.AVIMTextMessage)2 HashMap (java.util.HashMap)2