[Problem/Question]
// Detailed description of issue.
I am trying to build a chat app. I connect to SendBird, authenticate a user. And ask the app to create or join a channel called “General” with a custom type. The method executes succesfully with no reports of any errors, but when I refresh and list channels, the list is empty. Do not understand why. The code is below.
// If problem, please fill out the below. If question, please delete.
[SDK Version]
// What version of the SDK are you using?
Don’t know.
[Reproduction Steps]
// Please provide reproduction steps and, if possible, code snippets.
function joinOrCreateChannel() {
sb.setDebugMode(true);
const channelName = "General"; // Shared channel name
const customType = "shared_general_channel"; // Unique identifier for the global channel
const query1 = sb.GroupChannel.createMyGroupChannelListQuery();
query1.includeEmpty = true;
query1.next((channels, error) => {
console.log("All Channels:", channels);
});
// Search for an existing channel with the same custom type
const query = sb.GroupChannel.createMyGroupChannelListQuery();
query.customTypesFilter = [customType]; // Filter by custom type
query.includeEmpty = true; // Include empty channels in the results
query.next((channels, error) => {
if (error) {
console.error("Error searching for channels:", error);
return;
}
if (channels.length > 0) {
// Join the existing channel
const existingChannel = channels[0];
console.log("Joining existing channel:", existingChannel);
loadMessages(existingChannel);
setupMessageHandler(existingChannel);
} else {
if (!sb.currentUser) {
console.error("User is not authenticated. Please connect a user before creating channels.");
return;
}
console.log("User authenticated:", sb.currentUser.userId);
// Create a new channel if it doesn't exist
const params = new sb.GroupChannelParams();
params.name = channelName;
params.isDistinct = false; // This ensures the channel is not tied to specific users
params.customType = customType; // Use the unique custom type for this channel
params.addUserIds([]); // Leave empty to allow open access to the channel
console.log("Creating channel with parameters:", params);
sb.GroupChannel.createChannel(params, (channel, error) => {
if (error) {
console.error("Error creating channel:", error);
return;
}
console.log("Created new channel:", channel);
loadMessages(channel);
setupMessageHandler(channel);
});
}
});
}
[Frequency]
// How frequently is this issue occurring?
Everytime
[Current impact]
// How is this currently impacting your implementation?
Can’t move forward to the next step of my implementation because of this problem