mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
merging sealed topic add
This commit is contained in:
parent
f5e27c80e1
commit
65c0afb313
@ -361,7 +361,7 @@ export function useCardContext() {
|
||||
return await setCardCloseMessage(server, message);
|
||||
},
|
||||
getCardImageUrl: (cardId) => {
|
||||
const { profileRevision } = cards.current.get(cardId)?.card || { };
|
||||
const { profileRevision } = cards.current.get(cardId)?.card || {};
|
||||
const { server, token } = access.current;
|
||||
return getCardImageUrl(server, token, cardId, profileRevision);
|
||||
},
|
||||
@ -371,17 +371,17 @@ export function useCardContext() {
|
||||
return await removeContactChannel(profile?.node, cardToken, channelId);
|
||||
},
|
||||
addTopic: async (cardId, channelId, type, message, files) => {
|
||||
const { detail, profile } = cards.current.get(cardId) || {};
|
||||
const { detail, profile } = cards.current.get(cardId)?.card || {};
|
||||
const cardToken = `${profile?.guid}.${detail?.token}`;
|
||||
const node = profile?.node;
|
||||
if (files?.length > 0) {
|
||||
const topicId = await addContactChannelTopic(node, token, channelId, null, null, null);
|
||||
upload.actions.addContactTopic(node, token, cardId, channelId, topicId, files, async (assets) => {
|
||||
const topicId = await addContactChannelTopic(node, cardToken, channelId, null, null, null);
|
||||
upload.actions.addContactTopic(node, cardToken, cardId, channelId, topicId, files, async (assets) => {
|
||||
const subject = message(assets);
|
||||
await setContactChannelTopicSubject(node, token, channelId, topicId, type, subject);
|
||||
await setContactChannelTopicSubject(node, cardToken, channelId, topicId, type, subject);
|
||||
}, async () => {
|
||||
try {
|
||||
await removeContactChannelTopic(node, token, channelId, topicId);
|
||||
await removeContactChannelTopic(node, cardToken, channelId, topicId);
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
@ -390,7 +390,7 @@ export function useCardContext() {
|
||||
}
|
||||
else {
|
||||
const subject = message([]);
|
||||
await addContactChannelTopic(node, token, channelId, type, subject, []);
|
||||
await addContactChannelTopic(node, cardToken, channelId, type, subject, []);
|
||||
}
|
||||
},
|
||||
removeTopic: async (cardId, channelId, topicId) => {
|
||||
|
@ -61,7 +61,6 @@ export function useConversationContext() {
|
||||
const cardValue = cardId ? card.state.cards.get(cardId) : null;
|
||||
const channelValue = cardId ? cardValue?.channels.get(channelId) : channel.state.channels.get(channelId);
|
||||
const { topicRevision } = channelValue || {};
|
||||
let setChannel = false;
|
||||
|
||||
if (channelValue) {
|
||||
if (!loaded.current) {
|
||||
@ -76,9 +75,6 @@ export function useConversationContext() {
|
||||
curTopicMarker.current = topicMarker;
|
||||
loaded.current = true;
|
||||
}
|
||||
else {
|
||||
setChannel = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log("failed to load conversation");
|
||||
@ -93,25 +89,20 @@ export function useConversationContext() {
|
||||
await setMarkerAndSync(cardId, channelId, delta.marker, topicRevision);
|
||||
curTopicMarker.current = delta.marker;
|
||||
curSyncRevision.current = topicRevision;
|
||||
updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue });
|
||||
}
|
||||
else if (loadMore && marker) {
|
||||
if (loadMore && marker) {
|
||||
const delta = await getTopicDelta(cardId, channelId, null, COUNT, null, curTopicMarker.current);
|
||||
await setTopicDelta(cardId, channelId, delta.topics);
|
||||
await setTopicMarker(cardId, channelId, delta.marker);
|
||||
curTopicMarker.current = delta.marker;
|
||||
updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue });
|
||||
}
|
||||
else if (ignoreRevision || topicRevision !== curSyncRevision.current) {
|
||||
if (ignoreRevision || topicRevision > curSyncRevision.current) {
|
||||
const delta = await getTopicDelta(cardId, channelId, curSyncRevision.current, null, curTopicMarker.current, null);
|
||||
await setTopicDelta(cardId, channelId, delta.topics);
|
||||
await setSyncRevision(cardId, channelId, topicRevision);
|
||||
curSyncRevision.current = topicRevision;
|
||||
updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue });
|
||||
}
|
||||
else if (setChannel) {
|
||||
updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue });
|
||||
await setSyncRevision(cardId, channelId, delta.revision);
|
||||
curSyncRevision.current = delta.revision;
|
||||
}
|
||||
updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue });
|
||||
}
|
||||
catch(err) {
|
||||
console.log(err);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useEffect, useState, useRef, useContext } from 'react';
|
||||
import SQLite from "react-native-sqlite-storage";
|
||||
|
||||
const DATABAG_DB = 'db_v_115.db';
|
||||
const DATABAG_DB = 'db_v_116.db';
|
||||
|
||||
export function useStoreContext() {
|
||||
const [state, setState] = useState({});
|
||||
|
@ -159,7 +159,7 @@ export function AddTopic({ sealed, sealKey }) {
|
||||
<View style={styles.space} />
|
||||
<TouchableOpacity style={styles.addButton} onPress={sendMessage}>
|
||||
{ state.busy && (
|
||||
<ActivityIndicator color={Colors.white} />
|
||||
<ActivityIndicator color={Colors.primary} />
|
||||
)}
|
||||
{ !state.busy && (state.message || state.assets.length > 0) && (
|
||||
<MatIcons name="send-outline" size={20} color={Colors.text} />
|
||||
|
@ -2,6 +2,8 @@ import { useState, useRef, useEffect, useContext } from 'react';
|
||||
import { ConversationContext } from 'context/ConversationContext';
|
||||
import { Image } from 'react-native';
|
||||
import Colors from 'constants/Colors';
|
||||
import { getChannelSeals, getContentKey, encryptTopicSubject } from 'context/sealUtil';
|
||||
import { AccountContext } from 'context/AccountContext';
|
||||
|
||||
export function useAddTopic(sealed, sealKey) {
|
||||
|
||||
@ -23,6 +25,7 @@ export function useAddTopic(sealed, sealKey) {
|
||||
|
||||
const assetId = useRef(0);
|
||||
const conversation = useContext(ConversationContext);
|
||||
const account = useContext(AccountContext);
|
||||
|
||||
const updateState = (value) => {
|
||||
setState((s) => ({ ...s, ...value }));
|
||||
@ -107,17 +110,43 @@ export function useAddTopic(sealed, sealKey) {
|
||||
if (!state.busy) {
|
||||
try {
|
||||
updateState({ busy: true });
|
||||
let message = {
|
||||
text: state.message,
|
||||
textColor: state.colorSet ? state.color : null,
|
||||
textSize: state.sizeSet ? state.size : null,
|
||||
|
||||
let contentKey;
|
||||
const type = conversation.state.channel?.detail?.dataType === 'superbasic' ? 'superbasictopic' : 'sealedtopic';
|
||||
if (type === 'sealedtopic') {
|
||||
const channelDetail = conversation.state.channel?.detail;
|
||||
const seals = getChannelSeals(channelDetail?.data);
|
||||
const sealKey = account.state.sealKey;
|
||||
contentKey = await getContentKey(seals, sealKey);
|
||||
}
|
||||
const assemble = (assets) => {
|
||||
if (type === 'superbasictopic') {
|
||||
if (assets?.length) {
|
||||
return {
|
||||
assets,
|
||||
text: state.message,
|
||||
textColor: state.colorSet ? state.color : null,
|
||||
textSize: state.sizeSet ? state.size : null,
|
||||
}
|
||||
}
|
||||
else {
|
||||
return {
|
||||
text: state.message,
|
||||
textColor: state.colorSet ? state.color : null,
|
||||
textSize: state.sizeSet ? state.size : null,
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const message = {
|
||||
text: state.message,
|
||||
textColor: state.textColorSet ? state.textColor : null,
|
||||
textSize: state.textSizeSet ? state.textSize : null,
|
||||
}
|
||||
return encryptTopicSubject({ message }, contentKey);
|
||||
}
|
||||
};
|
||||
if (sealed) {
|
||||
await conversation.actions.addSealedTopic(message, sealKey);
|
||||
}
|
||||
else {
|
||||
await conversation.actions.addTopic(message, state.assets);
|
||||
}
|
||||
await conversation.actions.addTopic(type, assemble, state.assets);
|
||||
updateState({ busy: false, assets: [], message: null,
|
||||
size: 'medium', sizeSet: false, textSize: 14,
|
||||
color: Colors.text, colorSet: false,
|
||||
|
@ -205,7 +205,9 @@ export function Details({ channel, clearConversation }) {
|
||||
<TouchableOpacity onPress={() => setNotifications(!state.notification)} activeOpacity={1}>
|
||||
<Text style={styles.notifyText}>Enable Notifications</Text>
|
||||
</TouchableOpacity>
|
||||
<Switch style={styles.switch} value={state.notification} onValueChange={setNotifications} trackColor={styles.track}/>
|
||||
{ state.notification != null && (
|
||||
<Switch style={styles.switch} value={state.notification} onValueChange={setNotifications} trackColor={styles.track}/>
|
||||
)}
|
||||
</View>
|
||||
|
||||
</View>
|
||||
|
@ -14,6 +14,7 @@ export const styles = StyleSheet.create({
|
||||
paddingTop: 16,
|
||||
flexShrink: 1,
|
||||
minWidth: 0,
|
||||
maxWidth: '80%',
|
||||
},
|
||||
info: {
|
||||
paddingLeft: 8,
|
||||
|
@ -29,6 +29,7 @@ export function useDetails() {
|
||||
deleteBusy: false,
|
||||
blockBusy: false,
|
||||
unknown: 0,
|
||||
notification: null,
|
||||
});
|
||||
|
||||
const card = useContext(CardContext);
|
||||
|
Loading…
Reference in New Issue
Block a user