|
|
@ -1214,8 +1214,10 @@ angular.module('myApp.services', []) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
message.send = function () { |
|
|
|
message.send = function () { |
|
|
|
var uploaded = false; |
|
|
|
var uploaded = false, |
|
|
|
var promise = MtpApiFileManager.uploadFile(file).then(function (inputFile) { |
|
|
|
uploadPromise = MtpApiFileManager.uploadFile(file); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uploadPromise.then(function (inputFile) { |
|
|
|
uploaded = true; |
|
|
|
uploaded = true; |
|
|
|
var inputMedia; |
|
|
|
var inputMedia; |
|
|
|
switch (attachType) { |
|
|
|
switch (attachType) { |
|
|
@ -1265,22 +1267,15 @@ angular.module('myApp.services', []) |
|
|
|
toggleError(true); |
|
|
|
toggleError(true); |
|
|
|
}, function (progress) { |
|
|
|
}, function (progress) { |
|
|
|
// console.log('upload progress', progress);
|
|
|
|
// console.log('upload progress', progress);
|
|
|
|
var historyMessage = messagesForHistory[messageID], |
|
|
|
|
|
|
|
percent = Math.max(1, Math.floor(100 * progress.done / progress.total)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
media.progress.done = progress.done; |
|
|
|
media.progress.done = progress.done; |
|
|
|
media.progress.percent = percent; |
|
|
|
media.progress.percent = Math.max(1, Math.floor(100 * progress.done / progress.total)); |
|
|
|
if (historyMessage) { |
|
|
|
$rootScope.$broadcast('history_update', {peerID: peerID}); |
|
|
|
historyMessage.media.progress.done = progress.done; |
|
|
|
|
|
|
|
historyMessage.media.progress.percent = percent; |
|
|
|
|
|
|
|
$rootScope.$broadcast('history_update', {peerID: peerID}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
media.progress.cancel = function () { |
|
|
|
media.progress.cancel = function () { |
|
|
|
if (!uploaded) { |
|
|
|
if (!uploaded) { |
|
|
|
promise.cancel(); |
|
|
|
uploadPromise.cancel(); |
|
|
|
cancelPendingMessage(randomID); |
|
|
|
cancelPendingMessage(randomIDS); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
@ -1407,12 +1402,19 @@ angular.module('myApp.services', []) |
|
|
|
function cancelPendingMessage (randomID) { |
|
|
|
function cancelPendingMessage (randomID) { |
|
|
|
var pendingData = pendingByRandomID[randomID]; |
|
|
|
var pendingData = pendingByRandomID[randomID]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('pending', randomID, pendingData); |
|
|
|
|
|
|
|
|
|
|
|
if (pendingData) { |
|
|
|
if (pendingData) { |
|
|
|
var peerID = pendingData[0], |
|
|
|
var peerID = pendingData[0], |
|
|
|
tempID = pendingData[1], |
|
|
|
tempID = pendingData[1], |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
i; |
|
|
|
i; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApiUpdatesManager.saveUpdate({ |
|
|
|
|
|
|
|
_: 'updateDeleteMessages', |
|
|
|
|
|
|
|
messages: [tempID] |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < historyStorage.pending.length; i++) { |
|
|
|
for (i = 0; i < historyStorage.pending.length; i++) { |
|
|
|
if (historyStorage.pending[i] == tempID) { |
|
|
|
if (historyStorage.pending[i] == tempID) { |
|
|
|
historyStorage.pending.splice(i, 1); |
|
|
|
historyStorage.pending.splice(i, 1); |
|
|
@ -1423,10 +1425,6 @@ angular.module('myApp.services', []) |
|
|
|
delete messagesForHistory[tempID]; |
|
|
|
delete messagesForHistory[tempID]; |
|
|
|
delete messagesStorage[tempID]; |
|
|
|
delete messagesStorage[tempID]; |
|
|
|
|
|
|
|
|
|
|
|
ApiUpdatesManager.saveUpdate({ |
|
|
|
|
|
|
|
_: 'updateDeleteMessages', |
|
|
|
|
|
|
|
messages: [tempID] |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -1533,8 +1531,8 @@ angular.module('myApp.services', []) |
|
|
|
|
|
|
|
|
|
|
|
var message = angular.copy(messagesStorage[msgID]) || {id: msgID}; |
|
|
|
var message = angular.copy(messagesStorage[msgID]) || {id: msgID}; |
|
|
|
|
|
|
|
|
|
|
|
if (message.progress) { |
|
|
|
if (message.media && message.media.progress !== undefined) { |
|
|
|
message.progress = messagesStorage[msgID].progress; |
|
|
|
message.media.progress = messagesStorage[msgID].media.progress; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
message.fromUser = AppUsersManager.getUser(message.from_id); |
|
|
|
message.fromUser = AppUsersManager.getUser(message.from_id); |
|
|
@ -1836,13 +1834,22 @@ angular.module('myApp.services', []) |
|
|
|
|
|
|
|
|
|
|
|
var historyStorage = historiesStorage[peerID]; |
|
|
|
var historyStorage = historiesStorage[peerID]; |
|
|
|
if (historyStorage !== undefined) { |
|
|
|
if (historyStorage !== undefined) { |
|
|
|
var newHistory = []; |
|
|
|
var newHistory = [], |
|
|
|
|
|
|
|
newPending = []; |
|
|
|
for (var i = 0; i < historyStorage.history.length; i++) { |
|
|
|
for (var i = 0; i < historyStorage.history.length; i++) { |
|
|
|
if (!updatedData.msgs[historyStorage.history[i]]) { |
|
|
|
if (!updatedData.msgs[historyStorage.history[i]]) { |
|
|
|
newHistory.push(historyStorage.history[i]); |
|
|
|
newHistory.push(historyStorage.history[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
historyStorage.history = newHistory; |
|
|
|
historyStorage.history = newHistory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < historyStorage.pending.length; i++) { |
|
|
|
|
|
|
|
if (!updatedData.msgs[historyStorage.pending[i]]) { |
|
|
|
|
|
|
|
newPending.push(historyStorage.pending[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
historyStorage.pending = newPending; |
|
|
|
|
|
|
|
|
|
|
|
$rootScope.$broadcast('history_delete', {peerID: peerID, msgs: updatedData.msgs}); |
|
|
|
$rootScope.$broadcast('history_delete', {peerID: peerID, msgs: updatedData.msgs}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -2154,16 +2161,21 @@ angular.module('myApp.services', []) |
|
|
|
extensions: [ext] |
|
|
|
extensions: [ext] |
|
|
|
}] |
|
|
|
}] |
|
|
|
}, function (writableFileEntry) { |
|
|
|
}, function (writableFileEntry) { |
|
|
|
MtpApiFileManager.downloadFile(video.dc_id, inputFileLocation, video.size, writableFileEntry, {mime: mimeType}).then(function (url) { |
|
|
|
var downloadPromise = MtpApiFileManager.downloadFile(video.dc_id, inputFileLocation, video.size, writableFileEntry, {mime: mimeType}); |
|
|
|
|
|
|
|
downloadPromise.then(function (url) { |
|
|
|
delete historyVideo.progress; |
|
|
|
delete historyVideo.progress; |
|
|
|
console.log('file save done'); |
|
|
|
console.log('file save done'); |
|
|
|
}, function (e) { |
|
|
|
}, function (e) { |
|
|
|
console.log('video download failed', e); |
|
|
|
console.log('video download failed', e); |
|
|
|
historyVideo.progress.enabled = false; |
|
|
|
historyVideo.progress.enabled = false; |
|
|
|
}, updateDownloadProgress); |
|
|
|
}, updateDownloadProgress); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
historyVideo.progress.cancel = downloadPromise.cancel; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
MtpApiFileManager.downloadFile(video.dc_id, inputFileLocation, video.size, null, {mime: mimeType}).then(function (url) { |
|
|
|
var downloadPromise = MtpApiFileManager.downloadFile(video.dc_id, inputFileLocation, video.size, null, {mime: mimeType}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
downloadPromise.then(function (url) { |
|
|
|
delete historyVideo.progress; |
|
|
|
delete historyVideo.progress; |
|
|
|
|
|
|
|
|
|
|
|
if (popup) { |
|
|
|
if (popup) { |
|
|
@ -2187,6 +2199,8 @@ angular.module('myApp.services', []) |
|
|
|
console.log('video download failed', e); |
|
|
|
console.log('video download failed', e); |
|
|
|
historyVideo.progress.enabled = false; |
|
|
|
historyVideo.progress.enabled = false; |
|
|
|
}, updateDownloadProgress); |
|
|
|
}, updateDownloadProgress); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
historyVideo.progress.cancel = downloadPromise.cancel; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -2283,16 +2297,22 @@ angular.module('myApp.services', []) |
|
|
|
extensions: [ext] |
|
|
|
extensions: [ext] |
|
|
|
}] |
|
|
|
}] |
|
|
|
}, function (writableFileEntry) { |
|
|
|
}, function (writableFileEntry) { |
|
|
|
MtpApiFileManager.downloadFile(doc.dc_id, inputFileLocation, doc.size, writableFileEntry, {mime: doc.mime_type}).then(function (url) { |
|
|
|
var downloadPromise = MtpApiFileManager.downloadFile(doc.dc_id, inputFileLocation, doc.size, writableFileEntry, {mime: doc.mime_type}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
downloadPromise.then(function (url) { |
|
|
|
delete historyDoc.progress; |
|
|
|
delete historyDoc.progress; |
|
|
|
console.log('file save done'); |
|
|
|
console.log('file save done'); |
|
|
|
}, function (e) { |
|
|
|
}, function (e) { |
|
|
|
console.log('document download failed', e); |
|
|
|
console.log('document download failed', e); |
|
|
|
historyDoc.progress.enabled = false; |
|
|
|
historyDoc.progress.enabled = false; |
|
|
|
}, updateDownloadProgress); |
|
|
|
}, updateDownloadProgress); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
historyDoc.progress.cancel = downloadPromise.cancel; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
MtpApiFileManager.downloadFile(doc.dc_id, inputFileLocation, doc.size, null, {mime: doc.mime_type}).then(function (url) { |
|
|
|
var downloadPromise = MtpApiFileManager.downloadFile(doc.dc_id, inputFileLocation, doc.size, null, {mime: doc.mime_type}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
downloadPromise.then(function (url) { |
|
|
|
delete historyDoc.progress; |
|
|
|
delete historyDoc.progress; |
|
|
|
|
|
|
|
|
|
|
|
if (popup) { |
|
|
|
if (popup) { |
|
|
@ -2316,6 +2336,8 @@ angular.module('myApp.services', []) |
|
|
|
console.log('document download failed', e); |
|
|
|
console.log('document download failed', e); |
|
|
|
historyDoc.progress.enabled = false; |
|
|
|
historyDoc.progress.enabled = false; |
|
|
|
}, updateDownloadProgress); |
|
|
|
}, updateDownloadProgress); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
historyDoc.progress.cancel = downloadPromise.cancel; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2364,7 +2386,9 @@ angular.module('myApp.services', []) |
|
|
|
$rootScope.$broadcast('history_update'); |
|
|
|
$rootScope.$broadcast('history_update'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MtpApiFileManager.downloadFile(audio.dc_id, inputFileLocation, audio.size, null, {mime: 'audio/mpeg'}).then(function (url) { |
|
|
|
var downloadPromise = MtpApiFileManager.downloadFile(audio.dc_id, inputFileLocation, audio.size, null, {mime: 'audio/mpeg'}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
downloadPromise.then(function (url) { |
|
|
|
delete historyAudio.progress; |
|
|
|
delete historyAudio.progress; |
|
|
|
historyAudio.url = $sce.trustAsResourceUrl(url); |
|
|
|
historyAudio.url = $sce.trustAsResourceUrl(url); |
|
|
|
historyAudio.autoplay = true; |
|
|
|
historyAudio.autoplay = true; |
|
|
@ -2374,9 +2398,11 @@ angular.module('myApp.services', []) |
|
|
|
$rootScope.$broadcast('history_update'); |
|
|
|
$rootScope.$broadcast('history_update'); |
|
|
|
}, 1000); |
|
|
|
}, 1000); |
|
|
|
}, function (e) { |
|
|
|
}, function (e) { |
|
|
|
console.log('document download failed', e); |
|
|
|
console.log('audio download failed', e); |
|
|
|
historyDoc.progress.enabled = false; |
|
|
|
historyAudio.progress.enabled = false; |
|
|
|
}, updateDownloadProgress); |
|
|
|
}, updateDownloadProgress); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
historyAudio.progress.cancel = downloadPromise.cancel; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$rootScope.openAudio = openAudio; |
|
|
|
$rootScope.openAudio = openAudio; |
|
|
|