Browse Source

Support flush history in private supergroups

master
Igor Zhukov 7 years ago
parent
commit
e613f095ef
  1. 9
      app/js/controllers.js
  2. 36
      app/js/messages_manager.js
  3. 2
      app/js/services.js
  4. 13
      app/partials/desktop/channel_modal.html
  5. 6
      app/partials/mobile/channel_modal.html

9
app/js/controllers.js

@ -469,6 +469,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} else { } else {
$scope.$broadcast('ui_history_focus') $scope.$broadcast('ui_history_focus')
} }
$modalStack.dismissAll()
} else { } else {
var peerID = AppPeersManager.getPeerID(peerData.peerString) var peerID = AppPeersManager.getPeerID(peerData.peerString)
var username = AppPeersManager.getPeer(peerID).username 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 () { $scope.joinChannel = function () {
MtpApiManager.invokeApi('channels.joinChannel', { MtpApiManager.invokeApi('channels.joinChannel', {
channel: AppChatsManager.getChannelInput($scope.chatID) channel: AppChatsManager.getChannelInput($scope.chatID)

36
app/js/messages_manager.js

@ -1262,6 +1262,26 @@ angular.module('myApp.services')
} }
function flushHistory (peerID, justClear) { 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 () { return doFlushHistory(AppPeersManager.getInputPeerByID(peerID), justClear).then(function () {
if (justClear) { if (justClear) {
$rootScope.$broadcast('dialog_flush', {peerID: peerID}) $rootScope.$broadcast('dialog_flush', {peerID: peerID})
@ -3360,6 +3380,22 @@ angular.module('myApp.services')
} }
break 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 'updateDeleteMessages':
case 'updateDeleteChannelMessages': case 'updateDeleteChannelMessages':
var dialogsUpdated = {} var dialogsUpdated = {}

2
app/js/services.js

@ -796,7 +796,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
if (chatFull.participants && chatFull.participants._ == 'channelParticipants') { if (chatFull.participants && chatFull.participants._ == 'channelParticipants') {
var isAdmin = chat.pFlags.creator || chat.pFlags.editor || chat.pFlags.moderator var isAdmin = chat.pFlags.creator || chat.pFlags.editor || chat.pFlags.moderator
angular.forEach(chatFull.participants.participants, function (participant) { angular.forEach(chatFull.participants.participants, function (participant) {
participant.canLeave = !chat.pFlags.creator && participant._ == 'channelParticipantSelf' participant.canLeave = participant._ == 'channelParticipantSelf'
participant.canKick = isAdmin && participant._ == 'channelParticipant' participant.canKick = isAdmin && participant._ == 'channelParticipant'
// just for order by last seen // just for order by last seen

13
app/partials/desktop/channel_modal.html

@ -99,10 +99,19 @@
</div> </div>
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_link" ng-if="chatFull.chat.pFlags.creator || !chatFull.chat.pFlags.left && !chatFull.chat.pFlags.kicked && !isMegagroup"> <div class="md_modal_iconed_section_wrap md_modal_iconed_section_link" ng-if="isMegagroup && !chatFull.chat.username && !chatFull.chat.pFlags.left && !chatFull.chat.pFlags.kicked">
<i class="md_modal_section_icon md_modal_section_icon_more"></i> <i class="md_modal_section_icon md_modal_section_icon_more"></i>
<div class="md_modal_section_link_wrap" ng-if="!chatFull.chat.pFlags.creator && !chatFull.chat.pFlags.left && !chatFull.chat.pFlags.kicked && !isMegagroup"> <div class="md_modal_section_link_wrap">
<a class="md_modal_section_link" ng-click="flushHistory()" my-i18n="group_modal_menu_clear_history"></a>
</div>
</div>
<div class="md_modal_iconed_section_wrap md_modal_iconed_section_link" ng-if="!chatFull.chat.pFlags.left && !chatFull.chat.pFlags.kicked && !isMegagroup">
<i class="md_modal_section_icon md_modal_section_icon_more"></i>
<div class="md_modal_section_link_wrap" ng-if="!chatFull.chat.pFlags.left && !chatFull.chat.pFlags.kicked && !isMegagroup">
<a class="md_modal_section_link" ng-click="leaveChannel()" my-i18n="channel_modal_leave_channel"></a> <a class="md_modal_section_link" ng-click="leaveChannel()" my-i18n="channel_modal_leave_channel"></a>
</div> </div>

6
app/partials/mobile/channel_modal.html

@ -117,7 +117,11 @@
</a> </a>
</div> </div>
<div class="mobile_modal_action_wrap" ng-if="!chatFull.chat.pFlags.creator && !chatFull.chat.pFlags.left && !chatFull.chat.pFlags.kicked && !isMegagroup"> <div class="mobile_modal_action_wrap" ng-if="isMegagroup && !chatFull.chat.username && !chatFull.chat.pFlags.left && !chatFull.chat.pFlags.kicked">
<a class="mobile_modal_action" ng-click="flushHistory()" my-i18n="group_modal_menu_clear_history"></a>
</div>
<div class="mobile_modal_action_wrap" ng-if="!chatFull.chat.pFlags.left && !chatFull.chat.pFlags.kicked && !isMegagroup">
<a class="mobile_modal_action" ng-click="leaveChannel()" my-i18n="channel_modal_leave_channel"></a> <a class="mobile_modal_action" ng-click="leaveChannel()" my-i18n="channel_modal_leave_channel"></a>
</div> </div>

Loading…
Cancel
Save