- Added `joinChannel_imp(string channelName)` which performs the joining of a channel and returns a `Future`
- Added `joinChannel(string channelName)` which is a neat wrapper around the above
- `enumerateChannels(ulong offset, ubyte limit)` now handles incorrect replies by throwing a `ProtocolException` on wrong reply type

Client (unittests)

- Added a unit test for `joinChannel(string channelName)`
This commit is contained in:
Tristan B. Velloza Kildaire 2023-11-18 11:13:20 +02:00
parent 455bd6fa06
commit 4ad56763d8
1 changed files with 80 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import davinci;
import tristanable;
import guillotine;
import guillotine.providers.sequential;
import dante.exceptions;
version(dbg)
{
@ -134,12 +135,74 @@ public class DanteClient
return makeRequest(msg);
}
public Future joinChannel_imp(string channelName)
{
import davinci.c2s.channels : ChannelMembership;
import davinci;
ChannelMembership chanMembershipReq = new ChannelMembership();
chanMembershipReq.join(channelName);
BaseMessage msg = new BaseMessage(MessageType.CLIENT_TO_SERVER, CommandType.MEMBERSHIP_JOIN, chanMembershipReq);
return makeRequest(msg);
}
public void joinChannel(string channelName)
{
import davinci.c2s.channels : ChannelMembership;
import davinci;
BaseMessage response = cast(BaseMessage)joinChannel_imp(channelName).await().getValue().value.object;
import std.stdio;
writeln("Hallo");
writeln("Hallo");
writeln("Hallo");
writeln("Hallo");
writeln("Hallo");
writeln("Hallo");
writeln("Hallo");
writeln("Hallo");
writeln("Hallo");
// TODO: For absolute sanity we should check that
// ... it actually decoded to the type we EXPECT
// ... to be here (this would safeguard against
// ... bad server implementations)
// TODO: Make teh below a `mixin template`
ChannelMembership responseCommand = cast(ChannelMembership)response.getCommand();
if(responseCommand is null)
{
throw ProtocolException.expectedMessageKind(ChannelMembership.classinfo, responseCommand);
}
if(responseCommand.wasGood())
{
return;
}
else
{
throw new CommandException("Could not join channel '"~channelName~"'");
}
}
public string[] enumerateChannels(ulong offset, ubyte limit)
{
import davinci.c2s.channels : ChannelEnumerateReply;
BaseMessage response = cast(BaseMessage)enumerateChannels_imp(offset, limit).await().getValue().value.object;
// TODO: For absolute sanity we should check that
// ... it actually decoded to the type we EXPECT
// ... to be here (this would safeguard against
// ... bad server implementations)
// TODO: Make teh below a `mixin template`
ChannelEnumerateReply responseCommand = cast(ChannelEnumerateReply)response.getCommand();
if(responseCommand is null)
{
throw ProtocolException.expectedMessageKind(ChannelEnumerateReply.classinfo, responseCommand);
}
return responseCommand.getChannels();
}
@ -263,5 +326,22 @@ unittest
string[] channels = client.enumerateChannels();
writeln(dumpArray!(channels));
client.stop();
}
unittest
{
DanteClient client = new DanteClient(new UnixAddress("/tmp/renaissance.sock"));
client.start();
writeln("Joining channel #general...");
client.joinChannel("#general");
writeln("Joined");
// string[] members = client.getMembers("#general");
// client.leaveChannel("#general");
client.stop();
}