@tadano @compound Interesting idea. Might add this to mitra-web (as an optional feature)
Conversation
Notices
-
Embed this notice
silverpill (silverpill@mitra.social)'s status on Sunday, 01-Sep-2024 21:44:51 JST silverpill -
Embed this notice
Tadano (tadano@mt.watamelon.win)'s status on Sunday, 01-Sep-2024 21:44:52 JST Tadano -
Embed this notice
compound@mt.watamelon.win's status on Sunday, 01-Sep-2024 21:44:53 JST compound Okay, doing the counting by comparing size of ID number, seems to have things stabilized.
The fetches have been compacted.
The requests to the server, and the size of the data returned, minimized.
And, I've setup a series of sequential stages for the update itself, instead of doing one of those, ugly deep callback trees.
var mk_fetch = (URL) => { return fetch(URL, { "credentials": "include", "headers": { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/115.0", "Accept": "*/*", "Accept-Language": "en-US,en;q=0.5", "Authorization": "Bearer "+localStorage.getItem("auth_token"), "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin" }, "referrer": "https://mt.watamelon.win/federated", "method": "GET", "mode": "cors" })} var get_last_read_id = (cb) => { mk_fetch("https://mt.watamelon.win/api/v1/markers?timeline%5B%5D=notifications").then((response)=>{ response.json().then((data)=>{cb(data.notifications.last_read_id);}) }) } var get_last_id = (cb) => { mk_fetch("https://mt.watamelon.win/api/v1/notifications?limit=1").then((response)=>{ response.json().then((data)=>{cb(data[0].id);}) }) } var get_last_5_ids = (cb) => { mk_fetch("https://mt.watamelon.win/api/v1/notifications?limit=5").then((response)=>{ response.json().then((data)=>{ var output = [];data.forEach((x)=>{output.push(x.id)});cb(output);}) }) } var old_last_id = 0; var old_last_read_id = 0; var push_notification_count_to_title = () => { var actions = []; actions.push(()=>{ get_last_id((last_id)=>{actions.pop()(last_id);}) }) actions.push((last_id)=>{ get_last_read_id((last_read_id)=>{ console.log("last_id:",last_id,"last_read_id",last_read_id) if(last_id != old_last_id || last_read_id != old_last_read_id) { old_last_id = last_id;old_last_read_id = last_read_id; if(last_id!= last_read_id){actions.pop()(last_id,last_read_id);} else{document.title = "Mitra:(0)";} } }) }) actions.push((last_id,last_read_id)=>{ get_last_5_ids((ids)=>{ console.log("ids:",ids) var count = 0; var keep_counting = true; ids.forEach((id) => { if (id >= last_read_id) {count += 1;} }) if (count > 4) {document.title = "Mitra:(4+)";} else {document.title = "Mitra:(" + count + ")";} })}) actions.reverse(); actions.pop()(); } push_notification_count_to_title(); setInterval(push_notification_count_to_title,30000);
-
Embed this notice