Add: POST markers

This commit is contained in:
Cutls 2019-09-07 01:46:50 +09:00
parent 5e6c713f9d
commit 81b99515cd
2 changed files with 57 additions and 28 deletions

View File

@ -331,7 +331,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) {
localStorage.setItem("notice-mem", noticetext); localStorage.setItem("notice-mem", noticetext);
noticetext = ""; noticetext = "";
} }
var if_notf = 'data-notfIndv="' + acct_id + "_" + toot.id + '"'; var if_notf = 'data-notfIndv="' + acct_id + "_" + toot.id + '" data-notf="' + toot.id + '"';
var toot = toot.status; var toot = toot.status;
var dis_name = escapeHTML(toot.account.display_name); var dis_name = escapeHTML(toot.account.display_name);
if (toot.account.emojis) { if (toot.account.emojis) {

View File

@ -917,10 +917,10 @@ function getMarker(tlid, type, acct_id) {
}); });
} }
function showUnread(tlid, type, acct_id) { function showUnread(tlid, type, acct_id) {
if($("#unread_" + tlid + " .material-icons").hasClass("teal-text")){ if ($("#unread_" + tlid + " .material-icons").hasClass("teal-text")) {
$("#unread_" + tlid + " .material-icons").removeClass("teal-text") $("#unread_" + tlid + " .material-icons").removeClass("teal-text")
goTop(tlid) goTop(tlid)
return return
} }
$("#unread_" + tlid + " .material-icons").addClass("teal-text") $("#unread_" + tlid + " .material-icons").addClass("teal-text")
var domain = localStorage.getItem("domain_" + acct_id); var domain = localStorage.getItem("domain_" + acct_id);
@ -944,7 +944,7 @@ function showUnread(tlid, type, acct_id) {
todo(error); todo(error);
console.error(error); console.error(error);
}).then(function (json) { }).then(function (json) {
if(!json){ if (!json) {
columnReload(tlid) columnReload(tlid)
} }
if (localStorage.getItem("filter_" + acct_id) != "undefined") { if (localStorage.getItem("filter_" + acct_id) != "undefined") {
@ -963,15 +963,15 @@ function showUnread(tlid, type, acct_id) {
}); });
} }
var ueloadlock = false var ueloadlock = false
function ueload(tlid){ function ueload(tlid) {
if(ueloadlock){ if (ueloadlock) {
return false return false
} }
ueloadlock = true ueloadlock = true
var multi = localStorage.getItem("column") var multi = localStorage.getItem("column")
var obj = JSON.parse(multi) var obj = JSON.parse(multi)
var acct_id = obj[tlid*1].domain var acct_id = obj[tlid * 1].domain
var type = obj[tlid*1].type var type = obj[tlid * 1].type
var domain = localStorage.getItem("domain_" + acct_id) var domain = localStorage.getItem("domain_" + acct_id)
var at = localStorage.getItem("acct_" + acct_id + "_at") var at = localStorage.getItem("acct_" + acct_id + "_at")
var id = $("#timeline_" + tlid + " .cvo:eq(0)").attr("unique-id") var id = $("#timeline_" + tlid + " .cvo:eq(0)").attr("unique-id")
@ -993,7 +993,7 @@ function ueload(tlid){
todo(error); todo(error);
console.error(error); console.error(error);
}).then(function (json) { }).then(function (json) {
if(!json){ if (!json) {
columnReload(tlid) columnReload(tlid)
} }
if (localStorage.getItem("filter_" + acct_id) != "undefined") { if (localStorage.getItem("filter_" + acct_id) != "undefined") {
@ -1012,24 +1012,53 @@ function ueload(tlid){
ueloadlock = false ueloadlock = false
}); });
} }
function testAsRead(acct_id) { function asRead() {
var domain = localStorage.getItem("domain_" + acct_id); //Markers
var at = localStorage.getItem("acct_" + acct_id + "_at"); var markers = localStorage.getItem("markers");
var httpreq = new XMLHttpRequest(); if (markers == "no") {
var start = "https://" + domain + "/api/v1/markers" markers = false;
httpreq.open('POST', start, true); } else {
httpreq.setRequestHeader('Content-Type', 'application/json'); markers = true
httpreq.setRequestHeader('Authorization', 'Bearer ' + at); }
httpreq.responseType = "json"; if (markers) {
httpreq.send(JSON.stringify({ var multi = localStorage.getItem("column")
home: { var obj = JSON.parse(multi)
last_read_id: 1 for (var i = 0; i < obj.length; i++) {
} var acct_id = obj[i].domain
})); var type = obj[i].type
httpreq.onreadystatechange = function () { if(type == "home" || type == "notf"){
if (httpreq.readyState === 4) { if(type == "home"){
var json = httpreq.response; var id = $("#timeline_" + i + " .cvo:eq(0)").attr("unique-id")
console.log(json) var poster = {
home: {
last_read_id: id
}
}
}else{
var id = $("#timeline_" + i + " .cvo:eq(0)").attr("data-notf")
var poster = {
notifications: {
last_read_id: id
}
}
}
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem("acct_" + acct_id + "_at");
var httpreq = new XMLHttpRequest();
var start = "https://" + domain + "/api/v1/markers"
httpreq.open('POST', start, true);
httpreq.setRequestHeader('Content-Type', 'application/json');
httpreq.setRequestHeader('Authorization', 'Bearer ' + at);
httpreq.responseType = "json";
httpreq.send(JSON.stringify(poster));
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
var json = httpreq.response;
console.log(json)
}
}
}
} }
} }
} }
cbTimer1 = setInterval(asRead, 60000);