use of com.avos.avoscloud.im.v2.AVIMException 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;
}
});
}
}
}
});
}
use of com.avos.avoscloud.im.v2.AVIMException in project ride-read-android by Ride-Read.
the class ChatActivity method sendTextMessage.
private void sendTextMessage(String text) {
final AVIMTextMessage message = new AVIMTextMessage();
message.setText(text);
datas.add(new ChatMessage(1, R.mipmap.me, null, text, null));
adapter.notifyDataSetChanged();
chatlist.smoothScrollToPosition(adapter.getCount() - 1);
editor.setText("");
imConversation.sendMessage(message, new AVIMConversationCallback() {
@Override
public void done(AVIMException e) {
if (filterException(e)) {
Log.e("信息发送", "信息发送成功");
} else {
Log.e("信息发送", "信息发送失败");
}
}
});
}
use of com.avos.avoscloud.im.v2.AVIMException in project ride-read-android by Ride-Read.
the class ChatSingleActivity method initView.
@Override
public void initView() {
mUser = (UserBaseInfo) getIntent().getSerializableExtra(CHAT_USER);
mUserName = getIntent().getStringExtra(CHAT_USER_NAME);
if (TextUtils.isEmpty(mUserName))
mUserName = "消息";
new TitleBuilder(this).setTitleText(mUserName).IsBack(true).setLeftOnClickListener(v -> finish()).build();
mSwipeRefreshLayout.setEnabled(false);
layoutManager = new LinearLayoutManager(this);
mRecycleView.setLayoutManager(layoutManager);
mMsgAdapter = new ChatMsgAdapter();
mRecycleView.setAdapter(mMsgAdapter);
getConversation(mUser.getUid() + "");
mSwipeRefreshLayout.setOnRefreshListener(() -> {
AVIMMessage message = mMsgAdapter.getFirstMessage();
if (null != mImConversation) {
mImConversation.queryMessages(message.getMessageId(), message.getTimestamp(), 20, new AVIMMessagesQueryCallback() {
@Override
public void done(List<AVIMMessage> list, AVIMException e) {
mSwipeRefreshLayout.setRefreshing(false);
if (filterException(e)) {
if (null != list && list.size() > 0) {
mMsgAdapter.addMessageList(list);
mMsgAdapter.notifyDataSetChanged();
layoutManager.scrollToPositionWithOffset(list.size() - 1, 0);
}
}
}
});
} else {
mSwipeRefreshLayout.setRefreshing(false);
}
});
}
use of com.avos.avoscloud.im.v2.AVIMException in project ride-read-android by Ride-Read.
the class ChatSingleActivity method sendMsg.
private void sendMsg() {
String msg = mEdtChatInput.getText().toString();
AVIMTextMessage message = new AVIMTextMessage();
if (!TextUtils.isEmpty(msg)) {
message.setText(msg);
mMsgAdapter.addMessage(message);
mMsgAdapter.notifyDataSetChanged();
scrollToBottom();
mEdtChatInput.setText("");
mImConversation.sendMessage(message, new AVIMConversationCallback() {
@Override
public void done(AVIMException e) {
mMsgAdapter.notifyDataSetChanged();
MsgUtils.addMsgInfo(mUser, msg, System.currentTimeMillis());
}
});
}
}
use of com.avos.avoscloud.im.v2.AVIMException 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);
}
});
}
}
}
});
}
Aggregations