d->m: Sync missed emojis/stickers after restart

This commit is contained in:
Cadence Ember 2024-01-10 23:56:10 +13:00
parent a67708269d
commit 9efd6a49b8
7 changed files with 140 additions and 85 deletions

View file

@ -2,6 +2,7 @@
const assert = require("assert").strict
const mixin = require("mixin-deep")
const deepEqual = require("deep-equal")
/** Mutates the input. */
function kstateStripConditionals(kstate) {
@ -50,18 +51,14 @@ function diffKState(actual, target) {
// Special handling for power levels, we want to deep merge the actual and target into the final state.
if (!(key in actual)) throw new Error(`want to apply a power levels diff, but original power level data is missing\nstarted with: ${JSON.stringify(actual)}\nwant to apply: ${JSON.stringify(target)}`)
const temp = mixin({}, actual[key], target[key])
try {
assert.deepEqual(actual[key], temp)
} catch (e) {
if (!deepEqual(actual[key], temp, {strict: true})) {
// they differ. use the newly prepared object as the diff.
diff[key] = temp
}
} else if (key in actual) {
// diff
try {
assert.deepEqual(actual[key], target[key])
} catch (e) {
if (!deepEqual(actual[key], target[key], {strict: true})) {
// they differ. use the target as the diff.
diff[key] = target[key]
}