Skip to content

Commit

Permalink
feat: add user followed
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Apr 27, 2022
1 parent cdbf5ff commit 574e26e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"commander": "^9.2.0",
"enquirer": "^2.3.6",
"eventemitter3": "^4.0.7",
"jike-sdk": "^0.15.1",
"jike-sdk": "^0.16.0",
"node-fetch": "^3.2.3",
"open": "^8.4.0",
"terminal-image": "^2.0.0"
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions src/command/user/followed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { logger } from '@poppinss/cliui'
import { createCommand } from 'commander'
import { createClient, filterUsers } from '../../utils/user'

export const followed = createCommand('followed')
.description('output whether the follower is followed by following user')
.option('-f, --following <following>', 'the username of the following user')
.option('-F, --follower <follower>', 'the username of the follower user')
.action(() => {
const { following, follower } = followed.opts<{
following?: string
follower?: string
}>()
isFollowed(following, follower)
})

export const isFollowed = async (following?: string, follower?: string) => {
const [user] = filterUsers()
const client = createClient(user)

const getUser = (username?: string) =>
username ? client.getUser(username) : client.getSelf()

// TODO: auto select mode
const isFollowed = await getUser(following).isFollowing(
getUser(follower),
'following'
)

logger.info(`${isFollowed ? 'Followed!' : 'Not followed.'}`)
}
3 changes: 3 additions & 0 deletions src/command/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { profile } from './profile'
import { renew } from './renew'
import { view } from './view'
import { alias } from './alias'
import { followed } from './followed'

export const user = createCommand('user')
.description('user-related operations')
Expand All @@ -21,6 +22,7 @@ Example call:
$ jike-cli user view 82D23B32-CF36-4C59-AD6F-D05E3552CBF3
$ jike-cli user info
$ jike-cli user alias -u <user> <alias>
$ jike-cli user followed -f 5C505995-681E-4C1E-AD4A-1CC683627B6E
`
)
.usage('<command> [flags]')
Expand All @@ -32,3 +34,4 @@ Example call:
.addCommand(profile)
.addCommand(view)
.addCommand(alias)
.addCommand(followed)

0 comments on commit 574e26e

Please sign in to comment.