Browse Source

更新群公告相关逻辑

imndx 2 years ago
parent
commit
fe93af438c
2 changed files with 15 additions and 47 deletions
  1. 1 1
      api/appServerApi.js
  2. 14 46
      pages/conversation/GroupConversationInfoView.vue

+ 1 - 1
api/appServerApi.js

@@ -154,7 +154,7 @@ export class AppServerApi {
                         if (res.data.code === 0) {
                             resolve(res.data.result);
                         } else {
-                            throw new AppServerError(response.data.code, res.data.message)
+                            throw new AppServerError(res.data.code, res.data.message)
                         }
                     } else {
                         throw new Error('request error, status code: ' + res.status)

+ 14 - 46
pages/conversation/GroupConversationInfoView.vue

@@ -65,6 +65,7 @@ import GroupType from "@/wfc/model/groupType";
 import ModifyGroupInfoType from "@/wfc/model/modifyGroupInfoType";
 import Config from "../../config";
 import EventType from "../../wfc/client/wfcEvent";
+import appServerApi from "../../api/appServerApi";
 
 export default {
     name: "GroupConversationInfoView",
@@ -104,18 +105,18 @@ export default {
         })
     },
 
-    mounted(){
+    mounted() {
         wfc.eventEmitter.on(EventType.UserInfosUpdate, this.onConversationMembersUpdate)
         wfc.eventEmitter.on(EventType.GroupMembersUpdate, this.onConversationMembersUpdate)
     },
 
-    beforeDestroy(){
+    beforeDestroy() {
         wfc.eventEmitter.removeListener(EventType.UserInfosUpdate, this.onConversationMembersUpdate)
         wfc.eventEmitter.removeListener(EventType.GroupMembersUpdate, this.onConversationMembersUpdate)
     },
 
     methods: {
-        onConversationMembersUpdate(){
+        onConversationMembersUpdate() {
             this.groupMemberUserInfos = store.getConversationMemberUsrInfos(this.conversationInfo.conversation);
         },
 
@@ -170,30 +171,16 @@ export default {
         async getGroupAnnouncement() {
             let url = Config.APP_SERVER + '/get_group_announcement';
             console.log('to getGroupAnnouncement', url, this.conversationInfo.conversation.target)
-            uni.request({
-                url: Config.APP_SERVER + '/get_group_announcement',
-                method: 'POST',
-                data: {
-                    groupId: this.conversationInfo.conversation.target,
-                },
-                withCredentials: true,
-                success: (response) => {
-                    console.log('getGroupAnnouncement response ', response)
-                    if (response.data && response.data.result) {
-                        this.groupAnnouncement = response.data.result.text;
+            appServerApi.getGroupAnnouncement(this.conversationInfo.conversation.target)
+                .then(result => {
+                    if (result.text) {
+                        this.groupAnnouncement = result.text;
                     } else {
                         if (this.enableEditGroupNameOrAnnouncement) {
                             this.groupAnnouncement = this.$t('conversation.click_to_edit_group_announcement');
                         }
                     }
-                },
-                fail: (e) => {
-                    console.log('getGroupAnnouncement error', e)
-                },
-                complete: (obj) => {
-                    console.log('getGroupAnnouncement complete', obj)
-                }
-            });
+                })
         },
 
         updateGroupName() {
@@ -218,34 +205,15 @@ export default {
                 return;
             }
             console.log('updateGroupAnnouncement')
-            uni.request({
-                url: Config.APP_SERVER + '/put_group_announcement',
-                method: 'POST',
-                data: {
-                    author: wfc.getUserId(),
-                    groupId: this.conversationInfo.conversation.target,
-                    text: this.newGroupAnnouncement,
-                },
-                withCredentials: true,
-                success: (response) => {
-                    console.log('updateGroupAnnouncement success', response)
-                    if (response.data && response.data.code === 0) {
-                        this.groupAnnouncement = this.newGroupAnnouncement;
-                        this.$refs.groupAnnouncementInput.blur();
-                    }
-                },
-                fail: (err) => {
-                    console.log('updateGroupAnnouncement err', err)
-                },
-                complete: (obj) => {
-                    console.log('updateGroupAnnouncement complete', obj)
-                }
-            });
+            appServerApi.updateGroupAnnouncement(wfc.getUserId(), this.conversationInfo.conversation.target, this.newGroupAnnouncement)
+                .then(result => {
+                    this.groupAnnouncement = this.newGroupAnnouncement;
+                })
         },
 
         quitGroup() {
             let groupInfo = this.conversationInfo.conversation._target;
-            if (groupInfo.owner === store.state.contact.selfUserInfo.uid){
+            if (groupInfo.owner === store.state.contact.selfUserInfo.uid) {
                 store.quitGroup(this.conversationInfo.conversation.target)
             } else {
                 store.quitGroup(this.conversationInfo.conversation.target)