diff --git a/app/js/controllers.js b/app/js/controllers.js index 26d325bd..ba5333c9 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -469,6 +469,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) } else { $scope.$broadcast('ui_history_focus') } + $modalStack.dismissAll() } else { var peerID = AppPeersManager.getPeerID(peerData.peerString) var username = AppPeersManager.getPeer(peerID).username @@ -4003,6 +4004,14 @@ angular.module('myApp.controllers', ['myApp.i18n']) }) } + $scope.flushHistory = function () { + ErrorService.confirm({type: 'HISTORY_FLUSH'}).then(function () { + AppMessagesManager.flushHistory(-$scope.chatID).then(function () { + $rootScope.$broadcast('history_focus', {peerString: $scope.chatFull.peerString}) + }) + }) + } + $scope.joinChannel = function () { MtpApiManager.invokeApi('channels.joinChannel', { channel: AppChatsManager.getChannelInput($scope.chatID) diff --git a/app/js/messages_manager.js b/app/js/messages_manager.js index dd359785..1d12db82 100644 --- a/app/js/messages_manager.js +++ b/app/js/messages_manager.js @@ -1262,6 +1262,26 @@ angular.module('myApp.services') } function flushHistory (peerID, justClear) { + if (AppPeersManager.isChannel(peerID)) { + return getHistory(peerID, false, 1).then(function (historyResult) { + var channelID = -peerID + var maxID = AppMessagesIDsManager.getMessageLocalID(historyResult.history[0] || 0) + return MtpApiManager.invokeApi('channels.deleteHistory', { + channel: AppChatsManager.getChannelInput(channelID), + max_id: maxID + }).then(function () { + ApiUpdatesManager.processUpdateMessage({ + _: 'updateShort', + update: { + _: 'updateChannelAvailableMessages', + channel_id: channelID, + available_min_id: maxID + } + }) + return true + }) + }) + } return doFlushHistory(AppPeersManager.getInputPeerByID(peerID), justClear).then(function () { if (justClear) { $rootScope.$broadcast('dialog_flush', {peerID: peerID}) @@ -3360,6 +3380,22 @@ angular.module('myApp.services') } break + case 'updateChannelAvailableMessages': + var channelID = update.channel_id + var messages = [] + var peerID = -channelID + var history = (historiesStorage[peerID] || {}).history || [] + if (history.length) { + angular.forEach(history, function (msgID) { + if (!update.available_min_id || + AppMessagesIDsManager.getMessageLocalID(msgID) <= update.available_min_id) { + messages.push(msgID) + } + }) + } + update.messages = messages + console.warn(dT(), update, channelID, messages, history) + case 'updateDeleteMessages': case 'updateDeleteChannelMessages': var dialogsUpdated = {} diff --git a/app/js/services.js b/app/js/services.js index adbd7c81..2ab0d0bb 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -796,7 +796,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) if (chatFull.participants && chatFull.participants._ == 'channelParticipants') { var isAdmin = chat.pFlags.creator || chat.pFlags.editor || chat.pFlags.moderator angular.forEach(chatFull.participants.participants, function (participant) { - participant.canLeave = !chat.pFlags.creator && participant._ == 'channelParticipantSelf' + participant.canLeave = participant._ == 'channelParticipantSelf' participant.canKick = isAdmin && participant._ == 'channelParticipant' // just for order by last seen diff --git a/app/partials/desktop/channel_modal.html b/app/partials/desktop/channel_modal.html index 3d05bb8a..2ae2fe04 100644 --- a/app/partials/desktop/channel_modal.html +++ b/app/partials/desktop/channel_modal.html @@ -99,10 +99,19 @@ -