Browse Source

supported all service channel messages and conversations

master
Igor Zhukov 9 years ago
parent
commit
5aa5a1d9a2
  1. 12
      app/js/controllers.js
  2. 9
      app/js/directives.js
  3. 9
      app/js/locales/en-us.json
  4. 110
      app/js/services.js
  5. 24
      app/partials/desktop/dialog.html
  6. 24
      app/partials/desktop/dialog_service.html
  7. 3
      app/partials/desktop/message_service.html
  8. 25
      app/partials/desktop/reply_message.html

12
app/js/controllers.js

@ -419,13 +419,8 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -419,13 +419,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$broadcast(peerData.messageID ? 'ui_history_change_scroll' : 'ui_history_focus');
} else {
var peerID = AppPeersManager.getPeerID(peerData.peerString);
var peer = peerData.peerString;
if (peerID > 0) {
var username = AppUsersManager.getUser(peerID).username;
if (username) {
peer = '@' + username;
}
}
var username = AppPeersManager.getPeer(peerID).username;
var peer = username ? '@' + username : peerData.peerString;
if (peerData.messageID || peerData.startParam) {
pendingParams = {
messageID: peerData.messageID,
@ -836,6 +831,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -836,6 +831,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
function loadDialogs (force) {
offsetIndex = 0;
maxID = 0;
hasMore = false;
if (!searchMessages) {
peersInDialogs = {};
@ -2104,7 +2100,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2104,7 +2100,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (replyKeyboard) {
replyKeyboard = AppMessagesManager.wrapReplyMarkup(replyKeyboard);
}
console.log('update reply markup', peerID, replyKeyboard);
// console.log('update reply markup', peerID, replyKeyboard);
$scope.historyState.replyKeyboard = replyKeyboard;
var addReplyMessage =

9
app/js/directives.js

@ -328,6 +328,15 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -328,6 +328,15 @@ angular.module('myApp.directives', ['myApp.filters'])
};
})
.directive('myServiceShortMessage', function() {
return {
scope: {
message: '=myServiceShortMessage'
},
templateUrl: templateUrl('dialog_service')
};
})
.directive('myReplyMessage', function(AppPhotosManager, AppMessagesManager, AppPeersManager, $rootScope) {
return {

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

@ -256,6 +256,7 @@ @@ -256,6 +256,7 @@
"conversation_media_location": "Location",
"conversation_media_contact": "Contact",
"conversation_media_attachment": "Attachment",
"conversation_group_created": "created the group",
"conversation_group_renamed": "changed group name",
"conversation_group_photo_updated": "changed group photo",
@ -267,6 +268,11 @@ @@ -267,6 +268,11 @@
"conversation_invited_user_message": "invited user",
"conversation_kicked_user_message": "removed user",
"conversation_joined_by_link": "joined group",
"conversation_created_channel": "Channel created",
"conversation_changed_channel_name": "Channel renamed",
"conversation_changed_channel_photo": "Channel photo updated",
"conversation_removed_channel_photo": "Channel photo removed",
"conversation_message_sent": "sent you a message",
"conversation_forwarded_X_messages": "{'one': 'forwarded {} message', 'other': 'forwarded {} messages'}",
@ -284,7 +290,8 @@ @@ -284,7 +290,8 @@
"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_created_channel": "Channel {channel-name} created",
"message_service_created_channel": "Channel created",
"message_service_changed_channel_name": "Channel renamed to {channel-name}",
"message_service_changed_channel_photo": "Channel photo updated",
"message_service_removed_channel_photo": "Channel photo removed",

110
app/js/services.js

@ -794,8 +794,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -794,8 +794,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
.service('AppPeersManager', function (qSync, AppUsersManager, AppChatsManager, MtpApiManager) {
var usernames = {};
function getInputPeer (peerString) {
var firstChar = peerString.charAt(0),
peerParams = peerString.substr(1).split('_');
@ -921,6 +919,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -921,6 +919,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
: AppChatsManager.getChatPhoto(-peerID, chatPlaceholder)
}
function isChannel (peerID) {
return (peerID < 0) && AppChatsManager.isChannel(-peerID);
}
function isBot (peerID) {
return (peerID > 0) && AppUsersManager.isBot(peerID);
}
return {
getInputPeer: getInputPeer,
getInputPeerByID: getInputPeerByID,
@ -931,7 +937,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -931,7 +937,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
getPeer: getPeer,
getPeerPhoto: getPeerPhoto,
resolveUsername: resolveUsername,
usernames: usernames
isChannel: isChannel,
isBot: isBot
}
})
@ -1123,7 +1130,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1123,7 +1130,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
return $q.all([getAllChannels(), getTopMessages(loadedDialogsCount, limit)]).then(function () {
console.log(curDialogStorage);
offset = 0;
if (offsetIndex > 0) {
for (offset = 0; offset < curDialogStorage.dialogs.length; offset++) {
@ -1132,10 +1138,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1132,10 +1138,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
}
}
console.log(curDialogStorage.dialogs.slice(offset, offset + limit));
return {
// count: curDialogStorage.count,
dialogs: curDialogStorage.dialogs.slice(offset, offset + limit)
}
});
@ -1168,12 +1171,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1168,12 +1171,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
var peerText = AppPeersManager.getPeerSearchText(peerID);
SearchIndexManager.indexObject(peerID, peerText, dialogsIndex);
dialog.top_message = dialog.top_important_message;
var messageID = dialog.top_important_message;
dialog.top_message = peerID + '_' + messageID;
var message = getMessage(peerID + '_' + dialog.top_message);
var message = getMessage(dialog.top_message);
var topDate = message.date;
var channel = AppChatsManager.getChat(-peerID);
if (channel.date > topDate) {
if (!topDate || channel.date && channel.date > topDate) {
topDate = channel.date;
}
@ -1183,7 +1187,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1183,7 +1187,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
pushDialogToStorage(dialog);
if (historiesStorage[peerID] === undefined) {
var historyStorage = {count: null, history: [dialog.top_message], pending: []};
var historyStorage = {count: null, history: [messageID], pending: []};
historiesStorage[peerID] = historyStorage;
}
@ -1200,6 +1204,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1200,6 +1204,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}).then(function (dialogsResult) {
TelegramMeWebService.setAuthorized(true);
// Server-side bug
if (dialogsResult.count && offset >= dialogsResult.count) {
dialogsResult.dialogs = [];
}
AppUsersManager.saveApiUsers(dialogsResult.users);
AppChatsManager.saveApiChats(dialogsResult.chats);
saveMessages(dialogsResult.messages);
@ -1219,9 +1228,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1219,9 +1228,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
var message = getMessage(dialog.top_message);
dialog.index = generateDialogIndex(message.date);
if (dialog.index < 0) {
console.log('ind', dialog.index, message.date);
}
dialog.peerID = peerID;
pushDialogToStorage(dialog);
@ -1258,7 +1264,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1258,7 +1264,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
if (date === undefined) {
date = tsNow(true) + serverTimeOffset;
}
return (date * 65536) + ((++dialogsNum) & 0xFFFF);
return (date * 0x10000) + ((++dialogsNum) & 0xFFFF);
}
function pushDialogToStorage (dialog) {
@ -1278,15 +1284,12 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1278,15 +1284,12 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
var i, len = dialogs.length;
if (!len) {
if (!len || index < dialogs[len - 1].index) {
dialogs.push(dialog);
}
else if (index >= dialogs[0].index) {
dialogs.unshift(dialog);
}
else if (index < dialogs[len - 1].index) {
dialogs.push(dialog);
}
else {
for (i = 0; i < len; i++) {
if (index > dialogs[i].index) {
@ -1298,17 +1301,29 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1298,17 +1301,29 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
function requestHistory (inputPeer, maxID, limit, offset) {
return MtpApiManager.invokeApi('messages.getHistory', {
var peerID = AppPeersManager.getPeerID(inputPeer);
var promise;
if (AppPeersManager.isChannel(peerID)) {
promise = MtpApiManager.invokeApi('channels.getImportantHistory', {
peer: inputPeer,
offset_id: maxID || 0,
add_offset: offset || 0,
limit: limit || 0
}, {noErrorBox: true});
} else {
promise = MtpApiManager.invokeApi('messages.getHistory', {
peer: inputPeer,
offset_id: maxID || 0,
add_offset: offset || 0,
limit: limit || 0,
offset_id: maxID || 0
}, {noErrorBox: true}).then(function (historyResult) {
limit: limit || 0
}, {noErrorBox: true});
}
return promise.then(function (historyResult) {
AppUsersManager.saveApiUsers(historyResult.users);
AppChatsManager.saveApiChats(historyResult.chats);
saveMessages(historyResult.messages);
var peerID = AppPeersManager.getPeerID(inputPeer);
if (
peerID < 0 ||
!AppUsersManager.isBot(peerID) ||
@ -1850,24 +1865,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1850,24 +1865,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
apiMessage.out = apiMessage.flags & 2 ? true : false;
apiMessage.media_unread = apiMessage.flags & 32 ? true : false;
var toPeerID = AppPeersManager.getPeerID(apiMessage.to_id);
var isChannel = apiMessage.to_id._ == 'peerChannel';
var mid = isChannel ? toPeerID + '_' + apiMessage.id : apiMessage.id;
apiMessage.mid = mid;
messagesStorage[mid] = apiMessage;
apiMessage.date -= serverTimeOffset;
var toPeerID = AppPeersManager.getPeerID(apiMessage.to_id);
var isChannel = apiMessage.to_id._ == 'peerChannel';
apiMessage.toID = toPeerID;
apiMessage.fromID = apiMessage.from_id || toPeerID;
if (apiMessage.fwd_from_id) {
apiMessage.fwdFromID = AppPeersManager.getPeerID(apiMessage.fwd_from_id);
}
var mediaContext = {
user_id: apiMessage.from_id,
user_id: apiMessage.fromID,
date: apiMessage.date
};
@ -2643,7 +2656,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2643,7 +2656,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
var replyToMsgID = message.reply_to_msg_id;
if (replyToMsgID) {
if (messagesStorage[replyToMsgID]) {
if (messagesStorage[replyToMsgID] && false) {
message.reply_to_msg = wrapForDialog(replyToMsgID);
} else {
message.reply_to_msg = {id: replyToMsgID, loading: true};
@ -2803,8 +2816,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2803,8 +2816,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
options = options || {};
var peerID = getMessagePeer(message);
var fromUser = AppUsersManager.getUser(message.from_id);
var fromPhoto = AppUsersManager.getUserPhoto(message.from_id, 'User');
var peerString;
var notification = {},
notificationMessage = false,
@ -2843,10 +2854,15 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2843,10 +2854,15 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
} else if (message._ == 'messageService') {
switch (message.action._) {
case 'messageActionChatCreate': notificationMessage = _('conversation_group_created_raw'); break;
case 'messageActionChatEditTitle': notificationMessage = _('conversation_group_renamed_raw'); break;
case 'messageActionChatEditPhoto': notificationMessage = _('conversation_group_photo_updated_raw'); break;
case 'messageActionChatDeletePhoto': notificationMessage = _('conversation_group_photo_removed_raw'); break;
case 'messageActionChatCreate':
notificationMessage = _('conversation_group_created_raw');
break;
case 'messageActionChatEditTitle': notificationMessage = _('conversation_group_renamed_raw');
break;
case 'messageActionChatEditPhoto': notificationMessage = _('conversation_group_photo_updated_raw');
break;
case 'messageActionChatDeletePhoto': notificationMessage = _('conversation_group_photo_removed_raw');
break;
case 'messageActionChatAddUser':
notificationMessage = message.action.user_id == message.from_id ? _('conversation_returned_to_group') : _('conversation_invited_user_message_raw');
break;
@ -2856,10 +2872,26 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2856,10 +2872,26 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
case 'messageActionChatJoinedByLink':
notificationMessage = _('conversation_joined_by_link');
break;
case 'messageActionChannelCreate':
notificationMessage = _('conversation_created_channel');
break;
case 'messageActionChannelEditTitle':
notificationMessage = _('conversation_changed_channel_name');
break;
case 'messageActionChannelEditPhoto':
notificationMessage = _('conversation_changed_channel_photo');
break;
case 'messageActionChannelDeletePhoto':
notificationMessage = _('conversation_removed_channel_photo');
break;
}
}
if (peerID > 0) {
var fromUser = AppUsersManager.getUser(message.from_id);
var fromPhoto = AppUsersManager.getUserPhoto(message.from_id, 'User');
notification.title = (fromUser.first_name || '') +
(fromUser.first_name && fromUser.last_name ? ' ' : '') +
(fromUser.last_name || '');
@ -2872,9 +2904,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2872,9 +2904,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
peerString = AppUsersManager.getUserString(peerID);
} else {
notification.title = AppChatsManager.getChat(-peerID).title || _('conversation_unknown_chat_raw');
if (message.from_id > 0) {
notification.title = (fromUser.first_name || fromUser.last_name || _('conversation_unknown_user_raw')) +
' @ ' +
(AppChatsManager.getChat(-peerID).title || _('conversation_unknown_chat_raw'));
notification.title;
}
notificationPhoto = AppChatsManager.getChatPhoto(-peerID, 'Group');

24
app/partials/desktop/dialog.html

@ -73,29 +73,7 @@ @@ -73,29 +73,7 @@
<span ng-switch-when="messageMediaContact" my-i18n="conversation_media_contact"></span>
</span>
<span class="im_dialog_message_service" ng-if="dialogMessage._ == 'messageService'" ng-switch="dialogMessage.action._">
<span ng-switch-when="messageActionChatCreate" my-i18n="conversation_group_created"></span>
<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="dialogMessage.from_id == dialogMessage.action.user_id">
<span ng-switch-when="true" my-i18n="conversation_returned_to_group"></span>
<span ng-switch-default my-i18n="conversation_invited_user">
<my-i18n-param name="user"><span my-peer-link="dialogMessage.action.user_id"></span></my-i18n-param>
</span>
</span>
<span ng-switch-when="messageActionChatDeleteUser" ng-switch="dialogMessage.from_id == dialogMessage.action.user_id">
<span ng-switch-when="true" my-i18n="conversation_left_group"></span>
<span ng-switch-default my-i18n="conversation_kicked_user">
<my-i18n-param name="user"><span my-peer-link="dialogMessage.action.user_id"></span></my-i18n-param>
</span>
</span>
<span ng-switch-when="messageActionChatJoinedByLink" my-i18n="conversation_joined_by_link"></span>
</span>
<span class="im_dialog_message_service" ng-if="dialogMessage._ == 'messageService'" my-service-short-message="dialogMessage"></span>
<span class="im_dialog_message_text" ng-if="dialogMessage.message.length" ng-bind-html="dialogMessage.richMessage"></span>
</div>

24
app/partials/desktop/dialog_service.html

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
<span ng-switch="message.action._">
<span ng-switch-when="messageActionChatCreate" my-i18n="conversation_group_created"></span>
<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">
<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>
<span ng-switch-when="messageActionChatJoinedByLink" my-i18n="conversation_joined_by_link"></span>
<span ng-switch-when="messageActionChannelCreate" my-i18n-format="conversation_created_channel"></span>
<span ng-switch-when="messageActionChannelEditTitle" my-i18n-format="conversation_changed_channel_name"></span>
<span ng-switch-when="messageActionChannelEditPhoto" my-i18n="conversation_changed_channel_photo"></span>
<span ng-switch-when="messageActionChannelDeletePhoto" my-i18n="conversation_removed_channel_photo"></span>
</span>

3
app/partials/desktop/message_service.html

@ -20,7 +20,8 @@ @@ -20,7 +20,8 @@
</span>
<span ng-switch-when="messageActionChatJoinedByLink" my-i18n="message_service_joined_by_link"></span>
<span ng-switch-when="messageActionChannelCreate" my-i18n="message_service_created_channel">
<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>
</span>
<span ng-switch-when="messageActionChannelEditPhoto" my-i18n="message_service_changed_channel_photo"></span>

25
app/partials/desktop/reply_message.html

@ -28,32 +28,11 @@ @@ -28,32 +28,11 @@
</span>
<span ng-switch-when="messageMediaAudio" my-i18n="conversation_media_audio"></span>
<span ng-switch-when="messageMediaGeo" my-i18n="conversation_media_location"></span>
<span ng-switch-when="messageMediaVenue" my-i18n="conversation_media_location"></span>
<span ng-switch-when="messageMediaContact" my-i18n="conversation_media_contact"></span>
</span>
<span class="im_reply_message_service" ng-if="replyMessage._ == 'messageService'" ng-switch="replyMessage.action._">
<span ng-switch-when="messageActionChatCreate" my-i18n="conversation_group_created"></span>
<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="replyMessage.from_id == replyMessage.action.user_id">
<span ng-switch-when="true" my-i18n="conversation_returned_to_group"></span>
<span ng-switch-default my-i18n="conversation_invited_user">
<my-i18n-param name="user"><span my-peer-link="replyMessage.action.user_id"></span></my-i18n-param>
</span>
</span>
<span ng-switch-when="messageActionChatDeleteUser" ng-switch="replyMessage.from_id == replyMessage.action.user_id">
<span ng-switch-when="true" my-i18n="conversation_left_group"></span>
<span ng-switch-default my-i18n="conversation_kicked_user">
<my-i18n-param name="user"><span my-peer-link="replyMessage.action.user_id"></span></my-i18n-param>
</span>
</span>
<span ng-switch-when="messageActionChatJoinedByLink" my-i18n="conversation_joined_by_link"></span>
</span>
<span class="im_reply_message_service" ng-if="replyMessage._ == 'messageService'" my-service-short-message="replyMessage"></span>
<span class="im_reply_message_text" ng-if="replyMessage.message.length" ng-bind-html="replyMessage.richMessage"></span>
</div>

Loading…
Cancel
Save