2018-08-02 11:34:12 +02:00
|
|
|
import apiService from '../../services/api/api.service.js'
|
2018-12-13 17:57:11 +01:00
|
|
|
import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
|
2019-01-24 16:17:35 +01:00
|
|
|
import { shuffle } from 'lodash'
|
2018-08-02 11:34:12 +02:00
|
|
|
|
|
|
|
function showWhoToFollow (panel, reply) {
|
2019-01-24 16:17:35 +01:00
|
|
|
const shuffled = shuffle(reply)
|
2019-01-04 09:43:00 +01:00
|
|
|
|
2018-12-25 01:34:33 +01:00
|
|
|
panel.usersToFollow.forEach((toFollow, index) => {
|
2019-01-24 16:17:35 +01:00
|
|
|
let user = shuffled[index]
|
2018-12-25 01:34:33 +01:00
|
|
|
let img = user.avatar || '/images/avi.png'
|
|
|
|
let name = user.acct
|
|
|
|
|
|
|
|
toFollow.img = img
|
|
|
|
toFollow.name = name
|
|
|
|
|
2019-09-03 18:59:28 +02:00
|
|
|
panel.$store.state.api.backendInteractor.fetchUser({ id: name })
|
2018-12-25 01:34:33 +01:00
|
|
|
.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) {
|
2018-08-02 10:57:00 +02:00
|
|
|
var credentials = panel.$store.state.users.currentUser.credentials
|
|
|
|
if (credentials) {
|
2018-12-25 02:32:20 +01:00
|
|
|
panel.usersToFollow.forEach(toFollow => {
|
|
|
|
toFollow.name = 'Loading...'
|
2018-12-25 01:34:33 +01:00
|
|
|
})
|
2019-07-05 09:02:14 +02:00
|
|
|
apiService.suggestions({ credentials: credentials })
|
2018-08-02 11:38:43 +02:00
|
|
|
.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: () => ({
|
2018-12-25 01:34:33 +01:00
|
|
|
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: {
|
2018-12-13 17:57:11 +01:00
|
|
|
userProfileLink (id, name) {
|
2018-12-26 14:50:48 +01:00
|
|
|
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
|