Browse Source

Added userpic history

master
Igor Zhukov 11 years ago
parent
commit
fcfe613339
  1. 6
      app/css/app.css
  2. 177
      app/js/controllers.js
  3. 99
      app/js/services.js
  4. 2
      app/partials/confirm_modal.html
  5. 3
      app/partials/error_modal.html
  6. 2
      app/partials/peer_select.html
  7. 6
      app/partials/photo_modal.html
  8. 4
      app/partials/settings_modal.html
  9. 4
      app/partials/user_modal.html

6
app/css/app.css

@ -38,6 +38,10 @@ a:hover {
a:hover { a:hover {
cursor: pointer; cursor: pointer;
} }
a.disabled {
cursor: default;
pointer-events: none;
}
.form-control { .form-control {
color: #000; color: #000;
border: 1px solid #d9dbde; border: 1px solid #d9dbde;
@ -2039,9 +2043,9 @@ img.img_fullsize {
margin-bottom: 15px; margin-bottom: 15px;
} }
.user_modal_image_wrap { .user_modal_image_wrap {
display: block;
width: 100px; width: 100px;
margin-right: 22px; margin-right: 22px;
display: block;
overflow: hidden; overflow: hidden;
border-radius: 3px; border-radius: 3px;
} }

177
app/js/controllers.js

@ -1017,6 +1017,7 @@ angular.module('myApp.controllers', [])
if (searchCachedResult.history.indexOf($scope.messageID) >= 0) { if (searchCachedResult.history.indexOf($scope.messageID) >= 0) {
list = searchCachedResult.history; list = searchCachedResult.history;
maxID = list[list.length - 1]; maxID = list[list.length - 1];
hasMore = list.length < searchCachedResult.count;
updatePrevNext(); updatePrevNext();
} }
@ -1052,7 +1053,7 @@ angular.module('myApp.controllers', [])
maxID = searchResult.history[searchResult.history.length - 1]; maxID = searchResult.history[searchResult.history.length - 1];
list = list.concat(searchResult.history); list = list.concat(searchResult.history);
hasMore = searchResult.history.length || list.length < searchResult.count; hasMore = list.length < searchResult.count;
updatePrevNext(); updatePrevNext();
loadingPromise = false; loadingPromise = false;
}); });
@ -1062,6 +1063,7 @@ angular.module('myApp.controllers', [])
var index = list.indexOf($scope.messageID); var index = list.indexOf($scope.messageID);
$scope.nav.hasNext = index > 0; $scope.nav.hasNext = index > 0;
$scope.nav.hasPrev = hasMore || index < list.length - 1; $scope.nav.hasPrev = hasMore || index < list.length - 1;
$scope.canForward = $scope.canDelete = $scope.messageID > 0;
}; };
$scope.nav.next = function () { $scope.nav.next = function () {
@ -1125,6 +1127,116 @@ angular.module('myApp.controllers', [])
}) })
.controller('UserpicModalController', function ($q, $scope, $rootScope, $modalInstance, AppPhotosManager, AppUsersManager, AppPeersManager, AppMessagesManager, PeersSelectService, ErrorService) {
$scope.photo = AppPhotosManager.wrapForFull($scope.photoID);
$scope.nav = {};
$scope.canForward = true;
var inputUser = AppUsersManager.getUserInput($scope.userID),
list = [$scope.photoID],
maxID = $scope.photoID,
hasMore = true;
updatePrevNext();
AppPhotosManager.getUserPhotos(inputUser, 0, 1000).then(function (userpicCachedResult) {
if (userpicCachedResult.photos.indexOf($scope.photoID) >= 0) {
list = userpicCachedResult.photos;
maxID = list[list.length - 1];
hasMore = list.length < userpicCachedResult.count;
updatePrevNext();
}
});
var jump = 0;
function movePosition (sign) {
var curIndex = list.indexOf($scope.photoID),
index = curIndex >= 0 ? curIndex + sign : 0,
curJump = ++jump;
var promise = index >= list.length ? loadMore() : $q.when();
promise.then(function () {
if (curJump != jump) {
return;
}
$scope.photoID = list[index];
$scope.photo = AppPhotosManager.wrapForFull($scope.photoID);
updatePrevNext();
});
};
var loadingPromise = false;
function loadMore () {
if (loadingPromise) return loadingPromise;
return loadingPromise = AppPhotosManager.getUserPhotos(inputUser, maxID).then(function (userpicResult) {
maxID = userpicResult.photos[userpicResult.photos.length - 1];
list = list.concat(userpicResult.photos);
hasMore = list.length < userpicResult.count;
updatePrevNext();
loadingPromise = false;
}, function () {
loadingPromise = false;
});
};
function updatePrevNext () {
var index = list.indexOf($scope.photoID);
$scope.nav.hasNext = index > 0;
$scope.nav.hasPrev = hasMore || index < list.length - 1;
};
$scope.nav.next = function () {
if (!$scope.nav.hasNext) {
return false;
}
movePosition(-1);
};
$scope.nav.prev = function () {
if (!$scope.nav.hasPrev) {
return false;
}
movePosition(+1);
};
$scope.forward = function () {
var messageID = $scope.photoID;
PeersSelectService.selectPeer({confirm_type: 'FORWARD_PEER'}).then(function (peerString) {
var peerID = AppPeersManager.getPeerID(peerString);
AppMessagesManager.sendOther(peerID, {
_: 'inputMediaPhoto',
id: {
_: 'inputPhoto',
id: $scope.photoID,
access_hash: $scope.photo.access_hash,
}
});
$rootScope.$broadcast('history_focus', {peerString: peerString});
});
};
$scope.delete = function () {
var messageID = $scope.photoID;
ErrorService.confirm({type: 'MESSAGE_DELETE'}).then(function () {
AppMessagesManager.deleteMessages([messageID]);
});
};
$scope.download = function () {
AppPhotosManager.downloadPhoto($scope.photoID);
};
})
.controller('VideoModalController', function ($scope, $rootScope, $modalInstance, PeersSelectService, AppMessagesManager, AppVideoManager, AppPeersManager, ErrorService) { .controller('VideoModalController', function ($scope, $rootScope, $modalInstance, PeersSelectService, AppMessagesManager, AppVideoManager, AppPeersManager, ErrorService) {
$scope.video = AppVideoManager.wrapForFull($scope.videoID); $scope.video = AppVideoManager.wrapForFull($scope.videoID);
@ -1156,7 +1268,7 @@ angular.module('myApp.controllers', [])
}); });
}) })
.controller('UserModalController', function ($scope, $location, $rootScope, $modal, AppUsersManager, NotificationsManager, AppMessagesManager, AppPeersManager, PeersSelectService, ErrorService) { .controller('UserModalController', function ($scope, $location, $rootScope, $modal, AppUsersManager, MtpApiManager, NotificationsManager, AppPhotosManager, AppMessagesManager, AppPeersManager, PeersSelectService, ErrorService) {
var peerString = AppUsersManager.getUserString($scope.userID); var peerString = AppUsersManager.getUserString($scope.userID);
@ -1165,20 +1277,31 @@ angular.module('myApp.controllers', [])
$scope.settings = {notifications: true}; $scope.settings = {notifications: true};
NotificationsManager.getPeerMuted($scope.userID).then(function (muted) { MtpApiManager.invokeApi('users.getFullUser', {
$scope.settings.notifications = !muted; id: AppUsersManager.getUserInput($scope.userID)
}).then(function (userFullResult) {
AppUsersManager.saveApiUser(userFullResult.user);
AppPhotosManager.savePhoto(userFullResult.profile_photo);
if (userFullResult.profile_photo._ != 'photoEmpty') {
$scope.userPhoto.id = userFullResult.profile_photo.id;
}
$scope.$watch('settings.notifications', function(newValue, oldValue) { NotificationsManager.savePeerSettings($scope.userID, userFullResult.notify_settings);
if (newValue === oldValue) { NotificationsManager.getPeerMuted($scope.userID).then(function (muted) {
return false; $scope.settings.notifications = !muted;
}
NotificationsManager.getPeerSettings($scope.userID).then(function (settings) { $scope.$watch('settings.notifications', function(newValue, oldValue) {
if (newValue) { if (newValue === oldValue) {
settings.mute_until = 0; return false;
} else {
settings.mute_until = 2000000000;
} }
NotificationsManager.updatePeerSettings($scope.userID, settings); NotificationsManager.getPeerSettings($scope.userID).then(function (settings) {
if (newValue) {
settings.mute_until = 0;
} else {
settings.mute_until = 2000000000;
}
NotificationsManager.updatePeerSettings($scope.userID, settings);
});
}); });
}); });
}); });
@ -1409,7 +1532,7 @@ angular.module('myApp.controllers', [])
}) })
.controller('SettingsModalController', function ($rootScope, $scope, $timeout, $modal, AppUsersManager, AppChatsManager, MtpApiManager, AppConfigManager, NotificationsManager, MtpApiFileManager, ApiUpdatesManager, ChangelogNotifyService, ErrorService) { .controller('SettingsModalController', function ($rootScope, $scope, $timeout, $modal, AppUsersManager, AppChatsManager, AppPhotosManager, MtpApiManager, AppConfigManager, NotificationsManager, MtpApiFileManager, ApiUpdatesManager, ChangelogNotifyService, ErrorService) {
$scope.profile = {}; $scope.profile = {};
$scope.photo = {}; $scope.photo = {};
@ -1420,6 +1543,16 @@ angular.module('myApp.controllers', [])
$scope.photo = AppUsersManager.getUserPhoto(id, 'User'); $scope.photo = AppUsersManager.getUserPhoto(id, 'User');
}); });
MtpApiManager.invokeApi('users.getFullUser', {
id: {_: 'inputUserSelf'}
}).then(function (userFullResult) {
AppUsersManager.saveApiUser(userFullResult.user);
AppPhotosManager.savePhoto(userFullResult.profile_photo);
if (userFullResult.profile_photo._ != 'photoEmpty') {
$scope.photo.id = userFullResult.profile_photo.id;
}
});
$scope.notify = {}; $scope.notify = {};
$scope.send = {}; $scope.send = {};
@ -1550,11 +1683,11 @@ angular.module('myApp.controllers', [])
} }
$rootScope.$broadcast('settings_changed'); $rootScope.$broadcast('settings_changed');
} }
$scope.openChangelog = function () {
ChangelogNotifyService.showChangelog(false);
}
}); });
$scope.openChangelog = function () {
ChangelogNotifyService.showChangelog(false);
}
}) })
.controller('ProfileEditModalController', function ($rootScope, $scope, $timeout, $modal, $modalInstance, AppUsersManager, AppChatsManager, MtpApiManager, AppConfigManager, NotificationsManager, MtpApiFileManager, ApiUpdatesManager) { .controller('ProfileEditModalController', function ($rootScope, $scope, $timeout, $modal, $modalInstance, AppUsersManager, AppChatsManager, MtpApiManager, AppConfigManager, NotificationsManager, MtpApiFileManager, ApiUpdatesManager) {
@ -1599,7 +1732,7 @@ angular.module('myApp.controllers', [])
} }
}) })
.controller('ContactsModalController', function ($scope, $modal, $modalInstance, AppUsersManager) { .controller('ContactsModalController', function ($scope, $modal, $modalInstance, AppUsersManager, ErrorService) {
$scope.contacts = []; $scope.contacts = [];
$scope.search = {}; $scope.search = {};
@ -1678,6 +1811,10 @@ angular.module('myApp.controllers', [])
}).result.then(function (foundUserID) { }).result.then(function (foundUserID) {
if (foundUserID) { if (foundUserID) {
updateContacts($scope.search && $scope.search.query || ''); updateContacts($scope.search && $scope.search.query || '');
} else {
ErrorService.show({
error: {code: 404, type: 'USER_NOT_USING_TELEGRAM'}
});
} }
}); });
}; };

