|
|
@ -78,21 +78,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function userNameClean (username) { |
|
|
|
|
|
|
|
return username && username.toLowerCase() || ''; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function resolveUsername (username) { |
|
|
|
function resolveUsername (username) { |
|
|
|
var searchUserName = userNameClean(username); |
|
|
|
return usernames[username] || 0; |
|
|
|
var foundUserID = usernames[searchUserName]; |
|
|
|
|
|
|
|
if (foundUserID && |
|
|
|
|
|
|
|
userNameClean(users[foundUserID].username) == searchUserName) { |
|
|
|
|
|
|
|
return qSync.when(foundUserID); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return MtpApiManager.invokeApi('contacts.resolveUsername', {username: username}).then(function (resolveResult) { |
|
|
|
|
|
|
|
saveApiUser(resolveResult); |
|
|
|
|
|
|
|
return resolveResult.id; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function saveApiUsers (apiUsers) { |
|
|
|
function saveApiUsers (apiUsers) { |
|
|
@ -122,7 +109,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (apiUser.username) { |
|
|
|
if (apiUser.username) { |
|
|
|
usernames[userNameClean(apiUser.username)] = userID; |
|
|
|
var searchUsername = SearchIndexManager.cleanUsername(apiUser.username); |
|
|
|
|
|
|
|
usernames[searchUsername] = userID; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
apiUser.sortName = SearchIndexManager.cleanSearchText(apiUser.first_name + ' ' + (apiUser.last_name || '')); |
|
|
|
apiUser.sortName = SearchIndexManager.cleanSearchText(apiUser.first_name + ' ' + (apiUser.last_name || '')); |
|
|
@ -562,6 +550,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
|
|
|
|
|
|
|
|
.service('AppChatsManager', function ($q, $rootScope, $modal, _, MtpApiFileManager, MtpApiManager, AppUsersManager, AppPhotosManager, RichTextProcessor) { |
|
|
|
.service('AppChatsManager', function ($q, $rootScope, $modal, _, MtpApiFileManager, MtpApiManager, AppUsersManager, AppPhotosManager, RichTextProcessor) { |
|
|
|
var chats = {}, |
|
|
|
var chats = {}, |
|
|
|
|
|
|
|
usernames = {}, |
|
|
|
chatsFull = {}, |
|
|
|
chatsFull = {}, |
|
|
|
chatFullPromises = {}, |
|
|
|
chatFullPromises = {}, |
|
|
|
cachedPhotoLocations = {}; |
|
|
|
cachedPhotoLocations = {}; |
|
|
@ -583,6 +572,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
|
|
|
|
|
|
|
|
apiChat.num = (Math.abs(apiChat.id >> 1) % (Config.Mobile ? 4 : 8)) + 1; |
|
|
|
apiChat.num = (Math.abs(apiChat.id >> 1) % (Config.Mobile ? 4 : 8)) + 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (apiChat.username) { |
|
|
|
|
|
|
|
var searchUsername = SearchIndexManager.cleanUsername(apiChat.username); |
|
|
|
|
|
|
|
usernames[searchUsername] = apiChat.id; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (chats[apiChat.id] === undefined) { |
|
|
|
if (chats[apiChat.id] === undefined) { |
|
|
|
chats[apiChat.id] = apiChat; |
|
|
|
chats[apiChat.id] = apiChat; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -599,22 +593,27 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
return chats[id] || {id: id, deleted: true}; |
|
|
|
return chats[id] || {id: id, deleted: true}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function resolveUsername (username) { |
|
|
|
|
|
|
|
return usernames[username] || 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function isChannel (id) { |
|
|
|
function isChannel (id) { |
|
|
|
return (chats[id] || {})._ == 'channel'; |
|
|
|
return (chats[id] || {})._ == 'channel'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getChatInput (id) { |
|
|
|
function getChatInput (id) { |
|
|
|
|
|
|
|
return id || 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getChannelInput (id) { |
|
|
|
if (!id) { |
|
|
|
if (!id) { |
|
|
|
return {_: 'inputChatEmpty'}; |
|
|
|
return {_: 'inputChannelEmpty'}; |
|
|
|
} |
|
|
|
} |
|
|
|
if (isChannel(id)) { |
|
|
|
return { |
|
|
|
return { |
|
|
|
_: 'inputChannel', |
|
|
|
_: 'inputChannel', |
|
|
|
channel_id: id, |
|
|
|
channel_id: id, |
|
|
|
access_hash: getChat(id).access_hash || 0 |
|
|
|
access_hash: getChat(id).access_hash || 0 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return {_: 'inputChat', chat_id: id}; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getChatFull(id) { |
|
|
|
function getChatFull(id) { |
|
|
@ -781,112 +780,158 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
getChat: getChat, |
|
|
|
getChat: getChat, |
|
|
|
isChannel: isChannel, |
|
|
|
isChannel: isChannel, |
|
|
|
getChatInput: getChatInput, |
|
|
|
getChatInput: getChatInput, |
|
|
|
|
|
|
|
getChannelInput: getChannelInput, |
|
|
|
getChatFull: getChatFull, |
|
|
|
getChatFull: getChatFull, |
|
|
|
getChatPhoto: getChatPhoto, |
|
|
|
getChatPhoto: getChatPhoto, |
|
|
|
getChatString: getChatString, |
|
|
|
getChatString: getChatString, |
|
|
|
getChatInviteLink: getChatInviteLink, |
|
|
|
getChatInviteLink: getChatInviteLink, |
|
|
|
|
|
|
|
resolveUsername: resolveUsername, |
|
|
|
hasChat: hasChat, |
|
|
|
hasChat: hasChat, |
|
|
|
wrapForFull: wrapForFull, |
|
|
|
wrapForFull: wrapForFull, |
|
|
|
openChat: openChat |
|
|
|
openChat: openChat |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
.service('AppPeersManager', function (AppUsersManager, AppChatsManager, MtpApiManager) { |
|
|
|
.service('AppPeersManager', function (qSync, AppUsersManager, AppChatsManager, MtpApiManager) { |
|
|
|
return { |
|
|
|
|
|
|
|
getInputPeer: function (peerString) { |
|
|
|
|
|
|
|
var firstChar = peerString.charAt(0), |
|
|
|
|
|
|
|
peerParams = peerString.substr(1).split('_'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (firstChar == 'u') { |
|
|
|
var usernames = {}; |
|
|
|
return { |
|
|
|
|
|
|
|
_: 'inputPeerUser', |
|
|
|
function getInputPeer (peerString) { |
|
|
|
user_id: peerParams[0], |
|
|
|
var firstChar = peerString.charAt(0), |
|
|
|
access_hash: peerParams[1] |
|
|
|
peerParams = peerString.substr(1).split('_'); |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
if (firstChar == 'u') { |
|
|
|
else if (firstChar == 'c') { |
|
|
|
return { |
|
|
|
return { |
|
|
|
_: 'inputPeerUser', |
|
|
|
_: 'inputPeerChannel', |
|
|
|
user_id: peerParams[0], |
|
|
|
channel_id: peerParams[0], |
|
|
|
access_hash: peerParams[1] |
|
|
|
access_hash: peerParams[1] || 0 |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
else if (firstChar == 'c') { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
_: 'inputPeerChannel', |
|
|
|
|
|
|
|
channel_id: peerParams[0], |
|
|
|
|
|
|
|
access_hash: peerParams[1] || 0 |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
_: 'inputPeerChat', |
|
|
|
|
|
|
|
chat_id: peerParams[0] |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getInputPeerByID (peerID) { |
|
|
|
|
|
|
|
if (peerID < 0) { |
|
|
|
|
|
|
|
var chatID = -peerID; |
|
|
|
|
|
|
|
if (!AppChatsManager.isChannel(chatID)) { |
|
|
|
return { |
|
|
|
return { |
|
|
|
_: 'inputPeerChat', |
|
|
|
_: 'inputPeerChat', |
|
|
|
chat_id: peerParams[0] |
|
|
|
chat_id: chatID |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getInputPeerByID: function (peerID) { |
|
|
|
|
|
|
|
if (peerID > 0) { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
_: 'inputPeerUser', |
|
|
|
|
|
|
|
user_id: peerID, |
|
|
|
|
|
|
|
access_hash: AppUsersManager.getUser(peerID).access_hash || 0 |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
} else if (peerID < 0) { |
|
|
|
} else { |
|
|
|
var chatID = -peerID; |
|
|
|
|
|
|
|
if (!AppChatsManager.isChannel(chatID)) { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
_: 'inputPeerChat', |
|
|
|
|
|
|
|
chat_id: chatID |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
_: 'inputPeerChannel', |
|
|
|
_: 'inputPeerChannel', |
|
|
|
channel_id: chatID, |
|
|
|
channel_id: chatID, |
|
|
|
access_hash: AppChatsManager.getChat(chatID).access_hash || 0 |
|
|
|
access_hash: AppChatsManager.getChat(chatID).access_hash || 0 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
getPeerSearchText: function (peerID) { |
|
|
|
return { |
|
|
|
var text; |
|
|
|
_: 'inputPeerUser', |
|
|
|
if (peerID > 0) { |
|
|
|
user_id: peerID, |
|
|
|
text = '%pu ' + AppUsersManager.getUserSearchText(peerID); |
|
|
|
access_hash: AppUsersManager.getUser(peerID).access_hash || 0 |
|
|
|
} else if (peerID < 0) { |
|
|
|
}; |
|
|
|
var chat = AppChatsManager.getChat(-peerID); |
|
|
|
} |
|
|
|
text = '%pg ' + (chat.title || ''); |
|
|
|
|
|
|
|
} |
|
|
|
function getPeerSearchText (peerID) { |
|
|
|
return text; |
|
|
|
var text; |
|
|
|
}, |
|
|
|
if (peerID > 0) { |
|
|
|
getPeerString: function (peerID) { |
|
|
|
text = '%pu ' + AppUsersManager.getUserSearchText(peerID); |
|
|
|
if (peerID > 0) { |
|
|
|
} else if (peerID < 0) { |
|
|
|
return AppUsersManager.getUserString(peerID); |
|
|
|
var chat = AppChatsManager.getChat(-peerID); |
|
|
|
} |
|
|
|
text = '%pg ' + (chat.title || ''); |
|
|
|
return AppChatsManager.getChatString(-peerID); |
|
|
|
} |
|
|
|
}, |
|
|
|
return text; |
|
|
|
getOutputPeer: function (peerID) { |
|
|
|
} |
|
|
|
if (peerID > 0) { |
|
|
|
|
|
|
|
return {_: 'peerUser', user_id: peerID}; |
|
|
|
function getPeerString (peerID) { |
|
|
|
} |
|
|
|
if (peerID > 0) { |
|
|
|
var chatID = -peerID; |
|
|
|
return AppUsersManager.getUserString(peerID); |
|
|
|
if (AppChatsManager.isChannel(chatID)) { |
|
|
|
} |
|
|
|
return {_: 'peerChannel', channel_id: chatID} |
|
|
|
return AppChatsManager.getChatString(-peerID); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getOutputPeer (peerID) { |
|
|
|
|
|
|
|
if (peerID > 0) { |
|
|
|
|
|
|
|
return {_: 'peerUser', user_id: peerID}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var chatID = -peerID; |
|
|
|
|
|
|
|
if (AppChatsManager.isChannel(chatID)) { |
|
|
|
|
|
|
|
return {_: 'peerChannel', channel_id: chatID} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return {_: 'peerChat', chat_id: chatID} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function resolveUsername (username) { |
|
|
|
|
|
|
|
var searchUserName = SearchIndexManager.cleanUsername(username); |
|
|
|
|
|
|
|
var foundUserID, foundChatID, foundPeerID, foundUsername; |
|
|
|
|
|
|
|
if (foundUserID == AppUsersManager.resolveUsername(searchUserName)) { |
|
|
|
|
|
|
|
foundUsername = AppUsersManager.getUser(foundUserID).username; |
|
|
|
|
|
|
|
if (SearchIndexManager.cleanUsername(foundUsername) == searchUserName) { |
|
|
|
|
|
|
|
return qSync.when(foundUserID); |
|
|
|
} |
|
|
|
} |
|
|
|
return {_: 'peerChat', chat_id: chatID} |
|
|
|
} |
|
|
|
}, |
|
|
|
if (foundChatID == AppChatsManager.resolveUsername(searchUserName)) { |
|
|
|
getPeerID: function (peerString) { |
|
|
|
foundUsername = AppChatsManager.getChat(foundChatID).username; |
|
|
|
if (angular.isObject(peerString)) { |
|
|
|
if (SearchIndexManager.cleanUsername(foundUsername) == searchUserName) { |
|
|
|
return peerString.user_id |
|
|
|
return qSync.when(-foundChatID); |
|
|
|
? peerString.user_id |
|
|
|
|
|
|
|
: -peerString.chat_id; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
var isUser = peerString.charAt(0) == 'u', |
|
|
|
} |
|
|
|
peerParams = peerString.substr(1).split('_'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return isUser ? peerParams[0] : -peerParams[0] || 0; |
|
|
|
return MtpApiManager.invokeApi('contacts.resolveUsername', {username: username}).then(function (resolveResult) { |
|
|
|
}, |
|
|
|
AppUsersManager.saveApiUsers(resolveResult.users); |
|
|
|
getPeer: function (peerID) { |
|
|
|
AppChatsManager.saveApiChats(resolveResult.chats); |
|
|
|
return peerID > 0 |
|
|
|
return getPeerID(resolveResult.peer); |
|
|
|
? AppUsersManager.getUser(peerID) |
|
|
|
}); |
|
|
|
: AppChatsManager.getChat(-peerID); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
getPeerPhoto: function (peerID, userPlaceholder, chatPlaceholder) { |
|
|
|
function getPeerID (peerString) { |
|
|
|
return peerID > 0 |
|
|
|
if (angular.isObject(peerString)) { |
|
|
|
? AppUsersManager.getUserPhoto(peerID, userPlaceholder) |
|
|
|
return peerString.user_id |
|
|
|
: AppChatsManager.getChatPhoto(-peerID, chatPlaceholder) |
|
|
|
? peerString.user_id |
|
|
|
|
|
|
|
: -(peerString.channel_id || peerString.chat_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var isUser = peerString.charAt(0) == 'u', |
|
|
|
|
|
|
|
peerParams = peerString.substr(1).split('_'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return isUser ? peerParams[0] : -peerParams[0] || 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getPeer (peerID) { |
|
|
|
|
|
|
|
return peerID > 0 |
|
|
|
|
|
|
|
? AppUsersManager.getUser(peerID) |
|
|
|
|
|
|
|
: AppChatsManager.getChat(-peerID); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getPeerPhoto (peerID, userPlaceholder, chatPlaceholder) { |
|
|
|
|
|
|
|
return peerID > 0 |
|
|
|
|
|
|
|
? AppUsersManager.getUserPhoto(peerID, userPlaceholder) |
|
|
|
|
|
|
|
: AppChatsManager.getChatPhoto(-peerID, chatPlaceholder) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
getInputPeer: getInputPeer, |
|
|
|
|
|
|
|
getInputPeerByID: getInputPeerByID, |
|
|
|
|
|
|
|
getPeerSearchText: getPeerSearchText, |
|
|
|
|
|
|
|
getPeerString: getPeerString, |
|
|
|
|
|
|
|
getOutputPeer: getOutputPeer, |
|
|
|
|
|
|
|
getPeerID: getPeerID, |
|
|
|
|
|
|
|
getPeer: getPeer, |
|
|
|
|
|
|
|
getPeerPhoto: getPeerPhoto, |
|
|
|
|
|
|
|
resolveUsername: resolveUsername, |
|
|
|
|
|
|
|
usernames: usernames |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -1147,9 +1192,9 @@ 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', { |
|
|
|
return MtpApiManager.invokeApi('messages.getHistory', { |
|
|
|
peer: inputPeer, |
|
|
|
peer: inputPeer, |
|
|
|
offset: offset || 0, |
|
|
|
add_offset: offset || 0, |
|
|
|
limit: limit || 0, |
|
|
|
limit: limit || 0, |
|
|
|
max_id: maxID || 0 |
|
|
|
offset_id: maxID || 0 |
|
|
|
}, {noErrorBox: true}).then(function (historyResult) { |
|
|
|
}, {noErrorBox: true}).then(function (historyResult) { |
|
|
|
AppUsersManager.saveApiUsers(historyResult.users); |
|
|
|
AppUsersManager.saveApiUsers(historyResult.users); |
|
|
|
AppChatsManager.saveApiChats(historyResult.chats); |
|
|
|
AppChatsManager.saveApiChats(historyResult.chats); |
|
|
@ -1503,6 +1548,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return MtpApiManager.invokeApi('messages.search', { |
|
|
|
return MtpApiManager.invokeApi('messages.search', { |
|
|
|
|
|
|
|
flags: 0, |
|
|
|
peer: inputPeer, |
|
|
|
peer: inputPeer, |
|
|
|
q: query || '', |
|
|
|
q: query || '', |
|
|
|
filter: inputFilter || {_: 'inputMessagesFilterEmpty'}, |
|
|
|
filter: inputFilter || {_: 'inputMessagesFilterEmpty'}, |
|
|
@ -1699,6 +1745,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
|
|
|
|
|
|
|
|
apiMessage.date -= serverTimeOffset; |
|
|
|
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 = { |
|
|
|
var mediaContext = { |
|
|
|
user_id: apiMessage.from_id, |
|
|
|
user_id: apiMessage.from_id, |
|
|
|
date: apiMessage.date |
|
|
|
date: apiMessage.date |
|
|
@ -1726,8 +1780,16 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (apiMessage.action && apiMessage.action._ == 'messageActionChatEditPhoto') { |
|
|
|
if (apiMessage.action) { |
|
|
|
AppPhotosManager.savePhoto(apiMessage.action.photo, mediaContext); |
|
|
|
if (apiMessage.action._ == 'messageActionChatEditPhoto') { |
|
|
|
|
|
|
|
AppPhotosManager.savePhoto(apiMessage.action.photo, mediaContext); |
|
|
|
|
|
|
|
if (isChannel) { |
|
|
|
|
|
|
|
apiMessage.action._ = 'messageActionChannelEditPhoto'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (apiMessage.action._ == 'messageActionChatEditTitle' && isChannel) { |
|
|
|
|
|
|
|
apiMessage.action._ = 'messageActionChannelEditTitle'; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (apiMessage.reply_markup) { |
|
|
|
if (apiMessage.reply_markup) { |
|
|
|
apiMessage.reply_markup.pFlags = { |
|
|
|
apiMessage.reply_markup.pFlags = { |
|
|
@ -1819,7 +1881,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
if (entities.length) { |
|
|
|
if (entities.length) { |
|
|
|
flags |= 8; |
|
|
|
flags |= 8; |
|
|
|
} |
|
|
|
} |
|
|
|
console.log(flags, entities); |
|
|
|
// console.log(flags, entities);
|
|
|
|
MtpApiManager.invokeApi('messages.sendMessage', { |
|
|
|
MtpApiManager.invokeApi('messages.sendMessage', { |
|
|
|
flags: flags, |
|
|
|
flags: flags, |
|
|
|
peer: inputPeer, |
|
|
|
peer: inputPeer, |
|
|
@ -2379,8 +2441,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
message.media.progress = messagesStorage[msgID].media.progress; |
|
|
|
message.media.progress = messagesStorage[msgID].media.progress; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var fromUser = AppUsersManager.getUser(message.from_id); |
|
|
|
var fromUser = message.from_id && AppUsersManager.getUser(message.from_id); |
|
|
|
var fromBot = fromUser.pFlags.bot && fromUser.username || false; |
|
|
|
var fromBot = fromUser && fromUser.pFlags.bot && fromUser.username || false; |
|
|
|
var withBot = (fromBot || |
|
|
|
var withBot = (fromBot || |
|
|
|
message.to_id && ( |
|
|
|
message.to_id && ( |
|
|
|
message.to_id.chat_id || |
|
|
|
message.to_id.chat_id || |
|
|
@ -2451,11 +2513,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
else if (message.action) { |
|
|
|
else if (message.action) { |
|
|
|
switch (message.action._) { |
|
|
|
switch (message.action._) { |
|
|
|
case 'messageActionChatEditPhoto': |
|
|
|
case 'messageActionChatEditPhoto': |
|
|
|
|
|
|
|
case 'messageActionChannelEditPhoto': |
|
|
|
message.action.photo = AppPhotosManager.wrapForHistory(message.action.photo.id); |
|
|
|
message.action.photo = AppPhotosManager.wrapForHistory(message.action.photo.id); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'messageActionChatCreate': |
|
|
|
case 'messageActionChatCreate': |
|
|
|
case 'messageActionChatEditTitle': |
|
|
|
case 'messageActionChatEditTitle': |
|
|
|
|
|
|
|
case 'messageActionChannelCreate': |
|
|
|
|
|
|
|
case 'messageActionChannelEditTitle': |
|
|
|
message.action.rTitle = RichTextProcessor.wrapRichText(message.action.title, {noLinks: true, noLinebreaks: true}) || _('chat_title_deleted'); |
|
|
|
message.action.rTitle = RichTextProcessor.wrapRichText(message.action.title, {noLinks: true, noLinebreaks: true}) || _('chat_title_deleted'); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
@ -2568,29 +2633,29 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (curMessage.fwd_from_id && |
|
|
|
if (curMessage.fwdFromID && |
|
|
|
curMessage.media && |
|
|
|
curMessage.media && |
|
|
|
curMessage.media.document && |
|
|
|
curMessage.media.document && |
|
|
|
curMessage.media.document.sticker && |
|
|
|
curMessage.media.document.sticker && |
|
|
|
(curMessage.from_id != (prevMessage || {}).from_id || !(prevMessage || {}).fwd_from_id)) { |
|
|
|
(curMessage.from_id != (prevMessage || {}).from_id || !(prevMessage || {}).fwdFromID)) { |
|
|
|
delete curMessage.fwd_from_id; |
|
|
|
delete curMessage.fwdFromID; |
|
|
|
curMessage._ = 'message'; |
|
|
|
curMessage._ = 'message'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (prevMessage && |
|
|
|
if (prevMessage && |
|
|
|
curMessage.from_id == prevMessage.from_id && |
|
|
|
curMessage.from_id == prevMessage.from_id && |
|
|
|
!prevMessage.fwd_from_id == !curMessage.fwd_from_id && |
|
|
|
!prevMessage.fwdFromID == !curMessage.fwdFromID && |
|
|
|
!prevMessage.action && |
|
|
|
!prevMessage.action && |
|
|
|
!curMessage.action && |
|
|
|
!curMessage.action && |
|
|
|
curMessage.date < prevMessage.date + 900) { |
|
|
|
curMessage.date < prevMessage.date + 900) { |
|
|
|
|
|
|
|
|
|
|
|
var singleLine = curMessage.message && curMessage.message.length < 70 && curMessage.message.indexOf("\n") == -1 && !curMessage.reply_to_msg_id; |
|
|
|
var singleLine = curMessage.message && curMessage.message.length < 70 && curMessage.message.indexOf("\n") == -1 && !curMessage.reply_to_msg_id; |
|
|
|
if (groupFwd && curMessage.fwd_from_id && curMessage.fwd_from_id == prevMessage.fwd_from_id) { |
|
|
|
if (groupFwd && curMessage.fwdFromID && curMessage.fwdFromID == prevMessage.fwdFromID) { |
|
|
|
curMessage.grouped = singleLine ? 'im_grouped_fwd_short' : 'im_grouped_fwd'; |
|
|
|
curMessage.grouped = singleLine ? 'im_grouped_fwd_short' : 'im_grouped_fwd'; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
curMessage.grouped = !curMessage.fwd_from_id && singleLine ? 'im_grouped_short' : 'im_grouped'; |
|
|
|
curMessage.grouped = !curMessage.fwdFromID && singleLine ? 'im_grouped_short' : 'im_grouped'; |
|
|
|
} |
|
|
|
} |
|
|
|
if (groupFwd && curMessage.fwd_from_id) { |
|
|
|
if (groupFwd && curMessage.fwdFromID) { |
|
|
|
if (!prevMessage.grouped) { |
|
|
|
if (!prevMessage.grouped) { |
|
|
|
prevMessage.grouped = 'im_grouped_fwd_start'; |
|
|
|
prevMessage.grouped = 'im_grouped_fwd_start'; |
|
|
|
} |
|
|
|
} |
|
|
@ -2601,7 +2666,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} else if (prevMessage || !i) { |
|
|
|
} else if (prevMessage || !i) { |
|
|
|
delete curMessage.grouped; |
|
|
|
delete curMessage.grouped; |
|
|
|
|
|
|
|
|
|
|
|
if (groupFwd && prevMessage && prevMessage.grouped && prevMessage.fwd_from_id) { |
|
|
|
if (groupFwd && prevMessage && prevMessage.grouped && prevMessage.fwdFromID) { |
|
|
|
prevMessage.grouped += ' im_grouped_fwd_end'; |
|
|
|
prevMessage.grouped += ' im_grouped_fwd_end'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -2649,7 +2714,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
|
|
|
|
|
|
|
|
var notifySettings = NotificationsManager.getNotifySettings(); |
|
|
|
var notifySettings = NotificationsManager.getNotifySettings(); |
|
|
|
|
|
|
|
|
|
|
|
if (message.fwd_from_id && options.fwd_count) { |
|
|
|
if (message.fwdFromID && options.fwd_count) { |
|
|
|
notificationMessage = fwdMessagesPluralize(options.fwd_count); |
|
|
|
notificationMessage = fwdMessagesPluralize(options.fwd_count); |
|
|
|
} else if (message.message) { |
|
|
|
} else if (message.message) { |
|
|
|
if (notifySettings.nopreview) { |
|
|
|
if (notifySettings.nopreview) { |
|
|
@ -2924,7 +2989,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
notifyPeerToHandle.from_id = message.from_id; |
|
|
|
notifyPeerToHandle.from_id = message.from_id; |
|
|
|
notifyPeerToHandle.fwd_count = 0; |
|
|
|
notifyPeerToHandle.fwd_count = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
if (message.fwd_from_id) { |
|
|
|
if (message.fwdFromID) { |
|
|
|
notifyPeerToHandle.fwd_count++; |
|
|
|
notifyPeerToHandle.fwd_count++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -3132,6 +3197,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.service('AppChannelsManager', function () { |
|
|
|
|
|
|
|
var AppMessagesManager = {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getDialogs () { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setMessagesManager (messagesManager) { |
|
|
|
|
|
|
|
AppMessagesManager = messagesManager; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
setMessagesManager: setMessagesManager |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
.service('AppPhotosManager', function ($modal, $window, $rootScope, MtpApiManager, MtpApiFileManager, AppUsersManager, FileManager) { |
|
|
|
.service('AppPhotosManager', function ($modal, $window, $rootScope, MtpApiManager, MtpApiFileManager, AppUsersManager, FileManager) { |
|
|
|
var photos = {}, |
|
|
|
var photos = {}, |
|
|
|
windowW = $(window).width(), |
|
|
|
windowW = $(window).width(), |
|
|
@ -4473,10 +4554,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
if (update._ == 'updateNewMessage') { |
|
|
|
if (update._ == 'updateNewMessage') { |
|
|
|
var message = update.message; |
|
|
|
var message = update.message; |
|
|
|
|
|
|
|
var fwdPeerID = message.fwd_from_id ? AppPeersManager.getPeerID(message.fwd_from_id) : 0; |
|
|
|
|
|
|
|
var toPeerID = AppPeersManager.getPeerID(message.to_id); |
|
|
|
if (message.from_id && !AppUsersManager.hasUser(message.from_id) || |
|
|
|
if (message.from_id && !AppUsersManager.hasUser(message.from_id) || |
|
|
|
message.fwd_from_id && !AppUsersManager.hasUser(message.fwd_from_id) || |
|
|
|
fwdPeerID > 0 && !AppUsersManager.hasUser(fwdPeerID) || |
|
|
|
message.to_id.user_id && !AppUsersManager.hasUser(message.to_id.user_id) || |
|
|
|
fwdPeerID < 0 && !AppChatsManager.hasChat(-fwdPeerID) || |
|
|
|
message.to_id.chat_id && !AppChatsManager.hasChat(message.to_id.chat_id)) { |
|
|
|
toPeerID > 0 && !AppUsersManager.hasUser(toPeerID) || |
|
|
|
|
|
|
|
toPeerID < 0 && !AppChatsManager.hasChat(-toPeerID)) { |
|
|
|
console.warn(dT(), 'Short update not enough data', message); |
|
|
|
console.warn(dT(), 'Short update not enough data', message); |
|
|
|
forceGetDifference(); |
|
|
|
forceGetDifference(); |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -4820,9 +4904,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
rawOffset += match.index + match[0].length; |
|
|
|
rawOffset += match.index + match[0].length; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (entities.length) { |
|
|
|
// if (entities.length) {
|
|
|
|
console.log('parse entities', text, entities.slice()); |
|
|
|
// console.log('parse entities', text, entities.slice());
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
return entities; |
|
|
|
return entities; |
|
|
|
} |
|
|
|
} |
|
|
@ -6091,24 +6175,24 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
var matches; |
|
|
|
var matches; |
|
|
|
|
|
|
|
|
|
|
|
if (matches = url.match(/^resolve\?domain=(.+?)(?:&(start|startgroup)=(.+))?$/)) { |
|
|
|
if (matches = url.match(/^resolve\?domain=(.+?)(?:&(start|startgroup)=(.+))?$/)) { |
|
|
|
AppUsersManager.resolveUsername(matches[1]).then(function (userID) { |
|
|
|
AppPeersManager.resolveUsername(matches[1]).then(function (peerID) { |
|
|
|
|
|
|
|
|
|
|
|
if (matches[2] == 'startgroup') { |
|
|
|
if (peerID > 0 && AppUsersManager.isBot(peerID) && matches[2] == 'startgroup') { |
|
|
|
PeersSelectService.selectPeer({ |
|
|
|
PeersSelectService.selectPeer({ |
|
|
|
confirm_type: 'INVITE_TO_GROUP', |
|
|
|
confirm_type: 'INVITE_TO_GROUP', |
|
|
|
noUsers: true |
|
|
|
noUsers: true |
|
|
|
}).then(function (peerString) { |
|
|
|
}).then(function (toPeerString) { |
|
|
|
var peerID = AppPeersManager.getPeerID(peerString); |
|
|
|
var toPeerID = AppPeersManager.getPeerID(toPeerString); |
|
|
|
var chatID = peerID < 0 ? -peerID : 0; |
|
|
|
var toChatID = toPeerID < 0 ? -toPeerID : 0; |
|
|
|
AppMessagesManager.startBot(userID, chatID, matches[3]).then(function () { |
|
|
|
AppMessagesManager.startBot(peerID, toChatID, matches[3]).then(function () { |
|
|
|
$rootScope.$broadcast('history_focus', {peerString: peerString}); |
|
|
|
$rootScope.$broadcast('history_focus', {toPeerString: toPeerString}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$rootScope.$broadcast('history_focus', { |
|
|
|
$rootScope.$broadcast('history_focus', { |
|
|
|
peerString: AppUsersManager.getUserString(userID), |
|
|
|
peerString: AppPeersManager.getPeerString(peerID), |
|
|
|
startParam: matches[3] |
|
|
|
startParam: matches[3] |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|