feat: unify group mention defaults
This commit is contained in:
@@ -58,6 +58,14 @@ export function applyConfigSnapshot(state: ConfigState, snapshot: ConfigSnapshot
|
||||
.filter((v) => v.length > 0)
|
||||
.join(", ")
|
||||
: "";
|
||||
const telegramGroups =
|
||||
telegram.groups && typeof telegram.groups === "object"
|
||||
? (telegram.groups as Record<string, unknown>)
|
||||
: {};
|
||||
const telegramDefaultGroup =
|
||||
telegramGroups["*"] && typeof telegramGroups["*"] === "object"
|
||||
? (telegramGroups["*"] as Record<string, unknown>)
|
||||
: {};
|
||||
const allowFrom = Array.isArray(telegram.allowFrom)
|
||||
? toList(telegram.allowFrom)
|
||||
: typeof telegram.allowFrom === "string"
|
||||
@@ -67,7 +75,9 @@ export function applyConfigSnapshot(state: ConfigState, snapshot: ConfigSnapshot
|
||||
state.telegramForm = {
|
||||
token: typeof telegram.botToken === "string" ? telegram.botToken : "",
|
||||
requireMention:
|
||||
typeof telegram.requireMention === "boolean" ? telegram.requireMention : true,
|
||||
typeof telegramDefaultGroup.requireMention === "boolean"
|
||||
? telegramDefaultGroup.requireMention
|
||||
: true,
|
||||
allowFrom,
|
||||
proxy: typeof telegram.proxy === "string" ? telegram.proxy : "",
|
||||
webhookUrl: typeof telegram.webhookUrl === "string" ? telegram.webhookUrl : "",
|
||||
|
||||
@@ -147,7 +147,24 @@ export async function saveTelegramConfig(state: ConnectionsState) {
|
||||
if (token) telegram.botToken = token;
|
||||
else delete telegram.botToken;
|
||||
}
|
||||
telegram.requireMention = state.telegramForm.requireMention;
|
||||
const groups =
|
||||
telegram.groups && typeof telegram.groups === "object"
|
||||
? ({ ...(telegram.groups as Record<string, unknown>) } as Record<
|
||||
string,
|
||||
unknown
|
||||
>)
|
||||
: {};
|
||||
const defaultGroup =
|
||||
groups["*"] && typeof groups["*"] === "object"
|
||||
? ({ ...(groups["*"] as Record<string, unknown>) } as Record<
|
||||
string,
|
||||
unknown
|
||||
>)
|
||||
: {};
|
||||
defaultGroup.requireMention = state.telegramForm.requireMention;
|
||||
groups["*"] = defaultGroup;
|
||||
telegram.groups = groups;
|
||||
delete telegram.requireMention;
|
||||
const allowFrom = parseList(state.telegramForm.allowFrom);
|
||||
if (allowFrom.length > 0) telegram.allowFrom = allowFrom;
|
||||
else delete telegram.allowFrom;
|
||||
|
||||
@@ -298,7 +298,7 @@ function renderProvider(
|
||||
/>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Require mention</span>
|
||||
<span>Require mention in groups</span>
|
||||
<select
|
||||
.value=${props.telegramForm.requireMention ? "yes" : "no"}
|
||||
@change=${(e: Event) =>
|
||||
|
||||
Reference in New Issue
Block a user