Browse Source

Implement message delete, supported corresponding update

master
Igor Zhukov 11 years ago
parent
commit
27edee4007
  1. 17
      app/css/app.css
  2. 38
      app/js/controllers.js
  3. 10
      app/js/directives.js
  4. 20
      app/js/services.js
  5. 10
      app/partials/im.html

17
app/css/app.css

@ -693,17 +693,23 @@ a.im_dialog:hover .im_dialog_date { @@ -693,17 +693,23 @@ a.im_dialog:hover .im_dialog_date {
font-size: 13px;
margin-left: 5px;
}
.im_history_panel_info_link {
.im_history_panel_info_link,
.im_history_panel_edit_link {
color: #3a6d99;
font-size: 13px;
font-weight: normal;
padding-top: 5px;
line-height: 1;
}
.im_history_panel_info_link:hover {
.im_history_panel_info_link:hover,
.im_history_panel_edit_link:hover {
text-decoration: underline;
}
.im_history_panel_edit_link {
margin-right: 10px;
}
.im_history_wrap {
overflow: hidden;
@ -1340,9 +1346,14 @@ img.img_fullsize { @@ -1340,9 +1346,14 @@ img.img_fullsize {
}
.user_modal_window .modal-dialog {
padding-top: 150px;
max-width: 506px;
}
@media (min-height: 768px) {
.user_modal_window .modal-dialog {
padding-top: 150px;
}
}
.user_modal_wrap .modal-body {
padding: 23px 25px 30px;
}

38
app/js/controllers.js

@ -209,7 +209,7 @@ angular.module('myApp.controllers', []) @@ -209,7 +209,7 @@ angular.module('myApp.controllers', [])
$scope.$on('dialog_unread', function (e, dialog) {
angular.forEach($scope.dialogs, function(curDialog) {
if (curDialog.peerID == dialog.peerID) {
curDialog.unreadCount = dialog.unread_count;
curDialog.unreadCount = dialog.count;
}
});
});
@ -312,7 +312,9 @@ angular.module('myApp.controllers', []) @@ -312,7 +312,9 @@ angular.module('myApp.controllers', [])
$scope.selectedCount = 0;
$scope.selectActions = false;
$scope.toggleMessage = toggleMessage;
$scope.selectedDelete = selectedDelete;
$scope.selectedCancel = selectedCancel;
$scope.toggleEdit = toggleEdit;
$scope.typing = {};
$scope.state = {};
@ -453,6 +455,27 @@ angular.module('myApp.controllers', []) @@ -453,6 +455,27 @@ angular.module('myApp.controllers', [])
$scope.$broadcast('ui_panel_update');
}
function selectedDelete () {
if ($scope.selectedCount > 0) {
var selectedMessageIDs = [];
angular.forEach($scope.selectedMsgs, function (t, messageID) {
selectedMessageIDs.push(messageID);
});
AppMessagesManager.deleteMessages(selectedMessageIDs).then(function () {
selectedCancel();
});
}
}
function toggleEdit () {
if ($scope.selectActions) {
selectedCancel();
} else {
$scope.selectActions = true;
$scope.$broadcast('ui_panel_update');
}
}
var typingTimeouts = {};
@ -476,6 +499,19 @@ angular.module('myApp.controllers', []) @@ -476,6 +499,19 @@ angular.module('myApp.controllers', [])
}
});
$scope.$on('history_delete', function (e, historyUpdate) {
if (historyUpdate.peerID == $scope.curDialog.peerID) {
var newHistory = [];
for (var i = 0; i < $scope.history.length; i++) {
if (!historyUpdate.msgs[$scope.history[i].id]) {
newHistory.push($scope.history[i]);
}
};
$scope.history = newHistory;
}
})
$scope.$on('dialog_flush', function (e, dialog) {
if (dialog.peerID == $scope.curDialog.peerID) {
$scope.history = [];

10
app/js/directives.js

@ -204,14 +204,20 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -204,14 +204,20 @@ angular.module('myApp.directives', ['myApp.filters'])
});
scope.$on('ui_panel_update', function () {
element.addClass('im_panel_to_top');
var h = $(historyWrap).height();
$(panelWrap).addClass('im_panel_to_top');
onContentLoaded(function () {
element.removeClass('im_panel_to_top');
$(panelWrap).removeClass('im_panel_to_top');
updateSizes(true);
var newH = $(historyWrap).height();
if (atBottom) {
scrollableWrap.scrollTop = scrollableWrap.scrollHeight;
updateScroller();
} else {
scrollableWrap.scrollTop -= newH - h;
updateScroller();
}
});
});

20
app/js/services.js

@ -746,6 +746,22 @@ angular.module('myApp.services', []) @@ -746,6 +746,22 @@ angular.module('myApp.services', [])
return deferred.promise;
}
function deleteMessages (messageIDs) {
return MtpApiManager.invokeApi('messages.deleteMessages', {
id: messageIDs
}).then(function (deletedMessageIDs) {
ApiUpdatesManager.saveUpdate({
_: 'updateDeleteMessages',
messages: deletedMessageIDs
});
return deletedMessageIDs;
});
}
function processAffectedHistory (inputPeer, affectedHistory, method) {
if (!ApiUpdatesManager.saveSeq(affectedHistory.seq)) {
return false;
@ -1419,7 +1435,7 @@ angular.module('myApp.services', []) @@ -1419,7 +1435,7 @@ angular.module('myApp.services', [])
message = messagesStorage[messageID];
if (message) {
peerID = getMessagePeer(message);
history = historiesUpdated[peer] || (historiesUpdated[peer] = {count: 0, unread: 0, msgs: {}});
history = historiesUpdated[peerID] || (historiesUpdated[peerID] = {count: 0, unread: 0, msgs: {}});
if (!message.out && message.unread) {
history.unread++;
@ -1460,6 +1476,7 @@ angular.module('myApp.services', []) @@ -1460,6 +1476,7 @@ angular.module('myApp.services', [])
}
}
historyStorage.history = newHistory;
$rootScope.$broadcast('history_delete', {peerID: peerID, msgs: updatedData.msgs});
}
});
break;
@ -1471,6 +1488,7 @@ angular.module('myApp.services', []) @@ -1471,6 +1488,7 @@ angular.module('myApp.services', [])
getHistory: getHistory,
readHistory: readHistory,
flushHistory: flushHistory,
deleteMessages: deleteMessages,
saveMessages: saveMessages,
sendText: sendText,
sendFile: sendFile,

