Java Code Examples for cn.jpush.im.android.api.JMessageClient#getSingleConversation()

The following examples show how to use cn.jpush.im.android.api.JMessageClient#getSingleConversation() . 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: JMessageUtils.java    From jmessage-flutter-plugin with MIT License 6 votes vote down vote up
static Conversation getConversation(JSONObject params) throws JSONException {
    String type = params.getString("type");
    Conversation conversation = null;

    if (type.equals("single")) {
        String username = params.getString("username");
        String appKey = params.has("appKey") ? params.getString("appKey") : "";
        conversation = JMessageClient.getSingleConversation(username, appKey);

    } else if (type.equals("group")) {
        String groupId = params.getString("groupId");
        conversation = JMessageClient.getGroupConversation(Long.parseLong(groupId));

    } else if (type.equals("chatRoom")) {
        long roomId = Long.parseLong(params.getString("roomId"));
        conversation = JMessageClient.getChatRoomConversation(roomId);
    }

    return conversation;
}
 
Example 2
Source File: MsgListAdapter.java    From jmessage-android-uikit with MIT License 6 votes vote down vote up
public void setSendImg(int[] msgIds) {
    Message msg;
    if (mIsGroup) {
        mConv = JMessageClient.getGroupConversation(mGroupId);
    } else {
        mConv = JMessageClient.getSingleConversation(mTargetId, mTargetAppKey);
        Log.d(TAG, "mTargetAppKey: " + mTargetAppKey);
    }
    for (int msgId : msgIds) {
        msg = mConv.getMessage(msgId);
        if (msg != null) {
            mMsgList.add(msg);
            incrementStartPosition();
            mMsgQueue.offer(msg);
        }
    }

    if (mMsgQueue.size() > 0) {
        Message message = mMsgQueue.element();
        sendNextImgMsg(message);
        notifyDataSetChanged();
    }
}
 
