diff --git a/app/js/controllers.js b/app/js/controllers.js index e6e05dc1..f1336cf1 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -2150,8 +2150,8 @@ angular.module('myApp.controllers', ['myApp.i18n']) var lastIsRead = !historyMessage || !historyMessage.pFlags.unread for (i = 0; i < len; i++) { messageID = msgs[i] - if (messageID < maxID || - history.ids.indexOf(messageID) !== -1) { + if (messageID > 0 && messageID < maxID || + history.ids.indexOf(messageID) !== -1) { continue } historyMessage = AppMessagesManager.wrapForHistory(messageID) diff --git a/app/js/lib/mtproto_wrapper.js b/app/js/lib/mtproto_wrapper.js index eda656d0..50fda25f 100644 --- a/app/js/lib/mtproto_wrapper.js +++ b/app/js/lib/mtproto_wrapper.js @@ -157,6 +157,10 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto']) } deferred.reject(error) + if (error.code == 406) { + error.handled = true + } + if (!options.noErrorBox) { error.input = method error.stack = stack || (error.originalError && error.originalError.stack) || error.stack || (new Error()).stack diff --git a/app/js/locales/en-us.json b/app/js/locales/en-us.json index 401da1a9..689896a9 100644 --- a/app/js/locales/en-us.json +++ b/app/js/locales/en-us.json @@ -187,6 +187,8 @@ "changelog_modal_header_recent_updates_md": "Recent updates in **Telegram Web**", "changelog_modal_header_new_updates_md": "**Telegram Web** has been updated!", "changelog_modal_title_current_version": "current version", + "changelog_modal_full_description_md": "Official free messaging app based on Telegram API for speed and security.\n\nThis software is licensed under GNU GPL version 3.", + "changelog_modal_changelog_link": "Changelog", "group_create_contacts_modal_title": "New group", "group_create_modal_title": "Create group", @@ -419,7 +421,6 @@ "error_modal_media_not_supported_description": "Your browser cannot play this media file. Try downloading the file and opening it in a standalone player.", "error_modal_username_not_found_description": "There is no Telegram account with the username you provided.", "error_modal_phonecalls_not_supported_description_md": "Unfortunately calls are not supported in the Web App at the moment.\n\nYou can call {user} using our mobile apps or native desktop applications.\n{download-link: Download »}", - "error_modal_fresh_reset_authorization_forbidden": "For security reasons, you can't terminate older sessions from a device that you've just connected. Please use an earlier connection or wait for a few hours", "error_modal_app_signup_forbidden_md": "You don't have a Telegram account yet, please **sign up** with {signup-link: Android / iPhone} first.", "error_modal_bad_request_description": "One of the params is missing or invalid.", diff --git a/app/js/messages_manager.js b/app/js/messages_manager.js index 41911b19..29baa25b 100644 --- a/app/js/messages_manager.js +++ b/app/js/messages_manager.js @@ -18,6 +18,7 @@ angular.module('myApp.services') var pendingByRandomID = {} var pendingByMessageID = {} var pendingAfterMsgs = {} + var pendingTopMsgs = {} var sendFilePromise = $q.when() var tempID = -1 @@ -181,7 +182,11 @@ angular.module('myApp.services') if (historiesStorage[peerID] === undefined && !message.deleted) { - var historyStorage = {count: null, history: [mid], pending: []} + var historyStorage = {count: null, history: [], pending: []} + historyStorage[mid > 0 ? 'history' : 'pending'].push(mid) + if (mid < 0 && message.pFlags.unread) { + dialog.unread_count++ + } historiesStorage[peerID] = historyStorage if (mergeReplyKeyboard(historyStorage, message)) { $rootScope.$broadcast('history_reply_markup', {peerID: peerID}) @@ -526,6 +531,9 @@ angular.module('myApp.services') historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []} } + if (maxID < 0) { + maxID = 0 + } var isMigrated = false var reqPeerID = peerID if (migratedToFrom[peerID]) { @@ -3007,29 +3015,30 @@ angular.module('myApp.services') saveMessages([message], {isNew: true}) // console.warn(dT(), 'message unread', message.mid, message.pFlags.unread) - if (historyStorage !== undefined) { - var history = historyStorage.history - if (history.indexOf(message.mid) != -1) { - return false - } - var topMsgID = history[0] - history.unshift(message.mid) - if (message.mid > 0 && message.mid < topMsgID) { - history.sort(function (a, b) { - return b - a - }) - } - if (historyStorage.count !== null) { - historyStorage.count++ - } - } else { - historyStorage = historiesStorage[peerID] = { + if (historyStorage === undefined) { + historyStorage = historiesStorage[peerID] = { count: null, - history: [message.mid], + history: [], pending: [] } } + var history = message.mid > 0 ? historyStorage.history : historyStorage.pending + if (history.indexOf(message.mid) != -1) { + return false + } + var topMsgID = history[0] + history.unshift(message.mid) + if (message.mid > 0 && message.mid < topMsgID) { + history.sort(function (a, b) { + return b - a + }) + } + if (message.mid > 0 && + historyStorage.count !== null) { + historyStorage.count++ + } + if (mergeReplyKeyboard(historyStorage, message)) { $rootScope.$broadcast('history_reply_markup', {peerID: peerID}) } @@ -3466,6 +3475,49 @@ angular.module('myApp.services') }) } break + + case 'updateServiceNotification': + // update.inbox_date = tsNow(true) + // update.pFlags = {popup: true} + var fromID = 777000 + var peerID = fromID + var messageID = tempID-- + var message = { + _: 'message', + id: messageID, + from_id: fromID, + to_id: AppPeersManager.getOutputPeer(peerID), + flags: 0, + pFlags: {unread: true}, + date: (update.inbox_date || tsNow(true)) + ServerTimeManager.serverTimeOffset, + message: update.message, + media: update.media, + entities: update.entities + } + if (!AppUsersManager.hasUser(fromID)) { + AppUsersManager.saveApiUsers([{ + _: 'user', + id: fromID, + pFlags: {verified: true}, + access_hash: 0, + first_name: 'Telegram', + phone: '42777' + }]) + } + saveMessages([message]) + + if (update.inbox_date) { + pendingTopMsgs[peerID] = messageID + handleUpdate({ + _: 'updateNewMessage', + message: message + }) + } + if (update.pFlags.popup && update.message) { + var historyMessage = wrapForHistory(messageID) + ErrorService.show({error: {code: 400, type: 'UPDATE_SERVICE_NOTIFICATION'}, historyMessage: historyMessage}) + } + break } } @@ -3493,11 +3545,18 @@ angular.module('myApp.services') var hasUpdated = false angular.forEach(dialogsResult.dialogs, function (dialog) { var peerID = AppPeersManager.getPeerID(dialog.peer) - if (dialog.top_message) { + var topMessage = dialog.top_message + var topPendingMesage = pendingTopMsgs[peerID] + if (topPendingMesage) { + if (!topMessage || getMessage(topPendingMesage).date > getMessage(topMessage).date) { + dialog.top_message = topMessage = topPendingMesage + } + } + if (topMessage) { var wasBefore = getDialogByPeerID(peerID).length > 0 saveConversation(dialog) if (wasBefore) { - clearDialogCache(dialog.top_message) + clearDialogCache(topMessage) $rootScope.$broadcast('dialog_top', dialog) } else { updatedDialogs[peerID] = dialog diff --git a/app/js/services.js b/app/js/services.js index fbabb6cb..85d79a5c 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -4341,16 +4341,23 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } }) - .service('ChangelogNotifyService', function (Storage, $rootScope, $modal) { + .service('ChangelogNotifyService', function (Storage, $rootScope, $modal, $timeout, MtpApiManager, ApiUpdatesManager) { function checkUpdate () { - Storage.get('last_version').then(function (lastVersion) { - if (lastVersion != Config.App.version) { - if (lastVersion) { - showChangelog(lastVersion) + $timeout(function () { + Storage.get('last_version').then(function (lastVersion) { + if (lastVersion != Config.App.version) { + MtpApiManager.invokeApi('help.getAppChangelog', { + prev_app_version: lastVersion + }).then(function (updates) { + if (updates._ == 'updates' && !updates.updates.length) { + return false + } + ApiUpdatesManager.processUpdateMessage(updates) + Storage.set({last_version: Config.App.version}) + }) } - Storage.set({last_version: Config.App.version}) - } - }) + }) + }, 5000) } function showChangelog (lastVersion) { diff --git a/app/partials/desktop/changelog_modal.html b/app/partials/desktop/changelog_modal.html index 8e25b32c..646c424d 100644 --- a/app/partials/desktop/changelog_modal.html +++ b/app/partials/desktop/changelog_modal.html @@ -31,341 +31,8 @@
@gif dog
in your next chat. Sample bots: @gif, @wiki, @bing, @vid, @bold.
-
+