import request from "./fetcher/request"
import { API_BASE_URL } from './../config/config'


export default {
  register ({name}) {
    return request.post(`${API_BASE_URL}/im/register`, {name})
  },
  getContacts () {
    const app = getApp()
    return request.get(`${API_BASE_URL}/im/getContacts/${app.globalData.userinfo.viewerId}`, {user_id: app.globalData.userinfo.viewerId})
  },
  upload () {
    const formData = new FormData()
    formData.append("file", $('#file')[0].files[0])
    return request.post(`${API_BASE_URL}/im/upload`, formData)
  },
  addFriend (friend_id) {
    if (friend_id === getApp().globalData.userinfo.viewerId) return
    return request.get(`${API_BASE_URL}/im/addFriend/${friend_id}/${getApp().globalData.userinfo.viewerId}`)
  },

  getMsgHistory (friend_id, offset=0) {
    return request.get(`${API_BASE_URL}/im/getMsgHistory/${friend_id}/${getApp().globalData.userinfo.viewerId}/${offset}`)
  }
}