فهرست منبع

Messages timestamp, make API use less bandwidth

Nathaniel van Diepen 11 سال پیش
والد
کامیت
19a67f5316
4فایلهای تغییر یافته به همراه49 افزوده شده و 34 حذف شده
  1. 1 1
      api.php
  2. 5 0
      data/pages/messages.template
  3. 11 7
      js/index.js
  4. 32 26
      php/functions.php

+ 1 - 1
api.php

@@ -259,7 +259,7 @@
 										$ret['timestamp'] = $res['timestamp'];
 									}
 								}
-								retj($ret,$id);
+								retj($ret,$_GET['title']);
 							break;
 							case 'comment':
 								if(isset($_GET['comment_type'])&&isset($_GET['comment_id'])&&isset($_GET['message'])){

+ 5 - 0
data/pages/messages.template

@@ -10,6 +10,11 @@
 	</span>
 	{{#each messages}}
 		<h3>
+			<span style="float:right;">
+				<time style="font-size:smaller;" class="timeago">
+					{{timestamp}}
+				</time>
+			</span>
 			<a class="button" href="#~{{from}}">
 				From: {{from}}
 			</a>

+ 11 - 7
js/index.js

@@ -103,13 +103,15 @@
 					if(exists(d['error'])){
 						error(d);
 					}else{
-						d.state.title = d.state.title.capitalize();
-						if(location.href.substr(location.href.lastIndexOf('/')+1) != d.state.url && d.state.url != ''){
-							console.log('Forced redirection to '+d.state.url);
-							History.replaceState(d.state.data,d.state.title,d.state.url);
-							getNewState();
+						if(exists(d.state)){
+							d.state.title = d.state.title.capitalize();
+							if(location.href.substr(location.href.lastIndexOf('/')+1) != d.state.url && d.state.url != ''){
+								console.log('Forced redirection to '+d.state.url);
+								History.replaceState(d.state.data,d.state.title,d.state.url);
+								getNewState();
+							}
+							document.title = d.state.title;
 						}
-						document.title = d.state.title;
 					}
 					if(exists(callback)){
 						console.log('Running apiCall callback');
@@ -585,7 +587,8 @@
 		$.get(location.href,{
 			get: 'settings',
 			timestamp: +new Date,
-			back: false
+			back: false,
+			no_state: true
 		},function(d){
 			if(!exists(d.error)){
 				settings = d.settings;
@@ -625,6 +628,7 @@
 			context.url = State.url;
 			context.title = State.title;
 			context.topbar = false;
+			context.no_state = true;
 			apiCall(context,function(d){
 				if(!exists(d.error)){
 					if(d.count>0 && $.localStorage('last_pm_check') < d.timestamp){

+ 32 - 26
php/functions.php

@@ -5,18 +5,20 @@
 		global $LOGGEDIN;
 		$type=$_GET['type'];
 		$id=$_GET['id'];
-		// State
-		if(!isset($json['state'])){
-			$json['state'] = Array();
-		}
-		unset($_GET['password']);
-		unset($_GET['password1']);
-		if(!isset($json['state']['data'])){
-			$json['state']['data'] = $_GET;
-		}else{
-			foreach($_GET as $key => $val){
-				if(!isset($json['state']['data'][$key])&&$key!='password'){
-					$json['state']['data'][$key] = $val;
+		if(!isset($_GET['no_state'])){
+			// State
+			if(!isset($json['state'])){
+				$json['state'] = Array();
+			}
+			unset($_GET['password']);
+			unset($_GET['password1']);
+			if(!isset($json['state']['data'])){
+				$json['state']['data'] = $_GET;
+			}else{
+				foreach($_GET as $key => $val){
+					if(!isset($json['state']['data'][$key])&&$key!='password'){
+						$json['state']['data'][$key] = $val;
+					}
 				}
 			}
 		}
@@ -24,25 +26,27 @@
 		if(is_null($title)){
 			if(isset($json['title'])){
 				$title = $json['title'];
-			}elseif(isset($json['state']['title'])){
+			}elseif(isset($json['state']['title'])&&!isset($_GET['no_state'])){
 				$title = $json['state']['title'];
 			}else{
 				$title = $_GET['id'];
 			}
 		}
-		$json['state']['title'] = $title;
-		if(!isset($json['state']['url'])){
-			// URL
-			switch($type){
-				case 'user':$url='~'.$id;break;
-				case 'group':$url='+'.$id;break;
-				case 'issue':$url='!'.$id;break;
-				case 'action':$url='';break;
-				default:$url=$type.'-'.$id;
+		if(!isset($_GET['no_state'])){
+			$json['state']['title'] = $title;
+			if(!isset($json['state']['url'])){
+				// URL
+				switch($type){
+					case 'user':$url='~'.$id;break;
+					case 'group':$url='+'.$id;break;
+					case 'issue':$url='!'.$id;break;
+					case 'action':$url='';break;
+					default:$url=$type.'-'.$id;
+				}
+				$json['state']['url'] = $url;
+			}else{
+				$url = $json['state']['url'];
 			}
-			$json['state']['url'] = $url;
-		}else{
-			$url = $json['state']['url'];
 		}
 		if(!isset($_GET['topbar'])){
 			// Tobar
@@ -55,7 +59,9 @@
 				$context = Array();
 			}
 			$context['title'] = $title;
-			$context['url'] = $url;
+			if(!isset($_GET['no_state'])){
+				$context['url'] = $url;
+			}
 			if(file_exists(PATH_DATA.'topbars/'.$type.'-'.$id)){
 				$topbar = file_get_contents(PATH_DATA.'topbars/'.$type.'-'.$id.'.template');
 			}else{