thedesk/app/js/post/misskeystatus.js

273 lines
8.1 KiB
JavaScript
Raw Permalink Normal View History

2018-07-30 21:03:49 +10:00
//Renpost
function renote(id, acct_id, remote) {
2019-11-09 00:52:54 +11:00
if ($('#pub_' + id).hasClass('rted')) {
return false
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/notes/create'
if (localStorage.getItem('mode_' + domain) != 'misskey') {
return false
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.responseType = 'json'
httpreq.send(JSON.stringify({ i: at, renoteId: id }))
2019-11-04 03:10:06 +11:00
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
2019-11-09 00:52:54 +11:00
var json = httpreq.response
2019-11-04 03:10:06 +11:00
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, json)
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
console.log(['Success: renote', json])
$('[toot-id=' + id + ']').addClass('rted')
$('.rt_' + id).toggleClass('teal-text')
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
}
2018-07-30 21:03:49 +10:00
}
//Renote
function renoteqt(id, acct_id) {
2019-11-09 00:52:54 +11:00
localStorage.setItem('nohide', true)
show()
$('#reply').val('renote_' + id)
$('#rec').text('Renote')
$('#post-acct-sel').val(acct_id)
$('#post-acct-sel').prop('disabled', true)
$('select').formSelect()
$('#textarea').attr('placeholder', lang.lang_misskeyparse_qt)
$('#textarea').focus()
2018-07-30 21:03:49 +10:00
}
//Reply
function misskeyreply(id, acct_id) {
2019-11-09 00:52:54 +11:00
localStorage.setItem('nohide', true)
show()
$('#reply').val(id)
$('#rec').text('Renote')
$('#post-acct-sel').val(acct_id)
$('#post-acct-sel').prop('disabled', true)
$('select').formSelect()
$('#textarea').attr('placeholder', lang.lang_misskeyparse_qt)
$('#textarea').focus()
2018-07-30 21:03:49 +10:00
}
//Reaction
2019-05-19 17:39:30 +10:00
function reactiontoggle(id, acct_id, tlid) {
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/notes/show'
if (localStorage.getItem('mode_' + domain) != 'misskey') {
return false
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.responseType = 'json'
httpreq.send(JSON.stringify({ i: at, noteId: id }))
2019-11-04 03:10:06 +11:00
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
2019-11-09 00:52:54 +11:00
var json = httpreq.response
2019-11-04 03:10:06 +11:00
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, json)
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
console.log(['Success: reaction', json])
2019-11-04 03:10:06 +11:00
if (json.reactions) {
2019-11-09 00:52:54 +11:00
var reactions = [
'like',
'love',
'laugh',
'hmm',
'surprise',
'congrats',
'angry',
'confused',
'pudding',
'rip'
]
2019-11-04 03:10:06 +11:00
for (var i = 0; i < reactions.length; i++) {
if (json.reactions[reactions[i]]) {
2019-11-09 00:52:54 +11:00
$('#pub_' + id + ' .re-' + reactions[i] + 'ct').text(json.reactions[reactions[i]])
$('#pub_' + id + ' .re-' + reactions[i]).removeClass('hide')
2019-11-04 03:10:06 +11:00
} else {
2019-11-09 00:52:54 +11:00
$('#pub_' + id + ' .re-' + reactions[i] + 'ct').text(0)
if ($('#pub_' + id + ' .reactions').hasClass('fullreact')) {
$('#pub_' + id + ' .re-' + reactions[i]).addClass('hide')
2019-11-04 03:10:06 +11:00
} else {
2019-11-09 00:52:54 +11:00
$('#pub_' + id + ' .re-' + reactions[i]).removeClass('hide')
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
$('#pub_' + id + ' .re-' + reactions[i] + 'ct').text(json.reactions[reactions[i]])
2019-11-04 03:10:06 +11:00
}
}
2019-11-09 00:52:54 +11:00
$('#pub_' + id + ' .reactions').removeClass('hide')
$('#pub_' + id + ' .reactions').toggleClass('fullreact')
2019-11-04 03:10:06 +11:00
} else {
2019-11-09 00:52:54 +11:00
if ($('#pub_' + id + ' .reactions').hasClass('fullreact')) {
$('#pub_' + id + ' .reactions').addClass('hide')
$('#pub_' + id + ' .reactions').removeClass('fullreact')
2019-11-04 03:10:06 +11:00
} else {
2019-11-09 00:52:54 +11:00
$('#pub_' + id + ' .reactions').removeClass('hide')
$('#pub_' + id + ' .reaction').removeClass('hide')
$('#pub_' + id + ' .reactions').addClass('fullreact')
2019-11-04 03:10:06 +11:00
}
}
}
2019-11-09 00:52:54 +11:00
}
$('#pub_' + id + ' .freeReact').toggleClass('hide')
2019-04-11 02:52:01 +10:00
}
//reactioncustom
2019-05-19 17:39:30 +10:00
function reactioncustom(acct_id, id) {
2019-11-09 00:52:54 +11:00
$('#reply').val(id)
$('#unreact').hide()
$('#addreact').removeClass('hide')
$('#post-acct-sel').val(acct_id)
$('select').formSelect()
localStorage.setItem('nohide', true)
show()
emojiToggle(true)
$('#left-side').hide()
$('#default-emoji').hide()
2018-07-30 21:03:49 +10:00
}
2019-05-19 17:39:30 +10:00
function reactRefresh(acct_id, id) {
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/notes/show'
2019-05-19 17:39:30 +10:00
2019-11-09 00:52:54 +11:00
var req = {}
req.i = at
req.noteId = id
2019-11-04 03:10:06 +11:00
var i = {
2019-11-09 00:52:54 +11:00
method: 'POST',
2019-11-04 03:10:06 +11:00
body: JSON.stringify(req)
2019-11-09 00:52:54 +11:00
}
2019-11-04 03:10:06 +11:00
fetch(start, i)
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
2019-11-09 00:52:54 +11:00
setLog(response.url, response.status, text)
})
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
return response.json()
2019-11-04 03:10:06 +11:00
})
.catch(function(error) {
2019-11-09 00:52:54 +11:00
todo(error)
setLog(start, 'JSON', error)
console.error(error)
2019-11-04 03:10:06 +11:00
})
.then(function(json) {
if (!json) {
2019-11-09 00:52:54 +11:00
return false
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
var poll = ''
2019-11-04 03:10:06 +11:00
if (json.error) {
2019-11-09 00:52:54 +11:00
$('[toot-id=' + id + ']').hide()
$('[toot-id=' + id + ']').remove()
2019-11-04 03:10:06 +11:00
} else {
2019-11-09 00:52:54 +11:00
reactRefreshCore(json)
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
})
2018-08-17 03:21:40 +10:00
}
2019-05-19 17:39:30 +10:00
function reactRefreshCore(json) {
2019-11-09 00:52:54 +11:00
var id = json.id
2019-11-04 03:10:06 +11:00
if (json.reactions) {
2019-11-09 00:52:54 +11:00
$('#pub_' + id + ' .reactions').removeClass('hide')
var regExp = new RegExp(':', 'g')
2019-11-04 03:10:06 +11:00
Object.keys(json.reactions).forEach(function(keye) {
2019-11-09 00:52:54 +11:00
keyeClass = keye.replace(regExp, '')
2019-11-04 03:10:06 +11:00
if (json.reactions[keye]) {
2019-11-09 00:52:54 +11:00
$('#pub_' + id + ' .re-' + keyeClass + 'ct').text(json.reactions[keye])
$('#pub_' + id + ' .re-' + keyeClass).removeClass('hide')
2019-11-04 03:10:06 +11:00
} else {
2019-11-09 00:52:54 +11:00
$('#pub_' + id + ' .re-' + keyeClass + 'ct').text(0)
if ($('#pub_' + id + ' .reactions').hasClass('fullreact')) {
$('#pub_' + id + ' .re-' + keyeClass).addClass('hide')
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
$('#pub_' + id + ' .re-' + keyeClass + 'ct').text(json.reactions[keye])
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
})
2019-11-04 03:10:06 +11:00
}
2018-08-17 03:21:40 +10:00
}
2019-05-19 17:39:30 +10:00
function emojiReaction(emoji) {
2019-11-09 00:52:54 +11:00
var acct_id = $('#post-acct-sel').val()
var id = $('#reply').val()
reaction(emoji, id, acct_id, null)
clear()
hide()
2019-04-11 02:52:01 +10:00
}
2019-05-19 17:39:30 +10:00
function reaction(mode, id, acct_id, tlid) {
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
if ($('.fav_' + id).hasClass('yellow-text')) {
var flag = 'delete'
2019-11-04 03:10:06 +11:00
} else {
2019-11-09 00:52:54 +11:00
var flag = 'create'
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
var start = 'https://' + domain + '/api/notes/reactions/' + flag
if (localStorage.getItem('mode_' + domain) != 'misskey') {
return false
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.responseType = 'json'
httpreq.send(JSON.stringify({ i: at, noteId: id, reaction: mode }))
2019-11-04 03:10:06 +11:00
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, this.response)
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
$('.fav_' + id).toggleClass('yellow-text')
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
}
}
//Vote
2019-05-19 17:39:30 +10:00
function vote(acct_id, id, to) {
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/notes/polls/vote'
if (localStorage.getItem('mode_' + domain) != 'misskey') {
return false
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.responseType = 'json'
httpreq.send(JSON.stringify({ i: at, noteId: id, choice: to }))
2019-11-04 03:10:06 +11:00
httpreq.onreadystatechange = function() {
2019-11-09 00:52:54 +11:00
voterefresh(acct_id, id)
}
}
2019-05-19 17:39:30 +10:00
function voterefresh(acct_id, id) {
2019-11-09 00:52:54 +11:00
var httpreqd = new XMLHttpRequest()
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/notes/show'
httpreqd.open('POST', start, true)
httpreqd.setRequestHeader('Content-Type', 'application/json')
httpreqd.responseType = 'json'
httpreqd.send(JSON.stringify({ i: at, noteId: id }))
2019-11-04 03:10:06 +11:00
httpreqd.onreadystatechange = function() {
if (httpreqd.readyState == 4) {
2019-11-09 00:52:54 +11:00
var json = httpreqd.response
2019-11-04 03:10:06 +11:00
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, json)
2019-11-04 03:10:06 +11:00
}
if (!json) {
2019-11-09 00:52:54 +11:00
return false
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
var poll = ''
2019-11-04 03:10:06 +11:00
if (json.poll) {
2019-11-09 00:52:54 +11:00
var choices = json.poll.choices
2019-11-04 03:10:06 +11:00
Object.keys(choices).forEach(function(keyc) {
2019-11-09 00:52:54 +11:00
var choice = choices[keyc]
2019-11-04 03:10:06 +11:00
if (choice.isVoted) {
2019-11-09 00:52:54 +11:00
var myvote = twemoji.parse('✅')
2019-11-04 03:10:06 +11:00
} else {
2019-11-09 00:52:54 +11:00
var myvote = ''
2019-11-04 03:10:06 +11:00
}
2019-11-09 00:52:54 +11:00
poll = poll + `<div class="pointer vote" onclick="vote('${acct_id}','${json.id}',"${choice.id}')">${escapeHTML(choice.text)}(${choice.votes})${myvote})</div>`
})
$('.vote_' + json.id).html(poll)
2019-11-04 03:10:06 +11:00
}
}
2019-11-09 00:52:54 +11:00
}
2019-11-04 03:10:06 +11:00
}