[Kimchi-devel] [PATCH] [Wok 3/3] Implement notifications loop
Lucio Correia
luciojhc at linux.vnet.ibm.com
Thu Mar 31 21:02:48 UTC 2016
Check for new notifications each 5 seconds. Duplicated
notifications are controlled by postedNotifications var.
Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
---
ui/js/src/wok.main.js | 5 +++++
ui/js/src/wok.utils.js | 19 +++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/ui/js/src/wok.main.js b/ui/js/src/wok.main.js
index f3f837a..9b4343c 100644
--- a/ui/js/src/wok.main.js
+++ b/ui/js/src/wok.main.js
@@ -18,6 +18,8 @@
* limitations under the License.
*/
+wok.NOTIFICATION_INTERVAL = 5000
+wok.postedNotifications = []
wok.tabMode = {};
wok.config = undefined;
@@ -296,6 +298,7 @@ wok.main = function() {
* 5) About button click event
* 6) Help button click event
* 7) Peers button click event
+ * 8) Start notifications loop
*/
var searchingPeers = false;
var initListeners = function() {
@@ -466,6 +469,8 @@ wok.main = function() {
wok.message.error(data.responseJSON.reason);
}
);
+
+ setTimeout(wok.notificationsLoop, wok.NOTIFICATION_INTERVAL);
};
diff --git a/ui/js/src/wok.utils.js b/ui/js/src/wok.utils.js
index e5701e6..6392afb 100644
--- a/ui/js/src/wok.utils.js
+++ b/ui/js/src/wok.utils.js
@@ -193,3 +193,22 @@ wok.urlSafeB64Decode = function(str) {
wok.urlSafeB64Encode = function(str) {
return $.base64.btoa(str, true).replace(/\+/g, '-').replace(/\//g, '_');
}
+
+wok.notificationsLoop = function notificationsLoop() {
+ wok.getNotifications(
+ function(notifications){
+ if(notifications && notifications.length > 0) {
+ $.each(notifications, function(i, msg) {
+ if (wok.postedNotifications.indexOf(msg.message) == -1) {
+ wok.notification(msg, '#message-container-area');
+ wok.postedNotifications.push(msg.message);
+ }
+ })
+ };
+ setTimeout(notificationsLoop, wok.NOTIFICATION_INTERVAL);
+ },
+ function(data){
+ setTimeout(notificationsLoop, wok.NOTIFICATION_INTERVAL);
+ }
+ );
+}
--
1.9.1
More information about the Kimchi-devel
mailing list