Browse Source

Updated schema

Supported new service message actions
Improved update status
master
Igor Zhukov 9 years ago
parent
commit
1dec3c9451
  1. 6
      app/js/controllers.js
  2. 10
      app/js/directives.js
  3. 4
      app/js/locales/en-us.json
  4. 72
      app/js/messages_manager.js
  5. 21
      app/js/services.js
  6. 1
      app/less/app.less
  7. 24
      app/partials/desktop/dialog_service.html
  8. 24
      app/partials/desktop/message_service.html
  9. 24
      app/partials/mobile/message_service.html

6
app/js/controllers.js

@ -1241,7 +1241,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -1241,7 +1241,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
AppPeersManager.isChannel(peerID) &&
(channel = AppChatsManager.getChat(-peerID))) {
var canSend = channel.pFlags.creator || channel.pFlags.editor;
var canSend = AppChatsManager.hasRights(-peerID, 'send');
if (!canSend) {
if (channel.pFlags.left) {
$scope.historyState.channelActions = 'join';
@ -2217,7 +2217,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2217,7 +2217,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
// console.log(dT(), 'reset draft', $scope.curDialog.peer, forceDraft);
if (forceDraft) {
if (forceDraft == $scope.curDialog.peer) {
$scope.draftMessage.isBroadcast = AppPeersManager.isChannel($scope.curDialog.peerID);
$scope.draftMessage.isBroadcast = AppPeersManager.isChannel($scope.curDialog.peerID) && !AppPeersManager.isMegagroup($scope.curDialog.peerID);
$scope.$broadcast('ui_peer_draft');
return;
} else {
@ -2231,7 +2231,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2231,7 +2231,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
Storage.get('draft' + $scope.curDialog.peerID).then(function (draftText) {
// console.log('Restore draft', 'draft' + $scope.curDialog.peerID, draftText);
$scope.draftMessage.text = draftText || '';
$scope.draftMessage.isBroadcast = AppPeersManager.isChannel($scope.curDialog.peerID);
$scope.draftMessage.isBroadcast = AppPeersManager.isChannel($scope.curDialog.peerID) && !AppPeersManager.isMegagroup($scope.curDialog.peerID);
// console.log('send broadcast', $scope.draftMessage);
$scope.$broadcast('ui_peer_draft');
});

10
app/js/directives.js

@ -2519,7 +2519,7 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -2519,7 +2519,7 @@ angular.module('myApp.directives', ['myApp.filters'])
})
.directive('myUserStatus', function ($filter, AppUsersManager) {
.directive('myUserStatus', function ($filter, $rootScope, AppUsersManager) {
var statusFilter = $filter('userStatus'),
ind = 0,
@ -2527,6 +2527,13 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -2527,6 +2527,13 @@ angular.module('myApp.directives', ['myApp.filters'])
setInterval(updateAll, 90000);
$rootScope.$on('stateSynchronized', function () {
setTimeout(function () {
updateAll();
}, 100);
});
return {
link: link
};
@ -2545,6 +2552,7 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -2545,6 +2552,7 @@ angular.module('myApp.directives', ['myApp.filters'])
element
.html(statusFilter(user, attrs.botChatPrivacy))
.toggleClass('status_online', user.status && user.status._ == 'userStatusOnline' || false);
// console.log(dT(), 'update status', element[0], user.status && user.status, tsNow(true), element.html());
};
$scope.$watch(attrs.myUserStatus, function (newUserID) {

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

@ -283,11 +283,13 @@ @@ -283,11 +283,13 @@
"conversation_group_photo_removed": "removed group photo",
"conversation_returned_to_group": "returned to group",
"conversation_invited_user": "invited {user}",
"conversation_invited_users": "{'one': 'invited {} user', 'other': 'invited {} users'}",
"conversation_left_group": "left group",
"conversation_kicked_user": "removed {user}",
"conversation_invited_user_message": "invited user",
"conversation_kicked_user_message": "removed user",
"conversation_joined_by_link": "joined group",
"conversation_converted_to_supergroup": "upgraded to a supergroup",
"conversation_created_channel": "Channel created",
"conversation_changed_channel_name": "Channel renamed",
"conversation_changed_channel_photo": "Channel photo updated",
@ -304,12 +306,14 @@ @@ -304,12 +306,14 @@
"message_service_changed_group_photo": "changed group photo",
"message_service_removed_group_photo": "removed group photo",
"message_service_invited_user": "invited {user}",
"message_service_invited_users": "invited {user} and {num-more} more",
"message_service_returned_to_group": "returned to group",
"message_service_kicked_user": "removed {user}",
"message_service_left_group": "left group",
"message_service_joined_by_link": "joined group via invite link",
"message_service_unsupported_action": "unsupported action {action}",
"message_service_bot_intro_header": "What can this bot do?",
"message_service_converted_to_supergroup": "upgraded the group to a supergroup",
"message_service_created_channel": "Channel created",
"message_service_changed_channel_name": "Channel renamed to {channel-name}",
"message_service_changed_channel_photo": "Channel photo updated",

72
app/js/messages_manager.js

@ -152,9 +152,9 @@ angular.module('myApp.services') @@ -152,9 +152,9 @@ angular.module('myApp.services')
var mid = getFullMessageID(dialog.top_message, channelID);
} else {
var mid = getFullMessageID(dialog.top_important_message, channelID);
dialog.top_message = mid;
dialog.unread_count = dialog.unread_important_count;
}
dialog.unread_count = dialog.unread_important_count;
dialog.top_message = mid;
dialog.read_inbox_max_id = getFullMessageID(dialog.read_inbox_max_id, channelID);
var message = getMessage(dialog.top_message);
@ -207,7 +207,6 @@ angular.module('myApp.services') @@ -207,7 +207,6 @@ angular.module('myApp.services')
}, {
timeout: 300
}).then(function (dialogsResult) {
console.log('dialogs result', dialogsResult);
if (!offsetDate) {
TelegramMeWebService.setAuthorized(true);
}
@ -315,8 +314,10 @@ angular.module('myApp.services') @@ -315,8 +314,10 @@ angular.module('myApp.services')
function requestHistory (inputPeer, maxID, limit, offset) {
var peerID = AppPeersManager.getPeerID(inputPeer);
var isChannel = AppPeersManager.isChannel(peerID);
var isMegagroup = isChannel && AppPeersManager.isMegagroup(peerID);
var promise;
if (isChannel) {
if (isChannel && !isMegagroup) {
promise = MtpApiManager.invokeApi('channels.getImportantHistory', {
channel: AppChatsManager.getChannelInput(-peerID),
offset_id: maxID ? getMessageLocalID(maxID) : 0,
@ -1070,6 +1071,7 @@ angular.module('myApp.services') @@ -1070,6 +1071,7 @@ angular.module('myApp.services')
var toPeerID = AppPeersManager.getPeerID(apiMessage.to_id);
var isChannel = apiMessage.to_id._ == 'peerChannel';
var channelID = isChannel ? -toPeerID : 0;
var isBroadcast = isChannel && !AppChatsManager.isMegagroup(channelID);
var mid = getFullMessageID(apiMessage.id, channelID);
apiMessage.mid = mid;
@ -1124,19 +1126,43 @@ angular.module('myApp.services') @@ -1124,19 +1126,43 @@ angular.module('myApp.services')
}
}
if (apiMessage.action) {
if (apiMessage.action._ == 'messageActionChatEditPhoto') {
AppPhotosManager.savePhoto(apiMessage.action.photo, mediaContext);
if (isChannel) {
apiMessage.action._ = 'messageActionChannelEditPhoto';
}
}
else if (isChannel) {
if (apiMessage.action._ == 'messageActionChatEditTitle') {
apiMessage.action._ = 'messageActionChannelEditTitle';
}
if (apiMessage.action._ == 'messageActionChatDeletePhoto') {
apiMessage.action._ = 'messageActionChannelDeletePhoto';
}
switch (apiMessage.action._) {
case 'messageActionChatEditPhoto':
AppPhotosManager.savePhoto(apiMessage.action.photo, mediaContext);
if (isBroadcast) {
apiMessage.action._ = 'messageActionChannelEditPhoto';
}
break;
case 'messageActionChatEditTitle':
if (isBroadcast) {
apiMessage.action._ = 'messageActionChannelEditTitle';
}
break;
case 'messageActionChatDeletePhoto':
if (isBroadcast) {
apiMessage.action._ = 'messageActionChannelDeletePhoto';
}
break;
case 'messageActionChatAddUser':
if (apiMessage.action.users.length == 1) {
apiMessage.action.user_id = apiMessage.action.users[0];
if (apiMessage.fromID == apiMessage.action.user_id) {
apiMessage.action._ = 'messageActionChatReturn';
}
}
else if (apiMessage.action.users.length > 1) {
apiMessage.action._ = 'messageActionChatAddUsers';
}
break;
case 'messageActionChatDeleteUser':
if (apiMessage.fromID == apiMessage.action.user_id) {
apiMessage.action._ = 'messageActionChatLeave';
}
break;
}
}
@ -1162,7 +1188,8 @@ angular.module('myApp.services') @@ -1162,7 +1188,8 @@ angular.module('myApp.services')
pFlags = {},
replyToMsgID = options.replyToMsgID,
isChannel = AppPeersManager.isChannel(peerID),
asChannel = isChannel ? true : false,
isMegagroup = isChannel && AppPeersManager.isMegagroup(peerID),
asChannel = isChannel && !isMegagroup ? true : false,
entities = [],
message;
@ -1303,7 +1330,8 @@ angular.module('myApp.services') @@ -1303,7 +1330,8 @@ angular.module('myApp.services')
pFlags = {},
replyToMsgID = options.replyToMsgID,
isChannel = AppPeersManager.isChannel(peerID),
asChannel = isChannel ? true : false,
isMegagroup = isChannel && AppPeersManager.isMegagroup(peerID),
asChannel = isChannel && !isMegagroup ? true : false,
attachType, apiFileName, realFileName;
if (!options.isMedia) {
@ -1489,7 +1517,8 @@ angular.module('myApp.services') @@ -1489,7 +1517,8 @@ angular.module('myApp.services')
inputPeer = AppPeersManager.getInputPeerByID(peerID),
replyToMsgID = options.replyToMsgID,
isChannel = AppPeersManager.isChannel(peerID),
asChannel = isChannel ? true : false;
isMegagroup = isChannel && AppPeersManager.isMegagroup(peerID),
asChannel = isChannel && !isMegagroup ? true : false;
if (historyStorage === undefined) {
historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []};
@ -1622,7 +1651,8 @@ angular.module('myApp.services') @@ -1622,7 +1651,8 @@ angular.module('myApp.services')
var i, mid, msgID;
var fromChannel = getMessageIDInfo(mids[0])[1];
var isChannel = AppPeersManager.isChannel(peerID);
var asChannel = isChannel ? true : false;
var isMegagroup = isChannel && AppPeersManager.isMegagroup(peerID);
var asChannel = isChannel && !isMegagroup ? true : false;
if (asChannel) {
flags |= 16;

21
app/js/services.js

@ -442,6 +442,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -442,6 +442,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
setInterval(updateUsersStatuses, 60000);
$rootScope.$on('stateSynchronized', updateUsersStatuses);
return {
getContacts: getContacts,
@ -556,6 +557,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -556,6 +557,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
var chats = {},
usernames = {},
channelAccess = {},
megagroups = {},
cachedPhotoLocations = {};
function saveApiChats (apiChats) {
@ -612,7 +614,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -612,7 +614,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return false;
}
if (isChannel(id) && action == 'send') {
if (!chat.pFlags.creator && !chat.pFlags.editor) {
if (!chat.pFlags.megagroup &&
!chat.pFlags.creator &&
!chat.pFlags.editor) {
return false;
}
}
@ -627,6 +631,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -627,6 +631,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
channelAccess[id] = accessHash;
}
function saveIsMegagroup (id) {
megagroups[id] = true;
}
function isChannel (id) {
var chat = chats[id];
if (chat && (chat._ == 'channel' || chat._ == 'channelForbidden') ||
@ -637,6 +645,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -637,6 +645,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
function isMegagroup (id) {
if (megagroups[id]) {
return true;
}
var chat = chats[id];
if (chat && chat._ == 'channel' && chat.pFlags.megagroup) {
return true;
@ -679,7 +690,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -679,7 +690,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
function getChatString (id) {
var chat = getChat(id);
if (isChannel(id)) {
return 'c' + id + '_' + chat.access_hash;
return (isMegagroup(id) ? 's' : 'c') + id + '_' + chat.access_hash;
}
return 'g' + id;
}
@ -763,6 +774,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -763,6 +774,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
isMegagroup: isMegagroup,
hasRights: hasRights,
saveChannelAccess: saveChannelAccess,
saveIsMegagroup: saveIsMegagroup,
getChatInput: getChatInput,
getChannelInput: getChannelInput,
getChatPhoto: getChatPhoto,
@ -787,8 +799,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -787,8 +799,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
access_hash: peerParams[1]
};
}
else if (firstChar == 'c') {
else if (firstChar == 'c' || firstChar == 's') {
AppChatsManager.saveChannelAccess(peerParams[0], peerParams[1]);
if (firstChar == 's') {
AppChatsManager.saveIsMegagroup(peerParams[0]);
}
return {
_: 'inputPeerChannel',
channel_id: peerParams[0],

1
app/less/app.less

@ -3012,6 +3012,7 @@ _:-ms-lang(x), .composer_rich_textarea:empty:focus:before { @@ -3012,6 +3012,7 @@ _:-ms-lang(x), .composer_rich_textarea:empty:focus:before {
padding: 20px 0;
font-size: 14px;
line-height: 160%;
word-break: break-all;
}
.confirm_phone_number {
font-weight: bold;

24
app/partials/desktop/dialog_service.html

@ -3,20 +3,22 @@ @@ -3,20 +3,22 @@
<span ng-switch-when="messageActionChatEditTitle" my-i18n="conversation_group_renamed"></span>
<span ng-switch-when="messageActionChatEditPhoto" my-i18n="conversation_group_photo_updated"></span>
<span ng-switch-when="messageActionChatDeletePhoto" my-i18n="conversation_group_photo_removed"></span>
<span ng-switch-when="messageActionChatAddUser" ng-switch="::message.fromID != message.action.user_id">
<span ng-switch-when="true" my-i18n="conversation_invited_user">
<span ng-switch-when="messageActionChatJoinedByLink" my-i18n="conversation_joined_by_link"></span>
<span ng-switch-when="messageActionChatReturn" my-i18n="conversation_returned_to_group"></span>
<span ng-switch-when="messageActionChatAddUser" my-i18n="conversation_invited_user">
<my-i18n-param name="user"><span my-peer-link="message.action.user_id"></span></my-i18n-param>
</span>
<span ng-switch-default my-i18n="conversation_returned_to_group"></span>
</span>
<span ng-switch-when="messageActionChatDeleteUser" ng-switch="::message.fromID != message.action.user_id">
<span ng-switch-when="true" my-i18n="conversation_kicked_user">
<my-i18n-param name="user"><span my-peer-link="message.action.user_id"></span></my-i18n-param>
</span>
<span ng-switch-default my-i18n="conversation_left_group"></span>
<span ng-switch-when="messageActionChatAddUsers" my-i18n="">
<ng-pluralize count="message.action.users.length"
when="conversation_invited_users">
</ng-pluralize>
</span>
<span ng-switch-when="messageActionChatJoinedByLink" my-i18n="conversation_joined_by_link"></span>
<span ng-switch-when="messageActionChatLeave" my-i18n="conversation_left_group"></span>
<span ng-switch-when="messageActionChatDeleteUser" my-i18n="conversation_kicked_user">
<my-i18n-param name="user"><span my-peer-link="message.action.user_id"></span></my-i18n-param>
</span>
<span ng-switch-when="messageActionChatMigrateTo" my-i18n="conversation_converted_to_supergroup"></span>
<span ng-switch-when="messageActionChannelMigrateFrom" my-i18n="conversation_converted_to_supergroup"></span>
<span ng-switch-when="messageActionChannelCreate" my-i18n="conversation_created_channel"></span>
<span ng-switch-when="messageActionChannelEditTitle" my-i18n="conversation_changed_channel_name"></span>
<span ng-switch-when="messageActionChannelEditPhoto" my-i18n="conversation_changed_channel_photo"></span>

24
app/partials/desktop/message_service.html

@ -6,20 +6,22 @@ @@ -6,20 +6,22 @@
</my-i18n>
<span ng-switch-when="messageActionChatEditPhoto" my-i18n="message_service_changed_group_photo"></span>
<span ng-switch-when="messageActionChatDeletePhoto" my-i18n="message_service_removed_group_photo"></span>
<span ng-switch-when="messageActionChatAddUser" ng-switch="::historyMessage.fromID != historyMessage.action.user_id">
<span ng-switch-when="true" my-i18n="message_service_invited_user">
<my-i18n-param name="user"><a my-peer-link="historyMessage.action.user_id" color="true"></a></my-i18n-param>
</span>
<span ng-switch-default my-i18n="message_service_returned_to_group"></span>
<span ng-switch-when="messageActionChatJoinedByLink" my-i18n="message_service_joined_by_link"></span>
<span ng-switch-when="messageActionChatReturn" my-i18n="message_service_returned_to_group"></span>
<span ng-switch-when="messageActionChatAddUser" my-i18n="message_service_invited_user">
<my-i18n-param name="user"><a my-peer-link="historyMessage.action.user_id" color="true"></a></my-i18n-param>
</span>
<span ng-switch-when="messageActionChatDeleteUser" ng-switch="::historyMessage.fromID != historyMessage.action.user_id">
<span ng-switch-when="true" my-i18n="message_service_kicked_user">
<my-i18n-param name="user"><a my-peer-link="historyMessage.action.user_id" color="true"></a></my-i18n-param>
</span>
<span ng-switch-default my-i18n="message_service_left_group"></span>
<span ng-switch-when="messageActionChatAddUsers" my-i18n="message_service_invited_users">
<my-i18n-param name="user"><a my-peer-link="historyMessage.action.user_id" color="true"></a></my-i18n-param>
<my-i18n-param name="num-more"><span ng-bind="historyMessage.action.users.length - 1"></span></my-i18n-param>
</span>
<span ng-switch-when="messageActionChatLeave" my-i18n="message_service_left_group"></span>
<span ng-switch-when="messageActionChatDeleteUser" my-i18n="message_service_kicked_user">
<my-i18n-param name="user"><a my-peer-link="historyMessage.action.user_id" color="true"></a></my-i18n-param>
</span>
<span ng-switch-when="messageActionChatJoinedByLink" my-i18n="message_service_joined_by_link"></span>
<span ng-switch-when="messageActionChatMigrateTo" my-i18n="message_service_converted_to_supergroup"></span>
<span ng-switch-when="messageActionChannelMigrateFrom" my-i18n="message_service_converted_to_supergroup"></span>
<span ng-switch-when="messageActionChannelCreate" my-i18n="message_service_created_channel"></span>
<span ng-switch-when="messageActionChannelEditTitle" my-i18n="message_service_changed_channel_name">
<my-i18n-param name="channel-name">&laquo;<strong ng-bind-html="::historyMessage.action.rTitle"></strong>&raquo;</my-i18n-param>

24
app/partials/mobile/message_service.html

@ -6,20 +6,22 @@ @@ -6,20 +6,22 @@
</my-i18n>
<span ng-switch-when="messageActionChatEditPhoto" my-i18n="message_service_changed_group_photo"></span>
<span ng-switch-when="messageActionChatDeletePhoto" my-i18n="message_service_removed_group_photo"></span>
<span ng-switch-when="messageActionChatAddUser" ng-switch="::historyMessage.fromID != historyMessage.action.user_id">
<span ng-switch-when="true" my-i18n="message_service_invited_user">
<my-i18n-param name="user"><a my-peer-link="historyMessage.action.user_id" color="true"></a></my-i18n-param>
</span>
<span ng-switch-default my-i18n="message_service_returned_to_group"></span>
<span ng-switch-when="messageActionChatJoinedByLink" my-i18n="message_service_joined_by_link"></span>
<span ng-switch-when="messageActionChatReturn" my-i18n="message_service_returned_to_group"></span>
<span ng-switch-when="messageActionChatAddUser" my-i18n="message_service_invited_user">
<my-i18n-param name="user"><a my-peer-link="historyMessage.action.user_id" color="true"></a></my-i18n-param>
</span>
<span ng-switch-when="messageActionChatDeleteUser" ng-switch="::historyMessage.fromID != historyMessage.action.user_id">
<span ng-switch-when="true" my-i18n="message_service_kicked_user">
<my-i18n-param name="user"><a my-peer-link="historyMessage.action.user_id" color="true"></a></my-i18n-param>
</span>
<span ng-switch-default my-i18n="message_service_left_group"></span>
<span ng-switch-when="messageActionChatAddUsers" my-i18n="message_service_invited_users">
<my-i18n-param name="user"><a my-peer-link="historyMessage.action.user_id" color="true"></a></my-i18n-param>
<my-i18n-param name="num-more"><span ng-bind="historyMessage.action.users.length - 1"></span></my-i18n-param>
</span>
<span ng-switch-when="messageActionChatLeave" my-i18n="message_service_left_group"></span>
<span ng-switch-when="messageActionChatDeleteUser" my-i18n="message_service_kicked_user">
<my-i18n-param name="user"><a my-peer-link="historyMessage.action.user_id" color="true"></a></my-i18n-param>
</span>
<span ng-switch-when="messageActionChatJoinedByLink" my-i18n="message_service_joined_by_link"></span>
<span ng-switch-when="messageActionChatMigrateTo" my-i18n="message_service_converted_to_supergroup"></span>
<span ng-switch-when="messageActionChannelMigrateFrom" my-i18n="message_service_converted_to_supergroup"></span>
<span ng-switch-when="messageActionChannelCreate" my-i18n="message_service_created_channel"></span>
<span ng-switch-when="messageActionChannelEditTitle" my-i18n="message_service_changed_channel_name">
<my-i18n-param name="channel-name">&laquo;<strong ng-bind-html="::historyMessage.action.rTitle"></strong>&raquo;</my-i18n-param>

Loading…
Cancel
Save