fix(tl): cross-schema conflict resolution leading to missing references

This commit is contained in:
alina 🌸 2023-10-29 09:14:48 +03:00
parent 137f1cc81b
commit fcab8a5882
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
3 changed files with 10 additions and 6 deletions

File diff suppressed because one or more lines are too long

View file

@ -66,7 +66,6 @@
"messageActionInviteToGroupCall": ["users"],
"messageEntityMentionName": ["user_id"],
"messageMediaContact": ["user_id"],
"messageMediaStory": ["user_id"],
"messageReplies": ["channel_id"],
"messageReplyStoryHeader": ["user_id"],
"messageUserVote": ["user_id"],
@ -129,10 +128,8 @@
"updateReadChannelDiscussionOutbox": ["channel_id"],
"updateReadChannelInbox": ["channel_id"],
"updateReadChannelOutbox": ["channel_id"],
"updateReadStories": ["user_id"],
"updateShortChatMessage": ["from_id", "chat_id", "via_bot_id"],
"updateShortMessage": ["user_id", "via_bot_id"],
"updateStory": ["user_id"],
"updateUserEmojiStatus": ["user_id"],
"updateUserName": ["user_id"],
"updateUserPhone": ["user_id"],
@ -144,7 +141,6 @@
"userFull": ["id"],
"userStories": ["user_id"],
"webAuthorization": ["bot_id"],
"webPageAttributeStory": ["user_id"],
"_": "Dummy line teehee~"
},
"method": {

View file

@ -230,11 +230,19 @@ async function main() {
chooseOptions = options
} else {
// first of all, prefer entries from the latest layer
const fromLastSchema = options.filter((opt) => opt.schema.layer === resultLayer)
let fromLastSchema = options.filter((opt) => opt.entry && opt.schema.layer === resultLayer)
// if there is only one schema on the latest layer, we can simply return it
if (fromLastSchema.length === 1) return fromLastSchema[0].entry
// the conflict was earlier, and now this entry is removed altogether.
// keep it just in case for now, as it may still be referenced somewhere
if (fromLastSchema.length === 0) {
fromLastSchema = options.sort((a, b) => b.schema.layer - a.schema.layer).filter((opt) => opt.entry)
// only keep the latest item
fromLastSchema = [fromLastSchema[0]]
}
// there are multiple choices on the latest layer
// if they are all the same, it's just conflict between layers,
// and we can merge the ones from the latest layer