2019-06-17 17:15:27 +02:00
< template >
2020-06-25 11:36:35 +02:00
< div >
2022-01-10 15:19:16 +01:00
< breadcrumbs -nav :links ="breadcrumbsLinks" / >
2020-06-25 11:36:35 +02:00
< div class = "root" v-if ="identity" >
< h1 class = "title" >
< span v-if ="isUpdate" > {{ identity.displayName ( ) }} < / span >
< span v-else > {{ $ t ( " I create an identity " ) }} < / span >
< / h1 >
2020-11-30 10:24:11 +01:00
< picture -upload
v - model = "avatarFile"
: defaultImage = "identity.avatar"
2021-04-12 10:43:04 +02:00
: maxSize = "avatarMaxSize"
2020-11-30 10:24:11 +01:00
class = "picture-upload"
/ >
2020-06-25 11:36:35 +02:00
2021-09-07 17:52:34 +02:00
< b -field
horizontal
: label = "$t('Display name')"
label - for = "identity-display-name"
>
2020-02-18 08:57:00 +01:00
< b -input
aria - required = "true"
required
2020-06-25 11:36:35 +02:00
v - model = "identity.name"
@ input = "autoUpdateUsername($event)"
2021-09-07 17:52:34 +02:00
id = "identity-display-name"
2021-11-07 14:59:20 +01:00
dir = "auto"
2020-02-18 08:57:00 +01:00
/ >
2020-06-25 11:36:35 +02:00
< / b - f i e l d >
2019-06-17 17:15:27 +02:00
2020-06-25 11:36:35 +02:00
< b -field
horizontal
custom - class = "username-field"
expanded
: label = "$t('Username')"
2021-09-07 17:52:34 +02:00
label - for = "identity-username"
2020-06-25 11:36:35 +02:00
: message = "message"
>
< b -field expanded >
< b -input
aria - required = "true"
required
v - model = "identity.preferredUsername"
: disabled = "isUpdate"
2021-11-07 14:59:20 +01:00
dir = "auto"
2020-06-25 11:36:35 +02:00
: use - html5 - validation = "!isUpdate"
pattern = "[a-z0-9_]+"
2021-09-07 17:52:34 +02:00
id = "identity-username"
2020-06-25 11:36:35 +02:00
/ >
< p class = "control" >
< span class = "button is-static" > @ { { getInstanceHost } } < / span >
< / p >
< / b - f i e l d >
< / b - f i e l d >
2021-09-07 17:52:34 +02:00
< b -field
horizontal
: label = "$t('Description')"
label - for = "identity-summary"
>
2020-11-30 10:24:11 +01:00
< b -input
type = "textarea"
2021-11-07 14:59:20 +01:00
dir = "auto"
2020-11-30 10:24:11 +01:00
aria - required = "false"
v - model = "identity.summary"
2021-09-07 17:52:34 +02:00
id = "identity-summary"
2020-11-30 10:24:11 +01:00
/ >
2019-06-17 17:15:27 +02:00
< / b - f i e l d >
2020-06-25 11:36:35 +02:00
< b -notification
type = "is-danger"
has - icon
aria - close - label = "Close notification"
role = "alert"
: key = "error"
v - for = "error in errors"
> { { error } } < / b - n o t i f i c a t i o n
>
< b -field class = "submit" >
< div class = "control" >
< button type = "button" class = "button is-primary" @click ="submit()" >
{ { $t ( "Save" ) } }
< / button >
< / div >
< / b - f i e l d >
2021-09-07 17:52:34 +02:00
< b -field class = "delete-identity" >
< b -button
v - if = "isUpdate"
@ click = "openDeleteIdentityConfirmation()"
type = "is-text"
>
{ { $t ( "Delete this identity" ) } }
< / b - b u t t o n >
< / b - f i e l d >
2021-03-26 19:01:55 +01:00
< section v-if ="isUpdate" >
< div class = "setting-title" >
< h2 > { { $t ( "Profile feeds" ) } } < / h2 >
< / div >
< p >
{ {
$t (
"These feeds contain event data for the events for which this specific profile is a participant or creator. You should keep these private. You can find feeds for all of your profiles into your notification settings."
)
} }
< / p >
< div v-if ="identity.feedTokens && identity.feedTokens.length > 0" >
< div
class = "buttons"
v - for = "feedToken in identity.feedTokens"
: key = "feedToken.token"
>
< b -tooltip
: label = "$t('URL copied to clipboard')"
: active = "showCopiedTooltip.atom"
always
type = "is-success"
position = "is-left"
>
< b -button
tag = "a"
icon - left = "rss"
@ click = "
( e ) => copyURL ( e , tokenToURL ( feedToken . token , 'atom' ) , 'atom' )
"
: href = "tokenToURL(feedToken.token, 'atom')"
target = "_blank"
> { { $t ( "RSS/Atom Feed" ) } } < / b - b u t t o n
>
< / b - t o o l t i p >
< b -tooltip
: label = "$t('URL copied to clipboard')"
: active = "showCopiedTooltip.ics"
always
type = "is-success"
position = "is-left"
>
< b -button
tag = "a"
@ click = "
( e ) => copyURL ( e , tokenToURL ( feedToken . token , 'ics' ) , 'ics' )
"
icon - left = "calendar-sync"
: href = "tokenToURL(feedToken.token, 'ics')"
target = "_blank"
> { { $t ( "ICS/WebCal Feed" ) } } < / b - b u t t o n
>
< / b - t o o l t i p >
< b -button
icon - left = "refresh"
type = "is-text"
@ click = "openRegenerateFeedTokensConfirmation"
> { { $t ( "Regenerate new links" ) } } < / b - b u t t o n
>
< / div >
< / div >
< div v-else >
< b -button
icon - left = "refresh"
type = "is-text"
@ click = "generateFeedTokens"
> { { $t ( "Create new links" ) } } < / b - b u t t o n
>
< / div >
< / section >
2019-06-17 17:15:27 +02:00
< / div >
< / div >
< / template >
2021-11-07 14:59:20 +01:00
< style scoped lang = "scss" >
@ use "@/styles/_mixins" as * ;
2020-02-18 08:57:00 +01:00
h1 {
display : flex ;
justify - content : center ;
}
2019-06-17 17:15:27 +02:00
2020-02-18 08:57:00 +01:00
. picture - upload {
margin : 30 px 0 ;
}
2019-06-17 17:15:27 +02:00
2020-02-18 08:57:00 +01:00
. submit ,
. delete - identity {
display : flex ;
justify - content : center ;
}
2019-06-17 17:15:27 +02:00
2020-02-18 08:57:00 +01:00
. submit {
margin : 30 px 0 ;
}
2019-06-17 17:15:27 +02:00
2020-02-18 08:57:00 +01:00
. username - field + . field {
margin - bottom : 0 ;
}
2021-03-26 19:01:55 +01:00
: : v - deep . buttons > * : not ( : last - child ) . button {
2021-11-04 18:14:36 +01:00
@ include margin - right ( 0.5 rem ) ;
2021-03-26 19:01:55 +01:00
}
2019-06-17 17:15:27 +02:00
< / style >
< script lang = "ts" >
2020-02-18 08:57:00 +01:00
import { Component , Prop , Watch } from "vue-property-decorator" ;
import { mixins } from "vue-class-component" ;
2019-09-11 09:59:01 +02:00
import {
CREATE _PERSON ,
CURRENT _ACTOR _CLIENT ,
DELETE _PERSON ,
FETCH _PERSON ,
IDENTITIES ,
2021-08-05 15:49:54 +02:00
PERSON _FRAGMENT ,
2019-09-11 09:59:01 +02:00
UPDATE _PERSON ,
2020-02-18 08:57:00 +01:00
} from "../../../graphql/actor" ;
import { IPerson , Person } from "../../../types/actor" ;
import PictureUpload from "../../../components/PictureUpload.vue" ;
import { MOBILIZON _INSTANCE _HOST } from "../../../api/_entrypoint" ;
import RouteName from "../../../router/name" ;
2020-11-26 11:41:13 +01:00
import { buildFileVariable } from "../../../utils/image" ;
2020-02-18 08:57:00 +01:00
import { changeIdentity } from "../../../utils/auth" ;
import identityEditionMixin from "../../../mixins/identityEdition" ;
2021-03-26 19:01:55 +01:00
import {
CREATE _FEED _TOKEN _ACTOR ,
DELETE _FEED _TOKEN ,
} from "@/graphql/feed_tokens" ;
import { IFeedToken } from "@/types/feedtoken.model" ;
2021-04-12 10:43:04 +02:00
import { IConfig } from "@/types/config.model" ;
import { CONFIG } from "@/graphql/config" ;
2021-05-12 18:10:07 +02:00
import { ServerParseError } from "@apollo/client/link/http" ;
import { ApolloCache , FetchResult , InMemoryCache } from "@apollo/client/core" ;
2021-08-05 15:49:54 +02:00
import pick from "lodash/pick" ;
import { ActorType } from "@/types/enums" ;
2022-01-10 15:19:16 +01:00
import { Location } from "vue-router" ;
2019-06-17 17:15:27 +02:00
@ Component ( {
components : {
PictureUpload ,
} ,
2019-09-11 09:59:01 +02:00
apollo : {
currentActor : {
query : CURRENT _ACTOR _CLIENT ,
} ,
2019-12-17 19:32:48 +01:00
identity : {
query : FETCH _PERSON ,
2020-08-27 11:53:24 +02:00
fetchPolicy : "cache-and-network" ,
2019-12-17 19:32:48 +01:00
variables ( ) {
return {
username : this . identityName ,
} ;
} ,
2020-02-18 08:57:00 +01:00
skip ( ) {
return ! this . identityName ;
} ,
update : ( data ) => new Person ( data . fetchPerson ) ,
2020-10-02 09:52:47 +02:00
error ( { graphQLErrors } ) {
this . handleErrors ( graphQLErrors ) ;
} ,
2019-12-17 19:32:48 +01:00
} ,
2021-04-12 10:43:04 +02:00
config : CONFIG ,
2019-09-11 09:59:01 +02:00
} ,
2021-05-25 16:21:29 +02:00
metaInfo ( ) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const { isUpdate , identityName } = this ;
let title = this . $t ( "Create a new profile" ) as string ;
if ( isUpdate ) {
title = this . $t ( "Edit profile {profile}" , {
profile : identityName ,
} ) as string ;
}
return {
title ,
} ;
} ,
2019-06-17 17:15:27 +02:00
} )
2019-11-18 17:37:38 +01:00
export default class EditIdentity extends mixins ( identityEditionMixin ) {
2019-06-17 17:15:27 +02:00
@ Prop ( { type : Boolean } ) isUpdate ! : boolean ;
2020-02-18 08:57:00 +01:00
2019-12-17 19:32:48 +01:00
@ Prop ( { type : String } ) identityName ! : string ;
2019-06-17 17:15:27 +02:00
2021-04-12 10:43:04 +02:00
config ! : IConfig ;
2019-06-17 17:15:27 +02:00
errors : string [ ] = [ ] ;
avatarFile : File | null = null ;
2019-09-11 09:59:01 +02:00
private currentActor : IPerson | null = null ;
2019-06-17 17:15:27 +02:00
2020-06-25 11:36:35 +02:00
RouteName = RouteName ;
2021-03-26 19:01:55 +01:00
showCopiedTooltip = { ics : false , atom : false } ;
2020-09-29 09:53:48 +02:00
get message ( ) : string | null {
2019-11-18 17:37:38 +01:00
if ( this . isUpdate ) return null ;
2020-11-17 19:14:55 +01:00
return this . $t (
"Only alphanumeric lowercased characters and underscores are supported."
) as string ;
2019-11-18 17:37:38 +01:00
}
2020-02-18 08:57:00 +01:00
@ Watch ( "isUpdate" )
2020-09-29 09:53:48 +02:00
async isUpdateChanged ( ) : Promise < void > {
2019-06-17 17:15:27 +02:00
this . resetFields ( ) ;
}
2020-02-18 08:57:00 +01:00
@ Watch ( "identityName" , { immediate : true } )
2020-10-25 12:01:50 +01:00
async onIdentityParamChanged ( val : string ) : Promise < void > {
2019-06-17 17:15:27 +02:00
// Only used when we update the identity
2019-12-17 19:32:48 +01:00
if ( ! this . isUpdate ) return ;
2019-06-17 17:15:27 +02:00
await this . redirectIfNoIdentitySelected ( val ) ;
2019-12-17 19:32:48 +01:00
if ( ! this . identityName ) {
2020-10-25 12:01:50 +01:00
this . $router . push ( { name : "CreateIdentity" } ) ;
2019-11-05 15:03:35 +01:00
}
2019-12-17 19:32:48 +01:00
if ( this . identityName && this . identity ) {
2020-10-25 12:01:50 +01:00
this . avatarFile = null ;
2019-06-17 17:15:27 +02:00
}
}
2020-09-29 09:53:48 +02:00
submit ( ) : Promise < void > {
2019-06-17 17:15:27 +02:00
if ( this . isUpdate ) return this . updateIdentity ( ) ;
return this . createIdentity ( ) ;
}
2019-09-11 09:59:01 +02:00
/ * *
* Delete an identity
* /
2020-09-29 09:53:48 +02:00
async deleteIdentity ( ) : Promise < void > {
2019-06-17 17:15:27 +02:00
try {
await this . $apollo . mutate ( {
mutation : DELETE _PERSON ,
2019-10-04 18:28:25 +02:00
variables : {
id : this . identity . id ,
} ,
2021-05-12 18:10:07 +02:00
update : ( store : ApolloCache < InMemoryCache > ) => {
2020-02-18 08:57:00 +01:00
const data = store . readQuery < { identities : IPerson [ ] } > ( {
query : IDENTITIES ,
} ) ;
2019-06-17 17:15:27 +02:00
if ( data ) {
2021-08-05 15:49:54 +02:00
store . writeQuery ( {
query : IDENTITIES ,
data : {
identities : data . identities . filter (
( i ) => i . id !== this . identity . id
) ,
} ,
} ) ;
2019-06-17 17:15:27 +02:00
}
} ,
} ) ;
this . $notifier . success (
2020-02-18 08:57:00 +01:00
this . $t ( "Identity {displayName} deleted" , {
displayName : this . identity . displayName ( ) ,
} ) as string
2019-06-17 17:15:27 +02:00
) ;
2019-09-11 09:59:01 +02:00
/ * *
2020-11-30 10:24:11 +01:00
* If we just deleted the current identity ,
* we need to change it to the next one
2019-09-11 09:59:01 +02:00
* /
2020-02-18 08:57:00 +01:00
const data = this . $apollo . provider . defaultClient . readQuery < {
identities : IPerson [ ] ;
} > ( { query : IDENTITIES } ) ;
2019-09-11 09:59:01 +02:00
if ( data ) {
await this . maybeUpdateCurrentActorCache ( data . identities [ 0 ] ) ;
2019-06-17 17:15:27 +02:00
}
await this . redirectIfNoIdentitySelected ( ) ;
} catch ( err ) {
this . handleError ( err ) ;
}
}
2020-09-29 09:53:48 +02:00
async updateIdentity ( ) : Promise < void > {
2019-06-17 17:15:27 +02:00
try {
2019-10-08 19:32:48 +02:00
const variables = await this . buildVariables ( ) ;
2019-06-17 17:15:27 +02:00
await this . $apollo . mutate ( {
mutation : UPDATE _PERSON ,
2019-10-08 19:32:48 +02:00
variables ,
2021-05-12 18:10:07 +02:00
update : (
store : ApolloCache < InMemoryCache > ,
{ data : updateData } : FetchResult
) => {
2020-02-18 08:57:00 +01:00
const data = store . readQuery < { identities : IPerson [ ] } > ( {
query : IDENTITIES ,
} ) ;
2019-06-17 17:15:27 +02:00
2021-05-12 18:10:07 +02:00
if ( data && updateData ? . updatePerson ) {
this . maybeUpdateCurrentActorCache ( updateData ? . updatePerson ) ;
2019-06-17 17:15:27 +02:00
2021-08-05 15:49:54 +02:00
store . writeFragment ( {
fragment : PERSON _FRAGMENT ,
id : ` Person: ${ updateData ? . updatePerson . id } ` ,
data : {
... updateData ? . updatePerson ,
type : ActorType . PERSON ,
} ,
} ) ;
2019-06-17 17:15:27 +02:00
}
} ,
} ) ;
this . $notifier . success (
2020-02-18 08:57:00 +01:00
this . $t ( "Identity {displayName} updated" , {
displayName : this . identity . displayName ( ) ,
} ) as string
2019-06-17 17:15:27 +02:00
) ;
} catch ( err ) {
this . handleError ( err ) ;
}
}
2020-09-29 09:53:48 +02:00
async createIdentity ( ) : Promise < void > {
2019-06-17 17:15:27 +02:00
try {
2019-10-08 19:32:48 +02:00
const variables = await this . buildVariables ( ) ;
2019-06-17 17:15:27 +02:00
await this . $apollo . mutate ( {
mutation : CREATE _PERSON ,
2019-10-08 19:32:48 +02:00
variables ,
2021-05-12 18:10:07 +02:00
update : (
store : ApolloCache < InMemoryCache > ,
{ data : updateData } : FetchResult
) => {
2020-02-18 08:57:00 +01:00
const data = store . readQuery < { identities : IPerson [ ] } > ( {
query : IDENTITIES ,
} ) ;
2019-06-17 17:15:27 +02:00
2021-05-12 18:10:07 +02:00
if ( data && updateData ? . createPerson ) {
2021-08-05 15:49:54 +02:00
store . writeQuery ( {
query : IDENTITIES ,
data : {
identities : [
... data . identities ,
{ ... updateData ? . createPerson , type : ActorType . PERSON } ,
] ,
} ,
} ) ;
2019-06-17 17:15:27 +02:00
}
} ,
} ) ;
this . $notifier . success (
2020-02-18 08:57:00 +01:00
this . $t ( "Identity {displayName} created" , {
displayName : this . identity . displayName ( ) ,
} ) as string
2019-06-17 17:15:27 +02:00
) ;
2019-09-11 09:59:01 +02:00
2020-02-18 08:57:00 +01:00
await this . $router . push ( {
name : RouteName . UPDATE _IDENTITY ,
params : { identityName : this . identity . preferredUsername } ,
} ) ;
2019-06-17 17:15:27 +02:00
} catch ( err ) {
this . handleError ( err ) ;
}
}
2020-10-02 09:52:47 +02:00
handleErrors ( errors : any [ ] ) : void {
if ( errors . some ( ( error ) => error . status _code === 401 ) ) {
this . $router . push ( { name : RouteName . LOGIN } ) ;
}
}
2020-09-29 09:53:48 +02:00
// eslint-disable-next-line class-methods-use-this
get getInstanceHost ( ) : string {
2019-06-17 17:15:27 +02:00
return MOBILIZON _INSTANCE _HOST ;
}
2021-03-26 19:01:55 +01:00
tokenToURL ( token : string , format : string ) : string {
return ` ${ window . location . origin } /events/going/ ${ token } / ${ format } ` ;
}
copyURL ( e : Event , url : string , format : "ics" | "atom" ) : void {
if ( navigator . clipboard ) {
e . preventDefault ( ) ;
navigator . clipboard . writeText ( url ) ;
this . showCopiedTooltip [ format ] = true ;
setTimeout ( ( ) => {
this . showCopiedTooltip [ format ] = false ;
} , 2000 ) ;
}
}
2021-04-12 10:43:04 +02:00
get avatarMaxSize ( ) : number | undefined {
return this ? . config ? . uploadLimits ? . avatar ;
}
2021-03-26 19:01:55 +01:00
async generateFeedTokens ( ) : Promise < void > {
const newToken = await this . createNewFeedToken ( ) ;
2021-07-21 16:05:31 +02:00
this . identity . feedTokens = [ ... this . identity . feedTokens , newToken ] ;
2021-03-26 19:01:55 +01:00
}
async regenerateFeedTokens ( ) : Promise < void > {
if ( this . identity ? . feedTokens . length < 1 ) return ;
await this . deleteFeedToken ( this . identity . feedTokens [ 0 ] . token ) ;
const newToken = await this . createNewFeedToken ( ) ;
2021-07-21 16:05:31 +02:00
const feedTokens = this . identity . feedTokens . slice ( 0 , - 1 ) ;
this . identity . feedTokens = [ ... feedTokens , newToken ] ;
2021-03-26 19:01:55 +01:00
}
private async deleteFeedToken ( token : string ) : Promise < void > {
await this . $apollo . mutate ( {
mutation : DELETE _FEED _TOKEN ,
variables : { token } ,
} ) ;
}
private async createNewFeedToken ( ) : Promise < IFeedToken > {
const { data } = await this . $apollo . mutate ( {
mutation : CREATE _FEED _TOKEN _ACTOR ,
variables : { actor _id : this . identity ? . id } ,
} ) ;
return data . createFeedToken ;
}
openRegenerateFeedTokensConfirmation ( ) : void {
this . $buefy . dialog . confirm ( {
type : "is-warning" ,
title : this . $t ( "Regenerate new links" ) as string ,
message : this . $t (
"You'll need to change the URLs where there were previously entered."
) as string ,
confirmText : this . $t ( "Regenerate new links" ) as string ,
cancelText : this . $t ( "Cancel" ) as string ,
onConfirm : ( ) => this . regenerateFeedTokens ( ) ,
} ) ;
}
2020-09-29 09:53:48 +02:00
openDeleteIdentityConfirmation ( ) : void {
2019-08-21 11:25:09 +02:00
this . $buefy . dialog . prompt ( {
2020-02-18 08:57:00 +01:00
type : "is-danger" ,
title : this . $t ( "Delete your identity" ) as string ,
message : ` ${ this . $t (
"This will delete / anonymize all content (events, comments, messages, participations…) created from this identity."
) }
2019-09-12 11:34:01 +02:00
< br / > < br / >
2020-02-18 08:57:00 +01:00
$ { this . $t (
"If this identity is the only administrator of some groups, you need to delete them before being able to delete this identity."
) }
$ { this . $t (
"Otherwise this identity will just be removed from the group administrators."
) }
2019-09-12 11:34:01 +02:00
< br / > < br / >
2020-11-30 10:24:11 +01:00
$ { this . $t (
'To confirm, type your identity username "{preferredUsername}"' ,
{
preferredUsername : this . identity . preferredUsername ,
}
) } ` ,
2020-02-18 08:57:00 +01:00
confirmText : this . $t ( "Delete {preferredUsername}" , {
preferredUsername : this . identity . preferredUsername ,
} ) as string ,
2019-06-17 17:15:27 +02:00
inputAttrs : {
placeholder : this . identity . preferredUsername ,
pattern : this . identity . preferredUsername ,
} ,
onConfirm : ( ) => this . deleteIdentity ( ) ,
} ) ;
}
private handleError ( err : any ) {
console . error ( err ) ;
2021-04-12 10:43:04 +02:00
if ( err ? . networkError ? . name === "ServerParseError" ) {
const error = err ? . networkError as ServerParseError ;
if ( error ? . response ? . status === 413 ) {
const errorMessage = this . isUpdate
? this . $t (
"Unable to update the profile. The avatar picture may be too heavy."
)
: this . $t (
"Unable to create the profile. The avatar picture may be too heavy."
) ;
this . errors . push ( errorMessage as string ) ;
}
}
2019-09-11 09:59:01 +02:00
if ( err . graphQLErrors !== undefined ) {
2020-02-18 08:57:00 +01:00
err . graphQLErrors . forEach ( ( { message } : { message : string } ) => {
2019-09-11 09:59:01 +02:00
this . $notifier . error ( message ) ;
} ) ;
}
2019-06-17 17:15:27 +02:00
}
2021-08-05 15:49:54 +02:00
private async buildVariables ( ) : Promise < Record < string , unknown > > {
2019-10-08 19:32:48 +02:00
/ * *
2020-10-25 12:01:50 +01:00
* We set the avatar only if user has selected one
2019-10-08 19:32:48 +02:00
* /
2020-10-25 12:01:50 +01:00
let avatarObj : Record < string , unknown > = { avatar : null } ;
if ( this . avatarFile ) {
avatarObj = buildFileVariable (
this . avatarFile ,
"avatar" ,
` ${ this . identity . preferredUsername } 's avatar `
) ;
2019-10-08 19:32:48 +02:00
}
2021-08-05 15:49:54 +02:00
return pick ( { ... this . identity , ... avatarObj } , [
"id" ,
"preferredUsername" ,
"name" ,
"summary" ,
"avatar" ,
] ) ;
2019-06-17 17:15:27 +02:00
}
2019-12-17 19:32:48 +01:00
private async redirectIfNoIdentitySelected ( identityParam ? : string ) {
2020-02-18 08:57:00 +01:00
if ( identityParam ) return ;
2019-06-17 17:15:27 +02:00
await this . loadLoggedPersonIfNeeded ( ) ;
2020-02-18 08:57:00 +01:00
if ( this . currentActor ) {
await this . $router . push ( {
params : { identityName : this . currentActor . preferredUsername } ,
} ) ;
2019-09-11 09:59:01 +02:00
}
}
private async maybeUpdateCurrentActorCache ( identity : IPerson ) {
if ( this . currentActor ) {
2020-11-30 10:24:11 +01:00
if (
this . currentActor . preferredUsername === this . identity . preferredUsername
) {
2019-09-11 09:59:01 +02:00
await changeIdentity ( this . $apollo . provider . defaultClient , identity ) ;
}
this . currentActor = identity ;
2019-06-17 17:15:27 +02:00
}
}
2020-02-18 08:57:00 +01:00
private async loadLoggedPersonIfNeeded ( bypassCache = false ) {
2019-09-11 09:59:01 +02:00
if ( this . currentActor ) return ;
2019-06-17 17:15:27 +02:00
const result = await this . $apollo . query ( {
2019-09-11 09:59:01 +02:00
query : CURRENT _ACTOR _CLIENT ,
2020-02-18 08:57:00 +01:00
fetchPolicy : bypassCache ? "network-only" : undefined ,
2019-06-17 17:15:27 +02:00
} ) ;
2019-09-11 09:59:01 +02:00
this . currentActor = result . data . currentActor ;
2019-06-17 17:15:27 +02:00
}
2020-02-18 08:57:00 +01:00
private resetFields ( ) {
2019-06-17 17:15:27 +02:00
this . identity = new Person ( ) ;
this . oldDisplayName = null ;
this . avatarFile = null ;
}
2022-01-10 15:19:16 +01:00
get breadcrumbsLinks ( ) : ( Location & { text : string } ) [ ] {
const links = [
{
name : RouteName . IDENTITIES ,
params : { } ,
text : this . $t ( "Profiles" ) as string ,
} ,
] ;
if ( this . isUpdate && this . identity ) {
links . push ( {
name : RouteName . UPDATE _IDENTITY ,
params : { identityName : this . identity . preferredUsername } ,
text : this . identity . name ,
} ) ;
} else {
links . push ( {
name : RouteName . CREATE _IDENTITY ,
params : { } ,
text : this . $t ( "New profile" ) as string ,
} ) ;
}
return links ;
}
2019-06-17 17:15:27 +02:00
}
< / script >