package com.tencent.mm.plugin.appbrand.jsapi.contact;

import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.plugin.appbrand.config.AppBrandSysConfigWC;
import com.tencent.mm.plugin.appbrand.ipc.AppBrandMainProcessService;
import com.tencent.mm.plugin.appbrand.jsapi.a;
import com.tencent.mm.plugin.appbrand.jsapi.c;
import com.tencent.mm.plugin.appbrand.page.u;
import com.tencent.mm.plugin.appbrand.q;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import org.json.JSONObject;

public final class e extends a {
    public static final int CTRL_INDEX = 550;
    public static final String NAME = "privateEnterContact";
    String hID;
    String hIE;
    String hIF;
    String hIG;
    String hIH;
    private String sessionFrom;

    public final void a(c cVar, JSONObject jSONObject, int i) {
        AppMethodBeat.i(131022);
        if (cVar instanceof q) {
            q qVar = (q) cVar;
            u currentPageView = qVar.getCurrentPageView();
            if (currentPageView == null) {
                ab.i("MicroMsg.JsApiPrivateEnterContact", "privateEnterContact enterChatting fail, pageView is null");
                qVar.M(i, j("fail:current page do not exist", null));
                AppMethodBeat.o(131022);
                return;
            }
            a(currentPageView, qVar, jSONObject, i);
            AppMethodBeat.o(131022);
        } else if (cVar instanceof u) {
            a((u) cVar, cVar, jSONObject, i);
            AppMethodBeat.o(131022);
        } else {
            ab.w("MicroMsg.JsApiPrivateEnterContact", "privateEnterContact not support");
            AppMethodBeat.o(131022);
        }
    }

    private void a(u uVar, c cVar, JSONObject jSONObject, int i) {
        AppMethodBeat.i(131023);
        a(uVar, jSONObject, new 1(this, cVar, i));
        AppMethodBeat.o(131023);
    }

    private void a(u uVar, JSONObject jSONObject, a aVar) {
        AppMethodBeat.i(131024);
        if (jSONObject == null) {
            ab.e("MicroMsg.JsApiPrivateEnterContact", "privateEnterContact enterChatting fail, data is null");
            aVar.a(false, "fail:invalid data", null);
            AppMethodBeat.o(131024);
        } else if (((AppBrandSysConfigWC) uVar.getRuntime().ye()) == null) {
            ab.e("MicroMsg.JsApiPrivateEnterContact", "privateEnterContact enterChatting fail, config is null");
            aVar.a(false, "fail:config is null", null);
            AppMethodBeat.o(131024);
        } else {
            this.sessionFrom = jSONObject.optString("sessionFrom");
            if (this.sessionFrom.length() > 1024) {
                this.sessionFrom = this.sessionFrom.substring(0, 1024);
                ab.i("MicroMsg.JsApiPrivateEnterContact", "privateEnterContact sessionFrom length is large than 1024!");
            }
            this.hID = jSONObject.optString("appId");
            if (!bo.isNullOrNil(this.hID)) {
                this.hIE = jSONObject.optString("userName");
                this.hIF = jSONObject.optString("title");
                this.hIG = jSONObject.optString("subTitle");
                this.hIH = jSONObject.optString("headimgUrl");
                a(uVar, aVar);
            }
            AppMethodBeat.o(131024);
        }
    }

    private void a(u uVar, a aVar) {
        AppMethodBeat.i(131025);
        JsApiChattingTask jsApiChattingTask = new JsApiChattingTask();
        jsApiChattingTask.username = this.hIE;
        jsApiChattingTask.sessionFrom = this.sessionFrom;
        jsApiChattingTask.hww = new 2(this, jsApiChattingTask, uVar, aVar);
        jsApiChattingTask.aBV();
        AppBrandMainProcessService.a(jsApiChattingTask);
        AppMethodBeat.o(131025);
    }
}
