Skip to content

Commit

Permalink
MultiWebSocket
Browse files Browse the repository at this point in the history
Change: objects class move to the Models folder,
List will all the slackChannel(Group, DM, Channels).
Father class SlackChannel from all channels(Group, DM, Channels).
Fix bug when the socket receive a message with type null.
Fix the error when the slackSocketClient try open socket with
LoginReponse is not Ok,
Add more events, and now the event pass back the
slackclient/slacksocketclient
  • Loading branch information
CarlosPacheco committed Jun 27, 2016
1 parent ea9f946 commit 2389db1
Show file tree
Hide file tree
Showing 96 changed files with 754 additions and 681 deletions.
27 changes: 0 additions & 27 deletions Attachment.cs

This file was deleted.

37 changes: 0 additions & 37 deletions Channel.cs

This file was deleted.

21 changes: 0 additions & 21 deletions DirectMessageConversation.cs

This file was deleted.

3 changes: 2 additions & 1 deletion IntegrationTest/Connect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using IntegrationTest.Helpers;
using Polly;
using SlackAPI.WebSocketMessages;
using SlackAPI.Models;

namespace IntegrationTest
{
Expand Down Expand Up @@ -85,7 +86,7 @@ public void TestConnectPostAndDelete()

// then
Assert.IsNotNull(deletedResponse, "No response was found");
Assert.IsTrue(deletedResponse.ok, "Message not deleted!");
Assert.IsTrue(deletedResponse.Ok, "Message not deleted!");
Assert.AreEqual(channel, deletedResponse.channel, "Got invalid channel? Something's not right here...");
Assert.AreEqual(messageTimestamp, deletedResponse.ts, "Got invalid time stamp? Something's not right here...");
}
Expand Down
2 changes: 1 addition & 1 deletion IntegrationTest/Helpers/ClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static SlackSocketClient GetClient(string authToken)
var wait = new EventWaitHandle(false, EventResetMode.ManualReset);