Example 3
Source File: JsonUtils.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
static Message JsonToMessage(JSONObject json) {
    Conversation conversation = null;
    int msgId = 0;

    try {
        msgId = Integer.parseInt(json.getString("id"));
        boolean isSend = json.getBoolean("isSend");

        JSONObject target = json.getJSONObject("target");

        if (target.getString("type").equals("user")) {
            String username;
            String appKey;

            if (isSend) { // 消息由当前用户发送,则聊天对象为消息接收方。
                username = target.getString("username");
                appKey = target.has("appKey") ? target.getString("appKey") : null;

            } else { // 当前用户为消息接收方,则聊天对象为消息发送方。
                JSONObject opposite = json.getJSONObject("from");
                username = opposite.getString("username");
                appKey = opposite.has("appKey") ? opposite.getString("appKey") : null;
            }

            conversation = JMessageClient.getSingleConversation(username, appKey);

        } else if (target.getString("type").equals("group")) {
            long groupId = Long.parseLong(target.getString("id"));
            conversation = JMessageClient.getGroupConversation(groupId);

        } else if (target.getString("type").equals("chatRoom")) {
            long roomId = Long.parseLong(target.getString("roomId"));
            conversation = JMessageClient.getChatRoomConversation(roomId);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return conversation != null ? conversation.getMessage(msgId) : null;
}
 
Example 4
Source File: NotificationClickEventReceiver.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
     * 收到消息处理
     * @param notificationClickEvent 通知点击事件
     */
    public void onEvent(NotificationClickEvent notificationClickEvent) {
        if (null == notificationClickEvent) {
            return;
        }
        Message msg = notificationClickEvent.getMessage();
        if (msg != null) {
            String targetId = msg.getTargetID();
            String appKey = msg.getFromAppKey();
            ConversationType type = msg.getTargetType();
            Conversation conv;
            Intent notificationIntent = new Intent(mContext, ChatActivity.class);
            if (type == ConversationType.single) {
                conv = JMessageClient.getSingleConversation(targetId, appKey);
                notificationIntent.putExtra(JGApplication.TARGET_ID, targetId);
                notificationIntent.putExtra(JGApplication.TARGET_APP_KEY, appKey);
            } else {
                conv = JMessageClient.getGroupConversation(Long.parseLong(targetId));
                notificationIntent.putExtra(JGApplication.GROUP_ID, Long.parseLong(targetId));
            }
            notificationIntent.putExtra(JGApplication.CONV_TITLE, conv.getTitle());
            conv.resetUnreadCount();
//        notificationIntent.setAction(Intent.ACTION_MAIN);
            notificationIntent.putExtra("fromGroup", false);
            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            mContext.startActivity(notificationIntent);
        }
    }
 
Example 5
Source File: ChatDetailController.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public void delConvAndReturnMainActivity() {
    Conversation conversation = JMessageClient.getSingleConversation(mUserInfo.getUserName(), mUserInfo.getAppKey());
    EventBus.getDefault().post(new Event.Builder().setType(EventType.deleteConversation)
            .setConversation(conversation)
            .build());
    JMessageClient.deleteSingleConversation(mUserInfo.getUserName(), mUserInfo.getAppKey());
    mContext.startMainActivity();
}
 
Example 6
Source File: ChatDetailController.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public String getName() {
    if (mIsGroup) {
        if (TextUtils.isEmpty(mGroupName)) {
            Conversation groupConversation = JMessageClient.getGroupConversation(mGroupId);
            mGroupName = groupConversation.getTitle();
        }
        return mGroupName;
    } else {
        Conversation conv = JMessageClient.getSingleConversation(mTargetId, mTargetAppKey);
        return conv.getTitle();
    }
}
 
Example 7
Source File: SendFileController.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public SendFileController(SendFileActivity context, SendFileView view) {
    this.mContext = context;
    this.mSFView = view;
    List<Fragment> fragments = new ArrayList<Fragment>();
    // init Fragment
    mDocumentFragment = new DocumentFragment();
    mVideoFragment = new VideoFragment();
    mImgFragment = new ImageFragment();
    mAudioFragment = new AudioFragment();
    mOtherFragment = new OtherFragment();
    fragments.add(mDocumentFragment);
    fragments.add(mVideoFragment);
    fragments.add(mImgFragment);
    fragments.add(mAudioFragment);
    fragments.add(mOtherFragment);
    ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(mContext.getSupportFragmentManger(),
            fragments);
    mSFView.setViewPagerAdapter(viewPagerAdapter);
    mDocumentFragment.setController(this);
    mVideoFragment.setController(this);
    mImgFragment.setController(this);
    mAudioFragment.setController(this);
    mOtherFragment.setController(this);

    String targetId = mContext.getIntent().getStringExtra(JGApplication.TARGET_ID);
    String targetAppKey = mContext.getIntent().getStringExtra(JGApplication.TARGET_APP_KEY);
    long groupId = mContext.getIntent().getLongExtra(JGApplication.GROUP_ID, 0);
    if (groupId != 0) {
        mConv = JMessageClient.getGroupConversation(groupId);
    } else {
        mConv = JMessageClient.getSingleConversation(targetId, targetAppKey);
    }
}
 
Example 8
Source File: MapPickerActivity.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.picker_activity_map_picker);
    if (locationService == null) {
        locationService = new LocationService(getApplicationContext());
    }
    locationService.registerListener(mListener);//是否应该在onStart中注册

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    mDensity = dm.density;
    mDensityDpi = dm.densityDpi;
    mWidth = dm.widthPixels;
    mHeight = dm.heightPixels;

    mPopupView = LayoutInflater.from(this).inflate(R.layout.location_popup_layout, null);

    linearLayout = (LinearLayout) findViewById(R.id.listNearbyHolder);
    relativeLayout = (RelativeLayout) findViewById(R.id.mapholder);
    defineMyLocationButton = findViewById(R.id.define_my_location);

    initMap();
    initIntent();

    String targetId = getIntent().getStringExtra(JGApplication.TARGET_ID);
    String targetAppKey = getIntent().getStringExtra(JGApplication.TARGET_APP_KEY);
    long groupId = getIntent().getLongExtra(JGApplication.GROUP_ID, 0);

    if (groupId != 0) {
        conv = JMessageClient.getGroupConversation(groupId);
    } else {
        conv = JMessageClient.getSingleConversation(targetId, targetAppKey);
    }


}
 
Example 9
Source File: SearchMoreFriendsActivity.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Object selectObject = parent.getItemAtPosition(position);
    if (selectObject instanceof UserInfo) {
        UserInfo friend = (UserInfo) selectObject;
        final Intent intent = new Intent(SearchMoreFriendsActivity.this, ChatActivity.class);
        String notename = friend.getDisplayName();
        Conversation conv = JMessageClient.getSingleConversation(friend.getUserName(), friend.getAppKey());
        //如果会话为空,使用EventBus通知会话列表添加新会话
        if (conv == null) {
            conv = Conversation.createSingleConversation(friend.getUserName(), friend.getAppKey());
            EventBus.getDefault().post(new Event.Builder()
                    .setType(EventType.createConversation)
                    .setConversation(conv)
                    .build());
        }
        //转发消息
        if (isForwardMsg) {
            DialogCreator.createForwardMsg(SearchMoreFriendsActivity.this, mWidth, true, null, null, notename, friend);
            //进入聊天界面
        } else if (isBusinessCard) {
            setSearchContactsBusiness(getIntent(), null, friend);
        } else {
            intent.putExtra(JGApplication.TARGET_ID, friend.getUserName());
            intent.putExtra(JGApplication.TARGET_APP_KEY, friend.getAppKey());
            intent.putExtra(JGApplication.CONV_TITLE, notename);
            startActivity(intent);
        }
    }
}
 
