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

メッセージについてるスタンプを表示 #104

Merged
merged 6 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 21 additions & 1 deletion autoload/traqvim/view.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,31 @@ function traqvim#view#make_message_body(message, width) abort
endfor
endif
endif
let stamps = []
if !empty(a:message.stamps)
let stamps += [ "{{{" ]
endif
for stamp in a:message.stamps
let s = denops#request('traqvim', 'getStamp', [stamp.stampId])
let user = denops#request('traqvim', 'getUser', [stamp.userId])
let stamps += [ ":" . s.name . ":" . user.displayName . "(" . stamp.count . ")" ]
endfor
if !empty(a:message.stamps)
let stamps += [ "}}}" ]
endif
Comment on lines +38 to +49
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize asynchronous requests for stamps and users.

The use of denops#request within a loop for fetching stamp and user data could lead to performance bottlenecks due to multiple asynchronous calls. Consider implementing a caching mechanism or batching requests to improve performance.

" Consider caching stamp and user data to reduce the number of requests.
" Alternatively, batch requests if possible.

let footer = [ "", repeat("─", a:width - 2) ] " 2はsigncolumnの分
let messageBody = header + rows + quotes->flatten() + footer
let messageBody = header + rows + quotes->flatten() + stamps + footer
return #{ body: messageBody, position: #{ quote: quotePos }}
endfunction

function traqvim#view#folded_stamp_text() abort
let stamps = []
for l in getline(v:foldstart + 1, v:foldend - 1)
let stamps += [ matchstr(l, "^:[^:]*:") ]
endfor
return stamps->uniq()->join(" ")
endfunction

function traqvim#view#update_message_position(timeline, key, value) abort
if a:key == 0
let start = 1
Expand Down
11 changes: 11 additions & 0 deletions denops/traqvim/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
channelsRecursive,
channelTimeline,
channelUUID,
getStamp,
getUser,
homeChannelId,
homeChannelPath,
sendMessage,
Expand All @@ -16,6 +18,7 @@ import {
fn,
helper,
is,
traq,
vars,
} from "./deps.ts";
import {
Expand Down Expand Up @@ -399,4 +402,12 @@ export async function main(denops: Denops) {
const d = new Date(date);
return Promise.resolve(d.toLocaleString("ja-JP"));
};
denops.dispatcher["getUser"] = (userId: unknown): Promise<traq.User> => {
assert(userId, is.String);
return getUser(userId);
};
denops.dispatcher["getStamp"] = (stampId: unknown): Promise<traq.Stamp> => {
assert(stampId, is.String);
return getStamp(stampId);
};
}
8 changes: 8 additions & 0 deletions denops/traqvim/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,11 @@ export const removePin = async (
console.error(e);
}
};

export const getStamp = async (
stampId: string,
): Promise<traq.Stamp> => {
const stampRes = await api.api.getStamp(stampId);
const stamp = stampRes.data;
return stamp;
};
2 changes: 2 additions & 0 deletions ftplugin/traqvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
setlocal noswapfile
setlocal signcolumn=yes
setlocal nolist
setlocal foldmethod=marker
setlocal foldtext=traqvim#view#folded_stamp_text()

" TODO: nerd font導入してるかの確認とかしたいな
" call sign_define("pin", #{ text: "📌"})
Expand Down
Loading