文档中所写,聊天室是一种暂态的对话,标志位为tr为true的对话,所有对话中可用的方法,聊天室对象均可用。在开发过程中,发现在客户端,使用JS SDK内的quit()方法,tr为false的对话是可以退出的,而tr为true的对话是无法退出的。请问有什么解决方式吗?

我测试了是可以正常推出的。

嗯嗯,可以看一下您Javascript SDK测试的代码吗?我测试的时候,是同一套代码,只是换了不同的对话ObjectId,发现了结果的差异,所以跑来问问,目前发现利用REST API中,对话的成员移除接口可以达到我想要的效果,但是还是想弄明白客户端JS这边是不是我写的有什么问题,才导致正常群聊可退,聊天室退不出去的。谢谢了。

我是用vue测试的
App.vue内,JS代码如下

<template>
  <div id="app">
    <img src="./assets/logo.png">
    <router-view/>
    <button @click="test">测试退出leanCloud群聊</button>
    <button @click="test2">测试退出leanCloud聊天室</button>
    <button @click="test3">测试加入leanCloud群聊</button>
  </div>
</template>


 <script>
    /* eslint-disable spaced-comment,key-spacing,semi,indent,new-cap */
    
      export default {
        name: 'App',
        data () {
          return {
            client: {},
            conversation: {},
            chatRoom:{},
            conversationId:'5b3711c65b90c830ff7f926a', //非暂态对话ObjectId
            chatRoomId:'5b1931a99f545400360c03d9' //暂态对话ObjectId
          };
        },
        created () {
          let _this = this;
          _this.$realTime.createIMClient('48000').then(function (user) {
            //获取用户对象
            _this.client = user;
            //获取非暂态对话对象
            user.getConversation(_this.conversationId).then(function (conversation) {
              _this.conversation = conversation;
            });
            //获取暂态对话对象
            user.getConversation(_this.chatRoomId).then(function (chatRoom) {
              _this.chatRoom = chatRoom;
            })
          });
        },
        methods: {
          test: function () {
            //测试退出群聊
            console.log('client is:', this.client);
            console.log('conversation is:', this.conversation);
            this.conversation.quit().then(function (conversation) {
              console.log('退出群聊成功', conversation.members);
            }).catch(console.error.bind(console));
          },
          test2: function () {
            //测试退出聊天室
            console.log('client is:', this.client);
            console.log('chatRoom is:', this.conversation);
            this.chatRoom.quit().then(function (chatRoom) {
              console.log('退出聊天室成功', chatRoom.members);
            }).catch(console.error.bind(console));
          },
          test3: function () {
            //测试加入群聊
            this.conversation.join().then(function (conversation) {
              console.log('加入成功', conversation.members);
            }).catch(console.error.bind(console));
          }
        }
      }
    </script>

群聊的退出是正常的,在退出后的输出成员信息内,不再包含48000这个ClientId,但是聊天室的退出后,能够输出“退出成功”的信息,但是成员内仍有48000这个clientId,并且在控制台内查看,也还是有48000这个ClientId,所以从成员数据上来看,是没有退出成功的。不知道是不是我写的哪里有问题还是什么原因?

请问一下您是不是先创建了一个普通对话,然后在控制台将其 tr 改成了 true?

这样是会有问题的,请避免这样做,建议删掉这个对话重新创建一个。

额...并不是~群聊和聊天室是通过REST API,两个不同的接口创建的~我再新建两个试试~

这次测试,是直接在JS端创建了一个群聊,和一个聊天室(暂态群聊),发现聊天室对象,调用join()方法和quit()方法,都会报错,说是is not a function
测试代码如下

<template>
  <div id="app">
    <img src="./assets/logo.png">
    <router-view/>
    <button @click="createConversation">创建群聊</button>
    <button @click="createChatRoom">创建聊天室</button>
    <button @click="test">测试退出leanCloud群聊</button>
    <button @click="test2">测试退出leanCloud聊天室</button>
    <button @click="test3">测试加入leanCloud群聊</button>
    <button @click="test4">测试加入leanCloud聊天室</button>
  </div>
</template>

<script>
/* eslint-disable spaced-comment,key-spacing,semi,indent,new-cap */

  export default {
    name: 'App',
    data () {
      return {
        client: {},
        conversation: {},
        chatRoom:{},
        conversationId:'', //非暂态对话ObjectId
        chatRoomId:'' //暂态对话ObjectId
      };
    },
    created () {
      let _this = this;
      _this.$realTime.createIMClient('Harry').then(function (user) {
        //获取用户对象
        _this.client = user;

        //获取非暂态对话对象
        // user.getConversation(_this.conversationId).then(function (conversation) {
        //   _this.conversation = conversation;
        // });
        //获取暂态对话对象
        // user.getConversation(_this.chatRoomId).then(function (chatRoom) {
        //   _this.chatRoom = chatRoom;
        // })
      });
    },
    methods: {
      createConversation: function () {
        //创建非暂态对话对象
        let _this = this;
        this.client.createConversation({
          members: ['Harry', 'Tom', 'Jack'],
          name: '测试群聊1',
          transient: false,
          unique: true
        }).then(function (conversation) {
          console.log('创建群聊成功,conversation is:', conversation);
          _this.conversation = conversation;
          _this.conversationId = conversation.id;
        });
      },
      createChatRoom: function () {
        //创建暂态对话对象
        let _this = this;
        this.client.createConversation({
          name: '测试群聊天室1',
          transient: true
        }).then(function (chatRoom) {
          console.log('创建聊天室成功,chatRoom is:', chatRoom);
          _this.chatRoom = chatRoom;
          _this.chatRoom = chatRoom.id;
        });
      },
      test: function () {
        //测试退出群聊
        console.log('client is:', this.client);
        console.log('conversation is:', this.conversation);
        this.conversation.quit().then(function (conversation) {
          console.log('退出群聊成功', conversation.members);
        }).catch(console.error.bind(console));
      },
      test2: function () {
        //测试退出聊天室
        console.log('client is:', this.client);
        console.log('chatRoom is:', this.conversation);
        this.chatRoom.quit().then(function (chatRoom) {
          console.log('退出聊天室成功', chatRoom.members);
        }).catch(console.error.bind(console));
      },
      test3: function () {
        //测试加入群聊
        this.conversation.join().then(function (conversation) {
          console.log('加入成功', conversation.members);
        }).catch(console.error.bind(console));
      },
      test4: function () {
        //测试加入聊天室
        this.chatRoom.join().then(function (chatRoom) {
          console.log('加入聊天室成功', chatRoom.members);
        }).catch(console.error.bind(console));
      }
    }
  }
</script>

并且还发现,直接用js sdk里的,createChatRoom的那个方法,也会报错is not a function fearful

createChatRoom 不存在是因为你用的 SDK 是 3.5.7 版本,这个 API 是 4.0.0 加入的。

join 方法不存在是因为:

          console.log('创建聊天室成功,chatRoom is:', chatRoom);
          _this.chatRoom = chatRoom;
          _this.chatRoom = chatRoom.id;

scream
多谢指出bug
现在不报错,但是仍然,聊天室加入成员是木有效果的。

test4: function () {
        //测试加入聊天室
        this.chatRoom.join().then(function (chatRoom) {
          console.log('加入聊天室成功', chatRoom.members);
        }).catch(console.error.bind(console));
        this.chatRoom.add(['jerry']).then(function (chatRoom) {
          console.log('加入Jerry聊天室成功', chatRoom.members);
        }).catch(console.error.bind(console));
      }

有成功回调信息的输出,但是控制台里,没有成员信息,返回的members也是空的。

嗦嘎,我大概知道我为什么会产生这个问题,之前聊天室的成员加入,我是利用REST API中的添加对话成员的接口这种方式,就会在控制台内,m列上加上成员的clientId,所以都是利用members的列表来处理暂态对话,难怪利用REST API的查询聊天室的在线人数始终为0。聊天室的加入和退出,只能从客户端这边来操作,并且效果是体现在“在线人数”上面的,感谢您的解答,我知道怎么处理了。 gift gift

1 人赞了这个帖子.