Skip to content

Commit 3190a6c

Browse files
committed
chats: add URI to message; extract MessageDocumentQuery
1 parent 71d9f03 commit 3190a6c

5 files changed

Lines changed: 40 additions & 24 deletions

File tree

chats/rdflib/src/e2e-tests/read-chat.e2e.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe("read a chat", () => {
2626
);
2727
expect(chat.latestMessages).toEqual([
2828
{
29+
uri: "http://localhost:3456/chats/eBIszJ/2024/07/01/chat.ttl#Msg1723225634153",
2930
text: "Hello visitor, welcome to my public chat lobby!",
3031
date: new Date("2024-07-01T17:47:14Z"),
3132
authorWebId: "http://localhost:3000/alice/profile/card#me",

chats/rdflib/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,9 @@ export interface Chat {
5252
/**
5353
* Represents a message in a chat
5454
*/
55-
export interface Message {}
55+
export interface Message {
56+
uri: string;
57+
authorWebId: string;
58+
text: string;
59+
date: Date;
60+
}

chats/rdflib/src/module/ChatsModuleRdfLib.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import { Chat, ChatsModule, CreateChatCommand } from "../index.js";
2-
import {
3-
Fetcher,
4-
IndexedFormula,
5-
NamedNode,
6-
Node,
7-
sym,
8-
UpdateManager,
9-
} from "rdflib";
2+
import { Fetcher, IndexedFormula, NamedNode, sym, UpdateManager } from "rdflib";
103

114
import {
125
ContainerQuery,
@@ -18,7 +11,7 @@ import {
1811
import { generateId } from "@solid-data-modules/rdflib-utils/identifier";
1912
import { createChat } from "./update-operations/index.js";
2013
import { ChatQuery } from "./queries/index.js";
21-
import { wf } from "./namespaces.js";
14+
import { MessagesDocumentQuery } from './queries/MessagesDocumentQuery.js';
2215

2316
interface ModuleConfig {
2417
store: IndexedFormula;
@@ -70,22 +63,13 @@ export class ChatsModuleRdfLib implements ChatsModule {
7063

7164
const latestMonth = await this.fetchLatestSubContainer(latestYear);
7265
const latestDay = await this.fetchLatestSubContainer(latestMonth);
73-
const chatDocument = await this.fetchLatestDocument(latestDay);
66+
const messagesDocument = await this.fetchLatestDocument(latestDay);
7467

75-
const messages: Node[] = this.store.each(
68+
return new MessagesDocumentQuery(
7669
chatNode,
77-
wf("message"),
78-
undefined,
79-
chatDocument,
80-
);
81-
82-
// TODO query actual message
83-
const latestMessages = messages.map((it) => ({
84-
text: "Hello visitor, welcome to my public chat lobby!",
85-
date: new Date("2024-07-01T17:47:14Z"),
86-
authorWebId: "http://localhost:3000/alice/profile/card#me",
87-
}));
88-
return latestMessages;
70+
messagesDocument,
71+
this.store,
72+
).queryMessages();
8973
}
9074

9175
private async fetchLatestSubContainer(container: NamedNode) {

chats/rdflib/src/module/_integration-tests/read-chat-integration.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ describe("read chat", () => {
103103
// then the message is part of the latest messages
104104
expect(chat.latestMessages).toEqual([
105105
{
106+
uri: "https://pod.test/alice/chats/abc123/2024/07/01/chat.ttl#Msg1723225634153",
106107
authorWebId: "http://localhost:3000/alice/profile/card#me",
107108
date: new Date("2024-07-01T17:47:14Z"),
108109
text: "Hello visitor, welcome to my public chat lobby!",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { IndexedFormula, NamedNode } from "rdflib";
2+
import { Message } from '../../index.js';
3+
import { wf } from '../namespaces.js';
4+
5+
export class MessagesDocumentQuery {
6+
constructor(
7+
private chatNode: NamedNode,
8+
private messagesDocument: NamedNode,
9+
private store: IndexedFormula,
10+
) {}
11+
12+
queryMessages(): Message[] {
13+
const messages: NamedNode[] = this.store
14+
.each(this.chatNode, wf("message"), undefined, this.messagesDocument)
15+
.map((it) => it as NamedNode);
16+
17+
// TODO query actual message
18+
return messages.map((it) => ({
19+
uri: it.uri,
20+
text: "Hello visitor, welcome to my public chat lobby!",
21+
date: new Date("2024-07-01T17:47:14Z"),
22+
authorWebId: "http://localhost:3000/alice/profile/card#me",
23+
}));
24+
}
25+
}

0 commit comments

Comments
 (0)