mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
support updating sealed channels subjects in mobile app
This commit is contained in:
parent
d7cd2bd018
commit
6ee1ebef14
@ -669,7 +669,7 @@ SPEC CHECKSUMS:
|
|||||||
FirebaseInstallations: 99d24bac0243cf8b0e96cf5426340d211f0bcc80
|
FirebaseInstallations: 99d24bac0243cf8b0e96cf5426340d211f0bcc80
|
||||||
FirebaseMessaging: 4487bbff9b9b927ba1dd3ea40d1ceb58e4ee3cb5
|
FirebaseMessaging: 4487bbff9b9b927ba1dd3ea40d1ceb58e4ee3cb5
|
||||||
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
|
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
|
||||||
glog: 3d02b25ca00c2d456734d0bcff864cbc62f6ae1a
|
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
|
||||||
GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f
|
GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f
|
||||||
GoogleUtilities: 1d20a6ad97ef46f67bbdec158ce00563a671ebb7
|
GoogleUtilities: 1d20a6ad97ef46f67bbdec158ce00563a671ebb7
|
||||||
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
|
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function setChannelSubject(server, token, channelId, subject ) {
|
export async function setChannelSubject(server, token, channelId, dataType, data ) {
|
||||||
let data = { subject };
|
let params = { dataType, data: JSON.stringify(data) };
|
||||||
let params = { dataType: 'superbasic', data: JSON.stringify(data) };
|
|
||||||
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/subject?agent=${token}`, { method: 'PUT', body: JSON.stringify(params)} );
|
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/subject?agent=${token}`, { method: 'PUT', body: JSON.stringify(params)} );
|
||||||
checkResponse(channel);
|
checkResponse(channel);
|
||||||
return await channel.json();
|
return await channel.json();
|
||||||
|
@ -273,9 +273,30 @@ export function useChannelContext() {
|
|||||||
const { server, appToken } = session.current;
|
const { server, appToken } = session.current;
|
||||||
return await setChannelTopicSubject(server, appToken, channelId, topicId, data);
|
return await setChannelTopicSubject(server, appToken, channelId, topicId, data);
|
||||||
},
|
},
|
||||||
setSubject: async (channelId, data) => {
|
setSubject: async (channelId, subject) => {
|
||||||
const { server, appToken } = session.current;
|
const { server, appToken } = session.current;
|
||||||
return await setChannelSubject(server, appToken, channelId, data);
|
return await setChannelSubject(server, appToken, channelId, 'superbasic', { subject });
|
||||||
|
},
|
||||||
|
setSealedSubject: async (channelId, subject, sealKey) => {
|
||||||
|
const { server, appToken } = session.current;
|
||||||
|
const channel = channels.current.get(channelId);
|
||||||
|
|
||||||
|
let { seals, subjectEncrypted, subjectIv } = JSON.parse(channel.detail.data);
|
||||||
|
seals.forEach(seal => {
|
||||||
|
if (seal.publicKey === sealKey.public) {
|
||||||
|
let crypto = new JSEncrypt();
|
||||||
|
crypto.setPrivateKey(sealKey.private);
|
||||||
|
const unsealedKey = crypto.decrypt(seal.sealedKey);
|
||||||
|
const key = CryptoJS.enc.Hex.parse(unsealedKey);
|
||||||
|
|
||||||
|
const iv = CryptoJS.lib.WordArray.random(128 / 8);
|
||||||
|
const encrypted = CryptoJS.AES.encrypt(JSON.stringify({ subject }), key, { iv: iv });
|
||||||
|
subjectEncrypted = encrypted.ciphertext.toString(CryptoJS.enc.Base64)
|
||||||
|
subjectIv = iv.toString();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const data = { subjectEncrypted, subjectIv, seals };
|
||||||
|
return await setChannelSubject(server, appToken, channelId, 'sealed', data);
|
||||||
},
|
},
|
||||||
remove: async (channelId) => {
|
remove: async (channelId) => {
|
||||||
const { server, appToken } = session.current;
|
const { server, appToken } = session.current;
|
||||||
|
@ -333,7 +333,8 @@ export function useConversationContext() {
|
|||||||
locked = true;
|
locked = true;
|
||||||
unlocked = item.unsealedDetail != null;
|
unlocked = item.unsealedDetail != null;
|
||||||
if (item.unsealedDetail?.subject) {
|
if (item.unsealedDetail?.subject) {
|
||||||
subject = item.unsealedDetail.subject;
|
topic = item.unsealedDetail.subject;
|
||||||
|
subject = topic;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
seals = JSON.parse(item.detail.data).seals;
|
seals = JSON.parse(item.detail.data).seals;
|
||||||
@ -440,6 +441,15 @@ export function useConversationContext() {
|
|||||||
await channel.actions.setSubject(channelId, subject);
|
await channel.actions.setSubject(channelId, subject);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setSealedSubject: async (subject, sealKey) => {
|
||||||
|
if (conversationId.current) {
|
||||||
|
const { cardId, channelId } = conversationId.current;
|
||||||
|
if (cardId) {
|
||||||
|
throw new Error("can only set hosted channel subjects");
|
||||||
|
}
|
||||||
|
await channel.actions.setSealedSubject(channelId, subject, sealKey);
|
||||||
|
}
|
||||||
|
},
|
||||||
remove: async () => {
|
remove: async () => {
|
||||||
if (conversationId.current) {
|
if (conversationId.current) {
|
||||||
const { cardId, channelId } = conversationId.current;
|
const { cardId, channelId } = conversationId.current;
|
||||||
|
@ -19,7 +19,7 @@ export function ChannelItem({ item, openConversation }) {
|
|||||||
<Ionicons name="lock" style={styles.subjectIcon} size={16} color={Colors.text} />
|
<Ionicons name="lock" style={styles.subjectIcon} size={16} color={Colors.text} />
|
||||||
)}
|
)}
|
||||||
{ item.locked && item.unlocked && (
|
{ item.locked && item.unlocked && (
|
||||||
<Ionicons name="lock-open-variant-outline" style={styles.subjectIcon} size={16} color={Colors.text} />
|
<Ionicons name="lock-open-variant-outline" style={styles.subjectIcon} size={16} color={Colors.grey} />
|
||||||
)}
|
)}
|
||||||
<Text style={styles.subjectText} numberOfLines={1} ellipsizeMode={'tail'}>{ item.subject }</Text>
|
<Text style={styles.subjectText} numberOfLines={1} ellipsizeMode={'tail'}>{ item.subject }</Text>
|
||||||
</View>
|
</View>
|
||||||
|
@ -136,7 +136,7 @@ export function DetailsBody({ channel, clearConversation }) {
|
|||||||
<MatIcons name="lock-open-variant-outline" style={styles.subjectIcon} size={16} color={Colors.text} />
|
<MatIcons name="lock-open-variant-outline" style={styles.subjectIcon} size={16} color={Colors.text} />
|
||||||
)}
|
)}
|
||||||
<Text style={styles.subjectText} numberOfLines={1} ellipsizeMode={'tail'}>{ state.subject }</Text>
|
<Text style={styles.subjectText} numberOfLines={1} ellipsizeMode={'tail'}>{ state.subject }</Text>
|
||||||
{ !state.hostId && (
|
{ !state.hostId && (!state.locked || state.sealable) && (
|
||||||
<TouchableOpacity onPress={actions.showEditSubject}>
|
<TouchableOpacity onPress={actions.showEditSubject}>
|
||||||
<AntIcons name="edit" size={16} color={Colors.text} />
|
<AntIcons name="edit" size={16} color={Colors.text} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
@ -166,7 +166,7 @@ export function DetailsBody({ channel, clearConversation }) {
|
|||||||
<Text style={styles.buttonText}>Report Topic</Text>
|
<Text style={styles.buttonText}>Report Topic</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)}
|
)}
|
||||||
{ !state.hostId && (
|
{ !state.hostId && !state.locked && (
|
||||||
<TouchableOpacity style={styles.button} onPress={actions.showEditMembers}>
|
<TouchableOpacity style={styles.button} onPress={actions.showEditMembers}>
|
||||||
<Text style={styles.buttonText}>Edit Membership</Text>
|
<Text style={styles.buttonText}>Edit Membership</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
@ -20,7 +20,6 @@ export function useDetails() {
|
|||||||
locked: false,
|
locked: false,
|
||||||
unlocked: false,
|
unlocked: false,
|
||||||
sealable: false,
|
sealable: false,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const account = useContext(AccountContext);
|
const account = useContext(AccountContext);
|
||||||
@ -37,7 +36,7 @@ export function useDetails() {
|
|||||||
if (account.state.sealKey && conversation.state.seals) {
|
if (account.state.sealKey && conversation.state.seals) {
|
||||||
conversation.state.seals.forEach(seal => {
|
conversation.state.seals.forEach(seal => {
|
||||||
if (seal.publicKey === account.state.sealKey.public) {
|
if (seal.publicKey === account.state.sealKey.public) {
|
||||||
sealabel = true;
|
sealable = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -72,7 +71,12 @@ export function useDetails() {
|
|||||||
updateState({ subjectUpdate });
|
updateState({ subjectUpdate });
|
||||||
},
|
},
|
||||||
saveSubject: async () => {
|
saveSubject: async () => {
|
||||||
|
if (state.locked) {
|
||||||
|
await conversation.actions.setSealedSubject(state.subjectUpdate, account.state.sealKey);
|
||||||
|
}
|
||||||
|
else {
|
||||||
await conversation.actions.setSubject(state.subjectUpdate);
|
await conversation.actions.setSubject(state.subjectUpdate);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
remove: async () => {
|
remove: async () => {
|
||||||
await conversation.actions.remove();
|
await conversation.actions.remove();
|
||||||
|
Loading…
Reference in New Issue
Block a user