Browse Source

Firefox OS improvements

Closes #694
Closes #993
Closes #695
master
Igor Zhukov 9 years ago
parent
commit
36ef1084db
  1. 2
      app/js/controllers.js
  2. 4
      app/js/directives.js
  3. 86
      app/js/messages_manager.js
  4. 62
      app/js/services.js
  5. 22
      app/manifest.webapp

2
app/js/controllers.js

@ -2264,7 +2264,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2264,7 +2264,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (attachment._ == 'share_url') {
var url = attachment.url;
var text = attachment.text || '';
var text = attachment.text || ' ';
forceDraft = $scope.curDialog.peer;
$timeout(function () {

4
app/js/directives.js

@ -553,7 +553,7 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -553,7 +553,7 @@ angular.module('myApp.directives', ['myApp.filters'])
onContentLoaded(function () {
scroller.updateHeight();
scroller.scrollTo(0);
$scope.$emit('ui_panel_update', {blur: data.enabled});
$scope.$emit('ui_panel_update', {blur: data && data.enabled});
})
});
onContentLoaded(function () {
@ -759,7 +759,7 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -759,7 +759,7 @@ angular.module('myApp.directives', ['myApp.filters'])
return cancelEvent(e);
}
if (searchFocused && e.keyCode == 13) { // Enter
if (searchFocused && e.keyCode == 13 && !Config.Navigator.mobile) { // Enter
var currentSelected = $(scrollableWrap).find('.im_dialog_selected')[0] || $(scrollableWrap).find('.im_dialog_wrap a')[0];
if (currentSelected) {
$(currentSelected).trigger('mousedown');

86
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, PeersSelectService, Storage, AppProfileManager, TelegramMeWebService, ErrorService, StatusManager, _) {
.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, _) {
var messagesStorage = {};
var messagesForHistory = {};
@ -1439,6 +1439,8 @@ angular.module('myApp.services') @@ -1439,6 +1439,8 @@ angular.module('myApp.services')
apiFileName = 'document.' + file.type.split('/')[1];
}
console.log(attachType, apiFileName, file.type);
if (historyStorage === undefined) {
historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []};
}
@ -1786,19 +1788,35 @@ angular.module('myApp.services') @@ -1786,19 +1788,35 @@ angular.module('myApp.services')
}
if (chatID) {
return MtpApiManager.invokeApi('messages.addChatUser', {
chat_id: AppChatsManager.getChatInput(chatID),
user_id: AppUsersManager.getUserInput(botID)
}).then(function (updates) {
ApiUpdatesManager.processUpdateMessage(updates);
sendText(peerID, '/start@' + bot.username);
}, function (error) {
if (error && error.type == 'USER_ALREADY_PARTICIPANT') {
var bot = AppUsersManager.getUser(botID);
if (AppChatsManager.isChannel(chatID)) {
return MtpApiManager.invokeApi('channels.inviteToChannel', {
channel: AppChatsManager.getChannelInput(chatID),
users: [AppUsersManager.getUserInput(botID)]
}).then(function (updates) {
ApiUpdatesManager.processUpdateMessage(updates);
sendText(peerID, '/start@' + bot.username);
error.handled = true;
}
});
}, function (error) {
if (error && error.type == 'USER_ALREADY_PARTICIPANT') {
var bot = AppUsersManager.getUser(botID);
sendText(peerID, '/start@' + bot.username);
error.handled = true;
}
});
} else {
return MtpApiManager.invokeApi('messages.addChatUser', {
chat_id: AppChatsManager.getChatInput(chatID),
user_id: AppUsersManager.getUserInput(botID)
}).then(function (updates) {
ApiUpdatesManager.processUpdateMessage(updates);
sendText(peerID, '/start@' + bot.username);
}, function (error) {
if (error && error.type == 'USER_ALREADY_PARTICIPANT') {
var bot = AppUsersManager.getUser(botID);
sendText(peerID, '/start@' + bot.username);
error.handled = true;
}
});
}
}
return sendText(peerID, '/start');
@ -2474,28 +2492,6 @@ angular.module('myApp.services') @@ -2474,28 +2492,6 @@ angular.module('myApp.services')
}
}
if (window.navigator.mozSetMessageHandler) {
console.warn('set 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.blobs.length > 0) {
PeersSelectService.selectPeers({confirm_type: 'EXT_SHARE_PEER'}).then(function (peerStrings) {
angular.forEach(peerStrings, function (peerString) {
var peerID = AppPeersManager.getPeerID(peerString);
angular.forEach(source.data.blobs, function (blob) {
sendFile(peerID, blob, {isMedia: true});
});
})
if (peerStrings.length == 1) {
$rootScope.$broadcast('history_focus', {peerString: peerStrings[0]});
}
});
}
});
}
var newMessagesHandlePromise = false;
var newMessagesToHandle = {};
var newDialogsHandlePromise = false;
@ -2564,13 +2560,19 @@ angular.module('myApp.services') @@ -2564,13 +2560,19 @@ angular.module('myApp.services')
case 'updateNewChannelMessage':
var message = update.message,
peerID = getMessagePeer(message),
historyStorage = historiesStorage[peerID];
historyStorage = historiesStorage[peerID],
messageForMe = true;
if (update._ == 'updateNewChannelMessage' &&
!AppChatsManager.isMegagroup(-peerID) &&
!(message.flags & 16 || message.flags & 2 || (message.flags & 256) == 0)) {
// we don't support not important messages in channels yet
break;
if (update._ == 'updateNewChannelMessage') {
if (!AppChatsManager.isMegagroup(-peerID) &&
!(message.flags & 16 || message.flags & 2 || (message.flags & 256) == 0)) {
// we don't support not important messages in channels yet
break;
}
var chat = AppChatsManager.getChat(-peerID);
if (chat.pFlags && (chat.pFlags.left || chat.pFlags.kicked)) {
break;
}
}
saveMessages([message]);
@ -2771,7 +2773,7 @@ angular.module('myApp.services') @@ -2771,7 +2773,7 @@ angular.module('myApp.services')
history = historiesUpdated[peerID] || (historiesUpdated[peerID] = {count: 0, unread: 0, msgs: {}});
if (!message.pFlags.out && message.pFlags.unread) {
history.pFlags.unread++;
history.unread++;
NotificationsManager.cancel('msg' + messageID);
}
history.count++;

62
app/js/services.js

@ -3221,7 +3221,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -3221,7 +3221,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
else if (!data.image) {
data.image = 'img/icons/icon60.png';
}
console.log('notify image', data.image);
// console.log('notify image', data.image);
notificationsCount++;
@ -3899,9 +3899,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -3899,9 +3899,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
if (matches = url.match(/^msg_url\?url=([^&]+)(?:&text=(.*))?$/)) {
PeersSelectService.selectPeer({
confirm_type: 'SHARE_URL'
}).then(function (toPeerString) {
PeersSelectService.selectPeer().then(function (toPeerString) {
var url = decodeURIComponent(matches[1]);
var text = matches[2] ? decodeURIComponent(matches[2]) : '';
$rootScope.$broadcast('history_focus', {
@ -3963,6 +3961,62 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -3963,6 +3961,62 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} catch (e) {}
}
if (window.navigator.mozSetMessageHandler) {
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) {
handleTgProtoAddr(matches[3]);
}
}
else if (source.name == 'webrtc-call' && source.data.contact) {
var contact = source.data.contact;
var phones = [];
if (contact.tel != undefined) {
for (var i = 0; i < contact.tel.length; i++) {
phones.push(contact.tel[i].value);
}
}
var firstName = (contact.givenName || []).join(' ');
var lastName = (contact.familyName || []).join(' ');
if (phones.length) {
AppUsersManager.importContact(phones[0], firstName, lastName).then(function (foundUserID) {
if (foundUserID) {
var peerString = AppPeersManager.getPeerString(foundUserID);
$rootScope.$broadcast('history_focus', {peerString: peerString});
} else {
ErrorService.show({
error: {code: 404, type: 'USER_NOT_USING_TELEGRAM'}
});
}
});
}
}
else if (source.name === 'share' && source.data.blobs && source.data.blobs.length > 0) {
PeersSelectService.selectPeers({confirm_type: 'EXT_SHARE_PEER'}).then(function (peerStrings) {
angular.forEach(peerStrings, function (peerString) {
var peerID = AppPeersManager.getPeerID(peerString);
angular.forEach(source.data.blobs, function (blob) {
AppMessagesManager.sendFile(peerID, blob, {isMedia: true});
});
})
if (peerStrings.length == 1) {
$rootScope.$broadcast('history_focus', {peerString: peerStrings[0]});
}
});
}
});
}
$(document).on('click', function (event) {
var target = event.target;
if (target &&

22
app/manifest.webapp

@ -49,23 +49,35 @@ @@ -49,23 +49,35 @@
"activities": {
"share": {
"href": "/index.html",
"disposition": "window",
"filters": {
"type": ["image/*","audio/*","video/*", "url"],
"url": {
"required": true,
"regexp": "/^https?:/"
"pattern": "https?:.{1,16384}",
"regexp": "^https?:"
}
}
},
"returnValue": false
},
"view": {
"href": "/index.html",
"disposition": "window",
"filters": {
"type": "url",
"url": {
"required": true,
"regexp": "/^tg:/"
"pattern": "tg:.{1,16384}",
"regexp": "^tg:"
}
}
},
"returnValue": false
},
"webrtc-call": {
"href": "index.html",
"filters": {
"type": "webcontacts/contact"
},
"disposition": "window"
}
},
"orientation": "portrait-primary",

Loading…
Cancel
Save