Skip to content

Commit

Permalink
Merge pull request #44 from easemob/dev
Browse files Browse the repository at this point in the history
fix bugs & update version.
  • Loading branch information
dujiepeng authored Dec 22, 2021
2 parents dd573ac + 31f160f commit 0b4f4f4
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 203 deletions.
45 changes: 18 additions & 27 deletions ChatSDKDemo/Assets/ChatSDK/ChatSDK/ChatManager/ChatManager_iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override bool DeleteConversation(string conversationId, bool deleteMessag
JSONObject obj = new JSONObject();
obj.Add("convId", conversationId);
obj.Add("deleteMessages", deleteMessages);
string ret = ChatManagerNative.ChatManager_GetMethodCall("deleteConversation", obj.ToString());
string ret = ChatAPIIOS.ChatManager_GetMethodCall("deleteConversation", obj.ToString());
JSONNode jn = JSON.Parse(ret);
return jn["ret"].AsBool;
}
Expand All @@ -26,14 +26,14 @@ public override void DownloadAttachment(string messageId, CallBack handle = null
{
JSONObject obj = new JSONObject();
obj.Add("msgId", messageId);
ChatManagerNative.ChatManager_HandleMethodCall("downloadAttachment", obj.ToString(), handle?.callbackId);
ChatAPIIOS.ChatManager_HandleMethodCall("downloadAttachment", obj.ToString(), handle?.callbackId);
}

public override void DownloadThumbnail(string messageId, CallBack handle = null)
{
JSONObject obj = new JSONObject();
obj.Add("msgId", messageId);
ChatManagerNative.ChatManager_HandleMethodCall("downloadThumbnail", obj.ToString(), handle?.callbackId);
ChatAPIIOS.ChatManager_HandleMethodCall("downloadThumbnail", obj.ToString(), handle?.callbackId);
}

public override void FetchHistoryMessagesFromServer(string conversationId, ConversationType type, string startMessageId = null, int count = 20, ValueCallBack<CursorResult<Message>> handle = null)
Expand All @@ -44,7 +44,7 @@ public override void FetchHistoryMessagesFromServer(string conversationId, Conve
obj.Add("startMsgId", startMessageId ?? "");
obj.Add("count", count);
string jsonString = obj.ToString();
ChatManagerNative.ChatManager_HandleMethodCall("fetchHistoryMessages", jsonString, handle?.callbackId);
ChatAPIIOS.ChatManager_HandleMethodCall("fetchHistoryMessages", jsonString, handle?.callbackId);
}

public override Conversation GetConversation(string conversationId, ConversationType type, bool createIfNeed = true)
Expand All @@ -53,7 +53,7 @@ public override Conversation GetConversation(string conversationId, Conversation
obj.Add("convId", conversationId);
obj.Add("convType", TransformTool.ConversationTypeToInt(type));
obj.Add("createIfNeed", createIfNeed);
string jsonString = ChatManagerNative.ChatManager_GetMethodCall("getConversation", obj.ToString());
string jsonString = ChatAPIIOS.ChatManager_GetMethodCall("getConversation", obj.ToString());
if (jsonString == null || jsonString.Length == 0)
{
return null;
Expand All @@ -63,12 +63,12 @@ public override Conversation GetConversation(string conversationId, Conversation

public override void GetConversationsFromServer(ValueCallBack<List<Conversation>> handle = null)
{
ChatManagerNative.ChatManager_HandleMethodCall("getConversationsFromServer", null, handle?.callbackId);
ChatAPIIOS.ChatManager_HandleMethodCall("getConversationsFromServer", null, handle?.callbackId);
}

public override int GetUnreadMessageCount()
{
string jsonString = ChatManagerNative.ChatManager_GetMethodCall("getUnreadMessageCount");
string jsonString = ChatAPIIOS.ChatManager_GetMethodCall("getUnreadMessageCount");
if (jsonString == null || jsonString.Length == 0) {
return 0;
}
Expand All @@ -81,7 +81,7 @@ public override bool ImportMessages(List<Message> messages)
{
JSONObject obj = new JSONObject();
obj.Add("list", TransformTool.JsonObjectFromMessageList(messages));
string jsonString = ChatManagerNative.ChatManager_GetMethodCall("importMessages", obj.ToString());
string jsonString = ChatAPIIOS.ChatManager_GetMethodCall("importMessages", obj.ToString());
if (jsonString == null || jsonString.Length == 0) {
return false;
}
Expand All @@ -91,7 +91,7 @@ public override bool ImportMessages(List<Message> messages)

public override List<Conversation> LoadAllConversations()
{
string jsonString = ChatManagerNative.ChatManager_GetMethodCall("loadAllConversations");
string jsonString = ChatAPIIOS.ChatManager_GetMethodCall("loadAllConversations");
if (jsonString == null || jsonString.Length == 0) {
return null;
}
Expand All @@ -102,7 +102,7 @@ public override Message LoadMessage(string messageId)
{
JSONObject obj = new JSONObject();
obj.Add("msgId", messageId);
string jsonString = ChatManagerNative.ChatManager_GetMethodCall("getMessage", obj.ToString());
string jsonString = ChatAPIIOS.ChatManager_GetMethodCall("getMessage", obj.ToString());
if (jsonString == null || jsonString.Length == 0)
{
return null;
Expand All @@ -113,7 +113,7 @@ public override Message LoadMessage(string messageId)
public override bool MarkAllConversationsAsRead()
{
JSONObject obj = new JSONObject();
string jsonString = ChatManagerNative.ChatManager_GetMethodCall("markAllChatMsgAsRead", obj.ToString());
string jsonString = ChatAPIIOS.ChatManager_GetMethodCall("markAllChatMsgAsRead", obj.ToString());
if (jsonString == null || jsonString.Length == 0)
{
return false;
Expand All @@ -126,14 +126,14 @@ public override void RecallMessage(string messageId, CallBack handle = null)
{
JSONObject obj = new JSONObject();
obj.Add("msgId", messageId);
ChatManagerNative.ChatManager_HandleMethodCall("recallMessage", obj.ToString(), handle?.callbackId);
ChatAPIIOS.ChatManager_HandleMethodCall("recallMessage", obj.ToString(), handle?.callbackId);
}

public override Message ResendMessage(string messageId, CallBack handle = null)
{
JSONObject obj = new JSONObject();
obj.Add("msgId", messageId);
string jsonString = ChatManagerNative.ChatManager_GetMethodCall("resendMessage", obj.ToString(), handle?.callbackId);
string jsonString = ChatAPIIOS.ChatManager_GetMethodCall("resendMessage", obj.ToString(), handle?.callbackId);
if (jsonString == null || jsonString.Length == 0)
{
return null;
Expand All @@ -149,48 +149,39 @@ public override List<Message> SearchMsgFromDB(string keywords, long timestamp =
obj.Add("count", maxCount);
obj.Add("timestamp", timestamp);
obj.Add("direction", direction == MessageSearchDirection.UP ? "up" : "down");
string jsonString = ChatManagerNative.ChatManager_GetMethodCall("searchChatMsgFromDB", obj.ToString());
string jsonString = ChatAPIIOS.ChatManager_GetMethodCall("searchChatMsgFromDB", obj.ToString());
return TransformTool.JsonStringToMessageList(jsonString);
}

public override void SendConversationReadAck(string conversationId, CallBack handle = null)
{
JSONObject obj = new JSONObject();
obj.Add("convId", conversationId);
ChatManagerNative.ChatManager_HandleMethodCall("ackConversationRead", obj.ToString(), handle?.callbackId);
ChatAPIIOS.ChatManager_HandleMethodCall("ackConversationRead", obj.ToString(), handle?.callbackId);
}

public override void SendMessage(ref Message message, CallBack handle = null)
{
CallbackManager.Instance().tempMsgDict.Add(message.LocalTime.ToString(), message);

ChatManagerNative.ChatManager_GetMethodCall("sendMessage", message.ToJson().ToString(), handle?.callbackId);
ChatAPIIOS.ChatManager_GetMethodCall("sendMessage", message.ToJson().ToString(), handle?.callbackId);
}

public override void SendMessageReadAck(string messageId, CallBack handle = null)
{
JSONObject obj = new JSONObject();
obj.Add("msgId", messageId);
ChatManagerNative.ChatManager_GetMethodCall("ackMessageRead", obj.ToString(), handle?.callbackId);
ChatAPIIOS.ChatManager_GetMethodCall("ackMessageRead", obj.ToString(), handle?.callbackId);
}

public override bool UpdateMessage(Message message)
{
string jsonString = ChatManagerNative.ChatManager_GetMethodCall("updateChatMessage", message.ToJson().ToString());
string jsonString = ChatAPIIOS.ChatManager_GetMethodCall("updateChatMessage", message.ToJson().ToString());
if (jsonString == null || jsonString.Length == 0) {
return false;
}
JSONObject jsonObject = JSON.Parse(jsonString).AsObject;
return jsonObject["isLoggedIn"].AsBool;
}
}

class ChatManagerNative
{
[DllImport("__Internal")]
internal extern static void ChatManager_HandleMethodCall(string methodName, string jsonString = null, string callbackId = null);

[DllImport("__Internal")]
internal extern static string ChatManager_GetMethodCall(string methodName, string jsonString = null, string callbackId = null);
}
}
25 changes: 8 additions & 17 deletions ChatSDKDemo/Assets/ChatSDK/ChatSDK/Client/Client_iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ internal sealed class Client_iOS : IClient
{
public override void InitWithOptions(Options options)
{
ClientNative.Client_HandleMethodCall("initWithOptions", options.ToJsonString(), null);
ChatAPIIOS.Client_HandleMethodCall("initWithOptions", options.ToJsonString(), null);
}

public override void CreateAccount(string username, string password, CallBack callBack = null)
{
JSONObject obj = new JSONObject();
obj.Add("username", username);
obj.Add("password", password);
ClientNative.Client_HandleMethodCall("createAccount", obj.ToString(), callBack?.callbackId);
ChatAPIIOS.Client_HandleMethodCall("createAccount", obj.ToString(), callBack?.callbackId);
}

public override void Login(string username, string pwdOrToken, bool isToken = false, CallBack callBack = null)
Expand All @@ -27,25 +27,25 @@ public override void Login(string username, string pwdOrToken, bool isToken = fa
obj.Add("username", username);
obj.Add("pwdOrToken", pwdOrToken);
obj.Add("isToken", isToken);
ClientNative.Client_HandleMethodCall("login", obj.ToString(), callBack?.callbackId);
ChatAPIIOS.Client_HandleMethodCall("login", obj.ToString(), callBack?.callbackId);
}

public override void Logout(bool unbindDeviceToken, CallBack callBack = null)
{
JSONObject obj = new JSONObject();
obj.Add("unbindDeviceToken", unbindDeviceToken);
ClientNative.Client_HandleMethodCall("logout", obj.ToString(), callBack?.callbackId);
ChatAPIIOS.Client_HandleMethodCall("logout", obj.ToString(), callBack?.callbackId);
}

public override string CurrentUsername() {
string jsonString = ClientNative.Client_GetMethodCall("getCurrentUsername");
string jsonString = ChatAPIIOS.Client_GetMethodCall("getCurrentUsername");
JSONObject jo = JSON.Parse(jsonString).AsObject;
return jo["getCurrentUsername"].Value;
}

public override bool IsConnected {
get {
string jsonString = ClientNative.Client_GetMethodCall("isConnected");
string jsonString = ChatAPIIOS.Client_GetMethodCall("isConnected");
JSONObject jsonObject = JSON.Parse(jsonString).AsObject;
return jsonObject["isConnected"].AsBool;
}
Expand All @@ -54,14 +54,14 @@ public override bool IsConnected {
}

public override bool IsLoggedIn() {
string jsonString = ClientNative.Client_GetMethodCall("isLoggedIn");
string jsonString = ChatAPIIOS.Client_GetMethodCall("isLoggedIn");
JSONObject jsonObject = JSON.Parse(jsonString).AsObject;
return jsonObject["isLoggedIn"].AsBool;
}

public override string AccessToken()
{
string jsonString = ClientNative.Client_GetMethodCall("accessToken");
string jsonString = ChatAPIIOS.Client_GetMethodCall("accessToken");
JSONObject jo = JSON.Parse(jsonString).AsObject;
return jo["accessToken"].Value;
}
Expand All @@ -82,15 +82,6 @@ public override void ClearResource()
}

}

class ClientNative
{
[DllImport("__Internal")]
internal extern static void Client_HandleMethodCall(string methodName, string jsonString = null, string callbackId = null);

[DllImport("__Internal")]
internal extern static string Client_GetMethodCall(string methodName, string jsonString = null, string callbackId = null);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,42 @@ public override void AcceptInvitation(string username, CallBack handle = null)
{
JSONObject obj = new JSONObject();
obj.Add("username", username);
ContactManagerNative.ContactManager_HandleMethodCall("acceptInvitation", obj.ToString(), handle?.callbackId);
ChatAPIIOS.ContactManager_HandleMethodCall("acceptInvitation", obj.ToString(), handle?.callbackId);
}

public override void AddContact(string username, string reason = null, CallBack handle = null)
{
JSONObject obj = new JSONObject();
obj.Add("username", username);
obj.Add("reason", reason ?? "");
ContactManagerNative.ContactManager_HandleMethodCall("addContact", obj.ToString(), handle?.callbackId);
ChatAPIIOS.ContactManager_HandleMethodCall("addContact", obj.ToString(), handle?.callbackId);
}

public override void AddUserToBlockList(string username, CallBack handle = null)
{
JSONObject obj = new JSONObject();
obj.Add("username", username);
ContactManagerNative.ContactManager_HandleMethodCall("addUserToBlockList", obj.ToString(), handle?.callbackId);
ChatAPIIOS.ContactManager_HandleMethodCall("addUserToBlockList", obj.ToString(), handle?.callbackId);
}

public override void DeclineInvitation(string username, CallBack handle = null)
{
JSONObject obj = new JSONObject();
obj.Add("username", username);
ContactManagerNative.ContactManager_HandleMethodCall("declineInvitation", obj.ToString(), handle?.callbackId);
ChatAPIIOS.ContactManager_HandleMethodCall("declineInvitation", obj.ToString(), handle?.callbackId);
}

public override void DeleteContact(string username, bool keepConversation = false, CallBack handle = null)
{
JSONObject obj = new JSONObject();
obj.Add("username", username);
obj.Add("keepConversation", keepConversation);
ContactManagerNative.ContactManager_HandleMethodCall("deleteContact", obj.ToString(), handle?.callbackId);
ChatAPIIOS.ContactManager_HandleMethodCall("deleteContact", obj.ToString(), handle?.callbackId);
}

public override List<string> GetAllContactsFromDB()
{
string jsonString = ContactManagerNative.ContactManager_GetMethodCall("getAllContactsFromDB");
string jsonString = ChatAPIIOS.ContactManager_GetMethodCall("getAllContactsFromDB");
if (jsonString == null || jsonString.Length == 0)
{
return null;
Expand All @@ -61,33 +61,25 @@ public override List<string> GetAllContactsFromDB()

public override void GetAllContactsFromServer(ValueCallBack<List<string>> handle = null)
{
ContactManagerNative.ContactManager_HandleMethodCall("getAllContactsFromServer", null, handle?.callbackId);
ChatAPIIOS.ContactManager_HandleMethodCall("getAllContactsFromServer", null, handle?.callbackId);
}

public override void GetBlockListFromServer(ValueCallBack<List<string>> handle = null)
{
ContactManagerNative.ContactManager_HandleMethodCall("getBlockListFromServer", null, handle?.callbackId);
ChatAPIIOS.ContactManager_HandleMethodCall("getBlockListFromServer", null, handle?.callbackId);
}

public override void GetSelfIdsOnOtherPlatform(ValueCallBack<List<string>> handle = null)
{
ContactManagerNative.ContactManager_HandleMethodCall("getSelfIdsOnOtherPlatform", null, handle?.callbackId);
ChatAPIIOS.ContactManager_HandleMethodCall("getSelfIdsOnOtherPlatform", null, handle?.callbackId);
}

public override void RemoveUserFromBlockList(string username, CallBack handle = null)
{
JSONObject obj = new JSONObject();
obj.Add("username", username);
ContactManagerNative.ContactManager_HandleMethodCall("removeUserFromBlockList", obj.ToString(), handle?.callbackId);
ChatAPIIOS.ContactManager_HandleMethodCall("removeUserFromBlockList", obj.ToString(), handle?.callbackId);
}
}

class ContactManagerNative
{
[DllImport("__Internal")]
internal extern static void ContactManager_HandleMethodCall(string methodName, string jsonString = null, string callbackId = null);

[DllImport("__Internal")]
internal extern static string ContactManager_GetMethodCall(string methodName, string jsonString = null, string callbackId = null);
}
}
Loading

0 comments on commit 0b4f4f4

Please sign in to comment.