news-read.ts
1 import type { NewsInformation, NewsSurvey, SessionHandle } from "~/models"; 2 import { newsRemoteMutate } from "./private/news-remote-mutate"; 3 4 /** 5 * Patches the `read` state of the news to the given value. 6 * @remark Will do nothing if `read === status`. 7 * @param session - The current session handle. 8 * @param item - The news item to patch. 9 * @param read - The new read state. 10 * @returns Nothing. 11 */ 12 export const newsRead = async (session: SessionHandle, item: NewsInformation | NewsSurvey, read: boolean): Promise<void> => { 13 // Do nothing if the status is already the same. 14 if (item.read === read) { 15 return; 16 } 17 18 // Update the server state. 19 await newsRemoteMutate(session, item, { 20 onlyMarkAsRead: true, 21 markAsRead: read, 22 delete: false 23 }); 24 25 // Update the local state. 26 item.read = read; 27 };