This commit is contained in:
j3d1 2023-05-14 16:10:54 +02:00
parent c14762e20b
commit dfbe4d5dd4
2 changed files with 41 additions and 8 deletions

View file

@ -2,6 +2,7 @@ import {createStore} from 'vuex';
import router from '@/router'; import router from '@/router';
import FallBackResolver from "@/dns"; import FallBackResolver from "@/dns";
import NeighborsCache from "@/neigbors"; import NeighborsCache from "@/neigbors";
import {useRoute} from "vue-router";
export default createStore({ export default createStore({
@ -46,6 +47,9 @@ export default createStore({
setInventoryItems(state, {url, items}) { setInventoryItems(state, {url, items}) {
state.item_map[url] = items; state.item_map[url] = items;
}, },
setFriends(state, friends) {
state.friends = friends;
},
logout(state) { logout(state) {
state.user = null; state.user = null;
state.token = null; state.token = null;
@ -95,8 +99,15 @@ export default createStore({
return false; return false;
} }
}, },
async getFriends(state) { async getFriends({commit, dispatch, state}) {
return ['jedi@j3d1.de', 'foobar@example.com', 'foobaz@example.eleon', 'alice@example2.com']; const home_server = "localhost:8000"
const data = await dispatch('apiFederatedGet', {
host: home_server,
target: '/api/friends/'
})
console.log('getFriends', data)
commit('setFriends', data)
return data
}, },
async getFriendServer({state}, {username}) { async getFriendServer({state}, {username}) {
const domain = username.split('@')[1] const domain = username.split('@')[1]
@ -204,8 +215,30 @@ export default createStore({
console.log('ext_reply', ext_reply) console.log('ext_reply', ext_reply)
return true; return true;
}, },
async acceptFriend({state, dispatch}, args) { async acceptFriend({state, dispatch}, {id, secret}) {
console.log('accepting friend ' + args) console.log('accepting friend ' + id)
state.home_server = 'localhost:8000'
const home_reply = await dispatch('apiFederatedPost', {
host: state.home_server,
target: '/api/friends/',
data: {
friend_request_id: id, secret: secret
}
})
console.log('home_reply', home_reply)
const ext_serqver = await dispatch('getFriendServer', {username: home_reply.befriender})
const ext_reply = await dispatch('apiFederatedPost', {
host: ext_serqver[0],
target: '/api/friendrequests/',
data: {
befriender: state.user,
befriendee: username,
befriender_key: nacl.to_hex(state.keypair.signPk),
secret: home_reply.secret
}
})
console.log('ext_reply', ext_reply)
return true
}, },
async declineFriend({state, dispatch}, args) { async declineFriend({state, dispatch}, args) {
console.log('declining friend ' + args) console.log('declining friend ' + args)

View file

@ -80,11 +80,11 @@
<td class="d-none d-md-table-cell"> <td class="d-none d-md-table-cell">
{{ request.befriender_public_key.slice(0,32) }}...</td> {{ request.befriender_public_key.slice(0,32) }}...</td>
<td class="table-action"> <td class="table-action">
<button class="btn btn-sm btn-success" @click="tryAcceptFriend(request.befriender)"> <button class="btn btn-sm btn-success" @click="tryAcceptFriend(request)">
<b-icon-check></b-icon-check> <b-icon-check></b-icon-check>
Accept Accept
</button> &nbsp; </button> &nbsp;
<button class="btn btn-sm btn-danger" @click="tryRejectFriend(request.befriender)"> <button class="btn btn-sm btn-danger" @click="tryRejectFriend(request)">
<b-icon-x></b-icon-x> <b-icon-x></b-icon-x>
Decline Decline
</button> </button>
@ -158,8 +158,8 @@ export default {
} }
}).catch(() => {}) }).catch(() => {})
}, },
tryAcceptFriend(friend) { tryAcceptFriend(request) {
this.acceptFriend({username: friend}).then((ok) => { this.acceptFriend({id: request.id, secret: request.secret}).then((ok) => {
if (ok) { if (ok) {
this.fetchContent() this.fetchContent()
} }