Browse Source

Fixed delete messages from channels

Closes #950
Closes #953
master
Igor Zhukov 9 years ago
parent
commit
2c02832f5c
  1. 65
      app/js/messages_manager.js

65
app/js/messages_manager.js

@ -831,20 +831,61 @@ angular.module('myApp.services')
} }
function deleteMessages (messageIDs) { function deleteMessages (messageIDs) {
return MtpApiManager.invokeApi('messages.deleteMessages', { var splitted = splitMessageIDsByChannels(messageIDs);
id: messageIDs var promises = [];
}).then(function (affectedMessages) { angular.forEach(splitted.msgIDs, function (msgIDs, channelID) {
ApiUpdatesManager.processUpdateMessage({ var promise;
_: 'updateShort', if (channelID > 0) {
update: { var channel = AppChatsManager.getChat(channelID);
_: 'updateDeleteMessages', if (!channel.pFlags.creator) {
messages: messageIDs, var goodMsgIDs = [];
pts: affectedMessages.pts, if (channel.pFlags.editor) {
pts_count: affectedMessages.pts_count angular.forEach(msgIDs, function (msgID, i) {
var message = getMessage(splitted.mids[channelID][i]);
if (message.out) {
goodMsgIDs.push(msgID);
}
});
}
if (!goodMsgIDs.length) {
return;
}
msgIDs = goodMsgIDs;
} }
}); promise = MtpApiManager.invokeApi('channels.deleteMessages', {
return messageIDs; channel: AppChatsManager.getChannelInput(channelID),
id: msgIDs
}).then(function (affectedMessages) {
ApiUpdatesManager.processUpdateMessage({
_: 'updateShort',
update: {
_: 'updateDeleteChannelMessages',
channel_id: channelID,
messages: msgIDs,
pts: affectedMessages.pts,
pts_count: affectedMessages.pts_count
}
});
});
} else {
promise = MtpApiManager.invokeApi('messages.deleteMessages', {
id: msgIDs
}).then(function (affectedMessages) {
ApiUpdatesManager.processUpdateMessage({
_: 'updateShort',
update: {
_: 'updateDeleteMessages',
messages: msgIDs,
pts: affectedMessages.pts,
pts_count: affectedMessages.pts_count
}
});
});
}
promises.push(promise);
}); });
return $q.all(promises);
} }
function processAffectedHistory (inputPeer, affectedHistory, method) { function processAffectedHistory (inputPeer, affectedHistory, method) {

Loading…
Cancel
Save