Skip to content

Commit

Permalink
Iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
serefyarar committed Jun 16, 2024
1 parent 929768c commit 15d116c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 34 deletions.
6 changes: 3 additions & 3 deletions api/src/controllers/conversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ export const updates = async (req, res) => {
);
const conversation = await conversationService.getConversation(id);
if (!conversation) {
res.end();
return res.end();
}
} catch (error) {
res.status(500).json({ error: error.message });
return res.status(500).json({ error: error.message });
}
res.setHeader("Content-Type", "text/event-stream");
res.setHeader("Cache-Control", "no-cache");
Expand All @@ -71,7 +71,7 @@ export const updates = async (req, res) => {

// Cleanup on client disconnect
req.on("close", () => {
pubSubClient.pUnsubscribe(`agentStream:${conversationId}:*`, handleMessage);
pubSubClient.pUnsubscribe(`agentStream:${id}:*`, handleMessage);
res.end();
});
};
Expand Down
16 changes: 15 additions & 1 deletion api/src/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { getRolesFromSession } from "../libs/lit/index.js";
import { DIDService } from "../services/did.js";
import { IndexService } from "../services/index.js";
import RedisClient from "../clients/redis.js";

export const getRolesFromSession = (index, session, definition) => {
if (
session.cacao.p.resources.indexOf("ceramic://*") > -1 &&
index.controllerDID.id == session.did.parent
) {
return {
owner: true,
creator: false,
};
}
return {
owner: false,
creator: false,
};
};
const redis = RedisClient.getInstance();

export const getIndexById = async (req, res, next) => {
Expand Down
16 changes: 0 additions & 16 deletions api/src/libs/lit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,19 +621,3 @@ export const getPKPSessionWithLIT = async (session, index) => {
console.log("Error", e);
}
};

export const getRolesFromSession = (index, session, definition) => {
if (
session.cacao.p.resources.indexOf("ceramic://*") > -1 &&
index.controllerDID.id == session.did.parent
) {
return {
owner: true,
creator: false,
};
}
return {
owner: false,
creator: false,
};
};
27 changes: 15 additions & 12 deletions api/src/services/conversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,12 @@ export class ConversationService {
delete node.metadata;

const messages = await Promise.all(
node.messages.edges
.map(async (edge) => {
const decryptedContent = await decryptJWE(
this.did,
edge.node.content,
);
return { ...edge.node, ...decryptedContent };
})
.filter((m) => !m.content && m.deletedAt === null),
node.messages.edges.map(async (edge) => {
const decryptedContent = await decryptJWE(this.did, edge.node.content);
return { ...edge.node, ...decryptedContent };
}),
);
node.messages = messages;
node.messages = messages.filter((m) => m.role && m.deletedAt === null);
return node;
}

Expand All @@ -77,7 +72,11 @@ export class ConversationService {
query {
viewer {
... on CeramicAccount {
conversationList(first: 1000) {
conversationList(first: 1000, filters: {
where: {
deletedAt: {isNull: true}
}
}) {
edges {
node {
id
Expand Down Expand Up @@ -270,7 +269,11 @@ export class ConversationService {
}
if (conversation && conversation.messages) {
for (const message of conversation.messages) {
await this.deleteMessage(id, message.id);
try {
await this.deleteMessage(id, message.id);
} catch (e) {
console.error(e);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const decryptJWE = async (did, str) => {
const decryptedData = await did.decryptDagJWE(parsedStr);
return decryptedData;
} catch (error) {
console.error("Failed to decrypt JWE:", error);
console.error("Failed to decrypt JWE:", error.message);
}
};
export const createDagJWE = async (owner, dids, cleartext) => {
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/context/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export const AppContextProvider = ({ children }: AppContextProviderProps) => {
useEffect(() => {
// const newChatID = uuidv4();
const newChatID =
"kjzl6kcym7w8yavyrq0oqt0pziy2aqhu1vqwptjo4m6k4zdn8xy0pebyqt8hk7p";
"kjzl6kcym7w8y4z06z2gv3ulgup1l1onjkbog02uai6ktw30uxbqi8jm9f75epg";
localStorage.setItem("chatterID", newChatID);
setChatID(newChatID);
}, [id]);
Expand Down

0 comments on commit 15d116c

Please sign in to comment.