Implement unsend messages. Fix #1340
This commit is contained in:
parent
580ddd7105
commit
0bc21d74f7
@ -1797,8 +1797,37 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (selectedMessageIDs.length) {
|
if (selectedMessageIDs.length) {
|
||||||
ErrorService.confirm({type: 'MESSAGES_DELETE', count: selectedMessageIDs.length}).then(function () {
|
var peerID = $scope.curDialog.peerID
|
||||||
AppMessagesManager.deleteMessages(selectedMessageIDs).then(function () {
|
var isUser = peerID > 0
|
||||||
|
var isChannel = AppPeersManager.isChannel(peerID)
|
||||||
|
var isBroadcast = AppPeersManager.isBroadcast(peerID)
|
||||||
|
var isMegagroup = AppPeersManager.isMegagroup(peerID)
|
||||||
|
var isUsualGroup = !isChannel && !isUser
|
||||||
|
|
||||||
|
var revocable = !isChannel
|
||||||
|
for (var i = 0; revocable && i < selectedMessageIDs.length; i++) {
|
||||||
|
var messageID = selectedMessageIDs[i]
|
||||||
|
if (!AppMessagesManager.canRevokeMessage(messageID)) {
|
||||||
|
revocable = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var userFirstName = false
|
||||||
|
if (isUser) {
|
||||||
|
userFirstName = AppUsersManager.getUser(peerID).first_name
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorService.confirm({
|
||||||
|
type: 'MESSAGES_DELETE',
|
||||||
|
count: selectedMessageIDs.length,
|
||||||
|
revocable: revocable,
|
||||||
|
isUser: isUser,
|
||||||
|
userFirstName: userFirstName,
|
||||||
|
isChannel: isBroadcast,
|
||||||
|
isSupergroup: isMegagroup,
|
||||||
|
isUsualGroup: isUsualGroup
|
||||||
|
}, {}, { revoke: false }).then(function (data) {
|
||||||
|
AppMessagesManager.deleteMessages(selectedMessageIDs, data.revoke).then(function () {
|
||||||
selectedCancel()
|
selectedCancel()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -228,6 +228,11 @@
|
|||||||
"confirm_modal_clipboard_X_files_send": "{'one': 'Are you sure to send file from clipboard?', 'other': 'Are you sure to send {} files from clipboard?'}",
|
"confirm_modal_clipboard_X_files_send": "{'one': 'Are you sure to send file from clipboard?', 'other': 'Are you sure to send {} files from clipboard?'}",
|
||||||
"confirm_modal_message_delete": "Are you sure you want to delete the message?",
|
"confirm_modal_message_delete": "Are you sure you want to delete the message?",
|
||||||
"confirm_modal_X_messages_delete": "{'one': 'Are you sure you want to delete the message?', 'other': 'Are you sure you want to delete {} messages?'}",
|
"confirm_modal_X_messages_delete": "{'one': 'Are you sure you want to delete the message?', 'other': 'Are you sure you want to delete {} messages?'}",
|
||||||
|
"confirm_modal_message_revoke": "Delete for {recipient}",
|
||||||
|
"confirm_modal_message_revoke_recipient_group": "everyone",
|
||||||
|
"confirm_modal_X_messages_non_configurable_for_everyone": "{'one': 'This will delete it for everyone in this chat.', 'other': 'This will delete them for everyone in this chat.'}",
|
||||||
|
"confirm_modal_X_messages_non_configurable_for_user_only": "{'one': 'This will delete it just for you, not for {{ userFirstName }}.', 'other': 'This will delete them just for you, not for {{ userFirstName }}.'}",
|
||||||
|
"confirm_modal_X_messages_non_configurable_for_user_only_in_group": "{'one': 'This will delete it just for you, not for other participants of the chat.', 'other': 'This will delete them just for you, not for other participants of the chat.'}",
|
||||||
"confirm_modal_photo_delete": "Are you sure you want to delete the photo?",
|
"confirm_modal_photo_delete": "Are you sure you want to delete the photo?",
|
||||||
"confirm_modal_contacts_import": "Telegram will now sync your contacts in order to find your friends.",
|
"confirm_modal_contacts_import": "Telegram will now sync your contacts in order to find your friends.",
|
||||||
"confirm_modal_login_phone_correct": "Is this phone number correct?",
|
"confirm_modal_login_phone_correct": "Is this phone number correct?",
|
||||||
|
@ -957,7 +957,24 @@ angular.module('myApp.services')
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteMessages (messageIDs) {
|
function canRevokeMessage(messageID) {
|
||||||
|
if (messageID <= 0 ||
|
||||||
|
!messagesStorage[messageID]) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var message = messagesStorage[messageID]
|
||||||
|
if (message._ != 'message' ||
|
||||||
|
message.deleted ||
|
||||||
|
!message.pFlags.out ||
|
||||||
|
message.date < tsNow(true) - 2 * 86400) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteMessages (messageIDs, revoke) {
|
||||||
var splitted = AppMessagesIDsManager.splitMessageIDsByChannels(messageIDs)
|
var splitted = AppMessagesIDsManager.splitMessageIDsByChannels(messageIDs)
|
||||||
var promises = []
|
var promises = []
|
||||||
angular.forEach(splitted.msgIDs, function (msgIDs, channelID) {
|
angular.forEach(splitted.msgIDs, function (msgIDs, channelID) {
|
||||||
@ -995,7 +1012,12 @@ angular.module('myApp.services')
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
var flags = 0
|
||||||
|
if (revoke) {
|
||||||
|
flags |= 1
|
||||||
|
}
|
||||||
promise = MtpApiManager.invokeApi('messages.deleteMessages', {
|
promise = MtpApiManager.invokeApi('messages.deleteMessages', {
|
||||||
|
flags: flags,
|
||||||
id: msgIDs
|
id: msgIDs
|
||||||
}).then(function (affectedMessages) {
|
}).then(function (affectedMessages) {
|
||||||
ApiUpdatesManager.processUpdateMessage({
|
ApiUpdatesManager.processUpdateMessage({
|
||||||
@ -3392,6 +3414,7 @@ angular.module('myApp.services')
|
|||||||
canMessageBeEdited: canMessageBeEdited,
|
canMessageBeEdited: canMessageBeEdited,
|
||||||
canEditMessage: canEditMessage,
|
canEditMessage: canEditMessage,
|
||||||
getMessageEditData: getMessageEditData,
|
getMessageEditData: getMessageEditData,
|
||||||
|
canRevokeMessage: canRevokeMessage,
|
||||||
clearDialogCache: clearDialogCache,
|
clearDialogCache: clearDialogCache,
|
||||||
wrapForDialog: wrapForDialog,
|
wrapForDialog: wrapForDialog,
|
||||||
wrapForHistory: wrapForHistory,
|
wrapForHistory: wrapForHistory,
|
||||||
|
@ -4152,10 +4152,12 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function confirm (params, options) {
|
function confirm (params, options, data) {
|
||||||
options = options || {}
|
options = options || {}
|
||||||
|
data = data || {}
|
||||||
var scope = $rootScope.$new()
|
var scope = $rootScope.$new()
|
||||||
angular.extend(scope, params)
|
angular.extend(scope, params)
|
||||||
|
angular.extend(scope, { data: data })
|
||||||
|
|
||||||
var modal = $modal.open({
|
var modal = $modal.open({
|
||||||
templateUrl: templateUrl('confirm_modal'),
|
templateUrl: templateUrl('confirm_modal'),
|
||||||
|
@ -741,7 +741,7 @@ a {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
a.tg_checkbox {
|
a.tg_checkbox, p.tg_checkbox {
|
||||||
color: #000;
|
color: #000;
|
||||||
display: block;
|
display: block;
|
||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
|
@ -25,6 +25,20 @@
|
|||||||
<ng-pluralize count="count"
|
<ng-pluralize count="count"
|
||||||
when="confirm_modal_X_messages_delete">
|
when="confirm_modal_X_messages_delete">
|
||||||
</ng-pluralize>
|
</ng-pluralize>
|
||||||
|
<a class="tg_checkbox" ng-if="revocable" ng-click="data.revoke = !data.revoke" ng-class="data.revoke ? 'tg_checkbox_on' : ''">
|
||||||
|
<span class="icon icon-checkbox-outer"><i class="icon-checkbox-inner"></i></span>
|
||||||
|
<span class="tg_checkbox_label" my-i18n="confirm_modal_message_revoke">
|
||||||
|
<my-i18n-param name="recipient">
|
||||||
|
<span ng-if="isUser" ng-bind="userFirstName"></span>
|
||||||
|
<span ng-if="!isUser" my-i18n="confirm_modal_message_revoke_recipient_group"></span>
|
||||||
|
</my-i18n-param>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<p class="tg_checkbox" ng-if="!revocable && !isChannel">
|
||||||
|
<ng-pluralize ng-if="isUser" count="count" when="confirm_modal_X_messages_non_configurable_for_user_only"></ng-pluralize>
|
||||||
|
<ng-pluralize ng-if="isSupergroup" count="count" when="confirm_modal_X_messages_non_configurable_for_everyone"></ng-pluralize>
|
||||||
|
<ng-pluralize ng-if="isUsualGroup" count="count" when="confirm_modal_X_messages_non_configurable_for_user_only_in_group"></ng-pluralize>
|
||||||
|
</p>
|
||||||
</span>
|
</span>
|
||||||
<span ng-switch-when="PHOTO_DELETE" my-i18n="confirm_modal_photo_delete"></span>
|
<span ng-switch-when="PHOTO_DELETE" my-i18n="confirm_modal_photo_delete"></span>
|
||||||
<span ng-switch-when="CONTACTS_IMPORT_PERFORM" my-i18n="confirm_modal_contacts_import"></span>
|
<span ng-switch-when="CONTACTS_IMPORT_PERFORM" my-i18n="confirm_modal_contacts_import"></span>
|
||||||
@ -86,7 +100,7 @@
|
|||||||
<button class="btn btn-md" ng-click="$dismiss()">
|
<button class="btn btn-md" ng-click="$dismiss()">
|
||||||
<span my-i18n="modal_cancel"></span>
|
<span my-i18n="modal_cancel"></span>
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-md btn-md-primary" ng-switch="type" ng-click="$close()" ng-class="{'btn-md-danger': type == 'RESET_ACCOUNT' || type == 'HISTORY_LEAVE_AND_FLUSH' || type == 'HISTORY_FLUSH_AND_DELETE' || type == 'HISTORY_FLUSH'}" my-focused >
|
<button class="btn btn-md btn-md-primary" ng-switch="type" ng-click="$close(data)" ng-class="{'btn-md-danger': type == 'RESET_ACCOUNT' || type == 'HISTORY_LEAVE_AND_FLUSH' || type == 'HISTORY_FLUSH_AND_DELETE' || type == 'HISTORY_FLUSH'}" my-focused >
|
||||||
<span ng-switch-when="LOGOUT" my-i18n="confirm_modal_logout_submit"></span>
|
<span ng-switch-when="LOGOUT" my-i18n="confirm_modal_logout_submit"></span>
|
||||||
<span ng-switch-when="HISTORY_FLUSH" my-i18n="confirm_modal_clear_history_submit"></span>
|
<span ng-switch-when="HISTORY_FLUSH" my-i18n="confirm_modal_clear_history_submit"></span>
|
||||||
<span ng-switch-when="HISTORY_LEAVE_AND_FLUSH" my-i18n="confirm_modal_leave_chat_submit"></span>
|
<span ng-switch-when="HISTORY_LEAVE_AND_FLUSH" my-i18n="confirm_modal_leave_chat_submit"></span>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user