notifications order, unseen css class
ping return notfications ordered by notification id notifications list get seen/unseen class from ping xml global.css define 'notify-unseen'
This commit is contained in:
		
					parent
					
						
							
								bd3f29f266
							
						
					
				
			
			
				commit
				
					
						e29d05ce4a
					
				
			
		
					 5 changed files with 34 additions and 31 deletions
				
			
		
							
								
								
									
										30
									
								
								js/main.js
									
										
									
									
									
								
							
							
						
						
									
										30
									
								
								js/main.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -182,42 +182,32 @@
 | 
			
		|||
				nnm.html(notifications_all + notifications_mark);
 | 
			
		||||
				//nnm.attr('popup','true');
 | 
			
		||||
 | 
			
		||||
				var notification_lastitem = localStorage.getItem("notification-lastitem");
 | 
			
		||||
				var notification_first_id = 0;
 | 
			
		||||
				var notification_id;
 | 
			
		||||
				var notification_lastitem = parseInt(localStorage.getItem("notification-lastitem"));
 | 
			
		||||
				var notification_id = 0;
 | 
			
		||||
				eNotif.children("note").each(function(){
 | 
			
		||||
					e = $(this);
 | 
			
		||||
					text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
 | 
			
		||||
					html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
 | 
			
		||||
					nnm.append(html);
 | 
			
		||||
					
 | 
			
		||||
					notification_id = e.attr('href').match(/\d+$/)[0];
 | 
			
		||||
					if (notification_lastitem!== null && notification_id!=notification_lastitem) {
 | 
			
		||||
						if (notification_first_id===0) notification_first_id = notification_id;
 | 
			
		||||
				});
 | 
			
		||||
				$(eNotif.children("note").get().reverse()).each(function(){
 | 
			
		||||
					e = $(this);
 | 
			
		||||
					notification_id = parseInt(e.attr('href').match(/\d+$/)[0]);
 | 
			
		||||
					if (notification_lastitem!== null && notification_id > notification_lastitem) {
 | 
			
		||||
						if (getNotificationPermission()==="granted") {
 | 
			
		||||
							console.log("notification", e.text().replace('→ ','').format(e.attr('name')));
 | 
			
		||||
							var notification = new Notification(document.title, {
 | 
			
		||||
											  body: e.text().replace('→ ','').format(e.attr('name')),
 | 
			
		||||
											  icon: e.attr('photo'),
 | 
			
		||||
											  data: e.attr('href')
 | 
			
		||||
											 });
 | 
			
		||||
							// close notification after 5 secs.
 | 
			
		||||
							// see https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API#Closing_notifications
 | 
			
		||||
							//setTimeout(notification.close.bind(notification), 5000);
 | 
			
		||||
							
 | 
			
		||||
							notification['url'] = e.attr('href');
 | 
			
		||||
							notification.addEventListener("click", function(ev){
 | 
			
		||||
								window.location = ev.target.data;
 | 
			
		||||
								window.location = ev.target.url;
 | 
			
		||||
							});
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
					if (notification_id == notification_lastitem) {
 | 
			
		||||
						if (notification_first_id===0) notification_first_id = notification_id;
 | 
			
		||||
						notification_lastitem = null;
 | 
			
		||||
					}
 | 
			
		||||
				
 | 
			
		||||
					
 | 
			
		||||
				});
 | 
			
		||||
				if (notification_first_id!==0) notification_lastitem = notification_first_id;
 | 
			
		||||
				notification_lastitem = notification_id;
 | 
			
		||||
				localStorage.setItem("notification-lastitem", notification_lastitem)
 | 
			
		||||
 | 
			
		||||
				$("img[data-src]", nnm).each(function(i, el){
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue