Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

feat: use ayuskey.js #218

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"autosize": "5.0.1",
"autwh": "0.1.0",
"aws-sdk": "2.1225.0",
"ayuskey.js": "1.0.0-rc.8",
"bcryptjs": "2.4.3",
"blurhash": "2.0.2",
"bootstrap": "4.6.2",
Expand Down
15 changes: 7 additions & 8 deletions src/client/app/account.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { reactive } from 'vue';
import * as ayuskey from 'ayuskey.js';
import { apiUrl } from './config';
//import { waiting } from './os';
import { unisonReload } from './common/scripts/unison-reload';

// TODO: 他のタブと永続化されたstateを同期

type Account = {
id: string;
token: string;
isModerator: boolean;
isAdmin: boolean;
isDeleted: boolean;
};
type Account = ayuskey.entities.MeDetailed;

const data = localStorage.getItem('account');

Expand All @@ -25,7 +20,11 @@ const vuex = localStorage.getItem('vuex');
if (vuex) {
tmp = JSON.parse(vuex);
}
export const $i = tmp.i;
export const $i = tmp ? reactive(tmp.i as Account) : null;

export const iAmModerator = $i != null && ($i.isAdmin || $i.isModerator);
export const iAmAdmin = $i != null && $i.isAdmin;

//#endregion

