public interface YWConversationManager
YWConversationCreater.createConversationIfNotExist(String)
来创建与该聊天对象的会话记录 YWConversation。 之后通过YWMessageChannel
中的工厂方法创建一条消息,以文本消息为例, YWMessageChannel.createTextMessage(String)
创建了一条文本消息。之后通过调用
YWMessageSender.sendMessage(YWMessage, long, IWxCallback)
将消息发送到云旺服务器即可。 addP2PPushListener(IYWP2PPushListener)与
removeP2PPushListener(IYWP2PPushListener)处理[单聊]新消息到达的通知;
addTribePushListener(IYWTribePushListener)与
removeTribePushListener(IYWTribePushListener)处理[群聊]新消息到达的通知
。通过注册推送消息的监听,可以实时获取到其他用户发送过来消息的通知回调
getConversationList()
获取所有的会话列表,用于需要展现会话列表的ui页面使用。 getConversation(String)
获取与某个特定聊天对象的会话,可用于历史聊天会话的功能。 addConversationListener(IYWConversationListener)与
removeConversationListener(IYWConversationListener)
提供了会话列表变更的监听能力。注册会话列表的变更监听,当收到新的聊天对象的消息推送时,可以实时获取到更新通知回调。 该新的聊天对象的会话记录会被加入到
getConversationList()返回的会话记录列表中,如果该列表用于ui页面展现,可直接调用
BaseAdapter#notifyDataSetChanged()来通知ui更新 getAllUnreadCount()提供了获取未读条数的能力,可用于在ui特定的地方展现未读条数给用户。
markAllReaded()可将所有消息置为已读deleteAllConversation()、
deleteConversation(YWConversation)、
setTopConversation(YWConversation)、
removeTopConversation(YWConversation)来完成YWConversation| Modifier and Type | Method and Description |
|---|---|
void |
addConversationListener(IYWConversationListener listener)
增加会话记录变更监听,包含新增、删除,会话中的数据有变更等
|
void |
addP2PPushListener(IYWP2PPushListener listener)
注册单聊新消息通知监听
|
void |
addPushListener(IYWPushListener listener)
注册新消息通知监听
|
void |
addTotalUnreadChangeListener(IYWConversationUnreadChangeListener listener)
添加针对全部会话的总体未读消息数变化的监听器
|
void |
addTribePushListener(IYWTribePushListener listener)
注册群聊新消息通知监听
|
void |
checkHasUnreadAtMsgs(Context context,
YWConversation conversation,
IWxCallback callback)
检查是否有未读的@消息
|
void |
deleteAllConversation()
删除所有的会话记录,并清空消息
该方法必须在UI主线程调用
|
void |
deleteConversation(YWConversation conversation)
删除某一条会话记录,并清空消息
该方法必须在UI主线程调用
|
int |
getAllUnreadCount()
获取所有会记录的未读总数
该方法必须在UI主线程调用
|
void |
getAtMsgList(Context context,
java.util.List<YWConversation> conversations,
int count,
IWxCallback callback)
获取每个会话的@消息列表
|
YWConversation |
getConversation(EServiceContact setting)
与某个聊天对象的会话记录
|
YWConversation |
getConversation(long tribeId)
Deprecated.
|
YWConversation |
getConversation(java.lang.String userId)
Deprecated.
|
YWConversation |
getConversationByConversationId(java.lang.String conversationId)
获取某个会话记录
该方法必须在UI主线程调用
|
YWConversation |
getConversationById(java.lang.String conversationId)
Deprecated.
|
YWConversation |
getConversationByUserId(java.lang.String userId)
获取与某个聊天对象的会话记录
该方法必须在UI主线程调用
|
YWConversation |
getConversationByUserId(java.lang.String userId,
java.lang.String targetAppKey)
获取与某个聊天对象的会话记录
该方法必须在UI主线程调用
|
YWConversationCreater |
getConversationCreater()
获取会话的创建器
|
java.util.List<YWConversation> |
getConversationList()
获取当前登录用户所有的聊天会话,该列表只做只做只读用途,请勿自行往集合中增删东西,请通过云旺提供的api进行增删
该方法必须在UI主线程调用
|
YWConversation |
getCustomConversation(java.lang.String conversationId)
获取自定义会话
|
YWConversation |
getCustomConversationByConversationId(java.lang.String conversationId)
根据会话Id查询自定义会话
|
YWConversation |
getCustomViewConversationByConversationId(java.lang.String conversationId)
根据会话Id查询自定义View的会话
|
void |
getRecentConversations(int count,
boolean needSync,
boolean isManual,
IWxCallback result)
获取最近联系人,该列表只做只读用途,
该方法必须在UI主线程调用
|
YWConversation |
getTribeConversation(long tribeId)
根据群ID,获取群会话
|
void |
markAllReaded()
将所有的消息记录置为已读
该方法必须在UI主线程调用
|
void |
markReaded(YWConversation conversation)
将所有的消息记录置为已读
该方法必须在UI主线程调用
|
void |
removeConversationListener(IYWConversationListener listener)
移除会话记录变更监听
|
void |
removeP2PPushListener(IYWP2PPushListener listener)
注销单聊新消息通知监听
|
void |
removePushListener(IYWPushListener listener)
注销新消息通知监听
|
void |
removeTopConversation(YWConversation conversation)
将当前会话取消置顶
该方法必须在UI主线程调用
|
void |
removeTotalUnreadChangeListener(IYWConversationUnreadChangeListener listener)
删除针对全部会话的总体未读消息数变化的监听器
|
void |
removeTribePushListener(IYWTribePushListener listener)
注销群聊新消息通知监听
|
void |
setTopConversation(YWConversation conversation)
将当前会话置顶
该方法必须在UI主线程调用
|
void |
syncRecentConversations(IWxCallback callback)
[同步最近会话]:从服务器获取最近20个联系人及每人对应会话的最近1条消息]
|
boolean |
updateOrCreateCustomConversation(YWCustomConversationUpdateModel customConversationModel)
仅用于更新或者创建一个自定义会话,如果会话已存在则更新 。conversationId作为会话的标识必须传入.unreadCount 属性如果设置了会累加。
|
boolean |
updateOrCreateCustomViewConversation(YWCustomConversationUpdateModel customConversationModel)
更新或者创建一个自定义View展示的会话,如果会话已存在则更新。
|
boolean updateOrCreateCustomConversation(YWCustomConversationUpdateModel customConversationModel)
customConversationModel - void addPushListener(IYWPushListener listener)
listener - 推送消息监听void removePushListener(IYWPushListener listener)
listener - 推送消息监听void addP2PPushListener(IYWP2PPushListener listener)
listener - 推送消息监听void removeP2PPushListener(IYWP2PPushListener listener)
listener - 推送消息监听void addTribePushListener(IYWTribePushListener listener)
listener - 推送消息监听void removeTribePushListener(IYWTribePushListener listener)
listener - 推送消息监听java.util.List<YWConversation> getConversationList()
void getRecentConversations(int count,
boolean needSync,
boolean isManual,
IWxCallback result)
count - 获取最近联系人个数needSync - true,需要从服务器同步最近联系人,false 只取本地最近联系人isManual - 是否手动触发result - IWxCallback#onSuccess(Object...)返回List useridsvoid deleteConversation(YWConversation conversation)
conversation - 会话记录void deleteAllConversation()
int getAllUnreadCount()
void addConversationListener(IYWConversationListener listener)
listener - 会话记录变更监听void removeConversationListener(IYWConversationListener listener)
listener - 会话记录变更监听@Deprecated YWConversation getConversation(java.lang.String userId)
getConversationByUserId(String)userId - 聊天对象id, 如果是单聊即为对方的userIdYWConversation getConversationByUserId(java.lang.String userId)
userId - 聊天对象id, 如果是单聊即为对方的userIdYWConversation getConversationByUserId(java.lang.String userId, java.lang.String targetAppKey)
userId - 聊天对象id, 如果是单聊即为对方的userIdtargetAppKey - 聊天对象appkey@Deprecated YWConversation getConversation(long tribeId)
tribeId - YWConversation getTribeConversation(long tribeId)
tribeId - @Deprecated YWConversation getConversationById(java.lang.String conversationId)
getConversationByConversationId(String)conversationId - 会话idYWConversation getConversationByConversationId(java.lang.String conversationId)
conversationId - 会话idYWConversation getConversation(EServiceContact setting)
setting - e客服会话设置信息YWConversation getCustomConversation(java.lang.String conversationId)
conversationId - YWConversationCreater getConversationCreater()
void setTopConversation(YWConversation conversation)
conversation - 需要置顶显示的会话void removeTopConversation(YWConversation conversation)
conversation - 需要取消置顶的会话void markAllReaded()
void markReaded(YWConversation conversation)
conversation - void addTotalUnreadChangeListener(IYWConversationUnreadChangeListener listener)
listener - 总体未读消息数变化的监听器void removeTotalUnreadChangeListener(IYWConversationUnreadChangeListener listener)
listener - 总体未读消息数变化的监听器void syncRecentConversations(IWxCallback callback)
callback - onSuccess(Object...obj)中的obj为空,会话最近一条消息直接被更新到Cache和DBvoid checkHasUnreadAtMsgs(Context context,
YWConversation conversation,
IWxCallback callback)
context - conversation - 标识一个会话callback - 执行完成后的回调。因为查询数据库比较耗时,所以放在异步线程完成,通过回调通知UI
返回成功的处理方式如下:
onSuccess(Object... result){
if(result!=null && result.length==1) {
Message message = (Message) result[0];
}
}void getAtMsgList(Context context,
java.util.List<YWConversation> conversations,
int count,
IWxCallback callback)
conversations - 会话实例count - 每个会话要获取的@消息条数callback - 完成操作后的回调。执行成功后,@消息存入DB。
并且会在onSuccess(Object... result)中返回最新的一条未读@消息,格式为onSuccess(YWMessage)boolean updateOrCreateCustomViewConversation(YWCustomConversationUpdateModel customConversationModel)
customConversationModel - YWConversation getCustomConversationByConversationId(java.lang.String conversationId)
conversationId - 会话IdYWConversation getCustomViewConversationByConversationId(java.lang.String conversationId)
conversationId - 会话Id