Added end to end encryption

This commit is contained in:
Aslan 2026-01-13 17:34:39 -05:00
parent 5733975aa0
commit 6f292756ed
34 changed files with 682 additions and 69 deletions

View file

@ -7,6 +7,9 @@ import {
isUserOwnerOrAdmin,
} from "../auth/helpers.js";
import { PERMISSION } from "../auth/permission.js";
import { getUserIdsInCommunity } from "../user/user.js";
import { SocketMessageTypes } from "../websocket/types.js";
import { sendMessageToUsersWS } from "../websocket/websocket.js";
import type {
ICreateCommunity,
IUpdateCommunity,
@ -287,6 +290,7 @@ const createInviteAuth = async (
const community = await getCommunityById(id);
if (
!authUser ||
!(await isUserAllowed(
authUser,
{
@ -294,8 +298,7 @@ const createInviteAuth = async (
},
community,
[PERMISSION.INVITES_CREATE],
)) ||
!authUser
))
) {
return API_ERROR.ACCESS_DENIED;
}
@ -303,6 +306,60 @@ const createInviteAuth = async (
return await createInvite(id, authUser.id, createInviteData);
};
const deleteMemberById = async (
id: string,
memberId: string,
): Promise<Community> => {
const updatedCommunity = await getDB().community.update({
where: {
id: id,
},
data: {
members: {
disconnect: {
id: memberId,
},
},
},
});
const userIds = await getUserIdsInCommunity(updatedCommunity.id);
sendMessageToUsersWS(userIds, {
type: SocketMessageTypes.UPDATE_MEMBERS,
payload: {
communityId: updatedCommunity.id,
},
});
return updatedCommunity;
};
const deleteMemberByIdAuth = async (
id: string,
memberId: string,
authHeader: string | undefined,
): Promise<Community | API_ERROR.ACCESS_DENIED> => {
const authUser = await getUserFromAuth(authHeader);
const community = await getCommunityById(id);
if (
!(await isUserAllowed(
authUser,
{
community: community,
},
community,
[PERMISSION.MEMBERS_KICK],
)) &&
authUser?.id !== memberId
) {
return API_ERROR.ACCESS_DENIED;
}
return await deleteMemberById(id, memberId);
};
export {
getCommunityById,
createCommunity,
@ -321,4 +378,6 @@ export {
getCommunityInvitesByIdAuth,
createInvite,
createInviteAuth,
deleteMemberById,
deleteMemberByIdAuth,
};