Skip to content

Commit 6cf8e8e

Browse files
committed
chats: interface and failing e2e test to post a new message
1 parent 801a85e commit 6cf8e8e

4 files changed

Lines changed: 72 additions & 1 deletion

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { setupModule } from "../test-support/setupModule";
2+
3+
describe("chats", () => {
4+
it("post a new message to a chat", async () => {
5+
const chats = setupModule();
6+
const chatUri = "http://localhost:3456/chats/QteE42/index.ttl#this";
7+
const messageUri = await chats.postMessage({
8+
chatUri,
9+
text: "Hello, world!",
10+
authorWebId: "https://localhost:3456/profile/card#me",
11+
});
12+
const chat = await chats.readChat(chatUri);
13+
expect(chat.latestMessages).toContain(
14+
expect.objectContaining({
15+
uri: messageUri,
16+
authorWebId: "https://localhost:3456/profile/card#me",
17+
text: "Hello, world!",
18+
}),
19+
);
20+
});
21+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<#this>
2+
a <http://www.w3.org/ns/pim/meeting#LongChat> ;
3+
<http://purl.org/dc/elements/1.1/title> "Post message test" .

chats/rdflib/src/index.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ export interface ChatsModule {
1515
* @param chatUri
1616
*/
1717
readChat(chatUri: string): Promise<Chat>;
18+
19+
/**
20+
* Post a new message to an existing chat
21+
* @param command
22+
* @return The URI of the newly created message
23+
*/
24+
postMessage(command: PostMessageCommand): Promise<string>;
1825
}
1926

2027
/**
@@ -53,8 +60,38 @@ export interface Chat {
5360
* Represents a message in a chat
5461
*/
5562
export interface Message {
63+
/**
64+
* URI identifying the message
65+
*/
5666
uri: string;
67+
/**
68+
* WebID of the message author
69+
*/
5770
authorWebId: string;
71+
/**
72+
* Text of the message
73+
*/
5874
text: string;
75+
/**
76+
* Date and time the message was posted
77+
*/
5978
date: Date;
6079
}
80+
81+
/**
82+
* Data needed to post a new message
83+
*/
84+
export interface PostMessageCommand {
85+
/**
86+
* URI of the chat to post to
87+
*/
88+
chatUri: string;
89+
/**
90+
* Text of the message to post
91+
*/
92+
text: string;
93+
/**
94+
* WebID of the message author
95+
*/
96+
authorWebId: string;
97+
}

chats/rdflib/src/module/ChatsModuleRdfLib.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { Chat, ChatsModule, CreateChatCommand } from "../index.js";
1+
import {
2+
Chat,
3+
ChatsModule,
4+
CreateChatCommand,
5+
PostMessageCommand,
6+
} from "../index.js";
27
import { Fetcher, IndexedFormula, NamedNode, sym, UpdateManager } from "rdflib";
38

49
import {
@@ -94,4 +99,9 @@ export class ChatsModuleRdfLib implements ChatsModule {
9499
await this.support.fetchNode(anyDocument);
95100
return anyDocument;
96101
}
102+
103+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
104+
postMessage(command: PostMessageCommand): Promise<string> {
105+
throw new Error("Method not implemented.");
106+
}
97107
}

0 commit comments

Comments
 (0)