public async Task VerifyCanSendToChatChannel_PrivateChatDisabled_ReturnError() { // arrange var channelSelector = CreateChatChannelSelector(true); var mediator = CreateMediatorWithFindConference(new ChatOptions { IsPrivateChatEnabled = false }); var context = CreateContext(builder => { builder.RegisterInstance(channelSelector).AsImplementedInterfaces(); builder.RegisterInstance(mediator).AsImplementedInterfaces(); }); var channel = new PrivateChatChannel(new HashSet <string> { "1", "2" }); // act var result = await ServiceInvokerChatMiddleware.VerifyCanSendToChatChannel(context, channel); // assert Assert.False(result.Success); Assert.Equal(ChatError.PrivateMessagesDisabled.Code, result.Error !.Code); }
private bool CanParticipantSendPrivateChatInChannel(ChatOptions options, Participant participant, PrivateChatChannel privateChatChannel) { if (!options.IsPrivateChatEnabled) { return(false); } return(privateChatChannel.Participants.Contains(participant.Id)); }
public static ChatChannel CreateChannel(Player player, ushort channelId) { if (GetChannel(player, channelId) != null) { return(null); } switch (channelId) { case Constants.ChatChannelGuild: //Guild guild = player.getGuild(); //TODO: GUILD //if (guild) //{ // ChatChannel* newChannel = new ChatChannel(channelId, guild->getName()); // guildChannels[guild->getId()] = newChannel; // return newChannel; //} break; case Constants.ChatChannelParty: //Party* party = player.getParty(); //TODO: PARTY //if (party) //{ // ChatChannel* newChannel = new ChatChannel(channelId, "Party"); // partyChannels[party] = newChannel; // return newChannel; //} break; case Constants.ChatChannelPrivate: //only 1 private channel for each premium player if (!player.IsPremium() || GetPrivateChannel(player) != null) { return(null); } //find a free private channel slot for (ushort i = 100; i < 10000; ++i) { if (!PrivateChannels.ContainsKey(i)) { PrivateChatChannel newChannel = new PrivateChatChannel(i, string.Format("{0}'s Channel", player.CharacterName)) { Owner = player.CharacterId }; PrivateChannels[i] = newChannel; return(newChannel); } } break; } return(null); }
private async ValueTask <List <Participant> > UpdateParticipantsSubscriptionsIfNecessary( IReadOnlyList <Participant> subscribedParticipants, PrivateChatChannel channel, string conferenceId) { var result = subscribedParticipants.ToList(); foreach (var participantId in channel.Participants) { if (subscribedParticipants.All(participant => participant.Id != participantId)) { await _mediator.Send(new UpdateSubscriptionsRequest(new Participant(conferenceId, participantId))); result.Add(new Participant(conferenceId, participantId)); } } return(result); }