Commits

Shrikant Sharat Kandula  committed 3a06d9f

Retweet functionality json-ised and is now fully functional.

  • Participants
  • Parent commits b898e79

Comments (0)

Files changed (1)

File plugin/twitvim.vim

     endif
 endfunction
 
+" Add update to Twitter buffer if public, friends, or user timeline.
+function! s:add_update_json(item)
+    if has_key(s:curbuffer, 'buftype') && (
+                \ s:curbuffer.buftype == "public" ||
+                \ s:curbuffer.buftype == "friends" ||
+                \ s:curbuffer.buftype == "user" ||
+                \ s:curbuffer.buftype == "replies" ||
+                \ s:curbuffer.buftype == "list" ||
+                \ s:curbuffer.buftype == "retweeted_by_me" ||
+                \ s:curbuffer.buftype == "retweeted_to_me"
+                \)
+
+        " Parse the output from the Twitter update call.
+        let lines = s:format_status(a:item)
+
+        " Line number where new tweet will be inserted. It should be 2 if
+        " header is shown and 1 if header is hidden.
+        let insline = s:curbuffer.showheader ? 2 : 1
+
+        " Add the status ID to the current buffer's statuses list.
+        call insert(s:curbuffer.items, a:item, insline)
+
+        let twit_bufnr = bufwinnr('^'.s:twit_winname.'$')
+        if twit_bufnr > 0
+            let curwin = winnr()
+            execute twit_bufnr . "wincmd w"
+            setlocal modifiable
+            call append(insline - 1, lines)
+            execute "normal! ".insline."G"
+            setlocal nomodifiable
+            let s:curbuffer.buffer = getline(1, '$')
+            execute curwin .  "wincmd w"
+        endif
+    endif
+endfunction
+
 " Count number of characters in a multibyte string. Use technique from
 " :help strlen().
 function! s:mbstrlen(s)
     " Force POST instead of GET.
     let parms["dummy"] = "dummy1"
 
-    let url = s:get_api_root() . "/statuses/retweet/" . item.id_str . ".xml"
+    let url = s:get_api_root() . "/statuses/retweet/" . item.id_str . ".json"
 
     redraw
     echo "Retweeting..."
 
     let [error, output] = s:run_curl_oauth(url, s:ologin, s:get_proxy(), s:get_proxy_login(), parms)
-    if error != ''
-        let errormsg = s:xml_get_element(output, 'error')
-        call s:errormsg("Error retweeting: ".(errormsg != '' ? errormsg : error))
-    else
-        call s:add_update(output)
-        redraw
-        echo "Retweeted."
-    endif
+    let response = s:parse_json(output)
+
+    if !empty(error) || has_key(response, 'error')
+        call s:errormsg("Error retweeting: ".(empty(error) ? response.error : error))
+        return
+    endif
+    call s:add_update_json(response)
+    redraw
+    echo "Retweeted."
 endfunction
 
 " Show which tweet this one is replying to below the current line.