Cleanup normalizeGroupCallTimestamp non-number handling
This commit is contained in:
parent
168397d8ef
commit
c70a8955f9
2 changed files with 5 additions and 69 deletions
|
@ -2,31 +2,12 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
/**
|
||||
* Normalizes group call timestamps (`addedTime` and `speakerTime`) into numbers. We
|
||||
* expect RingRTC to send a string, but it sends a malformed number as of this writing,
|
||||
* RingRTC 2.8.3.
|
||||
*
|
||||
* We could probably safely do `Number(fromRingRtc)` and be done, but this is extra-
|
||||
* careful.
|
||||
* Normalizes RingRTC group call timestamps (`addedTime` and `speakerTime`) into numbers.
|
||||
*/
|
||||
export function normalizeGroupCallTimestamp(
|
||||
fromRingRtc: unknown
|
||||
fromRingRtc: string
|
||||
): undefined | number {
|
||||
let asNumber: number;
|
||||
|
||||
switch (typeof fromRingRtc) {
|
||||
case 'number':
|
||||
asNumber = fromRingRtc;
|
||||
break;
|
||||
case 'string':
|
||||
asNumber = parseInt(fromRingRtc.slice(0, 15), 10);
|
||||
break;
|
||||
case 'bigint':
|
||||
asNumber = Number(fromRingRtc);
|
||||
break;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
const asNumber = parseInt(fromRingRtc.slice(0, 15), 10);
|
||||
|
||||
if (Number.isNaN(asNumber) || asNumber <= 0) {
|
||||
return undefined;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue