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): { function buildApiChatRestrictions(peerEntity: GramJs.TypeUser | GramJs.TypeChat): {
isNotJoined?: boolean; isNotJoined?: boolean;
isForbidden?: boolean;
isRestricted?: boolean; isRestricted?: boolean;
restrictionReason?: ApiRestrictionReason; 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 { return {
isRestricted: true, isRestricted: true,
}; };
@ -139,7 +146,7 @@ function buildApiChatRestrictions(peerEntity: GramJs.TypeUser | GramJs.TypeChat)
if (peerEntity instanceof GramJs.Chat) { if (peerEntity instanceof GramJs.Chat) {
Object.assign(restrictions, { Object.assign(restrictions, {
isNotJoined: peerEntity.left, 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', '@type': 'updateChat',
id: message.chatId, id: message.chatId,
chat: { chat: {
isRestricted: true, isForbidden: true,
isNotJoined: true,
}, },
}); });
onUpdate({
'@type': 'updateChatLeave',
id: message.chatId,
});
} }
} else if (action instanceof GramJs.MessageActionChatAddUser) { } else if (action instanceof GramJs.MessageActionChatAddUser) {
// eslint-disable-next-line no-underscore-dangle // eslint-disable-next-line no-underscore-dangle

View File

@ -42,7 +42,8 @@ export interface ApiChat {
isNotJoined?: boolean; isNotJoined?: boolean;
isListed?: boolean; isListed?: boolean;
isCreator?: 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; restrictionReason?: ApiRestrictionReason;
adminRights?: ApiChatAdminRights; adminRights?: ApiChatAdminRights;
currentUserBannedRights?: ApiChatBannedRights; currentUserBannedRights?: ApiChatBannedRights;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -141,7 +141,7 @@ export function getCanPostInChat(chat: ApiChat, threadId: number) {
return true; 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; return false;
} }

View File

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