Browse Source

Improved channels error handling

master
Igor Zhukov 9 years ago
parent
commit
7ab5650f99
  1. 22
      app/js/controllers.js
  2. 3
      app/js/locales/en-us.json
  3. 21
      app/js/messages_manager.js
  4. 29
      app/js/services.js
  5. 3
      app/partials/desktop/confirm_modal.html
  6. 5
      app/partials/desktop/error_modal.html
  7. 15
      app/partials/desktop/im.html

22
app/js/controllers.js

@ -620,7 +620,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -620,7 +620,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.dialogs = [];
$scope.contacts = [];
$scope.foundUsers = [];
$scope.foundPeers = [];
$scope.foundMessages = [];
if ($scope.search === undefined) {
@ -854,7 +854,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -854,7 +854,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (!searchMessages) {
$scope.dialogs = [];
$scope.contacts = [];
$scope.foundUsers = [];
$scope.foundPeers = [];
}
$scope.foundMessages = [];
@ -966,15 +966,16 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -966,15 +966,16 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (curJump != contactsJump) return;
MtpApiManager.invokeApi('contacts.search', {q: $scope.search.query, limit: 10}).then(function (result) {
AppUsersManager.saveApiUsers(result.users);
AppChatsManager.saveApiChats(result.chats);
if (curJump != contactsJump) return;
$scope.foundUsers = [];
$scope.foundPeers = [];
angular.forEach(result.results, function(contactFound) {
var userID = contactFound.user_id;
if (peersInDialogs[userID] === undefined) {
$scope.foundUsers.push({
userID: userID,
user: AppUsersManager.getUser(userID),
peerString: AppUsersManager.getUserString(userID)
var peerID = AppPeersManager.getPeerID(contactFound);
if (peersInDialogs[peerID] === undefined) {
$scope.foundPeers.push({
id: peerID,
username: AppPeersManager.getPeer(peerID).username,
peerString: AppUsersManager.getUserString(peerID)
});
}
});
@ -1726,6 +1727,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -1726,6 +1727,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (updPeerID == $scope.curDialog.peerID) {
$location.url('/im');
}
historiesQueuePop(updPeerID);
});
$scope.$on('notify_settings', function (e, data) {
@ -3926,7 +3928,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -3926,7 +3928,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
.controller('ContactsModalController', function ($scope, $timeout, $modal, $modalInstance, MtpApiManager, AppUsersManager, ErrorService) {
$scope.contacts = [];
$scope.foundUsers = [];
$scope.foundPeers = [];
$scope.search = {};
$scope.slice = {limit: 20, limitDelta: 20};

3
app/js/locales/en-us.json

@ -217,6 +217,7 @@ @@ -217,6 +217,7 @@
"confirm_modal_abort_password_setup": "Abort two-step verification setup?",
"confirm_modal_reset_account_md": "Are you sure?\nThis action can not be undone.\n\nYou will lose all your chats and messages, along with any media and files you shared, if you proceed with resetting your account.",
"confirm_modal_join_group_link": "Do you want to join the group «{title}»?",
"confirm_modal_join_channel_link": "Do you want to join the channel «{title}»?",
"confirm_modal_revoke_group_link": "Are you sure you want to revoke this link? Once you do, no one will be able to join the group using it.",
"confirm_modal_revoke_channel_link": "Are you sure you want to revoke this link? Once you do, no one will be able to join the channel using it.",
"confirm_modal_delete_channel_md": "Are you sure you want to delete this channel?\n\nAll messages will be removed and all messages will be lost.",
@ -363,6 +364,8 @@ @@ -363,6 +364,8 @@
"error_modal_password_disabled_descripion": "You have disabled Two-Step Verification.",
"error_modal_user_not_mutual_contact": "The user can be invited by his contact only",
"error_modal_invite_link_invalid": "The invite link is invalid",
"error_modal_channel_not_accessible": "Sorry, this channel is not accessible.",
"error_modal_not_contact_flood": "Sorry, you can only send messages to mutual contacts at the moment. {more-info-link: More info »}",
"head_telegram": "Telegram",

21
app/js/messages_manager.js

@ -314,7 +314,7 @@ angular.module('myApp.services') @@ -314,7 +314,7 @@ angular.module('myApp.services')
offset_id: maxID ? getMessageLocalID(maxID) : 0,
add_offset: offset || 0,
limit: limit || 0
}, {noErrorBox: true});
});
} else {
promise = MtpApiManager.invokeApi('messages.getHistory', {
peer: inputPeer,
@ -365,6 +365,23 @@ angular.module('myApp.services') @@ -365,6 +365,23 @@ angular.module('myApp.services')
}
return historyResult;
});
}, function (error) {
switch (error.type) {
case 'CHANNEL_PRIVATE':
var channel = AppChatsManager.getChat(-peerID);
channel = {_: 'channelForbidden', access_hash: channel.access_hash, title: channel.title};
ApiUpdatesManager.processUpdateMessage({
_: 'updates',
updates: [{
_: 'updateChannel',
channel_id: -peerID
}],
chats: [channel],
users: []
});
break;
}
return $q.reject(error);
});
}
@ -1599,7 +1616,7 @@ angular.module('myApp.services') @@ -1599,7 +1616,7 @@ angular.module('myApp.services')
chatTitle = chatInvite.title;
}
ErrorService.confirm({
type: 'JOIN_GROUP_BY_LINK',
type: chatInvite.flags & 1 ? 'JOIN_CHANNEL_BY_LINK' : 'JOIN_GROUP_BY_LINK',
title: chatTitle
}).then(function () {
return MtpApiManager.invokeApi('messages.importChatInvite', {

29
app/js/services.js

@ -418,9 +418,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -418,9 +418,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
case 'updateUserPhoto':
var userID = update.user_id;
if (users[userID]) {
var user = users[userID];
if (user) {
forceUserOnline(userID);
safeReplaceObject(users[userID].photo, update.photo);
if (!user.photo) {
user.photo = update.photo;
} else {
safeReplaceObject(user.photo, update.photo);
}
if (cachedPhotoLocations[userID] !== undefined) {
safeReplaceObject(cachedPhotoLocations[userID], update.photo && update.photo.photo_small || {empty: true});
@ -619,7 +624,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -619,7 +624,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
function isChannel (id) {
var chat = chats[id];
if (chat && chat._ == 'channel' ||
if (chat && (chat._ == 'channel' || chat._ == 'channelForbidden') ||
channelAccess[id]) {
return true;
}
@ -965,7 +970,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -965,7 +970,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
})
.service('AppProfileManager', function ($q, $rootScope, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, NotificationsManager, MtpApiManager, RichTextProcessor) {
.service('AppProfileManager', function ($q, $rootScope, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, NotificationsManager, MtpApiManager, ApiUpdatesManager, RichTextProcessor) {
var botInfos = {};
var chatsFull = {};
@ -1129,6 +1134,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1129,6 +1134,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return fullChannel;
});
}, function (error) {
switch (error.type) {
case 'CHANNEL_PRIVATE':
var channel = AppChatsManager.getChat(id);
channel = {_: 'channelForbidden', access_hash: channel.access_hash, title: channel.title};
ApiUpdatesManager.processUpdateMessage({
_: 'updates',
updates: [{
_: 'updateChannel',
channel_id: id
}],
chats: [channel],
users: []
});
break;
}
});
}

3
app/partials/desktop/confirm_modal.html

@ -48,6 +48,9 @@ @@ -48,6 +48,9 @@
<div ng-switch-when="JOIN_GROUP_BY_LINK" my-i18n="confirm_modal_join_group_link">
<my-i18n-param name="title"><strong ng-bind="title"></strong></my-i18n-param>
</div>
<div ng-switch-when="JOIN_CHANNEL_BY_LINK" my-i18n="confirm_modal_join_channel_link">
<my-i18n-param name="title"><strong ng-bind="title"></strong></my-i18n-param>
</div>
<div ng-switch-when="REVOKE_GROUP_INVITE_LINK" my-i18n="confirm_modal_revoke_group_link"></div>
<div ng-switch-when="REVOKE_CHANNEL_INVITE_LINK" my-i18n="confirm_modal_revoke_channel_link"></div>
<div ng-switch-when="CHANNEL_DELETE" my-i18n="confirm_modal_delete_channel_md"></div>

5
app/partials/desktop/error_modal.html

@ -42,7 +42,10 @@ @@ -42,7 +42,10 @@
<span ng-switch-when="INVITE_HASH_INVALID" my-i18n="error_modal_invite_link_invalid"></span>
<span ng-switch-when="INVITE_HASH_EXPIRED" my-i18n="error_modal_invite_link_invalid"></span>
<span ng-switch-when="INVITE_HASH_EMPTY" my-i18n="error_modal_invite_link_invalid"></span>
<span ng-switch-when="CHANNEL_PRIVATE" my-i18n="error_modal_channel_not_accessible"></span>
<span ng-switch-when="PEER_FLOOD" my-i18n="error_modal_not_contact_flood">
<my-i18n-param name="more-info-link"><a href="https://telegram.org/faq#can-39t-send-messages-to-non-contacts" target="_blank">{0}</a></my-i18n-param>
</span>
<div ng-switch-default ng-switch="error.code">

15
app/partials/desktop/im.html

@ -48,19 +48,18 @@ @@ -48,19 +48,18 @@
</ul>
</div>
<div class="im_dialogs_contacts_wrap" ng-show="foundUsers.length > 0">
<div class="im_dialogs_contacts_wrap" ng-show="foundPeers.length > 0">
<h5 my-i18n="im_found_title"></h5>
<ul class="nav nav-pills nav-stacked">
<li class="im_dialog_wrap" ng-repeat="foundUser in foundUsers track by foundUser.userID" ng-class="{active: curDialog.peerID == foundUser.userID}">
<a class="im_dialog" ng-mousedown="dialogSelect(foundUser.peerString)">
<div class="im_dialog_photo pull-left" my-peer-photolink="foundUser.userID" img-class="im_dialog_photo" watch="true"></div>
<li class="im_dialog_wrap" ng-repeat="foundPeer in foundPeers track by foundPeer.id" ng-class="{active: curDialog.peerID == foundPeer.id}">
<a class="im_dialog" ng-mousedown="dialogSelect(foundPeer.peerString)">
<div class="im_dialog_photo pull-left" my-peer-photolink="foundPeer.id" img-class="im_dialog_photo" watch="true"></div>
<div class="im_dialog_message_wrap">
<div class="im_dialog_peer">
<span class="im_dialog_user" my-peer-link="foundUser.userID"></span>
<span class="im_dialog_user" my-peer-link="foundPeer.id"></span>
</div>
<div class="im_dialog_message" ng-switch="foundUser.user.username.length > 0">
<span ng-switch-when="true" class="im_dialog_message_text" ng-bind="::'@' + foundUser.user.username"></span>
<span ng-switch-default class="im_dialog_message_text" my-user-status="::foundUser.userID"></span>
<div class="im_dialog_message">
<span class="im_dialog_message_text" ng-bind="::'@' + foundPeer.username"></span>
</div>
</div>
</a>

Loading…
Cancel
Save