diff --git a/database/cloud-server.mwb b/database/cloud-server.mwb index 0a1d08b..3a536bb 100644 Binary files a/database/cloud-server.mwb and b/database/cloud-server.mwb differ diff --git a/src/application/controller/api/image.php b/src/application/controller/api/image.php deleted file mode 100755 index 01f9bb4..0000000 --- a/src/application/controller/api/image.php +++ /dev/null @@ -1,21 +0,0 @@ -generateImageResource($fileName, 42, 42, false); - - file_put_contents($filePath, $image); - } - - $image = file_get_contents($filePath); - - header("Content-Type: image/jpeg"); - - echo $image; -} diff --git a/src/application/controller/api/user/avatar.php b/src/application/controller/api/user/avatar.php index ac2aaf0..259b2d0 100644 --- a/src/application/controller/api/user/avatar.php +++ b/src/application/controller/api/user/avatar.php @@ -10,7 +10,15 @@ if (isset($_SESSION['userName'])) { $userName = isset($_GET['userName']) ? Filter::userName($_GET['userName']) : $_SESSION['userName']; - if ($avatarVersions = $_twister->getDHT($userName, 'avatar', 's')) { + if ($avatar = $_memcache->get('api.user.avatar.' . $userName)) { + + $response = [ + 'success' => true, + 'message' => _('Avatar successfully received from Cache'), + 'avatar' => $avatar + ]; + + } else if ($avatarVersions = $_twister->getDHT($userName, 'avatar', 's')) { // Check avatar exists if ($userId = $_modelUser->getUserId($userName)) { @@ -36,10 +44,12 @@ if (isset($_SESSION['userName'])) { $response = [ 'success' => true, - 'message' => _('Avatar successfully received'), + 'message' => _('Avatar successfully received from DHT'), 'avatar' => $avatarInfo['data'] ]; + $_memcache->set('api.user.avatar.' . $userName, $avatarInfo['data'], MEMCACHE_COMPRESS, MEMCACHE_DHT_AVATAR_TIMEOUT); + } else { $response = [ @@ -49,12 +59,26 @@ if (isset($_SESSION['userName'])) { ]; } + // Generate identity icon } else { + $fileName = md5($userName); + $filePath = PROJECT_DIR . '/cache/image/' . $fileName . '.jpeg'; + + if (!file_exists($filePath)) { + + $icon = new Icon(); + $image = $icon->generateImageResource($fileName, 42, 42, false); + + file_put_contents($filePath, $image); + } + + $image = file_get_contents($filePath); + $response = [ - 'success' => false, - 'message' => _('Could not receive avatar details'), - 'avatar' => false + 'success' => true, + 'message' => _('Avatar successfully received from Identity'), + 'avatar' => 'data:image/jpeg;base64,' . base64_encode($image) ]; } diff --git a/src/application/controller/api/user/profile.php b/src/application/controller/api/user/profile.php index 2cbccc1..13c1a6e 100644 --- a/src/application/controller/api/user/profile.php +++ b/src/application/controller/api/user/profile.php @@ -10,7 +10,15 @@ if (isset($_SESSION['userName'])) { $userName = isset($_GET['userName']) ? Filter::userName($_GET['userName']) : $_SESSION['userName']; - if ($userProfileVersions = $_twister->getDHT($userName, 'profile', 's')) { + if ($profile = $_memcache->get('api.user.profile.' . $userName)) { + + $response = [ + 'success' => true, + 'message' => _('Profile successfully received from Cache'), + 'profile' => $profile + ]; + + } else if ($userProfileVersions = $_twister->getDHT($userName, 'profile', 's')) { // Check user exists if ($userId = $_modelUser->getUserId($userName)) { @@ -43,20 +51,24 @@ if (isset($_SESSION['userName'])) { // Get latest version available if ($profileInfo = $_modelProfile->get($userId)) { + $profile = [ + 'userName' => $userName, + 'fullName' => $profileInfo['fullName'], + 'location' => $profileInfo['location'], + 'url' => $profileInfo['url'], + 'bitMessage' => $profileInfo['bitMessage'], + 'tox' => $profileInfo['tox'], + 'bio' => nl2br($profileInfo['bio']), + ]; + $response = [ 'success' => true, - 'message' => _('Profile successfully received'), - 'profile' => [ - 'userName' => $userName, - 'fullName' => $profileInfo['fullName'], - 'location' => $profileInfo['location'], - 'url' => $profileInfo['url'], - 'bitMessage' => $profileInfo['bitMessage'], - 'tox' => $profileInfo['tox'], - 'bio' => nl2br($profileInfo['bio']), - ] + 'message' => _('Profile successfully received from DHT'), + 'profile' => $profile ]; + $_memcache->set('api.user.profile.' . $userName, $profile, MEMCACHE_COMPRESS, MEMCACHE_DHT_PROFILE_TIMEOUT); + } else { $response = [ diff --git a/src/application/view/common/module/post.phtml b/src/application/view/common/module/post.phtml index 62a9a07..963ab9b 100644 --- a/src/application/view/common/module/post.phtml +++ b/src/application/view/common/module/post.phtml @@ -1,7 +1,7 @@
- +
diff --git a/src/config-default.php b/src/config-default.php index e8dd4cc..d46bc63 100644 --- a/src/config-default.php +++ b/src/config-default.php @@ -25,6 +25,9 @@ define('TWISTER_PASSWORD', ''); // MEMCACHE define('MEMCACHE_HOST', 'localhost'); define('MEMCACHE_PORT', 11211); +define('MEMCACHE_COMPRESS', false); +define('MEMCACHE_DHT_AVATAR_TIMEOUT', 3600); +define('MEMCACHE_DHT_PROFILE_TIMEOUT', 3600); // COMMON define('APPLICATION_ALLOW_REGISTRATION', true); diff --git a/src/public/css/template/default/module/feed.css b/src/public/css/template/default/module/feed.css index e353fe2..71b599b 100644 --- a/src/public/css/template/default/module/feed.css +++ b/src/public/css/template/default/module/feed.css @@ -25,6 +25,7 @@ border: 2px #fff solid; width: 46px; height: 46px; + display: none } .moduleFeed .item .message { diff --git a/src/public/css/template/default/module/following.css b/src/public/css/template/default/module/following.css index 5c3e8f4..e2d56bb 100644 --- a/src/public/css/template/default/module/following.css +++ b/src/public/css/template/default/module/following.css @@ -32,6 +32,7 @@ border: 2px #fff solid; width: 16px; height: 16px; + display: none } .moduleFollowing .item .action { diff --git a/src/public/css/template/default/module/post.css b/src/public/css/template/default/module/post.css index 272a1e6..8c7110d 100644 --- a/src/public/css/template/default/module/post.css +++ b/src/public/css/template/default/module/post.css @@ -17,6 +17,7 @@ border: 2px #fff solid; width: 46px; height: 46px; + display: none } .modulePost .message { diff --git a/src/public/js/module/feed.js b/src/public/js/module/feed.js index 3a276df..6a80ad7 100644 --- a/src/public/js/module/feed.js +++ b/src/public/js/module/feed.js @@ -38,7 +38,7 @@ var ModuleFeed = { 'href': 'people/' + userName }).append( $('', { - 'src': '/api/image?hash=' + userName, + 'src': '', 'alt': '', }) ) @@ -83,7 +83,7 @@ var ModuleFeed = { if (response.success) { if (response.avatar) { - $(feed).find('div[data-username="' + userName + '"] .avatar img').attr('src', response.avatar); + $(feed).find('div[data-username="' + userName + '"] .avatar img').attr('src', response.avatar).show(); } } else { diff --git a/src/public/js/module/following.js b/src/public/js/module/following.js index a74624a..4592af7 100644 --- a/src/public/js/module/following.js +++ b/src/public/js/module/following.js @@ -15,7 +15,7 @@ var ModuleFollowing = { 'href': 'people/' + userName }).append( $('', { - 'src': '/api/image?hash=' + userName, + 'src': '', 'alt': '', }) ) @@ -94,7 +94,7 @@ var ModuleFollowing = { } }, error: function(jqXHR, textStatus, errorThrown) { - console.log(textStatus, errorThrown); + console.log(textStatus, errorThrown); } }); }, @@ -110,7 +110,7 @@ var ModuleFollowing = { if (response.success) { if (response.avatar) { - $(list).find('div[data-username="' + userName + '"] .avatar img').attr('src', response.avatar); + $(list).find('div[data-username="' + userName + '"] .avatar img').attr('src', response.avatar).show(); } } else { @@ -120,7 +120,7 @@ var ModuleFollowing = { } }, error: function(jqXHR, textStatus, errorThrown) { - console.log(textStatus, errorThrown); + console.log(textStatus, errorThrown); } }); }, @@ -149,7 +149,7 @@ var ModuleFollowing = { } }, error: function(jqXHR, textStatus, errorThrown) { - console.log(textStatus, errorThrown); + console.log(textStatus, errorThrown); } }); }, @@ -176,7 +176,7 @@ var ModuleFollowing = { } }, error: function(jqXHR, textStatus, errorThrown) { - console.log(textStatus, errorThrown); + console.log(textStatus, errorThrown); } }); }, diff --git a/src/public/js/module/post.js b/src/public/js/module/post.js index b30bc02..bb52b2f 100644 --- a/src/public/js/module/post.js +++ b/src/public/js/module/post.js @@ -11,7 +11,7 @@ var ModulePost = { if (response.success) { if (response.avatar) { - $(element).find('img').attr('src', response.avatar); + $(element).find('img').attr('src', response.avatar).show(); } } else { @@ -27,7 +27,7 @@ var ModulePost = { }, add: function() { - var input = $('#modulePost > .message > textarea'); + var input = $('#modulePost > .message > textarea'); $.ajax({ url: 'api/post/add', diff --git a/src/public/js/module/users.js b/src/public/js/module/users.js index 6f23f81..e453f72 100644 --- a/src/public/js/module/users.js +++ b/src/public/js/module/users.js @@ -14,7 +14,7 @@ var ModuleUsers = { 'href': 'people/' + userName }).append( $('', { - 'src': '/api/image?hash=' + userName, + 'src': '', 'alt': '', }) )