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

Commit

Permalink
feat: ツイート取得処理の改善 (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
book000 authored May 23, 2023
1 parent 0da5395 commit 27a7358
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions api/src/routes/websocket/twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ export class SearchTweet extends BaseWSRouter<
// スクリーンネームは判明したので返す
if (screenNames.length === 0) {
this.send({
illustId: this.data.illust_id,
responseType: 'error',
message: 'screen name not found',
})
return
}
this.send({
illustId: this.data.illust_id,
responseType: 'screen_names',
screen_names: screenNames,
})
Expand All @@ -85,6 +87,7 @@ export class SearchTweet extends BaseWSRouter<
for (const screenName of screenNames) {
this.getTweets(screenName, postedAt, path).catch((error) => {
this.send({
illustId: this.data.illust_id,
responseType: 'error',
message: error.message,
})
Expand Down Expand Up @@ -121,12 +124,14 @@ export class SearchTweet extends BaseWSRouter<

if (tweetsBySearch.length > 0 || tweetsByUserTimeline.length > 0) {
this.send({
illustId: this.data.illust_id,
responseType: 'finish',
})
return
}

this.send({
illustId: this.data.illust_id,
responseType: 'error',
message: `@${screenName} tweet not found`,
})
Expand Down Expand Up @@ -202,6 +207,7 @@ export class SearchTweet extends BaseWSRouter<

const similarity = await this.calculateSimilarity(imagePath, tweetImagePath)
this.send({
illustId: this.data.illust_id,
responseType: 'tweet',
tweet: {
tweet,
Expand Down
20 changes: 20 additions & 0 deletions types/src/api/ws/twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export interface SearchTweetResult {
}

interface SearchTweetResponseScreenNameData {
/**
* イラスト ID
*/
illustId: number

/**
* レスポンスタイプ
*/
Expand All @@ -93,6 +98,11 @@ interface SearchTweetResponseScreenNameData {
}

interface SearchTweetResponseTweetData {
/**
* イラスト ID
*/
illustId: number

/**
* レスポンスタイプ
*/
Expand All @@ -105,6 +115,11 @@ interface SearchTweetResponseTweetData {
}

interface SearchTweetResponseError {
/**
* イラスト ID
*/
illustId: number

/**
* レスポンスタイプ
*/
Expand All @@ -117,6 +132,11 @@ interface SearchTweetResponseError {
}

interface SearchTweetResponseFinish {
/**
* イラスト ID
*/
illustId: number

/**
* レスポンスタイプ
*/
Expand Down
10 changes: 6 additions & 4 deletions view/src/components/items/illusts/IllustPopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ export default Vue.extend({
this.tweetStatus = 'LOADING'
this.isLoadingImage = true
setTimeout(() => {
this.fetchTweets()
}, 1000)
this.fetchTweets()
// イラストポップアップアクセス中は #illust-popup をつける
if (window.location.hash !== '#illust-popup') {
Expand Down Expand Up @@ -223,6 +221,7 @@ export default Vue.extend({
if (!this.item) {
return
}
const illustId = this.item.id
this.isLoadingTweet = true
this.tweetStatus = 'LOADING'
this.tweets = undefined
Expand All @@ -233,7 +232,7 @@ export default Vue.extend({
this.tweets = []
this.error = undefined
this.$api.twitter.searchByIllust(
this.item.id,
illustId,
this.searchCallback.bind(this),
(error) => {
this.tweetStatus = 'FAILED'
Expand All @@ -246,6 +245,9 @@ export default Vue.extend({
},
searchCallback(response: SearchTweetResponse) {
const data = response.data
if (!this.item || data.illustId !== this.item.id) {
return
}
switch (data.responseType) {
case 'screen_names': {
Expand Down

0 comments on commit 27a7358

Please sign in to comment.