2021-12-29 11:01:34 -05:00
|
|
|
"use strict";
|
2021-01-13 21:56:14 -05:00
|
|
|
Vue.component('tf-user', {
|
2021-12-28 15:21:23 -05:00
|
|
|
data: function() { return {
|
|
|
|
show_user_dialog: false,
|
|
|
|
show_follow_dialog: false,
|
|
|
|
edit_profile_name: null,
|
|
|
|
edit_profile_description: null,
|
|
|
|
} },
|
2021-01-13 21:56:14 -05:00
|
|
|
props: ['id'],
|
|
|
|
computed: {
|
|
|
|
following: {
|
|
|
|
get: function() {
|
2021-12-29 16:00:03 -05:00
|
|
|
return g_data.users &&
|
|
|
|
g_data.users[g_data.whoami] &&
|
|
|
|
g_data.users[g_data.whoami].following[this.id];
|
2021-01-13 21:56:14 -05:00
|
|
|
},
|
|
|
|
set: function(newValue) {
|
2021-12-29 16:00:03 -05:00
|
|
|
var already_following =
|
|
|
|
g_data.users &&
|
|
|
|
g_data.users[g_data.whoami] &&
|
|
|
|
g_data.users[g_data.whoami].following &&
|
|
|
|
g_data.users[g_data.whoami].following[this.id];
|
|
|
|
if (newValue && !already_following) {
|
|
|
|
if (confirm("Are you sure you want to follow " + this.id + "?")) {
|
2021-01-13 21:56:14 -05:00
|
|
|
window.parent.postMessage({appendMessage: {type: "contact", following: true, contact: this.id}}, '*');
|
2021-12-29 16:00:03 -05:00
|
|
|
}
|
|
|
|
} else if (!newValue && already_following) {
|
|
|
|
if (confirm("Are you sure you want to unfollow " + this.id + "?")) {
|
2021-01-13 21:56:14 -05:00
|
|
|
window.parent.postMessage({appendMessage: {type: "contact", following: false, contact: this.id}}, '*');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2021-12-28 15:21:23 -05:00
|
|
|
whoami: { get: function() { return g_data.whoami; } },
|
2021-12-28 16:54:43 -05:00
|
|
|
users: { get: function() { return g_data.users; } },
|
2021-12-28 15:21:23 -05:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
save_profile: function() {
|
|
|
|
var message = {appendMessage: {
|
|
|
|
type: 'about',
|
|
|
|
about: this.id,
|
|
|
|
name: this.edit_profile_name,
|
|
|
|
description: this.edit_profile_description,
|
|
|
|
}};
|
|
|
|
window.parent.postMessage(message, '*');
|
|
|
|
},
|
2021-12-28 16:54:43 -05:00
|
|
|
show_user: function() {
|
|
|
|
this.show_user_dialog = true;
|
|
|
|
if (this.id == this.whoami) {
|
|
|
|
this.edit_profile_name = this.users[this.id].name;
|
|
|
|
this.edit_profile_description = this.users[this.id].description;
|
|
|
|
}
|
|
|
|
},
|
2021-01-13 21:56:14 -05:00
|
|
|
},
|
2021-12-29 16:00:03 -05:00
|
|
|
template: `<span>
|
|
|
|
<md-chip md-clickable :class="following ? 'md-accent' : ''" @click="show_user()">
|
|
|
|
{{users[id] && users[id].name ? users[id].name : id}}
|
|
|
|
</md-chip>
|
2021-01-13 21:56:14 -05:00
|
|
|
<md-tooltip v-if="users[id] && users[id].name">{{id}}</md-tooltip>
|
|
|
|
<md-dialog :md-active.sync="show_user_dialog">
|
|
|
|
<md-dialog-title>{{users[id] && users[id].name ? users[id].name : id}}</md-dialog-title>
|
2021-12-28 15:21:23 -05:00
|
|
|
<md-dialog-content>
|
|
|
|
<div v-if="id == whoami">
|
|
|
|
<md-field>
|
|
|
|
<label>Name</label>
|
|
|
|
<md-input v-model="edit_profile_name"></md-input>
|
|
|
|
</md-field>
|
|
|
|
<md-field>
|
|
|
|
<label>Description</label>
|
|
|
|
<md-textarea v-model="edit_profile_description"></md-textarea>
|
|
|
|
</md-field>
|
|
|
|
</div>
|
|
|
|
<template v-if="users[id]">
|
|
|
|
<div v-if="users[id].image"><img :src="'/' + users[id].image + '/view'"></div>
|
|
|
|
<div v-if="users[id].name">{{id}}</div>
|
|
|
|
<div>{{users[id].description}}</div>
|
|
|
|
<div><md-switch v-model="following">Following</md-switch></div>
|
2021-12-30 19:57:57 -05:00
|
|
|
<div class="md-layout">
|
|
|
|
<div class="md-layout-item">
|
|
|
|
<md-list>
|
|
|
|
<md-subheader>Followers</md-subheader>
|
|
|
|
<md-list-item v-for="follower in Object.keys((users[id] && users[id].followers) ? users[id].followers : {})" v-bind:key="'follower-' + follower">
|
|
|
|
<tf-user :id="follower"></tf-user>
|
|
|
|
</md-list-item>
|
|
|
|
</md-list>
|
|
|
|
</div>
|
|
|
|
<div class="md-layout-item">
|
|
|
|
<md-list>
|
|
|
|
<md-subheader>Following</md-subheader>
|
|
|
|
<md-list-item v-for="user in Object.keys((users[id] && users[id].following) ? users[id].following : {})" v-bind:key="'following-' + user">
|
|
|
|
<tf-user :id="user"></tf-user>
|
|
|
|
</md-list-item>
|
|
|
|
</md-list>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-28 15:21:23 -05:00
|
|
|
</template>
|
2021-01-13 21:56:14 -05:00
|
|
|
</md-dialog-content>
|
|
|
|
<md-dialog-actions>
|
2021-12-29 16:00:03 -05:00
|
|
|
<md-button @click="save_profile" v-if="id == whoami">Save Profile</md-button>
|
2021-01-13 21:56:14 -05:00
|
|
|
<md-button @click="show_user_dialog = false">Close</md-button>
|
|
|
|
</md-dialog-actions>
|
|
|
|
</md-dialog>
|
|
|
|
</span>`,
|
|
|
|
});
|