Skip to content

Commit

Permalink
AwayStatusIndicator is now a functional component.
Browse files Browse the repository at this point in the history
  • Loading branch information
tralves committed Feb 15, 2021
1 parent 82cb102 commit a6711ce
Showing 1 changed file with 34 additions and 31 deletions.
65 changes: 34 additions & 31 deletions src/components/AwayStatusIndicator.vue
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
<template>
<label
v-if="shouldShowStatus"
:class="{ away: user && user.away }"
class="awaystatusindicator"
@tap="toggleSelfAway()"
/>
</template>

<script>
'kiwi public';
export default {
functional: true,
props: ['network', 'user', 'toggle'],
computed: {
isUserSelf() {
if (this.toggle === false) {
return false;
}
let user = this.$state.getUser(this.network.id, this.network.nick);
return this.user === user;
},
shouldShowStatus() {
if (!this.network || this.network.state !== 'connected' || !this.user) {
return false;
}
render(createElement, context) {
const network = context.props.network;
const user = context.props.user;
if (!network || network.state !== 'connected' || !user) {
return null;
}
let awayNotifyEnabled = this.network.ircClient.network.cap.isEnabled('away-notify');
return this.$state.setting('buffers.who_loop') || awayNotifyEnabled;
},
},
methods: {
toggleSelfAway() {
if (this.isUserSelf) {
let val = this.user.away;
this.network.ircClient.raw('AWAY', val ? '' : 'Currently away');
let awayNotifyEnabled = network.ircClient.network.cap.isEnabled('away-notify');
if (!(network.appState.setting('buffers.who_loop') || awayNotifyEnabled)) {
return null;
}
const listners = {};
const toggleable = context.props.toggle &&
network.appState.getUser(network.id, network.nick) === user;
if (toggleable) {
listners.tap = () => {
network.ircClient.raw('AWAY', user.away ? '' : 'Currently away');
}
},
}
return createElement('label', {
staticClass: context.data.staticClass,
directives: context.data.directives,
class: {
'away': user.away,
'awaystatusindicator': true,
...context.data.class
},
attrs: {
...context.data.attrs,
},
on: listners,
});
}
};
</script>
Expand Down

0 comments on commit a6711ce

Please sign in to comment.