Example 10
Source File: FriendSettingActivity.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public void delConvAndReturnMainActivity() {
    Conversation conversation = JMessageClient.getSingleConversation(mFriendInfo.getUserName(), mFriendInfo.getAppKey());
    EventBus.getDefault().post(new Event.Builder().setType(EventType.deleteConversation)
            .setConversation(conversation)
            .build());
    JMessageClient.deleteSingleConversation(mFriendInfo.getUserName(), mFriendInfo.getAppKey());
    Intent intent = new Intent(this, MainActivity.class);
    startActivity(intent);
    finish();
}
 
Example 11
Source File: UserInfoActivity.java    From Android-IM with Apache License 2.0 5 votes vote down vote up
@OnClick({R.id.title_bar_back, R.id.title_options_tv, R.id.bottom_bar_tv1, R.id.bottom_bar_tv2})
public void onViewClicked(View view) {
    switch (view.getId()) {
        case R.id.title_bar_back:
            finish();
            break;
        case R.id.title_options_tv:
            Intent intent1 = new Intent(UserInfoActivity.this, UserInfoOptionsActivity.class);
            intent1.putExtra("USERNAME", getIntent().getStringExtra("USERNAME"));
            startActivity(intent1);
            break;
        case R.id.bottom_bar_tv2:
            /*创建会话*/
            Conversation conv = JMessageClient.getSingleConversation(getIntent().getStringExtra("USERNAME"), SharedPrefHelper.getInstance().getAppKey());
            //如果会话为空,使用EventBus通知会话列表添加新会话
            if (conv == null) {
                Conversation.createSingleConversation(getIntent().getStringExtra("USERNAME"), SharedPrefHelper.getInstance().getAppKey());
            }
            Intent intent = new Intent(UserInfoActivity.this, ChatMsgActivity.class);
            intent.putExtra("USERNAME", getIntent().getStringExtra("USERNAME"));
            startActivity(intent);


            break;
        default:
            break;
    }
}
 
Example 12
Source File: MsgListAdapter.java    From jmessage-android-uikit with MIT License 5 votes vote down vote up
public MsgListAdapter(Context context, String targetId, String appKey,
                      ContentLongClickListener longClickListener) {
    initData(context);
    this.mTargetId = targetId;
    if (appKey != null) {
        mTargetAppKey = appKey;
        this.mConv = JMessageClient.getSingleConversation(mTargetId, appKey);
    } else {
        this.mConv = JMessageClient.getSingleConversation(mTargetId);
    }
    this.mLongClickListener = longClickListener;
    this.mMsgList = mConv.getMessagesFromNewest(0, mOffset);
    reverse(mMsgList);
    mStart = mOffset;
    UserInfo userInfo = (UserInfo) mConv.getTargetInfo();
    if (!TextUtils.isEmpty(userInfo.getAvatar())) {
        userInfo.getAvatarBitmap(new GetAvatarBitmapCallback() {
            @Override
            public void gotResult(int status, String desc, Bitmap bitmap) {
                if (status == 0) {
                    notifyDataSetChanged();
                } else {
                    HandleResponseCode.onHandle(mContext, status, false);
                }
            }
        });
    }
    checkSendingImgMsg();
}
 
