Sync pins back from Matrix to Discord
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* @param {string[]} pins
|
||||
* @param {string[]} prev
|
||||
* @returns {[string, boolean][]}
|
||||
*/
|
||||
function diffPins(pins, prev) {
|
||||
/** @type {[string, boolean][]} */
|
||||
const result = []
|
||||
return result.concat(
|
||||
prev.filter(id => !pins.includes(id)).map(id => [id, false]), // removed
|
||||
pins.filter(id => !prev.includes(id)).map(id => [id, true]) // added
|
||||
)
|
||||
}
|
||||
|
||||
module.exports.diffPins = diffPins
|
||||
@@ -0,0 +1,11 @@
|
||||
// @ts-check
|
||||
|
||||
const {test} = require("supertape")
|
||||
const diffPins = require("./diff-pins")
|
||||
|
||||
test("diff pins: diff is as expected", t => {
|
||||
t.deepEqual(
|
||||
diffPins.diffPins(["same", "new"], ["same", "old"]),
|
||||
[["old", false], ["new", true]]
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user