diff --git a/ChannelSurfCli/Utils/Channels.cs b/ChannelSurfCli/Utils/Channels.cs index 0fcb8e2..c09a050 100644 --- a/ChannelSurfCli/Utils/Channels.cs +++ b/ChannelSurfCli/Utils/Channels.cs @@ -36,6 +36,12 @@ public class Channels channelId = ""; } + if ((bool)obj.SelectToken("is_archived")) + { + Console.WriteLine("Skipping archived slack channel: {0}", obj["name"].ToString()); + continue; + } + slackChannels.Add(new Models.Slack.Channels() { channelId = channelId, diff --git a/ChannelSurfCli/Utils/Messages.cs b/ChannelSurfCli/Utils/Messages.cs index 3b65b6d..0f5e61b 100644 --- a/ChannelSurfCli/Utils/Messages.cs +++ b/ChannelSurfCli/Utils/Messages.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; namespace ChannelSurfCli.Utils { @@ -54,10 +55,10 @@ public static void ScanMessagesByChannel(List c // deal with message basics: when, body, who - var messageTs = (string)obj.SelectToken("ts"); + var messageTs = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(Double.Parse((string)obj.SelectToken("ts"))); var messageText = (string)obj.SelectToken("text"); var messageId = channelsMapping.slackChannelId + "." + messageTs; - //messageText = RegexDetector.DetectSlackParens(messageText, slackUserList); + messageText = DetectSlackParens(messageText, slackUserList); var messageSender = Utils.Messages.FindMessageSender(obj, slackUserList); // create a list of attachments to upload @@ -170,7 +171,7 @@ public static void ScanMessagesByChannel(List c { id = messageId, text = messageText, - ts = messageTs, + ts = messageTs.ToLocalTime().ToString(), user = messageSender, fileAttachment = fileAttachment, attachments = attachmentsList, @@ -358,6 +359,12 @@ public static string MessageToHtml(ViewModels.SimpleMessage simpleMessage, Model return w; } + static string DetectSlackParens(string messageText, List slackUserList) + { + return Regex.Replace(messageText, @"<@(\w+)>", + m => slackUserList.Where(w => w.userId == m.Groups[1].Value) + .DefaultIfEmpty(new ViewModels.SimpleUser() { name = m.Value }).First().name); + } static string FindMessageSender(JObject obj, List slackUserList) { diff --git a/README.md b/README.md index 0496f55..76ad56e 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ Either way, you'll need to decide if you want to: * Re-create Slack channels You can create a Slack Team export on a self-service basis as a Slack Team Owner or Admin at this page [https://my.slack.com/services/export](https://my.slack.com/services/export). Download the export file and tell Channel Surf its location. We'll scan it and re-create the Slack channel structure in Teams - and give you the option to do more. + + WARNING: Slack channels can be public or private - a concept not currently supported in Microsoft Teams. This import tool will re-create all Slack channels in MS Teams, irrespective of whether they were public or private in Slack. Want that to change? Go ahead and [file an issue](https://github.com/tamhinsf/ChannelSurf/issues). * Archive Slack message history (optional)