Manage Channel: Ability to disable all custom usernames (#3395)
This commit is contained in:
parent
05ff8ce87a
commit
ae4b193bf8
@ -49,7 +49,7 @@ export {
|
||||
} from './symbols';
|
||||
|
||||
export {
|
||||
checkChatUsername, setChatUsername, updatePrivateLink,
|
||||
checkChatUsername, setChatUsername, updatePrivateLink, deactivateAllUsernames,
|
||||
fetchExportedChatInvites, editExportedChatInvite, exportChatInvite, deleteExportedChatInvite,
|
||||
deleteRevokedExportedChatInvites, fetchChatInviteImporters, hideChatJoinRequest, hideAllChatJoinRequests,
|
||||
hideChatReportPanel,
|
||||
|
||||
@ -3,7 +3,7 @@ import { Api as GramJs } from '../../../lib/gramjs';
|
||||
import { invokeRequest } from './client';
|
||||
import { buildInputEntity, buildInputPeer } from '../gramjsBuilders';
|
||||
import type {
|
||||
ApiChat, ApiError, ApiUser, OnApiUpdate,
|
||||
ApiChat, ApiError, ApiUser, ApiUsername, OnApiUpdate,
|
||||
} from '../../types';
|
||||
|
||||
import { USERNAME_PURCHASE_ERROR } from '../../../config';
|
||||
@ -52,12 +52,11 @@ export async function setChatUsername(
|
||||
username,
|
||||
}));
|
||||
|
||||
const usernames = chat.usernames
|
||||
? chat.usernames
|
||||
.map((u) => (u.isEditable ? { ...u, username } : u))
|
||||
// User can remove username from chat when changing it type to private, so we need to filter out empty usernames
|
||||
.filter((u) => u.username)
|
||||
: [{ username, isEditable: true, isActive: true }];
|
||||
let usernames: ApiUsername[] = username ? [{ username, isEditable: true, isActive: true }] : [];
|
||||
if (chat.usernames) {
|
||||
// User can remove username from chat when changing it type to private, so we need to filter out empty usernames
|
||||
usernames = usernames.concat(chat.usernames.filter((u) => u.username && !u.isEditable));
|
||||
}
|
||||
|
||||
if (result) {
|
||||
onUpdate({
|
||||
@ -70,6 +69,29 @@ export async function setChatUsername(
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function deactivateAllUsernames({ chat }: { chat: ApiChat }) {
|
||||
const result = await invokeRequest(new GramJs.channels.DeactivateAllUsernames({
|
||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||
}));
|
||||
|
||||
if (result) {
|
||||
const usernames = chat.usernames
|
||||
? chat.usernames
|
||||
.map((u) => ({ ...u, isActive: false }))
|
||||
// User can remove username from chat when changing it type to private, so we need to filter out empty usernames
|
||||
.filter((u) => u.username)
|
||||
: undefined;
|
||||
|
||||
onUpdate({
|
||||
'@type': 'updateChat',
|
||||
id: chat.id,
|
||||
chat: { usernames },
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function updatePrivateLink({
|
||||
chat, usageLimit, expireDate,
|
||||
}: {
|
||||
|
||||
@ -87,16 +87,20 @@ const ManageUsernames: FC<OwnProps> = ({
|
||||
}, []);
|
||||
|
||||
const handleUsernameToggle = useCallback(() => {
|
||||
if (!usernameForConfirm) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (chatId) {
|
||||
toggleChatUsername({
|
||||
chatId,
|
||||
username: usernameForConfirm!.username,
|
||||
isActive: !usernameForConfirm!.isActive,
|
||||
username: usernameForConfirm.username,
|
||||
isActive: !usernameForConfirm.isActive,
|
||||
});
|
||||
} else {
|
||||
toggleUsername({
|
||||
username: usernameForConfirm!.username,
|
||||
isActive: !usernameForConfirm!.isActive,
|
||||
username: usernameForConfirm.username,
|
||||
isActive: !usernameForConfirm.isActive,
|
||||
});
|
||||
}
|
||||
closeConfirmUsernameDialog();
|
||||
|
||||
@ -293,7 +293,7 @@ const RightColumn: FC<OwnProps & StateProps> = ({
|
||||
case RightColumnContent.Management:
|
||||
return (
|
||||
<Management
|
||||
key={`management_${chatId!}`}
|
||||
key={`management_${chatId!}_${managementScreen}`}
|
||||
chatId={chatId!}
|
||||
currentScreen={managementScreen}
|
||||
isPromotedByCurrentUser={isPromotedByCurrentUser}
|
||||
|
||||
@ -150,7 +150,7 @@ const ManageChatPrivacyType: FC<OwnProps & StateProps> = ({
|
||||
}, [isPublic, openUsernameLostDialog, privacyType, updatePublicLink, editableUsername]);
|
||||
|
||||
const handleMakeChannelPrivateConfirm = useCallback(() => {
|
||||
updatePublicLink({ username: '' });
|
||||
updatePublicLink({ username: '', shouldDisableUsernames: true });
|
||||
closeUsernameLostDialog();
|
||||
}, [closeUsernameLostDialog, updatePublicLink]);
|
||||
|
||||
@ -177,7 +177,7 @@ const ManageChatPrivacyType: FC<OwnProps & StateProps> = ({
|
||||
}];
|
||||
|
||||
const isLoading = progress === ManagementProgress.InProgress;
|
||||
const shouldRenderUsernamesManage = privacyType === 'public' && chat.usernames && chat.usernames.length > 1;
|
||||
const shouldRenderUsernamesManage = privacyType === 'public' && chat.usernames && chat.usernames.length > 0;
|
||||
|
||||
function renderPurchaseLink() {
|
||||
const purchaseInfoLink = `${TME_LINK_PREFIX}${PURCHASE_USERNAME}`;
|
||||
|
||||
@ -53,7 +53,7 @@ addActionHandler('checkPublicLink', async (global, actions, payload): Promise<vo
|
||||
});
|
||||
|
||||
addActionHandler('updatePublicLink', async (global, actions, payload): Promise<void> => {
|
||||
const { username, tabId = getCurrentTabId() } = payload;
|
||||
const { username, shouldDisableUsernames, tabId = getCurrentTabId() } = payload;
|
||||
|
||||
const { chatId } = selectCurrentMessageList(global, tabId) || {};
|
||||
if (!chatId) {
|
||||
@ -69,6 +69,9 @@ addActionHandler('updatePublicLink', async (global, actions, payload): Promise<v
|
||||
setGlobal(global);
|
||||
|
||||
const result = await callApi('setChatUsername', { chat, username });
|
||||
if (shouldDisableUsernames) {
|
||||
await callApi('deactivateAllUsernames', { chat });
|
||||
}
|
||||
|
||||
global = getGlobal();
|
||||
global = updateManagementProgress(global, result ? ManagementProgress.Complete : ManagementProgress.Error, tabId);
|
||||
|
||||
@ -1532,7 +1532,7 @@ export interface ActionPayloads {
|
||||
} & WithTabId) | undefined;
|
||||
closeManagement: WithTabId | undefined;
|
||||
checkPublicLink: { username: string } & WithTabId;
|
||||
updatePublicLink: { username: string } & WithTabId;
|
||||
updatePublicLink: { username: string; shouldDisableUsernames?: boolean } & WithTabId;
|
||||
updatePrivateLink: WithTabId | undefined;
|
||||
resetManagementError: { chatId: string } & WithTabId;
|
||||
|
||||
|
||||
@ -1356,6 +1356,7 @@ channels.toggleJoinToSend#e4cb9580 channel:InputChannel enabled:Bool = Updates;
|
||||
channels.toggleJoinRequest#4c2985b6 channel:InputChannel enabled:Bool = Updates;
|
||||
channels.reorderUsernames#b45ced1d channel:InputChannel order:Vector<string> = Bool;
|
||||
channels.toggleUsername#50f24105 channel:InputChannel username:string active:Bool = Bool;
|
||||
channels.deactivateAllUsernames#a245dd3 channel:InputChannel = Bool;
|
||||
channels.toggleForum#a4298b29 channel:InputChannel enabled:Bool = Updates;
|
||||
channels.createForumTopic#f40c0224 flags:# channel:InputChannel title:string icon_color:flags.0?int icon_emoji_id:flags.3?long random_id:long send_as:flags.2?InputPeer = Updates;
|
||||
channels.getForumTopics#de560d1 flags:# channel:InputChannel q:flags.0?string offset_date:int offset_id:int offset_topic:int limit:int = messages.ForumTopics;
|
||||
|
||||
@ -273,6 +273,7 @@
|
||||
"messages.readMentions",
|
||||
"messages.getUnreadMentions",
|
||||
"help.getPremiumPromo",
|
||||
"channels.deactivateAllUsernames",
|
||||
"channels.toggleForum",
|
||||
"channels.createForumTopic",
|
||||
"channels.getForumTopics",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user