actions.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. import API from '@/api'
  2. import { getWsUrl } from '@/util/contract.js'
  3. import WsManager from '@/util/wsManager.js'
  4. import {
  5. decryptoMsg,
  6. dealErrorMsg,
  7. noticeManager,
  8. getUserOpt,
  9. setUserOpt
  10. } from '@/util/util.js'
  11. import axios from 'axios'
  12. import Message from '@/store/db/Message.js'
  13. var socket = null
  14. const actions = {
  15. /**
  16. * @des 获取群基础信息
  17. * @param {Object} store
  18. * @param {Object} params
  19. */
  20. async getGroupInfo ({ commit, state }, params) {
  21. API.group.getGroupInfo2({ group_id: state.groupId }, info => {
  22. if (info.data.code === 0) {
  23. let data = info.data.data
  24. let pinMsg = data.pinMsg
  25. let group = data.group
  26. let members = data.members
  27. let eosInfo = data.eosInfo
  28. let isJoin = data.members.some((item) => {
  29. return state.userId == item.user_id
  30. })
  31. let _members = {}
  32. pinMsg && (pinMsg.visible = true)
  33. members.forEach(n => {
  34. if (!n.user_id) return
  35. _members[n.user_id] = n
  36. })
  37. commit('setGroupInfo', {
  38. userCounts: members.length,
  39. groupName: group.group_title,
  40. shareName: group.group_name,
  41. members: _members,
  42. membersArray: members,
  43. membersNum: data.group.member_num,
  44. userInfo: data.userInfo,
  45. groupNotice: group.group_notice,
  46. url: group.url,
  47. inviteUrl: group.invite_url,
  48. sessionInfo: data.sessionInfo || {
  49. is_mute: 0,
  50. is_pin: 0,
  51. pin_time_int: 0
  52. },
  53. isJoin,
  54. coverPhoto: group.cover_photo,
  55. adminList: data.adminList,
  56. blockList: data.blockList,
  57. pinMsg: pinMsg || {},
  58. creator: group.creator,
  59. eosInfo: eosInfo
  60. })
  61. }
  62. })
  63. },
  64. /**
  65. * @des 获取最新消息【from indexeddb】【群聊&私聊】
  66. * @param {Object} store
  67. * @param {Object} params
  68. */
  69. async commonGetNewMsgFromDb (store, params = {}) {
  70. // 先读取indexDB的数据,来渲染
  71. let { rootState, state } = store
  72. const objMessage = new Message()
  73. let data = await objMessage.getMsg(params.isPrivate ? rootState.curSession : state.groupId)
  74. setUserOpt('lastShowMsgUid', 0)
  75. if (data && data.list.length > 0) {
  76. params.fromdb = true
  77. actions._renderMsg(store, data, params)
  78. return true
  79. } else {
  80. return false
  81. }
  82. },
  83. /**
  84. * @des 获取最新消息【不需要登录】【群聊&私聊】
  85. * @param {Object} store
  86. * @param {Object} params
  87. */
  88. async commonGetNewMsg (store, params = {}) {
  89. let { rootState, state } = store
  90. let lastSession = rootState.curSession
  91. let msg
  92. // 然后再请求网上的数据,来渲染
  93. if (params.isPrivate) {
  94. msg = await API.person.getNewMsg({
  95. session_id: rootState.curSession,
  96. client_hash: state.endHash
  97. }).catch(() => {})
  98. } else {
  99. msg = await API.group.getNewMsg({
  100. group_id: state.groupId,
  101. client_hash: state.endHash
  102. }).catch(() => {})
  103. }
  104. // 若请求回来数据不在当前会话,则弃掉
  105. if (lastSession != rootState.curSession) return []
  106. if (msg && msg.data.code === 0 && msg.data.data.list.length > 0) {
  107. params.fromdb = false
  108. actions._renderMsg(store, msg.data.data, params)
  109. }
  110. return msg.data
  111. },
  112. /**
  113. * @des 获取历史消息【不需要登录】【群聊&私聊】
  114. * @param {Object} store
  115. * @param {Object} params
  116. */
  117. async commonGetHistoryMsg (store, params = {}) {
  118. let { commit, state, rootState } = store
  119. let his = localStorage.getItem(params.hash) // 先从本地缓存中获取记录
  120. let cacheData = {}
  121. let status = '' // 请求状态
  122. if (his && state.useCache) {
  123. cacheData = JSON.parse(his)
  124. } else {
  125. // 本地缓存中没有记录,从接口获取
  126. let msg
  127. if (params.isPrivate) {
  128. msg = await API.person
  129. .getHistoryMsg({
  130. session_id: rootState.curSession,
  131. client_hash: state.startHash
  132. })
  133. .catch(() => {})
  134. } else {
  135. msg = await API.group.getHistoryMsg({
  136. group_id: state.groupId,
  137. client_hash: state.startHash
  138. }).catch(() => {})
  139. }
  140. if (msg && msg.data.code === 0 && msg.data.data.list.length > 0) {
  141. cacheData = msg.data.data
  142. }
  143. }
  144. if (cacheData.list && cacheData.list.length > 0) {
  145. commit('setHash', {
  146. startHash: cacheData.list[0].hash
  147. })
  148. params.fromHistory = true
  149. this._renderMsg(store, cacheData, params)
  150. status = 'done'
  151. } else {
  152. commit('setHash', {
  153. startHash: null
  154. })
  155. status = 'end'
  156. }
  157. return status
  158. },
  159. /**
  160. * 发送消息【群聊&私聊】
  161. * @param {Object} data
  162. * @param {Object} params
  163. */
  164. commonDoSendMsg ({ dispatch, commit, state, rootState }, params = {}) {
  165. return new Promise(async (resolve, reject) => {
  166. let res
  167. if (params.isPrivate) {
  168. res = await API.person.sendMsg({
  169. session_id: rootState.curSession,
  170. msg_type: params.type,
  171. msg: params.msg
  172. })
  173. } else {
  174. res = await API.group.sendMsg({
  175. group_id: state.groupId,
  176. msg_type: params.type,
  177. msg: params.msg
  178. }).catch(err => {
  179. if (params.createTime) {
  180. dealErrorMsg(state, params.createTime)
  181. }
  182. reject(err)
  183. })
  184. }
  185. let data = res.data
  186. if (data.code === 0) {
  187. if (params.createTime) {
  188. let createTime = params.createTime
  189. data.data.content = decryptoMsg(data.data.content)
  190. let list = state.chatList
  191. for (let i = list.length - 1; i >= 0; i--) {
  192. let listItem = list[i]
  193. if (listItem.createTime === createTime) {
  194. commit('updataChatItem', {
  195. index: i,
  196. hash: data.data.hash,
  197. isCommfirm: true
  198. })
  199. break
  200. }
  201. }
  202. } else {
  203. // 针对用户第一次发言
  204. commit('updateMembers', data.data.userMap)
  205. data.data.content = decryptoMsg(data.data.content)
  206. commit('addChatItem', data.data)
  207. }
  208. commit('setHash', {
  209. endHash: data.data.hash
  210. })
  211. commit('updateSessionLastMsgNoDecode', Object.assign(data.data, { group_id: state.groupId }))
  212. resolve(data.data)
  213. } else {
  214. if (params.createTime) {
  215. dealErrorMsg(state, params.createTime)
  216. }
  217. }
  218. })
  219. },
  220. /**
  221. * @des 消息渲染
  222. * @param {Boolean} params.isPrivate 是否私聊
  223. * @param {Boolean} params.fromdb 是否来自indexdb
  224. * @param {Boolean} params.fromHistory 是否来自历史记录
  225. */
  226. _renderMsg ({ commit, state, rootState }, data, params) {
  227. let list = []
  228. // 更新聊天userMap
  229. commit('setGroupMembers', Object.assign(data.userMap, state.members))
  230. // 解密数据&&计算头像信息
  231. let lastShowMsgUid = params.fromHistory ? 0 : (getUserOpt('lastShowMsgUid') || 0)
  232. data.list.forEach(n => {
  233. let member = state.members[n.from]
  234. if (!member) return
  235. // 退群消息只能显示给管理员/自己
  236. if (n.msg_type == 5 && n.ext_info && n.ext_info.event_type == 'leave_group') {
  237. if (rootState.userId != n.from && !state.adminList.some(item => item == rootState.userId)) {
  238. return
  239. }
  240. }
  241. // 解密数据
  242. if (n.msg_type == 4) {
  243. // 针对红包类型
  244. n.msg = typeof n.msg == 'string' ? JSON.parse(decryptoMsg(n.msg)) : n.msg
  245. } else {
  246. n.msg = decryptoMsg(n.msg)
  247. }
  248. // 显示信息
  249. list.push({
  250. name: member.nick_name || member.user_name || 'unknown',
  251. content: n.msg,
  252. userId: n.from,
  253. timestamp: n.create_time_int,
  254. avatar: member.cover_photo || '',
  255. hash: n.hash,
  256. type: n.from == state.userId ? 'me' : 'you',
  257. msg_type: n.msg_type,
  258. ext: n.ext ? n.ext : null,
  259. ext_info: n.ext_info ? n.ext_info : null,
  260. isShowFullInfo: n.from != lastShowMsgUid
  261. })
  262. lastShowMsgUid = n.msg_type == 5 ? 0 : n.from
  263. })
  264. if (params.fromHistory) {
  265. // 历史记录
  266. commit('addHistoryList', list)
  267. } else {
  268. // 最新聊天
  269. setUserOpt('lastShowMsgUid', lastShowMsgUid)
  270. if (state.chatList.length) {
  271. commit('setHash', {
  272. endHash: list[list.length - 1] ? list[list.length - 1].hash : ''
  273. })
  274. } else {
  275. commit('setHash', {
  276. endHash: list[list.length - 1] ? list[list.length - 1].hash : '',
  277. startHash: list[0] ? list[0].hash : ''
  278. })
  279. }
  280. let itemData = params.newMsg ? { list: list, newMsg: params.newMsg, fromdb: params.fromdb } : { list: list, fromdb: params.fromdb }
  281. commit('addChatItem', itemData)
  282. }
  283. },
  284. /**
  285. * @des 群聊 获取最新消息【from indexeddb】
  286. * @param {Object} store
  287. * @param {Object} params
  288. */
  289. async getNewMsgFromDb (store, params = {}) {
  290. params.isPrivate = false
  291. return actions.commonGetNewMsgFromDb(store, params)
  292. },
  293. /**
  294. * @des 群聊 获取最新消息【不需要登录】
  295. * @param {Object} store
  296. * @param {Object} params
  297. */
  298. async getNewMsg (store, params = {}) {
  299. params.isPrivate = false
  300. return actions.commonGetNewMsg(store, params)
  301. },
  302. async getPrivateNewMsgFromDb (store, params = {}) {
  303. params.isPrivate = true
  304. return actions.commonGetNewMsgFromDb(store, params)
  305. },
  306. /**
  307. * @des 私聊 获取最新消息【不需要登录】
  308. * @param {Object} store
  309. * @param {Object} params
  310. */
  311. async getPrivateNewMsg (store, params = {}) {
  312. params.isPrivate = true
  313. return actions.commonGetNewMsg(store, params)
  314. },
  315. /**
  316. * @des 群聊 获取历史消息【不需要登录】
  317. * @param {Object} store
  318. * @param {Object} params
  319. */
  320. async getHistoryMsg (store, params = {}) {
  321. return actions.commonGetHistoryMsg(store, params)
  322. },
  323. /**
  324. * @des 私聊 获取历史消息【不需要登录】
  325. * @param {Object} store
  326. * @param {Object} params
  327. */
  328. async getPrivateHistoryMsg (store, params = {}) {
  329. params.isPrivate = true
  330. return actions.commonGetHistoryMsg(store, params)
  331. },
  332. /**
  333. * 发送群聊消息
  334. * @param {Object} data
  335. * @param {Object} params
  336. */
  337. doSendMsg (store, params = {}) {
  338. params.isPrivate = false
  339. return actions.commonDoSendMsg(store, params)
  340. },
  341. /**
  342. * 发送聊天文件
  343. * @param {Object} data
  344. * @param {Object} params
  345. */
  346. async doSendFile ({ commit, state, rootState }, params = {}) {
  347. return new Promise((resolve, reject) => {
  348. let userId = rootState.userId
  349. let token = rootState.token
  350. let formData = new FormData()
  351. formData.append('res', params.res)
  352. formData.append('user_id', userId)
  353. formData.append('token', token)
  354. // 私聊群聊参数调整
  355. if (state.groupId) {
  356. formData.append('group_id', state.groupId)
  357. } else {
  358. let arr = rootState.curSession.split('-')
  359. let toUser
  360. if (arr[0] == rootState.userId) toUser = arr[1]
  361. else toUser = arr[0]
  362. formData.append('to_user', toUser)
  363. }
  364. let sendUrl = state.groupId ? 'group/sendFile' : 'person/sendFile'
  365. axios({
  366. url: [API.host, sendUrl].join(''),
  367. method: 'post',
  368. data: formData,
  369. headers: { 'Content-Type': 'multipart/form-data' }
  370. })
  371. .then(({ data }) => {
  372. if (data.code === 0) {
  373. if (params.createTime) {
  374. let createTime = params.createTime
  375. data.data.content = decryptoMsg(data.data.content)
  376. let list = state.chatList
  377. list.forEach(item => {
  378. if (item.createTime === createTime) {
  379. item.res = undefined
  380. item.content = data.data.content
  381. item.hash = data.data.hash
  382. item.loading = false
  383. item.fail = false
  384. if (!item.ext_info) item.ext_info = {}
  385. item.ext_info.cover_url = data.data.ext_info && data.data.ext_info.cover_url
  386. }
  387. })
  388. } else {
  389. // 针对用户第一次发言
  390. commit('updateMembers', data.data.userMap)
  391. data.data.content = decryptoMsg(data.data.content)
  392. commit('addChatItem', data.data)
  393. }
  394. commit('setHash', {
  395. endHash: data.data.hash
  396. })
  397. commit('updateSessionLastMsgNoDecode', Object.assign(data.data, { group_id: state.groupId || rootState.curSession }))
  398. resolve(data.data)
  399. } else {
  400. if (params.createTime) {
  401. dealErrorMsg(state, params.createTime)
  402. }
  403. }
  404. })
  405. .catch(err => {
  406. if (params.createTime) {
  407. dealErrorMsg(state, params.createTime)
  408. }
  409. reject(err)
  410. })
  411. })
  412. },
  413. /**
  414. * 发送私聊消息
  415. * @param {Object} data
  416. * @param {Object} params
  417. */
  418. doSendPrivateMsg (store, params = {}) {
  419. params.isPrivate = true
  420. return actions.commonDoSendMsg(store, params)
  421. },
  422. /**
  423. * 链接websocket
  424. * @param {Object} data
  425. * @param {Object} params
  426. */
  427. initSocket ({ commit, state, rootState, rootGetters, dispatch }, params = {}) {
  428. if (!window.WebSocket) {
  429. console.error('Error: WebSocket is not supported .')
  430. return
  431. }
  432. let host = `${getWsUrl()}/?user_id=${rootState.userId}&token=${
  433. rootState.token
  434. }`
  435. if (socket) {
  436. socket.destroy()
  437. socket = null
  438. }
  439. socket = new WsManager(host, {
  440. autoConnect: true, // 自动连接
  441. reconnection: true, // 断开自动重连
  442. reconnectionDelay: 5000, // 重连间隔时间,单位秒
  443. keepAliveContent: JSON.stringify({ act: 'alive', player: name }) // 心跳包内容
  444. })
  445. socket.on('open', res => {})
  446. socket.on('message', e => {
  447. let _data = JSON.parse(e)
  448. let channel = _data.channel
  449. let data = _data.data
  450. let muteList = rootGetters.muteList // 免打扰列表
  451. // 群聊
  452. if (channel.match('chat:group')) {
  453. let isMute = muteList.some(v => {
  454. return v.session_id == data.group_id
  455. })
  456. if (data.type === 'msg') {
  457. if (rootState.curSession == data.group_id) {
  458. // 当前会话需要加载新消息
  459. dispatch('getNewMsg', { newMsg: true })
  460. if (data.from != rootState.userId) commit('addUnreadNums')
  461. }
  462. if (!isMute) {
  463. noticeManager.showNotification(data)
  464. }
  465. }
  466. if (data.type === 'update') {
  467. }
  468. if (data.type === 'add_admin') {
  469. }
  470. if (data.type === 'remove_admin') {
  471. }
  472. if (data.type === 'repeal') {
  473. commit('repealChatItem', data)
  474. // 左侧会话
  475. data.msg_type = -1
  476. commit('updateSessionLastmsg', data)
  477. }
  478. if (data.type === 'block') {
  479. commit('updateGroupBlockList', {
  480. type: 'add',
  481. id: data.to
  482. })
  483. }
  484. if (data.type === 'unblock') {
  485. commit('updateGroupBlockList', {
  486. type: 'delete',
  487. id: data.to
  488. })
  489. }
  490. if (data.type === 'leave' && data.group_id == state.groupId) {
  491. if (data.user_info.user_id == rootState.userId) return // 本人-不走这个ws
  492. // 本人退出刷新群信息
  493. if (data.user_id == rootState.userId) {
  494. dispatch('getGroupInfo')
  495. } else {
  496. commit('updateMembersArray', {
  497. type: 'del',
  498. userInfo: data.user_info
  499. })
  500. }
  501. }
  502. if (data.type === 'join' && data.group_id == state.groupId) {
  503. if (data.user_info.user_id == rootState.userId) return
  504. data.joinMsg = (data.user_info.nick_name || data.user_info.name) + '加入群组'
  505. commit('updateMembers', {
  506. [data.user_info.user_id]: data.user_info
  507. })
  508. commit('updateMembersArray', {
  509. type: 'add',
  510. userInfo: data.user_info
  511. })
  512. // commit('addChatItem', data)
  513. }
  514. if (data.type === 'pin_msg' && data.group_id == state.groupId) {
  515. commit('updateGroupPinMsg', data.pinMsg)
  516. }
  517. if (data.type === 'unpin_msg' && data.group_id == state.groupId) {
  518. commit('updateGroupPinMsg', null)
  519. }
  520. if (data.type === 'new_redpack' && rootState.curSession == data.group_id) {
  521. commit('addPacketItem', data)
  522. commit('updateSessionLastmsg', data)
  523. }
  524. if (data.type === 'grab_redpack' && rootState.curSession == data.group_id) {
  525. if (data.from == rootState.userId || data.to == rootState.userId) {
  526. commit('addPacketTip', data)
  527. commit('updateSessionLastmsg', data)
  528. }
  529. }
  530. }
  531. // 私聊
  532. if (channel.match('chat:person')) {
  533. if (!rootState.curSession) return
  534. let curId = +data.to > +data.from ? `${data.from}-${data.to}` : `${data.to}-${data.from}`
  535. let isMute = muteList.some(v => {
  536. return v.session_id == curId
  537. })
  538. if (data.type === 'msg') {
  539. if (rootState.curSession == curId) {
  540. // 当前会话需要加载新消息
  541. dispatch('getPrivateNewMsg')
  542. if (data.from != rootState.userId) commit('addUnreadNums')
  543. }
  544. // 如果在隐藏tab就需要 通知
  545. if (!isMute) {
  546. noticeManager.showNotification(data)
  547. }
  548. }
  549. if (data.type === 'repeal') {
  550. commit('repealChatItem', data)
  551. let sessionId = data.from > data.to ? `${data.to}-${data.from}` : `${data.from}-${data.to}`
  552. data.group_id = sessionId
  553. data.msg_type = -1
  554. commit('updateSessionLastmsg', data)
  555. }
  556. // if (data.type === 'new_redpack' && rootGetters.otherUserId == data.from) {
  557. if (data.type === 'new_redpack') {
  558. commit('addPacketItem', data)
  559. }
  560. if (data.type === 'grab_redpack' && rootGetters.otherUserId == data.from) {
  561. if (data.from == rootState.userId || data.to == rootState.userId) {
  562. commit('addPacketTip', data)
  563. }
  564. }
  565. if (data.type === 'join_group') {
  566. commit('updateMembers', {
  567. [rootState.userInfo.user_id]: rootState.userInfo
  568. })
  569. commit('updateMembersArray', {
  570. type: 'add',
  571. userInfo: rootState.userInfo
  572. })
  573. // commit('addChatItem', data)
  574. }
  575. if (data.type === 'leave_group') {
  576. commit('updateMembersArray', {
  577. type: 'del',
  578. userInfo: rootState.userInfo
  579. })
  580. // commit('addChatItem', data)
  581. dispatch('getGroupInfo')
  582. }
  583. }
  584. // 有新session 更新sessionList-自己退群不做处理
  585. let isLeaveGroup = data.msg_type == 5 && data.ext_info.event_type == 'leave_group'
  586. if (!isLeaveGroup && (data.type === 'msg' || data.type === 'new_redpack')) {
  587. let sessionList = rootState.chat.sessionList
  588. let curId
  589. if (data.group_id) {
  590. curId = data.group_id
  591. } else {
  592. curId = +data.to > +data.from ? `${data.from}-${data.to}` : `${data.to}-${data.from}`
  593. }
  594. let isInSession = sessionList.some(v => {
  595. return v.session_id == curId
  596. })
  597. let baseObj = {
  598. session_id: curId,
  599. cont: decryptoMsg(data.content),
  600. unread: rootState.userId == data.from ? 0 : 1,
  601. update_time_int: data.timestamp,
  602. timestamp: data.timestamp
  603. }
  604. if (!isInSession) {
  605. if (!data.group_id) {
  606. // 私聊要拿对方的头像
  607. API.user.getOtherInfo({
  608. target_id: rootState.userId === data.from ? data.to : data.from
  609. }).then(({ data }) => {
  610. let obj = {
  611. cover_photo: data.data.cover_photo,
  612. is_group: '0',
  613. name: data.data.nick_name
  614. }
  615. commit('addSessionItem', Object.assign(obj, baseObj))
  616. })
  617. } else {
  618. API.group.getGroupInfo({
  619. group_id: data.group_id
  620. }).then(({ data }) => {
  621. let group = data.data.group
  622. let obj = {
  623. cover_photo: group.cover_photo,
  624. is_group: '1',
  625. is_auth: group.is_auth,
  626. name: group.group_title
  627. }
  628. commit('addSessionItem', Object.assign(obj, baseObj))
  629. })
  630. }
  631. }
  632. if (data.from != rootState.userId) {
  633. commit('setSessionItemUnread', Object.assign({ curSession: rootState.curSession }, baseObj))
  634. }
  635. commit('updateSessionLastmsg', Object.assign(data, { sessionId: curId }))
  636. }
  637. })
  638. },
  639. /**
  640. * 撤回消息
  641. * @param {Object} params
  642. * {index:number, session_id:string, hash:string}
  643. */
  644. doRepealGroupMsg ({ dispatch, commit, state }, params = {}) {
  645. try {
  646. API.group.repealGroupMsg({
  647. group_id: state.groupId,
  648. hash: params.hash
  649. })
  650. } catch (error) {}
  651. },
  652. /**
  653. * 封禁群用户
  654. */
  655. async doBlockUser ({ state }, params = {}) {
  656. try {
  657. await API.group.blockUser({
  658. group_id: state.groupId,
  659. block_id: params.id
  660. })
  661. } catch (error) {}
  662. },
  663. /**
  664. * 解禁用户
  665. */
  666. async doUnBlockUser ({ state }, params = {}) {
  667. try {
  668. await API.group.unblockUser({
  669. group_id: state.groupId,
  670. block_id: params.id
  671. })
  672. } catch (error) {}
  673. },
  674. /**
  675. * 更新置顶
  676. */
  677. async doPinMsg ({ state }, params = {}) {
  678. try {
  679. await API.group.pinMsg({
  680. group_id: state.groupId,
  681. hash: params.hash
  682. })
  683. } catch (error) {}
  684. },
  685. /**
  686. * 取消置顶
  687. */
  688. async doUnpinMsg ({ state }, params = {}) {
  689. try {
  690. await API.group.unpinMsg({
  691. group_id: state.groupId,
  692. hash: params.hash
  693. })
  694. } catch (error) {}
  695. },
  696. /**
  697. * 加入群组
  698. */
  699. async joinGroup ({ state, commit }, params = {}) {
  700. try {
  701. await API.group.joinGroup({
  702. group_id: state.groupId
  703. })
  704. commit('updateJoin', true)
  705. commit('changeHotGroupStatus', {
  706. groupId: state.groupId,
  707. isJoin: 1
  708. })
  709. } catch (error) {}
  710. }
  711. }
  712. export default actions