Fix previous commit

This commit is contained in:
Tulir Asokan 2019-08-31 12:44:32 +03:00
parent c9c8ac08a1
commit 811b5877b0
2 changed files with 22 additions and 12 deletions

View File

@ -46,8 +46,8 @@ class Client:
client: MaubotMatrixClient client: MaubotMatrixClient
started: bool started: bool
remote_displayname: str remote_displayname: Optional[str]
remote_avatar_url: ContentURI remote_avatar_url: Optional[ContentURI]
def __init__(self, db_instance: DBClient) -> None: def __init__(self, db_instance: DBClient) -> None:
self.db_instance = db_instance self.db_instance = db_instance
@ -56,6 +56,8 @@ class Client:
self.references = set() self.references = set()
self.started = False self.started = False
self.sync_ok = True self.sync_ok = True
self.remote_displayname = None
self.remote_avatar_url = None
self.client = MaubotMatrixClient(mxid=self.id, base_url=self.homeserver, self.client = MaubotMatrixClient(mxid=self.id, base_url=self.homeserver,
token=self.access_token, client_session=self.http_client, token=self.access_token, client_session=self.http_client,
log=self.log, loop=self.loop, store=self.db_instance) log=self.log, loop=self.loop, store=self.db_instance)

View File

@ -30,18 +30,24 @@ const ClientListEntry = ({ entry }) => {
} else if (!entry.started) { } else if (!entry.started) {
classes.push("stopped") classes.push("stopped")
} }
const avatarURL = entry.avatar_url && api.getAvatarURL({ const avatarMXC = entry.avatar_url === "disable"
? entry.remote_avatar_url
: entry.avatar_url
const avatarURL = avatarMXC && api.getAvatarURL({
id: entry.id, id: entry.id,
avatar_url: entry.avatar_url === "disabled" avatar_url: avatarMXC,
? entry.remote_avatar_url
: entry.avatar_url
}) })
const displayname = (
entry.displayname === "disable"
? entry.remote_displayname
: entry.displayname
) || entry.id
return ( return (
<NavLink className={classes.join(" ")} to={`/client/${entry.id}`}> <NavLink className={classes.join(" ")} to={`/client/${entry.id}`}>
{avatarURL {avatarURL
? <img className='avatar' src={avatarURL} alt=""/> ? <img className='avatar' src={avatarURL} alt=""/>
: <NoAvatarIcon className='avatar'/>} : <NoAvatarIcon className='avatar'/>}
<span className="displayname">{entry.displayname || entry.id}</span> <span className="displayname">{displayname}</span>
<ChevronRight className='chevron'/> <ChevronRight className='chevron'/>
</NavLink> </NavLink>
) )
@ -203,20 +209,22 @@ class Client extends BaseMainView {
</div> </div>
} }
get avatarMXC() {
return this.state.avatar_url === "disable" ? this.props.entry.remote_avatar_url : this.state.avatar_url
}
get avatarURL() { get avatarURL() {
return api.getAvatarURL({ return api.getAvatarURL({
id: this.state.id, id: this.state.id,
avatar_url: this.state.avatar_url === "disabled" avatar_url: this.avatarMXC,
? this.props.entry.remote_avatar_url
: this.state.avatar_url
}) })
} }
renderSidebar = () => !this.isNew && ( renderSidebar = () => !this.isNew && (
<div className="sidebar"> <div className="sidebar">
<div className={`avatar-container ${this.state.avatar_url ? "" : "no-avatar"} <div className={`avatar-container ${this.avatarMXC ? "" : "no-avatar"}
${this.state.uploadingAvatar ? "uploading" : ""}`}> ${this.state.uploadingAvatar ? "uploading" : ""}`}>
<img className="avatar" src={this.avatarURL} alt="Avatar"/> {this.avatarMXC && <img className="avatar" src={this.avatarURL} alt="Avatar"/>}
<UploadButton className="upload"/> <UploadButton className="upload"/>
<input className="file-selector" type="file" accept="image/png, image/jpeg" <input className="file-selector" type="file" accept="image/png, image/jpeg"
onChange={this.avatarUpload} disabled={this.state.uploadingAvatar} onChange={this.avatarUpload} disabled={this.state.uploadingAvatar}