@@ -143,30 +143,27 @@ export const extractDeviceJids = (
143143
144144 for ( const userResult of result ) {
145145 const { devices, id } = userResult as { devices : ParsedDeviceInfo ; id : string }
146- let { user, domainType, server } = jidDecode ( id ) !
146+ const decoded = jidDecode ( id ) ! ,
147+ { user, server } = decoded
148+ let { domainType } = decoded
147149 const deviceList = devices ?. deviceList as DeviceListData [ ]
148- if ( Array . isArray ( deviceList ) ) {
149- for ( const { id : device , keyIndex, isHosted } of deviceList ) {
150- if (
151- ( ! excludeZeroDevices || device !== 0 ) && // if zero devices are not-excluded, or device is non zero
152- ( ( myUser !== user && myLid !== user ) || myDevice !== device ) && // either different user or if me user, not this device
153- ( device === 0 || ! ! keyIndex ) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
154- ) {
155- if ( isHosted ) {
156- if ( domainType === WAJIDDomains . LID ) {
157- domainType = WAJIDDomains . HOSTED_LID
158- } else {
159- domainType = WAJIDDomains . HOSTED
160- }
161- }
162-
163- extracted . push ( {
164- user,
165- device,
166- domainType,
167- server : getServerFromDomainType ( server , domainType )
168- } )
150+ if ( ! Array . isArray ( deviceList ) ) continue
151+ for ( const { id : device , keyIndex, isHosted } of deviceList ) {
152+ if (
153+ ( ! excludeZeroDevices || device !== 0 ) && // if zero devices are not-excluded, or device is non zero
154+ ( ( myUser !== user && myLid !== user ) || myDevice !== device ) && // either different user or if me user, not this device
155+ ( device === 0 || ! ! keyIndex ) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
156+ ) {
157+ if ( isHosted ) {
158+ domainType = domainType === WAJIDDomains . LID ? WAJIDDomains . HOSTED_LID : WAJIDDomains . HOSTED
169159 }
160+
161+ extracted . push ( {
162+ user,
163+ device,
164+ domainType,
165+ server : getServerFromDomainType ( server , domainType )
166+ } )
170167 }
171168 }
172169 }
0 commit comments