Example 13
Source File: SearchMoreFriendsActivity.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setSearchContactsBusiness(final Intent intent, final GroupInfo groupInfo, final UserInfo userInfo) {
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_cancel:
                    mDialog.dismiss();
                    break;
                case R.id.btn_sure:
                    mDialog.dismiss();
                    //把名片的userName和appKey通过extra发送给对方
                    TextContent content = new TextContent("推荐了一张名片");
                    content.setStringExtra("userName", intent.getStringExtra("userName"));
                    content.setStringExtra("appKey", intent.getStringExtra("appKey"));
                    content.setStringExtra("businessCard", "businessCard");
                    Conversation conversation;
                    if (userInfo == null) {
                        conversation = JMessageClient.getGroupConversation(groupInfo.getGroupID());
                        if (conversation == null) {
                            conversation = Conversation.createGroupConversation(groupInfo.getGroupID());
                            EventBus.getDefault().post(new Event.Builder()
                                    .setType(EventType.createConversation)
                                    .setConversation(conversation)
                                    .build());
                        }
                    } else {
                        conversation = JMessageClient.getSingleConversation(userInfo.getUserName(), userInfo.getAppKey());
                        if (conversation == null) {
                            conversation = Conversation.createSingleConversation(userInfo.getUserName(), userInfo.getAppKey());
                            EventBus.getDefault().post(new Event.Builder()
                                    .setType(EventType.createConversation)
                                    .setConversation(conversation)
                                    .build());
                        }
                    }

                    Message textMessage = conversation.createSendMessage(content);
                    MessageSendingOptions options = new MessageSendingOptions();
                    options.setNeedReadReceipt(false);
                    JMessageClient.sendMessage(textMessage, options);
                    textMessage.setOnSendCompleteCallback(new BasicCallback() {
                        @Override
                        public void gotResult(int i, String s) {
                            if (i == 0) {
                                Toast.makeText(SearchMoreFriendsActivity.this, "发送成功", Toast.LENGTH_SHORT).show();
                            } else {
                                HandleResponseCode.onHandle(SearchMoreFriendsActivity.this, i, false);
                            }
                        }
                    });
                    break;
            }
        }
    };
    String name;
    if (userInfo == null) {
        name = groupInfo.getGroupName();
    } else {
        name = userInfo.getDisplayName();
    }
    mDialog = DialogCreator.createBusinessCardDialog(SearchMoreFriendsActivity.this, listener, name,
            intent.getStringExtra("userName"), intent.getStringExtra("avatar"));
    mDialog.getWindow().setLayout((int) (0.8 * mWidth), WindowManager.LayoutParams.WRAP_CONTENT);
    mDialog.show();
}
 
Example 14
Source File: SearchMoreGroupActivity.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setSearchContactsBusiness(final Intent intent, final GroupInfo groupInfo, final UserInfo userInfo) {
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_cancel:
                    mDialog.dismiss();
                    break;
                case R.id.btn_sure:
                    mDialog.dismiss();
                    //把名片的userName和appKey通过extra发送给对方
                    TextContent content = new TextContent("推荐了一张名片");
                    content.setStringExtra("userName", intent.getStringExtra("userName"));
                    content.setStringExtra("appKey", intent.getStringExtra("appKey"));
                    content.setStringExtra("businessCard", "businessCard");
                    Conversation conversation;
                    if (userInfo == null) {
                        conversation = JMessageClient.getGroupConversation(groupInfo.getGroupID());
                        if (conversation == null) {
                            conversation = Conversation.createGroupConversation(groupInfo.getGroupID());
                            EventBus.getDefault().post(new Event.Builder()
                                    .setType(EventType.createConversation)
                                    .setConversation(conversation)
                                    .build());
                        }
                    } else {
                        conversation = JMessageClient.getSingleConversation(userInfo.getUserName(), userInfo.getAppKey());
                        if (conversation == null) {
                            conversation = Conversation.createSingleConversation(userInfo.getUserName(), userInfo.getAppKey());
                            EventBus.getDefault().post(new Event.Builder()
                                    .setType(EventType.createConversation)
                                    .setConversation(conversation)
                                    .build());
                        }
                    }

                    Message textMessage = conversation.createSendMessage(content);
                    MessageSendingOptions options = new MessageSendingOptions();
                    options.setNeedReadReceipt(false);
                    JMessageClient.sendMessage(textMessage, options);
                    textMessage.setOnSendCompleteCallback(new BasicCallback() {
                        @Override
                        public void gotResult(int i, String s) {
                            if (i == 0) {
                                Toast.makeText(SearchMoreGroupActivity.this, "发送成功", Toast.LENGTH_SHORT).show();
                            } else {
                                HandleResponseCode.onHandle(SearchMoreGroupActivity.this, i, false);
                            }
                        }
                    });
                    break;
            }
        }
    };
    String name;
    if (userInfo == null) {
        name = groupInfo.getGroupName();
    } else {
        name = userInfo.getDisplayName();
    }
    mDialog = DialogCreator.createBusinessCardDialog(SearchMoreGroupActivity.this, listener, name,
            intent.getStringExtra("userName"), intent.getStringExtra("avatar"));
    mDialog.getWindow().setLayout((int) (0.8 * mWidth), WindowManager.LayoutParams.WRAP_CONTENT);
    mDialog.show();
}
 
