1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:00:04 +08:00

fix(gitter): notify wrong channel

This commit is contained in:
wsdjeg 2022-05-03 20:06:09 +08:00
parent 3d957013f7
commit a7fa0c73ed
2 changed files with 71 additions and 52 deletions

View File

@ -21,6 +21,9 @@ let s:room_jobs = {}
function! chat#gitter#enter_room(room) abort
if !has_key(s:room_jobs, a:room)
let roomid = s:room_to_roomid(a:room)
if empty(roomid)
return 0
endif
call s:fetch(roomid)
let cmd = printf('curl -s -N -H "Accept: application/json" -H "Authorization: Bearer %s" "https://stream.gitter.im/v1/rooms/%s/chatMessages"',g:chat_gitter_token , roomid)
let jobid = s:JOB.start(cmd, {
@ -30,6 +33,7 @@ function! chat#gitter#enter_room(room) abort
\ })
let s:room_jobs[a:room] = jobid
endif
return 1
endfunction
function! s:room_to_roomid(room) abort

View File

@ -394,12 +394,27 @@ function! s:enter() abort
return
elseif s:c_begin . s:c_char . s:c_end =~# '/set_channel\s*'
if !empty(s:protocol)
" check if the channel does not exists, notify user
let saved_channel = s:current_channel
let s:current_channel = matchstr(s:c_begin . s:c_char . s:c_end, '/set_channel\s*\zs\S*')
if !empty(s:current_channel)
call chat#{s:protocol}#enter_room(s:current_channel)
if chat#{s:protocol}#enter_room(s:current_channel)
" succeed to enter channel
if index(s:opened_channels[s:protocol], s:current_channel) ==# -1
call add(s:opened_channels[s:protocol], s:current_channel)
endif
else
" failed to switch channel
call chat#windows#push({
\ 'user' : '--->',
\ 'username' : '--->',
\ 'room' : saved_channel,
\ 'protocol' : s:protocol,
\ 'msg' : 'can not find channel:' . s:current_channel,
\ 'time': strftime("%Y-%m-%d %H:%M"),
\ })
let s:current_channel = saved_channel
endif
endif
endif
let s:c_end = ''