@@ -218,6 +218,31 @@ public static function clearCache(array $options = []): bool
218218 return (bool ) $ cache ->flush ();
219219 }
220220
221+ /*
222+ * @var Bool
223+ */
224+ public static function refreshFeedCache (array $ options = []): bool
225+ {
226+ $ cache = kirby ()->cache ('scottboms.mastodon ' );
227+ $ options = array_merge ([
228+ 'username ' => option ('scottboms.mastodon.username ' ),
229+ 'server ' => option ('scottboms.mastodon.server ' ),
230+ ], $ options );
231+
232+ if (empty ($ options ['username ' ]) || empty ($ options ['server ' ])) {
233+ return false ;
234+ }
235+
236+ $ userId = (new self ($ options ))->getUserId ();
237+
238+ if (!$ userId ) {
239+ return false ;
240+ }
241+
242+ $ cacheKey = CacheKey::forFeed ($ options ['server ' ], $ userId );
243+ return $ cache ->remove ($ cacheKey );
244+ }
245+
221246 /*
222247 * @var Object
223248 */
@@ -241,26 +266,39 @@ public function formatFeed(array $feed): array
241266
242267 // return an obj for the item
243268 return new Obj ([
244- 'id ' => $ item ['id ' ] ?? null ,
245- 'url ' => $ item ['url ' ] ?? null ,
246- 'author ' => $ item ['account ' ]['display_name ' ] ?? $ item ['account ' ]['username ' ] ?? '' ,
247- 'username ' => $ item ['account ' ]['username ' ] ?? '' ,
248- 'avatar ' => $ item ['account ' ]['avatar_static ' ] ?? null ,
249- 'originalContent ' => $ item ['content ' ] ?? '' ,
250- 'rebloggedContent ' => $ item ['reblog ' ]['content ' ] ?? '' ,
251- 'content ' => $ item ['content ' ] ?? ($ item ['reblog ' ]['content ' ] ?? '' ),
252- 'isBoost ' => $ isBoost ,
253- 'reblogAuthor ' => $ isBoost ? new Obj ([
269+ 'id ' => $ item ['id ' ] ?? null ,
270+ 'uri ' => $ item ['uri ' ] ?? null ,
271+ 'url ' => $ item ['url ' ] ?? null ,
272+ 'author ' => $ item ['account ' ]['display_name ' ] ?? $ item ['account ' ]['username ' ] ?? '' ,
273+ 'username ' => $ item ['account ' ]['username ' ] ?? '' ,
274+ 'avatar ' => $ item ['account ' ]['avatar_static ' ] ?? null ,
275+ 'originalContent ' => $ item ['content ' ] ?? '' ,
276+ 'rebloggedContent ' => $ item ['reblog ' ]['content ' ] ?? '' ,
277+ 'content ' => $ item ['content ' ] ?? ($ item ['reblog ' ]['content ' ] ?? '' ),
278+ 'repliesCount ' => $ item ['replies_count ' ] ?? 0 ,
279+ 'reblogsCount ' => $ item ['reblogs_count ' ] ?? 0 ,
280+ 'favouritesCount ' => $ item ['favourites_count ' ] ?? 0 ,
281+ 'favourited ' => $ item ['favourited ' ] ?? false ,
282+ 'reblogged ' => $ item ['reblogged ' ] ?? false ,
283+ 'bookmarked ' => $ item ['bookmarked ' ] ?? false ,
284+ 'sensitive ' => $ item ['sensitive ' ] ?? false ,
285+ 'visibility ' => $ item ['visibility ' ] ?? 'public ' ,
286+ 'muted ' => $ item ['muted ' ] ?? false ,
287+ 'language ' => $ item ['language ' ] ?? 'en ' ,
288+ 'inReplyToId ' => $ item ['in_reply_to_id ' ] ?? null ,
289+ 'inReplyToAccountId ' => $ item ['in_reply_to_account_id ' ] ?? null ,
290+ 'isBoost ' => $ isBoost ,
291+ 'reblogAuthor ' => $ isBoost ? new Obj ([
254292 'name ' => $ item ['reblog ' ]['account ' ]['display_name ' ] ?? $ item ['reblog ' ]['account ' ]['username ' ] ?? '' ,
255293 'url ' => $ item ['reblog ' ]['account ' ]['url ' ] ?? null ,
256294 ]) : null ,
257- 'attribution ' => $ isBoost ? 'Boosted from @ ' . ($ source ['account ' ]['acct ' ] ?? 'unknown ' ) : '' ,
258- 'date ' => isset ($ item ['created_at ' ])
295+ 'attribution ' => $ isBoost ? 'Boosted from @ ' . ($ source ['account ' ]['acct ' ] ?? 'unknown ' ) : '' ,
296+ 'date ' => isset ($ item ['created_at ' ])
259297 ? date ($ this ->options ['dateformat ' ] ?? 'Y-m-d ' , strtotime ($ item ['created_at ' ]))
260298 : '' ,
261- 'media ' => $ media , // array of obj
262- 'applicationName ' => $ item ['application ' ]['name ' ] ?? null ,
263- 'applicationWebsite ' => $ item ['application ' ]['website ' ] ?? null ,
299+ 'media ' => $ media , // array of obj
300+ 'applicationName ' => $ item ['application ' ]['name ' ] ?? null ,
301+ 'applicationWebsite ' => $ item ['application ' ]['website ' ] ?? null ,
264302 ]);
265303 }, $ feed );
266304 }
0 commit comments