Fix handling kicking from legacy groups (#1799)

This commit is contained in:
Alexander Zinchuk 2022-04-01 20:43:36 +02:00
parent 860937dcf4
commit 8cca43a4f8
10 changed files with 26 additions and 17 deletions

View File

@ -112,10 +112,17 @@ function buildApiChatPermissions(peerEntity: GramJs.TypeUser | GramJs.TypeChat):
function buildApiChatRestrictions(peerEntity: GramJs.TypeUser | GramJs.TypeChat): {
isNotJoined?: boolean;
isForbidden?: boolean;
isRestricted?: boolean;
restrictionReason?: ApiRestrictionReason;
} {
if (peerEntity instanceof GramJs.ChatForbidden || peerEntity instanceof GramJs.ChannelForbidden) {
if (peerEntity instanceof GramJs.ChatForbidden) {
return {
isForbidden: true,
};
}
if (peerEntity instanceof GramJs.ChannelForbidden) {
return {
isRestricted: true,
};
@ -139,7 +146,7 @@ function buildApiChatRestrictions(peerEntity: GramJs.TypeUser | GramJs.TypeChat)
if (peerEntity instanceof GramJs.Chat) {
Object.assign(restrictions, {
isNotJoined: peerEntity.left,
isRestricted: peerEntity.kicked,
isForbidden: peerEntity.kicked,
});
}

View File

@ -241,14 +241,10 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
'@type': 'updateChat',
id: message.chatId,
chat: {
isRestricted: true,
isForbidden: true,
isNotJoined: true,
},
});
onUpdate({
'@type': 'updateChatLeave',
id: message.chatId,
});
}
} else if (action instanceof GramJs.MessageActionChatAddUser) {
// eslint-disable-next-line no-underscore-dangle

View File

@ -42,7 +42,8 @@ export interface ApiChat {
isNotJoined?: boolean;
isListed?: boolean;
isCreator?: boolean;
isRestricted?: boolean;
isForbidden?: boolean; // Forbidden - can't send messages (user was kicked, for example)
isRestricted?: boolean; // Restricted - can't access the chat (user was banned or chat is violating rules)
restrictionReason?: ApiRestrictionReason;
adminRights?: ApiChatAdminRights;
currentUserBannedRights?: ApiChatBannedRights;

View File

@ -486,7 +486,7 @@ export default memo(withGlobal<OwnProps>(
canSaveGif: !isProtected && canSaveGif,
activeDownloads,
canShowSeenBy,
enabledReactions: chat?.fullInfo?.enabledReactions,
enabledReactions: chat?.isForbidden ? undefined : chat?.fullInfo?.enabledReactions,
isPrivate,
hasFullInfo: Boolean(chat?.fullInfo),
canShowReactionsCount,

View File

@ -289,10 +289,12 @@ const Profile: FC<OwnProps & StateProps> = ({
function renderContent() {
if (!viewportIds || !canRenderContent || !chatMessages) {
const noSpinner = isFirstTab && !canRenderContent;
const forceRenderHiddenMembers = Boolean(resultType === 'members' && areMembersHidden);
return (
<div className="content empty-list">
{!noSpinner && <Spinner />}
{!noSpinner && !forceRenderHiddenMembers && <Spinner />}
{forceRenderHiddenMembers && <NothingFound text="You have no access to group members list." />}
</div>
);
}
@ -518,7 +520,8 @@ export default memo(withGlobal<OwnProps>(
const isChannel = chat && isChatChannel(chat);
const hasMembersTab = isGroup || (isChannel && isChatAdmin(chat!));
const members = chat?.fullInfo?.members;
const areMembersHidden = hasMembersTab && chat && chat.fullInfo && !chat.fullInfo.canViewMembers;
const areMembersHidden = hasMembersTab && chat
&& (chat.isForbidden || (chat.fullInfo && !chat.fullInfo.canViewMembers));
const canAddMembers = hasMembersTab && chat && (getHasAdminRight(chat, 'inviteUsers') || chat.isCreator);
const canDeleteMembers = hasMembersTab && chat && (getHasAdminRight(chat, 'banUsers') || chat.isCreator);
const activeDownloadIds = selectActiveDownloadIds(global, chatId);

View File

@ -186,7 +186,7 @@ const ManageChannel: FC<OwnProps & StateProps> = ({
const enabledReactionsCount = chat.fullInfo?.enabledReactions?.length || 0;
if (chat.isRestricted) {
if (chat.isRestricted || chat.isForbidden) {
return undefined;
}

View File

@ -234,7 +234,7 @@ const ManageGroup: FC<OwnProps & StateProps> = ({
closeDeleteDialog, closeManagement, leaveChannel, deleteChannel, deleteChat, openChat,
]);
if (chat.isRestricted) {
if (chat.isRestricted || chat.isForbidden) {
return undefined;
}

View File

@ -312,6 +312,7 @@ addActionHandler('inviteToCallFallback', async (global, actions, payload) => {
channel.title === fallbackChannelTitle
&& channel.isCreator
&& !channel.isRestricted
&& !channel.isForbidden
);
});
if (!fallbackChannel) {

View File

@ -141,7 +141,7 @@ export function getCanPostInChat(chat: ApiChat, threadId: number) {
return true;
}
if (chat.isRestricted || chat.migratedTo || chat.isNotJoined || isChatWithRepliesBot(chat.id)) {
if (chat.isRestricted || chat.isForbidden || chat.migratedTo || chat.isNotJoined || isChatWithRepliesBot(chat.id)) {
return false;
}

View File

@ -380,9 +380,10 @@ export function selectAllowedMessageActions(global: GlobalState, message: ApiMes
)
&& !isForwardedMessage(message)
&& !message.viaBotId
&& !chat.isForbidden
);
const canReply = !isLocal && !isServiceNotification && getCanPostInChat(chat, threadId);
const canReply = !isLocal && !isServiceNotification && !chat.isForbidden && getCanPostInChat(chat, threadId);
const hasPinPermission = isPrivate || (
chat.isCreator
@ -410,7 +411,7 @@ export function selectAllowedMessageActions(global: GlobalState, message: ApiMes
const canReport = !isPrivate && !isOwn;
const canDeleteForAll = canDelete && (
const canDeleteForAll = canDelete && !chat.isForbidden && (
(isPrivate && !isChatWithSelf)
|| (isBasicGroup && (
isOwn || getHasAdminRight(chat, 'deleteMessages') || chat.isCreator