pleroma-fe/src/components/who_to_follow_panel/who_to_follow_panel.js

79 行
1.9 KiB
JavaScript
Raw 通常表示 履歴

2018-08-02 18:34:12 +09:00
import apiService from '../../services/api/api.service.js'
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
2019-01-25 00:17:35 +09:00
import { shuffle } from 'lodash'
2018-08-02 18:34:12 +09:00
function showWhoToFollow (panel, reply) {
2019-01-25 00:17:35 +09:00
const shuffled = shuffle(reply)
panel.usersToFollow.forEach((toFollow, index) => {
2022-07-31 18:35:48 +09:00
const user = shuffled[index]
const img = user.avatar || this.$store.state.instance.defaultAvatar
const name = user.acct
toFollow.img = img
toFollow.name = name
panel.$store.state.api.backendInteractor.fetchUser({ id: name })
.then((externalUser) => {
if (!externalUser.error) {
panel.$store.commit('addNewUsers', [externalUser])
toFollow.id = externalUser.id
}
})
})
2018-03-28 15:57:11 +09:00
}
function getWhoToFollow (panel) {
2022-07-31 18:35:48 +09:00
const credentials = panel.$store.state.users.currentUser.credentials
if (credentials) {
panel.usersToFollow.forEach(toFollow => {
toFollow.name = 'Loading...'
})
2022-07-31 18:35:48 +09:00
apiService.suggestions({ credentials })
2018-08-02 18:38:43 +09:00
.then((reply) => {
2018-08-02 18:34:12 +09:00
showWhoToFollow(panel, reply)
})
2018-03-28 15:57:11 +09:00
}
}
2018-02-11 23:12:05 +09:00
const WhoToFollowPanel = {
data: () => ({
usersToFollow: []
2018-02-11 23:12:05 +09:00
}),
computed: {
user: function () {
return this.$store.state.users.currentUser.screen_name
},
2018-08-22 15:15:15 +09:00
suggestionsEnabled () {
2018-09-10 04:31:34 +09:00
return this.$store.state.instance.suggestionsEnabled
2018-12-17 08:52:27 +09:00
}
},
methods: {
userProfileLink (id, name) {
return generateProfileLink(id, name, this.$store.state.instance.restrictedNicknames)
2018-02-11 23:12:05 +09:00
}
},
watch: {
user: function (user, oldUser) {
2018-08-22 15:15:15 +09:00
if (this.suggestionsEnabled) {
2018-03-28 15:57:11 +09:00
getWhoToFollow(this)
2018-02-11 23:12:05 +09:00
}
}
},
mounted:
function () {
this.usersToFollow = new Array(3).fill().map(x => (
{
img: this.$store.state.instance.defaultAvatar,
name: '',
id: 0
}
))
2018-08-22 15:15:15 +09:00
if (this.suggestionsEnabled) {
2018-03-28 15:57:11 +09:00
getWhoToFollow(this)
2018-02-11 23:12:05 +09:00
}
}
}
export default WhoToFollowPanel