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
d92645c8
Commit
d92645c8
authored
Mar 08, 2016
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show a desktop notification when a contact request is received
updates #443
parent
0aa0c021
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
8 deletions
+39
-8
docs/source/configuration.rst
docs/source/configuration.rst
+7
-2
spec/notification.js
spec/notification.js
+7
-1
src/converse-notification.js
src/converse-notification.js
+25
-5
No files found.
docs/source/configuration.rst
View file @
d92645c8
...
...
@@ -659,8 +659,13 @@ show_desktop_notifications
* Default: ``true``
Should HTML5 desktop notifications be shown when the browser is not visible or
not focused?
Should HTML5 desktop notifications be shown?
Notification will be shown in the following cases:
* the browser is not visible nor focused and a private message is received.
* the browser is not visible nor focused and a groupchat message is received which mentions you.
* `auto_subscribe` is set to `false` and a new contact request is received.
Requires the `src/converse-notification.js` plugin.
...
...
spec/notification.js
View file @
d92645c8
...
...
@@ -41,6 +41,7 @@
}).
c
(
'
body
'
).
t
(
message
).
up
()
.
c
(
'
active
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/chatstates
'
}).
tree
();
converse
.
chatboxes
.
onMessage
(
msg
);
// This will emit 'message'
expect
(
converse
.
areDesktopNotificationsEnabled
).
toHaveBeenCalled
();
expect
(
converse
.
showMessageNotification
).
toHaveBeenCalled
();
});
...
...
@@ -50,6 +51,7 @@
spyOn
(
converse
,
'
showChatStateNotification
'
);
var
jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
converse
.
roster
.
get
(
jid
).
set
(
'
chat_status
'
,
'
busy
'
);
// This will emit 'contactStatusChanged'
expect
(
converse
.
areDesktopNotificationsEnabled
).
toHaveBeenCalled
();
expect
(
converse
.
showChatStateNotification
).
toHaveBeenCalled
();
});
});
...
...
@@ -57,7 +59,11 @@
describe
(
"
When a new contact request is received
"
,
function
()
{
it
(
"
an HTML5 Notification is received
"
,
function
()
{
// TODO
spyOn
(
converse
,
'
areDesktopNotificationsEnabled
'
).
andReturn
(
true
);
spyOn
(
converse
,
'
showContactRequestNotification
'
);
converse
.
emit
(
'
contactRequest
'
,
{
'
fullname
'
:
'
Peter Parker
'
,
'
jid
'
:
'
peter@parker.com
'
});
expect
(
converse
.
areDesktopNotificationsEnabled
).
toHaveBeenCalled
();
expect
(
converse
.
showContactRequestNotification
).
toHaveBeenCalled
();
});
});
});
...
...
src/converse-notification.js
View file @
d92645c8
...
...
@@ -105,11 +105,15 @@
}
};
converse
.
areDesktopNotificationsEnabled
=
function
()
{
return
(
supports_html5_notification
&&
converse
.
show_desktop_notifications
&&
converse
.
windowState
===
'
blur
'
&&
Notification
.
permission
===
"
granted
"
);
converse
.
areDesktopNotificationsEnabled
=
function
(
ignore_blur
)
{
var
enabled
=
supports_html5_notification
&&
converse
.
show_desktop_notifications
&&
Notification
.
permission
===
"
granted
"
;
if
(
ignore_blur
)
{
return
enabled
;
}
else
{
return
enabled
&&
converse
.
windowState
===
'
blur
'
;
}
};
converse
.
showMessageNotification
=
function
(
$message
)
{
...
...
@@ -152,6 +156,15 @@
setTimeout
(
n
.
close
.
bind
(
n
),
5000
);
};
converse
.
showContactRequestNotification
=
function
(
contact
)
{
var
n
=
new
Notification
(
contact
.
fullname
,
{
body
:
__
(
'
is requesting to be your contact
'
),
lang
:
converse
.
i18n
.
locale_data
.
converse
[
""
].
lang
,
icon
:
'
logo/conversejs.png
'
});
setTimeout
(
n
.
close
.
bind
(
n
),
5000
);
};
converse
.
handleChatStateNotification
=
function
(
evt
,
contact
)
{
/* Event handler for on('contactStatusChanged').
* Will show an HTML5 notification to indicate that the chat
...
...
@@ -176,6 +189,13 @@
}
};
converse
.
handleContactRequestNotification
=
function
(
evt
,
contact
)
{
if
(
converse
.
areDesktopNotificationsEnabled
(
true
))
{
converse
.
showContactRequestNotification
(
contact
);
}
};
converse
.
on
(
'
contactRequest
'
,
converse
.
handleContactRequestNotification
);
converse
.
on
(
'
contactStatusChanged
'
,
converse
.
handleChatStateNotification
);
converse
.
on
(
'
message
'
,
converse
.
handleMessageNotification
);
}
...
...
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