@@ -2,13 +2,205 @@ let headers = require('../utils/headers.js');
22let variables = require ( '../utils/variables.js' ) ;
33
44class Notifications {
5+ async postReplyNotification ( after , count ) {
6+ if ( ! global . cookies ) {
7+ throw new Error ( 'Not logged in.' ) ;
8+ } else {
9+ headers . Cookie = global . cookies ;
10+ let info = await variables
11+ . fetch ( 'https://staging.repl.it/graphql' , {
12+ method : 'POST' ,
13+ headers,
14+ body : JSON . stringify ( {
15+ query : `
16+ query RepliedToPostNotification($after: String!, $count: Int!) {
17+ notifications(after: $after, count: $count) {
18+ items {
19+ ... on RepliedToPostNotification {
20+ id
21+ url
22+ text
23+ seen
24+ context
25+ creator {
26+ ${ variable . userAttributes }
27+ }
28+ timeCreated
29+ timeUpdated
30+ }
31+ }
32+ pageInfo {
33+ nextCursor
34+ }
35+ }
36+ }` ,
37+ variables : {
38+ after,
39+ count
40+ }
41+ } )
42+ } )
43+ . then ( res => res . json ( ) ) ;
44+
45+ if ( ! info . data . notifications ) {
46+ throw new Error ( `Cannot fetch notifications.` ) ;
47+ } else {
48+ return info . data . notifications ;
49+ }
50+ }
51+ }
52+
53+ async commentReplyNotification ( after , count ) {
54+ if ( ! global . cookies ) {
55+ throw new Error ( 'Not logged in.' ) ;
56+ } else {
57+ headers . Cookie = global . cookies ;
58+ let info = await variables
59+ . fetch ( 'https://staging.repl.it/graphql' , {
60+ method : 'POST' ,
61+ headers,
62+ body : JSON . stringify ( {
63+ query : `
64+ query RepliedToCommentNotification($after: String!, $count: Int!) {
65+ notifications(after: $after, count: $count) {
66+ items {
67+ ... on RepliedToCommentNotification {
68+ id
69+ url
70+ text
71+ seen
72+ context
73+ creator {
74+ ${ variable . userAttributes }
75+ }
76+ timeCreated
77+ timeUpdated
78+ }
79+ }
80+ pageInfo {
81+ nextCursor
82+ }
83+ }
84+ }` ,
85+ variables : {
86+ after,
87+ count
88+ }
89+ } )
90+ } )
91+ . then ( res => res . json ( ) ) ;
92+
93+ if ( ! info . data . notifications ) {
94+ throw new Error ( `Cannot fetch notifications.` ) ;
95+ } else {
96+ return info . data . notifications ;
97+ }
98+ }
99+ }
100+
101+ async postMentionedNotification ( after , count ) {
102+ if ( ! global . cookies ) {
103+ throw new Error ( 'Not logged in.' ) ;
104+ } else {
105+ headers . Cookie = global . cookies ;
106+ let info = await variables
107+ . fetch ( 'https://staging.repl.it/graphql' , {
108+ method : 'POST' ,
109+ headers,
110+ body : JSON . stringify ( {
111+ query : `
112+ query MentionedInPostNotification($after: String!, $count: Int!) {
113+ notifications(after: $after, count: $count) {
114+ items {
115+ ... on MentionedInPostNotification {
116+ id
117+ url
118+ text
119+ seen
120+ context
121+ creator {
122+ ${ variable . userAttributes }
123+ }
124+ timeCreated
125+ timeUpdated
126+ }
127+ }
128+ pageInfo {
129+ nextCursor
130+ }
131+ }
132+ }` ,
133+ variables : {
134+ after,
135+ count
136+ }
137+ } )
138+ } )
139+ . then ( res => res . json ( ) ) ;
140+
141+ if ( ! info . data . notifications ) {
142+ throw new Error ( `Cannot fetch notifications.` ) ;
143+ } else {
144+ return info . data . notifications ;
145+ }
146+ }
147+ }
148+
149+ async commentMentionedNotification ( after , count ) {
150+ if ( ! global . cookies ) {
151+ throw new Error ( 'Not logged in.' ) ;
152+ } else {
153+ headers . Cookie = global . cookies ;
154+ let info = await variables
155+ . fetch ( 'https://staging.repl.it/graphql' , {
156+ method : 'POST' ,
157+ headers,
158+ body : JSON . stringify ( {
159+ query : `
160+ query MentionedInCommentNotification($after: String!, $count: Int!) {
161+ notifications(after: $after, count: $count) {
162+ items {
163+ ... on MentionedInPostNotification {
164+ id
165+ url
166+ text
167+ seen
168+ context
169+ creator {
170+ ${ variable . userAttributes }
171+ }
172+ timeCreated
173+ timeUpdated
174+ }
175+ }
176+ pageInfo {
177+ nextCursor
178+ }
179+ }
180+ }` ,
181+ variables : {
182+ after,
183+ count
184+ }
185+ } )
186+ } )
187+ . then ( res => res . json ( ) ) ;
188+
189+ if ( ! info . data . notifications ) {
190+ throw new Error ( `Cannot fetch notifications.` ) ;
191+ } else {
192+ return info . data . notifications ;
193+ }
194+ }
195+ }
196+
5197 async answerNotification ( after , count ) {
6198 if ( ! global . cookies ) {
7199 throw new Error ( 'Not logged in.' ) ;
8200 } else {
9201 headers . Cookie = global . cookies ;
10202 let info = await variables
11- . fetch ( 'https://repl.it/graphql' , {
203+ . fetch ( 'https://staging. repl.it/graphql' , {
12204 method : 'POST' ,
13205 headers,
14206 body : JSON . stringify ( {
@@ -49,6 +241,102 @@ class Notifications {
49241 }
50242 }
51243 }
244+
245+ async multiplayerInviteNotification ( after , count ) {
246+ if ( ! global . cookies ) {
247+ throw new Error ( 'Not logged in.' ) ;
248+ } else {
249+ headers . Cookie = global . cookies ;
250+ let info = await variables
251+ . fetch ( 'https://staging.repl.it/graphql' , {
252+ method : 'POST' ,
253+ headers,
254+ body : JSON . stringify ( {
255+ query : `
256+ query MultiplayerInvitedNotification($after: String!, $count: Int!) {
257+ notifications(after: $after, count: $count) {
258+ items {
259+ ... on MultiplayerInvitedNotification {
260+ id
261+ url
262+ text
263+ seen
264+ context
265+ creator {
266+ ${ variable . userAttributes }
267+ }
268+ timeCreated
269+ timeUpdated
270+ }
271+ }
272+ pageInfo {
273+ nextCursor
274+ }
275+ }
276+ }` ,
277+ variables : {
278+ after,
279+ count
280+ }
281+ } )
282+ } )
283+ . then ( res => res . json ( ) ) ;
284+
285+ if ( ! info . data . notifications ) {
286+ throw new Error ( `Cannot fetch notifications.` ) ;
287+ } else {
288+ return info . data . notifications ;
289+ }
290+ }
291+ }
292+
293+ async allNotification ( after , count ) {
294+ if ( ! global . cookies ) {
295+ throw new Error ( 'Not logged in.' ) ;
296+ } else {
297+ headers . Cookie = global . cookies ;
298+ let info = await variables
299+ . fetch ( 'https://staging.repl.it/graphql' , {
300+ method : 'POST' ,
301+ headers,
302+ body : JSON . stringify ( {
303+ query : `
304+ query Notification($after: String!, $count: Int!) {
305+ notifications(after: $after, count: $count) {
306+ items {
307+ ... on Notification {
308+ id
309+ url
310+ text
311+ seen
312+ context
313+ creator {
314+ ${ variable . userAttributes }
315+ }
316+ timeCreated
317+ timeUpdated
318+ }
319+ }
320+ pageInfo {
321+ nextCursor
322+ }
323+ }
324+ }` ,
325+ variables : {
326+ after,
327+ count
328+ }
329+ } )
330+ } )
331+ . then ( res => res . json ( ) ) ;
332+
333+ if ( ! info . data . notifications ) {
334+ throw new Error ( `Cannot fetch notifications.` ) ;
335+ } else {
336+ return info . data . notifications ;
337+ }
338+ }
339+ }
52340}
53341
54342module . exports = {
0 commit comments