Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect user name #157

Open
FrantisekGazo opened this issue Jun 26, 2023 · 6 comments
Open

Incorrect user name #157

FrantisekGazo opened this issue Jun 26, 2023 · 6 comments

Comments

@FrantisekGazo
Copy link

we call both Crisp.setTokenID(...) and Crisp.setUserNickname() but sometimes the nickname gets ignored.

when I look into the setUserNickname() code i see just an obfuscated code:

    public static void setUserNickname(@NonNull String var0) {
        if (!im.crisp.client.internal.f.a.l()) {
            m = var0;
        } else {
            if (im.crisp.client.internal.f.b.l().c(var0)) {
                m = null;
            }

        }
    }

Can you please clarify in what circumstances it's ignored (set to null) ? That could help me explain our issues and fix them cause currently I'm not able to reliably replicate this behavior - it happens only sometimes.

@Doc1faux
Copy link
Collaborator

Hi @FrantisekGazo and thank you for your feedback.

The m var you see here is just a buffer var (like many for user/session public APIs) allowing you to call them even if a session is not currently ongoing (chatbox not shown). They will be dispatched on the session loaded event (see Web SDK documentation) upon the socket connection so the chatbox showing and cleared if successfully sent (that's the m = null; code you see as I reuse public APIs too).
However, these buffer vars are cleared also if any of the Crisp.resetChatSession or Crisp.configure (with a different websiteID than the current) methods are called before the session is loaded and as these buffers vars are on memory only, if the app has been killed either by the user or the system.

@FrantisekGazo
Copy link
Author

so it may be caused by calling Crisp.setUserNickname() too soon after Crisp.configure()/resetChatSession() or something similar ?

there's no callback to know when exactly configure() call was completed and those buffer vars cleared.

@Doc1faux
Copy link
Collaborator

Doc1faux commented Jul 4, 2023

Sorry for not answering you sooner...

Public API works synchronously so if you call Crisp.configure(), it is completed when it returns, unless a session is ongoing, i.e. ChatActivity running, socket connected and session loaded. In this case, it'll be performed when the session is closed.

So if you call Crisp.setUserNickname() right after Crisp.configure(), it will be honored unless you call Crisp.resetChatSession() or Crisp.configure() with a different websiteID before launching the ChatActivity. In this case, the user nickname will be reset and not sent.

For the moment, public API is not thread-safe, i.e. is running commands in the caller thread. Maybe that's the issue in your case? Maybe you're calling Crisp.configure() and Crisp.setUserNickname() not sequentially and/or in different threads?

Anyway, I'm working on the next release.
It will be thread-safe (using its own threads internally independently of caller thread).
I've already implemented the new public API String Crisp.getSessionIdentifier(Context) (see #125) which combines corresponding $crisp.get("session:identifier") and $crisp.is("session:ongoing") Web SDK methods, i.e. returning null if session is not ongoing, the session identifier otherwise.

Maybe we could add a CrispListener as I already offered in #119 for starting chat errors, adding some other callbacks like onConfigured(String websiteId) as asked in #138 with a corresponding getter method boolean isConfigured(String websiteId) and maybe a Web SDK equivalent to onSessionLoaded(String sessionIdentifier) even a onSessionClosed(String sessionIdentifier).

@FrantisekGazo
Copy link
Author

thank you for the answer.

the used thread should be the same for Crisp.configure() and Crisp.setUserNickname(), so I don't think that's the issue here.

it's hard to replicate and doesn't happen often, so I'll wait for your next release.

@Doc1faux Doc1faux self-assigned this Aug 21, 2023
@baronha
Copy link

baronha commented Jan 25, 2024

Hi @Doc1faux
Can we use onSessionLoaded(String sessionIdentifier)? I am needing it.

@baronha
Copy link

baronha commented Jan 25, 2024

@Doc1faux
I am having to setInterval every second until I can get the session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants