diff --git a/app/mobile/src/api/getContactChannelTopics.js b/app/mobile/src/api/getContactChannelTopics.js
index b63a3b8f..cef507d2 100644
--- a/app/mobile/src/api/getContactChannelTopics.js
+++ b/app/mobile/src/api/getContactChannelTopics.js
@@ -2,9 +2,6 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getContactChannelTopics(server, token, channelId, revision, count, begin, end) {
-console.log("GETTING:", revision, count, begin, end);
-
-
let rev = ''
if (revision != null) {
rev = `&revision=${revision}`
@@ -25,8 +22,6 @@ console.log("GETTING:", revision, count, begin, end);
{ method: 'GET' });
checkResponse(topics)
-console.log(topics.headers);
-
return {
marker: topics.headers.get('topic-marker'),
revision: topics.headers.get('topic-revision'),
diff --git a/app/mobile/src/context/useAppContext.hook.js b/app/mobile/src/context/useAppContext.hook.js
index d2cd77c9..f1a57bec 100644
--- a/app/mobile/src/context/useAppContext.hook.js
+++ b/app/mobile/src/context/useAppContext.hook.js
@@ -156,7 +156,6 @@ export function useAppContext() {
const setWebsocket = (session) => {
ws.current = createWebsocket(`wss://${session.server}/status`);
ws.current.onmessage = (ev) => {
-console.log("ON MESSAGE!");
try {
delay.current = 0;
const rev = JSON.parse(ev.data);
diff --git a/app/mobile/src/context/useConversationContext.hook.js b/app/mobile/src/context/useConversationContext.hook.js
index f027765b..d5f1b8d7 100644
--- a/app/mobile/src/context/useConversationContext.hook.js
+++ b/app/mobile/src/context/useConversationContext.hook.js
@@ -14,7 +14,6 @@ export function useConversationContext() {
topics: new Map(),
card: null,
channel: null,
- notification: null,
});
const card = useContext(CardContext);
const channel = useContext(ChannelContext);
@@ -39,7 +38,6 @@ export function useConversationContext() {
if (!syncing.current && (reset.current || update.current || force.current || more.current)) {
-console.log("SYNCING!", reset.current, update.current, force.current, more.current);
const loadMore = more.current;
const ignoreRevision = force.current;
const conversation = conversationId.current;
@@ -53,6 +51,9 @@ console.log("SYNCING!", reset.current, update.current, force.current, more.curre
reset.current = false;
loaded.current = false;
topics.current = new Map();
+ if (!conversation) {
+ updateState({ offsync: false, topics: topics.current, card: null, channel: null });
+ }
}
if (conversation) {
@@ -74,9 +75,6 @@ console.log("SYNCING!", reset.current, update.current, force.current, more.curre
curTopicMarker.current = topicMarker;
loaded.current = true;
}
- else {
- updateState({ card: cardValue, channel: channelValue });
- }
}
else {
console.log("failed to load conversation");
@@ -86,28 +84,25 @@ console.log("SYNCING!", reset.current, update.current, force.current, more.curre
try {
if (!curTopicMarker.current) {
-console.log("FIRST GET");
const delta = await getTopicDelta(cardId, channelId, null, COUNT, null, null);
await setTopicDelta(cardId, channelId, delta.topics);
await setMarkerAndSync(cardId, channelId, delta.marker, topicRevision);
curTopicMarker.current = delta.marker;
-console.log("---", delta);
curSyncRevision.current = topicRevision;
}
if (loadMore && marker) {
-console.log("MORE GET");
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;
}
if (ignoreRevision || topicRevision !== curSyncRevision.current) {
-console.log("UPDATE");
- const delta = await getTopicDelta(cardId, channelId, curSyncRevision.currnet, null, curTopicMarker.current, null);
+ 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 });
}
catch(err) {
console.log(err);
@@ -132,7 +127,7 @@ console.log("UPDATE");
}
else {
const topic = await getTopic(cardId, channelId, entry.id);
- const item = mapTopicEntry(entry);
+ const item = mapTopicEntry(topic);
setTopicItem(cardId, channelId, item);
topics.current.set(item.topicId, item);
}
@@ -142,7 +137,6 @@ console.log("UPDATE");
clearTopicItem(entry.id);
}
}
- updateState({ offsync: false, topics: topics.current });
}
useEffect(() => {
@@ -153,13 +147,11 @@ console.log("UPDATE");
const actions = {
setConversation: async (cardId, channelId) => {
-console.log(">>> SET");
conversationId.current = { cardId, channelId };
reset.current = true;
await sync();
},
clearConversation: async () => {
-console.log(">>> CLEAR");
conversationId.current = null;
reset.current = true;
await sync();
@@ -285,7 +277,7 @@ console.log(">>> CLEAR");
else if (channelId) {
await channel.actions.setUnsealedTopicSubject(channelId, topicId, revision, unsealed);
}
- setTopicField(topicId, 'unsaledDetail', unsealed);
+ setTopicField(topicId, 'unsealedDetail', unsealed);
},
setTopicSubject: async (topicId, type, subject) => {
const { cardId, channelId } = conversationId.current || {};
diff --git a/app/mobile/src/context/useStoreContext.hook.js b/app/mobile/src/context/useStoreContext.hook.js
index 88992019..a14c199d 100644
--- a/app/mobile/src/context/useStoreContext.hook.js
+++ b/app/mobile/src/context/useStoreContext.hook.js
@@ -1,7 +1,7 @@
import { useEffect, useState, useRef, useContext } from 'react';
import SQLite from "react-native-sqlite-storage";
-const DATABAG_DB = 'db_v_114.db';
+const DATABAG_DB = 'db_v_115.db';
export function useStoreContext() {
const [state, setState] = useState({});
diff --git a/app/mobile/src/session/Session.jsx b/app/mobile/src/session/Session.jsx
index 9a88c534..ee54e2be 100644
--- a/app/mobile/src/session/Session.jsx
+++ b/app/mobile/src/session/Session.jsx
@@ -43,11 +43,11 @@ export function Session() {
const screenParams = { headerShown: true, headerTintColor: Colors.primary };
const ConversationStackScreen = () => {
+ const conversation = useContext(ConversationContext);
const [cardId, setCardId] = useState();
const [channelId, setChannelId] = useState();
-
- const setConversation = (card, channel) => {
+ const openConversation = (navigation, card, channel) => {
(async () => {
conversation.actions.setConversation(card, channel);
setCardId(card);
@@ -55,13 +55,17 @@ export function Session() {
navigation.navigate('conversation');
})();
};
- const closeConversation = () => {
- console.log("CLOSE CALLED!");
+ const clearConversation = (navigation) => {
conversation.actions.clearConversation();
setCardId(null);
setChannelId(null);
navigation.popToTop();
};
+ const closeConversation = () => {
+ conversation.actions.clearConversation();
+ setCardId(null);
+ setChannelId(null);
+ }
const openDetails = (navigation) => {
navigation.navigate('details');
@@ -75,13 +79,13 @@ export function Session() {
- {(props) => openDetails(props.navigation)} closeConversation={closeConversation} /> }
+ {(props) => openDetails(props.navigation)} closeConversation={(pop) => closeConversation(props.navigation, pop)} /> }
(
Details
)}}>
- {(props) => closeConversation(props.navigation)} />}
+ {(props) => clearConversation(props.navigation)} />}
@@ -162,7 +166,6 @@ export function Session() {
})();
};
const closeConversation = () => {
- console.log("CLOSE CALLED!");
conversation.actions.clearConversation();
setCardId(null);
setChannelId(null);
diff --git a/app/mobile/src/session/conversation/topicItem/TopicItem.jsx b/app/mobile/src/session/conversation/topicItem/TopicItem.jsx
index 1f7872f2..d8c0cff7 100644
--- a/app/mobile/src/session/conversation/topicItem/TopicItem.jsx
+++ b/app/mobile/src/session/conversation/topicItem/TopicItem.jsx
@@ -14,9 +14,9 @@ import { AudioAsset } from './audioAsset/AudioAsset';
import { VideoAsset } from './videoAsset/VideoAsset';
import Carousel from 'react-native-reanimated-carousel';
-export function TopicItem({ item, focused, focus, hosting, sealed, sealKey, remove, update, block, report }) {
+export function TopicItem({ item, focused, focus, hosting, remove, update, block, report, contentKey }) {
- const { state, actions } = useTopicItem(item, hosting, remove, sealed, sealKey);
+ const { state, actions } = useTopicItem(item, hosting, remove, contentKey);
const erase = () => {
Alert.alert(
diff --git a/app/mobile/src/session/conversation/topicItem/useTopicItem.hook.js b/app/mobile/src/session/conversation/topicItem/useTopicItem.hook.js
index 46cf6104..9165ca1f 100644
--- a/app/mobile/src/session/conversation/topicItem/useTopicItem.hook.js
+++ b/app/mobile/src/session/conversation/topicItem/useTopicItem.hook.js
@@ -2,12 +2,14 @@ import { useState, useEffect, useContext } from 'react';
import { ConversationContext } from 'context/ConversationContext';
import { CardContext } from 'context/CardContext';
import { ProfileContext } from 'context/ProfileContext';
+import { AccountContext } from 'context/AccountContext';
import moment from 'moment';
import { useWindowDimensions } from 'react-native';
import Colors from 'constants/Colors';
import { getCardByGuid } from 'context/cardUtil';
+import { getChannelSeals, isUnsealed, getContentKey, decryptTopicSubject } from 'context/sealUtil';
-export function useTopicItem(item, hosting, remove, sealed, sealKey) {
+export function useTopicItem(item, hosting, remove, contentKey) {
const [state, setState] = useState({
name: null,
@@ -31,6 +33,7 @@ export function useTopicItem(item, hosting, remove, sealed, sealKey) {
const conversation = useContext(ConversationContext);
const profile = useContext(ProfileContext);
const card = useContext(CardContext);
+ const account = useContext(AccountContext);
const dimensions = useWindowDimensions();
const updateState = (value) => {
@@ -42,8 +45,9 @@ export function useTopicItem(item, hosting, remove, sealed, sealKey) {
}, [dimensions]);
useEffect(() => {
- const { topicId, detail, unsealedDetail } = item;
- const { guid, dataType, data, status, transform } = detail;
+
+ const { topicId, revision, detail, unsealedDetail } = item;
+ const { guid, created, dataType, data, status, transform } = detail || {};
let name, nameSet, known, logo;
const identity = profile.state?.identity;
@@ -135,13 +139,13 @@ export function useTopicItem(item, hosting, remove, sealed, sealKey) {
}
}
else {
- conversation.actions.unsealTopic(topicId, sealKey);
sealed = true;
+ unsealTopic(topicId, revision, detail);
}
}
let timestamp;
- const date = new Date(item.detail.created * 1000);
+ const date = new Date(created * 1000);
const now = new Date();
const offset = now.getTime() - date.getTime();
if(offset < 86400000) {
@@ -154,11 +158,27 @@ export function useTopicItem(item, hosting, remove, sealed, sealKey) {
timestamp = moment(date).format('M/DD/YYYY');
}
- const editable = detail.guid === identity.guid && parsed;
+ const editable = guid === identity?.guid && parsed;
const deletable = editable || hosting;
updateState({ logo, name, nameSet, known, sealed, message, fontSize, fontColor, timestamp, transform, status, assets, deletable, editable, editData: parsed, editMessage: message });
- }, [sealKey, card, item]);
+ }, [conversation.state, card.state, account.state, item]);
+
+ const unsealTopic = async (topicId, revision, topicDetail) => {
+ try {
+ const channelDetail = conversation.state.channel?.detail;
+ const seals = getChannelSeals(channelDetail?.data);
+ const sealKey = account.state.sealKey;
+ if (isUnsealed(seals, sealKey)) {
+ const contentKey = await getContentKey(seals, sealKey);
+ const unsealed = decryptTopicSubject(topicDetail.data, contentKey);
+ await conversation.actions.unsealTopic(topicId, revision, unsealed);
+ }
+ }
+ catch(err) {
+ console.log(err);
+ }
+ };
const actions = {
showCarousel: (index) => {
diff --git a/app/mobile/src/session/conversation/useConversation.hook.js b/app/mobile/src/session/conversation/useConversation.hook.js
index d5a2a578..26cfefb6 100644
--- a/app/mobile/src/session/conversation/useConversation.hook.js
+++ b/app/mobile/src/session/conversation/useConversation.hook.js
@@ -1,6 +1,7 @@
-import { useEffect, useState, useContext } from 'react';
+import { useEffect, useState, useContext, useRef } from 'react';
import { ProfileContext } from 'context/ProfileContext';
import { CardContext } from 'context/CardContext';
+import { AccountContext } from 'context/AccountContext';
import { ConversationContext } from 'context/ConversationContext';
import { getChannelSubjectLogo } from 'context/channelUtil';
@@ -17,6 +18,7 @@ export function useConversation() {
const profile = useContext(ProfileContext);
const card = useContext(CardContext);
const conversation = useContext(ConversationContext);
+ const account = useContext(AccountContext);
useEffect(() => {
const cardId = conversation.state.card?.cardId;
@@ -41,9 +43,7 @@ export function useConversation() {
const filtered = sorted.filter(item => !(item.blocked === 1));
updateState({ logo, subject, topics: filtered });
-
-console.log("UPDATE TOPICS", filtered.length);
- }, [conversation.state, card.state, profile.state]);
+ }, [conversation.state, profile.state]);
const actions = {};
diff --git a/app/mobile/src/session/details/useDetails.hook.js b/app/mobile/src/session/details/useDetails.hook.js
index 80ecda51..660e75b7 100644
--- a/app/mobile/src/session/details/useDetails.hook.js
+++ b/app/mobile/src/session/details/useDetails.hook.js
@@ -40,12 +40,19 @@ export function useDetails() {
setState((s) => ({ ...s, ...value }));
}
+ useEffect(() => {
+ (async () => {
+ const notification = await conversation.actions.getNotifications();
+ updateState({ notification });
+ })();
+ }, []);
+
useEffect(() => {
let locked;
let unlocked;
let seals;
let sealKey;
- const { channel, notification } = conversation.state;
+ const { channel } = conversation.state;
if (channel?.detail?.dataType === 'sealed') {
locked = true;
try {
@@ -62,7 +69,7 @@ export function useDetails() {
locked = false;
unlocked = false;
}
- updateState({ locked, unlocked, seals, sealKey, notification });
+ updateState({ locked, unlocked, seals, sealKey });
}, [account.state, conversation.state]);
const setMemberItem = (contact, guids) => {
@@ -223,6 +230,7 @@ export function useDetails() {
},
setNotifications: async (notification) => {
await conversation.actions.setNotifications(notification);
+ updateState({ notification });
},
};