crisp-sdk-android
crisp-sdk-android copied to clipboard
Incorrect user name
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.
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.
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.
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)
.
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.
Hi @Doc1faux Can we use onSessionLoaded(String sessionIdentifier)? I am needing it.
@Doc1faux I am having to setInterval every second until I can get the session.