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