Live Chat

Initial Setup

  1. Add a DataGridView.

  2. Set your DataGridView row select to FullRowSelect.

Update Chat

message.Author[1] gets the users username & message.Author[0] gets the users ID.

private async void UpdateChat()
{
var chat = await FusionApp.GetChat();
if (chat.Error == false)
{
dgMessage.Rows.Clear();
foreach (var message in chat.Chat)
{
dgMessage.Rows.Insert(0, message.MessageId, DateTimeOffset.FromUnixTimeSeconds((long)Convert.ToDouble(message.Timestamp)).DateTime, message.Author[1], message.Content);
}
}
else
{
MessageBox.Show(chat.Message, "FusionAPI.dev");
}
}

Send Message

private async void btnSend_Click(object sender, EventArgs e)
{
var sendMessage = await FusionApp.SendMessage(tbMessage.Text);
if (sendMessage.Error == false)
{
UpdateChat();
}
else
{
MessageBox.Show(sendMessage.Message, "FusionAPI.dev");
}
}

Delete Message

This requires MessageID in order to delete the message.

  1. Add a ContextMenuStrip to your application.

  2. Link your ContextMenuStrip to your DataGridView through its properties.

Double click Delete Message to create a click event.

private async void deleteMessageToolStripMenuItem_Click(object sender, EventArgs e)
{
var deleteMessage = await FusionApp.DeleteMessage(dgMessage.CurrentRow.Cells[0].Value.ToString());
if (deleteMessage.Error == false)
{
UpdateChat();
}
else
{
MessageBox.Show(deleteMessage.Message, "FusionAPI.dev");
}
}

Edit Message

This requires MessageID in order to edit the message.

  1. Add a ContextMenuStrip to your application.

  2. Link your ContextMenuStrip to your DataGridView through its properties.

  1. Add a panel to your app to edit the message.

Double click Edit Message to create a click event.

private async void btnEditMessage_Click(object sender, EventArgs e)
{
var editMessage = await FusionApp.EditMessage(dgMessage.CurrentRow.Cells[0].Value.ToString(), tbEditMessage.Text);
if (editMessage.Error == false)
{
pnlEditMessage.Visible = false;
UpdateChat();
}
else
{
MessageBox.Show(editMessage.Message, "FusionAPI.dev");
}
}