Skip to content

Commit 022e303

Browse files
committed
Fixed topic node updates being handled as unrecognised chat nodes and being added to chat history.
Added method for deleting chat posts from a story Added getter for a node's user id
1 parent f67ea2d commit 022e303

File tree

6 files changed

+72
-12
lines changed

6 files changed

+72
-12
lines changed

js/Akun.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,16 @@ class Akun {
193193
return this._closeNode(readerPostNodeId);
194194
}
195195

196-
ban(storyId, postId) {
196+
ban(storyId, chatNodeId) {
197197
return this.core.post(`/api/anonkun/ban`, {
198-
blockFor: postId,
198+
blockFor: chatNodeId,
199199
blockFrom: storyId
200200
}, false);
201201
}
202202

203-
unban(storyId, postId) {
203+
unban(storyId, chatNodeId) {
204204
return this.core.delete(`/api/anonkun/ban`, {
205-
blockFor: postId,
205+
blockFor: chatNodeId,
206206
blockFrom: storyId
207207
}, false);
208208
}
@@ -211,6 +211,14 @@ class Akun {
211211
return this.core.get(`/api/anonkun/story/bans/${storyId}`);
212212
}
213213

214+
deleteChatNodeFromStory(storyId, chatNodeId) {
215+
// Specific method name because deleting chapters and topic posts behave differently
216+
return this.core.delete(`/api/anonkun/node`, {
217+
deleteFrom: storyId,
218+
nid: chatNodeId
219+
}, false);
220+
}
221+
214222
_openNode(nodeId) {
215223
return this.core.post(`/api/anonkun/editChapter`, {
216224
'_id': nodeId,

js/nodes/Node.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ class Node {
9292
return this._userName;
9393
}
9494

95+
/**
96+
* The userId of the node creator
97+
*
98+
* @member {?string}
99+
* @readonly
100+
*/
101+
get userId(){
102+
return this._userId;
103+
}
104+
95105
/**
96106
* The avatar of the node creator
97107
*

js/threads/BaseThread.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class BaseThread extends events.EventEmitter {
9696
}
9797

9898
async _newMessage(data, notify = true) {
99+
if (!this._checkBelongsInHistory(data)) {
100+
return;
101+
}
99102
let nodeData = data;
100103
const nodeId = nodeData['_id'];
101104
const isUpdate = this._isNodeUpdate(nodeData);
@@ -118,13 +121,21 @@ class BaseThread extends events.EventEmitter {
118121
}
119122
}
120123

121-
_makeNode(nodeData) {
124+
_checkBelongsInHistory(nodeData) {
122125
switch (true) {
123126
// Extend with type handlers
124127
default:
125128
if (!this._akun.silent) {
126129
console.warn(new Error(`BaseThread received unrecognised nodeType '${nodeData['nt']}':\n${JSON.stringify(nodeData, null, '\t')}`));
127130
}
131+
return true;
132+
}
133+
}
134+
135+
_makeNode(nodeData) {
136+
switch (true) {
137+
// Extend with type handlers
138+
default:
128139
return new Node(nodeData);
129140
}
130141
}

js/threads/ChatThread.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ function isChoice(nodeData) {
99
return nodeData['nt'] === 'choice';
1010
}
1111

12+
function isTopic(nodeData) {
13+
return nodeData['nt'] === 'post';
14+
}
15+
1216
class ChatThread extends BaseThread {
1317
constructor(akun, nodeData) {
1418
super(akun, nodeData);
@@ -33,16 +37,30 @@ class ChatThread extends BaseThread {
3337
super._disconnect();
3438
}
3539

36-
_makeNode(nodeData) {
40+
_checkBelongsInHistory(nodeData) {
3741
switch (true) {
3842
case isChat(nodeData):
39-
return new ChatNode(nodeData);
43+
return true;
4044
case isChoice(nodeData):
41-
return new ChoiceNode(nodeData);
45+
return true;
46+
case isTopic(nodeData):
47+
// TODO handle topic node updates
48+
return false;
4249
default:
4350
if (!this._akun.silent) {
4451
console.warn(new Error(`ChatThread received unrecognised nodeType '${nodeData['nt']}':\n${JSON.stringify(nodeData, null, '\t')}`));
4552
}
53+
return true;
54+
}
55+
}
56+
57+
_makeNode(nodeData) {
58+
switch (true) {
59+
case isChat(nodeData):
60+
return new ChatNode(nodeData);
61+
case isChoice(nodeData):
62+
return new ChoiceNode(nodeData);
63+
default:
4664
return new Node(nodeData);
4765
}
4866
}

js/threads/StoryThread.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ class StoryThread extends BaseThread {
8080
super._disconnect();
8181
}
8282

83+
_checkBelongsInHistory(nodeData) {
84+
switch (true) {
85+
case isChapter(nodeData):
86+
return true;
87+
case isChoice(nodeData):
88+
return true;
89+
case isReaderPost(nodeData):
90+
return true;
91+
default:
92+
if (!this._akun.silent) {
93+
console.warn(new Error(`StoryThread received unrecognised nodeType '${nodeData['nt']}':\n${JSON.stringify(nodeData, null, '\t')}`));
94+
}
95+
return true;
96+
}
97+
}
98+
8399
_makeNode(nodeData) {
84100
switch (true) {
85101
case isChapter(nodeData):
@@ -89,9 +105,6 @@ class StoryThread extends BaseThread {
89105
case isReaderPost(nodeData):
90106
return new ReaderPostNode(nodeData);
91107
default:
92-
if (!this._akun.silent) {
93-
console.warn(new Error(`StoryThread received unrecognised nodeType '${nodeData['nt']}':\n${JSON.stringify(nodeData, null, '\t')}`));
94-
}
95108
return new Node(nodeData);
96109
}
97110
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "akun-api",
3-
"version": "4.1.0",
3+
"version": "4.2.0",
44
"description": "A module intended to enable easy interactions with Anonkun",
55
"main": "index.js",
66
"type": "module",

0 commit comments

Comments
 (0)