|
|
@ -2650,7 +2650,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getDifference () { |
|
|
|
function getDifference () { |
|
|
|
console.trace(dT(), 'Get full diff'); |
|
|
|
// console.trace(dT(), 'Get full diff');
|
|
|
|
if (!updatesState.syncLoading) { |
|
|
|
if (!updatesState.syncLoading) { |
|
|
|
updatesState.syncLoading = true; |
|
|
|
updatesState.syncLoading = true; |
|
|
|
updatesState.pendingSeqUpdates = {}; |
|
|
|
updatesState.pendingSeqUpdates = {}; |
|
|
@ -2704,7 +2704,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
updatesState.pts = nextState.pts; |
|
|
|
updatesState.pts = nextState.pts; |
|
|
|
updatesState.date = nextState.date; |
|
|
|
updatesState.date = nextState.date; |
|
|
|
|
|
|
|
|
|
|
|
console.log(dT(), 'apply diff', updatesState.seq, updatesState.pts); |
|
|
|
// console.log(dT(), 'apply diff', updatesState.seq, updatesState.pts);
|
|
|
|
|
|
|
|
|
|
|
|
if (differenceResult._ == 'updates.differenceSlice') { |
|
|
|
if (differenceResult._ == 'updates.differenceSlice') { |
|
|
|
getDifference(); |
|
|
|
getDifference(); |
|
|
@ -2726,14 +2726,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
clearTimeout(channelState.syncPending.timeout); |
|
|
|
clearTimeout(channelState.syncPending.timeout); |
|
|
|
channelState.syncPending = false; |
|
|
|
channelState.syncPending = false; |
|
|
|
} |
|
|
|
} |
|
|
|
console.log(dT(), 'Get channel diff', AppChatsManager.getChat(channelID), channelState.pts); |
|
|
|
// console.log(dT(), 'Get channel diff', AppChatsManager.getChat(channelID), channelState.pts);
|
|
|
|
MtpApiManager.invokeApi('updates.getChannelDifference', { |
|
|
|
MtpApiManager.invokeApi('updates.getChannelDifference', { |
|
|
|
channel: AppChatsManager.getChannelInput(channelID), |
|
|
|
channel: AppChatsManager.getChannelInput(channelID), |
|
|
|
filter: {_: 'channelMessagesFilterEmpty'}, |
|
|
|
filter: {_: 'channelMessagesFilterEmpty'}, |
|
|
|
pts: channelState.pts, |
|
|
|
pts: channelState.pts, |
|
|
|
limit: 30 |
|
|
|
limit: 30 |
|
|
|
}).then(function (differenceResult) { |
|
|
|
}).then(function (differenceResult) { |
|
|
|
console.log(dT(), 'channel diff result', differenceResult); |
|
|
|
// console.log(dT(), 'channel diff result', differenceResult);
|
|
|
|
channelState.pts = differenceResult.pts; |
|
|
|
channelState.pts = differenceResult.pts; |
|
|
|
|
|
|
|
|
|
|
|
if (differenceResult._ == 'updates.channelDifferenceEmpty') { |
|
|
|
if (differenceResult._ == 'updates.channelDifferenceEmpty') { |
|
|
@ -2816,16 +2816,13 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
channelID = update.channel_id; |
|
|
|
channelID = update.channel_id; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
// if (channelID) {
|
|
|
|
|
|
|
|
// console.log(dT(), channelID, update.pts, update);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (channelID && !AppChatsManager.hasChat(channelID)) { |
|
|
|
if (channelID && !AppChatsManager.hasChat(channelID)) { |
|
|
|
console.log(dT(), 'skip update, missing channel', channelID, update); |
|
|
|
// console.log(dT(), 'skip update, missing channel', channelID, update);
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
var curState = channelID ? getChannelState(channelID, update.pts) : updatesState; |
|
|
|
var curState = channelID ? getChannelState(channelID, update.pts) : updatesState; |
|
|
|
|
|
|
|
|
|
|
|
console.log(dT(), 'process', channelID, curState, update); |
|
|
|
// console.log(dT(), 'process', channelID, curState, update);
|
|
|
|
|
|
|
|
|
|
|
|
if (curState.syncLoading) { |
|
|
|
if (curState.syncLoading) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -3944,14 +3941,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
PeersSelectService.selectPeer().then(function (toPeerString) { |
|
|
|
PeersSelectService.selectPeer().then(function (toPeerString) { |
|
|
|
var url = decodeURIComponent(matches[1]); |
|
|
|
var url = decodeURIComponent(matches[1]); |
|
|
|
var text = matches[2] ? decodeURIComponent(matches[2]) : ''; |
|
|
|
var text = matches[2] ? decodeURIComponent(matches[2]) : ''; |
|
|
|
$rootScope.$broadcast('history_focus', { |
|
|
|
shareUrl(url, text); |
|
|
|
peerString: toPeerString, |
|
|
|
|
|
|
|
attachment: { |
|
|
|
|
|
|
|
_: 'share_url', |
|
|
|
|
|
|
|
url: url, |
|
|
|
|
|
|
|
text: text |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -3987,40 +3977,20 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var started = false; |
|
|
|
function handleActivityMessage (name, data) { |
|
|
|
function start () { |
|
|
|
console.log(dT(), 'Received activity', name, data); |
|
|
|
if (started) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
started = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ('registerProtocolHandler' in navigator) { |
|
|
|
if (name == 'share' && data.url) { |
|
|
|
try { |
|
|
|
shareUrl(data.url, ''); |
|
|
|
navigator.registerProtocolHandler('tg', '#im?tgaddr=%s', 'Telegram Web'); |
|
|
|
|
|
|
|
} catch (e) {} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
navigator.registerProtocolHandler('web+tg', '#im?tgaddr=%s', 'Telegram Web'); |
|
|
|
|
|
|
|
} catch (e) {} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (name == 'view' && data.url) { |
|
|
|
if (window.navigator.mozSetMessageHandler) { |
|
|
|
var matches = data.url.match(tgAddrRegExp); |
|
|
|
console.log(dT(), 'Set activity message handler'); |
|
|
|
|
|
|
|
window.navigator.mozSetMessageHandler('activity', function(activityRequest) { |
|
|
|
|
|
|
|
var source = activityRequest.source; |
|
|
|
|
|
|
|
console.log(dT(), 'Received activity', source.name, source.data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (source.name == 'share' && source.data.url) { |
|
|
|
|
|
|
|
var tgUrl = 'msg_url?url=' + encodeURIComponent(source.data.url); |
|
|
|
|
|
|
|
handleTgProtoAddr(tgUrl); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (source.name == 'view' && source.data.url) { |
|
|
|
|
|
|
|
var matches = source.data.url.match(tgAddrRegExp); |
|
|
|
|
|
|
|
if (matches) { |
|
|
|
if (matches) { |
|
|
|
handleTgProtoAddr(matches[3]); |
|
|
|
handleTgProtoAddr(matches[3]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (source.name == 'webrtc-call' && source.data.contact) { |
|
|
|
else if (name == 'webrtc-call' && data.contact) { |
|
|
|
var contact = source.data.contact; |
|
|
|
var contact = data.contact; |
|
|
|
var phones = []; |
|
|
|
var phones = []; |
|
|
|
if (contact.tel != undefined) { |
|
|
|
if (contact.tel != undefined) { |
|
|
|
for (var i = 0; i < contact.tel.length; i++) { |
|
|
|
for (var i = 0; i < contact.tel.length; i++) { |
|
|
@ -4043,11 +4013,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (source.name === 'share' && source.data.blobs && source.data.blobs.length > 0) { |
|
|
|
else if (name === 'share' && data.blobs && data.blobs.length > 0) { |
|
|
|
PeersSelectService.selectPeers({confirm_type: 'EXT_SHARE_PEER'}).then(function (peerStrings) { |
|
|
|
PeersSelectService.selectPeers({confirm_type: 'EXT_SHARE_PEER'}).then(function (peerStrings) { |
|
|
|
angular.forEach(peerStrings, function (peerString) { |
|
|
|
angular.forEach(peerStrings, function (peerString) { |
|
|
|
var peerID = AppPeersManager.getPeerID(peerString); |
|
|
|
var peerID = AppPeersManager.getPeerID(peerString); |
|
|
|
angular.forEach(source.data.blobs, function (blob) { |
|
|
|
angular.forEach(data.blobs, function (blob) { |
|
|
|
AppMessagesManager.sendFile(peerID, blob, {isMedia: true}); |
|
|
|
AppMessagesManager.sendFile(peerID, blob, {isMedia: true}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}) |
|
|
|
}) |
|
|
@ -4056,6 +4026,28 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var started = false; |
|
|
|
|
|
|
|
function start () { |
|
|
|
|
|
|
|
if (started) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
started = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ('registerProtocolHandler' in navigator) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
navigator.registerProtocolHandler('tg', '#im?tgaddr=%s', 'Telegram Web'); |
|
|
|
|
|
|
|
} catch (e) {} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
navigator.registerProtocolHandler('web+tg', '#im?tgaddr=%s', 'Telegram Web'); |
|
|
|
|
|
|
|
} catch (e) {} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (window.navigator.mozSetMessageHandler) { |
|
|
|
|
|
|
|
console.log(dT(), 'Set activity message handler'); |
|
|
|
|
|
|
|
window.navigator.mozSetMessageHandler('activity', function(activityRequest) { |
|
|
|
|
|
|
|
handleActivityMessage(activityRequest.source.name, activityRequest.source.data); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -4079,7 +4071,21 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
checkLocationTgAddr(); |
|
|
|
checkLocationTgAddr(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function shareUrl (url, text) { |
|
|
|
|
|
|
|
PeersSelectService.selectPeer().then(function (toPeerString) { |
|
|
|
|
|
|
|
$rootScope.$broadcast('history_focus', { |
|
|
|
|
|
|
|
peerString: toPeerString, |
|
|
|
|
|
|
|
attachment: { |
|
|
|
|
|
|
|
_: 'share_url', |
|
|
|
|
|
|
|
url: url, |
|
|
|
|
|
|
|
text: text |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
start: start |
|
|
|
start: start, |
|
|
|
|
|
|
|
shareUrl: shareUrl |
|
|
|
}; |
|
|
|
}; |
|
|
|
}) |
|
|
|
}) |
|
|
|