var registrationId = deviceObjectList[i].registrationId || deviceObjectList[i].sessions.registrationId;
This line of code assumes that for any device object, either the first registrationId is truthy /or/ sessions is defined, which might not be true.
I was seeing an exception on the above line for the first message sent to a new contact's secondary device. The server returned 0 (falsey) for the secondary device's registrationId and the sessions attribute was undefined because we had no sessions yet. The 0 registration id happens to be a server bug, but we shouldn't crash because of it.
The best you can really do here is just throw a nicer error than an undefined object error. The server gave us a crap registrationId which means we cannot possibly send the message.
On https://github.com/WhisperSystems/TextSecure-Browser/blob/master/libtextsecure/sendmessage.js#L72
This line of code assumes that for any device object, either the first
registrationId
is truthy /or/sessions
is defined, which might not be true.I was seeing an exception on the above line for the first message sent to a new contact's secondary device. The server returned 0 (falsey) for the secondary device's registrationId and the
sessions
attribute was undefined because we had no sessions yet. The 0 registration id happens to be a server bug, but we shouldn't crash because of it.