Added `hasJoinedBefore()` to check whether the channel has been joined or not

This commit is contained in:
Tristan B. Kildaire 2020-10-18 11:49:04 +02:00
parent e126bf62c1
commit bee0cbc5b7
2 changed files with 32 additions and 4 deletions

View File

@ -10,6 +10,7 @@
import gtk.Box; import gtk.Box;
import gtk.ListBox; import gtk.ListBox;
import gtk.Label; import gtk.Label;
import gtk.TextView;
public final class Channel public final class Channel
{ {
@ -29,10 +30,10 @@ public final class Channel
* Users's box * Users's box
* - Label users * - Label users
* - ListBox users * - ListBox users
*/ */
private ListBox users; private ListBox users;
private ListBox textArea; private ListBox textArea;
private TextView textInput;
this(string channelName) this(string channelName)
{ {
@ -62,8 +63,9 @@ public final class Channel
ScrolledWindow scrollTextChats = new ScrolledWindow(textArea); ScrolledWindow scrollTextChats = new ScrolledWindow(textArea);
textBox.add(scrollTextChats); textBox.add(scrollTextChats);
import gtk.TextView;
textBox.add(new TextView()); textInput = new TextView();
textBox.add(textInput);
// import gtk.TextView; // import gtk.TextView;
@ -86,4 +88,8 @@ public final class Channel
return box; return box;
} }
public string getName()
{
return channelName;
}
} }

View File

@ -11,6 +11,7 @@ import gtk.ListBox;
import gtk.Label; import gtk.Label;
import Channel; import Channel;
import std.string;
public final class Connection : Thread public final class Connection : Thread
{ {
@ -181,11 +182,32 @@ public final class Connection : Thread
} }
} }
private bool hasJoinedBefore(string channelName)
{
bool result;
foreach(Channel channel; chans)
{
if(cmp(channel.getName(), channelName))
{
result = true;
break;
}
}
return result;
}
private void selectChannel(ListBox s) private void selectChannel(ListBox s)
{ {
/* Get the name of the channel selected */ /* Get the name of the channel selected */
string channelSelected = (cast(Label)(s.getSelectedRow().getChild())).getText(); string channelSelected = (cast(Label)(s.getSelectedRow().getChild())).getText();
/* Check if we have joined this channel already */
hasJoinedBefore(channelSelected);
/* Join the channel */ /* Join the channel */
client.join(channelSelected); client.join(channelSelected);