99
app/js/services.js

@ -380,6 +380,7 @@ angular.module('myApp.services', [])
saveApiUsers: saveApiUsers, saveApiUsers: saveApiUsers,
saveApiUser: saveApiUser, saveApiUser: saveApiUser,
getUser: getUser, getUser: getUser,
getUserInput: getUserInput,
getUserPhoto: getUserPhoto, getUserPhoto: getUserPhoto,
getUserString: getUserString, getUserString: getUserString,
getUserSearchText: getUserSearchText, getUserSearchText: getUserSearchText,
@ -1410,6 +1411,10 @@ angular.module('myApp.services', [])
case 'inputMediaContact': case 'inputMediaContact':
media = angular.extend({}, inputMedia, {_: 'messageMediaContact'}); media = angular.extend({}, inputMedia, {_: 'messageMediaContact'});
break; break;
case 'inputMediaPhoto':
media = {photo: AppPhotosManager.getPhoto(inputMedia.id.id)};
break;
} }
var message = { var message = {
@ -1982,7 +1987,7 @@ angular.module('myApp.services', [])
} }
}) })
.service('AppPhotosManager', function ($modal, $window, $timeout, $rootScope, MtpApiFileManager, AppUsersManager) { .service('AppPhotosManager', function ($modal, $window, $timeout, $rootScope, MtpApiManager, MtpApiFileManager, AppUsersManager) {
var photos = {}; var photos = {};
function savePhoto (apiPhoto) { function savePhoto (apiPhoto) {
@ -2016,6 +2021,56 @@ angular.module('myApp.services', [])
return bestPhotoSize; return bestPhotoSize;
} }
function getUserPhotos (inputUser, maxID, limit) {
return MtpApiManager.invokeApi('photos.getUserPhotos', {
user_id: inputUser,
offset: 0,
limit: limit || 20,
max_id: maxID || 0
}).then(function (photosResult) {
AppUsersManager.saveApiUsers(photosResult.users);
var photoIDs = [];
for (var i = 0; i < photosResult.photos.length; i++) {
savePhoto(photosResult.photos[i]);
photoIDs.push(photosResult.photos[i].id)
}
return {
count: photosResult.count || photosResult.photos.length,
photos: photoIDs
};
});
}
function preloadPhoto (photoID) {
if (!photos[photoID]) {
return;
}
var photo = photos[photoID],
fullWidth = $(window).width() - 36,
fullHeight = $($window).height() - 150,
fullPhotoSize = choosePhotoSize(photo, fullWidth, fullHeight);
if (fullPhotoSize && !fullPhotoSize.preloaded) {
fullPhotoSize.preloaded = true;
if (fullPhotoSize.size) {
MtpApiFileManager.downloadFile(fullPhotoSize.location.dc_id, {
_: 'inputFileLocation',
volume_id: fullPhotoSize.location.volume_id,
local_id: fullPhotoSize.location.local_id,
secret: fullPhotoSize.location.secret
}, fullPhotoSize.size);
} else {
MtpApiFileManager.downloadSmallFile(fullPhotoSize.location);
}
}
};
$rootScope.preloadPhoto = preloadPhoto;
function getPhoto (photoID) {
return photos[photoID] || {_: 'photoEmpty'};
}
function wrapForHistory (photoID) { function wrapForHistory (photoID) {
var photo = angular.copy(photos[photoID]) || {_: 'photoEmpty'}, var photo = angular.copy(photos[photoID]) || {_: 'photoEmpty'},
width = 260, width = 260,
@ -2047,31 +2102,6 @@ angular.module('myApp.services', [])
return photo; return photo;
} }
function preloadPhoto (photoID) {
if (!photos[photoID]) {
return;
}
var photo = photos[photoID],
fullWidth = $(window).width() - 36,
fullHeight = $($window).height() - 150,
fullPhotoSize = choosePhotoSize(photo, fullWidth, fullHeight);
if (fullPhotoSize && !fullPhotoSize.preloaded) {
fullPhotoSize.preloaded = true;
if (fullPhotoSize.size) {
MtpApiFileManager.downloadFile(fullPhotoSize.location.dc_id, {
_: 'inputFileLocation',
volume_id: fullPhotoSize.location.volume_id,
local_id: fullPhotoSize.location.local_id,
secret: fullPhotoSize.location.secret
}, fullPhotoSize.size);
} else {
MtpApiFileManager.downloadSmallFile(fullPhotoSize.location);
}
}
};
$rootScope.preloadPhoto = preloadPhoto;
function wrapForFull (photoID) { function wrapForFull (photoID) {
var photo = wrapForHistory(photoID), var photo = wrapForHistory(photoID),
fullWidth = $(window).width() - 36, fullWidth = $(window).width() - 36,
@ -2117,14 +2147,23 @@ angular.module('myApp.services', [])
return photo; return photo;
} }
function openPhoto (photoID, messageID) { function openPhoto (photoID, peerListID) {
if (!photoID || photoID === '0') {
return false;
}
var scope = $rootScope.$new(true); var scope = $rootScope.$new(true);
scope.photoID = photoID; scope.photoID = photoID;
scope.messageID = messageID; if (peerListID < 0) {
scope.userID = -peerListID;
} else{
scope.messageID = peerListID;
}
var modalInstance = $modal.open({ var modalInstance = $modal.open({
templateUrl: 'partials/photo_modal.html', templateUrl: 'partials/photo_modal.html',
controller: 'PhotoModalController', controller: scope.userID ? 'UserpicModalController' : 'PhotoModalController',
scope: scope, scope: scope,
windowClass: 'photo_modal_window' windowClass: 'photo_modal_window'
}); });
@ -2195,6 +2234,8 @@ angular.module('myApp.services', [])
return { return {
savePhoto: savePhoto, savePhoto: savePhoto,
preloadPhoto: preloadPhoto, preloadPhoto: preloadPhoto,
getUserPhotos: getUserPhotos,
getPhoto: getPhoto,
wrapForHistory: wrapForHistory, wrapForHistory: wrapForHistory,
wrapForFull: wrapForFull, wrapForFull: wrapForFull,
openPhoto: openPhoto, openPhoto: openPhoto,

2
app/partials/confirm_modal.html

@ -42,7 +42,7 @@
<a class="btn btn-link" ng-click="$dismiss()" ng-switch="type"> <a class="btn btn-link" ng-click="$dismiss()" ng-switch="type">
<span ng-switch-default>Cancel</span> <span ng-switch-default>Cancel</span>
</a> </a>
<button type="button" class="btn btn-primary" ng-switch="type" ng-click="$close()"> <button type="button" class="btn btn-primary" ng-switch="type" ng-click="$close()" my-focused>
<span ng-switch-when="LOGOUT">Log Out</span> <span ng-switch-when="LOGOUT">Log Out</span>
<span ng-switch-when="HISTORY_FLUSH">Delete Chat</span> <span ng-switch-when="HISTORY_FLUSH">Delete Chat</span>
<span ng-switch-when="FILES_CLIPBOARD_PASTE">Send</span> <span ng-switch-when="FILES_CLIPBOARD_PASTE">Send</span>

3
app/partials/error_modal.html

@ -47,6 +47,9 @@
Sorry, there is no <strong>Telegram</strong> account for {{phone | phoneNumber}}<br/><br/> Sorry, there is no <strong>Telegram</strong> account for {{phone | phoneNumber}}<br/><br/>
Please <strong>sign up</strong> using our mobile apps for <a href="https://telegram.org/" target="_blank">iOS</a> or <a href="https://telegram.org/" target="_blank">Android</a>. Please <strong>sign up</strong> using our mobile apps for <a href="https://telegram.org/" target="_blank">iOS</a> or <a href="https://telegram.org/" target="_blank">Android</a>.
</span> </span>
<span ng-switch-when="USER_NOT_USING_TELEGRAM">
Sorry, there is no <strong>Telegram</strong> account with the phone number you provided.
</span>
<div ng-switch-default ng-switch="error.code"> <div ng-switch-default ng-switch="error.code">

2
app/partials/peer_select.html

@ -2,7 +2,7 @@
<div class="modal-body"> <div class="modal-body">
<div class="im_dialogs_modal_col_wrap" ng-controller="AppImDialogsController"> <div class="im_dialogs_modal_col_wrap" ng-controller="AppImDialogsController" my-dialogs>
<div class="im_dialogs_panel"> <div class="im_dialogs_panel">
<div class="im_dialogs_search"> <div class="im_dialogs_search">
<input my-focused class="form-control im_dialogs_search_field" type="search" placeholder="Search" ng-model="search.query"/> <input my-focused class="form-control im_dialogs_search_field" type="search" placeholder="Search" ng-model="search.query"/>

6
app/partials/photo_modal.html

@ -4,10 +4,10 @@
<div class="photo_modal_image_wrap" my-load-full-photo full-photo="photo.full" thumb-location="photo.thumb.location" ng-click="nav.next()"> </div> <div class="photo_modal_image_wrap" my-load-full-photo full-photo="photo.full" thumb-location="photo.thumb.location" ng-click="nav.next()"> </div>
<div class="media_modal_actions pull-right" ng-if="messageID"> <div class="media_modal_actions pull-right">
<a href="" class="media_modal_action_link" ng-click="download()">Download</a> <a href="" class="media_modal_action_link" ng-click="download()">Download</a>
<a href="" class="media_modal_action_link" ng-click="forward()">Forward</a> <a href="" class="media_modal_action_link" ng-if="canForward" ng-click="forward()">Forward</a>
<a href="" class="media_modal_action_link" ng-click="delete()">Delete</a> <a href="" class="media_modal_action_link" ng-if="canDelete" ng-click="delete()">Delete</a>
</div> </div>
<p class="media_modal_info"> <p class="media_modal_info">

4
app/partials/settings_modal.html

@ -6,13 +6,13 @@
<div class="user_modal_photo_profile_wrap"> <div class="user_modal_photo_profile_wrap">
<div class="user_modal_image_wrap pull-left"> <a href="" ng-click="openPhoto(photo.id, -profile.id)" class="user_modal_image_wrap pull-left" ng-class="{disabled: !photo.id}">
<img <img
class="user_modal_image" class="user_modal_image"
my-load-thumb my-load-thumb
thumb="photo" thumb="photo"
/> />
</div> </a>
<div class="user_modal_info_wrap clearfix"> <div class="user_modal_info_wrap clearfix">
<h4 class="user_modal_header" ng-bind-html="profile.rFullName"></h4> <h4 class="user_modal_header" ng-bind-html="profile.rFullName"></h4>

4
app/partials/user_modal.html

@ -6,13 +6,13 @@
<div class="user_modal_photo_profile_wrap"> <div class="user_modal_photo_profile_wrap">
<div class="user_modal_image_wrap pull-left"> <a href="" ng-click="openPhoto(userPhoto.id, -user.id)" class="user_modal_image_wrap pull-left" ng-class="{disabled: !userPhoto.id}">
<img <img
class="user_modal_image" class="user_modal_image"
my-load-thumb my-load-thumb
thumb="userPhoto" thumb="userPhoto"
/> />
</div> </a>
<div class="user_modal_info_wrap clearfix"> <div class="user_modal_info_wrap clearfix">
<h4 class="user_modal_header" ng-bind="user | userName"></h4> <h4 class="user_modal_header" ng-bind="user | userName"></h4>

Loading…
Cancel
Save