mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-25 11:27:31 -07:00
Merge pull request '[PR]: [mastodon-client] Various fixes & improvements' (#10450) from e2net/calckey:masto-client-improvements into develop
Reviewed-on: https://codeberg.org/calckey/calckey/pulls/10450
This commit is contained in:
commit
594daec8a9
9 changed files with 60 additions and 18 deletions
|
@ -21,6 +21,7 @@ export const meta = {
|
|||
message: "No such note.",
|
||||
code: "NO_SUCH_NOTE",
|
||||
id: "24fcbfc6-2e37-42b6-8388-c29b3861a08d",
|
||||
httpStatusCode: 404,
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
|
|
@ -67,6 +67,25 @@ export function apiStatusMastodon(router: Router): void {
|
|||
const { sensitive } = body;
|
||||
body.sensitive =
|
||||
typeof sensitive === "string" ? sensitive === "true" : sensitive;
|
||||
|
||||
if (body.poll) {
|
||||
if (
|
||||
body.poll.expires_in != null &&
|
||||
typeof body.poll.expires_in === "string"
|
||||
)
|
||||
body.poll.expires_in = parseInt(body.poll.expires_in);
|
||||
if (
|
||||
body.poll.multiple != null &&
|
||||
typeof body.poll.multiple === "string"
|
||||
)
|
||||
body.poll.multiple = body.poll.multiple == "true";
|
||||
if (
|
||||
body.poll.hide_totals != null &&
|
||||
typeof body.poll.hide_totals === "string"
|
||||
)
|
||||
body.poll.hide_totals = body.poll.hide_totals == "true";
|
||||
}
|
||||
|
||||
const data = await client.postStatus(text, body);
|
||||
ctx.body = convertStatus(data.data);
|
||||
} catch (e: any) {
|
||||
|
@ -86,7 +105,7 @@ export function apiStatusMastodon(router: Router): void {
|
|||
ctx.body = convertStatus(data.data);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
ctx.status = 401;
|
||||
ctx.status = ctx.status == 404 ? 404 : 401;
|
||||
ctx.body = e.response.data;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -408,7 +408,7 @@ export default class Misskey implements MegalodonInterface {
|
|||
if (options) {
|
||||
if (options.limit) {
|
||||
params = Object.assign(params, {
|
||||
limit: options.limit
|
||||
limit: options.limit <= 100 ? options.limit : 100
|
||||
})
|
||||
}
|
||||
if (options.max_id) {
|
||||
|
@ -738,7 +738,7 @@ export default class Misskey implements MegalodonInterface {
|
|||
if (options) {
|
||||
if (options.limit) {
|
||||
params = Object.assign(params, {
|
||||
limit: options.limit
|
||||
limit: options.limit <= 100 ? options.limit : 100
|
||||
})
|
||||
}
|
||||
else {
|
||||
|
@ -1169,7 +1169,7 @@ export default class Misskey implements MegalodonInterface {
|
|||
let pollParam = {
|
||||
choices: options.poll.options,
|
||||
expiresAt: null,
|
||||
expiredAfter: options.poll.expires_in
|
||||
expiredAfter: options.poll.expires_in * 1000
|
||||
}
|
||||
if (options.poll.multiple !== undefined) {
|
||||
pollParam = Object.assign(pollParam, {
|
||||
|
@ -1236,14 +1236,24 @@ export default class Misskey implements MegalodonInterface {
|
|||
const notification = this.converter.notification(n, host);
|
||||
if (n.note)
|
||||
notification.status = await this.noteWithDetails(n.note, host, cache);
|
||||
if (notification.account)
|
||||
notification.account = (await this.getAccount(notification.account.id)).data
|
||||
return notification;
|
||||
}
|
||||
|
||||
public async noteWithDetails(n: MisskeyAPI.Entity.Note, host: string, cache: AccountCache): Promise<MegalodonEntity.Status> {
|
||||
const status = await this.addUserDetailsToStatus(this.converter.note(n, host), cache);
|
||||
status.bookmarked = await this.isStatusBookmarked(n.id);
|
||||
return this.addMentionsToStatus(status, cache);
|
||||
}
|
||||
|
||||
public async isStatusBookmarked(id: string) : Promise<boolean> {
|
||||
return this.client
|
||||
.post<MisskeyAPI.Entity.State>('/api/notes/state', {
|
||||
noteId: id
|
||||
}).then(p => p.data.isFavorited ?? false);
|
||||
}
|
||||
|
||||
public async addUserDetailsToStatus(status: Entity.Status, cache: AccountCache) : Promise<Entity.Status> {
|
||||
if (status.account.followers_count === 0 && status.account.followers_count === 0 && status.account.statuses_count === 0)
|
||||
status.account = await this.getAccountCached(status.account.id, status.account.acct, cache) ?? status.account;
|
||||
|
|
|
@ -40,7 +40,8 @@ namespace MisskeyAPI {
|
|||
export type GetAll = MisskeyEntity.GetAll
|
||||
export type UserKey = MisskeyEntity.UserKey
|
||||
export type Session = MisskeyEntity.Session
|
||||
export type Stats = MisskeyEntity.Stats
|
||||
export type Stats = MisskeyEntity.Stats
|
||||
export type State = MisskeyEntity.State
|
||||
export type APIEmoji = { emojis: Emoji[] }
|
||||
}
|
||||
|
||||
|
@ -396,8 +397,8 @@ namespace MisskeyAPI {
|
|||
return MisskeyNotificationType.Reaction
|
||||
case NotificationType.Reblog:
|
||||
return MisskeyNotificationType.Renote
|
||||
case NotificationType.PollVote:
|
||||
return MisskeyNotificationType.PollVote
|
||||
case NotificationType.Poll:
|
||||
return MisskeyNotificationType.PollEnded
|
||||
case NotificationType.FollowRequest:
|
||||
return MisskeyNotificationType.ReceiveFollowRequest
|
||||
default:
|
||||
|
@ -417,8 +418,8 @@ namespace MisskeyAPI {
|
|||
return NotificationType.Reblog
|
||||
case MisskeyNotificationType.Reaction:
|
||||
return NotificationType.EmojiReaction
|
||||
case MisskeyNotificationType.PollVote:
|
||||
return NotificationType.PollVote
|
||||
case MisskeyNotificationType.PollEnded:
|
||||
return NotificationType.Poll
|
||||
case MisskeyNotificationType.ReceiveFollowRequest:
|
||||
return NotificationType.FollowRequest
|
||||
case MisskeyNotificationType.FollowRequestAccepted:
|
||||
|
@ -458,6 +459,11 @@ namespace MisskeyAPI {
|
|||
notification = Object.assign(notification, {
|
||||
status: this.note(n.note, host)
|
||||
})
|
||||
if (notification.type === NotificationType.Poll) {
|
||||
notification = Object.assign(notification, {
|
||||
account: this.note(n.note, host).account
|
||||
})
|
||||
}
|
||||
}
|
||||
if (n.reaction) {
|
||||
notification = Object.assign(notification, {
|
||||
|
|
7
packages/megalodon/src/misskey/entities/state.ts
Normal file
7
packages/megalodon/src/misskey/entities/state.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace MisskeyEntity {
|
||||
export type State = {
|
||||
isFavorited: boolean
|
||||
isMutedThread: boolean
|
||||
isWatching: boolean
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ namespace MisskeyNotificationType {
|
|||
export const Renote: MisskeyEntity.NotificationType = 'renote'
|
||||
export const Quote: MisskeyEntity.NotificationType = 'quote'
|
||||
export const Reaction: MisskeyEntity.NotificationType = 'favourite'
|
||||
export const PollVote: MisskeyEntity.NotificationType = 'pollVote'
|
||||
export const PollEnded: MisskeyEntity.NotificationType = 'pollEnded'
|
||||
export const ReceiveFollowRequest: MisskeyEntity.NotificationType = 'receiveFollowRequest'
|
||||
export const FollowRequestAccepted: MisskeyEntity.NotificationType = 'followRequestAccepted'
|
||||
export const GroupInvited: MisskeyEntity.NotificationType = 'groupInvited'
|
||||
|
|
|
@ -8,8 +8,7 @@ namespace NotificationType {
|
|||
export const EmojiReaction: Entity.NotificationType = 'emoji_reaction'
|
||||
export const FollowRequest: Entity.NotificationType = 'follow_request'
|
||||
export const Status: Entity.NotificationType = 'status'
|
||||
export const PollVote: Entity.NotificationType = 'poll_vote'
|
||||
export const PollExpired: Entity.NotificationType = 'poll_expired'
|
||||
export const Poll: Entity.NotificationType = 'poll'
|
||||
}
|
||||
|
||||
export default NotificationType
|
||||
|
|
|
@ -93,7 +93,7 @@ const pollVote: MisskeyEntity.Notification = {
|
|||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: user.id,
|
||||
user: user,
|
||||
type: MisskeyNotificationType.PollVote,
|
||||
type: MisskeyNotificationType.PollEnded,
|
||||
note: note
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ describe('getNotifications', () => {
|
|||
},
|
||||
{
|
||||
event: pollVote,
|
||||
expected: MegalodonNotificationType.PollVote,
|
||||
expected: MegalodonNotificationType.Poll,
|
||||
title: 'pollVote'
|
||||
},
|
||||
{
|
||||
|
|
|
@ -42,8 +42,8 @@ describe('api_client', () => {
|
|||
dist: MisskeyNotificationType.Renote
|
||||
},
|
||||
{
|
||||
src: MegalodonNotificationType.PollVote,
|
||||
dist: MisskeyNotificationType.PollVote
|
||||
src: MegalodonNotificationType.Poll,
|
||||
dist: MisskeyNotificationType.PollEnded
|
||||
},
|
||||
{
|
||||
src: MegalodonNotificationType.FollowRequest,
|
||||
|
@ -83,8 +83,8 @@ describe('api_client', () => {
|
|||
dist: MegalodonNotificationType.EmojiReaction
|
||||
},
|
||||
{
|
||||
src: MisskeyNotificationType.PollVote,
|
||||
dist: MegalodonNotificationType.PollVote
|
||||
src: MisskeyNotificationType.PollEnded,
|
||||
dist: MegalodonNotificationType.Poll
|
||||
},
|
||||
{
|
||||
src: MisskeyNotificationType.ReceiveFollowRequest,
|
||||
|
|
Loading…
Reference in a new issue