Improved updates handling
Now basic edit message update handling
This commit is contained in:
parent
2ed0cc6074
commit
106555c368
@ -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':
|
||||||
|
@ -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);
|
||||||
forceGetDifference();
|
if (channelID && AppChatsManager.hasChat(channelID)) {
|
||||||
|
getChannelDifference(channelID);
|
||||||
|
} else {
|
||||||
|
forceGetDifference();
|
||||||
|
}
|
||||||
return false;
|
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);
|
getChannelDifference(channelID);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var popPts, popSeq;
|
var popPts, popSeq;
|
||||||
|
@ -1292,13 +1292,17 @@ i.icon-verified {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
}
|
}
|
||||||
.im_dialog_chat_from_wrap,
|
|
||||||
.im_short_message_media,
|
a.im_dialog {
|
||||||
.im_short_message_service {
|
.im_dialog_chat_from_wrap,
|
||||||
color: #3a6d99;
|
.im_short_message_media,
|
||||||
}
|
.im_short_message_service {
|
||||||
.im_short_message_text {
|
color: #3a6d99;
|
||||||
color: #808080;
|
}
|
||||||
|
.im_short_message_text {
|
||||||
|
color: #808080;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
a.im_dialog:hover,
|
a.im_dialog:hover,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user