File tree Expand file tree Collapse file tree 6 files changed +72
-12
lines changed Expand file tree Collapse file tree 6 files changed +72
-12
lines changed Original file line number Diff line number Diff line change @@ -193,16 +193,16 @@ class Akun {
193
193
return this . _closeNode ( readerPostNodeId ) ;
194
194
}
195
195
196
- ban ( storyId , postId ) {
196
+ ban ( storyId , chatNodeId ) {
197
197
return this . core . post ( `/api/anonkun/ban` , {
198
- blockFor : postId ,
198
+ blockFor : chatNodeId ,
199
199
blockFrom : storyId
200
200
} , false ) ;
201
201
}
202
202
203
- unban ( storyId , postId ) {
203
+ unban ( storyId , chatNodeId ) {
204
204
return this . core . delete ( `/api/anonkun/ban` , {
205
- blockFor : postId ,
205
+ blockFor : chatNodeId ,
206
206
blockFrom : storyId
207
207
} , false ) ;
208
208
}
@@ -211,6 +211,14 @@ class Akun {
211
211
return this . core . get ( `/api/anonkun/story/bans/${ storyId } ` ) ;
212
212
}
213
213
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
+
214
222
_openNode ( nodeId ) {
215
223
return this . core . post ( `/api/anonkun/editChapter` , {
216
224
'_id' : nodeId ,
Original file line number Diff line number Diff line change @@ -92,6 +92,16 @@ class Node {
92
92
return this . _userName ;
93
93
}
94
94
95
+ /**
96
+ * The userId of the node creator
97
+ *
98
+ * @member {?string}
99
+ * @readonly
100
+ */
101
+ get userId ( ) {
102
+ return this . _userId ;
103
+ }
104
+
95
105
/**
96
106
* The avatar of the node creator
97
107
*
Original file line number Diff line number Diff line change @@ -96,6 +96,9 @@ class BaseThread extends events.EventEmitter {
96
96
}
97
97
98
98
async _newMessage ( data , notify = true ) {
99
+ if ( ! this . _checkBelongsInHistory ( data ) ) {
100
+ return ;
101
+ }
99
102
let nodeData = data ;
100
103
const nodeId = nodeData [ '_id' ] ;
101
104
const isUpdate = this . _isNodeUpdate ( nodeData ) ;
@@ -118,13 +121,21 @@ class BaseThread extends events.EventEmitter {
118
121
}
119
122
}
120
123
121
- _makeNode ( nodeData ) {
124
+ _checkBelongsInHistory ( nodeData ) {
122
125
switch ( true ) {
123
126
// Extend with type handlers
124
127
default :
125
128
if ( ! this . _akun . silent ) {
126
129
console . warn ( new Error ( `BaseThread received unrecognised nodeType '${ nodeData [ 'nt' ] } ':\n${ JSON . stringify ( nodeData , null , '\t' ) } ` ) ) ;
127
130
}
131
+ return true ;
132
+ }
133
+ }
134
+
135
+ _makeNode ( nodeData ) {
136
+ switch ( true ) {
137
+ // Extend with type handlers
138
+ default :
128
139
return new Node ( nodeData ) ;
129
140
}
130
141
}
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ function isChoice(nodeData) {
9
9
return nodeData [ 'nt' ] === 'choice' ;
10
10
}
11
11
12
+ function isTopic ( nodeData ) {
13
+ return nodeData [ 'nt' ] === 'post' ;
14
+ }
15
+
12
16
class ChatThread extends BaseThread {
13
17
constructor ( akun , nodeData ) {
14
18
super ( akun , nodeData ) ;
@@ -33,16 +37,30 @@ class ChatThread extends BaseThread {
33
37
super . _disconnect ( ) ;
34
38
}
35
39
36
- _makeNode ( nodeData ) {
40
+ _checkBelongsInHistory ( nodeData ) {
37
41
switch ( true ) {
38
42
case isChat ( nodeData ) :
39
- return new ChatNode ( nodeData ) ;
43
+ return true ;
40
44
case isChoice ( nodeData ) :
41
- return new ChoiceNode ( nodeData ) ;
45
+ return true ;
46
+ case isTopic ( nodeData ) :
47
+ // TODO handle topic node updates
48
+ return false ;
42
49
default :
43
50
if ( ! this . _akun . silent ) {
44
51
console . warn ( new Error ( `ChatThread received unrecognised nodeType '${ nodeData [ 'nt' ] } ':\n${ JSON . stringify ( nodeData , null , '\t' ) } ` ) ) ;
45
52
}
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 :
46
64
return new Node ( nodeData ) ;
47
65
}
48
66
}
Original file line number Diff line number Diff line change @@ -80,6 +80,22 @@ class StoryThread extends BaseThread {
80
80
super . _disconnect ( ) ;
81
81
}
82
82
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
+
83
99
_makeNode ( nodeData ) {
84
100
switch ( true ) {
85
101
case isChapter ( nodeData ) :
@@ -89,9 +105,6 @@ class StoryThread extends BaseThread {
89
105
case isReaderPost ( nodeData ) :
90
106
return new ReaderPostNode ( nodeData ) ;
91
107
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
108
return new Node ( nodeData ) ;
96
109
}
97
110
}
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " akun-api" ,
3
- "version" : " 4.1 .0" ,
3
+ "version" : " 4.2 .0" ,
4
4
"description" : " A module intended to enable easy interactions with Anonkun" ,
5
5
"main" : " index.js" ,
6
6
"type" : " module" ,
You can’t perform that action at this time.
0 commit comments