【问题标题】:Joining a 1-to-1 private group in SendBird加入 SendBird 中的一对一私人群组
【发布时间】:2020-03-20 10:12:40
【问题描述】:

使用 SendBird JavaScript SDK,我能够正确地为一对一消息创建一个私人组:

var params = new sb.GroupChannelParams();
params.isPublic = false;
params.isEphemeral = false;
params.isDistinct = true;
params.addUserIds([1, 2]);
params.operatorIds = [1];
params.name = name;

sb.GroupChannel.createChannel(params, function(groupChannel, error) {
    if (error) {
        console.log(error);
        return false;
    }

    sb.GroupChannel.getChannel(groupChannel.url, function(groupChannel) {
        var userIds = [2];

        groupChannel.inviteWithUserIds(userIds, function(response, error) {
            if (error) {
                console.log(error);
                return false;
            }

            console.log(response);
        });
    });
});

这一切正常,在检索群组列表时,两个用户都可以看到私人聊天室。但是,当任一用户尝试加入私有组时,都会遇到错误:

SendBirdException:未授权。 “不能加入非公开 频道。”。

要加入群组,我使用以下代码:

sb.GroupChannel.getChannel(id, function(openChannel, error) {
    if (error) {
        console.log(error);
        return false;
    }

    console.log('Channel Found: ' + openChannel.name + '. Current Participants: ' + openChannel.participantCount);

    openChannel.join(function(response, error) {
        if (error) {
            console.log(error);
            return false;
        }

        console.log('Channel Joined: ' + openChannel.name + '. Current Participants: ' + openChannel.participantCount);

        // retrieving previous messages.
    });
});

上述代码的响应是:

{
    "message": "Not authorized. \"Can't join to non-public channel.\".",
    "code": 400108,
    "error": true
}

非常感谢任何帮助。请注意,我已经检查了文档,它没有提到如何加入私人群组(只有公共群组)。尽管被设置为“操作员”,但我看不到聊天室的“创建者”如何能够加入房间。

【问题讨论】:

    标签: javascript sendbird


    【解决方案1】:

    您似乎正在尝试加入开放频道,而它实际上是一个群组频道。调用该方法调用即可加入群组频道成为会员。

    if (groupChannel.isPublic) {
    groupChannel.join(function(response, error) {
        if (error) {
            return;
        }
    });
    

    }

    代替

    openChannel.join(function(response, error) {
        if (error) {
            console.log(error);
            return false;
        }
    
        console.log('Channel Joined: ' + openChannel.name + '. Current Participants: ' + openChannel.participantCount);
    
        // retrieving previous messages.
    });
    

    https://docs.sendbird.com/javascript/group_channel#3_join_a_channel_as_a_member

    【讨论】:

    • openChannel 只是一个变量。你会注意到我在主函数中使用了sb.GroupChannel。该频道不公开,我的代码中也提到了这一点:params.isPublic = false;。
    • 嗨@NirajShah,您可以将isPublic 设置为true 以查看您的用户是否可以加入。顾名思义,群组频道主要用于私人群组频道,人们通过邀请加入成为会员。如果将 isPublic 的值设置为 true,则人们无需邀请即可加入公共群组频道。请在我们的文档中找到说明“这仅适用于公共群组频道。任何用户都可以作为成员加入公共群组频道而无需邀请并与频道中的其他成员聊天”
    • 是的,设置isPublic = true 让我创建一个房间并加入它没有问题。但是,我特别希望在两个用户之间创建一个私人群组频道,其他人都不能加入(除非受到邀请)。
    猜你喜欢
    • 2019-08-03
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-30
    • 2017-04-30
    相关资源
    最近更新 更多