add toot-edit

This commit is contained in:
cutls 2022-10-10 17:19:30 +09:00
parent cb9a3c4af1
commit 742b93bbef
8 changed files with 218 additions and 160 deletions

View File

@ -82,7 +82,13 @@ function post(mode, postvis, dry) {
$('.toot-btn-group').prop('disabled', true)
todo('Posting')
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v1/statuses'
let start = 'https://' + domain + '/api/v1/statuses'
let method = 'POST'
const editTarget = $('#tootmodal').attr('data-edit')
if (editTarget) {
start = start + `/${editTarget}`
method = 'PUT'
}
var reply = $('#reply').val()
if (str.indexOf(localStorage.getItem('stable')) == -1) {
str + ' #' + localStorage.getItem('stable')
@ -174,7 +180,7 @@ function post(mode, postvis, dry) {
return toot
}
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.open(method, start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.setRequestHeader('Idempotency-Key', ideKey)
@ -375,5 +381,6 @@ function clear() {
width = 300
}
$('#post-box').css('width', width)
$('#tootmodal').attr('data-edit', null)
mdCheck()
}

View File

@ -15,7 +15,7 @@ function fav(id, acct_id, remote) {
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
httpreq.onreadystatechange = function() {
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
@ -75,7 +75,7 @@ function rt(id, acct_id, remote, vis) {
} else {
httpreq.send()
}
httpreq.onreadystatechange = function() {
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
@ -132,7 +132,7 @@ function bkm(id, acct_id, tlid) {
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
httpreq.onreadystatechange = function() {
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
@ -201,7 +201,7 @@ async function follow(acct_id, resolve) {
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send(JSON.stringify(ent))
httpreq.onreadystatechange = function() {
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
@ -296,7 +296,7 @@ function block(acct_id) {
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
httpreq.onreadystatechange = function() {
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
if (this.status !== 200) {
setLog(start, this.status, this.response)
@ -364,7 +364,7 @@ function muteDo(acct_id) {
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send(rq)
httpreq.onreadystatechange = function() {
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
if (this.status !== 200) {
setLog(start, this.status, this.response)
@ -413,7 +413,7 @@ function del(id, acct_id) {
httpreq.responseType = 'json'
httpreq.send()
}
httpreq.onreadystatechange = function() {
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
if (this.status !== 200) {
setLog(start, this.status, this.response)
@ -453,7 +453,31 @@ function redraft(id, acct_id) {
httpreq.responseType = 'json'
httpreq.send()
}
httpreq.onreadystatechange = function() {
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
if (this.status !== 200) {
setLog(start, this.status, this.response)
}
var json = httpreq.response
draftToPost(json, acct_id, null)
}
}
}
})
}
// edit
function editToot(id, acct_id) {
show()
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v1/statuses/' + id + '/source'
var httpreq = new XMLHttpRequest()
httpreq.open('GET', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
if (this.status !== 200) {
setLog(start, this.status, this.response)
@ -462,14 +486,13 @@ function redraft(id, acct_id) {
draftToPost(json, acct_id, id)
}
}
}
})
}
function draftToPost(json, acct_id, id) {
$('#post-acct-sel').prop('disabled', true)
$('#post-acct-sel').val(acct_id)
$('select').formSelect()
if (id) $('#tootmodal').attr('data-edit', id)
mdCheck()
mediack = null
if (json.media_attachments) mediack = json.media_attachments[0]
@ -532,7 +555,7 @@ function pin(id, acct_id) {
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
httpreq.onreadystatechange = function() {
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
@ -563,7 +586,7 @@ function request(id, flag, acct_id) {
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
httpreq.onreadystatechange = function() {
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
@ -589,7 +612,7 @@ function domainblock(add, flag, acct_id) {
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
httpreq.onreadystatechange = function() {
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
@ -616,7 +639,7 @@ function empUser() {
M.toast({ html: id + lang.lang_status_emphas, displayLength: 4000 })
} else {
var can
Object.keys(obj).forEach(function(key) {
Object.keys(obj).forEach(function (key) {
var usT = obj[key]
if (usT != id && !can) {
can = false
@ -648,7 +671,7 @@ function pinUser() {
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
httpreq.onreadystatechange = function() {
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
@ -684,20 +707,20 @@ function staEx(mode) {
Authorization: 'Bearer ' + at,
},
})
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
.then(function (json) {
if (json.statuses) {
if (json.statuses[0]) {
var id = json.statuses[0].id

View File

@ -1,12 +1,12 @@
//トゥートの詳細
function details(id, acct_id, tlid, mode) {
async function details(id, acct_id, tlid, mode) {
if (mode == 'dm') {
$('.dm-hide').hide()
} else {
$('.dm-hide').show()
}
const context = localStorage.getItem('moreContext')
if(context != 'yes') {
if (context != 'yes') {
$('.contextTool').hide()
} else {
$('.contextTool').show()
@ -39,25 +39,17 @@ function details(id, acct_id, tlid, mode) {
}
}
}
fetch(start, i)
.then(function(response) {
try {
const response = await fetch(start, i)
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
const json = await response.json()
console.log(['Toot data:', json])
if (!$('#timeline_' + tlid + ' #pub_' + id).length) {
var html = parse([json], '', acct_id)
var html = parse([json], '', acct_id, '', '', mute)
$('#toot-this').html(html)
jQuery('time.timeago').timeago()
}
@ -112,6 +104,18 @@ function details(id, acct_id, tlid, mode) {
afterFTLToot(id, acct_id, dom)
faved(id, acct_id)
rted(id, acct_id)
if (json.edited_at) {
$('.edited-hide').show()
try {
const history = await (await fetch(`https://${domain}/api/v1/statuses/${id}/history`, i)).json()
const temp = parse(history, 'noauth', acct_id)
console.log(temp)
$('#toot-edit').html(temp)
} catch(e) { console.error(e) }
} else {
$('#toot-edit').html('')
$('.edited-hide').hide()
}
if ($('#toot-this div').hasClass('cvo')) {
$('#toot-this').removeClass('cvo')
} else {
@ -122,7 +126,11 @@ function details(id, acct_id, tlid, mode) {
if (!$('#activator').hasClass('active')) {
$('#det-col').collapsible('open', 4)
}
})
} catch (e) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
}
}
//返信タイムライン
@ -145,20 +153,20 @@ function replyTL(id, acct_id) {
return false
}
fetch(start, i)
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
.then(function (json) {
var mute = getFilterTypeByAcct(acct_id, 'thread')
if (localStorage.getItem('mode_' + domain) == 'misskey') {
var templete = misskeyParse([json], '', acct_id, '', '', mute)
@ -201,20 +209,20 @@ function getContext(id, acct_id) {
}
}
fetch(start, i)
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
.then(function (json) {
if (localStorage.getItem('mode_' + domain) == 'misskey') {
json.reverse()
var templete = misskeyParse(json, '', acct_id, '', '', [])
@ -269,20 +277,20 @@ function beforeToot(id, acct_id, domain) {
untilID: id
})
})
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
.then(function (json) {
var templete = misskeyParse(json, 'noauth', acct_id)
$('#toot-before').html(templete)
jQuery('time.timeago').timeago()
@ -295,20 +303,20 @@ function beforeToot(id, acct_id, domain) {
'content-type': 'application/json'
}
})
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
.then(function (json) {
var templete = parse(json, 'noauth', acct_id)
if (templete != '') {
$('#toot-before .no-data').hide()
@ -335,20 +343,20 @@ function userToot(id, acct_id, user) {
userId: user
})
})
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
.then(function (json) {
var templete = misskeyParse(json, 'noauth', acct_id)
$('#user-before').html(templete)
jQuery('time.timeago').timeago()
@ -362,20 +370,20 @@ function userToot(id, acct_id, user) {
Authorization: 'Bearer ' + at
}
})
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
.then(function (json) {
var templete = parse(json, '', acct_id)
if (templete != '') {
$('#user-before .no-data').hide()
@ -396,20 +404,20 @@ function afterToot(id, acct_id, domain) {
'content-type': 'application/json'
}
})
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
.then(function (json) {
var templete = parse(json, 'noauth', acct_id)
if (templete != '') {
$('#ltl-after .no-data').hide()
@ -430,20 +438,20 @@ function afterUserToot(id, acct_id, user) {
Authorization: 'Bearer ' + at
}
})
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
.then(function (json) {
var templete = parse(json, '', acct_id)
if (templete != '') {
$('#user-after .no-data').hide()
@ -463,20 +471,20 @@ function afterFTLToot(id, acct_id, domain) {
'content-type': 'application/json'
}
})
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
.then(function (json) {
var templete = parse(json, 'noauth', acct_id)
if (templete != '') {
$('#ftl-after .no-data').hide()
@ -501,20 +509,20 @@ function faved(id, acct_id) {
Authorization: 'Bearer ' + at
}
})
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
.then(function (json) {
var templete = userparse(json, '', acct_id)
if (templete != '') {
$('#toot-fav .no-data').hide()
@ -539,20 +547,20 @@ function rted(id, acct_id) {
Authorization: 'Bearer ' + at
}
})
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
.then(function (json) {
var templete = userparse(json, '', acct_id)
$('#toot-rt').html(templete)
jQuery('time.timeago').timeago()
@ -614,20 +622,20 @@ function trans(tar, to, elem) {
fetch(exec, {
method: 'GET'
})
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(text) {
.then(function (text) {
elem.parents('.cvo').find('.toot').append('<span class="gray translate">' + text.text + '</span>')
})
}

View File

@ -482,6 +482,9 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type, onlyContent) {
var locked = ' <i class="fas fa-lock red-text"></i>'
} else {
var locked = ''
}
if (toot.edited_at) {
locked = locked + ` <i class="material-icons teal-text" style="font-size: 0.8rem" title="Edited at ${date(toot.edited_at, 'absolute')}">create</i>`
}
if (!toot.application) {
var via = ''
@ -642,7 +645,6 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type, onlyContent) {
} else {
var desc = ''
}
console.log('https://' + domain + '/storage/no-preview.png')
if (media.preview_url == 'https://' + domain + '/storage/no-preview.png') {
purl = url
nsfwmes = '<div class="nsfw-media">Unavailable preview</div>'
@ -664,10 +666,9 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type, onlyContent) {
viewer = ''
hasmedia = 'nomedia'
}
var menck = toot.mentions[0]
var mentions = ''
//メンションであれば
if (menck) {
if (toot.mentions && toot.mentions[0]) {
mentions = ''
var to_mention = []
Object.keys(toot.mentions).forEach(function (key3) {
@ -1144,6 +1145,10 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type, onlyContent) {
style="padding:0; padding-top: 5px;">
<i class="material-icons" aria-hidden="true">redo</i>${lang.lang_parse_redraft}
</li>
<li class="${if_mine}" onclick="editToot('${uniqueid}','${acct_id}')"
style="padding:0; padding-top: 5px;">
<i class="material-icons" aria-hidden="true">create</i>${lang.lang_edit}(v3.5.0~)
</li>
${trans}
<li onclick="postMessage(['openUrl', '${toot.url}'], '*')"
style="padding:0; padding-top: 5px;">
@ -1565,6 +1570,13 @@ function mastodonBaseStreaming(acct_id) {
filterUpdate(acct_id)
} else if (~typeA.indexOf('announcement')) {
announ(acct_id, tlid)
} else if (typeA === 'status.update') {
const tl = JSON.parse(mess.data).stream
const obj = JSON.parse(JSON.parse(mess.data).payload)
const tls = getTlMeta(tl[0], tl, acct_id, obj)
const template = insertTl(obj, tls, true)
$(`[unique-id=${obj.id}]`).html(template)
$(`[unique-id=${obj.id}] [unique-id=${obj.id}]`).unwrap()
} else if (typeA == 'notification') {
const obj = JSON.parse(JSON.parse(mess.data).payload)
let template = ''
@ -1635,7 +1647,7 @@ function mastodonBaseStreaming(acct_id) {
return false
}
}
function insertTl(obj, tls) {
function insertTl(obj, tls, dry) {
for (const timeline of tls) {
const { id, voice, type, acct_id } = timeline
const mute = getFilterTypeByAcct(acct_id, type)
@ -1645,6 +1657,7 @@ function insertTl(obj, tls) {
say(obj.content)
}
const template = parse([obj], type, acct_id, id, '', mute, type)
if (dry) return template
console.log($(`#timeline_box_${id}_box .tl-box`).scrollTop(), `timeline_box_${id}_box .tl-box`)
if (
$(`#timeline_box_${id}_box .tl-box`).scrollTop() === 0

View File

@ -50,6 +50,10 @@
<div class="collapsible-header"><i class="text-darken-3 false fas fa-retweet"></i>@@btedPeople@@</div>
<div class="collapsible-body toot-reset" id="toot-rt"></div>
</li>
<li class="edited-hide">
<div class="collapsible-header"><i class="material-icons">create</i>@@editHistory@@</div>
<div class="collapsible-body toot-reset" id="toot-edit"></div>
</li>
</ul>
<div class="dm-hide" style="max-width: 450px">
@@useOtherAcct1@@(<i class="fas fa-retweet"></i>/<i class="fas fa-star"></i>@@useOtherAcct2@@)<br />

View File

@ -65,6 +65,7 @@
"afterFTL": "Federated TL after this toot",
"favedPeople": "People who favourited it",
"btedPeople": "People who boosted it",
"editHistory": "Edit history",
"useOtherAcct1": "Use other account",
"useOtherAcct2": ":unfav and unBT are disabled.",
"btWithVis": "Boost with visibility",

View File

@ -63,6 +63,7 @@
"afterFTL": "これより後の連合TL(誰のトゥート言及してんねん)",
"favedPeople": "誰がお気に入りに登録してるんや",
"btedPeople": "誰がお気に入りブーストしたんや",
"editHistory": "編集履歴",
"useOtherAcct1": "他のアカウント使う",
"useOtherAcct2": "の解除はできひん",
"btWithVis": "公開範囲も決めてからブースト",

View File

@ -65,6 +65,7 @@
"afterFTL": "これより後の連合TL(言及確認)",
"favedPeople": "このトゥートをお気に入りに登録した人",
"btedPeople": "このトゥートをブーストした人",
"editHistory": "編集履歴",
"useOtherAcct1": "他のアカウントを使用",
"useOtherAcct2": "の解除はできません",
"btWithVis": "公開範囲を指定してブースト",