Now messages are received and placed in the respective channel

This commit is contained in:
Tristan B. Kildaire 2020-10-20 23:39:56 +02:00
parent bf36f033be
commit 953493cb07
2 changed files with 43 additions and 4 deletions

View File

@ -302,7 +302,29 @@ public final class Channel
// box.showAll();+
}
public void sendMessage(string message)
{
}
public void receiveMessage(string username, string message)
{
/* Create the MessageBox */
Box messageBox = new Box(GtkOrientation.VERTICAL, 1);
/* Create and add the username */
Label usernameLabel = new Label("");
usernameLabel.setMarkup("<b>"~username~"</b>");
usernameLabel.setHalign(GtkAlign.START);
messageBox.add(usernameLabel);
/* Create and add the message */
Label messageLabel = new Label(message);
messageLabel.setHalign(GtkAlign.START);
messageBox.add(messageLabel);
textArea.add(messageBox);
}
public void addMessage(string s)
{

View File

@ -104,9 +104,6 @@ public final class Connection : Thread
/* Set your prescense */
client.setProperty("pres","available");
/* Display all channels */
//channelList();
/**
* Notification loop
*
@ -155,6 +152,26 @@ public final class Connection : Thread
/* TODO: Decode using tristanable */
writeln("new message");
writeln(data);
/* Decode is a test for assuming channel message received */
data = data[1..data.length];
/* Decode the [usernameLength, username] */
ubyte usernameLength = data[1];
writeln(usernameLength);
string username = cast(string)data[2..2+usernameLength];
writeln(username);
/* Decode the [channelLength, channel] */
ubyte channelLength = data[2+usernameLength];
writeln(channelLength);
string channel = cast(string)data[2+usernameLength+1..2+usernameLength+1+channelLength];
writeln(channel);
findChannel(channel).receiveMessage(username, cast(string)data[2+usernameLength+1+channelLength..data.length]);
writeln("hdsfhdk");
}
/* Channel notification (ntype=1) */
else if(notificationType == 1)