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
b15c107e
Commit
b15c107e
authored
Feb 24, 2017
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't show notifications for full JID headline messages if...
allow_non_roster_messaging is false.
parent
453d98db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
15 deletions
+81
-15
spec/notification.js
spec/notification.js
+56
-2
src/converse-notification.js
src/converse-notification.js
+25
-13
No files found.
spec/notification.js
View file @
b15c107e
(
function
(
root
,
factory
)
{
define
([
"
mock
"
,
"
converse-core
"
,
"
test_utils
"
],
factory
);
}
(
this
,
function
(
mock
,
converse
,
test_utils
)
{
define
([
"
mock
"
,
"
converse-core
"
,
"
test_utils
"
,
"
utils
"
],
factory
);
}
(
this
,
function
(
mock
,
converse
,
test_utils
,
utils
)
{
"
use strict
"
;
var
_
=
converse
.
env
.
_
;
var
$msg
=
converse
.
env
.
$msg
;
describe
(
"
Notifications
"
,
function
()
{
...
...
@@ -64,6 +65,59 @@
}
}));
it
(
"
is shown for headline messages
"
,
mock
.
initConverse
(
function
(
_converse
)
{
spyOn
(
_converse
,
'
showMessageNotification
'
).
andCallThrough
();
spyOn
(
_converse
,
'
areDesktopNotificationsEnabled
'
).
andReturn
(
true
);
runs
(
function
()
{
var
stanza
=
$msg
({
'
type
'
:
'
headline
'
,
'
from
'
:
'
notify.example.com
'
,
'
to
'
:
'
dummy@localhost
'
,
'
xml:lang
'
:
'
en
'
})
.
c
(
'
subject
'
).
t
(
'
SIEVE
'
).
up
()
.
c
(
'
body
'
).
t
(
'
<juliet@example.com> You got mail.
'
).
up
()
.
c
(
'
x
'
,
{
'
xmlns
'
:
'
jabber:x:oob
'
})
.
c
(
'
url
'
).
t
(
'
imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18
'
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
});
waits
(
250
);
runs
(
function
()
{
expect
(
_
.
includes
(
_converse
.
chatboxviews
.
keys
(),
'
notify.example.com
'
)
).
toBeTruthy
();
expect
(
_converse
.
showMessageNotification
).
toHaveBeenCalled
();
});
}));
it
(
"
is not shown for full JID headline messages if allow_non_roster_messaging is false
"
,
mock
.
initConverse
(
function
(
_converse
)
{
_converse
.
allow_non_roster_messaging
=
false
;
spyOn
(
_converse
,
'
showMessageNotification
'
).
andCallThrough
();
spyOn
(
_converse
,
'
areDesktopNotificationsEnabled
'
).
andReturn
(
true
);
runs
(
function
()
{
var
stanza
=
$msg
({
'
type
'
:
'
headline
'
,
'
from
'
:
'
someone@notify.example.com
'
,
'
to
'
:
'
dummy@localhost
'
,
'
xml:lang
'
:
'
en
'
})
.
c
(
'
subject
'
).
t
(
'
SIEVE
'
).
up
()
.
c
(
'
body
'
).
t
(
'
<juliet@example.com> You got mail.
'
).
up
()
.
c
(
'
x
'
,
{
'
xmlns
'
:
'
jabber:x:oob
'
})
.
c
(
'
url
'
).
t
(
'
imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18
'
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
});
waits
(
250
);
runs
(
function
()
{
expect
(
_
.
includes
(
_converse
.
chatboxviews
.
keys
(),
'
someone@notify.example.com
'
)
).
toBeFalsy
();
expect
(
_converse
.
showMessageNotification
).
not
.
toHaveBeenCalled
();
});
}));
it
(
"
is shown when a user changes their chat state (if show_chatstate_notifications is true)
"
,
mock
.
initConverse
(
function
(
_converse
)
{
// TODO: not yet testing show_desktop_notifications setting
_converse
.
show_chatstate_notifications
=
true
;
...
...
src/converse-notification.js
View file @
b15c107e
...
...
@@ -130,26 +130,38 @@
/* Shows an HTML5 Notification to indicate that a new chat
* message was received.
*/
var
n
,
title
,
contact_jid
,
roster_item
,
from_jid
=
message
.
getAttribute
(
'
from
'
);
if
(
message
.
getAttribute
(
'
type
'
)
===
'
headline
'
||
!
_
.
includes
(
from_jid
,
'
@
'
))
{
// XXX: 2nd check is workaround for Prosody which doesn't
// give type "headline"
var
title
,
roster_item
,
from_jid
=
Strophe
.
getBareJidFromJid
(
message
.
getAttribute
(
'
from
'
));
if
(
message
.
getAttribute
(
'
type
'
)
===
'
headline
'
)
{
if
(
!
_
.
includes
(
from_jid
,
'
@
'
)
||
_converse
.
allow_non_roster_messaging
)
{
title
=
__
(
___
(
"
Notification from %1$s
"
),
from_jid
);
}
else
{
return
;
}
}
else
if
(
!
_
.
includes
(
from_jid
,
'
@
'
))
{
// XXX: workaround for Prosody which doesn't give type "headline"
title
=
__
(
___
(
"
Notification from %1$s
"
),
from_jid
);
}
else
if
(
message
.
getAttribute
(
'
type
'
)
===
'
groupchat
'
)
{
title
=
__
(
___
(
"
%1$s says
"
),
Strophe
.
getResourceFromJid
(
from_jid
));
}
else
{
if
(
message
.
getAttribute
(
'
type
'
)
===
'
groupchat
'
)
{
title
=
__
(
___
(
"
%1$s says
"
),
Strophe
.
getResourceFromJid
(
from_jid
));
if
(
_
.
isUndefined
(
_converse
.
roster
))
{
_converse
.
log
(
"
Could not send notification, because roster is undefined
"
,
"
error
"
);
return
;
}
roster_item
=
_converse
.
roster
.
get
(
from_jid
);
if
(
!
_
.
isUndefined
(
roster_item
))
{
title
=
__
(
___
(
"
%1$s says
"
),
roster_item
.
get
(
'
fullname
'
));
}
else
{
if
(
_
.
isUndefined
(
_converse
.
roster
))
{
_converse
.
log
(
"
Could not send notification, because roster is undefined
"
,
"
error
"
);
if
(
_converse
.
allow_non_roster_messaging
)
{
title
=
__
(
___
(
"
%1$s says
"
),
from_jid
);
}
else
{
return
;
}
contact_jid
=
Strophe
.
getBareJidFromJid
(
message
.
getAttribute
(
'
from
'
));
roster_item
=
_converse
.
roster
.
get
(
contact_jid
);
title
=
__
(
___
(
"
%1$s says
"
),
roster_item
.
get
(
'
fullname
'
));
}
}
n
=
new
Notification
(
title
,
{
var
n
=
new
Notification
(
title
,
{
body
:
message
.
querySelector
(
'
body
'
).
textContent
,
lang
:
_converse
.
i18n
.
locale_data
.
converse
[
""
].
lang
,
icon
:
_converse
.
notification_icon
...
...
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