diff --git a/app/js/controllers.js b/app/js/controllers.js index 4b555499..a5ff2fcb 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -1332,7 +1332,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) // console.log(dT(), 'start load history', $scope.curDialog); getMessagesPromise.then(function (historyResult) { if (curJump != jump) return; - // console.log(dT(), 'history loaded', historyResult); + // console.log(dT(), 'history loaded', angular.copy(historyResult)); var fetchedLength = historyResult.history.length; @@ -1724,7 +1724,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) }); $scope.$on('history_multiappend', function (e, historyMultiAdded) { - // console.log(dT(), 'multiappend', historyMultiAdded); + // console.log(dT(), 'multiappend', angular.copy(historyMultiAdded)); var regroupped = false; var unreadAfterChanged = false; var isIDLE = $rootScope.idle.isIDLE; @@ -1769,7 +1769,8 @@ angular.module('myApp.controllers', ['myApp.i18n']) var lastIsRead = !historyMessage || !historyMessage.unread; for (i = 0; i < len; i++) { messageID = msgs[i]; - if (history.ids.indexOf(messageID) !== -1) { + if (messageID < maxID || + history.ids.indexOf(messageID) !== -1) { continue; } historyMessage = AppMessagesManager.wrapForHistory(messageID); @@ -1788,6 +1789,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) hasOut = true; } } + // console.log('after append', angular.copy(history.messages), angular.copy(history.ids)); if (AppMessagesManager.regroupWrappedHistory(history.messages, -len - 2)) { regroupped = true; diff --git a/app/js/messages_manager.js b/app/js/messages_manager.js index 69447b8a..ee86ae06 100644 --- a/app/js/messages_manager.js +++ b/app/js/messages_manager.js @@ -374,7 +374,7 @@ angular.module('myApp.services') var fullMsgIDModulus = 4294967296; function getFullMessageID (msgID, channelID) { - if (!channelID) { + if (!channelID || msgID < 0) { return msgID; } msgID = getMessageLocalID(msgID); @@ -1020,6 +1020,8 @@ angular.module('myApp.services') inputPeer = AppPeersManager.getInputPeerByID(peerID), flags = 0, replyToMsgID = options.replyToMsgID, + isChannel = AppPeersManager.isChannel(peerID), + asChannel = isChannel ? true : false, entities = [], message; @@ -1032,13 +1034,18 @@ angular.module('myApp.services') MtpApiManager.getUserID().then(function (fromID) { if (peerID != fromID) { flags |= 2; - if (!AppUsersManager.isBot(peerID)) { + if (!isChannel && !AppUsersManager.isBot(peerID)) { flags |= 1; } } if (replyToMsgID) { flags |= 8; } + if (asChannel) { + fromID = 0; + } else { + flags |= 256; + } message = { _: 'message', id: messageID, @@ -1082,6 +1089,9 @@ angular.module('myApp.services') if (entities.length) { flags |= 8; } + if (asChannel) { + flags |= 16; + } // console.log(flags, entities); MtpApiManager.invokeApi('messages.sendMessage', { flags: flags, @@ -1107,7 +1117,7 @@ angular.module('myApp.services') random_id: randomIDS, id: updates.id }, { - _: 'updateNewMessage', + _: isChannel ? 'updateNewChannelMessage' : 'updateNewMessage', message: message, pts: updates.pts, pts_count: updates.pts_count @@ -1147,6 +1157,8 @@ angular.module('myApp.services') inputPeer = AppPeersManager.getInputPeerByID(peerID), flags = 0, replyToMsgID = options.replyToMsgID, + isChannel = AppPeersManager.isChannel(peerID), + asChannel = isChannel ? true : false, attachType, apiFileName, realFileName; if (!options.isMedia) { @@ -1173,13 +1185,18 @@ angular.module('myApp.services') MtpApiManager.getUserID().then(function (fromID) { if (peerID != fromID) { flags |= 2; - if (!AppUsersManager.isBot(peerID)) { + if (!isChannel && !AppUsersManager.isBot(peerID)) { flags |= 1; } } if (replyToMsgID) { flags |= 8; } + if (asChannel) { + fromID = 0; + } else { + flags |= 256; + } var media = { _: 'messageMediaPending', type: attachType, @@ -1319,7 +1336,9 @@ angular.module('myApp.services') randomIDS = bigint(randomID[0]).shiftLeft(32).add(bigint(randomID[1])).toString(), historyStorage = historiesStorage[peerID], inputPeer = AppPeersManager.getInputPeerByID(peerID), - replyToMsgID = options.replyToMsgID; + replyToMsgID = options.replyToMsgID, + isChannel = AppPeersManager.isChannel(peerID), + asChannel = isChannel ? true : false; if (historyStorage === undefined) { historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []}; @@ -1354,6 +1373,14 @@ angular.module('myApp.services') flags |= 1; } } + if (replyToMsgID) { + flags |= 8; + } + if (asChannel) { + fromID = 0; + } else { + flags |= 256; + } var message = { _: 'message', @@ -1365,6 +1392,7 @@ angular.module('myApp.services') message: '', media: media, random_id: randomIDS, + reply_to_msg_id: replyToMsgID, pending: true }; @@ -1425,14 +1453,17 @@ angular.module('myApp.services') msgIDs.push(getMessageLocalID(mids[i])); randomIDs.push([nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)]); } - + var sentRequestOptions = {}; + if (pendingAfterMsgs[peerID]) { + sentRequestOptions.afterMessageID = pendingAfterMsgs[peerID].messageID; + } return MtpApiManager.invokeApi('messages.forwardMessages', { flags: flags, from_peer: AppPeersManager.getInputPeerByID(-fromChannel), id: msgIDs, random_id: randomIDs, to_peer: AppPeersManager.getInputPeerByID(peerID), - }).then(function (updates) { + }, sentRequestOptions).then(function (updates) { ApiUpdatesManager.processUpdateMessage(updates); }); }; @@ -2015,6 +2046,7 @@ angular.module('myApp.services') notification.title = AppChatsManager.getChat(-peerID).title || _('conversation_unknown_chat_raw'); if (message.from_id > 0) { + var fromUser = AppUsersManager.getUser(message.from_id); notification.title = (fromUser.first_name || fromUser.last_name || _('conversation_unknown_user_raw')) + ' @ ' + notification.title; @@ -2123,12 +2155,18 @@ angular.module('myApp.services') } $rootScope.$on('apiUpdate', function (e, update) { - if (update._ != 'updateUserStatus') { - console.log('on apiUpdate', update); - } + // if (update._ != 'updateUserStatus') { + // console.log('on apiUpdate', update); + // } switch (update._) { case 'updateMessageID': - pendingByMessageID[update.id] = update.random_id; + var randomID = update.random_id; + var pendingData = pendingByRandomID[randomID]; + if (pendingData) { + var peerID = pendingData[0]; + var channelID = AppPeersManager.isChannel(peerID) ? -peerID : 0; + pendingByMessageID[getFullMessageID(update.id, channelID)] = randomID; + } break; case 'updateNewMessage': diff --git a/app/js/services.js b/app/js/services.js index b1700b94..1a5180e6 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -2572,7 +2572,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } var curState = channelID ? getChannelState(channelID, update.pts) : updatesState; - console.log('process', channelID, curState, update); + // console.log('process', channelID, curState, update); if (curState.syncLoading) { return false;