Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

javascript - 如何与getstream.io进行一对一聊天?(how to initiate one-to-one chat with getstream.io?)

I'm trying to create slack like application using getstream.io chat SDK.(我正在尝试使用getstream.io chat SDK创建类似应用程序的松弛。)

In the documentation we can find out, how to initiate a channel to start group chat.(在文档中,我们可以找到如何启动频道以开始群聊。) But there is no any information about one-to-one chat.(但是,没有有关一对一聊天的任何信息。) Does anyone knows how to initiate a one-to-one chat?(有谁知道如何发起一对一聊天?) code sample to create new channel for group chat(代码示例以创建新的群组聊天渠道) const client = new StreamChat('t5v25xyujjjq'); await client.setUser( { id: 'jlahey', name: 'Jim Lahey', image: 'https://i.imgur.com/fR9Jz14.png', }, 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiamxhaGV5In0.sFe9WvuHIKgQmgtEWFh708Nu_a2wy8Zj3Q8BJz7fDRY', ); const channel = chatClient.channel('messaging', 'groupname', { name: 'Founder Chat', image: 'profile image url', members: ['user1', 'user2'], }); const response = await channel.sendMessage({ text: 'Josh I told them I was pesca-pescatarian' });   ask by Ajantha Bandara translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want to have the guarantee that only one channel exists between N users you can instantiate the Channel without ID and the list of its members.(如果要保证N个用户之间仅存在一个频道,则可以实例化没有ID的频道及其成员列表。)

When you do that, the API will ensure that only one channel with the list of members exists (order of the members does not matter).(当您执行此操作时,API将确保仅存在一个包含成员列表的频道(成员的顺序无关紧要)。) const distinctChannel = conversation.channel("messaging","", { members: [user1.id, user2.id], }); await distinctChannel.create(); Since the channel data is going to be the same for both members;(由于两个成员的渠道数据都将相同;) I suggest to not store the image field the way you do in your code example.(我建议不要image在代码示例中那样存储image字段。) It is easier to use the "other" member profile image as the channel image when you render the conversation.(呈现对话时,使用“其他”成员个人资料图像作为频道图像会更容易。) For example:(例如:) let channelImage = "https://path/to/fallback/image"; otherMembers = channel.members.filter(member => member.user.id != currentUser.id); if otherMembers.length > 0 { channelImage = otherMembers[0].image; }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[2] html - How to create even cell spacing within a

1.4m articles

1.4m replys

5 comments

57.0k users

...