pinafore/routes/_store/mixins/statusMixins.js
Nolan Lawson 2449a27767
fix pinned/unpinned state of recently pinned statuses (#521)
* fix pinned/unpinned state of recently pinned statuses

* fixup

* fix test
2018-08-29 18:10:09 -07:00

30 lines
1 KiB
JavaScript

function getStatusModifications (store, instanceName) {
let { statusModifications } = store.get()
statusModifications[instanceName] = statusModifications[instanceName] || {
favorites: {},
reblogs: {},
pins: {}
}
return statusModifications
}
function setStatusModification (store, instanceName, statusId, key, value) {
let statusModifications = getStatusModifications(store, instanceName)
statusModifications[instanceName][key][statusId] = value
store.set({ statusModifications })
}
export function statusMixins (Store) {
Store.prototype.setStatusFavorited = function (instanceName, statusId, favorited) {
setStatusModification(this, instanceName, statusId, 'favorites', favorited)
}
Store.prototype.setStatusReblogged = function (instanceName, statusId, reblogged) {
setStatusModification(this, instanceName, statusId, 'reblogs', reblogged)
}
Store.prototype.setStatusPinned = function (instanceName, statusId, pinned) {
setStatusModification(this, instanceName, statusId, 'pins', pinned)
}
}