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
0895abf3
Commit
0895abf3
authored
Sep 26, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chatboxes: Replace lodash methods and only import what's necessary
parent
44e5b4c9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
20 deletions
+21
-20
src/headless/converse-chatboxes.js
src/headless/converse-chatboxes.js
+21
-20
No files found.
src/headless/converse-chatboxes.js
View file @
0895abf3
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
*/
*/
import
"
./converse-emoji
"
;
import
"
./converse-emoji
"
;
import
"
./utils/form
"
;
import
"
./utils/form
"
;
import
{
get
,
isObject
,
isString
,
propertyOf
}
from
"
lodash
"
;
import
BrowserStorage
from
"
backbone.browserStorage
"
;
import
BrowserStorage
from
"
backbone.browserStorage
"
;
import
converse
from
"
./converse-core
"
;
import
converse
from
"
./converse-core
"
;
import
filesize
from
"
filesize
"
;
import
filesize
from
"
filesize
"
;
...
@@ -280,7 +281,7 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -280,7 +281,7 @@ converse.plugins.add('converse-chatboxes', {
return
{
return
{
'
bookmarked
'
:
false
,
'
bookmarked
'
:
false
,
'
chat_state
'
:
undefined
,
'
chat_state
'
:
undefined
,
'
hidden
'
:
_
.
includes
([
'
mobile
'
,
'
fullscreen
'
],
_converse
.
view_mode
),
'
hidden
'
:
[
'
mobile
'
,
'
fullscreen
'
].
includes
(
_converse
.
view_mode
),
'
message_type
'
:
'
chat
'
,
'
message_type
'
:
'
chat
'
,
'
nickname
'
:
undefined
,
'
nickname
'
:
undefined
,
'
num_unread
'
:
0
,
'
num_unread
'
:
0
,
...
@@ -353,8 +354,8 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -353,8 +354,8 @@ converse.plugins.add('converse-chatboxes', {
const
resolve
=
this
.
messages
.
fetched
.
resolve
;
const
resolve
=
this
.
messages
.
fetched
.
resolve
;
this
.
messages
.
fetch
({
this
.
messages
.
fetch
({
'
add
'
:
true
,
'
add
'
:
true
,
'
success
'
:
_
.
flow
(
this
.
afterMessagesFetched
.
bind
(
this
),
resolve
)
,
'
success
'
:
()
=>
{
this
.
afterMessagesFetched
();
resolve
()
}
,
'
error
'
:
_
.
flow
(
this
.
afterMessagesFetched
.
bind
(
this
),
resolve
)
'
error
'
:
()
=>
{
this
.
afterMessagesFetched
();
resolve
()
}
});
});
return
this
.
messages
.
fetched
;
return
this
.
messages
.
fetched
;
},
},
...
@@ -405,9 +406,9 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -405,9 +406,9 @@ converse.plugins.add('converse-chatboxes', {
if
(
!
attrs
.
jid
)
{
if
(
!
attrs
.
jid
)
{
return
'
Ignored ChatBox without JID
'
;
return
'
Ignored ChatBox without JID
'
;
}
}
const
room_jids
=
_converse
.
auto_join_rooms
.
map
(
s
=>
_
.
isObject
(
s
)
?
s
.
jid
:
s
);
const
room_jids
=
_converse
.
auto_join_rooms
.
map
(
s
=>
isObject
(
s
)
?
s
.
jid
:
s
);
const
auto_join
=
_converse
.
auto_join_private_chats
.
concat
(
room_jids
);
const
auto_join
=
_converse
.
auto_join_private_chats
.
concat
(
room_jids
);
if
(
_converse
.
singleton
&&
!
_
.
includes
(
auto_join
,
attrs
.
jid
)
&&
!
_converse
.
auto_join_on_invite
)
{
if
(
_converse
.
singleton
&&
!
auto_join
.
includes
(
attrs
.
jid
)
&&
!
_converse
.
auto_join_on_invite
)
{
const
msg
=
`
${
attrs
.
jid
}
is not allowed because singleton is true and it's not being auto_joined`
;
const
msg
=
`
${
attrs
.
jid
}
is not allowed because singleton is true and it's not being auto_joined`
;
_converse
.
log
(
msg
,
Strophe
.
LogLevel
.
WARN
);
_converse
.
log
(
msg
,
Strophe
.
LogLevel
.
WARN
);
return
msg
;
return
msg
;
...
@@ -835,8 +836,8 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -835,8 +836,8 @@ converse.plugins.add('converse-chatboxes', {
return
;
return
;
}
}
const
data
=
item
.
dataforms
.
where
({
'
FORM_TYPE
'
:
{
'
value
'
:
Strophe
.
NS
.
HTTPUPLOAD
,
'
type
'
:
"
hidden
"
}}).
pop
(),
const
data
=
item
.
dataforms
.
where
({
'
FORM_TYPE
'
:
{
'
value
'
:
Strophe
.
NS
.
HTTPUPLOAD
,
'
type
'
:
"
hidden
"
}}).
pop
(),
max_file_size
=
window
.
parseInt
(
_
.
get
(
data
,
'
attributes.max-file-size.value
'
)),
max_file_size
=
window
.
parseInt
(
get
(
data
,
'
attributes.max-file-size.value
'
)),
slot_request_url
=
_
.
get
(
item
,
'
id
'
);
slot_request_url
=
get
(
item
,
'
id
'
);
if
(
!
slot_request_url
)
{
if
(
!
slot_request_url
)
{
this
.
messages
.
create
({
this
.
messages
.
create
({
...
@@ -871,7 +872,7 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -871,7 +872,7 @@ converse.plugins.add('converse-chatboxes', {
},
},
getReferencesFromStanza
(
stanza
)
{
getReferencesFromStanza
(
stanza
)
{
const
text
=
_
.
propertyOf
(
stanza
.
querySelector
(
'
body
'
))(
'
textContent
'
);
const
text
=
propertyOf
(
stanza
.
querySelector
(
'
body
'
))(
'
textContent
'
);
return
sizzle
(
`reference[xmlns="
${
Strophe
.
NS
.
REFERENCE
}
"]`
,
stanza
).
map
(
ref
=>
{
return
sizzle
(
`reference[xmlns="
${
Strophe
.
NS
.
REFERENCE
}
"]`
,
stanza
).
map
(
ref
=>
{
const
begin
=
ref
.
getAttribute
(
'
begin
'
),
const
begin
=
ref
.
getAttribute
(
'
begin
'
),
end
=
ref
.
getAttribute
(
'
end
'
);
end
=
ref
.
getAttribute
(
'
end
'
);
...
@@ -917,7 +918,7 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -917,7 +918,7 @@ converse.plugins.add('converse-chatboxes', {
getErrorMessage
(
stanza
)
{
getErrorMessage
(
stanza
)
{
const
error
=
stanza
.
querySelector
(
'
error
'
);
const
error
=
stanza
.
querySelector
(
'
error
'
);
return
_
.
propertyOf
(
error
.
querySelector
(
'
text
'
))(
'
textContent
'
)
||
return
propertyOf
(
error
.
querySelector
(
'
text
'
))(
'
textContent
'
)
||
__
(
'
Sorry, an error occurred:
'
)
+
'
'
+
error
.
innerHTML
;
__
(
'
Sorry, an error occurred:
'
)
+
'
'
+
error
.
innerHTML
;
},
},
...
@@ -971,8 +972,8 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -971,8 +972,8 @@ converse.plugins.add('converse-chatboxes', {
'
msgid
'
:
msgid
,
'
msgid
'
:
msgid
,
'
replaced_id
'
:
replaced_id
,
'
replaced_id
'
:
replaced_id
,
'
references
'
:
this
.
getReferencesFromStanza
(
stanza
),
'
references
'
:
this
.
getReferencesFromStanza
(
stanza
),
'
subject
'
:
_
.
propertyOf
(
stanza
.
querySelector
(
'
subject
'
))(
'
textContent
'
),
'
subject
'
:
propertyOf
(
stanza
.
querySelector
(
'
subject
'
))(
'
textContent
'
),
'
thread
'
:
_
.
propertyOf
(
stanza
.
querySelector
(
'
thread
'
))(
'
textContent
'
),
'
thread
'
:
propertyOf
(
stanza
.
querySelector
(
'
thread
'
))(
'
textContent
'
),
'
time
'
:
delay
?
dayjs
(
delay
.
getAttribute
(
'
stamp
'
)).
toISOString
()
:
(
new
Date
()).
toISOString
(),
'
time
'
:
delay
?
dayjs
(
delay
.
getAttribute
(
'
stamp
'
)).
toISOString
()
:
(
new
Date
()).
toISOString
(),
'
type
'
:
stanza
.
getAttribute
(
'
type
'
)
'
type
'
:
stanza
.
getAttribute
(
'
type
'
)
},
this
.
getStanzaIDs
(
original_stanza
));
},
this
.
getStanzaIDs
(
original_stanza
));
...
@@ -1244,7 +1245,7 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -1244,7 +1245,7 @@ converse.plugins.add('converse-chatboxes', {
// Get chat box, but only create when the message has something to show to the user
// Get chat box, but only create when the message has something to show to the user
const
has_body
=
sizzle
(
`body, encrypted[xmlns="
${
Strophe
.
NS
.
OMEMO
}
"]`
,
stanza
).
length
>
0
;
const
has_body
=
sizzle
(
`body, encrypted[xmlns="
${
Strophe
.
NS
.
OMEMO
}
"]`
,
stanza
).
length
>
0
;
const
roster_nick
=
_
.
get
(
contact
,
'
attributes.nickname
'
);
const
roster_nick
=
get
(
contact
,
'
attributes.nickname
'
);
const
chatbox
=
this
.
getChatBox
(
contact_jid
,
{
'
nickname
'
:
roster_nick
},
has_body
);
const
chatbox
=
this
.
getChatBox
(
contact_jid
,
{
'
nickname
'
:
roster_nick
},
has_body
);
if
(
chatbox
)
{
if
(
chatbox
)
{
...
@@ -1285,7 +1286,7 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -1285,7 +1286,7 @@ converse.plugins.add('converse-chatboxes', {
* chat box already exists, its attributes will be updated.
* chat box already exists, its attributes will be updated.
*/
*/
getChatBox
(
jid
,
attrs
=
{},
create
)
{
getChatBox
(
jid
,
attrs
=
{},
create
)
{
if
(
_
.
isObject
(
jid
))
{
if
(
isObject
(
jid
))
{
create
=
attrs
;
create
=
attrs
;
attrs
=
jid
;
attrs
=
jid
;
jid
=
attrs
.
jid
;
jid
=
attrs
.
jid
;
...
@@ -1320,7 +1321,7 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -1320,7 +1321,7 @@ converse.plugins.add('converse-chatboxes', {
if
(
_converse
.
chatboxes
.
where
({
'
jid
'
:
jid
}).
length
)
{
if
(
_converse
.
chatboxes
.
where
({
'
jid
'
:
jid
}).
length
)
{
return
;
return
;
}
}
if
(
_
.
isString
(
jid
))
{
if
(
isString
(
jid
))
{
_converse
.
api
.
chats
.
open
(
jid
);
_converse
.
api
.
chats
.
open
(
jid
);
}
else
{
}
else
{
_converse
.
log
(
_converse
.
log
(
...
@@ -1381,10 +1382,10 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -1381,10 +1382,10 @@ converse.plugins.add('converse-chatboxes', {
* @param {object} [attrs] An object containing configuration attributes.
* @param {object} [attrs] An object containing configuration attributes.
*/
*/
async
create
(
jids
,
attrs
)
{
async
create
(
jids
,
attrs
)
{
if
(
_
.
isString
(
jids
))
{
if
(
isString
(
jids
))
{
if
(
attrs
&&
!
_
.
get
(
attrs
,
'
fullname
'
))
{
if
(
attrs
&&
!
get
(
attrs
,
'
fullname
'
))
{
const
contact
=
await
_converse
.
api
.
contacts
.
get
(
jids
);
const
contact
=
await
_converse
.
api
.
contacts
.
get
(
jids
);
attrs
.
fullname
=
_
.
get
(
contact
,
'
attributes.fullname
'
);
attrs
.
fullname
=
get
(
contact
,
'
attributes.fullname
'
);
}
}
const
chatbox
=
_converse
.
chatboxes
.
getChatBox
(
jids
,
attrs
,
true
);
const
chatbox
=
_converse
.
chatboxes
.
getChatBox
(
jids
,
attrs
,
true
);
if
(
!
chatbox
)
{
if
(
!
chatbox
)
{
...
@@ -1396,7 +1397,7 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -1396,7 +1397,7 @@ converse.plugins.add('converse-chatboxes', {
if
(
Array
.
isArray
(
jids
))
{
if
(
Array
.
isArray
(
jids
))
{
return
Promise
.
all
(
jids
.
forEach
(
async
jid
=>
{
return
Promise
.
all
(
jids
.
forEach
(
async
jid
=>
{
const
contact
=
await
_converse
.
api
.
contacts
.
get
(
jids
);
const
contact
=
await
_converse
.
api
.
contacts
.
get
(
jids
);
attrs
.
fullname
=
_
.
get
(
contact
,
'
attributes.fullname
'
);
attrs
.
fullname
=
get
(
contact
,
'
attributes.fullname
'
);
return
_converse
.
chatboxes
.
getChatBox
(
jid
,
attrs
,
true
).
maybeShow
();
return
_converse
.
chatboxes
.
getChatBox
(
jid
,
attrs
,
true
).
maybeShow
();
}));
}));
}
}
...
@@ -1454,7 +1455,7 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -1454,7 +1455,7 @@ converse.plugins.add('converse-chatboxes', {
_converse
.
api
.
waitUntil
(
'
chatBoxesFetched
'
)
_converse
.
api
.
waitUntil
(
'
chatBoxesFetched
'
)
]);
]);
if
(
_
.
isString
(
jids
))
{
if
(
isString
(
jids
))
{
const
chat
=
await
_converse
.
api
.
chats
.
create
(
jids
,
attrs
);
const
chat
=
await
_converse
.
api
.
chats
.
create
(
jids
,
attrs
);
if
(
chat
)
{
if
(
chat
)
{
return
chat
.
maybeShow
(
force
);
return
chat
.
maybeShow
(
force
);
...
@@ -1502,7 +1503,7 @@ converse.plugins.add('converse-chatboxes', {
...
@@ -1502,7 +1503,7 @@ converse.plugins.add('converse-chatboxes', {
}
}
});
});
return
result
;
return
result
;
}
else
if
(
_
.
isString
(
jids
))
{
}
else
if
(
isString
(
jids
))
{
return
_converse
.
chatboxes
.
getChatBox
(
jids
);
return
_converse
.
chatboxes
.
getChatBox
(
jids
);
}
}
return
jids
.
map
(
jid
=>
_converse
.
chatboxes
.
getChatBox
(
jid
,
{},
true
));
return
jids
.
map
(
jid
=>
_converse
.
chatboxes
.
getChatBox
(
jid
,
{},
true
));
...
...
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