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
8e4e9185
Commit
8e4e9185
authored
Oct 10, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace lodash methods with built-in ones and add jsdoc strings
parent
2d44144b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
18 deletions
+20
-18
src/converse-notification.js
src/converse-notification.js
+20
-18
No files found.
src/converse-notification.js
View file @
8e4e9185
...
@@ -8,9 +8,10 @@
...
@@ -8,9 +8,10 @@
* @module converse-notification
* @module converse-notification
*/
*/
import
converse
from
"
@converse/headless/converse-core
"
;
import
converse
from
"
@converse/headless/converse-core
"
;
import
{
get
}
from
"
lodash
"
;
const
{
Strophe
,
_
,
sizzle
}
=
converse
.
env
,
const
{
Strophe
,
sizzle
}
=
converse
.
env
;
u
=
converse
.
env
.
utils
;
const
u
=
converse
.
env
.
utils
;
converse
.
plugins
.
add
(
'
converse-notification
'
,
{
converse
.
plugins
.
add
(
'
converse-notification
'
,
{
...
@@ -56,7 +57,7 @@ converse.plugins.add('converse-notification', {
...
@@ -56,7 +57,7 @@ converse.plugins.add('converse-notification', {
}
}
const
mentioned
=
(
new
RegExp
(
`\\b
${
room
.
get
(
'
nick
'
)}
\\b`
)).
test
(
body
.
textContent
);
const
mentioned
=
(
new
RegExp
(
`\\b
${
room
.
get
(
'
nick
'
)}
\\b`
)).
test
(
body
.
textContent
);
notify_all
=
notify_all
===
true
||
notify_all
=
notify_all
===
true
||
(
Array
.
isArray
(
notify_all
)
&&
_
.
includes
(
notify_all
,
room_jid
));
(
Array
.
isArray
(
notify_all
)
&&
notify_all
.
includes
(
room_jid
));
if
(
sender
===
room
.
get
(
'
nick
'
)
||
(
!
notify_all
&&
!
mentioned
))
{
if
(
sender
===
room
.
get
(
'
nick
'
)
||
(
!
notify_all
&&
!
mentioned
))
{
return
false
;
return
false
;
}
}
...
@@ -93,12 +94,12 @@ converse.plugins.add('converse-notification', {
...
@@ -93,12 +94,12 @@ converse.plugins.add('converse-notification', {
};
};
/**
* Plays a notification sound
* @private
* @method _converse#playSoundNotification
*/
_converse
.
playSoundNotification
=
function
()
{
_converse
.
playSoundNotification
=
function
()
{
/* Plays a sound to notify that a new message was recieved.
*/
// XXX Eventually this can be refactored to use Notification's sound
// feature, but no browser currently supports it.
// https://developer.mozilla.org/en-US/docs/Web/API/notification/sound
if
(
_converse
.
play_sounds
&&
window
.
Audio
!==
undefined
)
{
if
(
_converse
.
play_sounds
&&
window
.
Audio
!==
undefined
)
{
const
audioOgg
=
new
Audio
(
_converse
.
sounds_path
+
"
msg_received.ogg
"
);
const
audioOgg
=
new
Audio
(
_converse
.
sounds_path
+
"
msg_received.ogg
"
);
const
canPlayOgg
=
audioOgg
.
canPlayType
(
'
audio/ogg
'
);
const
canPlayOgg
=
audioOgg
.
canPlayType
(
'
audio/ogg
'
);
...
@@ -123,10 +124,13 @@ converse.plugins.add('converse-notification', {
...
@@ -123,10 +124,13 @@ converse.plugins.add('converse-notification', {
Notification
.
permission
===
"
granted
"
;
Notification
.
permission
===
"
granted
"
;
};
};
/**
* Shows an HTML5 Notification with the passed in message
* @private
* @method _converse#showMessageNotification
* @param { String } message
*/
_converse
.
showMessageNotification
=
function
(
message
)
{
_converse
.
showMessageNotification
=
function
(
message
)
{
/* Shows an HTML5 Notification to indicate that a new chat
* message was received.
*/
if
(
!
_converse
.
areDesktopNotificationsEnabled
())
{
if
(
!
_converse
.
areDesktopNotificationsEnabled
())
{
return
;
return
;
}
}
...
@@ -134,12 +138,12 @@ converse.plugins.add('converse-notification', {
...
@@ -134,12 +138,12 @@ converse.plugins.add('converse-notification', {
const
full_from_jid
=
message
.
getAttribute
(
'
from
'
),
const
full_from_jid
=
message
.
getAttribute
(
'
from
'
),
from_jid
=
Strophe
.
getBareJidFromJid
(
full_from_jid
);
from_jid
=
Strophe
.
getBareJidFromJid
(
full_from_jid
);
if
(
message
.
getAttribute
(
'
type
'
)
===
'
headline
'
)
{
if
(
message
.
getAttribute
(
'
type
'
)
===
'
headline
'
)
{
if
(
!
_
.
includes
(
from_jid
,
'
@
'
)
||
_converse
.
allow_non_roster_messaging
)
{
if
(
!
from_jid
.
includes
(
'
@
'
)
||
_converse
.
allow_non_roster_messaging
)
{
title
=
__
(
"
Notification from %1$s
"
,
from_jid
);
title
=
__
(
"
Notification from %1$s
"
,
from_jid
);
}
else
{
}
else
{
return
;
return
;
}
}
}
else
if
(
!
_
.
includes
(
from_jid
,
'
@
'
))
{
}
else
if
(
!
from_jid
.
includes
(
'
@
'
))
{
// workaround for Prosody which doesn't give type "headline"
// workaround for Prosody which doesn't give type "headline"
title
=
__
(
"
Notification from %1$s
"
,
from_jid
);
title
=
__
(
"
Notification from %1$s
"
,
from_jid
);
}
else
if
(
message
.
getAttribute
(
'
type
'
)
===
'
groupchat
'
)
{
}
else
if
(
message
.
getAttribute
(
'
type
'
)
===
'
groupchat
'
)
{
...
@@ -166,7 +170,7 @@ converse.plugins.add('converse-notification', {
...
@@ -166,7 +170,7 @@ converse.plugins.add('converse-notification', {
// the message...
// the message...
const
body
=
sizzle
(
`encrypted[xmlns="
${
Strophe
.
NS
.
OMEMO
}
"]`
,
message
).
length
?
const
body
=
sizzle
(
`encrypted[xmlns="
${
Strophe
.
NS
.
OMEMO
}
"]`
,
message
).
length
?
__
(
'
OMEMO Message received
'
)
:
__
(
'
OMEMO Message received
'
)
:
_
.
get
(
message
.
querySelector
(
'
body
'
),
'
textContent
'
);
get
(
message
.
querySelector
(
'
body
'
),
'
textContent
'
);
if
(
!
body
)
{
if
(
!
body
)
{
return
;
return
;
}
}
...
@@ -185,7 +189,7 @@ converse.plugins.add('converse-notification', {
...
@@ -185,7 +189,7 @@ converse.plugins.add('converse-notification', {
/* Creates an HTML5 Notification to inform of a change in a
/* Creates an HTML5 Notification to inform of a change in a
* contact's chat state.
* contact's chat state.
*/
*/
if
(
_
.
includes
(
_converse
.
chatstate_notification_blacklist
,
contact
.
jid
))
{
if
(
_
converse
.
chatstate_notification_blacklist
.
includes
(
contact
.
jid
))
{
// Don't notify if the user is being ignored.
// Don't notify if the user is being ignored.
return
;
return
;
}
}
...
@@ -274,8 +278,7 @@ converse.plugins.add('converse-notification', {
...
@@ -274,8 +278,7 @@ converse.plugins.add('converse-notification', {
};
};
_converse
.
requestPermission
=
function
()
{
_converse
.
requestPermission
=
function
()
{
if
(
_converse
.
supports_html5_notification
&&
if
(
_converse
.
supports_html5_notification
&&
!
[
'
denied
'
,
'
granted
'
].
includes
(
Notification
.
permission
))
{
!
_
.
includes
([
'
denied
'
,
'
granted
'
],
Notification
.
permission
))
{
// Ask user to enable HTML5 notifications
// Ask user to enable HTML5 notifications
Notification
.
requestPermission
();
Notification
.
requestPermission
();
}
}
...
@@ -293,4 +296,3 @@ converse.plugins.add('converse-notification', {
...
@@ -293,4 +296,3 @@ converse.plugins.add('converse-notification', {
});
});
}
}
});
});
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