mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
use sealed channel when required for direct message
This commit is contained in:
parent
bba5a1c6de
commit
a689a40a6d
@ -46,6 +46,7 @@ export function useAppContext() {
|
|||||||
|
|
||||||
const setDeviceToken = async () => {
|
const setDeviceToken = async () => {
|
||||||
if (!deviceToken.current) {
|
if (!deviceToken.current) {
|
||||||
|
try {
|
||||||
const token = await messaging().getToken();
|
const token = await messaging().getToken();
|
||||||
if (!token) {
|
if (!token) {
|
||||||
throw new Error('null push token');
|
throw new Error('null push token');
|
||||||
@ -53,6 +54,10 @@ export function useAppContext() {
|
|||||||
deviceToken.current = token;
|
deviceToken.current = token;
|
||||||
pushType.current = "fcm";
|
pushType.current = "fcm";
|
||||||
}
|
}
|
||||||
|
catch(err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -64,12 +69,7 @@ export function useAppContext() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
|
||||||
await setDeviceToken();
|
await setDeviceToken();
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
access.current = await store.actions.init();
|
access.current = await store.actions.init();
|
||||||
if (access.current) {
|
if (access.current) {
|
||||||
await setSession();
|
await setSession();
|
||||||
|
@ -91,7 +91,8 @@ export function Cards({ navigation, openContact, openRegistry, addChannel }) {
|
|||||||
data={state.cards}
|
data={state.cards}
|
||||||
initialNumToRender={25}
|
initialNumToRender={25}
|
||||||
renderItem={({ item }) => <CardItem item={item} openContact={openContact}
|
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}
|
keyExtractor={item => item.cardId}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
@ -6,7 +6,7 @@ import Colors from 'constants/Colors';
|
|||||||
import { Menu, MenuOptions, MenuOption, MenuTrigger } from 'react-native-popup-menu';
|
import { Menu, MenuOptions, MenuOption, MenuTrigger } from 'react-native-popup-menu';
|
||||||
import { getLanguageStrings } from 'constants/Strings';
|
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();
|
const strings = getLanguageStrings();
|
||||||
|
|
||||||
@ -43,12 +43,16 @@ export function CardItem({ item, openContact, enableIce, call, message }) {
|
|||||||
<MenuOption onSelect={select}>
|
<MenuOption onSelect={select}>
|
||||||
<Text style={styles.option}>{ strings.viewProfile }</Text>
|
<Text style={styles.option}>{ strings.viewProfile }</Text>
|
||||||
</MenuOption>
|
</MenuOption>
|
||||||
|
{ canMessage && (
|
||||||
<MenuOption onSelect={message}>
|
<MenuOption onSelect={message}>
|
||||||
<Text style={styles.option}>{ strings.messageContact }</Text>
|
<Text style={styles.option}>{ strings.messageContact }</Text>
|
||||||
</MenuOption>
|
</MenuOption>
|
||||||
|
)}
|
||||||
|
{ enableIce && (
|
||||||
<MenuOption onSelect={call}>
|
<MenuOption onSelect={call}>
|
||||||
<Text style={styles.option}>{ strings.callContact }</Text>
|
<Text style={styles.option}>{ strings.callContact }</Text>
|
||||||
</MenuOption>
|
</MenuOption>
|
||||||
|
)}
|
||||||
</MenuOptions>
|
</MenuOptions>
|
||||||
</Menu>
|
</Menu>
|
||||||
)}
|
)}
|
||||||
|
@ -10,6 +10,8 @@ export function useCards() {
|
|||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
cards: [],
|
cards: [],
|
||||||
enableIce: false,
|
enableIce: false,
|
||||||
|
sealable: false,
|
||||||
|
allowUnsealed: false,
|
||||||
strings: getLanguageStrings(),
|
strings: getLanguageStrings(),
|
||||||
sort: false,
|
sort: false,
|
||||||
filter: null,
|
filter: null,
|
||||||
@ -25,13 +27,19 @@ export function useCards() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { enableIce } = account.state.status || {};
|
const { enableIce, allowUnsealed } = account.state.status || {};
|
||||||
updateState({ enableIce });
|
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]);
|
}, [account.state]);
|
||||||
|
|
||||||
const setCardItem = (item) => {
|
const setCardItem = (item) => {
|
||||||
const { profile, detail, cardId, blocked, offsync } = item.card || { profile: {}, detail: {} }
|
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 {
|
return {
|
||||||
cardId: cardId,
|
cardId: cardId,
|
||||||
@ -44,6 +52,7 @@ export function useCards() {
|
|||||||
description: description,
|
description: description,
|
||||||
status: detail.status,
|
status: detail.status,
|
||||||
token: detail.token,
|
token: detail.token,
|
||||||
|
seal: seal,
|
||||||
offsync: offsync,
|
offsync: offsync,
|
||||||
blocked: blocked,
|
blocked: blocked,
|
||||||
updated: detail.statusUpdated,
|
updated: detail.statusUpdated,
|
||||||
@ -111,8 +120,6 @@ export function useCards() {
|
|||||||
updateState({ filter });
|
updateState({ filter });
|
||||||
},
|
},
|
||||||
setSort: (sort) => {
|
setSort: (sort) => {
|
||||||
console.log("SETTTING : ", sort);
|
|
||||||
|
|
||||||
updateState({ sort });
|
updateState({ sort });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -3,10 +3,12 @@ import { useWindowDimensions } from 'react-native';
|
|||||||
import config from 'constants/Config';
|
import config from 'constants/Config';
|
||||||
import { StoreContext } from 'context/StoreContext';
|
import { StoreContext } from 'context/StoreContext';
|
||||||
import { CardContext } from 'context/CardContext';
|
import { CardContext } from 'context/CardContext';
|
||||||
|
import { AccountContext } from 'context/AccountContext';
|
||||||
import { ChannelContext } from 'context/ChannelContext';
|
import { ChannelContext } from 'context/ChannelContext';
|
||||||
import { RingContext } from 'context/RingContext';
|
import { RingContext } from 'context/RingContext';
|
||||||
import { ProfileContext } from 'context/ProfileContext';
|
import { ProfileContext } from 'context/ProfileContext';
|
||||||
import { getLanguageStrings } from 'constants/Strings';
|
import { getLanguageStrings } from 'constants/Strings';
|
||||||
|
import { encryptChannelSubject } from 'context/sealUtil';
|
||||||
|
|
||||||
export function useSession() {
|
export function useSession() {
|
||||||
|
|
||||||
@ -30,6 +32,7 @@ export function useSession() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const ring = useContext(RingContext);
|
const ring = useContext(RingContext);
|
||||||
|
const account = useContext(AccountContext);
|
||||||
const channel = useContext(ChannelContext);
|
const channel = useContext(ChannelContext);
|
||||||
const card = useContext(CardContext);
|
const card = useContext(CardContext);
|
||||||
const profile = useContext(ProfileContext);
|
const profile = useContext(ProfileContext);
|
||||||
@ -70,6 +73,18 @@ export function useSession() {
|
|||||||
updateState({ ringing, callStatus, callLogo, localStream, localVideo, localAudio, remoteStream, remoteVideo, remoteAudio });
|
updateState({ ringing, callStatus, callLogo, localStream, localVideo, localAudio, remoteStream, remoteVideo, remoteAudio });
|
||||||
}, [ring.state]);
|
}, [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(() => {
|
useEffect(() => {
|
||||||
checkFirstRun();
|
checkFirstRun();
|
||||||
}, []);
|
}, []);
|
||||||
@ -140,8 +155,17 @@ export function useSession() {
|
|||||||
if (channelId != null) {
|
if (channelId != null) {
|
||||||
return channelId;
|
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 ]);
|
const conversation = await channel.actions.addChannel('superbasic', { subject: null }, [ cardId ]);
|
||||||
return conversation.id;
|
return conversation.id;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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 \
|
&& 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
|
&& 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 config set network-timeout 300000
|
||||||
RUN yarn --cwd /app/databag/net/web install
|
RUN yarn --cwd /app/databag/net/web install
|
||||||
|
Loading…
Reference in New Issue
Block a user