use sealed channel when required for direct message

This commit is contained in:
balzack 2024-01-18 18:01:15 -08:00
parent bba5a1c6de
commit a689a40a6d
6 changed files with 64 additions and 28 deletions

View File

@ -46,6 +46,7 @@ export function useAppContext() {
const setDeviceToken = async () => {
if (!deviceToken.current) {
try {
const token = await messaging().getToken();
if (!token) {
throw new Error('null push token');
@ -53,6 +54,10 @@ export function useAppContext() {
deviceToken.current = token;
pushType.current = "fcm";
}
catch(err) {
console.log(err);
}
}
}
useEffect(() => {
@ -64,12 +69,7 @@ export function useAppContext() {
});
(async () => {
try {
await setDeviceToken();
}
catch (err) {
console.log(err);
}
access.current = await store.actions.init();
if (access.current) {
await setSession();

View File

@ -91,7 +91,8 @@ export function Cards({ navigation, openContact, openRegistry, addChannel }) {
data={state.cards}
initialNumToRender={25}
renderItem={({ item }) => <CardItem item={item} openContact={openContact}
enableIce={state.enableIce} call={() => call(item)} message={() => addChannel(item.cardId)} />}
enableIce={state.enableIce} call={() => call(item)} message={() => addChannel(item.cardId)}
canMessage={(item.seal && state.sealable) || state.allowUnsealed} />}
keyExtractor={item => item.cardId}
/>
)}

View File

@ -6,7 +6,7 @@ import Colors from 'constants/Colors';
import { Menu, MenuOptions, MenuOption, MenuTrigger } from 'react-native-popup-menu';
import { getLanguageStrings } from 'constants/Strings';
export function CardItem({ item, openContact, enableIce, call, message }) {
export function CardItem({ item, openContact, enableIce, call, message, canMessage }) {
const strings = getLanguageStrings();
@ -43,12 +43,16 @@ export function CardItem({ item, openContact, enableIce, call, message }) {
<MenuOption onSelect={select}>
<Text style={styles.option}>{ strings.viewProfile }</Text>
</MenuOption>
{ canMessage && (
<MenuOption onSelect={message}>
<Text style={styles.option}>{ strings.messageContact }</Text>
</MenuOption>
)}
{ enableIce && (
<MenuOption onSelect={call}>
<Text style={styles.option}>{ strings.callContact }</Text>
</MenuOption>
)}
</MenuOptions>
</Menu>
)}

View File

@ -10,6 +10,8 @@ export function useCards() {
const [state, setState] = useState({
cards: [],
enableIce: false,
sealable: false,
allowUnsealed: false,
strings: getLanguageStrings(),
sort: false,
filter: null,
@ -25,13 +27,19 @@ export function useCards() {
}
useEffect(() => {
const { enableIce } = account.state.status || {};
updateState({ enableIce });
const { enableIce, allowUnsealed } = account.state.status || {};
const { status, sealKey } = account.state;
if (status?.seal?.publicKey && sealKey?.public && sealKey?.private && sealKey?.public === status.seal.publicKey) {
updateState({ sealable: true, allowUnsealed, enableIce });
}
else {
updateState({ sealable: false, allowUnsealed, enableIce });
}
}, [account.state]);
const setCardItem = (item) => {
const { profile, detail, cardId, blocked, offsync } = item.card || { profile: {}, detail: {} }
const { name, handle, node, guid, location, description, imageSet } = profile;
const { name, handle, node, guid, location, description, imageSet, seal } = profile;
return {
cardId: cardId,
@ -44,6 +52,7 @@ export function useCards() {
description: description,
status: detail.status,
token: detail.token,
seal: seal,
offsync: offsync,
blocked: blocked,
updated: detail.statusUpdated,
@ -111,8 +120,6 @@ export function useCards() {
updateState({ filter });
},
setSort: (sort) => {
console.log("SETTTING : ", sort);
updateState({ sort });
},
};

View File

@ -3,10 +3,12 @@ import { useWindowDimensions } from 'react-native';
import config from 'constants/Config';
import { StoreContext } from 'context/StoreContext';
import { CardContext } from 'context/CardContext';
import { AccountContext } from 'context/AccountContext';
import { ChannelContext } from 'context/ChannelContext';
import { RingContext } from 'context/RingContext';
import { ProfileContext } from 'context/ProfileContext';
import { getLanguageStrings } from 'constants/Strings';
import { encryptChannelSubject } from 'context/sealUtil';
export function useSession() {
@ -30,6 +32,7 @@ export function useSession() {
});
const ring = useContext(RingContext);
const account = useContext(AccountContext);
const channel = useContext(ChannelContext);
const card = useContext(CardContext);
const profile = useContext(ProfileContext);
@ -70,6 +73,18 @@ export function useSession() {
updateState({ ringing, callStatus, callLogo, localStream, localVideo, localAudio, remoteStream, remoteVideo, remoteAudio });
}, [ring.state]);
useEffect(() => {
const { allowUnsealed } = account.state.status || {};
const { status, sealKey } = account.state;
if (status?.seal?.publicKey && sealKey?.public && sealKey?.private && sealKey?.public === status.seal.publicKey) {
updateState({ sealable: true, allowUnsealed });
}
else {
updateState({ sealable: false, allowUnsealed });
}
}, [account.state]);
useEffect(() => {
checkFirstRun();
}, []);
@ -140,8 +155,17 @@ export function useSession() {
if (channelId != null) {
return channelId;
}
if (state.sealable && !state.allowUnsealed) {
const keys = [ account.state.sealKey.public ];
keys.push(card.state.cards.get(cardId).card.profile.seal);
const sealed = encryptChannelSubject(state.subject, keys);
const conversation = await channel.actions.addChannel('sealed', sealed, [ cardId ]);
return conversation.id;
}
else {
const conversation = await channel.actions.addChannel('superbasic', { subject: null }, [ cardId ]);
return conversation.id;
}
},
};

View File

@ -36,7 +36,7 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then ARCHITECTURE=amd64; elif [ "$
&& wget -P /app https://go.dev/dl/go1.18.10.linux-${ARCHITECTURE}.tar.gz \
&& tar -C /usr/local -xzf /app/go1.18.10.linux-${ARCHITECTURE}.tar.gz
RUN git clone https://github.com/balzack/databag.git -b openwrt /app/databag
RUN git clone https://github.com/balzack/databag.git /app/databag
RUN yarn config set network-timeout 300000
RUN yarn --cwd /app/databag/net/web install