Browse Source

Improved updates handling

Now basic edit message update handling
master
Igor Zhukov 8 years ago
parent
commit
106555c368
  1. 42
      app/js/messages_manager.js
  2. 41
      app/js/services.js
  3. 18
      app/less/app.less

42
app/js/messages_manager.js

@ -1154,7 +1154,7 @@ angular.module('myApp.services') @@ -1154,7 +1154,7 @@ angular.module('myApp.services')
});
}
function saveMessages (apiMessages) {
function saveMessages (apiMessages, edited) {
angular.forEach(apiMessages, function (apiMessage) {
if (apiMessage.pFlags === undefined) {
apiMessage.pFlags = {};
@ -1176,13 +1176,10 @@ angular.module('myApp.services') @@ -1176,13 +1176,10 @@ angular.module('myApp.services')
var mid = getFullMessageID(apiMessage.id, channelID);
apiMessage.mid = mid;
messagesStorage[mid] = apiMessage;
if (channelID && !apiMessage.pFlags.out) {
var dialog = getDialogByPeerID(toPeerID)[0];
apiMessage.pFlags.unread = dialog ? mid > dialog.read_inbox_max_id : true;
} else {
apiMessage.pFlags.unread = apiMessage.flags & 1 ? true : false;
}
if (apiMessage.reply_to_msg_id) {
@ -1292,6 +1289,10 @@ angular.module('myApp.services') @@ -1292,6 +1289,10 @@ angular.module('myApp.services')
var apiEntities = apiMessage.entities || [];
apiMessage.totalEntities = RichTextProcessor.mergeEntities(myEntities, apiEntities, !apiMessage.pending);
}
if (!edited) {
messagesStorage[mid] = apiMessage;
}
});
}
@ -2653,12 +2654,11 @@ angular.module('myApp.services') @@ -2653,12 +2654,11 @@ angular.module('myApp.services')
case 'updateNewChannelMessage':
var message = update.message,
peerID = getMessagePeer(message),
historyStorage = historiesStorage[peerID],
messageForMe = true;
historyStorage = historiesStorage[peerID];
if (update._ == 'updateNewChannelMessage') {
if (!AppChatsManager.isMegagroup(-peerID) &&
!(message.flags & 16 || message.flags & 2 || (message.flags & 256) == 0)) {
!(message.pFlags.out || message.pFlags.mention || message.pFlags.post)) {
// we don't support not important messages in channels yet
break;
}
@ -2778,6 +2778,34 @@ angular.module('myApp.services') @@ -2778,6 +2778,34 @@ angular.module('myApp.services')
incrementMaxSeenID(message.id);
break;
case 'updateEditMessage':
case 'updateEditChannelMessage':
var message = update.message,
peerID = getMessagePeer(message),
historyStorage = historiesStorage[peerID];
saveMessages([message], true);
var mid = message.mid;
if (messagesStorage[mid] !== undefined) {
safeReplaceObject(messagesStorage[mid], message);
messagesStorage[mid] = message;
}
if (messagesForHistory[mid] !== undefined) {
var wasForHistory = messagesForHistory[mid];
delete messagesForHistory[mid];
var newForHistory = wrapForHistory(message);
safeReplaceObject(wasForHistory, newForHistory);
messagesForHistory[mid] = newForHistory;
}
// if (messagesForDialogs[mid] !== undefined) {
// var wasForHistory = messagesForDialogs[mid];
// delete messagesForDialogs[mid];
// var newForHistory = wrapForHistory(message);
// safeReplaceObject(wasForHistory, newForHistory);
// messagesForDialogs[mid] = newForHistory;
// }
break;
case 'updateReadHistoryInbox':
case 'updateReadHistoryOutbox':
case 'updateReadChannelInbox':

41
app/js/services.js

@ -2683,6 +2683,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2683,6 +2683,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return false;
}
console.log(dT(), 'pop pending pts updates', goodPts, curState.pendingPtsUpdates.slice(0, goodIndex + 1));
curState.pts = goodPts;
for (i = 0; i <= goodIndex; i++) {
update = curState.pendingPtsUpdates[i];
@ -2932,6 +2934,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2932,6 +2934,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
var channelID = false;
switch (update._) {
case 'updateNewChannelMessage':
case 'updateEditChannelMessage':
channelID = -AppPeersManager.getPeerID(update.message.to_id);
break;
case 'updateDeleteChannelMessages':
@ -2944,20 +2947,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2944,20 +2947,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
break;
}
if (channelID && !AppChatsManager.hasChat(channelID)) {
// console.log(dT(), 'skip update, missing channel', channelID, update);
return false;
}
var curState = channelID ? getChannelState(channelID, update.pts) : updatesState;
// console.log(dT(), 'process', channelID, curState, update);
if (curState.syncLoading) {
return false;
}
if (update._ == 'updateNewMessage' ||
update._ == 'updateNewChannelMessage') {
update._ == 'updateEditMessage' ||
update._ == 'updateNewChannelMessage' ||
update._ == 'updateEditChannelMessage') {
var message = update.message;
var toPeerID = AppPeersManager.getPeerID(message.to_id);
var fwdHeader = message.fwdHeader || {};
@ -2967,13 +2961,30 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2967,13 +2961,30 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
toPeerID > 0 && !AppUsersManager.hasUser(toPeerID) ||
toPeerID < 0 && !AppChatsManager.hasChat(-toPeerID)) {
console.warn(dT(), 'Short update not enough data', message);
forceGetDifference();
if (channelID && AppChatsManager.hasChat(channelID)) {
getChannelDifference(channelID);
} else {
forceGetDifference();
}
return false;
}
}
if (update._ == 'updateChannelTooLong' &&
!channelState.syncLoading) {
if (channelID && !AppChatsManager.hasChat(channelID)) {
// console.log(dT(), 'skip update, missing channel', channelID, update);
return false;
}
var curState = channelID ? getChannelState(channelID, update.pts) : updatesState;
console.log(dT(), 'process', channelID, curState.pts, update);
if (curState.syncLoading) {
return false;
}
if (update._ == 'updateChannelTooLong') {
getChannelDifference(channelID);
return false;
}
var popPts, popSeq;

18
app/less/app.less

@ -1292,13 +1292,17 @@ i.icon-verified { @@ -1292,13 +1292,17 @@ i.icon-verified {
overflow: hidden;
word-wrap: break-word;
}
.im_dialog_chat_from_wrap,
.im_short_message_media,
.im_short_message_service {
color: #3a6d99;
}
.im_short_message_text {
color: #808080;
a.im_dialog {
.im_dialog_chat_from_wrap,
.im_short_message_media,
.im_short_message_service {
color: #3a6d99;
}
.im_short_message_text {
color: #808080;
}
}
a.im_dialog:hover,

Loading…
Cancel
Save