Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

メッセージが投稿されたチャンネル名を表示するようにした #831

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/MessageWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const InnerMessageWidget = async (

const store = await getStore()
const user = await store.getUser(message.userId)
const channelPath = await store.getChannelPath(message.channelId)

return html`
<article class="main-message message">
Expand All @@ -72,6 +73,7 @@ const InnerMessageWidget = async (
${quotedMessages.map(({ id }) => QuotedMessage(id))}
</section>
<footer>
<p class="channel-path">${channelPath}</p>
<a
href="https://q.trap.jp/messages/${id}"
target="_blank"
Expand Down
20 changes: 19 additions & 1 deletion src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ interface Store {
channelIdMap: Map<string, Channel>
stampNameMap: Map<string, Stamp>
getUser(userId: string): Promise<User>
getChannelPath(channelId: string): Promise<string>
}

const createStore = async (): Promise<Store> => {
Expand All @@ -99,6 +100,22 @@ const createStore = async (): Promise<Store> => {
get<Map<string, Channel>>('channelIdMap', store),
get<Map<string, Stamp>>('stampNameMap', store)
])

const getChannelPath = async (channelId: string) => {
const nameList: string[] = []

let currentChannelId: string | null = channelId
while (currentChannelId) {
/* eslint-disable @typescript-eslint/no-non-null-assertion */
const channel = channelIdMap!.get(currentChannelId)
nameList.unshift(channel!.name)
currentChannelId = channel!.parentId
/* eslint-enable @typescript-eslint/no-non-null-assertion */
}

return `#${nameList.join('/')}`
}

return {
/* eslint-disable @typescript-eslint/no-non-null-assertion */
userIdMap: userIdMap!,
Expand All @@ -112,7 +129,8 @@ const createStore = async (): Promise<Store> => {
// 凍結されたユーザーは一覧にないので取得する
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return userIdMap!.get(userId) ?? (await apis.getUser(userId)).data
}
},
getChannelPath
}
}

Expand Down
Loading