10
app/partials/im.html

@ -31,9 +31,10 @@ @@ -31,9 +31,10 @@
<div class="im_history_panel clearfix" ng-controller="AppImPanelController">
<div class="im_history_panel_title">
<div ng-if="historyPeer.id < 0" ng-click="openChat(-historyPeer.id)">
<div ng-if="historyPeer.id < 0">
<span class="im_history_panel_info_link pull-right">Info</span>
<h4>
<span class="im_history_panel_edit_link pull-right" ng-click="toggleEdit()">Edit</span>
<h4 ng-click="openChat(-historyPeer.id)">
<span ng-bind-html="historyPeer.data.rTitle"></span>
<small class="im_chat_users">
<ng-pluralize count="historyPeer.data.participants_count"
@ -43,9 +44,10 @@ @@ -43,9 +44,10 @@
</h4>
</div>
<div ng-if="historyPeer.id > 0" ng-click="openUser(historyPeer.id)">
<div ng-if="historyPeer.id > 0">
<span class="im_history_panel_info_link pull-right">Info</span>
<h4>
<span class="im_history_panel_edit_link pull-right" ng-click="toggleEdit()">Edit</span>
<h4 ng-click="openUser(historyPeer.id)">
<span ng-bind-html="historyPeer.data.rFullName"></span>
<small class="im_peer_online">{{historyPeer.data | userStatus}}</small>
</h4>

Loading…
Cancel
Save