var client = new SlackSocketClient(authToken);
client.Connect(x =>
client.Connect((x,sc) =>
{
Console.WriteLine("RTM Start");
}, () =>
Expand Down
33 changes: 17 additions & 16 deletions IntegrationTest/Helpers/SlackMother.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
namespace IntegrationTest.Helpers
{
using SlackAPI;
using SlackAPI;
using SlackAPI.Models;

namespace IntegrationTest.Helpers
{
public class SlackMother
{
public static Attachment[] SomeAttachments => new[]
{
new Attachment()
{
fallback = "Required plain-text summary of the attachment.",
color = "#36a64f",
pretext = "Optional text that appears above the attachment block",
author_name = "Bobby Tables",
author_link = "http://flickr.com/bobby/",
author_icon = "http://flickr.com/icons/bobby.jpg",
title = "Slack API Documentation",
title_link = "https://api.slack.com/",
text = "Optional text that appears within the attachment",
fields = new[]
Fallback = "Required plain-text summary of the attachment.",
Color = "#36a64f",
Pretext = "Optional text that appears above the attachment block",
AuthorName = "Bobby Tables",
AuthorLink = "http://flickr.com/bobby/",
AuthorIcon = "http://flickr.com/icons/bobby.jpg",
Title = "Slack API Documentation",
TitleLink = "https://api.slack.com/",
Text = "Optional text that appears within the attachment",
Fields = new[]
{
new Field() { title = "Priority", value = "High", @short = false },
new Field() { title = "Priority", value = "High", @short = true },
new Field() { title = "Priority", value = "High", @short = true }
new Field() { Title = "Priority", Value = "High", IsShort = false },
new Field() { Title = "Priority", Value = "High", IsShort = true },
new Field() { Title = "Priority", Value = "High", IsShort = true }
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions IntegrationTest/JoinDirectMessageChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public void ShouldJoinDirectMessageChannel()
EventWaitHandle wait = new EventWaitHandle(false, EventResetMode.ManualReset);
client.JoinDirectMessageChannel(response =>
{
Assert.IsTrue(response.ok, "Error while joining user channel");
Assert.IsTrue(!string.IsNullOrEmpty(response.channel.id), "We expected a channel id to be returned");
Assert.IsTrue(response.Ok, "Error while joining user channel");
Assert.IsTrue(!string.IsNullOrEmpty(response.channel.Id), "We expected a channel id to be returned");
wait.Set();
}, user);

Expand Down
6 changes: 3 additions & 3 deletions IntegrationTest/PostMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace IntegrationTest
{
using SlackAPI;

using SlackAPI.Models;
[TestClass]
public class PostMessage
{
Expand Down Expand Up @@ -41,7 +41,7 @@ public void SimpleMessageDelivery()
}

// then
Assert.IsTrue(actual.ok, "Error while posting message to channel. ");
Assert.IsTrue(actual.Ok, "Error while posting message to channel. ");
Assert.AreEqual(actual.message.text, "Hi there!");
Assert.AreEqual(actual.message.type, "message");
}
Expand All @@ -68,7 +68,7 @@ public void Attachments()
}

// then
Assert.IsTrue(actual.ok, "Error while posting message to channel. ");
Assert.IsTrue(actual.Ok, "Error while posting message to channel. ");
}
}
}
6 changes: 3 additions & 3 deletions IntegrationTest/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace IntegrationTest
{
using SlackAPI;

using SlackAPI.Models;
[TestClass]
public class Update
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public void SimpleUpdate()
}

// then
Assert.IsTrue(actual.ok, "Error while posting message to channel. ");
Assert.IsTrue(actual.Ok, "Error while posting message to channel. ");
Assert.AreEqual(actual.message.text, "[changed]");
Assert.AreEqual(actual.message.type, "message");
}
Expand All @@ -56,7 +56,7 @@ private string PostedMessage(SlackSocketClient client)
response =>
{
messageId = response.ts;
Assert.IsTrue(response.ok, "Error while posting message to channel. ");
Assert.IsTrue(response.Ok, "Error while posting message to channel. ");
sync.Proceed();
},
_config.Slack.TestChannel,
Expand Down
3 changes: 2 additions & 1 deletion JavascriptBotsToArray.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using SlackAPI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
59 changes: 59 additions & 0 deletions Models/Attachment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace SlackAPI.Models
{
//See: https://api.slack.com/docs/attachments
public class Attachment
{
[JsonProperty(PropertyName = "fallback")]
public string Fallback { get; set; }

[JsonProperty(PropertyName = "color")]
public string Color { get; set; }

[JsonProperty(PropertyName = "pretext")]
public string Pretext { get; set; }

[JsonProperty(PropertyName = "author_name")]
public string AuthorName { get; set; }

[JsonProperty(PropertyName = "author_link")]
public string AuthorLink { get; set; }

[JsonProperty(PropertyName = "author_icon")]
public string AuthorIcon { get; set; }

[JsonProperty(PropertyName = "title")]
public string Title { get; set; }

[JsonProperty(PropertyName = "title_link")]
public string TitleLink { get; set; }

[JsonProperty(PropertyName = "text")]
public string Text { get; set; }

[JsonProperty(PropertyName = "fields")]
public Field[] Fields { get; set; }

[JsonProperty(PropertyName = "image_url")]
public string ImageUrl { get; set; }

[JsonProperty(PropertyName = "thumb_url")]
public string ThumbUrl { get; set; }

[JsonProperty(PropertyName = "mrkdwn_in")]
public string[] MrkdwnIn { get; set; }
}

public class Field{
[JsonProperty(PropertyName = "title")]
public string Title { get; set; }

[JsonProperty(PropertyName = "value")]
public string Value { get; set; }

[JsonProperty(PropertyName = "short")]
public bool IsShort { get; set; }
}
}
2 changes: 1 addition & 1 deletion Bot.cs → Models/Bot.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace SlackAPI
namespace SlackAPI.Models
{
public class Bot
{
Expand Down
70 changes: 70 additions & 0 deletions Models/Channel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Newtonsoft.Json;
using System;

namespace SlackAPI.Models
{
/// <summary>
/// https://api.slack.com/types/channel
/// </summary>
public class Channel : SlackChannel
{
[JsonProperty(PropertyName = "is_channel")]
public bool IsChannel { get; set; }

/// <summary>
/// Is the user ID of the member that created this private channel.
/// </summary>
[JsonProperty(PropertyName = "creator")]
public string CreatorUserId { get; set; }

/// <summary>
/// Will be true if the channel is archived.
/// </summary>
[JsonProperty(PropertyName = "is_archived")]
public bool IsArchived { get; set; }

[JsonProperty(PropertyName = "is_mpim")]
public bool IsMpim { get; set; }

/// <summary>
/// Is a list of user ids for all users in this channel.
/// This includes any disabled accounts that were in this channel when they were disabled.
/// </summary>
[JsonProperty(PropertyName = "members")]
public string[] Members { get; set; }

/// <summary>
/// Will be true if the calling member is part of the channel.
/// </summary>
[JsonProperty(PropertyName = "is_member")]
public bool IsMember { get; set; }

/// <summary>
/// Will be true if this channel is the "general" channel that includes all regular team members.
/// In most teams this is called #general but some teams have renamed it.
/// </summary>
[JsonProperty(PropertyName = "is_general")]
public bool IsGeneral { get; set; }

[JsonProperty(PropertyName = "is_group")]
public bool IsGroup { get; set; }

[Obsolete]
[JsonProperty(PropertyName = "num_members")]
public int NumMembers { get; set; }

/// <summary>
/// Provide information about the channel topic
/// </summary>
[JsonProperty(PropertyName = "topic")]
public OwnedStampedMessage Topic { get; set; }

/// <summary>
/// Provide information about the channel purpose
/// </summary>
[JsonProperty(PropertyName = "purpose")]
public OwnedStampedMessage Purpose { get; set; }

public override SlackChannelType Type { get { return IsChannel ? SlackChannelType.Channel : SlackChannelType.Group; } }
}
}
8 changes: 1 addition & 7 deletions ContextMessage.cs → Models/ContextMessage.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SlackAPI
namespace SlackAPI.Models
{
public class ContextMessage : Message
{
Expand Down
Loading

1 comment on commit 2389db1

@Inumedia
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty big refactor.

Skimming over it, are you still supporting the original object only callback?

Please sign in to comment.