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';
|
} from './symbols';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
checkChatUsername, setChatUsername, updatePrivateLink,
|
checkChatUsername, setChatUsername, updatePrivateLink, deactivateAllUsernames,
|
||||||
fetchExportedChatInvites, editExportedChatInvite, exportChatInvite, deleteExportedChatInvite,
|
fetchExportedChatInvites, editExportedChatInvite, exportChatInvite, deleteExportedChatInvite,
|
||||||
deleteRevokedExportedChatInvites, fetchChatInviteImporters, hideChatJoinRequest, hideAllChatJoinRequests,
|
deleteRevokedExportedChatInvites, fetchChatInviteImporters, hideChatJoinRequest, hideAllChatJoinRequests,
|
||||||
hideChatReportPanel,
|
hideChatReportPanel,
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { Api as GramJs } from '../../../lib/gramjs';
|
|||||||
import { invokeRequest } from './client';
|
import { invokeRequest } from './client';
|
||||||
import { buildInputEntity, buildInputPeer } from '../gramjsBuilders';
|
import { buildInputEntity, buildInputPeer } from '../gramjsBuilders';
|
||||||
import type {
|
import type {
|
||||||
ApiChat, ApiError, ApiUser, OnApiUpdate,
|
ApiChat, ApiError, ApiUser, ApiUsername, OnApiUpdate,
|
||||||
} from '../../types';
|
} from '../../types';
|
||||||
|
|
||||||
import { USERNAME_PURCHASE_ERROR } from '../../../config';
|
import { USERNAME_PURCHASE_ERROR } from '../../../config';
|
||||||
@ -52,12 +52,11 @@ export async function setChatUsername(
|
|||||||
username,
|
username,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const usernames = chat.usernames
|
let usernames: ApiUsername[] = username ? [{ username, isEditable: true, isActive: true }] : [];
|
||||||
? chat.usernames
|
if (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
|
||||||
// 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));
|
||||||
.filter((u) => u.username)
|
}
|
||||||
: [{ username, isEditable: true, isActive: true }];
|
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
onUpdate({
|
onUpdate({
|
||||||
@ -70,6 +69,29 @@ export async function setChatUsername(
|
|||||||
return result;
|
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({
|
export async function updatePrivateLink({
|
||||||
chat, usageLimit, expireDate,
|
chat, usageLimit, expireDate,
|
||||||
}: {
|
}: {
|
||||||
|
|||||||
@ -87,16 +87,20 @@ const ManageUsernames: FC<OwnProps> = ({
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleUsernameToggle = useCallback(() => {
|
const handleUsernameToggle = useCallback(() => {
|
||||||
|
if (!usernameForConfirm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (chatId) {
|
if (chatId) {
|
||||||
toggleChatUsername({
|
toggleChatUsername({
|
||||||
chatId,
|
chatId,
|
||||||
username: usernameForConfirm!.username,
|
username: usernameForConfirm.username,
|
||||||
isActive: !usernameForConfirm!.isActive,
|
isActive: !usernameForConfirm.isActive,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
toggleUsername({
|
toggleUsername({
|
||||||
username: usernameForConfirm!.username,
|
username: usernameForConfirm.username,
|
||||||
isActive: !usernameForConfirm!.isActive,
|
isActive: !usernameForConfirm.isActive,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
closeConfirmUsernameDialog();
|
closeConfirmUsernameDialog();
|
||||||
|
|||||||
@ -293,7 +293,7 @@ const RightColumn: FC<OwnProps & StateProps> = ({
|
|||||||
case RightColumnContent.Management:
|
case RightColumnContent.Management:
|
||||||
return (
|
return (
|
||||||
<Management
|
<Management
|
||||||
key={`management_${chatId!}`}
|
key={`management_${chatId!}_${managementScreen}`}
|
||||||
chatId={chatId!}
|
chatId={chatId!}
|
||||||
currentScreen={managementScreen}
|
currentScreen={managementScreen}
|
||||||
isPromotedByCurrentUser={isPromotedByCurrentUser}
|
isPromotedByCurrentUser={isPromotedByCurrentUser}
|
||||||
|
|||||||
@ -150,7 +150,7 @@ const ManageChatPrivacyType: FC<OwnProps & StateProps> = ({
|
|||||||
}, [isPublic, openUsernameLostDialog, privacyType, updatePublicLink, editableUsername]);
|
}, [isPublic, openUsernameLostDialog, privacyType, updatePublicLink, editableUsername]);
|
||||||
|
|
||||||
const handleMakeChannelPrivateConfirm = useCallback(() => {
|
const handleMakeChannelPrivateConfirm = useCallback(() => {
|
||||||
updatePublicLink({ username: '' });
|
updatePublicLink({ username: '', shouldDisableUsernames: true });
|
||||||
closeUsernameLostDialog();
|
closeUsernameLostDialog();
|
||||||
}, [closeUsernameLostDialog, updatePublicLink]);
|
}, [closeUsernameLostDialog, updatePublicLink]);
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ const ManageChatPrivacyType: FC<OwnProps & StateProps> = ({
|
|||||||
}];
|
}];
|
||||||
|
|
||||||
const isLoading = progress === ManagementProgress.InProgress;
|
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() {
|
function renderPurchaseLink() {
|
||||||
const purchaseInfoLink = `${TME_LINK_PREFIX}${PURCHASE_USERNAME}`;
|
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> => {
|
addActionHandler('updatePublicLink', async (global, actions, payload): Promise<void> => {
|
||||||
const { username, tabId = getCurrentTabId() } = payload;
|
const { username, shouldDisableUsernames, tabId = getCurrentTabId() } = payload;
|
||||||
|
|
||||||
const { chatId } = selectCurrentMessageList(global, tabId) || {};
|
const { chatId } = selectCurrentMessageList(global, tabId) || {};
|
||||||
if (!chatId) {
|
if (!chatId) {
|
||||||
@ -69,6 +69,9 @@ addActionHandler('updatePublicLink', async (global, actions, payload): Promise<v
|
|||||||
setGlobal(global);
|
setGlobal(global);
|
||||||
|
|
||||||
const result = await callApi('setChatUsername', { chat, username });
|
const result = await callApi('setChatUsername', { chat, username });
|
||||||
|
if (shouldDisableUsernames) {
|
||||||
|
await callApi('deactivateAllUsernames', { chat });
|
||||||
|
}
|
||||||
|
|
||||||
global = getGlobal();
|
global = getGlobal();
|
||||||
global = updateManagementProgress(global, result ? ManagementProgress.Complete : ManagementProgress.Error, tabId);
|
global = updateManagementProgress(global, result ? ManagementProgress.Complete : ManagementProgress.Error, tabId);
|
||||||
|
|||||||
@ -1532,7 +1532,7 @@ export interface ActionPayloads {
|
|||||||
} & WithTabId) | undefined;
|
} & WithTabId) | undefined;
|
||||||
closeManagement: WithTabId | undefined;
|
closeManagement: WithTabId | undefined;
|
||||||
checkPublicLink: { username: string } & WithTabId;
|
checkPublicLink: { username: string } & WithTabId;
|
||||||
updatePublicLink: { username: string } & WithTabId;
|
updatePublicLink: { username: string; shouldDisableUsernames?: boolean } & WithTabId;
|
||||||
updatePrivateLink: WithTabId | undefined;
|
updatePrivateLink: WithTabId | undefined;
|
||||||
resetManagementError: { chatId: string } & WithTabId;
|
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.toggleJoinRequest#4c2985b6 channel:InputChannel enabled:Bool = Updates;
|
||||||
channels.reorderUsernames#b45ced1d channel:InputChannel order:Vector<string> = Bool;
|
channels.reorderUsernames#b45ced1d channel:InputChannel order:Vector<string> = Bool;
|
||||||
channels.toggleUsername#50f24105 channel:InputChannel username:string active:Bool = 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.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.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;
|
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.readMentions",
|
||||||
"messages.getUnreadMentions",
|
"messages.getUnreadMentions",
|
||||||
"help.getPremiumPromo",
|
"help.getPremiumPromo",
|
||||||
|
"channels.deactivateAllUsernames",
|
||||||
"channels.toggleForum",
|
"channels.toggleForum",
|
||||||
"channels.createForumTopic",
|
"channels.createForumTopic",
|
||||||
"channels.getForumTopics",
|
"channels.getForumTopics",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user