@@ -259,7 +259,12 @@ function onEndShowFooter($action) {
259
259
$ note ->user_id = $ user ->id ;
260
260
$ note ->type = 'grouppost ' ;
261
261
$ note ->arg = $ action ->group ->id ;
262
- $ note ->delete ();
262
+ if ($ note ->delete ()) {
263
+ // Clear the user's notification cache
264
+ $ cache = Cache::instance ();
265
+ $ key = Cache::key ('usernotifications: ' .$ user ->id );
266
+ $ cache ->delete ($ key );
267
+ }
263
268
264
269
return true ;
265
270
}
@@ -269,7 +274,12 @@ function onEndShowFooter($action) {
269
274
$ note ->user_id = $ user ->id ;
270
275
$ note ->type = 'groupjoin ' ;
271
276
$ note ->arg = $ action ->group ->id ;
272
- $ note ->delete ();
277
+ if ($ note ->delete ()) {
278
+ // Clear the user's notification cache
279
+ $ cache = Cache::instance ();
280
+ $ key = Cache::key ('usernotifications: ' .$ user ->id );
281
+ $ cache ->delete ($ key );
282
+ }
273
283
274
284
return true ;
275
285
}
@@ -279,7 +289,12 @@ function onEndShowFooter($action) {
279
289
$ note ->user_id = $ user ->id ;
280
290
$ note ->type = 'grouprequest ' ;
281
291
$ note ->arg = $ action ->group ->id ;
282
- $ note ->delete ();
292
+ if ($ note ->delete ()) {
293
+ // Clear the user's notification cache
294
+ $ cache = Cache::instance ();
295
+ $ key = Cache::key ('usernotifications: ' .$ user ->id );
296
+ $ cache ->delete ($ key );
297
+ }
283
298
284
299
return true ;
285
300
}
@@ -288,7 +303,12 @@ function onEndShowFooter($action) {
288
303
$ note = new User_notification ();
289
304
$ note ->user_id = $ user ->id ;
290
305
$ note ->type = 'subscribe ' ;
291
- $ note ->delete ();
306
+ if ($ note ->delete ()) {
307
+ // Clear the user's notification cache
308
+ $ cache = Cache::instance ();
309
+ $ key = Cache::key ('usernotifications: ' .$ user ->id );
310
+ $ cache ->delete ($ key );
311
+ }
292
312
293
313
return true ;
294
314
}
@@ -297,7 +317,12 @@ function onEndShowFooter($action) {
297
317
$ note = new User_notification ();
298
318
$ note ->user_id = $ user ->id ;
299
319
$ note ->type = 'message ' ;
300
- $ note ->delete ();
320
+ if ($ note ->delete ()) {
321
+ // Clear the user's notification cache
322
+ $ cache = Cache::instance ();
323
+ $ key = Cache::key ('usernotifications: ' .$ user ->id );
324
+ $ cache ->delete ($ key );
325
+ }
301
326
302
327
return true ;
303
328
}
@@ -306,7 +331,12 @@ function onEndShowFooter($action) {
306
331
$ note = new User_notification ();
307
332
$ note ->user_id = $ user ->id ;
308
333
$ note ->type = 'mention ' ;
309
- $ note ->delete ();
334
+ if ($ note ->delete ()) {
335
+ // Clear the user's notification cache
336
+ $ cache = Cache::instance ();
337
+ $ key = Cache::key ('usernotifications: ' .$ user ->id );
338
+ $ cache ->delete ($ key );
339
+ }
310
340
311
341
return true ;
312
342
}
@@ -316,17 +346,37 @@ function onEndShowFooter($action) {
316
346
$ note ->user_id = $ user ->id ;
317
347
$ note ->type = 'mention ' ;
318
348
$ note ->arg = $ action ->notice ->id ;
319
- $ note ->delete ();
349
+ if ($ note ->delete ()) {
350
+ // Clear the user's notification cache
351
+ $ cache = Cache::instance ();
352
+ $ key = Cache::key ('usernotifications: ' .$ user ->id );
353
+ $ cache ->delete ($ key );
354
+ }
320
355
$ note ->type = 'favorite ' ;
321
- $ note ->delete ();
356
+ if ($ note ->delete ()) {
357
+ // Clear the user's notification cache
358
+ $ cache = Cache::instance ();
359
+ $ key = Cache::key ('usernotifications: ' .$ user ->id );
360
+ $ cache ->delete ($ key );
361
+ }
322
362
$ note ->type = 'repeat ' ;
323
- $ note ->delete ();
363
+ if ($ note ->delete ()) {
364
+ // Clear the user's notification cache
365
+ $ cache = Cache::instance ();
366
+ $ key = Cache::key ('usernotifications: ' .$ user ->id );
367
+ $ cache ->delete ($ key );
368
+ }
324
369
325
370
$ note = new User_notification ();
326
371
$ note ->user_id = $ user ->id ;
327
372
$ note ->type = 'grouppost ' ;
328
373
$ note ->arg2 = $ action ->notice ->id ;
329
- $ note ->delete ();
374
+ if ($ note ->delete ()) {
375
+ // Clear the user's notification cache
376
+ $ cache = Cache::instance ();
377
+ $ key = Cache::key ('usernotifications: ' .$ user ->id );
378
+ $ cache ->delete ($ key );
379
+ }
330
380
331
381
return true ;
332
382
}
@@ -381,7 +431,7 @@ function onEndShowScripts($action) {
381
431
if (!User_notification_settings::isEnabled ($ user ->id ))
382
432
return true ;
383
433
$ action ->script ($ this ->path ('notify.js ' ));
384
- $ action ->inlineScript ('SNNote.init( ' .json_encode (User_notification::getAllForUser ($ user ))
434
+ $ action ->inlineScript ('SNNote.init( ' .(User_notification::getCachedNotes ($ user ))
385
435
.', ' .json_encode (array ('updateUrl ' => common_local_url ('getnotificationjson ' ),
386
436
'removeUrl ' => common_local_url ('removenotifications ' ),
387
437
'openInNewWindow ' => (User_notification_settings::openInNewWindow ($ user ->id ) ? true : false ),
0 commit comments