Added end to end encryption

This commit is contained in:
Aslan 2026-01-13 17:33:23 -05:00
parent 9153ba841d
commit 575e9e2010
131 changed files with 2289 additions and 1670 deletions

View file

@ -8,22 +8,33 @@ import {
fetchCommunityMembersApi,
fetchCommunityInvitesApi,
} from "../../api/community";
import { CommunityActionTypes } from "../../store/community";
import { ChannelActionTypes } from "../../store/channel";
import { RoleActionTypes } from "../../store/role";
import { UserActionTypes } from "../../store/user";
import { dispatch, state } from "../../store/state";
import { InviteActionTypes } from "../../store/invite";
import { setChannel } from "../../store/channel";
import {
deleteCommunity,
setCommunity,
setCommunityChannels,
setCommunityEncryptionKey,
setCommunityInvites,
setCommunityMembers,
setCommunityRoles,
} from "../../store/community";
import { setInvite } from "../../store/invite";
import { setRole } from "../../store/role";
import { state } from "../../store/state";
import { setUser } from "../../store/user";
import { DB_STORE, dbLoadEncrypted } from "../database";
import { fetchUserCommunities } from "../user";
const fetchCommunity = async (id: string) => {
const data = await fetchCommunityApi({
id: id,
});
dispatch({
type: CommunityActionTypes.FETCH_COMMUNITY_FINISH,
payload: data,
});
if (typeof data.error === "string") {
return;
}
setCommunity(data);
};
const createCommunity = async (name: string) => {
@ -31,16 +42,14 @@ const createCommunity = async (name: string) => {
name: name,
});
dispatch({
type: CommunityActionTypes.CREATE_COMMUNITY_FINISH,
payload: data,
});
if (typeof data.error === "string") {
return;
}
setCommunity(data);
if (state.user.loggedUserId) {
dispatch({
type: UserActionTypes.FETCH_USER_COMMUNITIES_START,
payload: state.user.loggedUserId,
});
fetchUserCommunities(state.user.loggedUserId);
}
};
@ -55,16 +64,14 @@ const updateCommunity = async (
description: description,
});
dispatch({
type: CommunityActionTypes.UPDATE_COMMUNITY_FINISH,
payload: data,
});
if (typeof data.error === "string") {
return;
}
setCommunity(data);
if (state.user.loggedUserId) {
dispatch({
type: UserActionTypes.FETCH_USER_COMMUNITIES_START,
payload: state.user.loggedUserId,
});
fetchUserCommunities(state.user.loggedUserId);
}
};
@ -73,16 +80,14 @@ const removeCommunity = async (id: string) => {
id: id,
});
dispatch({
type: CommunityActionTypes.REMOVE_COMMUNITY_FINISH,
payload: data,
});
if (typeof data.error === "string") {
return;
}
deleteCommunity(data.id);
if (state.user.loggedUserId) {
dispatch({
type: UserActionTypes.FETCH_USER_COMMUNITIES_START,
payload: state.user.loggedUserId,
});
fetchUserCommunities(state.user.loggedUserId);
}
};
@ -91,16 +96,14 @@ const fetchCommunityChannels = async (id: string) => {
id: id,
});
dispatch({
type: CommunityActionTypes.FETCH_COMMUNITY_CHANNELS_FINISH,
payload: data,
});
if (typeof data.error === "string") {
return;
}
setCommunityChannels(data.id, data.channels);
data.channels.forEach((channel) => {
dispatch({
type: ChannelActionTypes.SET_CHANNEL,
payload: channel,
});
setChannel(channel);
});
};
@ -109,16 +112,14 @@ const fetchCommunityRoles = async (id: string) => {
id: id,
});
dispatch({
type: CommunityActionTypes.FETCH_COMMUNITY_ROLES_FINISH,
payload: data,
});
if (typeof data.error === "string") {
return;
}
setCommunityRoles(data.id, data.roles);
data.roles.forEach((role) => {
dispatch({
type: RoleActionTypes.SET_ROLE,
payload: role,
});
setRole(role);
});
};
@ -127,16 +128,14 @@ const fetchCommunityMembers = async (id: string) => {
id: id,
});
dispatch({
type: CommunityActionTypes.FETCH_COMMUNITY_MEMBERS_FINISH,
payload: data,
});
if (typeof data.error === "string") {
return;
}
setCommunityMembers(data.id, data.members);
data.members.forEach((member) => {
dispatch({
type: UserActionTypes.SET_USER,
payload: member,
});
setUser(member);
});
};
@ -145,15 +144,34 @@ const fetchCommunityInvites = async (id: string) => {
id: id,
});
dispatch({
type: CommunityActionTypes.FETCH_COMMUNITY_INVITES_FINISH,
payload: data,
});
if (typeof data.error === "string") {
return;
}
setCommunityInvites(data.id, data.invites);
data.invites.forEach((invite) => {
dispatch({
type: InviteActionTypes.SET_INVITE,
payload: invite,
setInvite(invite);
});
};
const loadCommunityCryptoStates = async () => {
if (!state.user.loggedUserId) {
return;
}
const communities = state.user.users[state.user.loggedUserId]?.communities;
if (!communities) {
return;
}
communities.forEach((communityId) => {
dbLoadEncrypted<string>(
DB_STORE.COMMUNITY_ENCRYPTION_KEYS,
communityId,
).then((communityEncryptionKey) => {
if (communityEncryptionKey) {
setCommunityEncryptionKey(communityId, communityEncryptionKey);
}
});
});
};
@ -167,4 +185,5 @@ export {
fetchCommunityRoles,
fetchCommunityMembers,
fetchCommunityInvites,
loadCommunityCryptoStates,
};