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

78 lines
1.8 KiB
JavaScript
Raw Normal View History

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