From f1c4276d06b85ec955f8ad2ea590d97d438132cc Mon Sep 17 00:00:00 2001 From: Cutls Date: Mon, 8 Apr 2019 00:14:06 +0900 Subject: [PATCH] Add list on misskey --- app/js/login/manager.js | 10 +- app/js/tl/list.js | 187 +++++++++++++++++++++------- app/js/tl/tl.js | 114 ++++++++++++++++- app/js/ui/layout.js | 11 +- app/view/en/acct.html | 2 +- app/view/ja/acct.html | 2 +- app/view/make/language/acct.en.json | 2 +- app/view/make/language/acct.ja.json | 2 +- 8 files changed, 270 insertions(+), 60 deletions(-) diff --git a/app/js/login/manager.js b/app/js/login/manager.js index e9dd6776..45b4264e 100644 --- a/app/js/login/manager.js +++ b/app/js/login/manager.js @@ -57,14 +57,8 @@ function load() { localStorage.setItem("acct", 0); var acctN = 0; } - var electron = require("electron"); - var remote=electron.remote; - var platform=remote.process.platform; - if(localStorage.getItem("winstore")!="localinstall"){ - $("#linux").prop("checked", false); - }else{ - $("#linux").prop("checked", true); - } + //全部チェックアリでいいと思うの + $("#linux").prop("checked", true); } //最初に読む diff --git a/app/js/tl/list.js b/app/js/tl/list.js index 674e2c74..53c103c2 100644 --- a/app/js/tl/list.js +++ b/app/js/tl/list.js @@ -12,40 +12,68 @@ function list(){ $("#lists-user").html(""); var acct_id = $("#list-acct-sel").val(); var domain = localStorage.getItem("domain_" + acct_id); - var at = localStorage.getItem("acct_"+ acct_id + "_at"); - var start = "https://" + domain + "/api/v1/lists" - console.log(start) - fetch(start, { - method: 'GET', - headers: { - 'content-type': 'application/json', - 'Authorization': 'Bearer ' + at - }, - }).then(function(response) { - return response.json(); - }).catch(function(error) { - todo(error); - console.error(error); - }).then(function(json) { - if (json) { - var lists = ""; - Object.keys(json).forEach(function(key) { - var list = json[key]; - lists = lists + list.title+':'+lang.lang_list_show+'/'+lang.lang_list_users+'
'; - }); - $("#lists").html(lists); - }else{ - $("#lists").html(lang.lang_list_nodata); - } - }); + var at = localStorage.getItem("acct_"+ acct_id + "_at"); + if(localStorage.getItem("mode_" + domain)=="misskey"){ + var start = "https://" + domain + "/api/users/lists/list" + fetch(start, { + method: 'POST', + body: JSON.stringify({ + i:at + }), + }).then(function(response) { + return response.json(); + }).catch(function(error) { + todo(error); + console.error(error); + }).then(function(json) { + if (json) { + var lists = ""; + Object.keys(json).forEach(function(key) { + var list = json[key]; + lists = lists + list.title+':'+lang.lang_list_show+''; + }); + $("#lists").html(lists); + }else{ + $("#lists").html(lang.lang_list_nodata); + } + }); + }else{ + var start = "https://" + domain + "/api/v1/lists" + console.log(start) + fetch(start, { + method: 'GET', + headers: { + 'content-type': 'application/json', + 'Authorization': 'Bearer ' + at + }, + }).then(function(response) { + return response.json(); + }).catch(function(error) { + todo(error); + console.error(error); + }).then(function(json) { + if (json) { + var lists = ""; + Object.keys(json).forEach(function(key) { + var list = json[key]; + lists = lists + list.title+':'+lang.lang_list_show+'/'+lang.lang_list_users+'"; Object.keys(json).forEach(function(key) { var list = json[key]; - lists = lists + ''+escapeHTML(list.title)+'
'; }); $("#his-lists-a").html(lists); @@ -144,28 +192,65 @@ function hisList(user,acct_id){ var lists = lang.lang_list_remove+"
"; Object.keys(json).forEach(function(key) { var list = json[key]; - lists = lists + ''+list.title+'
'; }); $("#his-lists-b").html(lists); }else{ $("#his-lists-b").html(lang.lang_list_nodata); } - }); + }); +}else{ + var start = "https://" + domain + "/api/users/lists/list" + fetch(start, { + method: 'POST', + body: JSON.stringify({ + i:at + }), + }).then(function(response) { + return response.json(); + }).catch(function(error) { + todo(error); + console.error(error); + }).then(function(json) { + if (json) { + var lists = ""; + Object.keys(json).forEach(function(key) { + var list = json[key]; + lists = lists + list.title+':'+lang.lang_list_show+''; + }); + $("#his-lists-a").html(lists); + }else{ + $("#his-lists-a").html(lang.lang_list_nodata); + } + }); + $("#his-lists-b").html(""); +} } function listAdd(id,user,acct_id){ var domain = localStorage.getItem("domain_" + acct_id); - var at = localStorage.getItem("acct_"+ acct_id + "_at"); - var start = "https://" + domain + "/api/v1/lists/"+id+"/accounts" + var at = localStorage.getItem("acct_"+ acct_id + "_at"); + if(localStorage.getItem("mode_" + domain)=="misskey"){ + var start = "https://" + domain + "/api/users/lists/push" + var i={ + i:at, + listId:id, + userId:user + } + }else{ + var start = "https://" + domain + "/api/v1/lists/"+id+"/accounts" + var i={ + account_ids: [user] + } + } console.log(start) var httpreq = new XMLHttpRequest(); httpreq.open('POST', start, true); httpreq.setRequestHeader('Content-Type', 'application/json'); httpreq.setRequestHeader('Authorization', 'Bearer ' + at); httpreq.responseType = "json"; - httpreq.send(JSON.stringify({ - account_ids: [user] - })); + httpreq.send(JSON.stringify(i)); httpreq.onreadystatechange = function() { if (httpreq.readyState === 4) { var json = httpreq.response; @@ -176,16 +261,28 @@ function listAdd(id,user,acct_id){ function listRemove(id,user,acct_id){ var domain = localStorage.getItem("domain_" + acct_id); var at = localStorage.getItem("acct_"+ acct_id + "_at"); - var start = "https://" + domain + "/api/v1/lists/"+id+"/accounts" + if(localStorage.getItem("mode_" + domain)=="misskey"){ + var start = "https://" + domain + "/api/users/lists/push" + var method='POST' + var i={ + i:at, + listId:id, + userId:user + } + }else{ + var start = "https://" + domain + "/api/v1/lists/"+id+"/accounts" + var method='DELETE' + var i={ + account_ids: [user] + } + } console.log(start) var httpreq = new XMLHttpRequest(); - httpreq.open('DELETE', start, true); + httpreq.open(method, start, true); httpreq.setRequestHeader('Content-Type', 'application/json'); httpreq.setRequestHeader('Authorization', 'Bearer ' + at); httpreq.responseType = "json"; - httpreq.send(JSON.stringify({ - account_ids: [user] - })); + httpreq.send(JSON.stringify(i)); httpreq.onreadystatechange = function() { if (httpreq.readyState === 4) { var json = httpreq.response; diff --git a/app/js/tl/tl.js b/app/js/tl/tl.js index b73709af..f4abf172 100644 --- a/app/js/tl/tl.js +++ b/app/js/tl/tl.js @@ -164,6 +164,7 @@ function reload(type, cc, acct_id, tlid, data, mute, delc, voice, mode) { localStorage.setItem("now", type); if(localStorage.getItem("mode_" + domain)=="misskey"){ var misskey=true; + console.log(type); if (type == "home") { var start = "wss://" + domain + "/?i=" + at; @@ -183,12 +184,12 @@ function reload(type, cc, acct_id, tlid, data, mute, delc, voice, mode) { var start = "wss://" + domain + "/hybrid-timeline?i=" + at; } else if (type == "tag") { - Materialize.toast(lang_misskeyparse_tagnostr[lang], 1000); + Materialize.toast(lang.lang_misskeyparse_tagnostr, 3000); } else if (type == "noauth") { var start = "wss://" + acct_id + "/local-timeline?i=" + at; } else if (type=="list"){ - Materialize.toast(lang_misskeyparse_listnostr[lang], 1000); + Materialize.toast(lang.lang_misskeyparse_listnostr, 3000); } }else{ var misskey=false; @@ -463,6 +464,115 @@ function moreload(type, tlid) { }); } } +//TL差分取得 +function tlDiff(type, data, acct_id, tlid, delc, voice, mode) { + console.log("sabun") + var multi = localStorage.getItem("column"); + var obj = JSON.parse(multi); + var acct_id = obj[tlid].domain; + if (!type) { + var type = obj[tlid].type; + }else{ + var data; + } + if(type=="tag"){ + var data=obj[tlid].data; + var tag = localStorage.getItem("tag-range"); + if(tag=="local"){ + data=data+"&local=true"; + } + }else if(type=="list"){ + var data=obj[tlid].data; + } + var sid = $("#timeline_" + tlid + " .cvo").first().attr("unique-id"); + if (sid && !moreloading) { + if (type == "mix" && localStorage.getItem("mode_" + localStorage.getItem("domain_" + acct_id))!="misskey") { + return; + }else if (type == "plus" && localStorage.getItem("mode_" + localStorage.getItem("domain_" + acct_id))!="misskey") { + return; + }else if (type == "notf") { + return; + } + moreloading=true; + localStorage.setItem("now", type); + todo(cap(type) + " TL MoreLoading"); + if(type!="noauth"){ + var at = localStorage.getItem("acct_"+ acct_id + "_at"); + var hdr={ + 'content-type': 'application/json', + 'Authorization': 'Bearer ' + at + }; + var domain = localStorage.getItem("domain_" + acct_id); + }else{ + var hdr={ + 'content-type': 'application/json' + }; + domain=acct_id; + } + if(localStorage.getItem("mode_" + domain)=="misskey"){ + var misskey=true; + hdr={ + 'content-type': 'application/json' + }; + var url=misskeycom(type, data); + var start = "https://" + domain + "/api/notes/"+url; + var method="POST"; + var req={}; + if(type!="noauth"){ + req.i=at; + } + if(type=="local-media"||type=="pub-media"){ + req.mediaOnly=true; + } + if(type=="tag"){ + req.tag=data; + } + if(type=="list"){ + req.listId=data; + } + req.sinceId=sid; + req.limit=20; + var i={ + method: method, + headers: hdr, + body: JSON.stringify(req), + } + }else{ + var misskey=false; + var start = "https://" + domain + "/api/v1/timelines/" + com(type,data) + + "since_id=" + sid; + if(type=="dm"){ + var start = "https://" + domain + "/api/v1/conversations?" + + "since_id=" + sid; + } + var method="GET"; + var i={ + method: method, + headers: hdr + }; + } + + + fetch(start, i).then(function(response) { + return response.json(); + }).catch(function(error) { + todo(error); + console.error(error); + }).then(function(json) { + console.log(json); + if(misskey){ + var templete = misskeyParse(json, '', acct_id, tlid,"",mute); + }else{ + var templete = parse(json, '', acct_id, tlid,"",mute, type); + } + $("#timeline_" + tlid).prepend(templete); + additional(acct_id, tlid); + jQuery("time.timeago").timeago(); + moreloading=false; + todc(); + }); + } +} //WebSocket切断 function tlCloser() { diff --git a/app/js/ui/layout.js b/app/js/ui/layout.js index b024f4e6..1ca54f61 100644 --- a/app/js/ui/layout.js +++ b/app/js/ui/layout.js @@ -168,7 +168,7 @@ function parseColumn() { } var html='