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

38
app/js/controllers.js

@ -209,7 +209,7 @@ angular.module('myApp.controllers', [])
$scope.$on('dialog_unread', function (e, dialog) { $scope.$on('dialog_unread', function (e, dialog) {
angular.forEach($scope.dialogs, function(curDialog) { angular.forEach($scope.dialogs, function(curDialog) {
if (curDialog.peerID == dialog.peerID) { if (curDialog.peerID == dialog.peerID) {
curDialog.unreadCount = dialog.unread_count; curDialog.unreadCount = dialog.count;
} }
}); });
}); });
@ -312,7 +312,9 @@ angular.module('myApp.controllers', [])
$scope.selectedCount = 0; $scope.selectedCount = 0;
$scope.selectActions = false; $scope.selectActions = false;
$scope.toggleMessage = toggleMessage; $scope.toggleMessage = toggleMessage;
$scope.selectedDelete = selectedDelete;
$scope.selectedCancel = selectedCancel; $scope.selectedCancel = selectedCancel;
$scope.toggleEdit = toggleEdit;
$scope.typing = {}; $scope.typing = {};
$scope.state = {}; $scope.state = {};
@ -453,6 +455,27 @@ angular.module('myApp.controllers', [])
$scope.$broadcast('ui_panel_update'); $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 = {}; var typingTimeouts = {};
@ -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) { $scope.$on('dialog_flush', function (e, dialog) {
if (dialog.peerID == $scope.curDialog.peerID) { if (dialog.peerID == $scope.curDialog.peerID) {
$scope.history = []; $scope.history = [];

10
app/js/directives.js

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

20
app/js/services.js

@ -746,6 +746,22 @@ angular.module('myApp.services', [])
return deferred.promise; 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) { function processAffectedHistory (inputPeer, affectedHistory, method) {
if (!ApiUpdatesManager.saveSeq(affectedHistory.seq)) { if (!ApiUpdatesManager.saveSeq(affectedHistory.seq)) {
return false; return false;
@ -1419,7 +1435,7 @@ angular.module('myApp.services', [])
message = messagesStorage[messageID]; message = messagesStorage[messageID];
if (message) { if (message) {
peerID = getMessagePeer(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) { if (!message.out && message.unread) {
history.unread++; history.unread++;
@ -1460,6 +1476,7 @@ angular.module('myApp.services', [])
} }
} }
historyStorage.history = newHistory; historyStorage.history = newHistory;
$rootScope.$broadcast('history_delete', {peerID: peerID, msgs: updatedData.msgs});
} }
}); });
break; break;
@ -1471,6 +1488,7 @@ angular.module('myApp.services', [])
getHistory: getHistory, getHistory: getHistory,
readHistory: readHistory, readHistory: readHistory,
flushHistory: flushHistory, flushHistory: flushHistory,
deleteMessages: deleteMessages,
saveMessages: saveMessages, saveMessages: saveMessages,
sendText: sendText, sendText: sendText,
sendFile: sendFile, sendFile: sendFile,

10
app/partials/im.html

@ -31,9 +31,10 @@
<div class="im_history_panel clearfix" ng-controller="AppImPanelController"> <div class="im_history_panel clearfix" ng-controller="AppImPanelController">
<div class="im_history_panel_title"> <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> <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> <span ng-bind-html="historyPeer.data.rTitle"></span>
<small class="im_chat_users"> <small class="im_chat_users">
<ng-pluralize count="historyPeer.data.participants_count" <ng-pluralize count="historyPeer.data.participants_count"
@ -43,9 +44,10 @@
</h4> </h4>
</div> </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> <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> <span ng-bind-html="historyPeer.data.rFullName"></span>
<small class="im_peer_online">{{historyPeer.data | userStatus}}</small> <small class="im_peer_online">{{historyPeer.data | userStatus}}</small>
</h4> </h4>

Loading…
Cancel
Save