refs #125 Implement timeline methods for misskey

This commit is contained in:
AkiraFukushima 2020-03-04 00:52:24 +09:00
parent 027b884227
commit 2b1f15ad82
3 changed files with 213 additions and 13 deletions

View file

@ -1218,4 +1218,186 @@ export default class Misskey {
reject(err)
})
}
// ======================================
// timelines
// ======================================
/**
* POST /api/notes/global-timeline
*/
public async getPublicTimeline(
only_media?: boolean | null,
limit?: number | null,
max_id?: string | null,
since_id?: string | null,
_min_id?: string | null
): Promise<Response<Array<Entity.Status>>> {
let params = {}
if (only_media) {
params = Object.assign(params, {
withFiles: only_media
})
}
if (limit) {
params = Object.assign(params, {
limit: limit
})
}
if (max_id) {
params = Object.assign(params, {
untilId: max_id
})
}
if (since_id) {
params = Object.assign(params, {
sinceId: since_id
})
}
return this.client
.post<Array<MisskeyAPI.Entity.Note>>('/api/notes/global-timeline', params)
.then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.note(n)) }))
}
/**
* POST /api/notes/local-timeline
*/
public async getLocalTimeline(
only_media?: boolean | null,
limit?: number | null,
max_id?: string | null,
since_id?: string | null,
_min_id?: string | null
): Promise<Response<Array<Entity.Status>>> {
let params = {}
if (only_media) {
params = Object.assign(params, {
withFiles: only_media
})
}
if (limit) {
params = Object.assign(params, {
limit: limit
})
}
if (max_id) {
params = Object.assign(params, {
untilId: max_id
})
}
if (since_id) {
params = Object.assign(params, {
sinceId: since_id
})
}
return this.client
.post<Array<MisskeyAPI.Entity.Note>>('/api/notes/local-timeline', params)
.then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.note(n)) }))
}
/**
* POST /api/notes/search-by-tag
*/
public async getTagTimeline(
hashtag: string,
_local?: boolean | null,
only_media?: boolean | null,
limit?: number | null,
max_id?: string | null,
since_id?: string | null,
_min_id?: string | null
): Promise<Response<Array<Entity.Status>>> {
let params = {
tag: hashtag
}
if (only_media) {
params = Object.assign(params, {
withFiles: only_media
})
}
if (limit) {
params = Object.assign(params, {
limit: limit
})
}
if (max_id) {
params = Object.assign(params, {
untilId: max_id
})
}
if (since_id) {
params = Object.assign(params, {
sinceId: since_id
})
}
return this.client
.post<Array<MisskeyAPI.Entity.Note>>('/api/notes/search-by-tag', params)
.then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.note(n)) }))
}
/**
* POST /api/notes/timeline
*/
public async getHomeTimeline(
_local?: boolean | null,
limit?: number | null,
max_id?: string | null,
since_id?: string | null,
_min_id?: string | null
): Promise<Response<Array<Entity.Status>>> {
let params = {
withFiles: false
}
if (limit) {
params = Object.assign(params, {
limit: limit
})
}
if (max_id) {
params = Object.assign(params, {
untilId: max_id
})
}
if (since_id) {
params = Object.assign(params, {
sinceId: since_id
})
}
return this.client
.post<Array<MisskeyAPI.Entity.Note>>('/api/notes/timeline', params)
.then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.note(n)) }))
}
/**
* POST /api/notes/user-list-timeline
*/
public async getListTimeline(
list_id: string,
limit?: number | null,
max_id?: string | null,
since_id?: string | null,
_min_id?: string | null
): Promise<Response<Array<Entity.Status>>> {
let params = {
listId: list_id,
withFiles: false
}
if (limit) {
params = Object.assign(params, {
limit: limit
})
}
if (max_id) {
params = Object.assign(params, {
untilId: max_id
})
}
if (since_id) {
params = Object.assign(params, {
sinceId: since_id
})
}
return this.client
.post<Array<MisskeyAPI.Entity.Note>>('/api/notes/user-list-timeline', params)
.then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.note(n)) }))
}
}

View file

@ -94,27 +94,29 @@ namespace MisskeyAPI {
}
}
export const visibility = (v: 'public' | 'home' | 'followers' | 'direct'): 'public' | 'unlisted' | 'private' | 'direct' => {
export const visibility = (v: 'public' | 'home' | 'followers' | 'specified'): 'public' | 'unlisted' | 'private' | 'direct' => {
switch (v) {
case 'public':
case 'direct':
return v
case 'home':
return 'unlisted'
case 'followers':
return 'private'
case 'specified':
return 'direct'
}
}
export const encodeVisibility = (v: 'public' | 'unlisted' | 'private' | 'direct'): 'public' | 'home' | 'followers' | 'direct' => {
export const encodeVisibility = (v: 'public' | 'unlisted' | 'private' | 'direct'): 'public' | 'home' | 'followers' | 'specified' => {
switch (v) {
case 'public':
case 'direct':
return v
case 'unlisted':
return 'home'
case 'private':
return 'followers'
case 'direct':
return 'specified'
}
}
@ -207,6 +209,19 @@ namespace MisskeyAPI {
pinned: null
}
}
export const noteToConversation = (n: Entity.Note): MegalodonEntity.Conversation => {
const accounts: Array<MegalodonEntity.Account> = [user(n.user)]
if (n.reply) {
accounts.push(user(n.reply.user))
}
return {
id: n.id,
accounts: accounts,
last_status: note(n),
unread: false
}
}
}
export const DEFAULT_SCOPE = [

View file

@ -7,22 +7,25 @@ namespace MisskeyEntity {
export type Note = {
id: string
createdAt: string
text: string
cw: string | null
userId: string
user: User
replyId: string | null
renoteId: string | null
renote?: Note
repliesCount: number
text: string
cw: string | null
visibility: 'public' | 'home' | 'followers' | 'specified'
renoteCount: number
viaMobile?: boolean
visibility: 'public' | 'home' | 'followers' | 'direct'
repliesCount: number
reactions: { [key: string]: number }
tags?: Array<string>
emojis: Array<Emoji>
fileIds: Array<string>
files: Array<File>
replyId: string | null
renoteId: string | null
uri?: string
reply?: Note
renote?: Note
viaMobile?: boolean
tags?: Array<string>
poll?: Poll
mentions?: Array<string>
}
}