summaryrefslogtreecommitdiffstats
path: root/src/views/OStatus.vue
blob: 2ce96cffe3aef50daf647cca1768186a188937cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<template>
	<div v-if="account">
		<div v-if="!serverData.local">
			<h2>{{ t('social', 'Follow on Nextcloud Social') }}</h2>
			<p>{{ t('social', 'Hello') }} <avatar :user="currentUser.uid" :size="16" />{{ currentUser.displayName }}</p>
			<p v-if="!isFollowing">
				{{ t('social', 'Please confirm that you want to follow this account:') }}
			</p>

			<avatar :url="avatarUrl" :disable-tooltip="true" :size="128" />
			<h2>{{ displayName }}</h2>
			<form v-if="!isFollowing" @submit.prevent="follow">
				<input type="submit" class="primary" value="Follow">
			</form>
			<p v-else>
				<span class="icon icon-checkmark-white" />
				{{ t('social', 'You are following this account') }}
			</p>

			<div v-if="isFollowing">
				<button @click="close">
					{{ t('social', 'Close') }}
				</button>
			</div>
		</div>
		<!-- Some unauthenticated user wants to follow a local account -->
		<div v-if="serverData.local">
			<p>{{ t('social', 'You are going to follow:') }}</p>
			<avatar :user="serverData.local" :disable-tooltip="true" :size="128" />
			<h2>{{ displayName }}</h2>
			<form @submit.prevent="followRemote">
				<input v-model="remote" type="text" :placeholder="t('social', 'name@domain of your federation account')">
				<input type="submit" class="primary" :value="t('social', 'Continue')">
			</form>
			<p>{{ t('social', 'This step is needed as the user is probably not registered on the same server as you are. We will redirect you to your homeserver to follow this account.') }}</p>
		</div>
	</div>
	<div v-else :class="{ 'icon-loading-dark': !account }" />
</template>

<style scoped>
	h2, p {
		color: var(--color-primary-text);
	}
	p .icon {
		display: inline-block;
	}
	.avatardiv {
		vertical-align: -4px;
		margin-right: 3px;
		filter: drop-shadow(0 0 0.5rem #333);
		margin-top: 10px;
		margin-bottom: 20px;
	}
</style>

<style>
	.wrapper {
		margin-top: 20px;
	}
</style>

<script>
import Avatar from '@nextcloud/vue/dist/Components/Avatar'
import axios from '@nextcloud/axios'
import accountMixins from '../mixins/accountMixins'
import currentuserMixin from '../mixins/currentUserMixin'
import { loadState } from '@nextcloud/initial-state'
import { generateUrl } from '@nextcloud/router'

export default {
	name: 'App',
	components: {
		Avatar
	},
	mixins: [
		accountMixins,
		currentuserMixin
	],
	data() {
		return {
			remote: '',
			account: {}
		}
	},
	computed: {
		isFollowing() {
			return this.$store.getters.isFollowingUser(this.account.id)
		},
		avatarUrl() {
			return generateUrl('/apps/social/api/v1/global/actor/avatar?id=' + this.account.id)
		},
		currentUser() {
			return window.oc_current_user
		},
		displayName() {
			if (typeof this.account.id === 'undefined') {
				return (this.serverData.account ? this.serverData.account : this.serverData.local)
			}

			return (this.account.name ? this.account.name : this.account.preferredUsername)
		}
	},
	beforeMount: function() {
		// importing server data into the store and fetching viewed account's information
		try {
			const serverData = loadState('social', 'serverData')
			if (serverData.currentUser) {
				window.oc_current_user = JSON.parse(JSON.stringify(serverData.currentUser))
			}
			this.$store.commit('setServerData', serverData)
			if (this.serverData.account && !this.serverData.local) {
				this.$store.dispatch('fetchAccountInfo', this.serverData.account).then((result) => {
					this.account = result
				})
			}
			if (this.serverData.local) {
				this.$store.dispatch('fetchPublicAccountInfo', this.serverData.local).then((result) => {
					this.account = result
				})
			}
		} catch {
			/* empty */
		}
	},
	methods: {
		follow() {
			this.$store.dispatch('followAccount', { currentAccount: this.cloudId, accountToFollow: this.account.account }).then(() => {

			})
		},
		followRemote() {
			axios.get(generateUrl(`/apps/social/api/v1/ostatus/link/${this.serverData.local}/` + encodeURI(this.remote))).then((a) => {
				window.location = a.data.result.url
			})
		},
		close() {
			window.close()
		}
	}
}
</script>