Fixed conversation w/ deleted message on top

Closes #349
Closes #326
This commit is contained in:
Igor Zhukov 2014-07-07 12:55:46 +04:00
parent fd3758327a
commit fef4457417
4 changed files with 81 additions and 60 deletions

View File

@ -399,12 +399,23 @@ angular.module('myApp.controllers', [])
$scope.$on('dialog_flush', function (e, dialog) { $scope.$on('dialog_flush', function (e, dialog) {
for (var i = 0; i < $scope.dialogs.length; i++) { for (var i = 0; i < $scope.dialogs.length; i++) {
if ($scope.dialogs[i].peerID == dialog.peerID) { if ($scope.dialogs[i].peerID == dialog.peerID) {
$scope.dialogs.splice(i, 1); $scope.dialogs[i].deleted = true;
break; break;
} }
} }
}); });
$scope.$on('history_delete', function (e, historyUpdate) {
for (var i = 0; i < $scope.dialogs.length; i++) {
if ($scope.dialogs[i].peerID == historyUpdate.peerID) {
if (historyUpdate.msgs[$scope.dialogs[i].id]) {
$scope.dialogs[i].deleted = true;
}
break;
}
}
});
$scope.$on('contact_imported', function () { $scope.$on('contact_imported', function () {
if (contactsShown) { if (contactsShown) {
loadDialogs(); loadDialogs();
@ -1091,7 +1102,7 @@ angular.module('myApp.controllers', [])
$scope.history = newHistory; $scope.history = newHistory;
updateHistoryGroups(); updateHistoryGroups();
} }
}) });
$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) {

View File

@ -118,7 +118,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
return new SecureRandom(); return new SecureRandom();
}) })
.factory('MtpMessageIdGenerator', function (Storage) { .factory('MtpDateManager', function (Storage) {
var lastMessageID = [0, 0], var lastMessageID = [0, 0],
timeOffset = 0; timeOffset = 0;
@ -155,18 +155,23 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
lastMessageID = [0, 0]; lastMessageID = [0, 0];
timeOffset = newTimeOffset; timeOffset = newTimeOffset;
console.log('Apply server time', serverTime, localTime, newTimeOffset, changed); console.log(dT(), 'Apply server time', serverTime, localTime, newTimeOffset, changed);
return changed; return changed;
}; };
function getTimeOffset () {
return timeOffset;
};
return { return {
generateID: generateMessageID, generateID: generateMessageID,
applyServerTime: applyServerTime applyServerTime: applyServerTime,
getTimeOffset: getTimeOffset
}; };
}) })
.factory('MtpAuthorizer', function (MtpDcConfigurator, MtpRsaKeysManager, MtpSecureRandom, MtpMessageIdGenerator, CryptoWorker, $http, $q, $timeout) { .factory('MtpAuthorizer', function (MtpDcConfigurator, MtpRsaKeysManager, MtpSecureRandom, MtpDateManager, CryptoWorker, $http, $q, $timeout) {
function mtpSendPlainRequest (dcID, requestBuffer) { function mtpSendPlainRequest (dcID, requestBuffer) {
var requestLength = requestBuffer.byteLength, var requestLength = requestBuffer.byteLength,
@ -174,7 +179,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
var header = new TLSerialization(); var header = new TLSerialization();
header.storeLongP(0, 0, 'auth_key_id'); // Auth key header.storeLongP(0, 0, 'auth_key_id'); // Auth key
header.storeLong(MtpMessageIdGenerator.generateID(), 'msg_id'); // Msg_id header.storeLong(MtpDateManager.generateID(), 'msg_id'); // Msg_id
header.storeInt(requestLength, 'request_length'); header.storeInt(requestLength, 'request_length');
var headerBuffer = header.getBuffer(), var headerBuffer = header.getBuffer(),
@ -386,7 +391,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
throw new Error('server_DH_inner_data SHA1-hash mismatch'); throw new Error('server_DH_inner_data SHA1-hash mismatch');
} }
MtpMessageIdGenerator.applyServerTime(auth.serverTime, auth.localTime); MtpDateManager.applyServerTime(auth.serverTime, auth.localTime);
}; };
function mtpSendSetClientDhParams(auth) { function mtpSendSetClientDhParams(auth) {
@ -534,7 +539,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
}) })
.factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerator, MtpSecureRandom, Storage, CryptoWorker, $http, $q, $timeout, $interval, $rootScope) { .factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpDateManager, MtpSecureRandom, Storage, CryptoWorker, $http, $q, $timeout, $interval, $rootScope) {
var updatesProcessor, var updatesProcessor,
iii = 0, iii = 0,
@ -637,7 +642,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
sentMessage.inner = newInner; sentMessage.inner = newInner;
} }
sentMessage.msg_id = MtpMessageIdGenerator.generateID(); sentMessage.msg_id = MtpDateManager.generateID();
sentMessage.seq_no = this.generateSeqNo( sentMessage.seq_no = this.generateSeqNo(
sentMessage.notContentRelated || sentMessage.notContentRelated ||
sentMessage.container sentMessage.container
@ -664,7 +669,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
serializer.storeMethod(method, params); serializer.storeMethod(method, params);
var messageID = MtpMessageIdGenerator.generateID(), var messageID = MtpDateManager.generateID(),
seqNo = this.generateSeqNo(), seqNo = this.generateSeqNo(),
message = { message = {
msg_id: messageID, msg_id: messageID,
@ -685,7 +690,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
var serializer = new TLSerialization({mtproto: true}); var serializer = new TLSerialization({mtproto: true});
serializer.storeObject(object, 'Object'); serializer.storeObject(object, 'Object');
var messageID = MtpMessageIdGenerator.generateID(), var messageID = MtpDateManager.generateID(),
seqNo = this.generateSeqNo(options.notContentRelated), seqNo = this.generateSeqNo(options.notContentRelated),
message = { message = {
msg_id: messageID, msg_id: messageID,
@ -720,7 +725,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
options.resultType = serializer.storeMethod(method, params); options.resultType = serializer.storeMethod(method, params);
var messageID = MtpMessageIdGenerator.generateID(), var messageID = MtpDateManager.generateID(),
seqNo = this.generateSeqNo(), seqNo = this.generateSeqNo(),
message = { message = {
msg_id: messageID, msg_id: messageID,
@ -844,7 +849,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
serializer.storeMethod('ping', {ping_id: pingID}); serializer.storeMethod('ping', {ping_id: pingID});
var pingMessage = { var pingMessage = {
msg_id: MtpMessageIdGenerator.generateID(), msg_id: MtpDateManager.generateID(),
seq_no: this.generateSeqNo(true), seq_no: this.generateSeqNo(true),
body: serializer.getBytes() body: serializer.getBytes()
}; };
@ -959,7 +964,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
var serializer = new TLSerialization({mtproto: true}); var serializer = new TLSerialization({mtproto: true});
serializer.storeMethod('http_wait', {max_delay: 0, wait_after: 0, max_wait: 1000}); serializer.storeMethod('http_wait', {max_delay: 0, wait_after: 0, max_wait: 1000});
messages.push({ messages.push({
msg_id: MtpMessageIdGenerator.generateID(), msg_id: MtpDateManager.generateID(),
seq_no: this.generateSeqNo(), seq_no: this.generateSeqNo(),
body: serializer.getBytes() body: serializer.getBytes()
}); });
@ -990,7 +995,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
} }
var containerSentMessage = { var containerSentMessage = {
msg_id: MtpMessageIdGenerator.generateID(), msg_id: MtpDateManager.generateID(),
seq_no: this.generateSeqNo(true), seq_no: this.generateSeqNo(true),
container: true, container: true,
inner: innerMessages inner: innerMessages
@ -1340,7 +1345,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
} }
if (message.error_code == 16 || message.error_code == 17) { if (message.error_code == 16 || message.error_code == 17) {
if (MtpMessageIdGenerator.applyServerTime( if (MtpDateManager.applyServerTime(
bigStringInt(messageID).shiftRight(32).toString(10) bigStringInt(messageID).shiftRight(32).toString(10)
)) { )) {
this.updateSession(); this.updateSession();

View File

@ -1992,14 +1992,14 @@ angular.module('myApp.services', [])
history.msgs[messageID] = true; history.msgs[messageID] = true;
if (messagesForHistory[messageID]) { if (messagesForHistory[messageID]) {
messagesForHistory[messageID].DELETED = true; messagesForHistory[messageID].deleted = true;
delete messagesForHistory[messageID]; delete messagesForHistory[messageID];
} }
if (messagesForDialogs[messageID]) { if (messagesForDialogs[messageID]) {
messagesForDialogs[messageID].DELETED = true; messagesForDialogs[messageID].deleted = true;
delete messagesForDialogs[messageID]; delete messagesForDialogs[messageID];
} }
message.DELETED = true; message.deleted = true;
delete messagesStorage[messageID]; delete messagesStorage[messageID];
} }
} }

View File

@ -30,53 +30,58 @@
</span> </span>
</div> </div>
<div class="im_dialog_message"> <div ng-switch="dialogMessage.deleted">
<span class="im_dialog_chat_from_wrap"> <div ng-switch-when="true" class="im_dialog_message">
<span <span class="im_dialog_message_text">deleted message</span>
class="im_dialog_chat_from" </div>
ng-if="!dialogMessage.out &amp;&amp; dialogMessage.chatID" <div ng-switch-default class="im_dialog_message">
ng-bind-html="dialogMessage.fromUser.rFirstName" <span class="im_dialog_chat_from_wrap">
></span><span <span
class="im_dialog_chat_from" class="im_dialog_chat_from"
ng-if="dialogMessage.out" ng-if="!dialogMessage.out &amp;&amp; dialogMessage.chatID"
>You</span>{{((dialogMessage.out || dialogMessage.peerID &lt; 0) &amp;&amp; (dialogMessage.message.length || dialogMessage.media &amp;&amp; dialogMessage.media._ != 'messageMediaEmpty')) ? ':' : ''}} ng-bind-html="dialogMessage.fromUser.rFirstName"
</span> ></span><span
class="im_dialog_chat_from"
ng-if="dialogMessage.out"
>You</span>{{((dialogMessage.out || dialogMessage.peerID &lt; 0) &amp;&amp; (dialogMessage.message.length || dialogMessage.media &amp;&amp; dialogMessage.media._ != 'messageMediaEmpty')) ? ':' : ''}}
</span>
<span class="im_dialog_message_media" ng-if="dialogMessage.media &amp;&amp; dialogMessage.media._ != 'messageMediaEmpty'" ng-switch="dialogMessage.media._"> <span class="im_dialog_message_media" ng-if="dialogMessage.media &amp;&amp; dialogMessage.media._ != 'messageMediaEmpty'" ng-switch="dialogMessage.media._">
<span ng-switch-when="messageMediaPhoto">Photo</span> <span ng-switch-when="messageMediaPhoto">Photo</span>
<span ng-switch-when="messageMediaVideo">Video</span> <span ng-switch-when="messageMediaVideo">Video</span>
<span ng-switch-when="messageMediaDocument">Document</span> <span ng-switch-when="messageMediaDocument">Document</span>
<span ng-switch-when="messageMediaAudio">Audio</span> <span ng-switch-when="messageMediaAudio">Audio</span>
<span ng-switch-when="messageMediaGeo">Location</span> <span ng-switch-when="messageMediaGeo">Location</span>
<span ng-switch-when="messageMediaContact">Contact</span> <span ng-switch-when="messageMediaContact">Contact</span>
</span> </span>
<span class="im_dialog_message_service" ng-if="dialogMessage._ == 'messageService'" ng-switch="dialogMessage.action._"> <span class="im_dialog_message_service" ng-if="dialogMessage._ == 'messageService'" ng-switch="dialogMessage.action._">
<span ng-switch-when="messageActionChatCreate">created the group</span> <span ng-switch-when="messageActionChatCreate">created the group</span>
<span ng-switch-when="messageActionChatEditTitle">changed group name</span> <span ng-switch-when="messageActionChatEditTitle">changed group name</span>
<span ng-switch-when="messageActionChatEditPhoto">changed group photo</span> <span ng-switch-when="messageActionChatEditPhoto">changed group photo</span>
<span ng-switch-when="messageActionChatDeletePhoto">removed group photo</span> <span ng-switch-when="messageActionChatDeletePhoto">removed group photo</span>
<span ng-switch-when="messageActionChatAddUser" ng-switch="dialogMessage.from_id == dialogMessage.action.user_id"> <span ng-switch-when="messageActionChatAddUser" ng-switch="dialogMessage.from_id == dialogMessage.action.user_id">
<span ng-switch-when="true"> <span ng-switch-when="true">
returned to group returned to group
</span>
<span ng-switch-default>
invited <span ng-bind-html="dialogMessage.action.user.rFullName"></span>
</span>
</span> </span>
<span ng-switch-default>
invited <span ng-bind-html="dialogMessage.action.user.rFullName"></span> <span ng-switch-when="messageActionChatDeleteUser" ng-switch="dialogMessage.from_id == dialogMessage.action.user_id">
<span ng-switch-when="true">
left group
</span>
<span ng-switch-default>
kicked <span ng-bind-html="dialogMessage.action.user.rFullName"></span>
</span>
</span> </span>
</span> </span>
<span ng-switch-when="messageActionChatDeleteUser" ng-switch="dialogMessage.from_id == dialogMessage.action.user_id"> <span class="im_dialog_message_text" ng-if="dialogMessage.message.length" ng-bind-html="dialogMessage.richMessage"></span>
<span ng-switch-when="true"> </div>
left group
</span>
<span ng-switch-default>
kicked <span ng-bind-html="dialogMessage.action.user.rFullName"></span>
</span>
</span>
</span>
<span class="im_dialog_message_text" ng-if="dialogMessage.message.length" ng-bind-html="dialogMessage.richMessage"></span>
</div> </div>
</div> </div>