Skip to content

Commit

Permalink
fixed frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
nicarq committed Sep 8, 2023
1 parent 78800ed commit 54ee4da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
16 changes: 12 additions & 4 deletions shinkai-app/src/components/ChatMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const ChatMessages: React.FC<ChatMessagesProps> = ({ deserializedId }) => {
);

const [lastKey, setLastKey] = useState<string | undefined>(undefined);
const [mostRecentKey, setMostRecentKey] = useState<string | undefined>(undefined);
const [prevMessagesLength, setPrevMessagesLength] = useState(0);
const [hasMoreMessages, setHasMoreMessages] = useState(true);
const [messages, setMessages] = useState<ShinkaiMessage[]>([]);
Expand All @@ -42,13 +43,13 @@ const ChatMessages: React.FC<ChatMessagesProps> = ({ deserializedId }) => {
console.log("Debug> Last Message:", lastMessage);
console.log("Debug> Last Message Content:", extractContent(lastMessage.body));
console.log("Debug> Hash Key from above:", hashKey);
console.log("Debug> Last key (stored):", lastKey);
console.log("Debug> Last key (stored):", mostRecentKey);
dispatch(
getLastUnreadMessagesFromInbox(deserializedId, 10, lastKey, setupDetailsState)
getLastUnreadMessagesFromInbox(deserializedId, 10, mostRecentKey, setupDetailsState)
);
}, 5000); // 2000 milliseconds = 2 seconds
return () => clearInterval(interval);
}, [dispatch, deserializedId, lastKey, setupDetailsState, reduxMessages]);
}, [dispatch, deserializedId, mostRecentKey, setupDetailsState, reduxMessages]);

useEffect(() => {
if (reduxMessages && reduxMessages.length > 0) {
Expand All @@ -57,8 +58,15 @@ const ChatMessages: React.FC<ChatMessagesProps> = ({ deserializedId }) => {
console.log("Last Message:", lastMessage);
const timeKey = lastMessage.external_metadata.scheduled_time;
const hashKey = calculateMessageHash(lastMessage);
const lastMessageKey = `${timeKey}:${hashKey}`;
const lastMessageKey = `${timeKey}:::${hashKey}`;
setLastKey(lastMessageKey);

const mostRecentMessage = reduxMessages[0];
const mostRecentTimeKey = mostRecentMessage.external_metadata.scheduled_time;
const mostRecentHashKey = calculateMessageHash(mostRecentMessage);
const mostRecentMessageKey = `${mostRecentTimeKey}:::${mostRecentHashKey}`;
setMostRecentKey(mostRecentMessageKey);

setMessages(reduxMessages);

if (reduxMessages.length - prevMessagesLength < 10) {
Expand Down
5 changes: 4 additions & 1 deletion src/db/db_inbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,14 @@ impl ShinkaiDB {
let offset_hash = match &from_offset_key {
Some(offset_key) => {
let split: Vec<&str> = offset_key.split(":::").collect();
if split.len() < 2 {
return Err(ShinkaiDBError::SomeError("Invalid offset key format".to_string()));
}
Some(split[1].to_string())
}
None => None,
};

let mut messages = Vec::new();
let mut first_message = true;
for item in iter.take(n) {
Expand Down

0 comments on commit 54ee4da

Please sign in to comment.