Browse Source

Migrating schema pt1

Video, audio => document
master
Igor Zhukov 8 years ago
parent
commit
10dd0c8167
  1. 5
      app/js/controllers.js
  2. 35
      app/js/directives.js
  3. 11
      app/js/lib/mtproto_wrapper.js
  4. 77
      app/js/messages_manager.js
  5. 494
      app/js/services.js
  6. 6
      app/partials/desktop/dialog.html
  7. 6
      app/partials/desktop/message_attach_document.html
  8. 6
      app/partials/desktop/reply_message.html
  9. 16
      app/partials/desktop/user_modal.html
  10. 6
      app/partials/mobile/dialog.html
  11. 6
      app/partials/mobile/message_attach_document.html
  12. 4
      app/partials/mobile/user_modal.html

5
app/js/controllers.js

@ -1089,7 +1089,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -1089,7 +1089,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
photos: 'inputMessagesFilterPhotos',
video: 'inputMessagesFilterVideo',
documents: 'inputMessagesFilterDocument',
audio: 'inputMessagesFilterAudio'
audio: 'inputMessagesFilterVoice'
},
unfocusMessagePromise,
jump = 0,
@ -3192,8 +3192,9 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -3192,8 +3192,9 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.settings = {notifications: true};
AppProfileManager.getProfile($scope.userID, $scope.override).then(function (userFull) {
$scope.blocked = userFull.blocked;
$scope.blocked = userFull.pFlags.blocked;
$scope.bot_info = userFull.bot_info;
$scope.rAbout = userFull.rAbout;
NotificationsManager.getPeerMuted($scope.userID).then(function (muted) {
$scope.settings.notifications = !muted;

35
app/js/directives.js

@ -579,7 +579,7 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -579,7 +579,7 @@ angular.module('myApp.directives', ['myApp.filters'])
}
};
})
.directive('myMessageVideo', function(AppVideoManager) {
.directive('myMessageVideo', function(AppDocsManager) {
return {
scope: {
'media': '=myMessageVideo',
@ -587,12 +587,12 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -587,12 +587,12 @@ angular.module('myApp.directives', ['myApp.filters'])
},
templateUrl: templateUrl('message_attach_video'),
link: function ($scope, element, attrs) {
AppVideoManager.updateVideoDownloaded($scope.media.video.id);
AppDocsManager.updateDocDownloaded($scope.media.video.id);
$scope.videoSave = function () {
AppVideoManager.saveVideoFile($scope.media.video.id);
AppDocsManager.saveDocFile($scope.media.video.id);
};
$scope.videoOpen = function () {
AppVideoManager.openVideo($scope.media.video.id, $scope.messageId);
AppDocsManager.openVideo($scope.media.video.id, $scope.messageId);
};
}
};
@ -1944,7 +1944,7 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -1944,7 +1944,7 @@ angular.module('myApp.directives', ['myApp.filters'])
})
.directive('myLoadVideo', function($sce, AppVideoManager, ErrorService, _) {
.directive('myLoadVideo', function($sce, AppDocsManager, ErrorService, _) {
return {
link: link,
@ -1957,7 +1957,7 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -1957,7 +1957,7 @@ angular.module('myApp.directives', ['myApp.filters'])
function link ($scope, element, attrs) {
var downloadPromise = AppVideoManager.downloadVideo($scope.video.id);
var downloadPromise = AppDocsManager.downloadDoc($scope.video.id);
downloadPromise.then(function () {
$scope.$emit('ui_height');
@ -2950,7 +2950,7 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -2950,7 +2950,7 @@ angular.module('myApp.directives', ['myApp.filters'])
}
})
.directive('myAudioPlayer', function ($timeout, $q, Storage, AppAudioManager, AppDocsManager, AppMessagesManager, ErrorService) {
.directive('myAudioPlayer', function ($timeout, $q, Storage, AppDocsManager, AppMessagesManager, ErrorService) {
var currentPlayer = false;
var audioVolume = 0.5;
@ -2995,21 +2995,13 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -2995,21 +2995,13 @@ angular.module('myApp.directives', ['myApp.filters'])
}
function link($scope, element, attrs) {
if ($scope.audio._ == 'audio') {
AppAudioManager.updateAudioDownloaded($scope.audio.id);
} else {
AppDocsManager.updateDocDownloaded($scope.audio.id);
}
AppDocsManager.updateDocDownloaded($scope.audio.id);
$scope.volume = audioVolume;
$scope.mediaPlayer = {};
$scope.download = function () {
if ($scope.audio._ == 'audio') {
AppAudioManager.saveAudioFile($scope.audio.id);
} else {
AppDocsManager.saveDocFile($scope.audio.id);
}
AppDocsManager.saveDocFile($scope.audio.id);
};
$scope.togglePlay = function () {
@ -3021,14 +3013,7 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -3021,14 +3013,7 @@ angular.module('myApp.directives', ['myApp.filters'])
return;
}
else {
var downloadPromise;
if ($scope.audio._ == 'audio') {
downloadPromise = AppAudioManager.downloadAudio($scope.audio.id);
} else {
downloadPromise = AppDocsManager.downloadDoc($scope.audio.id);
}
downloadPromise.then(function () {
AppDocsManager.downloadDoc($scope.audio.id).then(function () {
onContentLoaded(function () {
var errorListenerEl = $('audio', element)[0] || element[0];
if (errorListenerEl) {

11
app/js/lib/mtproto_wrapper.js

@ -339,22 +339,13 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto']) @@ -339,22 +339,13 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
function getFileName(location) {
switch (location._) {
case 'inputVideoFileLocation':
return 'video' + location.id + '.mp4';
case 'inputDocumentFileLocation':
var fileName = (location.file_name || '').split('.', 2);
var ext = fileName[1] || '';
if (location.sticker && !WebpManager.isWebpSupported()) {
ext += '.png';
}
if (fileName.length) {
return fileName[0] + '_' + location.id + '.' + ext;
}
return 'doc' + location.id;
case 'inputAudioFileLocation':
return 'audio' + location.id;
return fileName[0] + '_' + location.id + '.' + ext;
default:
if (!location.volume_id) {

77
app/js/messages_manager.js

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
angular.module('myApp.services')
.service('AppMessagesManager', function ($q, $rootScope, $location, $filter, $timeout, $sce, ApiUpdatesManager, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, AppVideoManager, AppDocsManager, AppStickersManager, AppAudioManager, AppWebPagesManager, MtpApiManager, MtpApiFileManager, RichTextProcessor, NotificationsManager, Storage, AppProfileManager, TelegramMeWebService, ErrorService, StatusManager, _) {
.service('AppMessagesManager', function ($q, $rootScope, $location, $filter, $timeout, $sce, ApiUpdatesManager, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, AppDocsManager, AppStickersManager, AppWebPagesManager, MtpApiManager, MtpApiFileManager, RichTextProcessor, NotificationsManager, Storage, AppProfileManager, TelegramMeWebService, ErrorService, StatusManager, _) {
var messagesStorage = {};
var messagesForHistory = {};
@ -719,6 +719,10 @@ angular.module('myApp.services') @@ -719,6 +719,10 @@ angular.module('myApp.services')
!message.action) {
return false;
}
if (message.reply_markup &&
message.reply_markup._ == 'replyInlineMarkup') {
return false;
}
var messageReplyMarkup = message.reply_markup;
var lastReplyMarkup = historyStorage.reply_markup;
if (messageReplyMarkup) {
@ -797,6 +801,7 @@ angular.module('myApp.services') @@ -797,6 +801,7 @@ angular.module('myApp.services')
if (historyStorage !== undefined && historyStorage.history.length) {
var neededContents = {},
neededDocType,
neededLimit = limit || 20,
i, message;
@ -805,26 +810,35 @@ angular.module('myApp.services') @@ -805,26 +810,35 @@ angular.module('myApp.services')
neededContents['messageMediaPhoto'] = true;
break;
case 'inputMessagesFilterVideo':
neededContents['messageMediaVideo'] = true;
break;
case 'inputMessagesFilterPhotoVideo':
neededContents['messageMediaPhoto'] = true;
neededContents['messageMediaVideo'] = true;
neededContents['messageMediaDocument'] = true;
neededDocType = 'video';
break;
case 'inputMessagesFilterVideo':
neededContents['messageMediaDocument'] = true;
neededDocType = 'video';
break;
case 'inputMessagesFilterDocument':
neededContents['messageMediaDocument'] = true;
neededDocType = false;
break;
case 'inputMessagesFilterAudio':
neededContents['messageMediaAudio'] = true;
case 'inputMessagesFilterVoice':
neededContents['messageMediaDocument'] = true;
neededDocType = 'voice';
break;
}
for (i = 0; i < historyStorage.history.length; i++) {
message = messagesStorage[historyStorage.history[i]];
if (message.media && neededContents[message.media._]) {
if (neededDocType !== undefined &&
message.media._ == 'messageMediaDocument' &&
message.media.document.type != neededDocType) {
continue;
}
foundMsgs.push(message.mid);
if (foundMsgs.length >= neededLimit) {
break;
@ -1199,15 +1213,9 @@ angular.module('myApp.services') @@ -1199,15 +1213,9 @@ angular.module('myApp.services')
case 'messageMediaPhoto':
AppPhotosManager.savePhoto(apiMessage.media.photo, mediaContext);
break;
case 'messageMediaVideo':
AppVideoManager.saveVideo(apiMessage.media.video, mediaContext);
break;
case 'messageMediaDocument':
AppDocsManager.saveDoc(apiMessage.media.document, mediaContext);
break;
case 'messageMediaAudio':
AppAudioManager.saveAudio(apiMessage.media.audio);
break;
case 'messageMediaWebPage':
AppWebPagesManager.saveWebPage(apiMessage.media.webpage, apiMessage.mid, mediaContext);
break;
@ -1559,14 +1567,6 @@ angular.module('myApp.services') @@ -1559,14 +1567,6 @@ angular.module('myApp.services')
inputMedia = {_: 'inputMediaUploadedPhoto', file: inputFile};
break;
case 'video':
inputMedia = {_: 'inputMediaUploadedVideo', file: inputFile, duration: 0, w: 0, h: 0, mime_type: file.type};
break;
case 'audio':
inputMedia = {_: 'inputMediaUploadedAudio', file: inputFile, duration: 0, mime_type: file.type};
break;
case 'document':
default:
inputMedia = {_: 'inputMediaUploadedDocument', file: inputFile, mime_type: file.type, caption: '', attributes: [
@ -2093,18 +2093,10 @@ angular.module('myApp.services') @@ -2093,18 +2093,10 @@ angular.module('myApp.services')
message.media.photo = AppPhotosManager.wrapForHistory(message.media.photo.id);
break;
case 'messageMediaVideo':
message.media.video = AppVideoManager.wrapForHistory(message.media.video.id);
break;
case 'messageMediaDocument':
message.media.document = AppDocsManager.wrapForHistory(message.media.document.id);
break;
case 'messageMediaAudio':
message.media.audio = AppAudioManager.wrapForHistory(message.media.audio.id);
break;
case 'messageMediaGeo':
var mapUrl = 'https://maps.google.com/?q=' + message.media.geo['lat'] + ',' + message.media.geo['long'];
message.media.mapUrl = $sce.trustAsResourceUrl(mapUrl);
@ -2453,11 +2445,8 @@ angular.module('myApp.services') @@ -2453,11 +2445,8 @@ angular.module('myApp.services')
case 'messageMediaPhoto':
notificationMessage = _('conversation_media_photo_raw');
break;
case 'messageMediaVideo':
notificationMessage = _('conversation_media_video_raw');
break;
case 'messageMediaDocument':
switch (message.media.document.isSpecial) {
switch (message.media.document.type) {
case 'gif':
notificationMessage = _('conversation_media_gif_raw');
break;
@ -2468,27 +2457,19 @@ angular.module('myApp.services') @@ -2468,27 +2457,19 @@ angular.module('myApp.services')
notificationMessage = RichTextProcessor.wrapPlainText(stickerEmoji) + ' ' + notificationMessage;
}
break;
case 'video':
notificationMessage = _('conversation_media_video_raw');
break;
case 'voice':
case 'audio':
notificationMessage = _('conversation_media_audio_raw');
break;
default:
notificationMessage = message.media.document.file_name || _('conversation_media_attachment_raw');
notificationMessage = message.media.document.file_name || _('conversation_media_document_raw');
break;
}
if (message.media.document.sticker) {
notificationMessage = _('conversation_media_sticker');
var stickerEmoji = message.media.document.stickerEmojiRaw;
if (stickerEmoji !== undefined) {
notificationMessage = RichTextProcessor.wrapPlainText(stickerEmoji) + ' (' + notificationMessage + ')';
}
} else {
notificationMessage = message.media.document.file_name || _('conversation_media_document_raw');
}
break;
case 'messageMediaAudio':
notificationMessage = _('conversation_media_audio_raw');
break;
case 'messageMediaGeo':
case 'messageMediaVenue':
notificationMessage = _('conversation_media_location_raw');

494
app/js/services.js

@ -1035,7 +1035,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1035,7 +1035,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
version: botInfo.version,
shareText: botInfo.share_text,
description: botInfo.description,
rAbout: RichTextProcessor.wrapRichText(botInfo.share_text, {noLinebreaks: true}),
commands: commands
};
}
@ -1055,13 +1054,21 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1055,13 +1054,21 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
AppUsersManager.saveApiUser(userFull.user, true);
}
AppPhotosManager.savePhoto(userFull.profile_photo, {
user_id: id
});
if (userFull.profile_photo) {
AppPhotosManager.savePhoto(userFull.profile_photo, {
user_id: id
});
}
if (userFull.about !== undefined) {
userFull.rAbout = RichTextProcessor.wrapRichText(userFull.about, {noLinebreaks: true});
}
NotificationsManager.savePeerSettings(id, userFull.notify_settings);
userFull.bot_info = saveBotInfo(userFull.bot_info);
if (userFull.bot_info) {
userFull.bot_info = saveBotInfo(userFull.bot_info);
}
return userFull;
});
@ -1733,203 +1740,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1733,203 +1740,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
})
.service('AppVideoManager', function ($sce, $rootScope, $modal, $window, MtpApiFileManager, AppUsersManager, FileManager, qSync) {
var videos = {},
videosForHistory = {},
windowW = $(window).width(),
windowH = $(window).height();
function saveVideo (apiVideo, context) {
if (context) {
angular.extend(apiVideo, context);
}
videos[apiVideo.id] = apiVideo;
if (apiVideo.thumb && apiVideo.thumb._ == 'photoCachedSize') {
MtpApiFileManager.saveSmallFile(apiVideo.thumb.location, apiVideo.thumb.bytes);
// Memory
apiVideo.thumb.size = apiVideo.thumb.bytes.length;
delete apiVideo.thumb.bytes;
apiVideo.thumb._ = 'photoSize';
}
};
function wrapForHistory (videoID) {
if (videosForHistory[videoID] !== undefined) {
return videosForHistory[videoID];
}
var video = angular.copy(videos[videoID]),
width = Math.min(windowW - 80, Config.Mobile ? 210 : 150),
height = Math.min(windowH - 100, Config.Mobile ? 210 : 150),
thumbPhotoSize = video.thumb,
thumb = {
placeholder: 'img/placeholders/VideoThumbConversation.gif',
width: width,
height: height
};
if (thumbPhotoSize && thumbPhotoSize._ != 'photoSizeEmpty') {
if ((thumbPhotoSize.w / thumbPhotoSize.h) > (width / height)) {
thumb.height = parseInt(thumbPhotoSize.h * width / thumbPhotoSize.w);
}
else {
thumb.width = parseInt(thumbPhotoSize.w * height / thumbPhotoSize.h);
if (thumb.width > width) {
thumb.height = parseInt(thumb.height * width / thumb.width);
thumb.width = width;
}
}
thumb.location = thumbPhotoSize.location;
thumb.size = thumbPhotoSize.size;
}
video.thumb = thumb;
return videosForHistory[videoID] = video;
}
function wrapForFull (videoID) {
var video = wrapForHistory(videoID),
fullWidth = Math.min($(window).width() - (Config.Mobile ? 0 : 60), 542),
fullHeight = $($window).height() - (Config.Mobile ? 92 : 150),
fullPhotoSize = video,
full = {
placeholder: 'img/placeholders/VideoThumbModal.gif',
width: fullWidth,
height: fullHeight,
};
if (!video.w || !video.h) {
full.height = full.width = Math.min(fullWidth, fullHeight);
} else {
var wh = calcImageInBox(video.w, video.h, fullWidth, fullHeight);
full.width = wh.w;
full.height = wh.h;
}
video.full = full;
video.fullThumb = angular.copy(video.thumb);
video.fullThumb.width = full.width;
video.fullThumb.height = full.height;
return video;
}
function openVideo (videoID, messageID) {
var scope = $rootScope.$new(true);
scope.videoID = videoID;
scope.messageID = messageID;
return $modal.open({
templateUrl: templateUrl('video_modal'),
windowTemplateUrl: templateUrl('media_modal_layout'),
controller: 'VideoModalController',
scope: scope,
windowClass: 'video_modal_window'
});
}
function updateVideoDownloaded (videoID) {
var video = videos[videoID],
historyVideo = videosForHistory[videoID] || video || {},
inputFileLocation = {
_: 'inputVideoFileLocation',
id: videoID,
access_hash: video.access_hash
};
// historyVideo.progress = {enabled: true, percent: 10, total: video.size};
if (historyVideo.downloaded === undefined) {
MtpApiFileManager.getDownloadedFile(inputFileLocation, video.size).then(function () {
historyVideo.downloaded = true;
}, function () {
historyVideo.downloaded = false;
});
}
}
function downloadVideo (videoID, toFileEntry) {
var video = videos[videoID],
historyVideo = videosForHistory[videoID] || video || {},
mimeType = video.mime_type || 'video/ogg',
inputFileLocation = {
_: 'inputVideoFileLocation',
id: videoID,
access_hash: video.access_hash
};
if (historyVideo.downloaded && !toFileEntry) {
var cachedBlob = MtpApiFileManager.getCachedFile(inputFileLocation);
if (cachedBlob) {
return qSync.when(cachedBlob);
}
}
historyVideo.progress = {enabled: !historyVideo.downloaded, percent: 1, total: video.size};
var downloadPromise = MtpApiFileManager.downloadFile(video.dc_id, inputFileLocation, video.size, {
mime: mimeType,
toFileEntry: toFileEntry
});
downloadPromise.then(function (blob) {
FileManager.getFileCorrectUrl(blob, mimeType).then(function (url) {
historyVideo.url = $sce.trustAsResourceUrl(url);
});
delete historyVideo.progress;
historyVideo.downloaded = true;
console.log('video save done');
}, function (e) {
console.log('video download failed', e);
historyVideo.progress.enabled = false;
}, function (progress) {
console.log('dl progress', progress);
historyVideo.progress.enabled = true;
historyVideo.progress.done = progress.done;
historyVideo.progress.percent = Math.max(1, Math.floor(100 * progress.done / progress.total));
$rootScope.$broadcast('history_update');
});
historyVideo.progress.cancel = downloadPromise.cancel;
return downloadPromise;
}
function saveVideoFile (videoID) {
var video = videos[videoID],
mimeType = video.mime_type || 'video/mp4',
fileExt = mimeType.split('.')[1] || 'mp4',
fileName = 't_video' + videoID + '.' + fileExt,
historyVideo = videosForHistory[videoID] || video || {};
FileManager.chooseSave(fileName, fileExt, mimeType).then(function (writableFileEntry) {
if (writableFileEntry) {
downloadVideo(videoID, writableFileEntry);
}
}, function () {
downloadVideo(videoID).then(function (blob) {
FileManager.download(blob, mimeType, fileName);
});
});
}
return {
saveVideo: saveVideo,
wrapForHistory: wrapForHistory,
wrapForFull: wrapForFull,
openVideo: openVideo,
updateVideoDownloaded: updateVideoDownloaded,
downloadVideo: downloadVideo,
saveVideoFile: saveVideoFile
}
})
.service('AppDocsManager', function ($sce, $rootScope, $modal, $window, $q, $timeout, RichTextProcessor, MtpApiFileManager, FileManager, qSync) {
var docs = {},
docsForHistory = {},
@ -1950,6 +1760,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1950,6 +1760,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
delete apiDoc.thumb.bytes;
apiDoc.thumb._ = 'photoSize';
}
if (apiDoc.thumb && apiDoc.thumb._ == 'photoSizeEmpty') {
delete apiDoc.thumb;
}
angular.forEach(apiDoc.attributes, function (attribute) {
switch (attribute._) {
case 'documentAttributeFilename':
@ -1959,11 +1772,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1959,11 +1772,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
apiDoc.duration = attribute.duration;
apiDoc.audioTitle = attribute.title;
apiDoc.audioPerformer = attribute.performer;
apiDoc.type = attribute.pFlags.voice ? 'voice' : 'audio';
break;
case 'documentAttributeVideo':
apiDoc.duration = attribute.duration;
apiDoc.w = attribute.w;
apiDoc.h = attribute.h;
apiDoc.type = 'video';
break;
case 'documentAttributeSticker':
apiDoc.sticker = true;
@ -1979,34 +1794,43 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -1979,34 +1794,43 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
apiDoc.stickerSetInput = attribute.stickerset;
}
}
if (apiDoc.mime_type == 'image/webp') {
apiDoc.type = 'sticker';
}
break;
case 'documentAttributeImageSize':
apiDoc.w = attribute.w;
apiDoc.h = attribute.h;
break;
case 'documentAttributeAnimated':
if ((apiDoc.mime_type == 'image/gif' || apiDoc.mime_type == 'video/mp4') &&
apiDoc.thumb &&
apiDoc.thumb._ == 'photoSize') {
apiDoc.type = 'gif';
}
apiDoc.animated = true;
break;
}
});
apiDoc.mime_type = apiDoc.mime_type || '';
apiDoc.file_name = apiDoc.file_name || 'file';
if (apiDoc._ == 'documentEmpty') {
apiDoc.file_name = 'DELETED';
apiDoc.size = 0;
if (!apiDoc.mime_type) {
switch (apiDoc.type) {
case 'gif': apiDoc.mime_type = 'video/mp4'; break;
case 'video': apiDoc.mime_type = 'video/mp4'; break;
case 'sticker': apiDoc.mime_type = 'image/webp'; break;
case 'audio': apiDoc.mime_type = 'audio/mpeg'; break;
case 'voice': apiDoc.mime_type = 'audio/ogg'; break;
default: apiDoc.mime_type = 'application/octet-stream'; break;
}
}
if ((apiDoc.mime_type == 'image/gif' || apiDoc.animated && apiDoc.mime_type == 'video/mp4') && apiDoc.thumb && apiDoc.thumb._ == 'photoSize') {
apiDoc.isSpecial = 'gif';
}
else if (apiDoc.mime_type == 'image/webp' && apiDoc.sticker) {
apiDoc.isSpecial = 'sticker';
}
else if (apiDoc.mime_type.substr(0, 6) == 'audio/') {
apiDoc.isSpecial = 'audio';
if (!apiDoc.file_name) {
apiDoc.file_name = '';
}
if (apiDoc._ == 'documentEmpty') {
apiDoc.size = 0;
}
};
@ -2018,50 +1842,66 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2018,50 +1842,66 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return docs[docID] !== undefined;
}
function getFileName(doc) {
if (doc.file_name) {
return doc.file_name;
}
var fileExt = '.' + doc.mime_type.split('.')[1];
if (fileExt == '.octet-stream') {
fileExt = '';
}
return 't_' + (doc.type || 'file') + doc.id + fileExt;
}
function wrapForHistory (docID) {
if (docsForHistory[docID] !== undefined) {
return docsForHistory[docID];
}
var doc = angular.copy(docs[docID]),
isGif = doc.isSpecial == 'gif',
isSticker = doc.isSpecial == 'sticker',
thumbPhotoSize = doc.thumb,
width, height, thumb, dim;
inlineImage = false,
boxWidth, boxHeight, thumb, dim;
if (isGif) {
width = Math.min(windowW - 80, Config.Mobile ? 210 : 260);
height = Math.min(windowH - 100, Config.Mobile ? 210 : 260);
}
else if (isSticker) {
width = Math.min(windowW - 80, Config.Mobile ? 128 : 192);
height = Math.min(windowH - 100, Config.Mobile ? 128 : 192);
} else {
width = height = 100;
}
switch (doc.type) {
case 'video':
boxWidth = Math.min(windowW - 80, Config.Mobile ? 210 : 150),
boxHeight = Math.min(windowH - 100, Config.Mobile ? 210 : 150);
break;
thumb = {
width: width,
height: height
};
case 'sticker':
inlineImage = true;
boxWidth = Math.min(windowW - 80, Config.Mobile ? 128 : 192);
boxHeight = Math.min(windowH - 100, Config.Mobile ? 128 : 192);
break;
if (thumbPhotoSize && thumbPhotoSize._ != 'photoSizeEmpty') {
if (isGif && doc.w && doc.h) {
dim = calcImageInBox(doc.w, doc.h, width, height);
} else {
dim = calcImageInBox(thumbPhotoSize.w, thumbPhotoSize.h, width, height);
}
thumb.width = dim.w;
thumb.height = dim.h;
thumb.location = thumbPhotoSize.location;
thumb.size = thumbPhotoSize.size;
case 'gif':
inlineImage = true;
boxWidth = Math.min(windowW - 80, Config.Mobile ? 210 : 260);
boxHeight = Math.min(windowH - 100, Config.Mobile ? 210 : 260);
break;
default:
boxWidth = boxHeight = 100;
}
else if (isSticker) {
dim = calcImageInBox(doc.w, doc.h, width, height);
thumb.width = dim.w;
thumb.height = dim.h;
if (inlineImage && doc.w && doc.h) {
dim = calcImageInBox(doc.w, doc.h, boxWidth, boxHeight);
}
else {
else if (thumbPhotoSize) {
dim = calcImageInBox(thumbPhotoSize.w, thumbPhotoSize.h, boxWidth, boxHeight);
}
if (dim) {
thumb = {
width: dim.w,
height: dim.h
};
if (thumbPhotoSize) {
thumb.location = thumbPhotoSize.location;
thumb.size = thumbPhotoSize.size;
}
} else {
thumb = false;
}
doc.thumb = thumb;
@ -2078,7 +1918,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2078,7 +1918,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
_: 'inputDocumentFileLocation',
id: docID,
access_hash: doc.access_hash,
file_name: doc.file_name
file_name: getFileName(doc)
};
if (historyDoc.downloaded === undefined) {
@ -2097,7 +1937,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2097,7 +1937,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
_: 'inputDocumentFileLocation',
id: docID,
access_hash: doc.access_hash,
file_name: doc.file_name
file_name: getFileName(doc)
};
if (doc._ == 'documentEmpty') {
@ -2164,141 +2004,73 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2164,141 +2004,73 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
function saveDocFile (docID) {
var doc = docs[docID],
historyDoc = docsForHistory[docID] || doc || {};
historyDoc = docsForHistory[docID] || doc || {},
mimeType = video.mime_type || 'video/mp4',
fileName = getFileName(doc),
ext = (fileName.split('.', 2) || [])[1] || '';
var ext = (doc.file_name.split('.', 2) || [])[1] || '';
FileManager.chooseSave(doc.file_name, ext, doc.mime_type).then(function (writableFileEntry) {
FileManager.chooseSave(getFileName(doc), ext, doc.mime_type).then(function (writableFileEntry) {
if (writableFileEntry) {
downloadDoc(docID, writableFileEntry);
}
}, function () {
downloadDoc(docID).then(function (blob) {
FileManager.download(blob, doc.mime_type, doc.file_name);
FileManager.download(blob, doc.mime_type, fileName);
});
});
}
return {
saveDoc: saveDoc,
getDoc: getDoc,
hasDoc: hasDoc,
wrapForHistory: wrapForHistory,
updateDocDownloaded: updateDocDownloaded,
downloadDoc: downloadDoc,
openDoc: openDoc,
saveDocFile: saveDocFile
}
})
.service('AppAudioManager', function ($sce, $rootScope, $modal, $window, MtpApiFileManager, FileManager, qSync) {
var audios = {};
var audiosForHistory = {};
function saveAudio (apiAudio) {
audios[apiAudio.id] = apiAudio;
};
function wrapForHistory (audioID) {
if (audiosForHistory[audioID] !== undefined) {
return audiosForHistory[audioID];
}
var audio = angular.copy(audios[audioID]);
return audiosForHistory[audioID] = audio;
}
function updateAudioDownloaded (audioID) {
var audio = audios[audioID],
historyAudio = audiosForHistory[audioID] || audio || {},
inputFileLocation = {
_: 'inputAudioFileLocation',
id: audioID,
access_hash: audio.access_hash
};
// historyAudio.progress = {enabled: !historyAudio.downloaded, percent: 10, total: audio.size};
if (historyAudio.downloaded === undefined) {
MtpApiFileManager.getDownloadedFile(inputFileLocation, audio.size).then(function () {
historyAudio.downloaded = true;
}, function () {
historyAudio.downloaded = false;
});
}
}
function downloadAudio (audioID, toFileEntry) {
var audio = audios[audioID],
historyAudio = audiosForHistory[audioID] || audio || {},
mimeType = audio.mime_type || 'audio/ogg',
inputFileLocation = {
_: 'inputAudioFileLocation',
id: audioID,
access_hash: audio.access_hash
function wrapVideoForFull (docID) {
var doc = wrapForHistory(docID),
fullWidth = Math.min($(window).width() - (Config.Mobile ? 0 : 60), 542),
fullHeight = $(window).height() - (Config.Mobile ? 92 : 150),
full = {
placeholder: 'img/placeholders/docThumbModal.gif',
width: fullWidth,
height: fullHeight,
};
if (historyAudio.downloaded && !toFileEntry) {
var cachedBlob = MtpApiFileManager.getCachedFile(inputFileLocation);
if (cachedBlob) {
return qSync.when(cachedBlob);
}
if (!doc.w || !doc.h) {
full.height = full.width = Math.min(fullWidth, fullHeight);
} else {
var dim = calcImageInBox(doc.w, doc.h, fullWidth, fullHeight);
full.width = dim.w;
full.height = dim.h;
}
historyAudio.progress = {enabled: !historyAudio.downloaded, percent: 1, total: audio.size};
var downloadPromise = MtpApiFileManager.downloadFile(audio.dc_id, inputFileLocation, audio.size, {
mime: mimeType,
toFileEntry: toFileEntry
});
downloadPromise.then(function (blob) {
FileManager.getFileCorrectUrl(blob, mimeType).then(function (url) {
historyAudio.url = $sce.trustAsResourceUrl(url);
});
delete historyAudio.progress;
historyAudio.downloaded = true;
console.log('audio save done');
}, function (e) {
console.log('audio download failed', e);
historyAudio.progress.enabled = false;
}, function (progress) {
console.log('dl progress', progress);
historyAudio.progress.enabled = true;
historyAudio.progress.done = progress.done;
historyAudio.progress.percent = Math.max(1, Math.floor(100 * progress.done / progress.total));
$rootScope.$broadcast('history_update');
});
historyAudio.progress.cancel = downloadPromise.cancel;
doc.full = full;
doc.fullThumb = angular.copy(doc.thumb);
doc.fullThumb.width = full.width;
doc.fullThumb.height = full.height;
return downloadPromise;
return doc;
}
function saveAudioFile (audioID) {
var audio = audios[audioID],
mimeType = audio.mime_type || 'audio/ogg',
fileExt = mimeType.split('.')[1] || 'ogg',
fileName = 't_audio' + audioID + '.' + fileExt,
historyAudio = audiosForHistory[audioID] || audio || {};
function openVideo (docID, messageID) {
var scope = $rootScope.$new(true);
scope.docID = docID;
scope.messageID = messageID;
FileManager.chooseSave(fileName, fileExt, mimeType).then(function (writableFileEntry) {
if (writableFileEntry) {
downloadAudio(audioID, writableFileEntry);
}
}, function () {
downloadAudio(audioID).then(function (blob) {
FileManager.download(blob, mimeType, fileName);
});
return $modal.open({
templateUrl: templateUrl('video_modal'),
windowTemplateUrl: templateUrl('media_modal_layout'),
controller: 'VideoModalController',
scope: scope,
windowClass: 'video_modal_window'
});
}
return {
saveAudio: saveAudio,
saveDoc: saveDoc,
getDoc: getDoc,
hasDoc: hasDoc,
wrapForHistory: wrapForHistory,
updateAudioDownloaded: updateAudioDownloaded,
downloadAudio: downloadAudio,
saveAudioFile: saveAudioFile
wrapVideoForFull: wrapVideoForFull,
updateDocDownloaded: updateDocDownloaded,
downloadDoc: downloadDoc,
openDoc: openDoc,
openVideo: openVideo,
saveDocFile: saveDocFile
}
})

6
app/partials/desktop/dialog.html

@ -59,17 +59,17 @@ @@ -59,17 +59,17 @@
<span class="im_dialog_message_media" ng-if="dialogMessage.media" ng-switch="dialogMessage.media._">
<span ng-switch-when="messageMediaPhoto" my-i18n="conversation_media_photo"></span>
<span ng-switch-when="messageMediaVideo" my-i18n="conversation_media_video"></span>
<span ng-switch-when="messageMediaDocument" ng-switch="dialogMessage.media.document.isSpecial || false">
<span ng-switch-when="messageMediaDocument" ng-switch="dialogMessage.media.document.type || false">
<span ng-switch-when="sticker">
<span ng-bind-html="dialogMessage.media.document.stickerEmoji"></span>
<my-i18n msgid="conversation_media_sticker"></my-i18n>
</span>
<span ng-switch-when="gif" my-i18n="conversation_media_gif"></span>
<span ng-switch-when="audio" my-i18n="conversation_media_audio"></span>
<span ng-switch-when="voice" my-i18n="conversation_media_audio"></span>
<span ng-switch-when="video" my-i18n="conversation_media_video"></span>
<span ng-switch-default ng-bind="dialogMessage.media.document.file_name"></span>
</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>

6
app/partials/desktop/message_attach_document.html

@ -1,9 +1,13 @@ @@ -1,9 +1,13 @@
<div ng-switch="::media.document.isSpecial">
<div ng-switch="::media.document.type">
<div ng-switch-when="gif" my-load-gif document="media.document"></div>
<div ng-switch-when="sticker" my-load-sticker document="media.document" open="true"></div>
<div ng-switch-when="voice" class="im_message_audio">
<div my-audio-player audio="media.document"></div>
</div>
<div ng-switch-when="audio" class="im_message_audio">
<div my-audio-player audio="media.document"></div>
</div>

6
app/partials/desktop/reply_message.html

@ -20,17 +20,17 @@ @@ -20,17 +20,17 @@
<span class="im_reply_message_media" ng-if="replyMessage.media" ng-switch="replyMessage.media._">
<span ng-switch-when="messageMediaPhoto" my-i18n="conversation_media_photo"></span>
<span ng-switch-when="messageMediaVideo" my-i18n="conversation_media_video"></span>
<span ng-switch-when="messageMediaDocument" ng-switch="dialogMessage.media.document.isSpecial || false">
<span ng-switch-when="messageMediaDocument" ng-switch="dialogMessage.media.document.type || false">
<span ng-switch-when="sticker">
<span ng-bind-html="replyMessage.media.document.stickerEmoji"></span>
<my-i18n msgid="conversation_media_sticker"></my-i18n>
</span>
<span ng-switch-when="gif" my-i18n="conversation_media_gif"></span>
<span ng-switch-when="video" my-i18n="conversation_media_video"></span>
<span ng-switch-when="audio" my-i18n="conversation_media_audio"></span>
<span ng-switch-when="voice" my-i18n="conversation_media_audio"></span>
<span ng-switch-default ng-bind="replyMessage.media.document.file_name"></span>
</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>

16
app/partials/desktop/user_modal.html

@ -33,16 +33,9 @@ @@ -33,16 +33,9 @@
<div class="md_modal_sections clearfix">
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_number" ng-if="user.phone || user.username">
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_number" ng-if="user.phone || user.username || rAbout">
<i class="md_modal_section_icon md_modal_section_icon_phone"></i>
<div class="md_modal_section_param_wrap" ng-if="user.pFlags.bot &amp;&amp; bot_info.rAbout">
<div class="md_modal_section_param_value">
<span ng-bind-html="bot_info.rAbout"></span>
</div>
<div class="md_modal_section_param_name" my-i18n="user_modal_about"></div>
</div>
<div class="md_modal_section_param_wrap" ng-if="user.phone">
<div class="md_modal_section_param_value" ng-bind="user.phone | phoneNumber"></div>
<div class="md_modal_section_param_name" my-i18n="user_modal_phone"></div>
@ -54,6 +47,13 @@ @@ -54,6 +47,13 @@
</div>
<div class="md_modal_section_param_name" my-i18n="user_modal_username"></div>
</div>
<div class="md_modal_section_param_wrap" ng-if="rAbout">
<div class="md_modal_section_param_value">
<span ng-bind-html="rAbout"></span>
</div>
<div class="md_modal_section_param_name" my-i18n="user_modal_about"></div>
</div>
</div>
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_toggle">

6
app/partials/mobile/dialog.html

@ -59,17 +59,17 @@ @@ -59,17 +59,17 @@
<span class="im_dialog_message_media" ng-if="dialogMessage.media" ng-switch="dialogMessage.media._">
<span ng-switch-when="messageMediaPhoto" my-i18n="conversation_media_photo"></span>
<span ng-switch-when="messageMediaVideo" my-i18n="conversation_media_video"></span>
<span ng-switch-when="messageMediaDocument" ng-switch="dialogMessage.media.document.isSpecial || false">
<span ng-switch-when="messageMediaDocument" ng-switch="dialogMessage.media.document.type || false">
<span ng-switch-when="sticker">
<span ng-bind-html="dialogMessage.media.document.stickerEmoji"></span>
<my-i18n msgid="conversation_media_sticker"></my-i18n>
</span>
<span ng-switch-when="video" my-i18n="conversation_media_video"></span>
<span ng-switch-when="gif" my-i18n="conversation_media_gif"></span>
<span ng-switch-when="audio" my-i18n="conversation_media_audio"></span>
<span ng-switch-when="voice" my-i18n="conversation_media_audio"></span>
<span ng-switch-default ng-bind="dialogMessage.media.document.file_name"></span>
</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>

6
app/partials/mobile/message_attach_document.html

@ -1,9 +1,13 @@ @@ -1,9 +1,13 @@
<div ng-switch="::media.document.isSpecial">
<div ng-switch="::media.document.type">
<div ng-switch-when="gif" my-load-gif document="media.document"></div>
<div ng-switch-when="sticker" my-load-sticker document="media.document" open="true"></div>
<div ng-switch-when="voice" class="im_message_audio">
<div my-audio-player audio="media.document"></div>
</div>
<div ng-switch-when="audio" class="im_message_audio">
<div my-audio-player audio="media.document"></div>
</div>

4
app/partials/mobile/user_modal.html

@ -58,9 +58,9 @@ @@ -58,9 +58,9 @@
</div>
<div class="mobile_modal_section" ng-if="user.pFlags.bot &amp;&amp; bot_info.rAbout">
<div class="mobile_modal_section" ng-if="rAbout">
<h4 class="mobile_modal_section_header" my-i18n="user_modal_about"></h4>
<div class="mobile_modal_section_value" ng-bind-html="bot_info.rAbout"></div>
<div class="mobile_modal_section_value" ng-bind-html="rAbout"></div>
</div>
<div class="mobile_modal_action_wrap">

Loading…
Cancel
Save