Browse Source

Improved updates handling

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

42
app/js/messages_manager.js

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

39
app/js/services.js

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

4
app/less/app.less

@ -1292,6 +1292,8 @@ i.icon-verified {
overflow: hidden; overflow: hidden;
word-wrap: break-word; word-wrap: break-word;
} }
a.im_dialog {
.im_dialog_chat_from_wrap, .im_dialog_chat_from_wrap,
.im_short_message_media, .im_short_message_media,
.im_short_message_service { .im_short_message_service {
@ -1301,6 +1303,8 @@ i.icon-verified {
color: #808080; color: #808080;
} }
}
a.im_dialog:hover, a.im_dialog:hover,
a.im_dialog_selected { a.im_dialog_selected {
.im_short_message_text { .im_short_message_text {

Loading…
Cancel
Save