Skip to content

Commit

Permalink
Prefix channel rules to community rules
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan committed Sep 19, 2023
1 parent 1dc6734 commit 0b09a9c
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 52 deletions.
10 changes: 1 addition & 9 deletions frontend/app/src/components/home/AcceptRulesModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@
const dispatch = createEventDispatcher();
const client = getContext<OpenChat>("client");
// Deliberately not reactive statements so that the rules don't change while the user is reading them
let currentChatRules = client.currentChatRules;
let currentCommunityRules = client.currentCommunityRules;
let chatRulesEnabled = $currentChatRules?.enabled ?? false;
let communityRulesEnabled = $currentCommunityRules?.enabled ?? false;
function buildConfirmMessage(): string {
const chatRulesText = chatRulesEnabled ? $currentChatRules?.text : "";
const comunityRulesText = communityRulesEnabled ? $currentCommunityRules?.text : "";
let lineBreak = chatRulesEnabled && communityRulesEnabled ? "\n\n" : "";
return comunityRulesText + lineBreak + chatRulesText;
}
function onAction(accepted: boolean): Promise<void> {
let chatRulesVersion = undefined;
let communityRulesVersion = undefined;
Expand All @@ -43,7 +35,7 @@

<AreYouSure
title={$_("rules.acceptTitle")}
message={buildConfirmMessage()}
message={client.combineRulesText($currentChatRules, $currentCommunityRules)}
yesLabel={$_("rules.accept")}
noLabel={$_("rules.reject")}
action={onAction} />
2 changes: 0 additions & 2 deletions frontend/app/src/components/home/RightPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
$: currentChatMembers = client.currentChatMembers;
$: currentChatInvited = client.currentChatInvitedUsers;
$: currentChatBlocked = client.currentChatBlockedUsers;
$: currentChatRules = client.currentChatRules;
$: currentChatPinnedMessages = client.currentChatPinnedMessages;
$: currentCommunityMembers = client.currentCommunityMembers;
$: currentCommunityInvited = client.currentCommunityInvitedUsers;
Expand Down Expand Up @@ -348,7 +347,6 @@
<GroupDetails
chat={$multiUserChat}
memberCount={$currentChatMembers.length}
rules={$currentChatRules}
on:close={popRightPanelHistory}
on:deleteGroup
on:editGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
$: isValid = !rules.enabled || (rules.text.length > 0 && rules.text.length <= MAX_RULES_LENGTH);
$: rulesDirty = rules.text !== originalRules.text || rules.enabled !== originalRules.enabled;
function buildRulesExplanation(level: Level): string | undefined {
switch (level) {
case "community":
return $_("rules.communityRulesExplanation");
case "channel":
return $_("rules.channelRulesExplanation");
case "group":
return undefined;
}
}
function toggleRules() {
rules.enabled = !rules.enabled;
}
Expand All @@ -41,7 +52,9 @@
checked={rules.enabled} />
<div class="instructions">{interpolateLevel("rules.instructions", level, true)}</div>

<Legend label={interpolateLevel("rules.rules", level)} />
<Legend
label={interpolateLevel("rules.levelRules", level)}
rules={buildRulesExplanation(level)} />
<TextArea
bind:value={rules.text}
minlength={0}
Expand Down
6 changes: 3 additions & 3 deletions frontend/app/src/components/home/addgroup/NewGroup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import Button from "../../Button.svelte";
import { menuCloser } from "../../../actions/closeMenu";
import GroupDetails from "./GroupDetails.svelte";
import Rules from "../Rules.svelte";
import RulesEditor from "../RulesEditor.svelte";
import GroupPermissionsEditor from "../GroupPermissionsEditor.svelte";
import GroupPermissionsViewer from "../GroupPermissionsViewer.svelte";
import { toastStore } from "../../../stores/toast";
Expand Down Expand Up @@ -76,7 +76,7 @@
let steps = [
{ labelKey: "group.details", valid: detailsValid },
{ labelKey: "access.visibility", valid: true },
{ labelKey: interpolateLevel("rules.rules", candidateGroup.level), valid: true },
{ labelKey: $_("rules.rules"), valid: true },
{ labelKey: "permissions.permissions", valid: true },
];
Expand Down Expand Up @@ -406,7 +406,7 @@
bind:candidate={candidateGroup} />
</div>
<div class="rules" class:visible={step === 2}>
<Rules
<RulesEditor
bind:valid={rulesValid}
level={candidateGroup.level}
bind:rules={candidateGroup.rules}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<CollapsibleCard
on:toggle={communityRulesOpen.toggle}
open={$communityRulesOpen}
headerText={interpolateLevel("rules.rules", community.level)}>
headerText={interpolateLevel("rules.levelRules", community.level)}>
<Markdown inline={false} text={rules.text} />
</CollapsibleCard>
{/if}
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/communities/edit/Edit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import StageHeader from "../../StageHeader.svelte";
import PermissionsEditor from "./PermissionsEditor.svelte";
import PermissionsViewer from "../PermissionsViewer.svelte";
import RulesEditor from "../../Rules.svelte";
import RulesEditor from "../../RulesEditor.svelte";
import Details from "./Details.svelte";
import { createCandidateCommunity } from "../../../../stores/community";
import VisibilityControl from "../../VisibilityControl.svelte";
Expand Down Expand Up @@ -217,7 +217,7 @@
bind:valid={rulesValid}
level={candidate.level}
bind:rules={candidateRules}
editing />
{editing} />
</div>
<div use:menuCloser class="permissions" class:visible={step === 3}>
{#if canEditPermissions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
} from "../../../stores/settings";
import AdvancedSection from "./AdvancedSection.svelte";
import InviteUsersWithLink from "../InviteUsersWithLink.svelte";
import type { OpenChat, Rules, MultiUserChat } from "openchat-client";
import type { OpenChat, MultiUserChat } from "openchat-client";
import { AvatarSize } from "openchat-client";
import AccessGateSummary from "../AccessGateSummary.svelte";
import { interpolateLevel } from "../../../utils/i18n";
Expand All @@ -31,7 +31,10 @@
export let chat: MultiUserChat;
export let memberCount: number;
export let rules: Rules | undefined;
$: currentChatRules = client.currentChatRules;
$: currentCommunityRules = client.currentCommunityRules;
$: combinedRulesText = client.combineRulesText($currentChatRules, $currentCommunityRules);
// capture a snapshot of the chat as it is right now
$: canEdit = client.canEditGroupDetails(chat.id);
Expand All @@ -40,7 +43,7 @@
function editGroup() {
if (canEdit) {
dispatch("editGroup", { chat, rules: { ...rules, newVersion: false } });
dispatch("editGroup", { chat, rules: { ...$currentChatRules, newVersion: false } });
}
}
Expand Down Expand Up @@ -121,12 +124,12 @@
</div>
<AccessGateSummary gate={chat.gate} />
</CollapsibleCard>
{#if rules !== undefined && rules.enabled}
{#if combinedRulesText.length > 0}
<CollapsibleCard
on:toggle={groupRulesOpen.toggle}
open={$groupRulesOpen}
headerText={interpolateLevel("rules.rules", chat.level)}>
<Markdown inline={false} text={rules.text} />
headerText={$_("rules.rules")}>
<Markdown inline={false} text={combinedRulesText} />
</CollapsibleCard>
{/if}
{#if canInvite}
Expand Down
7 changes: 5 additions & 2 deletions frontend/app/src/i18n/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,15 @@
"enable": "启用群规",
"accept": "接受",
"reject": "拒绝",
"rules": "{level} 规则",
"rules": "规则",
"placeholder": "{level}规则是什么?",
"instructions": "如果启用,新成员必须同意规则才能发送消息。",
"acceptTitle": "聊天规则",
"promptExistingUsers": "提示现有会员",
"promptExistingUsersInstructions": "现有会员必须同意新规则才能发送消息。"
"promptExistingUsersInstructions": "现有会员必须同意新规则才能发送消息。",
"levelRules": "{level} 规则",
"communityRulesExplanation": "任何频道规则都将作为这些规则的前缀",
"channelRulesExplanation": "这些将作为任何社区规则的前缀"
},
"group": {
"publicGroup": "公开{level}",
Expand Down
7 changes: 5 additions & 2 deletions frontend/app/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,15 @@
"enable": "Regeln aktivieren",
"accept": "Annehmen",
"reject": "Ablehnen",
"rules": "{level}-Regeln",
"rules": "Regeln",
"placeholder": "Was sind die {level}-Regeln?",
"instructions": "Wenn diese Option aktiviert ist, müssen neue Mitglieder den Regeln zustimmen, bevor sie Nachrichten senden können.",
"acceptTitle": "Chat-Regeln",
"promptExistingUsers": "Fordern Sie bestehende Mitglieder auf",
"promptExistingUsersInstructions": "Bestehende Mitglieder müssen den neuen Regeln zustimmen, bevor sie Nachrichten senden können."
"promptExistingUsersInstructions": "Bestehende Mitglieder müssen den neuen Regeln zustimmen, bevor sie Nachrichten senden können.",
"levelRules": "{level}-Regeln",
"communityRulesExplanation": "Alle Kanalregeln werden diesen Regeln vorangestellt",
"channelRulesExplanation": "Diese werden allen Community-Regeln vorangestellt"
},
"group": {
"publicGroup": "Öffentlich {level}",
Expand Down
5 changes: 4 additions & 1 deletion frontend/app/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,10 @@
"invite": "Invite"
},
"rules": {
"rules": "{level} rules",
"rules": "Rules",
"levelRules": "{level} rules",
"communityRulesExplanation": "any channel rules will be prefixed to these rules",
"channelRulesExplanation": "these will be prefixed to any community rules",
"enable": "Enable rules",
"placeholder": "what are the {level} rules?",
"instructions": "If enabled, new members must agree to the rules before they can send messages.",
Expand Down
7 changes: 5 additions & 2 deletions frontend/app/src/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,15 @@
"enable": "Habilitar reglas",
"accept": "Aceptar",
"reject": "Rechazar",
"rules": "{level} reglas",
"rules": "Normas",
"placeholder": "¿Cuáles son las reglas {level}?",
"instructions": "Si está habilitado, los nuevos miembros deben aceptar las reglas antes de poder enviar mensajes.",
"acceptTitle": "reglas de chat",
"promptExistingUsers": "Solicitar a los miembros existentes",
"promptExistingUsersInstructions": "Los miembros existentes deben aceptar las nuevas reglas antes de poder enviar mensajes."
"promptExistingUsersInstructions": "Los miembros existentes deben aceptar las nuevas reglas antes de poder enviar mensajes.",
"levelRules": "{level} reglas",
"communityRulesExplanation": "Cualquier regla del canal tendrá como prefijo estas reglas.",
"channelRulesExplanation": "Estos tendrán el prefijo de cualquier regla comunitaria."
},
"group": {
"publicGroup": "Público {level}",
Expand Down
7 changes: 5 additions & 2 deletions frontend/app/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,15 @@
"enable": "Activer les règles",
"accept": "Accepter",
"reject": "Rejeter",
"rules": "{level} règles",
"rules": "Règles",
"placeholder": "quelles sont les règles {level} ?",
"instructions": "Si cette option est activée, les nouveaux membres doivent accepter les règles avant de pouvoir envoyer des messages.",
"acceptTitle": "Règles de discussion",
"promptExistingUsers": "Inviter les membres existants",
"promptExistingUsersInstructions": "Les membres existants doivent accepter les nouvelles règles avant de pouvoir envoyer des messages."
"promptExistingUsersInstructions": "Les membres existants doivent accepter les nouvelles règles avant de pouvoir envoyer des messages.",
"levelRules": "Règles {level}",
"communityRulesExplanation": "toutes les règles de chaîne seront préfixées à ces règles",
"channelRulesExplanation": "ceux-ci seront préfixés à toutes les règles de la communauté"
},
"group": {
"publicGroup": "Publique {level}",
Expand Down
7 changes: 5 additions & 2 deletions frontend/app/src/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,15 @@
"enable": "Abilita regole",
"accept": "Accettare",
"reject": "Rifiutare",
"rules": "{level} regole",
"rules": "Regole",
"placeholder": "quali sono le regole {level}?",
"instructions": "Se abilitato, i nuovi membri devono accettare le regole prima di poter inviare messaggi.",
"acceptTitle": "Regole della chat",
"promptExistingUsers": "Chiedi ai membri esistenti",
"promptExistingUsersInstructions": "I membri esistenti devono accettare le nuove regole prima di poter inviare messaggi."
"promptExistingUsersInstructions": "I membri esistenti devono accettare le nuove regole prima di poter inviare messaggi.",
"levelRules": "{level} regole",
"communityRulesExplanation": "qualsiasi regola del canale verrà preceduta da queste regole",
"channelRulesExplanation": "questi saranno preceduti da eventuali regole comunitarie"
},
"group": {
"publicGroup": "Pubblico {level}",
Expand Down
7 changes: 5 additions & 2 deletions frontend/app/src/i18n/iw.json
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,15 @@
"enable": "אפשר כללים",
"accept": "לְקַבֵּל",
"reject": "לִדחוֹת",
"rules": "{level} חוקים",
"rules": "כללים",
"placeholder": "מה הם הכללים של {level}?",
"instructions": "אם מופעל, חברים חדשים חייבים להסכים לכללים לפני שהם יכולים לשלוח הודעות.",
"acceptTitle": "כללי צ'אט",
"promptExistingUsers": "בקש לחברים קיימים",
"promptExistingUsersInstructions": "חברים קיימים חייבים להסכים לכללים החדשים לפני שהם יכולים לשלוח הודעות."
"promptExistingUsersInstructions": "חברים קיימים חייבים להסכים לכללים החדשים לפני שהם יכולים לשלוח הודעות.",
"levelRules": "{level} חוקים",
"communityRulesExplanation": "כל כללי ערוץ יקדמו לכללים אלה",
"channelRulesExplanation": "אלה יהיו קידומת לכל חוקי הקהילה"
},
"group": {
"publicGroup": "ציבורי {level}",
Expand Down
7 changes: 5 additions & 2 deletions frontend/app/src/i18n/jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,15 @@
"enable": "ルールを有効にする",
"accept": "承認",
"reject": "拒否",
"rules": "{level} ルール",
"rules": "ルール",
"placeholder": "{level} ルールとは何ですか?",
"instructions": "有効にすると、新しいメンバーはメッセージを送信する前にルールに同意する必要があります。",
"acceptTitle": "チャットのルール",
"promptExistingUsers": "既存のメンバーにプロンプトを表示する",
"promptExistingUsersInstructions": "既存のメンバーは、メッセージを送信する前に新しいルールに同意する必要があります。"
"promptExistingUsersInstructions": "既存のメンバーは、メッセージを送信する前に新しいルールに同意する必要があります。",
"levelRules": "{level} ルール",
"communityRulesExplanation": "チャネル ルールはこれらのルールの前に付けられます。",
"channelRulesExplanation": "これらはコミュニティ ルールの先頭に付けられます"
},
"group": {
"publicGroup": "パブリック {level}",
Expand Down
7 changes: 5 additions & 2 deletions frontend/app/src/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,15 @@
"enable": "Включить правила",
"accept": "Принимать",
"reject": "Отклонять",
"rules": "{level} правила",
"rules": "Правила",
"placeholder": "каковы правила {level}?",
"instructions": "Если эта опция включена, новые участники должны согласиться с правилами, прежде чем они смогут отправлять сообщения.",
"acceptTitle": "Правила чата",
"promptExistingUsers": "Подскажите существующим участникам",
"promptExistingUsersInstructions": "Существующие участники должны согласиться с новыми правилами, прежде чем они смогут отправлять сообщения."
"promptExistingUsersInstructions": "Существующие участники должны согласиться с новыми правилами, прежде чем они смогут отправлять сообщения.",
"levelRules": "{level} правила",
"communityRulesExplanation": "любые правила канала будут предваряться этими правилами.",
"channelRulesExplanation": "они будут стоять перед любыми правилами сообщества"
},
"group": {
"publicGroup": "Общедоступный {level}",
Expand Down
7 changes: 5 additions & 2 deletions frontend/app/src/i18n/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,15 @@
"enable": "Bật quy tắc",
"accept": "Chấp nhận",
"reject": "Từ chối",
"rules": "quy tắc {level}",
"rules": "Quy tắc",
"placeholder": "các quy tắc {level} là gì?",
"instructions": "Nếu được bật, thành viên mới phải đồng ý với các quy tắc trước khi họ có thể gửi tin nhắn.",
"acceptTitle": "Quy tắc trò chuyện",
"promptExistingUsers": "Nhắc nhở các thành viên hiện có",
"promptExistingUsersInstructions": "Các thành viên hiện tại phải đồng ý với các quy định mới trước khi họ có thể gửi tin nhắn."
"promptExistingUsersInstructions": "Các thành viên hiện tại phải đồng ý với các quy định mới trước khi họ có thể gửi tin nhắn.",
"levelRules": "quy tắc {level}",
"communityRulesExplanation": "mọi quy tắc kênh sẽ được đặt trước các quy tắc này",
"channelRulesExplanation": "những điều này sẽ được đặt trước bất kỳ quy tắc cộng đồng nào"
},
"group": {
"publicGroup": "Công khai {level}",
Expand Down
10 changes: 10 additions & 0 deletions frontend/openchat-client/src/openchat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ import { isDisplayNameValid, isUsernameValid } from "./utils/validation";
import type { Member } from "openchat-shared";
import type { Level } from "openchat-shared";
import type { DraftMessage } from "./stores/draftMessageFactory";
import type { VersionedRules } from "openchat-shared";

const UPGRADE_POLL_INTERVAL = 1000;
const MARK_ONLINE_INTERVAL = 61 * 1000;
Expand Down Expand Up @@ -2929,6 +2930,15 @@ export class OpenChat extends OpenChatAgentWorker {
);
}

combineRulesText(chatRules: VersionedRules | undefined, communityRules: VersionedRules | undefined): string {
const chatRulesEnabled = chatRules?.enabled ?? false;
const communityRulesEnabled = communityRules?.enabled ?? false;
const chatRulesText = chatRulesEnabled ? chatRules?.text : "";
const communityRulesText = communityRulesEnabled ? communityRules?.text : "";
const lineBreak = chatRulesEnabled && communityRulesEnabled ? "\n" : "";
return chatRulesText + lineBreak + communityRulesText;
}

markChatRulesAcceptedLocally(rulesAccepted: boolean) {
const selectedChatId = this._liveState.selectedChatId;
if (selectedChatId !== undefined) {
Expand Down
Loading

0 comments on commit 0b09a9c

Please sign in to comment.