Skip to content

Commit ead7774

Browse files
author
Adam Warner
committed
- Check for null before Attachments.Any()
- move message number to start of message
1 parent 8b799b4 commit ead7774

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

Matterhook.NET.MatterhookClient/MatterhookClient.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public MattermostMessage CloneMessage(MattermostMessage message)
3232
return new MattermostMessage
3333
{
3434
Text = "",
35-
Attachments = null,
3635
Channel = message.Channel,
3736
Username = message.Username,
3837
IconUrl = message.IconUrl
@@ -43,7 +42,6 @@ public async Task<HttpResponseMessage> PostAsync(MattermostMessage message)
4342
{
4443
try
4544
{
46-
//string[] lines = theText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
4745
HttpResponseMessage response = null;
4846
var messages = new List<MattermostMessage>();
4947

@@ -53,7 +51,7 @@ public async Task<HttpResponseMessage> PostAsync(MattermostMessage message)
5351
var lines = new string[] { };
5452
if (message.Text != null)
5553
{
56-
lines = message.Text.Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.None);
54+
lines = message.Text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
5755
}
5856

5957
messages.Add(CloneMessage(message));
@@ -71,20 +69,20 @@ public async Task<HttpResponseMessage> PostAsync(MattermostMessage message)
7169

7270
var len = messages[cnt].Text.Length;
7371

74-
if (message.Attachments.Any())
72+
if (message.Attachments?.Any() ?? false)
7573
{
76-
messages[cnt].Attachments = new List<MattermostAttachment> {new MattermostAttachment()};
74+
messages[cnt].Attachments = new List<MattermostAttachment> { new MattermostAttachment() };
7775
messages[cnt].Attachments[0].Text = "";
7876

79-
lines = message.Attachments[0].Text.Split(new[] {"\r\n", "\r", "\n"}, StringSplitOptions.None);
77+
lines = message.Attachments[0].Text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
8078

8179
foreach (var line in lines)
8280
{
8381
if (len + messages[cnt].Attachments[0].Text.Length + line.Length > 3800)
8482
{
8583
cnt += 1;
8684
messages.Add(CloneMessage(message));
87-
messages[cnt].Attachments = new List<MattermostAttachment> {new MattermostAttachment()};
85+
messages[cnt].Attachments = new List<MattermostAttachment> { new MattermostAttachment() };
8886
messages[cnt].Attachments[0].Text = "";
8987
}
9088

@@ -98,7 +96,7 @@ public async Task<HttpResponseMessage> PostAsync(MattermostMessage message)
9896
var num = 1;
9997
foreach (var msg in messages)
10098
{
101-
msg.Text += $" ({num}/{cnt + 1})";
99+
msg.Text = $"`({num}/{cnt + 1}): ` " + msg.Text;
102100
num++;
103101
}
104102
}

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 1.2.{build}
1+
version: 1.2.1{build}
22
pull_requests:
33
do_not_increment_build_number: true
44
image: Visual Studio 2017

0 commit comments

Comments
 (0)