Browse Source

BotsManager draft

master
Igor Zhukov 10 years ago
parent
commit
092aaf3395
  1. 12
      app/js/controllers.js
  2. 42
      app/js/services.js

12
app/js/controllers.js

@ -2512,9 +2512,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.settings = {notifications: true}; $scope.settings = {notifications: true};
MtpApiManager.invokeApi('users.getFullUser', { AppUsersManager.getUserFull($scope.userID).then(function (userFullResult) {
id: AppUsersManager.getUserInput($scope.userID)
}).then(function (userFullResult) {
if ($scope.override && $scope.override.phone_number) { if ($scope.override && $scope.override.phone_number) {
userFullResult.user.phone = $scope.override.phone_number; userFullResult.user.phone = $scope.override.phone_number;
if ($scope.override.first_name || $scope.override.last_name) { if ($scope.override.first_name || $scope.override.last_name) {
@ -2522,8 +2520,6 @@ angular.module('myApp.controllers', ['myApp.i18n'])
userFullResult.user.last_name = $scope.override.last_name; userFullResult.user.last_name = $scope.override.last_name;
} }
AppUsersManager.saveApiUser(userFullResult.user); AppUsersManager.saveApiUser(userFullResult.user);
} else {
AppUsersManager.saveApiUser(userFullResult.user, true);
} }
AppPhotosManager.savePhoto(userFullResult.profile_photo); AppPhotosManager.savePhoto(userFullResult.profile_photo);
$scope.blocked = userFullResult.blocked; $scope.blocked = userFullResult.blocked;
@ -2537,11 +2533,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
return false; return false;
} }
NotificationsManager.getPeerSettings($scope.userID).then(function (settings) { NotificationsManager.getPeerSettings($scope.userID).then(function (settings) {
if (newValue) { settings.mute_until = newValue ? 0 : 2000000000;
settings.mute_until = 0;
} else {
settings.mute_until = 2000000000;
}
NotificationsManager.updatePeerSettings($scope.userID, settings); NotificationsManager.updatePeerSettings($scope.userID, settings);
}); });
}); });

42
app/js/services.js

@ -171,7 +171,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
case 'userStatusLastWeek': case 'userStatusLastWeek':
return tsNow(true) + serverTimeOffset - 86400 * 7; return tsNow(true) + serverTimeOffset - 86400 * 7;
case 'userStatusLastMonth': case 'userStatusLastMonth':
return tsNow(true) + serverTimeOffset - 86400 * 30; return tsNow(true) + serverTimeOffset - 86400 * 30;
} }
} }
@ -185,6 +185,15 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return users[id] || {id: id, deleted: true, num: 1}; return users[id] || {id: id, deleted: true, num: 1};
} }
function getUserFull (id) {
return MtpApiManager.invokeApi('users.getFullUser', {
id: getUserInput(id)
}).then(function (userFullResult) {
saveApiUser(userFullResult.user, true);
return userFullResult;
});
}
function getSelf() { function getSelf() {
return getUser(myID); return getUser(myID);
} }
@ -451,6 +460,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
getUserString: getUserString, getUserString: getUserString,
getUserSearchText: getUserSearchText, getUserSearchText: getUserSearchText,
hasUser: hasUser, hasUser: hasUser,
getUserFull: getUserFull,
importContact: importContact, importContact: importContact,
importContacts: importContacts, importContacts: importContacts,
deleteContacts: deleteContacts, deleteContacts: deleteContacts,
@ -823,6 +833,36 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} }
}) })
.service('AppBotsManager', function (AppUsersManager, AppChatsManager) {
return {
getPeerBots: function (peerID) {
var peerBots = [];
if (peerID > 0) {
var user = AppUsersManager.getUser(peerID);
if (!user.pFlags.bot) {
return $q.when(peerBots);
}
return AppUsersManager.getUserFull(peerID).then(function (userFull) {
var botInfo = userFull.bot_info;
if (botInfo && botInfo._ != 'botInfoEmpty') {
peerBots.push(botInfo);
}
return peerBots;
});
}
return AppChatsManager.getFullChat(-peerID).then(function (chatFull) {
angular.forEach(chatFull.bot_info, function (botInfo) {
peerBots.push(botInfo);
});
return peerBots;
});
}
};
})
.service('AppMessagesManager', function ($q, $rootScope, $location, $filter, $timeout, $sce, ApiUpdatesManager, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, AppVideoManager, AppDocsManager, AppAudioManager, AppWebPagesManager, MtpApiManager, MtpApiFileManager, RichTextProcessor, NotificationsManager, PeersSelectService, Storage, FileManager, TelegramMeWebService, ErrorService, StatusManager, _) { .service('AppMessagesManager', function ($q, $rootScope, $location, $filter, $timeout, $sce, ApiUpdatesManager, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, AppVideoManager, AppDocsManager, AppAudioManager, AppWebPagesManager, MtpApiManager, MtpApiFileManager, RichTextProcessor, NotificationsManager, PeersSelectService, Storage, FileManager, TelegramMeWebService, ErrorService, StatusManager, _) {
var messagesStorage = {}; var messagesStorage = {};

Loading…
Cancel
Save