|
@@ -1,12 +1,28 @@
|
|
|
package cn.org.bjca.trust.android.lib.im.manager;
|
|
|
|
|
|
+import static cn.org.bjca.trust.android.lib.im.request.RequestConstant.MsgHistoryForCount;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
import cn.org.bjca.trust.android.lib.im.enums.MsgType;
|
|
|
+import cn.org.bjca.trust.android.lib.im.http.HttpManage;
|
|
|
+import cn.org.bjca.trust.android.lib.im.http.HttpResult;
|
|
|
import cn.org.bjca.trust.android.lib.im.im.IMHelper;
|
|
|
import cn.org.bjca.trust.android.lib.im.im.msg.message.SZYXMessage;
|
|
|
import cn.org.bjca.trust.android.lib.im.im.msg.message.SZYXTextMessage;
|
|
|
+import cn.org.bjca.trust.android.lib.im.kit.IMMsgCallback;
|
|
|
import cn.org.bjca.trust.android.lib.im.kit.IMSDKCallback;
|
|
|
import cn.org.bjca.trust.android.lib.im.kit.MsgListener;
|
|
|
import cn.org.bjca.trust.android.lib.im.kit.SdkMsgInterface;
|
|
|
+import cn.org.bjca.trust.android.lib.im.repository.Service;
|
|
|
+import cn.org.bjca.trust.android.lib.im.repository.msg.MsgHistoryForCountData;
|
|
|
+import cn.org.bjca.trust.android.lib.im.request.RequestCallback;
|
|
|
+import cn.org.bjca.trust.android.lib.im.request.RequestHelper;
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.disposables.Disposable;
|
|
|
+import io.reactivex.schedulers.Schedulers;
|
|
|
|
|
|
public class SZYXMessageManager implements SdkMsgInterface {
|
|
|
|
|
@@ -22,22 +38,100 @@ public class SZYXMessageManager implements SdkMsgInterface {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public SZYXMessage sendMsgForTextToC(String toUserId, String text, IMSDKCallback callback) {
|
|
|
- SZYXTextMessage textMessage = new SZYXTextMessage(text);
|
|
|
+ public SZYXMessage sendMsgForText(@NonNull String toClientId, String text) {
|
|
|
+ return this.sendMsgForText(toClientId, false, text, null, null);
|
|
|
+ }
|
|
|
|
|
|
- SZYXMessage szyxMessage = IMHelper.getInstance().createMsg(MsgType.Text, toUserId, false, textMessage, null);
|
|
|
+ @Override
|
|
|
+ public SZYXMessage sendMsgForText(String toClientId, String text, String describe) {
|
|
|
+ return this.sendMsgForText(toClientId, false, text, describe, null);
|
|
|
+ }
|
|
|
|
|
|
- IMHelper.getInstance().sendSZYXMessage(szyxMessage, callback);
|
|
|
- return szyxMessage;
|
|
|
+ @Override
|
|
|
+ public SZYXMessage sendMsgForText(String toClientId, String text, String describe, IMSDKCallback callback) {
|
|
|
+ return this.sendMsgForText(toClientId, false, text, describe, callback);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SZYXMessage sendMsgForText(String toClientId, String text, IMSDKCallback callback) {
|
|
|
+ return this.sendMsgForText(toClientId, false, text, null, callback);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SZYXMessage sendMsgForText(String toClientId, boolean isGroup, String text) {
|
|
|
+ return this.sendMsgForText(toClientId, isGroup, text, null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SZYXMessage sendMsgForText(String toClientId, boolean isGroup, String text, IMSDKCallback callback) {
|
|
|
+ return this.sendMsgForText(toClientId, isGroup, text, null, callback);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SZYXMessage sendMsgForText(String toClientId, boolean isGroup, String text, String describe) {
|
|
|
+ return this.sendMsgForText(toClientId, isGroup, text, describe, null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public SZYXMessage sendMsgForTextToG(String toGroupId, String text, IMSDKCallback callback) {
|
|
|
+ public SZYXMessage sendMsgForText(@NonNull String toClientId, boolean isGroup, @NonNull String text, String describe, IMSDKCallback callback) {
|
|
|
SZYXTextMessage textMessage = new SZYXTextMessage(text);
|
|
|
|
|
|
- SZYXMessage szyxMessage = IMHelper.getInstance().createMsg(MsgType.Text, toGroupId, true, textMessage, null);
|
|
|
+ SZYXMessage szyxMessage = IMHelper.getInstance().createMsg(MsgType.Text, toClientId, isGroup, textMessage, describe);
|
|
|
|
|
|
IMHelper.getInstance().sendSZYXMessage(szyxMessage, callback);
|
|
|
return szyxMessage;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getHistory(String userId, IMMsgCallback callback) {
|
|
|
+ this.getHistory(userId, System.currentTimeMillis(), 10, callback);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getHistory(String userId, long timestamp, IMMsgCallback callback) {
|
|
|
+ this.getHistory(userId, timestamp, 10, callback);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getHistory(@NonNull String userId, long timestamp, int size, @NonNull IMMsgCallback callback) {
|
|
|
+ MsgHistoryForCountData data = new MsgHistoryForCountData(userId, timestamp, size);
|
|
|
+ RequestHelper.getInstance().requestList(MsgHistoryForCount, data, SZYXMessage.class, new RequestCallback<List<SZYXMessage>>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void success(HttpResult<List<SZYXMessage>> result) {
|
|
|
+ if (result.getCode() == 200) {
|
|
|
+ callback.success(result.getData());
|
|
|
+ } else
|
|
|
+ callback.failed(result.getCode(), result.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void failed(int code, String error) {
|
|
|
+ callback.failed(code, error);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void standby(RequestCallback<List<SZYXMessage>> imCallback) {
|
|
|
+
|
|
|
+ Disposable d = HttpManage.getApi(Service.class)
|
|
|
+ .getHistoryForCount(data)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(httpResult -> {
|
|
|
+ if (httpResult.getCode() == 200) {
|
|
|
+ imCallback.success(httpResult);
|
|
|
+ } else
|
|
|
+ imCallback.failed(httpResult.getCode(), httpResult.getMsg());
|
|
|
+ }, throwable -> {
|
|
|
+ imCallback.failed(4002, throwable.getMessage());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getHistory(String userId, long timestampStart, long timestampEnd, IMMsgCallback callback) {
|
|
|
+
|
|
|
+ }
|
|
|
}
|