Trip On v2.1.2版本的 MD5 值为:55953a6deb5e434bd7a356ea51d31456
以下内容为反编译后的 d.java 源代码,内容仅作参考
package com.meiqia.core;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.text.TextUtils;
import com.meiqia.core.a.j;
import com.meiqia.core.a.k;
import com.meiqia.core.bean.MQAgent;
import com.meiqia.core.bean.MQClient;
import com.meiqia.core.bean.MQClientEvent;
import com.meiqia.core.bean.MQConversation;
import com.meiqia.core.bean.MQEnterpriseConfig;
import com.meiqia.core.bean.MQInquireForm;
import com.meiqia.core.bean.MQMessage;
import com.meiqia.core.bean.MQNotificationMessage;
import com.meiqia.core.callback.OnClientInfoCallback;
import com.meiqia.core.callback.OnEndConversationCallback;
import com.meiqia.core.callback.OnEvaluateRobotAnswerCallback;
import com.meiqia.core.callback.OnGetClientCallback;
import com.meiqia.core.callback.OnGetMQClientIdCallBackOn;
import com.meiqia.core.callback.OnGetMessageListCallback;
import com.meiqia.core.callback.OnInitCallback;
import com.meiqia.core.callback.OnMessageSendCallback;
import com.meiqia.core.callback.OnProgressCallback;
import com.meiqia.core.callback.OnRegisterDeviceTokenCallback;
import com.meiqia.core.callback.OnResultCallback;
import com.meiqia.core.callback.OnTicketCategoriesCallback;
import com.meiqia.core.callback.OnValueCallback;
import com.meiqia.core.callback.SimpleCallback;
import com.meiqia.core.callback.SuccessCallback;
import com.meiqia.core.h;
import com.meiqia.meiqiasdk.util.ErrorCode;
import com.taobao.weex.el.parse.Operators;
import com.taobao.weex.ui.component.list.template.TemplateDom;
import io.dcloud.common.constant.AbsoluteConst;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import okhttp3.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class d {
protected static MQClient a = null;
protected static MQAgent b = null;
protected static com.meiqia.core.a.i c = null;
private static int d = 100;
private final Handler e;
private final f f;
private final Context g;
private MQConversation h;
private MQEnterpriseConfig i;
private h j;
private String k;
private String l;
private String n;
private MQScheduleRule m = MQScheduleRule.REDIRECT_ENTERPRISE;
private boolean o = false;
private boolean p = true;
public class AnonymousClass20 implements OnGetMessageListCallback {
final MQClient a;
final String b;
final long c;
final OnGetMessageListCallback d;
AnonymousClass20(MQClient mQClient, String str, long j, OnGetMessageListCallback onGetMessageListCallback) {
this.a = mQClient;
this.b = str;
this.c = j;
this.d = onGetMessageListCallback;
}
@Override
public void onFailure(int i, String str) {
OnGetMessageListCallback onGetMessageListCallback = this.d;
if (onGetMessageListCallback != null) {
if (i == 404) {
onGetMessageListCallback.onSuccess(new ArrayList());
} else {
onGetMessageListCallback.onFailure(i, str);
}
}
}
@Override
public void onSuccess(List<MQMessage> list) {
d.this.a(this.a, this.b, list, new OnGetMessageListCallback() {
@Override
public void onFailure(int i, String str) {
if (AnonymousClass20.this.d != null) {
if (i == 404) {
AnonymousClass20.this.d.onSuccess(new ArrayList());
} else {
AnonymousClass20.this.d.onFailure(i, str);
}
}
}
@Override
public void onSuccess(final List<MQMessage> list2) {
d.this.a(list2, AnonymousClass20.this.c);
if (AnonymousClass20.this.d != null) {
d.this.f.a(list2);
d.this.a(new Runnable() {
@Override
public void run() {
AnonymousClass20.this.d.onSuccess(list2);
}
});
}
}
});
}
}
public class AnonymousClass7 implements OnGetMessageListCallback {
final long a;
final int b;
final OnGetMessageListCallback c;
AnonymousClass7(long j, int i, OnGetMessageListCallback onGetMessageListCallback) {
this.a = j;
this.b = i;
this.c = onGetMessageListCallback;
}
@Override
public void onFailure(int i, String str) {
OnGetMessageListCallback onGetMessageListCallback = this.c;
if (onGetMessageListCallback != null) {
onGetMessageListCallback.onFailure(i, str);
}
}
@Override
public void onSuccess(List<MQMessage> list) {
d.this.f.b(list);
MQManager.getInstance(d.this.g).getMQMessageFromDatabase(this.a, this.b, new OnGetMessageListCallback() {
@Override
public void onFailure(final int i, final String str) {
d.this.a(new Runnable() {
@Override
public void run() {
if (AnonymousClass7.this.c != null) {
AnonymousClass7.this.c.onFailure(i, str);
}
}
});
}
@Override
public void onSuccess(final List<MQMessage> list2) {
d.this.a(new Runnable() {
@Override
public void run() {
if (AnonymousClass7.this.c != null) {
AnonymousClass7.this.c.onSuccess(list2);
}
}
});
}
});
}
}
public class a implements OnGetClientCallback {
private OnGetMQClientIdCallBackOn b;
public a(OnGetMQClientIdCallBackOn onGetMQClientIdCallBackOn) {
this.b = onGetMQClientIdCallBackOn;
}
@Override
public void onFailure(int i, String str) {
OnGetMQClientIdCallBackOn onGetMQClientIdCallBackOn = this.b;
if (onGetMQClientIdCallBackOn != null) {
onGetMQClientIdCallBackOn.onFailure(i, str);
}
}
@Override
public void onSuccess(boolean z, String str, final String str2, String str3, String str4, String str5, String str6) {
d.this.f.a(new MQClient(d.c.a(), "", str2, str, str3, str4, str5, str6));
d.this.a(new Runnable() {
@Override
public void run() {
if (a.this.b != null) {
a.this.b.onSuccess(str2);
}
}
});
}
}
public d(Context context, com.meiqia.core.a.i iVar, f fVar, Handler handler) {
this.g = context;
c = iVar;
this.e = handler;
this.j = h.a();
this.f = fVar;
}
private void a(long j, final h.i iVar) {
this.j.a(j, new h.e() {
@Override
public void a(JSONObject jSONObject) {
String optString = jSONObject.optString("status");
if ("closed".equals(optString) || "processed".equals(optString)) {
iVar.b();
} else {
iVar.a();
}
}
@Override
public void onFailure(int i, String str) {
iVar.onFailure(i, str);
}
});
}
public void a(long j, List<MQMessage> list) {
if (list.size() != 0) {
try {
Intent intent = new Intent("ACTION_MARK_MESSAGES_READ");
intent.putExtra("message_ids", k.a(list));
intent.putExtra("conv_id", j);
this.g.sendBroadcast(intent);
} catch (Exception unused) {
}
}
}
public void a(MQClient mQClient, String str, final List<MQMessage> list, final OnGetMessageListCallback onGetMessageListCallback) {
HashMap hashMap = new HashMap();
hashMap.put("enterprise_id", mQClient.getEnterpriseId());
hashMap.put("begin", str);
this.j.a(hashMap, mQClient.getTrackId(), new OnGetMessageListCallback() {
@Override
public void onFailure(int i, String str2) {
onGetMessageListCallback.onFailure(i, str2);
}
@Override
public void onSuccess(final List<MQMessage> list2) {
final OnResultCallback onResultCallback = new OnResultCallback() {
@Override
public void onResult(Object obj) {
int i = 0;
for (MQMessage mQMessage : list2) {
d.a(mQMessage, i);
mQMessage.setTrack_id(d.a.getTrackId());
i++;
}
if (list2.size() > 0) {
List list3 = list2;
d.c.c(d.a, ((MQMessage) list3.get(list3.size() - 1)).getCreated_on());
}
list.addAll(list2);
Collections.sort(list, new com.meiqia.core.a.h());
onGetMessageListCallback.onSuccess(list);
}
};
d.this.f.a(System.currentTimeMillis(), 30, new OnGetMessageListCallback() {
@Override
public void onFailure(int i, String str2) {
onResultCallback.onResult(null);
}
@Override
public void onSuccess(List<MQMessage> list3) {
for (MQMessage mQMessage : list3) {
if (MQMessage.TYPE_SDK.equals(mQMessage.getType())) {
Iterator it = list2.iterator();
while (true) {
if (it.hasNext()) {
MQMessage mQMessage2 = (MQMessage) it.next();
if (TextUtils.equals(MQMessage.TYPE_SDK, mQMessage.getType()) && TextUtils.equals(mQMessage.getContent(), mQMessage2.getContent()) && mQMessage.getCreated_on() == mQMessage2.getCreated_on()) {
d.this.f.a(mQMessage.getId());
break;
}
}
}
}
}
onResultCallback.onResult(null);
}
});
}
});
}
public void a(MQConversation mQConversation) {
this.h = mQConversation;
MeiQiaService.f = mQConversation != null ? mQConversation.getId() : 0L;
}
private void a(MQMessage mQMessage) {
MQAgent mQAgent;
mQMessage.setAvatar(c.j(a));
mQMessage.setFrom_type("client");
mQMessage.setType("message");
String trackId = a.getTrackId();
if (!TextUtils.isEmpty(trackId)) {
mQMessage.setTrack_id(trackId);
}
if (this.h == null || (mQAgent = b) == null) {
return;
}
mQMessage.setAgent_nickname(mQAgent.getNickname());
mQMessage.setConversation_id(this.h.getId());
mQMessage.setAgent_id(this.h.getAgent_id());
mQMessage.setEnterprise_id(this.h.getEnterprise_id());
}
public static void a(MQMessage mQMessage, long j) {
}
public void a(final MQMessage mQMessage, final OnMessageSendCallback onMessageSendCallback) {
if (b == null) {
b(mQMessage, onMessageSendCallback);
return;
}
HashMap hashMap = new HashMap();
hashMap.put("browser_id", a.getBrowserId());
hashMap.put("track_id", a.getTrackId());
hashMap.put("ent_id", a.getEnterpriseId());
hashMap.put("type", mQMessage.getContent_type());
hashMap.put("content", mQMessage.getContent());
if (TextUtils.equals(mQMessage.getContent_type(), "video")) {
JSONObject jSONObject = null;
try {
jSONObject = new JSONObject(mQMessage.getExtra());
} catch (JSONException e) {
e.printStackTrace();
}
hashMap.put("extra", jSONObject);
}
this.j.a("https://new-api.meiqia.com/client/send_msg", hashMap, new h.InterfaceC0024h() {
@Override
public void a(String str, long j, String str2) {
MQMessage mQMessage2;
long a2 = j.a(str);
long id = mQMessage.getId();
mQMessage.setCreated_on(a2);
mQMessage.setId(j);
mQMessage.setStatus("arrived");
if (!TextUtils.isEmpty(str2)) {
mQMessage.setExtra(str2);
try {
JSONObject jSONObject2 = new JSONObject(str2);
boolean optBoolean = jSONObject2.optBoolean("contains_sensitive_words", false);
String optString = jSONObject2.optString("replaced_content");
if (optBoolean) {
mQMessage2 = mQMessage;
} else {
mQMessage2 = mQMessage;
optString = mQMessage2.getContent();
}
mQMessage2.setContent(optString);
if (TextUtils.equals(jSONObject2.optString("result"), "queueing")) {
d.this.a(true);
k.a(d.this.g, new Intent("queueing_state"));
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
if (d.this.e() != null) {
mQMessage.setAgent_nickname(d.this.e().getNickname());
}
d.this.f.a(mQMessage, id);
d.this.a(new Runnable() {
@Override
public void run() {
if (onMessageSendCallback != null) {
onMessageSendCallback.onSuccess(mQMessage, 1);
}
}
});
}
@Override
public void onFailure(int i, String str) {
OnMessageSendCallback onMessageSendCallback2;
if (i != 400) {
if (i == 19997) {
d.this.a((MQConversation) null);
d.this.a((MQAgent) null);
d.this.b(mQMessage, onMessageSendCallback);
return;
}
if (i != 20008) {
if (i == 20009) {
d.this.a((MQAgent) null);
}
mQMessage.setStatus("failed");
d.this.f.a(mQMessage);
onMessageSendCallback2 = onMessageSendCallback;
if (onMessageSendCallback2 == null) {
onMessageSendCallback2.onFailure(mQMessage, i, str);
return;
}
return;
}
d.this.a(true);
}
if (i != 20008) {
if (d.b != null && !d.b.isRealAgent() && d.this.h().ticketConfig.isSdkEnabled()) {
d.this.a(true, mQMessage, (Map<String, String>) null, onMessageSendCallback);
return;
}
i = ErrorCode.NO_AGENT_ONLINE;
}
mQMessage.setStatus("failed");
d.this.f.a(mQMessage);
onMessageSendCallback2 = onMessageSendCallback;
if (onMessageSendCallback2 == null) {
}
}
});
}
public void a(MQMessage mQMessage, Map<String, String> map, h.f fVar) {
long a2 = c.a(a);
HashMap hashMap = new HashMap();
hashMap.put("enterprise_id", a.getEnterpriseId());
hashMap.put("track_id", a.getTrackId());
hashMap.put("visit_id", a.getVisitId());
hashMap.put(AbsoluteConst.XML_CHANNEL, MQMessage.TYPE_SDK);
if (a2 != -1) {
hashMap.put("conv_id", Long.valueOf(a2));
}
hashMap.put("content_type", mQMessage.getContent_type());
hashMap.put("content", mQMessage.getContent());
if (map != null) {
hashMap.put("client_info", com.meiqia.core.a.c.a((Map<?, ?>) b(map)));
}
if (!TextUtils.isEmpty(mQMessage.getExtra())) {
try {
String optString = new JSONObject(mQMessage.getExtra()).optString("thumb_url");
if (!TextUtils.isEmpty(optString)) {
hashMap.put("thumb_url", optString);
}
} catch (Exception e) {
e.printStackTrace();
}
}
this.j.a(hashMap, fVar);
a(false, map, (OnClientInfoCallback) null);
}
public void a(final h.a aVar, List<MQMessage> list) {
a(new Runnable() {
@Override
public void run() {
if (aVar != null) {
MQManager.getInstance(d.this.g).getMQMessageFromDatabase(Long.MAX_VALUE, 10, new OnGetMessageListCallback() {
@Override
public void onFailure(int i, String str) {
aVar.onFailure(i, str);
}
@Override
public void onSuccess(List<MQMessage> list2) {
aVar.a(d.this.o, d.b, d.this.h, list2);
if (list2 == null || list2.size() == 0 || d.this.h == null) {
return;
}
MQConversation mQConversation = new MQConversation();
mQConversation.setId(d.this.h.getId());
ArrayList arrayList = new ArrayList();
for (MQMessage mQMessage : list2) {
if (mQMessage.getRead_status() != 3 && d.this.h.getId() == mQMessage.getConversation_id()) {
arrayList.add(mQMessage);
}
}
if (arrayList.size() > 0) {
mQConversation.setMessageList(arrayList);
i.a().a("ONLINE_MARK_READ_CONVERSATION_KEY", mQConversation);
d.this.a(mQConversation.getId(), arrayList);
}
}
});
}
Intent intent = new Intent(d.this.g, MeiQiaService.class);
intent.setAction("ACTION_OPEN_SOCKET");
intent.putExtra("KEY_BOOLEAN_SYNC_MSG", true);
try {
d.this.g.startService(intent);
} catch (Throwable unused) {
}
}
});
}
public void a(Runnable runnable) {
this.e.post(runnable);
}
public void a(String str, final SimpleCallback simpleCallback) {
try {
String g = c.g(a);
final MQClient a2 = this.f.a(str);
final String g2 = c.g(a2);
Map<String, Object> e = k.e(this.g);
final String jSONObject = com.meiqia.core.a.c.a((Map<?, ?>) e).toString();
if (!TextUtils.isEmpty(g2) && !TextUtils.isEmpty(g) && (TextUtils.isEmpty(g) || g.equals(jSONObject))) {
if (simpleCallback != null) {
a(new Runnable() {
@Override
public void run() {
simpleCallback.onSuccess();
}
});
return;
}
return;
}
this.j.a(str, e, new OnClientInfoCallback() {
@Override
public void onFailure(int i, String str2) {
SimpleCallback simpleCallback2 = simpleCallback;
if (simpleCallback2 != null) {
simpleCallback2.onFailure(i, str2);
}
}
@Override
public void onSuccess() {
com.meiqia.core.a.i iVar;
MQClient mQClient;
if (TextUtils.isEmpty(g2)) {
iVar = d.c;
mQClient = a2;
} else {
iVar = d.c;
mQClient = d.a;
}
iVar.b(mQClient, jSONObject);
if (simpleCallback != null) {
d.this.a(new Runnable() {
@Override
public void run() {
simpleCallback.onSuccess();
}
});
}
}
});
} catch (Exception unused) {
if (simpleCallback != null) {
a(new Runnable() {
@Override
public void run() {
simpleCallback.onFailure(20000, "UNKNOW");
}
});
}
}
}
private void a(String str, String str2, final h.j jVar) {
try {
File file = new File(str2);
str.hashCode();
char c2 = 65535;
switch (str.hashCode()) {
case 3143036:
if (str.equals("file")) {
c2 = 0;
break;
}
break;
case 93166550:
if (str.equals("audio")) {
c2 = 1;
break;
}
break;
case 106642994:
if (str.equals("photo")) {
c2 = 2;
break;
}
break;
case 112202875:
if (str.equals("video")) {
c2 = 3;
break;
}
break;
}
switch (c2) {
case 0:
return;
case 1:
this.j.b(file, new h.b() {
@Override
public void a(JSONObject jSONObject, Response response) {
final String optString = jSONObject.optString("audio_url");
final String optString2 = jSONObject.optString("audio_key");
d.this.a(new Runnable() {
@Override
public void run() {
if (jVar != null) {
jVar.a(optString2, optString);
}
}
});
}
}, jVar);
return;
case 2:
String a2 = k.a(this.g);
File file2 = new File(a2, System.currentTimeMillis() + "");
if (this.p) {
com.meiqia.core.a.b.a(file, file2);
file = file2;
}
this.j.a(file, new h.b() {
@Override
public void a(JSONObject jSONObject, Response response) {
final String optString = jSONObject.optString("photo_url");
final String optString2 = jSONObject.optString("photo_key");
d.this.a(new Runnable() {
@Override
public void run() {
if (jVar != null) {
jVar.a(optString2, optString);
}
}
});
}
}, jVar);
return;
case 3:
MQClient mQClient = a;
if (mQClient != null && !TextUtils.isEmpty(mQClient.getEnterpriseId())) {
final HashMap hashMap = new HashMap();
this.j.a(file, hashMap, new OnProgressCallback() {
@Override
public void onFailure(int i, String str3) {
jVar.onFailure(i, str3);
}
@Override
public void onProgress(int i) {
}
@Override
public void onSuccess() {
jVar.a((String) hashMap.get("key"), ((String) hashMap.get("file_url")) + "-separator-" + ((String) hashMap.get("thumb_url")));
}
});
return;
}
break;
}
jVar.onFailure(ErrorCode.PARAMETER_ERROR, "unknown contentType");
} catch (Exception unused) {
jVar.onFailure(ErrorCode.FILE_NOT_FOUND, "file not found");
}
}
public void a(List<MQMessage> list, long j) {
Iterator<MQMessage> it = list.iterator();
while (it.hasNext()) {
MQMessage next = it.next();
if ("ending".equals(next.getType()) || next.getCreated_on() <= j || "client".equals(next.getFrom_type())) {
it.remove();
}
}
}
private void a(final List<MQMessage> list, final List<String> list2, final Map<String, String> map, final SimpleCallback simpleCallback) {
final int[] iArr = {0, 0};
for (String str : list2) {
a("photo", str, new h.j() {
@Override
public void a(String str2, String str3) {
int[] iArr2 = iArr;
iArr2[0] = iArr2[0] + 1;
MQMessage mQMessage = new MQMessage("photo");
mQMessage.setContent(str2);
mQMessage.setMedia_url(str3);
list.add(mQMessage);
int[] iArr3 = iArr;
if (iArr3[0] + iArr3[1] == list2.size()) {
if (iArr[0] == list2.size()) {
d.this.a(list, map, simpleCallback);
return;
}
SimpleCallback simpleCallback2 = simpleCallback;
if (simpleCallback2 != null) {
simpleCallback2.onFailure(20002, "upload photo failed");
}
}
}
@Override
public void onFailure(int i, String str2) {
SimpleCallback simpleCallback2;
int[] iArr2 = iArr;
iArr2[1] = iArr2[1] + 1;
if (iArr2[0] + iArr2[1] != list2.size() || (simpleCallback2 = simpleCallback) == null) {
return;
}
simpleCallback2.onFailure(i, str2);
}
});
}
}
public void a(final List<MQMessage> list, final Map<String, String> map, final SimpleCallback simpleCallback) {
HashMap hashMap = new HashMap();
hashMap.put("browser_id", a.getBrowserId());
hashMap.put("track_id", a.getTrackId());
hashMap.put("enterprise_id", a.getEnterpriseId());
hashMap.put("visit_id", a.getVisitId());
ArrayList arrayList = new ArrayList();
for (MQMessage mQMessage : list) {
HashMap hashMap2 = new HashMap();
hashMap2.put("content_type", mQMessage.getContent_type());
hashMap2.put("content", mQMessage.getContent());
arrayList.add(hashMap2);
}
hashMap.put("replies", arrayList);
this.j.a(hashMap, new h.g() {
@Override
public void a(JSONArray jSONArray) {
for (int i = 0; i < list.size(); i++) {
MQMessage mQMessage2 = (MQMessage) list.get(i);
JSONObject optJSONObject = jSONArray.optJSONObject(i);
if (optJSONObject != null) {
mQMessage2.setCreated_on(j.a(optJSONObject.optString("created_on")));
mQMessage2.setId(optJSONObject.optLong("id"));
mQMessage2.setStatus("arrived");
mQMessage2.setFrom_type("client");
mQMessage2.setType("message");
mQMessage2.setTrack_id(d.a.getTrackId());
if (d.this.h != null && d.b != null) {
mQMessage2.setAgent_nickname(d.b.getNickname());
mQMessage2.setConversation_id(d.this.h.getId());
mQMessage2.setAgent_id(d.this.h.getAgent_id());
mQMessage2.setEnterprise_id(d.this.h.getEnterprise_id());
}
d.this.f.a(mQMessage2);
}
}
Map map2 = map;
if (map2 != null && map2.keySet().size() != 0) {
d.this.a(map, simpleCallback);
} else if (simpleCallback != null) {
d.this.a(new Runnable() {
@Override
public void run() {
simpleCallback.onSuccess();
}
});
}
}
@Override
public void onFailure(int i, String str) {
SimpleCallback simpleCallback2 = simpleCallback;
if (simpleCallback2 != null) {
simpleCallback2.onFailure(i, str);
}
}
});
}
public void a(Map<String, String> map, final SimpleCallback simpleCallback) {
a(map, new OnClientInfoCallback() {
@Override
public void onFailure(int i, String str) {
SimpleCallback simpleCallback2 = simpleCallback;
if (simpleCallback2 != null) {
simpleCallback2.onFailure(i, str);
}
}
@Override
public void onSuccess() {
if (simpleCallback != null) {
d.this.a(new Runnable() {
@Override
public void run() {
simpleCallback.onSuccess();
}
});
}
}
});
}
public void a(final Map<String, Object> map, final List<MQMessage> list, final h.a aVar) {
a(a.getTrackId(), new OnClientInfoCallback() {
@Override
public void onFailure(int i, String str) {
d.this.b(map, list, aVar);
}
@Override
public void onSuccess() {
d.this.b(map, list, aVar);
}
});
}
private Map<String, Object> b(Map<String, String> map) {
HashMap hashMap = new HashMap();
for (Map.Entry<String, String> entry : map.entrySet()) {
hashMap.put(entry.getKey(), entry.getValue());
}
try {
if (map.containsKey("obj_key_array")) {
JSONArray jSONArray = new JSONArray((String) hashMap.remove("obj_key_array"));
for (int i = 0; i < jSONArray.length(); i++) {
String string = jSONArray.getString(i);
String str = (String) hashMap.remove(string);
try {
hashMap.put(string, new JSONArray(str));
} catch (Exception unused) {
hashMap.put(string, new JSONObject(str));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return hashMap;
}
public void b(final MQMessage mQMessage, final OnMessageSendCallback onMessageSendCallback) {
a(this.f, this.k, this.l, false, this.m, new h.a() {
@Override
public void a(boolean z, MQAgent mQAgent, MQConversation mQConversation, List<MQMessage> list) {
d.this.a(z);
if (z) {
Intent intent = new Intent(d.this.g, MeiQiaService.class);
intent.setAction("ACTION_OPEN_SOCKET");
try {
d.this.g.startService(intent);
} catch (Throwable unused) {
}
mQMessage.setStatus("failed");
d.this.f.a(mQMessage);
onMessageSendCallback.onFailure(mQMessage, ErrorCode.QUEUEING, null);
return;
}
MQMessageManager.getInstance(d.this.g).setCurrentAgent(mQAgent);
Intent intent2 = new Intent("agent_change_action");
intent2.putExtra("conversation_id", String.valueOf(mQConversation.getId()));
k.a(d.this.g, intent2);
d.this.a(mQAgent);
d.this.a(mQMessage, new OnMessageSendCallback() {
@Override
public void onFailure(MQMessage mQMessage2, int i, String str) {
onMessageSendCallback.onFailure(mQMessage2, i, str);
}
@Override
public void onSuccess(MQMessage mQMessage2, int i) {
Intent intent3 = new Intent(d.this.g, MeiQiaService.class);
intent3.setAction("ACTION_OPEN_SOCKET");
try {
d.this.g.startService(intent3);
} catch (Throwable unused2) {
}
onMessageSendCallback.onSuccess(mQMessage2, i);
}
});
}
@Override
public void onFailure(int i, String str) {
OnMessageSendCallback onMessageSendCallback2;
if (i != 19998) {
mQMessage.setStatus("failed");
d.this.f.a(mQMessage);
onMessageSendCallback2 = onMessageSendCallback;
if (onMessageSendCallback2 == null) {
return;
}
} else {
d.this.a((MQAgent) null);
if (d.this.h().ticketConfig.isSdkEnabled()) {
d.this.a(true, mQMessage, (Map<String, String>) null, onMessageSendCallback);
return;
}
mQMessage.setStatus("failed");
d.this.f.a(mQMessage);
onMessageSendCallback2 = onMessageSendCallback;
if (onMessageSendCallback2 == null) {
return;
}
}
onMessageSendCallback2.onFailure(mQMessage, i, str);
}
});
}
public void b(MQMessage mQMessage, Map<String, String> map, h.f fVar) {
long f = c.f(a);
HashMap hashMap = new HashMap();
hashMap.put("enterprise_id", a.getEnterpriseId());
hashMap.put("type", MQMessage.TYPE_SDK);
hashMap.put("content_type", mQMessage.getContent_type());
hashMap.put("source", "client");
hashMap.put("content", mQMessage.getContent());
if (!TextUtils.isEmpty(mQMessage.getExtra())) {
try {
String optString = new JSONObject(mQMessage.getExtra()).optString("thumb_url");
if (!TextUtils.isEmpty(optString)) {
hashMap.put("thumb_url", optString);
}
} catch (Exception e) {
e.printStackTrace();
}
}
this.j.a(hashMap, f, fVar);
a(false, map, (OnClientInfoCallback) null);
}
private void b(final OnGetMessageListCallback onGetMessageListCallback) {
long b2 = c.b(a);
int parseInt = Integer.parseInt(a.getEnterpriseId());
String a2 = j.a(b2);
this.j.a(a.getTrackId(), d, 0, parseInt, a2, 1, new OnGetMessageListCallback() {
@Override
public void onFailure(int i, String str) {
OnGetMessageListCallback onGetMessageListCallback2 = onGetMessageListCallback;
if (onGetMessageListCallback2 != null) {
onGetMessageListCallback2.onFailure(i, str);
}
}
@Override
public void onSuccess(final List<MQMessage> list) {
for (MQMessage mQMessage : list) {
if (TextUtils.equals("client", mQMessage.getFrom_type())) {
mQMessage.setAvatar(d.c.j(d.a));
}
}
if (onGetMessageListCallback != null) {
d.this.a(new Runnable() {
@Override
public void run() {
onGetMessageListCallback.onSuccess(list);
}
});
}
}
});
}
public void b(Map<String, Object> map, final List<MQMessage> list, final h.a aVar) {
this.j.a(map, new h.a() {
@Override
public void a(boolean z, MQAgent mQAgent, MQConversation mQConversation, List<MQMessage> list2) {
List list3;
if (list2 != null) {
for (MQMessage mQMessage : list2) {
if (TextUtils.equals("client", mQMessage.getFrom_type())) {
mQMessage.setAvatar(d.c.j(d.a));
}
}
}
if (mQConversation != null) {
d.c.a(d.a, mQConversation.getId());
}
if (list2 != null && (list3 = list) != null) {
list2.removeAll(list3);
list2.addAll(0, list);
}
d.this.a(z);
if (!z) {
MQNotificationMessage b2 = g.a().b();
if (g.a().c() && b2 != null && mQConversation != null) {
g.a().a(mQConversation.getId());
MQMessage mQMessage2 = new MQMessage();
mQMessage2.setId(System.currentTimeMillis());
mQMessage2.setType("agent");
mQMessage2.setContent_type("text");
mQMessage2.setAgent_nickname(b2.getAgentName());
mQMessage2.setAvatar(b2.getAvatar());
mQMessage2.setTrack_id(b2.getTrackId());
mQMessage2.setContent(b2.getContent());
mQMessage2.setConversation_id(mQConversation.getId());
mQMessage2.setCreated_on(System.currentTimeMillis());
mQMessage2.setEnterprise_id(mQConversation.getEnterprise_id());
if (mQAgent != null) {
mQMessage2.setAgent_id(mQAgent.getId());
}
if (list2 != null) {
list2.add(mQMessage2);
}
}
d.c.a(d.a, true);
d.this.a(mQAgent);
d.this.a(mQConversation);
d.this.f.b(list2);
}
d.this.a(aVar, list2);
d.this.m();
if (TextUtils.isEmpty(d.this.n)) {
return;
}
d.this.j.a(d.this.n, (SimpleCallback) null);
d.this.n = "";
}
@Override
public void onFailure(int i, String str) {
if (i == 20004 || i == 19998) {
try {
Intent intent = new Intent(d.this.g, MeiQiaService.class);
intent.setAction("ACTION_OPEN_SOCKET");
d.this.g.startService(intent);
} catch (Throwable unused) {
}
if (i == 19998) {
d.this.a(false);
d.this.a((MQAgent) null);
}
}
h.a aVar2 = aVar;
if (aVar2 != null) {
aVar2.onFailure(i, str);
}
}
});
}
public void m() {
if (c.n(a)) {
return;
}
this.j.a(c.m(a), new OnRegisterDeviceTokenCallback() {
@Override
public void onFailure(int i, String str) {
}
@Override
public void onSuccess() {
d.c.b(d.a, true);
}
});
}
public void a() {
b(new OnGetMessageListCallback() {
@Override
public void onFailure(int i, String str) {
}
@Override
public void onSuccess(List<MQMessage> list) {
for (MQMessage mQMessage : list) {
c.a(d.this.g).a(mQMessage);
}
}
});
}
public void a(int i, int i2, long j, int i3, OnGetMessageListCallback onGetMessageListCallback) {
int parseInt = Integer.parseInt(a.getEnterpriseId());
String a2 = j.a(j);
this.j.a(a.getTrackId(), i, i2, parseInt, a2, i3, new AnonymousClass7(j, i, onGetMessageListCallback));
}
public void a(long j) {
this.f.a(j);
}
public void a(long j, int i) {
MQMessage b2 = this.f.b(j);
if (b2 != null) {
b2.setFeedbackUseful(i);
this.f.a(b2);
}
}
public void a(final long j, String str, long j2, final int i, final OnEvaluateRobotAnswerCallback onEvaluateRobotAnswerCallback) {
MQConversation mQConversation = this.h;
long id = mQConversation != null ? mQConversation.getId() : -1L;
MQAgent mQAgent = b;
this.j.a(j, mQAgent != null ? mQAgent.getAgentId() : -1, str, id, j2, i, new OnEvaluateRobotAnswerCallback() {
@Override
public void onFailure(int i2, String str2) {
onEvaluateRobotAnswerCallback.onFailure(i2, str2);
}
@Override
public void onSuccess(final String str2) {
d.this.a(j, i);
d.this.a(new Runnable() {
@Override
public void run() {
onEvaluateRobotAnswerCallback.onSuccess(str2);
}
});
}
});
}
public void a(long j, boolean z) {
MQMessage b2 = this.f.b(j);
if (b2 != null) {
b2.setIs_read(z);
this.f.a(b2);
}
}
public void a(Context context) {
try {
Intent intent = new Intent(context, MeiQiaService.class);
intent.setAction("ACTION_OPEN_SOCKET");
context.startService(intent);
a();
} catch (Throwable unused) {
}
}
public void a(MQAgent mQAgent) {
b = mQAgent;
if (mQAgent != null && !mQAgent.isRobot()) {
c.a(a, (String) null);
}
MQMessageManager.getInstance(this.g).setCurrentAgent(mQAgent);
}
public void a(MQClient mQClient) {
if (mQClient != null) {
a = mQClient;
c.b(mQClient.getTrackId());
com.meiqia.core.a.f.b((("current info: t = " + mQClient.getTrackId()) + " b " + mQClient.getBrowserId()) + " e " + mQClient.getEnterpriseId());
}
}
public void a(MQClientEvent mQClientEvent, final OnClientInfoCallback onClientInfoCallback) {
HashMap hashMap = new HashMap();
hashMap.put("ent_id", Integer.valueOf(Integer.parseInt(a.getEnterpriseId())));
hashMap.put("track_id", a.getTrackId());
hashMap.put("name", mQClientEvent.getName());
hashMap.put("metadata", mQClientEvent.getEvent().toString());
this.j.b(hashMap, new OnClientInfoCallback() {
@Override
public void onFailure(final int i, final String str) {
if (onClientInfoCallback != null) {
d.this.a(new Runnable() {
@Override
public void run() {
onClientInfoCallback.onFailure(i, str);
}
});
}
}
@Override
public void onSuccess() {
if (onClientInfoCallback != null) {
d.this.a(new Runnable() {
@Override
public void run() {
onClientInfoCallback.onSuccess();
}
});
}
}
});
}
public void a(final MQMessage mQMessage, long j, Map<String, String> map, final OnMessageSendCallback onMessageSendCallback) {
long a2 = c.a(a);
HashMap hashMap = new HashMap();
if (j != -1) {
hashMap.put("category_id", Long.valueOf(j));
}
if (a2 != -1) {
hashMap.put("conv_id", Long.valueOf(a2));
}
hashMap.put("enterprise_id", a.getEnterpriseId());
hashMap.put("track_id", a.getTrackId());
hashMap.put("visit_id", a.getVisitId());
hashMap.put(AbsoluteConst.XML_CHANNEL, MQMessage.TYPE_SDK);
hashMap.put("content_type", mQMessage.getContent_type());
hashMap.put("content", mQMessage.getContent());
if (map != null) {
hashMap.put("client_info", com.meiqia.core.a.c.a((Map<?, ?>) b(map)));
}
if (!TextUtils.isEmpty(mQMessage.getExtra())) {
try {
String optString = new JSONObject(mQMessage.getExtra()).optString("thumb_url");
if (!TextUtils.isEmpty(optString)) {
hashMap.put("thumb_url", optString);
}
} catch (Exception e) {
e.printStackTrace();
}
}
this.j.a(hashMap, new h.f() {
@Override
public void a(String str, long j2) {
mQMessage.setCreated_on(j.a(str));
mQMessage.setId(j2);
mQMessage.setStatus("arrived");
d.this.a(new Runnable() {
@Override
public void run() {
onMessageSendCallback.onSuccess(mQMessage, 1);
}
});
}
@Override
public void onFailure(int i, String str) {
mQMessage.setStatus("failed");
onMessageSendCallback.onFailure(mQMessage, i, str);
}
});
a(false, map, (OnClientInfoCallback) null);
}
public void a(MQMessage mQMessage, final OnProgressCallback onProgressCallback) {
File externalStoragePublicDirectory;
Runnable runnable;
if (k.a()) {
this.j.a(mQMessage.getConversation_id(), mQMessage.getId(), a.getTrackId(), Long.parseLong(a.getEnterpriseId()), (SimpleCallback) null);
if (Build.VERSION.SDK_INT >= 29) {
externalStoragePublicDirectory = this.g.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
if (externalStoragePublicDirectory != null) {
externalStoragePublicDirectory.mkdirs();
} else {
runnable = new Runnable() {
@Override
public void run() {
onProgressCallback.onFailure(20005, "sdcard is not available");
}
};
}
} else {
externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
}
String absolutePath = externalStoragePublicDirectory.getAbsolutePath();
try {
String optString = new JSONObject(mQMessage.getExtra()).optString(AbsoluteConst.JSON_KEY_FILENAME);
int lastIndexOf = optString.lastIndexOf(Operators.DOT_STR);
final String str = optString.substring(0, lastIndexOf) + mQMessage.getId() + optString.substring(lastIndexOf, optString.length());
File file = new File(absolutePath);
if (!file.exists()) {
file.mkdirs();
}
final File file2 = new File(file, str);
this.j.a(mQMessage, file2, new OnProgressCallback() {
@Override
public void onFailure(final int i, final String str2) {
d.this.a(new Runnable() {
@Override
public void run() {
onProgressCallback.onFailure(i, str2);
}
});
}
@Override
public void onProgress(final int i) {
d.this.a(new Runnable() {
@Override
public void run() {
onProgressCallback.onProgress(i);
}
});
}
@Override
public void onSuccess() {
if (Build.VERSION.SDK_INT >= 29) {
k.a(d.this.g, file2.getAbsolutePath(), str);
}
d.this.a(new Runnable() {
@Override
public void run() {
onProgressCallback.onSuccess();
}
});
}
});
return;
} catch (Exception unused) {
a(new Runnable() {
@Override
public void run() {
onProgressCallback.onFailure(20000, "download file failed");
}
});
return;
}
}
runnable = new Runnable() {
@Override
public void run() {
onProgressCallback.onFailure(20005, "sdcard is not available");
}
};
a(runnable);
}
public void a(MQMessage mQMessage, Map<String, String> map, OnMessageSendCallback onMessageSendCallback) {
a(mQMessage, -1L, map, onMessageSendCallback);
}
public void a(final OnEndConversationCallback onEndConversationCallback) {
this.j.a(new OnClientInfoCallback() {
@Override
public void onFailure(int i, String str) {
OnEndConversationCallback onEndConversationCallback2 = onEndConversationCallback;
if (onEndConversationCallback2 != null) {
onEndConversationCallback2.onFailure(i, str);
}
}
@Override
public void onSuccess() {
d.c.a(d.a, (String) null);
d.this.a((MQAgent) null);
d.this.a(new Runnable() {
@Override
public void run() {
if (onEndConversationCallback != null) {
onEndConversationCallback.onSuccess();
}
}
});
MQManager.getInstance(d.this.g).closeMeiqiaService();
}
});
}
public void a(OnGetMQClientIdCallBackOn onGetMQClientIdCallBackOn) {
this.j.a(new a(onGetMQClientIdCallBackOn));
}
public void a(final OnGetMessageListCallback onGetMessageListCallback) {
if (c.d(a)) {
b(new OnGetMessageListCallback() {
@Override
public void onFailure(int i, String str) {
if (i == 20010) {
onGetMessageListCallback.onFailure(i, str);
return;
}
d.this.a(d.a, j.a(d.c.c(d.a)), new ArrayList(), onGetMessageListCallback);
}
@Override
public void onSuccess(List<MQMessage> list) {
d.this.a(d.a, j.a(d.c.c(d.a)), list, onGetMessageListCallback);
}
});
} else {
a(new Runnable() {
@Override
public void run() {
onGetMessageListCallback.onSuccess(new ArrayList());
}
});
}
}
public void a(final OnInitCallback onInitCallback) {
MQClient d2 = d();
if (d2 == null) {
d2 = l();
}
if (!(d2 != null)) {
a(new OnGetMQClientIdCallBackOn() {
@Override
public void onFailure(int i, String str) {
OnInitCallback onInitCallback2 = onInitCallback;
if (onInitCallback2 != null) {
onInitCallback2.onFailure(i, str);
}
}
@Override
public void onSuccess(String str) {
OnInitCallback onInitCallback2 = onInitCallback;
if (onInitCallback2 != null) {
onInitCallback2.onSuccess(str);
}
d.this.a(str, (SimpleCallback) null);
}
});
} else if (onInitCallback != null) {
onInitCallback.onSuccess(d2.getTrackId());
}
}
public void a(final OnTicketCategoriesCallback onTicketCategoriesCallback) {
this.j.a(new h.e() {
@Override
public void a(final JSONObject jSONObject) {
d.this.a(new Runnable() {
@Override
public void run() {
onTicketCategoriesCallback.onSuccess(jSONObject.optJSONArray("categories"));
}
});
}
@Override
public void onFailure(int i, String str) {
onTicketCategoriesCallback.onFailure(i, str);
}
});
}
public void a(final SimpleCallback simpleCallback) {
if (System.currentTimeMillis() - c.p(a) < 30000) {
if (simpleCallback != null) {
simpleCallback.onSuccess();
return;
}
return;
}
HashMap hashMap = new HashMap();
hashMap.put("ent_id", a.getEnterpriseId());
hashMap.put("track_id", a.getTrackId());
this.j.a(hashMap, new h.e() {
@Override
public void a(JSONObject jSONObject) {
d.c.h(d.a, System.currentTimeMillis());
d.c.g(d.a, jSONObject.toString());
com.meiqia.core.a.c.a(d.this.h(), jSONObject, d.c, d.a);
d.this.i = null;
if (simpleCallback != null) {
d.this.a(new Runnable() {
@Override
public void run() {
simpleCallback.onSuccess();
}
});
}
}
@Override
public void onFailure(int i, String str) {
SimpleCallback simpleCallback2 = simpleCallback;
if (simpleCallback2 != null) {
simpleCallback2.onFailure(i, str);
}
}
});
}
public void a(final f fVar, String str, String str2, boolean z, MQScheduleRule mQScheduleRule, final h.a aVar) {
MQAgent mQAgent;
MQAgent mQAgent2;
if (!z && MeiQiaService.e && (mQAgent2 = b) != null && mQAgent2.isRealAgent() && aVar != null && c.d(a)) {
a(aVar, (List<MQMessage>) null);
return;
}
String trackId = a.getTrackId();
String visitId = a.getVisitId();
String enterpriseId = a.getEnterpriseId();
final HashMap hashMap = new HashMap();
if (!TextUtils.isEmpty(str)) {
hashMap.put("group_token", str);
}
if (!TextUtils.isEmpty(str2)) {
hashMap.put("agent_token", str2);
}
hashMap.put("fallback", Integer.valueOf(mQScheduleRule.getValue()));
hashMap.put("visit_id", visitId);
hashMap.put("track_id", trackId);
hashMap.put("ent_id", Long.valueOf(enterpriseId));
if (z && (mQAgent = b) != null) {
hashMap.put("exclude_agent_tokens", Arrays.asList(mQAgent.getId()));
}
if (!TextUtils.isEmpty(c.e(a))) {
hashMap.put("exclude_agent_tokens", Arrays.asList(c.e(a)));
}
hashMap.put("queueing", true);
if (c.d(a)) {
a(new OnGetMessageListCallback() {
@Override
public void onFailure(int i, String str3) {
if (i == 20010) {
aVar.onFailure(i, str3);
} else {
d.this.a(hashMap, (List<MQMessage>) null, aVar);
}
}
@Override
public void onSuccess(List<MQMessage> list) {
fVar.a(list);
d.this.a(hashMap, list, aVar);
}
});
} else {
a(hashMap, (List<MQMessage>) null, aVar);
}
}
public void a(final h.d dVar) {
this.j.a(new h.d() {
@Override
public void a(final int i) {
d.this.a(new Runnable() {
@Override
public void run() {
dVar.a(d.this.o ? i : 0);
}
});
}
@Override
public void onFailure(int i, String str) {
dVar.onFailure(i, str);
}
});
}
public void a(String str) {
MQAgent mQAgent = b;
this.j.a(str, mQAgent != null ? mQAgent.getAgentId() : -1);
}
public void a(String str, int i, String str2, final SimpleCallback simpleCallback) {
this.j.a(str, i, str2, new SimpleCallback() {
@Override
public void onFailure(int i2, String str3) {
simpleCallback.onFailure(i2, str3);
}
@Override
public void onSuccess() {
d.this.a(new Runnable() {
@Override
public void run() {
simpleCallback.onSuccess();
}
});
}
});
}
public void a(String str, OnGetMQClientIdCallBackOn onGetMQClientIdCallBackOn) {
this.j.a(str, new a(onGetMQClientIdCallBackOn));
}
public void a(String str, OnGetMessageListCallback onGetMessageListCallback) {
String str2;
int parseInt;
String trackId;
long j;
MQClient mQClient;
if (TextUtils.isEmpty(str)) {
long k = c.k(a);
long l = c.l(a);
if (k <= l) {
k = l;
}
String a2 = j.a(k);
int parseInt2 = Integer.parseInt(a.getEnterpriseId());
str2 = a2;
parseInt = parseInt2;
trackId = a.getTrackId();
mQClient = a;
j = k;
} else {
MQClient a3 = this.f.a(str);
if (a3 == null) {
a3 = this.f.b(str);
}
if (a3 == null) {
a((String) null, onGetMessageListCallback);
return;
}
long k2 = c.k(a3);
long l2 = c.l(a3);
if (k2 <= l2) {
k2 = l2;
}
String a4 = j.a(k2);
str2 = a4;
parseInt = Integer.parseInt(a3.getEnterpriseId());
trackId = a3.getTrackId();
j = k2;
mQClient = a3;
}
this.j.a(trackId, d, 0, parseInt, str2, 1, new AnonymousClass20(mQClient, str2, j, onGetMessageListCallback));
}
public void a(final String str, final OnInitCallback onInitCallback) {
if (TextUtils.isEmpty(str)) {
if (onInitCallback != null) {
onInitCallback.onFailure(ErrorCode.PARAMETER_ERROR, "customizedId can't be empty");
return;
}
return;
}
MQClient b2 = this.f.b(str);
if (b2 == null) {
this.j.b(str, new OnGetClientCallback() {
@Override
public void onFailure(int i, String str2) {
OnInitCallback onInitCallback2 = onInitCallback;
if (onInitCallback2 != null) {
onInitCallback2.onFailure(i, str2);
}
}
@Override
public void onSuccess(boolean z, String str2, final String str3, String str4, String str5, String str6, String str7) {
d.this.f.a(new MQClient(d.c.a(), str, str3, str2, str4, str5, str6, str7));
d.this.a(new Runnable() {
@Override
public void run() {
if (onInitCallback != null) {
onInitCallback.onSuccess(str3);
}
}
});
}
});
} else if (onInitCallback != null) {
onInitCallback.onSuccess(b2.getTrackId());
}
}
public void a(String str, final OnRegisterDeviceTokenCallback onRegisterDeviceTokenCallback) {
Runnable runnable;
if (TextUtils.isEmpty(str)) {
runnable = new Runnable() {
@Override
public void run() {
onRegisterDeviceTokenCallback.onFailure(ErrorCode.PARAMETER_ERROR, "token is null");
}
};
} else {
c.f(a, str);
runnable = new Runnable() {
@Override
public void run() {
onRegisterDeviceTokenCallback.onSuccess();
}
};
}
a(runnable);
}
public void a(String str, String str2, MQScheduleRule mQScheduleRule) {
this.l = str;
this.k = str2;
if (mQScheduleRule != null) {
this.m = mQScheduleRule;
}
}
public void a(String str, final String str2, final String str3, final OnMessageSendCallback onMessageSendCallback) {
final MQMessage mQMessage = new MQMessage(str2);
mQMessage.setContent(str);
mQMessage.setMedia_url(str3);
mQMessage.setFrom_type("client");
a(mQMessage);
this.f.a(mQMessage);
if ("text".equals(str2) || "hybrid".equals(str2)) {
a(mQMessage, onMessageSendCallback);
} else {
a(str2, str3, new h.j() {
@Override
public void a(String str4, String str5) {
MQMessage mQMessage2;
String jSONObject;
mQMessage.setMedia_url(str5);
mQMessage.setContent(str4);
if (!"file".equals(str2)) {
if ("video".equals(str2)) {
mQMessage.setContent(str4);
String[] split = str5.split("-separator-");
mQMessage.setMedia_url(split[0]);
JSONObject jSONObject2 = new JSONObject();
try {
if (split.length >= 2) {
jSONObject2.put("thumb_url", split[1]);
}
File file = new File(str3);
jSONObject2.put(AbsoluteConst.JSON_KEY_FILENAME, file.getName());
jSONObject2.put(AbsoluteConst.JSON_KEY_SIZE, file.length());
jSONObject2.put("type", "video");
} catch (JSONException e) {
e.printStackTrace();
}
mQMessage2 = mQMessage;
jSONObject = jSONObject2.toString();
}
d.this.a(mQMessage, onMessageSendCallback);
}
mQMessage2 = mQMessage;
jSONObject = "";
mQMessage2.setExtra(jSONObject);
d.this.a(mQMessage, onMessageSendCallback);
}
@Override
public void onFailure(int i, String str4) {
mQMessage.setStatus("failed");
d.this.f.a(mQMessage);
OnMessageSendCallback onMessageSendCallback2 = onMessageSendCallback;
if (onMessageSendCallback2 != null) {
onMessageSendCallback2.onFailure(mQMessage, i, str4);
}
}
});
}
}
public void a(String str, List<String> list, Map<String, String> map, SimpleCallback simpleCallback) {
MQMessage mQMessage = new MQMessage("text");
mQMessage.setContent(str);
ArrayList arrayList = new ArrayList();
arrayList.add(mQMessage);
if (list == null || list.size() <= 0) {
a(arrayList, map, simpleCallback);
} else {
a(arrayList, list, map, simpleCallback);
}
}
public void a(String str, final Map<String, Object> map, final Map<String, String> map2, final SimpleCallback simpleCallback) {
MQClient a2 = this.f.a(str);
if (a2 == null && (a2 = this.f.b(str)) == null) {
a(str, new OnInitCallback() {
@Override
public void onFailure(int i, String str2) {
SimpleCallback simpleCallback2 = simpleCallback;
if (simpleCallback2 != null) {
simpleCallback2.onFailure(i, str2);
}
}
@Override
public void onSuccess(String str2) {
d.this.b(str2, map, map2, simpleCallback);
}
});
} else {
b(a2.getTrackId(), map, map2, simpleCallback);
}
}
public void a(Map<String, Object> map) {
if (map.containsKey(AbsoluteConst.XML_CHANNEL)) {
String str = (String) map.get(AbsoluteConst.XML_CHANNEL);
if (TextUtils.equals(str, MQMessage.TYPE_SDK) || TextUtils.equals(str, "dcloud") || TextUtils.equals(str, "apicloud") || TextUtils.equals(str, "flutter") || TextUtils.equals(str, "appcan")) {
this.j.b(str);
}
}
}
public void a(Map<String, String> map, final OnClientInfoCallback onClientInfoCallback) {
try {
final String jSONObject = com.meiqia.core.a.c.a((Map<?, ?>) map).toString();
if (jSONObject.equals(c.h(a)) && onClientInfoCallback != null) {
onClientInfoCallback.onSuccess();
return;
}
Map<String, Object> b2 = b(map);
String trackId = a.getTrackId();
String enterpriseId = a.getEnterpriseId();
JSONObject a2 = com.meiqia.core.a.c.a((Map<?, ?>) b2);
HashMap hashMap = new HashMap();
hashMap.put(TemplateDom.KEY_ATTRS, a2);
hashMap.put("track_id", trackId);
hashMap.put("ent_id", enterpriseId);
hashMap.put("visit_id", a.getVisitId());
if (map.containsKey("avatar")) {
c.e(a, map.get("avatar"));
}
this.j.a(hashMap, new OnClientInfoCallback() {
@Override
public void onFailure(int i, String str) {
OnClientInfoCallback onClientInfoCallback2 = onClientInfoCallback;
if (onClientInfoCallback2 != null) {
onClientInfoCallback2.onFailure(i, str);
}
}
@Override
public void onSuccess() {
d.this.a(new Runnable() {
@Override
public void run() {
d.c.c(d.a, jSONObject);
if (onClientInfoCallback != null) {
onClientInfoCallback.onSuccess();
}
}
});
}
});
} catch (Exception unused) {
if (onClientInfoCallback != null) {
onClientInfoCallback.onFailure(ErrorCode.PARAMETER_ERROR, "parameter error");
}
}
}
public void a(JSONObject jSONObject, long j) {
HashMap hashMap = new HashMap();
long a2 = c.a(a);
hashMap.put("body", jSONObject);
hashMap.put("ent_id", Long.valueOf(Long.parseLong(a.getEnterpriseId())));
hashMap.put("track_id", a.getTrackId());
if (a2 != -1) {
hashMap.put("conv_id", Long.valueOf(a2));
}
hashMap.put("message_id", Long.valueOf(j));
this.j.b(hashMap, new SuccessCallback());
}
public void a(JSONObject jSONObject, SuccessCallback successCallback) {
long a2 = c.a(a);
HashMap hashMap = new HashMap();
hashMap.put("track_id", a.getTrackId());
hashMap.put("visit_id", a.getVisitId());
hashMap.put("card_type", "client_card");
hashMap.put(TemplateDom.KEY_ATTRS, jSONObject);
if (a2 != -1) {
hashMap.put("conv_id", Long.valueOf(a2));
}
this.j.a(hashMap, successCallback);
}
public void a(boolean z) {
com.meiqia.core.a.i iVar;
MQClient mQClient;
String str;
this.o = z;
if (z) {
MQAgent mQAgent = b;
if (mQAgent == null || !mQAgent.isRobot()) {
return;
}
iVar = c;
mQClient = a;
str = b.getId();
} else {
iVar = c;
mQClient = a;
str = null;
}
iVar.a(mQClient, str);
}
public void a(final boolean z, final MQMessage mQMessage, final Map<String, String> map, final OnMessageSendCallback onMessageSendCallback) {
final h.f fVar = new h.f() {
@Override
public void a(String str, long j) {
d.c.c(d.a, j.a(str));
d.c.d(d.a, j);
long a2 = j.a(str);
long id = mQMessage.getId();
mQMessage.setCreated_on(a2);
d.a(mQMessage, System.currentTimeMillis());
mQMessage.setStatus("arrived");
mQMessage.setType(MQMessage.TYPE_SDK);
if (z) {
d.this.f.a(mQMessage, id);
}
d.this.a(new Runnable() {
@Override
public void run() {
onMessageSendCallback.onSuccess(mQMessage, ErrorCode.NO_AGENT_ONLINE);
}
});
}
@Override
public void onFailure(int i, String str) {
mQMessage.setStatus("failed");
if (z) {
d.this.f.a(mQMessage);
}
onMessageSendCallback.onFailure(mQMessage, i, str);
}
};
long f = c.f(a);
if (f == -1) {
a(mQMessage, map, fVar);
} else {
a(f, new h.i() {
@Override
public void a() {
d.this.b(mQMessage, map, fVar);
}
@Override
public void b() {
d.this.a(mQMessage, map, fVar);
}
@Override
public void onFailure(int i, String str) {
fVar.onFailure(i, str);
}
});
}
}
public void a(final boolean z, final Map<String, String> map, final OnClientInfoCallback onClientInfoCallback) {
try {
if (map.containsKey("avatar")) {
c.e(a, map.get("avatar"));
}
if (TextUtils.isEmpty(c.h(a))) {
a(map, onClientInfoCallback);
return;
}
if (z) {
if (com.meiqia.core.a.c.a((Map<?, ?>) map).toString().equals(c.i(a)) && onClientInfoCallback != null) {
onClientInfoCallback.onSuccess();
return;
}
}
Map<String, Object> b2 = b(map);
String trackId = a.getTrackId();
String enterpriseId = a.getEnterpriseId();
JSONObject a2 = com.meiqia.core.a.c.a((Map<?, ?>) b2);
HashMap hashMap = new HashMap();
hashMap.put(TemplateDom.KEY_ATTRS, a2);
hashMap.put("track_id", trackId);
hashMap.put("ent_id", enterpriseId);
hashMap.put("visit_id", a.getVisitId());
hashMap.put("overwrite", true);
this.j.a(hashMap, new OnClientInfoCallback() {
@Override
public void onFailure(int i, String str) {
OnClientInfoCallback onClientInfoCallback2 = onClientInfoCallback;
if (onClientInfoCallback2 != null) {
onClientInfoCallback2.onFailure(i, str);
}
}
@Override
public void onSuccess() {
if (z) {
d.c.d(d.a, com.meiqia.core.a.c.a((Map<?, ?>) map).toString());
}
if (onClientInfoCallback != null) {
d.this.a(new Runnable() {
@Override
public void run() {
onClientInfoCallback.onSuccess();
}
});
}
}
});
} catch (Exception unused) {
if (onClientInfoCallback != null) {
onClientInfoCallback.onFailure(ErrorCode.PARAMETER_ERROR, "parameter error");
}
}
}
public void b() {
this.f.a();
}
public void b(final Context context) {
this.j.a(a.getTrackId(), a.getEnterpriseId(), new OnValueCallback<List<MQNotificationMessage>>() {
@Override
public void onSuccess(List<MQNotificationMessage> list) {
if (list.size() != 0) {
g.a().a(context, list.get(0), false);
}
}
@Override
public void onFailure(int i, String str) {
}
});
}
public void b(String str) {
this.j.a(str);
}
public void b(String str, final OnRegisterDeviceTokenCallback onRegisterDeviceTokenCallback) {
long o = c.o(a);
long currentTimeMillis = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance(Locale.getDefault());
calendar.setTimeInMillis(o);
calendar.add(5, 2);
if (currentTimeMillis < calendar.getTimeInMillis()) {
onRegisterDeviceTokenCallback.onSuccess();
} else {
this.j.b(str, new OnRegisterDeviceTokenCallback() {
@Override
public void onFailure(int i, String str2) {
OnRegisterDeviceTokenCallback onRegisterDeviceTokenCallback2 = onRegisterDeviceTokenCallback;
if (onRegisterDeviceTokenCallback2 != null) {
onRegisterDeviceTokenCallback2.onFailure(i, str2);
}
}
@Override
public void onSuccess() {
d.this.a(new Runnable() {
@Override
public void run() {
d.c.g(d.a, System.currentTimeMillis());
if (onRegisterDeviceTokenCallback != null) {
onRegisterDeviceTokenCallback.onSuccess();
}
}
});
}
});
}
}
public void b(String str, Map<String, Object> map, Map<String, String> map2, final SimpleCallback simpleCallback) {
this.j.a(str, map, map2, new SimpleCallback() {
@Override
public void onFailure(int i, String str2) {
SimpleCallback simpleCallback2 = simpleCallback;
if (simpleCallback2 != null) {
simpleCallback2.onFailure(i, str2);
}
}
@Override
public void onSuccess() {
d.this.h().survey.setHas_submitted_form(true);
d.c.a(d.a, "has_submitted_form", true);
if (simpleCallback != null) {
d.this.a(new Runnable() {
@Override
public void run() {
simpleCallback.onSuccess();
}
});
}
}
});
}
public void b(boolean z) {
this.p = z;
}
public String c() {
return a.getTrackId();
}
public void c(String str) {
this.n = str;
}
public MQClient d() {
String b2 = c.b();
if (TextUtils.isEmpty(b2)) {
return null;
}
return this.f.a(b2);
}
public MQAgent e() {
return b;
}
public boolean f() {
return this.o;
}
public boolean g() {
return MeiQiaService.e;
}
public MQEnterpriseConfig h() {
if (this.i == null) {
this.i = new MQEnterpriseConfig();
String q = c.q(a);
if (!TextUtils.isEmpty(q)) {
try {
com.meiqia.core.a.c.a(this.i, new JSONObject(q), c, a);
} catch (Exception unused) {
}
}
}
return this.i;
}
public MQInquireForm i() {
String form_def = h().form.getForm_def();
MQInquireForm mQInquireForm = new MQInquireForm();
try {
JSONObject jSONObject = new JSONObject(form_def);
mQInquireForm.setVersion(jSONObject.optInt("version"));
mQInquireForm.setCaptcha(jSONObject.optBoolean(MQInquireForm.KEY_CAPTCHA));
mQInquireForm.setInputs(jSONObject.optJSONObject(MQInquireForm.KEY_INPUTS));
mQInquireForm.setMenus(jSONObject.optJSONObject(MQInquireForm.KEY_MENUS));
mQInquireForm.setSubmitForm(h().survey.isHas_submitted_form());
mQInquireForm.setContent(h().form.getContent());
} catch (Exception e) {
e.printStackTrace();
}
return mQInquireForm;
}
public void j() {
h.a().c();
}
public void k() {
a((MQAgent) null);
this.i = null;
}
public MQClient l() {
com.meiqia.core.a.i iVar = new com.meiqia.core.a.i(this.g);
String c2 = iVar.c();
String a2 = iVar.a();
iVar.b(c2);
MQClient a3 = k.a(c2, iVar);
if (a3 != null) {
a3.setAppKey(a2);
this.f.a(a3);
}
return a3;
}
}