Browse Source

Implement unsend messages. Fix #1340

master
John Yong 8 years ago
parent
commit
0bc21d74f7
  1. 33
      app/js/controllers.js
  2. 5
      app/js/locales/en-us.json
  3. 25
      app/js/messages_manager.js
  4. 4
      app/js/services.js
  5. 2
      app/less/app.less
  6. 16
      app/partials/desktop/confirm_modal.html

33
app/js/controllers.js

@ -1797,8 +1797,37 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -1797,8 +1797,37 @@ angular.module('myApp.controllers', ['myApp.i18n'])
})
}
if (selectedMessageIDs.length) {
ErrorService.confirm({type: 'MESSAGES_DELETE', count: selectedMessageIDs.length}).then(function () {
AppMessagesManager.deleteMessages(selectedMessageIDs).then(function () {
var peerID = $scope.curDialog.peerID
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()
})
})

5
app/js/locales/en-us.json

@ -228,6 +228,11 @@ @@ -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_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_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_contacts_import": "Telegram will now sync your contacts in order to find your friends.",
"confirm_modal_login_phone_correct": "Is this phone number correct?",

25
app/js/messages_manager.js

@ -957,7 +957,24 @@ angular.module('myApp.services') @@ -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 promises = []
angular.forEach(splitted.msgIDs, function (msgIDs, channelID) {
@ -995,7 +1012,12 @@ angular.module('myApp.services') @@ -995,7 +1012,12 @@ angular.module('myApp.services')
})
})
} else {
var flags = 0
if (revoke) {
flags |= 1
}
promise = MtpApiManager.invokeApi('messages.deleteMessages', {
flags: flags,
id: msgIDs
}).then(function (affectedMessages) {
ApiUpdatesManager.processUpdateMessage({
@ -3392,6 +3414,7 @@ angular.module('myApp.services') @@ -3392,6 +3414,7 @@ angular.module('myApp.services')
canMessageBeEdited: canMessageBeEdited,
canEditMessage: canEditMessage,
getMessageEditData: getMessageEditData,
canRevokeMessage: canRevokeMessage,
clearDialogCache: clearDialogCache,
wrapForDialog: wrapForDialog,
wrapForHistory: wrapForHistory,

4
app/js/services.js

@ -4152,10 +4152,12 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -4152,10 +4152,12 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
})
}
function confirm (params, options) {
function confirm (params, options, data) {
options = options || {}
data = data || {}
var scope = $rootScope.$new()
angular.extend(scope, params)
angular.extend(scope, { data: data })
var modal = $modal.open({
templateUrl: templateUrl('confirm_modal'),

2
app/less/app.less

@ -741,7 +741,7 @@ a { @@ -741,7 +741,7 @@ a {
}
}
a.tg_checkbox {
a.tg_checkbox, p.tg_checkbox {
color: #000;
display: block;
line-height: 18px;

16
app/partials/desktop/confirm_modal.html

@ -25,6 +25,20 @@ @@ -25,6 +25,20 @@
<ng-pluralize count="count"
when="confirm_modal_X_messages_delete">
</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 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>
@ -86,7 +100,7 @@ @@ -86,7 +100,7 @@
<button class="btn btn-md" ng-click="$dismiss()">
<span my-i18n="modal_cancel"></span>
</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="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>

Loading…
Cancel
Save