|
|
@ -599,6 +599,64 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getChatInviteLink (id, force) { |
|
|
|
|
|
|
|
return getChatFull(id).then(function (chatFull) { |
|
|
|
|
|
|
|
if (!force && |
|
|
|
|
|
|
|
chatFull.exported_invite && |
|
|
|
|
|
|
|
chatFull.exported_invite._ == 'chatInviteExported') { |
|
|
|
|
|
|
|
return chatFull.exported_invite.link; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return MtpApiManager.invokeApi('messages.exportChatInvite', { |
|
|
|
|
|
|
|
chat_id: id |
|
|
|
|
|
|
|
}).then(function (exportedInvite) { |
|
|
|
|
|
|
|
if (chatsFull[id] !== undefined) { |
|
|
|
|
|
|
|
chatsFull[id].exported_invite = exportedInvite; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return exportedInvite.link; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function openInviteLink (hash) { |
|
|
|
|
|
|
|
return MtpApiManager.invokeApi('messages.checkChatInvite', { |
|
|
|
|
|
|
|
hash: hash |
|
|
|
|
|
|
|
}).then(function (chatInvite) { |
|
|
|
|
|
|
|
var chatTitle; |
|
|
|
|
|
|
|
if (chatInvite._ == 'chatInviteAlready') { |
|
|
|
|
|
|
|
saveApiChat(chatInvite.chat); |
|
|
|
|
|
|
|
if (!chatInvite.chat.left) { |
|
|
|
|
|
|
|
return $rootScope.$broadcast('history_focus', { |
|
|
|
|
|
|
|
peerString: getChatString(chatInvite.chat.id) |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
chatTitle = chatInvite.chat.title; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
chatTitle = chatInvite.title; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ErrorService.confirm({ |
|
|
|
|
|
|
|
type: 'JOIN_GROUP_BY_LINK', |
|
|
|
|
|
|
|
title: chatTitle |
|
|
|
|
|
|
|
}).then(function () { |
|
|
|
|
|
|
|
return MtpApiManager.invokeApi('messages.importChatInvite', { |
|
|
|
|
|
|
|
hash: hash |
|
|
|
|
|
|
|
}).then(function (updates) { |
|
|
|
|
|
|
|
ApiUpdatesManager.processUpdateMessage(updates); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (updates.updates && updates.updates.length) { |
|
|
|
|
|
|
|
for (var i = 0, len = updates.updates.length, update; i < len; i++) { |
|
|
|
|
|
|
|
update = updates.updates[i]; |
|
|
|
|
|
|
|
if (update._ == 'updateNewMessage') { |
|
|
|
|
|
|
|
$rootScope.$broadcast('history_focus', {peerString: AppChatsManager.getChatString(update.message.to_id.chat_id) |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function hasChat (id) { |
|
|
|
function hasChat (id) { |
|
|
|
return angular.isObject(chats[id]); |
|
|
|
return angular.isObject(chats[id]); |
|
|
|
} |
|
|
|
} |
|
|
@ -628,10 +686,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
|
|
|
|
|
|
|
|
if (chatFull.participants && chatFull.participants._ == 'chatParticipants') { |
|
|
|
if (chatFull.participants && chatFull.participants._ == 'chatParticipants') { |
|
|
|
MtpApiManager.getUserID().then(function (myID) { |
|
|
|
MtpApiManager.getUserID().then(function (myID) { |
|
|
|
|
|
|
|
chatFull.isAdmin = (myID == chatFull.participants.admin_id); |
|
|
|
angular.forEach(chatFull.participants.participants, function(participant){ |
|
|
|
angular.forEach(chatFull.participants.participants, function(participant){ |
|
|
|
participant.user = AppUsersManager.getUser(participant.user_id); |
|
|
|
participant.user = AppUsersManager.getUser(participant.user_id); |
|
|
|
participant.canLeave = myID == participant.user_id; |
|
|
|
participant.canLeave = myID == participant.user_id; |
|
|
|
participant.canKick = !participant.canLeave && (myID == chatFull.participants.admin_id || myID == participant.inviter_id); |
|
|
|
participant.canKick = !participant.canLeave && (chatFull.isAdmin || myID == participant.inviter_id); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -717,6 +776,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
getChatFull: getChatFull, |
|
|
|
getChatFull: getChatFull, |
|
|
|
getChatPhoto: getChatPhoto, |
|
|
|
getChatPhoto: getChatPhoto, |
|
|
|
getChatString: getChatString, |
|
|
|
getChatString: getChatString, |
|
|
|
|
|
|
|
getChatInviteLink: getChatInviteLink, |
|
|
|
|
|
|
|
openInviteLink: openInviteLink, |
|
|
|
hasChat: hasChat, |
|
|
|
hasChat: hasChat, |
|
|
|
wrapForFull: wrapForFull, |
|
|
|
wrapForFull: wrapForFull, |
|
|
|
openChat: openChat |
|
|
|
openChat: openChat |
|
|
@ -792,7 +853,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
.service('AppMessagesManager', function ($q, $rootScope, $location, $filter, $timeout, ApiUpdatesManager, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, AppVideoManager, AppDocsManager, AppAudioManager, AppWebPagesManager, MtpApiManager, MtpApiFileManager, RichTextProcessor, NotificationsManager, PeersSelectService, Storage, FileManager, TelegramMeWebService, StatusManager, _) { |
|
|
|
.service('AppMessagesManager', function ($q, $rootScope, $location, $filter, $timeout, $sce, ApiUpdatesManager, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, AppVideoManager, AppDocsManager, AppAudioManager, AppWebPagesManager, MtpApiManager, MtpApiFileManager, RichTextProcessor, NotificationsManager, PeersSelectService, Storage, FileManager, TelegramMeWebService, StatusManager, _) { |
|
|
|
|
|
|
|
|
|
|
|
var messagesStorage = {}; |
|
|
|
var messagesStorage = {}; |
|
|
|
var messagesForHistory = {}; |
|
|
|
var messagesForHistory = {}; |
|
|
@ -1358,6 +1419,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
return historyStorage.readPromise; |
|
|
|
return historyStorage.readPromise; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function readMessages (messageIDs) { |
|
|
|
|
|
|
|
MtpApiManager.invokeApi('messages.readMessageContents', { |
|
|
|
|
|
|
|
id: messageIDs |
|
|
|
|
|
|
|
}).then(function (affectedMessages) { |
|
|
|
|
|
|
|
ApiUpdatesManager.processUpdateMessage({ |
|
|
|
|
|
|
|
_: 'updateShort', |
|
|
|
|
|
|
|
update: { |
|
|
|
|
|
|
|
_: 'updateReadMessagesContents', |
|
|
|
|
|
|
|
messages: messageIDs, |
|
|
|
|
|
|
|
pts: affectedMessages.pts, |
|
|
|
|
|
|
|
pts_count: affectedMessages.pts_count |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function flushHistory (inputPeer) { |
|
|
|
function flushHistory (inputPeer) { |
|
|
|
// console.log('start flush');
|
|
|
|
// console.log('start flush');
|
|
|
|
var peerID = AppPeersManager.getPeerID(inputPeer), |
|
|
|
var peerID = AppPeersManager.getPeerID(inputPeer), |
|
|
@ -1382,6 +1459,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
angular.forEach(apiMessages, function (apiMessage) { |
|
|
|
angular.forEach(apiMessages, function (apiMessage) { |
|
|
|
apiMessage.unread = apiMessage.flags & 1 ? true : false; |
|
|
|
apiMessage.unread = apiMessage.flags & 1 ? true : false; |
|
|
|
apiMessage.out = apiMessage.flags & 2 ? true : false; |
|
|
|
apiMessage.out = apiMessage.flags & 2 ? true : false; |
|
|
|
|
|
|
|
apiMessage.media_unread = apiMessage.flags & 32 ? true : false; |
|
|
|
messagesStorage[apiMessage.id] = apiMessage; |
|
|
|
messagesStorage[apiMessage.id] = apiMessage; |
|
|
|
|
|
|
|
|
|
|
|
apiMessage.date -= serverTimeOffset; |
|
|
|
apiMessage.date -= serverTimeOffset; |
|
|
@ -1949,9 +2027,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (message.media) { |
|
|
|
if (message.media) { |
|
|
|
|
|
|
|
if (message.media.caption && |
|
|
|
|
|
|
|
message.media.caption.length) { |
|
|
|
|
|
|
|
message.media.rCaption = RichTextProcessor.wrapRichText(message.media.caption); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (message.media._) { |
|
|
|
switch (message.media._) { |
|
|
|
case 'messageMediaPhoto': |
|
|
|
case 'messageMediaPhoto': |
|
|
|
message.media.photo = AppPhotosManager.wrapForHistory(message.media.photo.id) |
|
|
|
message.media.photo = AppPhotosManager.wrapForHistory(message.media.photo.id); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'messageMediaVideo': |
|
|
|
case 'messageMediaVideo': |
|
|
@ -1966,6 +2049,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
message.media.audio = AppAudioManager.wrapForHistory(message.media.audio.id); |
|
|
|
message.media.audio = AppAudioManager.wrapForHistory(message.media.audio.id); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'messageMediaGeo': |
|
|
|
|
|
|
|
var mapUrl = 'https://maps.google.com/?q=' + message.media.geo['lat'] + ',' + message.media.geo['long']; |
|
|
|
|
|
|
|
message.media.mapUrl = $sce.trustAsResourceUrl(mapUrl); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'messageMediaVenue': |
|
|
|
|
|
|
|
var mapUrl; |
|
|
|
|
|
|
|
if (message.media.provider == 'foursquare' && |
|
|
|
|
|
|
|
message.media.venue_id) { |
|
|
|
|
|
|
|
mapUrl = 'https://foursquare.com/v/' + encodeURIComponent(message.media.venue_id); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
mapUrl = 'https://maps.google.com/?q=' + message.media.geo['lat'] + ',' + message.media.geo['long']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
message.media.mapUrl = $sce.trustAsResourceUrl(mapUrl); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'messageMediaContact': |
|
|
|
case 'messageMediaContact': |
|
|
|
message.media.rFullName = RichTextProcessor.wrapRichText( |
|
|
|
message.media.rFullName = RichTextProcessor.wrapRichText( |
|
|
|
message.media.first_name + ' ' + (message.media.last_name || ''), |
|
|
|
message.media.first_name + ' ' + (message.media.last_name || ''), |
|
|
@ -1975,7 +2074,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
|
|
|
|
|
|
|
|
case 'messageMediaWebPage': |
|
|
|
case 'messageMediaWebPage': |
|
|
|
if (!message.media.webpage || |
|
|
|
if (!message.media.webpage || |
|
|
|
message.media.webpage._ == 'webPageEmpty') { |
|
|
|
message.media.webpage._ == 'webPageEmpty' || |
|
|
|
|
|
|
|
Config.Mobile) { |
|
|
|
delete message.media; |
|
|
|
delete message.media; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -2187,7 +2287,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'messageMediaAudio': notificationMessage = _('conversation_media_audio_raw'); break; |
|
|
|
case 'messageMediaAudio': notificationMessage = _('conversation_media_audio_raw'); break; |
|
|
|
case 'messageMediaGeo': notificationMessage = _('conversation_media_location_raw'); break; |
|
|
|
case 'messageMediaGeo': |
|
|
|
|
|
|
|
case 'messageMediaVenue': notificationMessage = _('conversation_media_location_raw'); break; |
|
|
|
case 'messageMediaContact': notificationMessage = _('conversation_media_contact_raw'); break; |
|
|
|
case 'messageMediaContact': notificationMessage = _('conversation_media_contact_raw'); break; |
|
|
|
default: notificationMessage = _('conversation_media_attachment_raw'); break; |
|
|
|
default: notificationMessage = _('conversation_media_attachment_raw'); break; |
|
|
|
} |
|
|
|
} |
|
|
@ -2464,6 +2565,21 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'updateReadMessagesContents': |
|
|
|
|
|
|
|
var messages = update.messages; |
|
|
|
|
|
|
|
var len = messages.length; |
|
|
|
|
|
|
|
var i, messageID, message, historyMessage; |
|
|
|
|
|
|
|
for (i = 0; i < len; i++) { |
|
|
|
|
|
|
|
messageID = messages[i]; |
|
|
|
|
|
|
|
if (message = messagesStorage[messageID]) { |
|
|
|
|
|
|
|
delete message.media_unread; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (historyMessage = messagesForHistory[messageID]) { |
|
|
|
|
|
|
|
delete historyMessage.media_unread; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'updateDeleteMessages': |
|
|
|
case 'updateDeleteMessages': |
|
|
|
var dialogsUpdated = {}, |
|
|
|
var dialogsUpdated = {}, |
|
|
|
historiesUpdated = {}, |
|
|
|
historiesUpdated = {}, |
|
|
@ -2558,6 +2674,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
getSearch: getSearch, |
|
|
|
getSearch: getSearch, |
|
|
|
getMessage: getMessage, |
|
|
|
getMessage: getMessage, |
|
|
|
readHistory: readHistory, |
|
|
|
readHistory: readHistory, |
|
|
|
|
|
|
|
readMessages: readMessages, |
|
|
|
flushHistory: flushHistory, |
|
|
|
flushHistory: flushHistory, |
|
|
|
deleteMessages: deleteMessages, |
|
|
|
deleteMessages: deleteMessages, |
|
|
|
saveMessages: saveMessages, |
|
|
|
saveMessages: saveMessages, |
|
|
@ -5152,7 +5269,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.service('LocationParamsService', function ($rootScope, $routeParams, AppUsersManager) { |
|
|
|
.service('LocationParamsService', function ($rootScope, $routeParams, AppUsersManager, AppChatsManager) { |
|
|
|
|
|
|
|
|
|
|
|
function checkTgAddr () { |
|
|
|
function checkTgAddr () { |
|
|
|
if (!$routeParams.tgaddr) { |
|
|
|
if (!$routeParams.tgaddr) { |
|
|
@ -5165,6 +5282,12 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
peerString: AppUsersManager.getUserString(userID) |
|
|
|
peerString: AppUsersManager.getUserString(userID) |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var matches = $routeParams.tgaddr.match(/^(web\+)?tg:(\/\/)?join\?invite=(.+)$/); |
|
|
|
|
|
|
|
if (matches && matches[3]) { |
|
|
|
|
|
|
|
AppChatsManager.openInviteLink(matches[3]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|