|
|
@ -53,25 +53,32 @@ class ThreadWatcher { |
|
|
|
res = await fetch(`/${board}/thread/${postId}.json`); |
|
|
|
res = await fetch(`/${board}/thread/${postId}.json`); |
|
|
|
json = await res.json(); |
|
|
|
json = await res.json(); |
|
|
|
} catch (e) { /* ignore */ } |
|
|
|
} catch (e) { /* ignore */ } |
|
|
|
if (json && json.replies && json.replies.length > 0) { |
|
|
|
if (json && json.replies) { |
|
|
|
|
|
|
|
const newData = { |
|
|
|
|
|
|
|
...data, |
|
|
|
|
|
|
|
subject: (json.subject || json.nomarkup || "No subject").substring(0, 25), |
|
|
|
|
|
|
|
}; |
|
|
|
const updatedDate = new Date(data.updatedDate); |
|
|
|
const updatedDate = new Date(data.updatedDate); |
|
|
|
const newPosts = json.replies.filter(r => new Date(r.date) > updatedDate); |
|
|
|
const newPosts = json.replies.filter(r => new Date(r.date) > updatedDate); |
|
|
|
if (newPosts.length > 0) { |
|
|
|
if (newPosts.length > 0) { |
|
|
|
data.subject = (json.subject || json.nomarkup || "No subject").substring(0, 25); |
|
|
|
|
|
|
|
data.updatedDate = new Date(); |
|
|
|
|
|
|
|
if (this.isFocused && this.threadMatch |
|
|
|
if (this.isFocused && this.threadMatch |
|
|
|
&& this.threadMatch[1] === board && this.threadMatch[2] === postId) { |
|
|
|
&& this.threadMatch[1] === board && this.threadMatch[2] === postId) { |
|
|
|
//unread=0 when fetching from inside a thread that is focused
|
|
|
|
//unread=0 when fetching from inside a thread that is focused
|
|
|
|
data.unread = 0; |
|
|
|
newData.unread = 0; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
data.unread += newPosts.length; |
|
|
|
newData.unread += newPosts.length; |
|
|
|
//this.notify(newPosts);
|
|
|
|
//this.notify(newPosts);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (newData.subject !== data.subject |
|
|
|
|
|
|
|
|| newData.unread !== data.unread) { |
|
|
|
|
|
|
|
newData.updatedDate = new Date(); |
|
|
|
const key = `${board}-${postId}`; |
|
|
|
const key = `${board}-${postId}`; |
|
|
|
this.watchListMap.set(key, data); |
|
|
|
this.watchListMap.set(key, newData); |
|
|
|
this.updateRow(board, postId, data); |
|
|
|
this.updateRow(board, postId, newData); |
|
|
|
this.commit(); |
|
|
|
this.commit(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else if (res && res.status === 404) { |
|
|
|
} else if (res && res.status === 404) { |
|
|
|
console.log('removing 404 thread from watchlist'); |
|
|
|
console.log('removing 404 thread from watchlist'); |
|
|
|
this.remove(board, postId); |
|
|
|
this.remove(board, postId); |
|
|
@ -248,6 +255,8 @@ class ThreadWatcher { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
row.setAttribute('data-unread', data.unread); |
|
|
|
row.setAttribute('data-unread', data.unread); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//subject *can* change rarely, if the op was edited
|
|
|
|
|
|
|
|
row.children[1].textContent = `/${board}/ - ${data.subject}`; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|