Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
54c90e14
Commit
54c90e14
authored
Sep 10, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace lodash methods with built-ins
parent
54b3fc6d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
46 deletions
+37
-46
src/converse-chatview.js
src/converse-chatview.js
+4
-8
src/converse-omemo.js
src/converse-omemo.js
+31
-36
src/converse-register.js
src/converse-register.js
+1
-1
src/converse-roomslist.js
src/converse-roomslist.js
+1
-1
No files found.
src/converse-chatview.js
View file @
54c90e14
...
...
@@ -1310,10 +1310,8 @@ converse.plugins.add('converse-chatview', {
});
});
_converse
.
api
.
listen
.
on
(
'
connected
'
,
()
=>
{
// Advertise that we support XEP-0382 Message Spoilers
_converse
.
api
.
disco
.
own
.
features
.
add
(
Strophe
.
NS
.
SPOILER
);
});
// Advertise that we support XEP-0382 Message Spoilers
_converse
.
api
.
listen
.
on
(
'
connected
'
,
()
=>
_converse
.
api
.
disco
.
own
.
features
.
add
(
Strophe
.
NS
.
SPOILER
));
/************************ BEGIN API ************************/
Object
.
assign
(
_converse
.
api
,
{
...
...
@@ -1327,15 +1325,13 @@ converse.plugins.add('converse-chatview', {
'
chatviews
'
:
{
/**
* Get the view of an already open chat.
*
* @method _converse.api.chatviews.get
* @param { Array.string | string } jids
* @returns {ChatBoxView} A [Backbone.View](http://backbonejs.org/#View) instance.
* The chat should already be open, otherwise `undefined` will be returned.
*
* @example
* // To return a single view, provide the JID of the contact:
* _converse.api.chatviews.get('buddy@example.com')
*
* @example
* // To return an array of views, provide an array of JIDs:
* _converse.api.chatviews.get(['buddy1@example.com', 'buddy2@example.com'])
...
...
@@ -1351,7 +1347,7 @@ converse.plugins.add('converse-chatview', {
if
(
_
.
isString
(
jids
))
{
return
_converse
.
chatboxviews
.
get
(
jids
);
}
return
_
.
map
(
jids
,
(
jid
)
=>
_converse
.
chatboxviews
.
get
(
jids
));
return
jids
.
map
(
jid
=>
_converse
.
chatboxviews
.
get
(
jids
));
}
}
});
...
...
src/converse-omemo.js
View file @
54c90e14
...
...
@@ -48,14 +48,12 @@ function parseBundle (bundle_el) {
signed_prekey_signature_el
=
bundle_el
.
querySelector
(
'
signedPreKeySignature
'
),
identity_key_el
=
bundle_el
.
querySelector
(
'
identityKey
'
);
const
prekeys
=
_
.
map
(
sizzle
(
`prekeys > preKeyPublic`
,
bundle_el
),
(
el
)
=>
{
return
{
'
id
'
:
parseInt
(
el
.
getAttribute
(
'
preKeyId
'
),
10
),
'
key
'
:
el
.
textContent
}
});
const
prekeys
=
sizzle
(
`prekeys > preKeyPublic`
,
bundle_el
)
.
map
(
el
=>
({
'
id
'
:
parseInt
(
el
.
getAttribute
(
'
preKeyId
'
),
10
),
'
key
'
:
el
.
textContent
}));
return
{
'
identity_key
'
:
bundle_el
.
querySelector
(
'
identityKey
'
).
textContent
.
trim
(),
'
signed_prekey
'
:
{
...
...
@@ -122,8 +120,7 @@ converse.plugins.add('converse-omemo', {
ev
.
preventDefault
();
ev
.
stopPropagation
();
ev
.
target
.
querySelector
(
'
.select-all
'
).
checked
=
false
const
checkboxes
=
ev
.
target
.
querySelectorAll
(
'
.fingerprint-removal-item input[type="checkbox"]:checked
'
),
device_ids
=
_
.
map
(
checkboxes
,
'
value
'
);
const
device_ids
=
sizzle
(
'
.fingerprint-removal-item input[type="checkbox"]:checked
'
,
ev
.
target
).
map
(
c
=>
c
.
value
);
this
.
devicelist
.
removeOwnDevices
(
device_ids
)
.
then
(
this
.
modal
.
hide
)
.
catch
(
err
=>
{
...
...
@@ -848,19 +845,19 @@ converse.plugins.add('converse-omemo', {
},
async
generateMissingPreKeys
()
{
const
current_keys
=
this
.
getPreKeys
(),
missing_keys
=
_
.
difference
(
_
.
invokeMap
(
_
.
range
(
0
,
_converse
.
NUM_PREKEYS
),
Number
.
prototype
.
toString
),
Object
.
keys
(
current_keys
));
const
missing_keys
=
_
.
difference
(
_
.
invokeMap
(
_
.
range
(
0
,
_converse
.
NUM_PREKEYS
),
Number
.
prototype
.
toString
),
Object
.
keys
(
this
.
getPreKeys
())
);
if
(
missing_keys
.
length
<
1
)
{
_converse
.
log
(
"
No missing prekeys to generate for our own device
"
,
Strophe
.
LogLevel
.
WARN
);
return
Promise
.
resolve
();
}
const
keys
=
await
Promise
.
all
(
_
.
map
(
missing_keys
,
id
=>
libsignal
.
KeyHelper
.
generatePreKey
(
parseInt
(
id
,
10
))));
_
.
forEach
(
keys
,
k
=>
this
.
storePreKey
(
k
.
keyId
,
k
.
keyPair
));
const
marshalled_keys
=
_
.
map
(
this
.
getPreKeys
(),
k
=>
({
'
id
'
:
k
.
keyId
,
'
key
'
:
u
.
arrayBufferToBase64
(
k
.
pubKey
)})),
devicelist
=
_converse
.
devicelists
.
get
(
_converse
.
bare_jid
),
device
=
devicelist
.
devices
.
get
(
this
.
get
(
'
device_id
'
));
const
keys
=
await
Promise
.
all
(
missing_keys
.
map
(
id
=>
libsignal
.
KeyHelper
.
generatePreKey
(
parseInt
(
id
,
10
))));
keys
.
forEach
(
k
=>
this
.
storePreKey
(
k
.
keyId
,
k
.
keyPair
));
const
marshalled_keys
=
Object
.
keys
(
this
.
getPreKeys
()).
map
(
k
=>
({
'
id
'
:
k
.
keyId
,
'
key
'
:
u
.
arrayBufferToBase64
(
k
.
pubKey
)}));
const
devicelist
=
_converse
.
devicelists
.
get
(
_converse
.
bare_jid
);
const
device
=
devicelist
.
devices
.
get
(
this
.
get
(
'
device_id
'
));
const
bundle
=
await
device
.
getBundle
();
device
.
save
(
'
bundle
'
,
Object
.
assign
(
bundle
,
{
'
prekeys
'
:
marshalled_keys
}));
},
...
...
@@ -895,11 +892,11 @@ converse.plugins.add('converse-omemo', {
'
public_key
'
:
u
.
arrayBufferToBase64
(
signed_prekey
.
keyPair
.
privKey
),
'
signature
'
:
u
.
arrayBufferToBase64
(
signed_prekey
.
signature
)
}
const
keys
=
await
Promise
.
all
(
_
.
map
(
_
.
range
(
0
,
_converse
.
NUM_PREKEYS
),
id
=>
libsignal
.
KeyHelper
.
generatePreKey
(
id
)));
_
.
forEach
(
keys
,
k
=>
_converse
.
omemo_store
.
storePreKey
(
k
.
keyId
,
k
.
keyPair
));
const
devicelist
=
_converse
.
devicelists
.
get
(
_converse
.
bare_jid
)
,
device
=
devicelist
.
devices
.
create
({
'
id
'
:
bundle
.
device_id
,
'
jid
'
:
_converse
.
bare_jid
}),
marshalled_keys
=
_
.
map
(
keys
,
k
=>
({
'
id
'
:
k
.
keyId
,
'
key
'
:
u
.
arrayBufferToBase64
(
k
.
keyPair
.
pubKey
)}));
const
keys
=
await
Promise
.
all
(
_
.
range
(
0
,
_converse
.
NUM_PREKEYS
).
map
(
id
=>
libsignal
.
KeyHelper
.
generatePreKey
(
id
)));
keys
.
forEach
(
k
=>
_converse
.
omemo_store
.
storePreKey
(
k
.
keyId
,
k
.
keyPair
));
const
devicelist
=
_converse
.
devicelists
.
get
(
_converse
.
bare_jid
)
;
const
device
=
devicelist
.
devices
.
create
({
'
id
'
:
bundle
.
device_id
,
'
jid
'
:
_converse
.
bare_jid
});
const
marshalled_keys
=
keys
.
map
(
k
=>
({
'
id
'
:
k
.
keyId
,
'
key
'
:
u
.
arrayBufferToBase64
(
k
.
keyPair
.
pubKey
)}));
bundle
[
'
prekeys
'
]
=
marshalled_keys
;
device
.
save
(
'
bundle
'
,
bundle
);
},
...
...
@@ -1061,7 +1058,7 @@ converse.plugins.add('converse-omemo', {
_converse
.
log
(
e
,
Strophe
.
LogLevel
.
ERROR
);
return
[];
}
const
device_ids
=
_
.
map
(
sizzle
(
`list[xmlns="
${
Strophe
.
NS
.
OMEMO
}
"] device`
,
iq
),
dev
=>
dev
.
getAttribute
(
'
id
'
));
const
device_ids
=
sizzle
(
`list[xmlns="
${
Strophe
.
NS
.
OMEMO
}
"] device`
,
iq
).
map
(
dev
=>
dev
.
getAttribute
(
'
id
'
));
_
.
forEach
(
device_ids
,
id
=>
this
.
devices
.
create
({
'
id
'
:
id
,
'
jid
'
:
this
.
get
(
'
jid
'
)}));
return
device_ids
;
},
...
...
@@ -1133,22 +1130,20 @@ converse.plugins.add('converse-omemo', {
if
(
!
items_el
)
{
return
;
}
const
device_ids
=
_
.
map
(
sizzle
(
`item list[xmlns="
${
Strophe
.
NS
.
OMEMO
}
"] device`
,
items_el
),
(
device
)
=>
device
.
getAttribute
(
'
id
'
)
);
const
jid
=
stanza
.
getAttribute
(
'
from
'
),
devicelist
=
_converse
.
devicelists
.
getDeviceList
(
jid
),
devices
=
devicelist
.
devices
,
removed_ids
=
_
.
difference
(
devices
.
pluck
(
'
id
'
),
device_ids
);
_
.
forEach
(
removed_ids
,
(
id
)
=>
{
const
device_selector
=
`item list[xmlns="
${
Strophe
.
NS
.
OMEMO
}
"] device`
;
const
device_ids
=
sizzle
(
device_selector
,
items_el
).
map
(
d
=>
d
.
getAttribute
(
'
id
'
));
const
jid
=
stanza
.
getAttribute
(
'
from
'
);
const
devicelist
=
_converse
.
devicelists
.
getDeviceList
(
jid
);
const
devices
=
devicelist
.
devices
;
const
removed_ids
=
_
.
difference
(
devices
.
pluck
(
'
id
'
),
device_ids
);
removed_ids
.
forEach
(
id
=>
{
if
(
jid
===
_converse
.
bare_jid
&&
id
===
_converse
.
omemo_store
.
get
(
'
device_id
'
))
{
return
// We don't set the current device as inactive
}
devices
.
get
(
id
).
save
(
'
active
'
,
false
);
});
_
.
forEach
(
device_ids
,
(
device_id
)
=>
{
device_ids
.
forEach
(
device_id
=>
{
const
device
=
devices
.
get
(
device_id
);
if
(
device
)
{
device
.
save
(
'
active
'
,
true
);
...
...
src/converse-register.js
View file @
54c90e14
...
...
@@ -626,7 +626,7 @@ converse.plugins.add('converse-register', {
return
;
}
else
if
(
field
.
tagName
.
toLowerCase
()
===
'
x
'
)
{
if
(
field
.
getAttribute
(
'
xmlns
'
)
===
'
jabber:x:oob
'
)
{
this
.
urls
.
concat
(
_
.
map
(
field
.
querySelectorAll
(
'
url
'
),
'
textContent
'
));
this
.
urls
.
concat
(
sizzle
(
'
url
'
,
field
).
map
(
u
=>
u
.
textContent
));
}
return
;
}
...
...
src/converse-roomslist.js
View file @
54c90e14
...
...
@@ -66,7 +66,7 @@ converse.plugins.add('converse-roomslist', {
_converse
.
chatboxes
.
on
(
'
change:num_unread
'
,
this
.
onChatBoxChanged
,
this
);
_converse
.
chatboxes
.
on
(
'
change:num_unread_general
'
,
this
.
onChatBoxChanged
,
this
);
_converse
.
chatboxes
.
on
(
'
remove
'
,
this
.
onChatBoxRemoved
,
this
);
this
.
reset
(
_
.
map
(
_converse
.
chatboxes
.
where
({
'
type
'
:
_converse
.
CHATROOMS_TYPE
}),
'
attributes
'
));
this
.
reset
(
_
converse
.
chatboxes
.
where
({
'
type
'
:
_converse
.
CHATROOMS_TYPE
}).
map
(
cb
=>
cb
.
attributes
));
},
onChatBoxAdded
(
item
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment