mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-24 10:47:07 +08:00
fix(gitter): notify wrong channel
This commit is contained in:
parent
3d957013f7
commit
a7fa0c73ed
@ -21,6 +21,9 @@ let s:room_jobs = {}
|
|||||||
function! chat#gitter#enter_room(room) abort
|
function! chat#gitter#enter_room(room) abort
|
||||||
if !has_key(s:room_jobs, a:room)
|
if !has_key(s:room_jobs, a:room)
|
||||||
let roomid = s:room_to_roomid(a:room)
|
let roomid = s:room_to_roomid(a:room)
|
||||||
|
if empty(roomid)
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
call s:fetch(roomid)
|
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 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, {
|
let jobid = s:JOB.start(cmd, {
|
||||||
@ -30,6 +33,7 @@ function! chat#gitter#enter_room(room) abort
|
|||||||
\ })
|
\ })
|
||||||
let s:room_jobs[a:room] = jobid
|
let s:room_jobs[a:room] = jobid
|
||||||
endif
|
endif
|
||||||
|
return 1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:room_to_roomid(room) abort
|
function! s:room_to_roomid(room) abort
|
||||||
|
@ -394,12 +394,27 @@ function! s:enter() abort
|
|||||||
return
|
return
|
||||||
elseif s:c_begin . s:c_char . s:c_end =~# '/set_channel\s*'
|
elseif s:c_begin . s:c_char . s:c_end =~# '/set_channel\s*'
|
||||||
if !empty(s:protocol)
|
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*')
|
let s:current_channel = matchstr(s:c_begin . s:c_char . s:c_end, '/set_channel\s*\zs\S*')
|
||||||
if !empty(s:current_channel)
|
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
|
if index(s:opened_channels[s:protocol], s:current_channel) ==# -1
|
||||||
call add(s:opened_channels[s:protocol], s:current_channel)
|
call add(s:opened_channels[s:protocol], s:current_channel)
|
||||||
endif
|
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
|
||||||
endif
|
endif
|
||||||
let s:c_end = ''
|
let s:c_end = ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user