refactor follow and unfollow to share code
This commit is contained in:
parent
78b26f3de9
commit
22bf2719be
|
@ -113,29 +113,6 @@ module.exports = (cooler) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
models.friend = {
|
models.friend = {
|
||||||
// TODO: Refactor `follow` and `unfollow` to share code.
|
|
||||||
follow: async (feedId) => {
|
|
||||||
const ssb = await cooler.connect()
|
|
||||||
|
|
||||||
const content = {
|
|
||||||
type: 'contact',
|
|
||||||
contact: feedId,
|
|
||||||
following: true
|
|
||||||
}
|
|
||||||
|
|
||||||
return cooler.get(ssb.publish, content)
|
|
||||||
},
|
|
||||||
unfollow: async (feedId) => {
|
|
||||||
const ssb = await cooler.connect()
|
|
||||||
|
|
||||||
const content = {
|
|
||||||
type: 'contact',
|
|
||||||
contact: feedId,
|
|
||||||
following: false
|
|
||||||
}
|
|
||||||
|
|
||||||
return cooler.get(ssb.publish, content)
|
|
||||||
},
|
|
||||||
isFollowing: async (feedId) => {
|
isFollowing: async (feedId) => {
|
||||||
const ssb = await cooler.connect()
|
const ssb = await cooler.connect()
|
||||||
const { id } = ssb
|
const { id } = ssb
|
||||||
|
@ -149,6 +126,29 @@ module.exports = (cooler) => {
|
||||||
)
|
)
|
||||||
return isFollowing
|
return isFollowing
|
||||||
},
|
},
|
||||||
|
setFollowing: async ({ feedId, following }) => {
|
||||||
|
const ssb = await cooler.connect()
|
||||||
|
|
||||||
|
const content = {
|
||||||
|
type: 'contact',
|
||||||
|
contact: feedId,
|
||||||
|
following
|
||||||
|
}
|
||||||
|
|
||||||
|
return cooler.get(ssb.publish, content)
|
||||||
|
},
|
||||||
|
follow: async (feedId) => {
|
||||||
|
const isFollowing = await models.friend.isFollowing(feedId)
|
||||||
|
if (!isFollowing) {
|
||||||
|
await models.friend.setFollowing({ feedId, following: true })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
unfollow: async (feedId) => {
|
||||||
|
const isFollowing = await models.friend.isFollowing(feedId)
|
||||||
|
if (isFollowing) {
|
||||||
|
await models.friend.setFollowing({ feedId, following: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
getRelationship: async (feedId) => {
|
getRelationship: async (feedId) => {
|
||||||
const ssb = await cooler.connect()
|
const ssb = await cooler.connect()
|
||||||
const { id } = ssb
|
const { id } = ssb
|
||||||
|
|
Loading…
Reference in New Issue