Example 15
Source File: FriendInfoActivity.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_friend_info);
    mFriendInfoView = (FriendInfoView) findViewById(R.id.friend_info_view);
    mTargetId = getIntent().getStringExtra(JGApplication.TARGET_ID);
    mTargetAppKey = getIntent().getStringExtra(JGApplication.TARGET_APP_KEY);
    mUserID = getIntent().getStringExtra("targetId");
    if (mTargetAppKey == null) {
        mTargetAppKey = JMessageClient.getMyInfo().getAppKey();
    }
    mFriendInfoView.initModel(this);
    mFriendInfoController = new FriendInfoController(mFriendInfoView, this);
    mFriendInfoView.setListeners(mFriendInfoController);
    mFriendInfoView.setOnChangeListener(mFriendInfoController);
    mIsFromContact = getIntent().getBooleanExtra("fromContact", false);
    mIsFromSearch = getIntent().getBooleanExtra("fromSearch", false);
    mIsAddFriend = getIntent().getBooleanExtra("addFriend", false);
    mFromGroup = getIntent().getBooleanExtra("group_grid", false);

    //从通讯录中点击过来
    if (mIsFromContact || mIsFromSearch || mFromGroup || mIsAddFriend) {
        updateUserInfo();
    } else {
        mGroupId = getIntent().getLongExtra(JGApplication.GROUP_ID, 0);
        Conversation conv;
        if (mGroupId == 0) {
            conv = JMessageClient.getSingleConversation(mTargetId, mTargetAppKey);
            mUserInfo = (UserInfo) conv.getTargetInfo();
        } else {
            conv = JMessageClient.getGroupConversation(mGroupId);
            GroupInfo groupInfo = (GroupInfo) conv.getTargetInfo();
            mUserInfo = groupInfo.getGroupMemberInfo(mTargetId, mTargetAppKey);
        }

        //先从Conversation里获得UserInfo展示出来
        mFriendInfoView.initInfo(mUserInfo);
        updateUserInfo();
    }

}
 
Example 16
Source File: GroupNotFriendActivity.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void onClick(View v) {
    Intent intent = new Intent();
    switch (v.getId()) {
        case R.id.btn_add_friend:
            if (mUserInfo.isFriend()) {
                ToastUtil.shortToast(GroupNotFriendActivity.this, "对方已经是你的好友");
            } else {
                intent.setClass(GroupNotFriendActivity.this, VerificationActivity.class);
                //对方信息
                intent.putExtra("detail_add_friend", mUserName);
                intent.putExtra("detail_add_nick_name", mNickName);
                intent.putExtra("detail_add_avatar_path", mAvatarPath);
                //自己的昵称或者是用户名
                intent.putExtra("detail_add_friend_my_nickname", mMyName);
                intent.setFlags(1);
                startActivity(intent);
            }
            break;
        case R.id.btn_send_message:
            intent.setClass(GroupNotFriendActivity.this, ChatActivity.class);
            //创建会话
            intent.putExtra(JGApplication.TARGET_ID, mUserInfo.getUserName());
            intent.putExtra(JGApplication.TARGET_APP_KEY, mUserInfo.getAppKey());
            String notename = mUserInfo.getNotename();
            if (TextUtils.isEmpty(notename)) {
                notename = mUserInfo.getNickname();
                if (TextUtils.isEmpty(notename)) {
                    notename = mUserInfo.getUserName();
                }
            }
            intent.putExtra(JGApplication.CONV_TITLE, notename);
            Conversation conv = JMessageClient.getSingleConversation(mUserInfo.getUserName(), mUserInfo.getAppKey());
            //如果会话为空,使用EventBus通知会话列表添加新会话
            if (conv == null) {
                conv = Conversation.createSingleConversation(mUserInfo.getUserName(), mUserInfo.getAppKey());
                EventBus.getDefault().post(new Event.Builder()
                        .setType(EventType.createConversation)
                        .setConversation(conv)
                        .build());
            }
            startActivity(intent);
            break;
        case R.id.return_btn:
            finish();
            break;
        case R.id.iv_more:
            intent.setClass(GroupNotFriendActivity.this, NotFriendSettingActivity.class);
            intent.putExtra("notFriendUserName", mUserName);
            startActivity(intent);
            break;
        default:
            break;
    }
}