using System.Web; using MahApps.Twitter.Models; using MahTweets.Extensions.Twitter.Mango.Models; using MahTweets.Mango.Core.Extensions; using MahTweets.Mango.Core.Extensions.MahTweets.Core.Extensions; using MahTweets.Mango.Core.Models; using MahTweets.Mango.Core.Repositories; using MahTweets.Mango.Core.UpdateTypes; namespace MahTweets.Extensions.Twitter.Mango.Extensions { public static class TweetExtensions { public static TweetStatusUpdate ToStatus(this Tweet s, IContactRepository contactsRepository) { if (s.Id == null) return null; var contact = contactsRepository.GetContact(s.User.ScreenName); contact.UpdateContact(s.User); if (s.RetweetedStatus != null) { var retweet = s.RetweetedStatus.ToStatus(contactsRepository); retweet.Time = s.Created.ToLocalTime(); retweet.RetweetBy = contact; retweet.IsRetweet = true; return retweet; } var status = new TweetStatusUpdate { Id = s.Id.ToString(), Contact = contact, Text = HttpUtility.HtmlDecode(s.Text), Time = s.Created.ToLocalTime(), SourceUri = s.Source.GetSourceUrl(), Source = s.Source.GetSourceText(), Favourite = s.Favourited, }; if (s.Source != null) status.Source = s.Source.GetSourceText(); if (s.Geo != null) status.Location = new GeoLocation(s.Geo.Coordinates[0], s.Geo.Coordinates[1]); if (s.InReplyToStatusId > 0) { status.InReplyToId = s.InReplyToStatusId.ToString(); status.InReplyTo = new Contact {Name = s.InReplyToScreenName}; } return status; } public static DirectMessageStatusUpdate ToStatus(this DirectMessage s, Contact contact) { var status = new DirectMessageStatusUpdate { Id = s.Id.ToString(), Contact = contact, Text = HttpUtility.HtmlDecode(s.Text), Time = s.Created.ToLocalTime(), }; return status; } public static void ToTimeline(this TweetStatusUpdate t, AccountCredentials account) { if (t == null) return; t.Accounts.Add(account); if (t is DirectMessageStatusUpdate) t.Types.AddUpdate(account); else if (t.Text.ToUpper().Contains("@" + account.AccountName.ToUpper())) t.Types.AddUpdate(account); else t.Types.AddUpdate(account); } } }