leancloud / LeanCloudChatKit-Android

95 stars 33 forks source link

IMKit 接口设计 #2

Closed daweibayu closed 8 years ago

daweibayu commented 8 years ago

具体上下文可参照 https://github.com/leancloud/paas/issues/816 、#1 ,以下为具体设计

ChatManager (以下函数依次调用即可 )

1.获取单例

getInstance()

2.初始化

// 包含初始化 sdk,注册各种 handler,设置离线消息等
init(Context, appId,appKey)

3.设置用户体系

setProfileProvider(ProfileProvider) 

4.设置签名

setSignatureFactory(SignatureFactory)

5.开启聊天

// open 成功后,可以执行自己逻辑,或者跳转到聊天页面,具体跳转到聊天页面的逻辑可参见 ChatActivity
open(String clientId,Callback)

6.关闭聊天

close(Callback)

ProfileProvider 相关

用户需要自己实现接口

public interface ProfileProvider {
    // 获取指定 id list 的用户信息
    public void getProfiles(List<String> list, FetchUserCallBack callBack);
}

CallBack

public interface FetchUserCallBack {
    public void done(List<UserProfile> userList, Exception e);
}

UserProfile 的相关属性

public class UserProfile {
    String userId;
    String avatarUrl;
    String name;
}

UI 相关

1.ConversationFragment 作用:展示所有 conversation list 的 fragment(需要 open 后才会执行相关逻辑 ) 参数:无 函数:updateFragment() 主动刷新 Fragment

2.ChatActivity 作用:聊天页面,只要发起 StartActivity,并且 Intent 中包含以下参数即可 参数:Constants.MEMBER_ID、Constants.CONVERSATION_ID(二选一即可) Action:Constants.AVATAR_CLICK_EVENT(头像点击事件)

其他

jwfing commented 8 years ago

ChatManager 中是否需要增加一个 getCurrentUserId 的方法?我想你在 ChatActivity 里面为了展示消息列表,肯定是需要拿到 currentUserId 的,不知道在现有接口下会如何获取?

daweibayu commented 8 years ago

open 的时候会传入 currentUserId,根据这个 id 以及 getProfiles() 可以获取当单签用户的信息。

jwfing commented 8 years ago

你可以把工程框架和这部分接口的代码发个 PR 上来了。有关处理细节在 PR 上去讨论。

daweibayu commented 8 years ago

3 pr 已经提了。