Skip to content
Open
26 changes: 22 additions & 4 deletions android/src/main/java/io/rong/imlib/ipc/IMLibModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.ReadableNativeArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Conversation.ConversationType;
import io.rong.imlib.model.Message;

/**
Expand Down Expand Up @@ -109,23 +115,35 @@ public void onError(RongIMClient.ErrorCode errorCode) {
}

@ReactMethod
public void getConversationList(final Promise promise){
public void getConversationList(ReadableArray types, final Promise promise) {
if (client == null) {
promise.reject("NotLogined", "Must call connect first.");
return;
}
ConversationType[] conversationTypes = {
ConversationType.PRIVATE,
ConversationType.DISCUSSION,
ConversationType.GROUP,
ConversationType.CHATROOM,
ConversationType.CUSTOMER_SERVICE,
ConversationType.SYSTEM,
ConversationType.APP_PUBLIC_SERVICE,
ConversationType.PUBLIC_SERVICE,
ConversationType.PUSH_SERVICE
};
if (types.size() > 0) {
conversationTypes = Utils.conversationTypeToEnumArray(types).toArray(new ConversationType[0]);
}
client.getConversationList(new RongIMClient.ResultCallback<List<Conversation>>() {

@Override
public void onSuccess(List<Conversation> conversations) {
promise.resolve(Utils.convertConversationList(conversations));
}

@Override
public void onError(RongIMClient.ErrorCode errorCode) {
promise.reject("" + errorCode.getValue(), errorCode.getMessage());
}
});
}, conversationTypes);
}

@ReactMethod
Expand Down
71 changes: 69 additions & 2 deletions android/src/main/java/io/rong/imlib/ipc/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,31 @@
import android.net.Uri;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import io.rong.imlib.RongIMClient;

import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Conversation.ConversationType;
import io.rong.imlib.model.Message;
import io.rong.imlib.model.MessageContent;
import io.rong.message.CommandNotificationMessage;
import io.rong.message.ImageMessage;
import io.rong.message.RichContentMessage;
import io.rong.message.TextMessage;
import io.rong.message.VoiceMessage;

/**
* Created by tdzl2003 on 4/13/16.
* Updated by mot
*/
public class Utils {

Expand Down Expand Up @@ -59,10 +65,17 @@ private static WritableMap convertMessageContent(MessageContent content) {
ret.putString("thumb", imageContent.getThumUri().toString());
ret.putString("extra", imageContent.getExtra());
} else if (content instanceof CommandNotificationMessage) {
CommandNotificationMessage notifyContent = (CommandNotificationMessage)content;
CommandNotificationMessage notifyContent = (CommandNotificationMessage) content;
ret.putString("type", "notify");
ret.putString("name", notifyContent.getName());
ret.putString("data", notifyContent.getData());
} else if (content instanceof RichContentMessage) {
RichContentMessage richContent = (RichContentMessage) content;
ret.putString("type", "rich");
ret.putString("title", richContent.getTitle());
ret.putString("image", richContent.getImgUrl());
ret.putString("url", richContent.getUrl());
ret.putString("extra", richContent.getExtra());
} else {
ret.putString("type", "unknown");
}
Expand Down Expand Up @@ -97,6 +110,17 @@ private static WritableMap convertConversation(Conversation conv) {
ret.putString("targetId", conv.getTargetId());
ret.putInt("unreadCount", conv.getUnreadMessageCount());
ret.putMap("lastMessage", convertMessageContent(conv.getLatestMessage()));

ret.putBoolean("isTop", conv.isTop());
ret.putInt("receivedStatus", conv.getReceivedStatus().getFlag());
ret.putInt("sentStatus", conv.getSentStatus().getValue());
ret.putDouble("receivedTime", conv.getReceivedTime());
ret.putDouble("sentTime", conv.getSentTime());
ret.putString("draft", conv.getDraft());
ret.putString("objectName", conv.getObjectName());

ret.putString("senderUserId", conv.getSenderUserId());
ret.putInt("lastestMessageId", conv.getLatestMessageId());
return ret;
}

Expand Down Expand Up @@ -128,4 +152,47 @@ public static MessageContent convertToMessageContent(ReadableMap map) {
}
return TextMessage.obtain("[未知消息]");
}

public static ArrayList<ConversationType> conversationTypeToEnumArray(ReadableArray conversationTypes) {
ArrayList<ConversationType> collection = new ArrayList<>();
for(int key = 0 ; key < conversationTypes.size(); key++) {
String type = conversationTypes.getString(key);
ConversationType t;
switch(type) {
case "private" :
t = ConversationType.PRIVATE;
break;
case "discussion" :
t = ConversationType.DISCUSSION;
break;
case "group" :
t = ConversationType.GROUP;
break;
case "chatroom" :
t = ConversationType.CHATROOM;
break;
case "customer_service" :
t = ConversationType.CUSTOMER_SERVICE;
break;
case "system" :
t = ConversationType.SYSTEM;
break;
case "app_public_service" :
t = ConversationType.APP_PUBLIC_SERVICE;
break;
case "public_service" :
t = ConversationType.PUBLIC_SERVICE;
break;
case "push_service" :
t = ConversationType.PUSH_SERVICE;
break;
default:
t = ConversationType.PRIVATE;
break;
}
collection.add(t);
}

return collection;
}
}
Loading