export function signout() {
Expand Down
3 changes: 2 additions & 1 deletion src/client/app/admin/views/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import XApLog from './dashboard.ap-log.vue';
import { faDatabase } from '@fortawesome/free-solid-svg-icons';
import MarqueeText from 'vue-marquee-text-component';
import randomColor from 'randomcolor';
import { stream } from '../../stream';

export default Vue.extend({
i18n: i18n('admin/views/dashboard.vue'),
Expand All @@ -120,7 +121,7 @@ export default Vue.extend({
},

created() {
this.connection = this.$root.stream.useSharedConnection('serverStats');
this.connection = stream.useChannel('serverStats');

this.updateStats();

Expand Down
3 changes: 2 additions & 1 deletion src/client/app/admin/views/queue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { faTasks, faInbox, faDatabase, faCloud } from '@fortawesome/free-solid-s
import { faPaperPlane, faChartBar } from '@fortawesome/free-regular-svg-icons';
import i18n from '../../i18n';
import XChart from './queue.chart.vue';
import { stream } from '../../stream';

export default Vue.extend({
i18n: i18n('admin/views/queue.vue'),
Expand Down Expand Up @@ -107,7 +108,7 @@ export default Vue.extend({
mounted() {
this.fetchJobs();

this.connection = this.$root.stream.useSharedConnection('queueStats');
this.connection = stream.useChannel('queueStats');
this.connection.send('requestLog', {
id: Math.random().toString().substr(2, 8),
length: this.chartLimit,
Expand Down
3 changes: 2 additions & 1 deletion src/client/app/common/views/components/follow-button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<script lang="ts">
import Vue from 'vue';
import i18n from '../../../i18n';
import { stream } from '../../../stream';

export default Vue.extend({
i18n: i18n('common/views/components/follow-button.vue'),
Expand Down Expand Up @@ -70,7 +71,7 @@ export default Vue.extend({
},

mounted() {
this.connection = this.$root.stream.useSharedConnection('main');
this.connection = stream.useChannel('main');

this.connection.on('follow', this.onFollowChange);
this.connection.on('unfollow', this.onFollowChange);
Expand Down
3 changes: 2 additions & 1 deletion src/client/app/common/views/components/messaging-room.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import XForm from './messaging-room.form.vue';
import * as sound from '../../../common/scripts/sound';
import { url } from '../../../config';
import { faArrowCircleDown, faFlag } from '@fortawesome/free-solid-svg-icons';
import { stream } from '../../../stream';

export default Vue.extend({
i18n: i18n('common/views/components/messaging-room.vue'),
Expand Down Expand Up @@ -90,7 +91,7 @@ export default Vue.extend({
},

mounted() {
this.connection = this.$root.stream.connectToChannel('messaging', {
this.connection = stream.useChannel('messaging', {
otherparty: this.user ? this.user.id : undefined,
group: this.group ? this.group.id : undefined,
});
Expand Down
3 changes: 2 additions & 1 deletion src/client/app/common/views/components/settings/signins.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<script lang="ts">
import Vue from 'vue';
import { stream } from '../../../../stream';
export default Vue.extend({
data() {
return {
Expand All @@ -33,7 +34,7 @@ export default Vue.extend({
this.fetching = false;
});

this.connection = this.$root.stream.useSharedConnection('main');
this.connection = stream.useChannel('main');

this.connection.on('signin', this.onSignin);
},
Expand Down
11 changes: 6 additions & 5 deletions src/client/app/common/views/components/stream-indicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import i18n from '../../../i18n';
import anime from 'animejs';
import checkForUpdate from '../../scripts/check-for-update';
import { env } from '../../../config';
import { stream } from '../../../stream';

export default Vue.extend({
i18n: i18n('common/views/components/stream-indicator.vue'),
Expand All @@ -49,12 +50,12 @@ export default Vue.extend({
},
computed: {
stream() {
return this.$root.stream;
return stream;
},
},
created() {
this.$root.stream.on('_connected_', this.onConnected);
this.$root.stream.on('_disconnected_', this.onDisconnected);
stream.on('_connected_', this.onConnected);
stream.on('_disconnected_', this.onDisconnected);

this.$nextTick(() => {
if (this.stream.state == 'connected') {
Expand All @@ -63,8 +64,8 @@ export default Vue.extend({
});
},
beforeDestroy() {
this.$root.stream.off('_connected_', this.onConnected);
this.$root.stream.off('_disconnected_', this.onDisconnected);
stream.off('_connected_', this.onConnected);
stream.off('_disconnected_', this.onDisconnected);
},
methods: {
onConnected() {
Expand Down
3 changes: 2 additions & 1 deletion src/client/app/common/views/components/welcome-timeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

<script lang="ts">
import Vue from 'vue';
import { stream } from '../../../stream';

export default Vue.extend({
props: {
Expand All @@ -52,7 +53,7 @@ export default Vue.extend({
mounted() {
this.fetch();

this.connection = this.$root.stream.useSharedConnection('localTimeline');
this.connection = stream.useChannel('localTimeline');

this.connection.on('note', this.onNote);
},
Expand Down
3 changes: 2 additions & 1 deletion src/client/app/common/views/deck/deck.direct-column.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<script lang="ts">
import Vue from 'vue';
import i18n from '../../../i18n';
import { stream } from '../../../stream';
import XColumn from './deck.column.vue';
import XNotes from './deck.notes.vue';

Expand Down Expand Up @@ -60,7 +61,7 @@ export default Vue.extend({
},

mounted() {
this.connection = this.$root.stream.useSharedConnection('main');
this.connection = stream.useChannel('main');
this.connection.on('mention', this.onNote);
},

Expand Down
3 changes: 2 additions & 1 deletion src/client/app/common/views/deck/deck.mentions-column.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<script lang="ts">
import Vue from 'vue';
import i18n from '../../../i18n';
import { stream } from '../../../stream';
import XColumn from './deck.column.vue';
import XNotes from './deck.notes.vue';

Expand Down Expand Up @@ -60,7 +61,7 @@ export default Vue.extend({
},

mounted() {
this.connection = this.$root.stream.useSharedConnection('main');
this.connection = stream.useChannel('main');
this.connection.on('mention', this.onNote);
},

Expand Down
5 changes: 3 additions & 2 deletions src/client/app/common/views/deck/deck.notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import * as sound from '../../scripts/sound';
import XNotification from './deck.notification.vue';
import paging from '../../../common/scripts/paging';
import * as config from '../../../config';
import { stream } from '../../../stream';

const displayLimit = 20;

Expand Down Expand Up @@ -90,7 +91,7 @@ export default Vue.extend({
},

mounted() {
this.connection = this.$root.stream.useSharedConnection('main');
this.connection = stream.useChannel('main');
this.connection.on('notification', this.onNotification);

this.column.$on('top', this.onTop);
Expand All @@ -107,7 +108,7 @@ export default Vue.extend({
methods: {
onNotification(notification) {
// TODO: ユーザーが画面を見てないと思われるとき(ブラウザやタブがアクティブじゃないなど)は送信しない
this.$root.stream.send('readNotification', {
stream.send('readNotification', {
id: notification.id,
});

Expand Down
9 changes: 5 additions & 4 deletions src/client/app/common/views/deck/deck.tl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Vue from 'vue';
import XNotes from './deck.notes.vue';
import { faMinusCircle } from '@fortawesome/free-solid-svg-icons';
import i18n from '../../../i18n';
import { stream } from '../../../stream';

export default Vue.extend({
i18n: i18n('deck'),
Expand Down Expand Up @@ -47,10 +48,10 @@ export default Vue.extend({
computed: {
stream(): any {
switch (this.src) {
case 'home': return this.$root.stream.useSharedConnection('homeTimeline');
case 'local': return this.$root.stream.useSharedConnection('localTimeline');
case 'hybrid': return this.$root.stream.useSharedConnection('hybridTimeline');
case 'global': return this.$root.stream.useSharedConnection('globalTimeline');
case 'home': return stream.useChannel('homeTimeline');
case 'local': return stream.useChannel('localTimeline');
case 'hybrid': return stream.useChannel('hybridTimeline');
case 'global': return stream.useChannel('globalTimeline');
}
},

Expand Down
3 changes: 2 additions & 1 deletion src/client/app/common/views/widgets/photo-stream.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<script lang="ts">
import define from '../../../common/define-widget';
import i18n from '../../../i18n';
import { stream } from '../../../stream';
import { getStaticImageUrl } from '../../scripts/get-static-image-url';

export default define({
Expand All @@ -40,7 +41,7 @@ export default define({
},

mounted() {
this.connection = this.$root.stream.useSharedConnection('main');
this.connection = stream.useChannel('main');

this.connection.on('driveFileCreated', this.onDriveFileCreated);

Expand Down
3 changes: 2 additions & 1 deletion src/client/app/common/views/widgets/server.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import XMemory from './server.memory.vue';
import XDisk from './server.disk.vue';
import XUptimes from './server.uptimes.vue';
import XInfo from './server.info.vue';
import { stream } from '../../../stream';

export default define({
name: 'server',
Expand Down Expand Up @@ -57,7 +58,7 @@ export default define({
this.fetching = false;
});

this.connection = this.$root.stream.useSharedConnection('serverStats');
this.connection = stream.useChannel('serverStats');
},
beforeDestroy() {
this.connection.dispose();
Expand Down
5 changes: 3 additions & 2 deletions src/client/app/desktop/views/components/notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ import i18n from '../../../i18n';
import * as sound from '../../../common/scripts/sound';
import getNoteSummary from '../../../../../misc/get-note-summary';
import paging from '../../../common/scripts/paging';
import { stream } from '../../../stream';

export default Vue.extend({
i18n: i18n('desktop/views/components/notifications.vue'),
Expand Down Expand Up @@ -211,7 +212,7 @@ export default Vue.extend({
},

mounted() {
this.connection = this.$root.stream.useSharedConnection('main');
this.connection = stream.useChannel('main');
this.connection.on('notification', this.onNotification);
},

Expand All @@ -222,7 +223,7 @@ export default Vue.extend({
methods: {
onNotification(notification) {
// TODO: ユーザーが画面を見てないと思われるとき(ブラウザやタブがアクティブじゃないなど)は送信しない
this.$root.stream.send('readNotification', {
stream.send('readNotification', {
id: notification.id,
});

Expand Down
3 changes: 2 additions & 1 deletion src/client/app/desktop/views/components/ui.header.nav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Vue from 'vue';
import i18n from '../../../i18n';
import MkGameWindow from './game-window.vue';
import { faNewspaper, faHashtag } from '@fortawesome/free-solid-svg-icons';
import { stream } from '../../../stream';

export default Vue.extend({
i18n: i18n('desktop/views/components/ui.header.nav.vue'),
Expand All @@ -38,7 +39,7 @@ export default Vue.extend({
},
mounted() {
if (this.$store.getters.isSignedIn) {
this.connection = this.$root.stream.useSharedConnection('main');
this.connection = stream.useChannel('main');

this.connection.on('reversiInvited', this.onReversiInvited);
this.connection.on('reversiNoInvites', this.onReversiNoInvites);
Expand Down
3 changes: 2 additions & 1 deletion src/client/app/desktop/views/components/ui.sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import MkMessagingWindow from './messaging-window.vue';
import MkGameWindow from './game-window.vue';
import contains from '../../../common/scripts/contains';
import { faNewspaper, faHashtag } from '@fortawesome/free-solid-svg-icons';
import { stream } from '../../../stream';

export default Vue.extend({
i18n: i18n('desktop/views/components/ui.sidebar.vue'),
Expand All @@ -105,7 +106,7 @@ export default Vue.extend({

mounted() {
if (this.$store.getters.isSignedIn) {
this.connection = this.$root.stream.useSharedConnection('main');
this.connection = stream.useChannel('main');

this.connection.on('reversiInvited', this.onReversiInvited);
this.connection.on('reversiNoInvites', this.onReversiNoInvites);
Expand Down
3 changes: 2 additions & 1 deletion src/client/app/desktop/views/home/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import i18n from '../../../i18n';
import XDraggable from 'vuedraggable';
import { v4 as uuid } from 'uuid';
import XWelcome from '../pages/welcome.vue';
import { stream } from '../../../stream';

export default Vue.extend({
i18n: i18n('desktop/views/components/home.vue'),
Expand Down Expand Up @@ -194,7 +195,7 @@ export default Vue.extend({
},

mounted() {
this.connection = this.$root.stream.useSharedConnection('main');
this.connection = stream.useChannel('main');
},

beforeDestroy() {
Expand Down
Loading