From 32ae34a37a42e91d47358b9a0e601b423f042d99 Mon Sep 17 00:00:00 2001 From: Fang Date: Fri, 13 Mar 2020 18:14:57 +0100 Subject: [PATCH] chat fe: support groupify operation --- pkg/interface/chat/src/js/api.js | 5 ++ pkg/interface/chat/src/js/components/root.js | 6 +++ .../chat/src/js/components/settings.js | 50 +++++++++++++++++-- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/pkg/interface/chat/src/js/api.js b/pkg/interface/chat/src/js/api.js index 97bff6a260..ab93771974 100644 --- a/pkg/interface/chat/src/js/api.js +++ b/pkg/interface/chat/src/js/api.js @@ -24,6 +24,7 @@ class UrbitApi { create: this.chatViewCreate.bind(this), delete: this.chatViewDelete.bind(this), join: this.chatViewJoin.bind(this), + groupify: this.chatViewGroupify.bind(this) }; this.chatHook = { @@ -174,6 +175,10 @@ class UrbitApi { }); } + chatViewGroupify(path) { + return this.chatViewAction({ groupify: { 'app-path': path } }); + } + inviteAction(data) { this.action("invite-store", "json", data); } diff --git a/pkg/interface/chat/src/js/components/root.js b/pkg/interface/chat/src/js/components/root.js index dda1af05ae..2c6e9794d6 100644 --- a/pkg/interface/chat/src/js/components/root.js +++ b/pkg/interface/chat/src/js/components/root.js @@ -259,6 +259,11 @@ export class Root extends Component { let popout = props.match.url.includes("/popout/"); + let permission = state.permissions[station] || { + kind: "", + who: new Set([]) + }; + let association = station in associations["chat"] ? associations.chat[station] : {}; @@ -274,6 +279,7 @@ export class Root extends Component { {...props} station={station} association={association} + permission={permission} api={api} station={station} group={group} diff --git a/pkg/interface/chat/src/js/components/settings.js b/pkg/interface/chat/src/js/components/settings.js index 2d8b73a0a7..c7759c2f3f 100644 --- a/pkg/interface/chat/src/js/components/settings.js +++ b/pkg/interface/chat/src/js/components/settings.js @@ -76,7 +76,22 @@ export class SettingsScreen extends Component { props.api.setSpinner(true); this.setState({ - isLoading: true + isLoading: true, + loadingText: (deSig(props.match.params.ship) === window.ship) + ? 'Deleting...' + : 'Leaving...' + }); + } + + groupifyChat() { + const { props, state } = this; + + props.api.chatView.groupify(props.station); + props.api.setSpinner(true); + + this.setState({ + isLoading: true, + loadingText: 'Converting...' }); } @@ -106,6 +121,33 @@ export class SettingsScreen extends Component { ); } + renderGroupify() { + const { props, state } = this; + + const chatOwner = (deSig(props.match.params.ship) === window.ship); + console.log(chatOwner, props.match.params.ship, window.ship); + + const ownedUnmanagedVillage = + chatOwner && + props.station.slice(0, 3) === '/~/' && + props.permission.kind === 'white'; + + if (!ownedUnmanagedVillage) { + return null; + } else { + return ( +
+
+

Convert Chat

+

Convert this chat into a group + associated chat.

+ Convert to group +
+
+ ); + } + } + renderMetadataSettings() { const { props, state } = this; @@ -210,10 +252,7 @@ export class SettingsScreen extends Component { let writeGroup = Array.from(props.group.values()); if (!!state.isLoading) { - let text = "Deleting..."; - if (deSig(props.match.params.ship) !== window.ship) { - text = "Leaving..."; - } + let text = state.loadingText || 'Working...'; let title = props.station.substr(1); @@ -321,6 +360,7 @@ export class SettingsScreen extends Component { + {this.renderGroupify()} {this.renderDelete()} {this.renderMetadataSettings()}