Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Fav TL #796
Browse files Browse the repository at this point in the history
  • Loading branch information
cutls committed Jan 9, 2023
1 parent f42a27b commit 75581d0
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 9 deletions.
80 changes: 74 additions & 6 deletions app/js/tl/tl.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,18 @@ function tl(type, data, acct_id, tlid, delc, voice, mode) {
//ブックマークなら飛ばす
getBookmark(acct_id, tlid)
$('#notice_' + tlid).text(
cap(type, data, acct_id) +
'(' +
localStorage.getItem('user_' + acct_id) +
'@' +
domain +
')'
`${cap(type, data, acct_id)}(${localStorage.getItem('user_' + acct_id)}@${domain})`
)
$('#notice_icon_' + tlid).text('bookmark')
return
} else if (type == 'fav') {
//お気に入りなら飛ばす
getFav(acct_id, tlid)
$('#notice_' + tlid).text(
`${cap(type, data, acct_id)}(${localStorage.getItem('user_' + acct_id)}@${domain})`
)
$('#notice_icon_' + tlid).text('star')
return
} else if (type == 'utl') {
//UTLなら飛ばす
getUtl(acct_id, tlid, data, false)
Expand Down Expand Up @@ -533,6 +536,9 @@ function moreload(type, tlid) {
} else if (type == 'bookmark') {
getBookmark(acct_id, tlid, true)
return
} else if (type == 'fav') {
getFav(acct_id, tlid, true)
return
} else if (type == 'utl') {
var data = obj[tlid].data
getUtl(acct_id, tlid, data, true)
Expand Down Expand Up @@ -899,6 +905,8 @@ function cap(type, data, acct_id) {
var response = 'tootsearch(' + escapeHTML(data) + ')'
} else if (type == 'bookmark') {
var response = 'Bookmarks'
} else if (type == 'fav') {
var response = 'Favourites'
} else if (type == 'utl') {
var response = 'User TL(' + escapeHTML(data.acct) + ')'
}
Expand Down Expand Up @@ -947,6 +955,8 @@ function com(type, data, tlid) {
return 'direct?'
} else if (type == 'bookmark') {
return 'bookmarks?'
} else if (type == 'fav') {
return 'favourites?'
}
}
//Misskey
Expand Down Expand Up @@ -1020,6 +1030,8 @@ function icon(type) {
var response = 'search'
} else if (type == 'bookmark') {
var response = 'bookmark'
} else if (type == 'fav') {
var response = 'star'
}
return response
}
Expand Down Expand Up @@ -1084,6 +1096,9 @@ function columnReload(tlid, type) {
} else if (type == 'bookmark') {
$('#notice_icon_' + tlid).removeClass('red-text')
getBookmark(acct_id, tlid, false)
} else if (type == 'fav') {
$('#notice_icon_' + tlid).removeClass('red-text')
getFav(acct_id, tlid, false)
} else {

var wss = localStorage.getItem('wss_' + tlid)
Expand Down Expand Up @@ -1402,6 +1417,59 @@ function getBookmark(acct_id, tlid, more) {
}
}
}
//お気に入り
function getFav(acct_id, tlid, more) {
moreloading = true
console.log(acct_id, tlid, more)
if (more) {
var sid = $('#timeline_' + tlid + ' .notif-marker')
.last()
.attr('data-maxid')
var ad = '?max_id=' + sid
} else {
var ad = ''
}
var at = localStorage.getItem('acct_' + acct_id + '_at')
var domain = localStorage.getItem('domain_' + acct_id)
var start = 'https://' + domain + '/api/v1/favourites' + ad
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) {
var json = httpreq.response
if (this.status !== 200) {
setLog(start, this.status, this.response)
}
var max_ids = httpreq.getResponseHeader('link')
var max_id = 0
if (max_ids) {
max_ids = max_ids.match(/[?&]{1}max_id=([0-9]+)/)
if (max_ids) {
max_id = max_ids[1]
}
}
var templete = parse(json, 'fav', acct_id, tlid, -1, null)
templete =
templete +
'<div class="hide notif-marker" data-maxid="' +
max_id +
'"></div>'
if (more) {
$('#timeline_' + tlid).append(templete)
} else {
$('#timeline_' + tlid).html(templete)
}
$('#landing_' + tlid).hide()
jQuery('time.timeago').timeago()
moreloading = false
todc()
}
}
}

function getUtl(acct_id, tlid, data, more) {

Expand Down
19 changes: 16 additions & 3 deletions app/js/ui/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function parseColumn(target, dontclose) {
var animecss = ''
}
unstreamingTL(acct.type, key, basekey, insert, icnsert, acct.left_fold, css, animecss, acct.data)
} else if (acct.type == 'bookmark') {
} else if (acct.type == 'bookmark' || acct.type == 'fav') {
if (!acct.left_fold) {
basekey = key
}
Expand Down Expand Up @@ -840,11 +840,13 @@ function unstreamingTL(type, key, basekey, insert, icnsert, left_fold, css, anim
} else {
var dataHtml = data
}
let typeFunc = type
if (type === 'fav') typeFunc = 'favTl'
var html = `<div class="boxIn" id="timeline_box_${key}_box" tlid="${key}">
<div class="notice-box z-depth-2" id="menu_${key}" style="${insert} ">
<div class="area-notice">
<i class="material-icons waves-effect" id="notice_icon_${key}" style="font-size:40px; padding-top:25%;"
onclick="${type}('${key}','${dataHtml}');" title="${lang.lang_layout_gotop}"></i>
onclick="goTop(${key}); ${typeFunc}('${key}','${dataHtml}');" title="${lang.lang_layout_gotop}"></i>
</div>
<div class="area-notice_name">
<span id="notice_${key}" class="tl-title"></span>
Expand Down Expand Up @@ -883,8 +885,10 @@ function unstreamingTL(type, key, basekey, insert, icnsert, left_fold, css, anim
if (type == 'tootsearch') {
tootsearch(key, data)
} else if (type == 'bookmark') {
console.log(key, data)
bookmark(key, data)
} else if (type == 'fav') {
console.log(key, data)
favTl(key, data)
} else if (type == 'utl') {
utl(key, data.acct, data.data)
}
Expand All @@ -904,6 +908,15 @@ function bookmark(key, data) {
}
tl('bookmark', '', data, key, 'false', voice, '')
}
function favTl(key, data) {
console.log(key, data)
if (localStorage.getItem('voice_' + key)) {
var voice = true
} else {
var voice = false
}
tl('fav', '', data, key, 'false', voice, '')
}
function utl(key, acct_id, data) {
if (!data) {
var multi = localStorage.getItem('column')
Expand Down
4 changes: 4 additions & 0 deletions app/view/make/components/menuHtml.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
<div><i class="material-icons" aria-hidden="true">bookmark</i></div>
<span>@@bookmark@@</span>
</a>
<a class="type waves-effect" data-type="fav" title="@@bookmark@@">
<div><i class="material-icons" aria-hidden="true">star</i></div>
<span>@@favRegist@@</span>
</a>
</div>
</div>
<div id="noauth" class="hide">
Expand Down

0 comments on commit 75581d0

Please sign in to comment.