public Actor GetUser(TwitterUser twitterUser) { var actorUrl = UrlFactory.GetActorUrl(_instanceSettings.Domain, twitterUser.Acct); var acct = twitterUser.Acct.ToLowerInvariant(); // Extract links, mentions, etc var description = twitterUser.Description; if (!string.IsNullOrWhiteSpace(description)) { var extracted = _statusExtractor.Extract(description, _instanceSettings.ResolveMentionsInProfiles); description = extracted.content; _statisticsHandler.ExtractedDescription(extracted.tags.Count(x => x.type == "Mention")); } var user = new Actor { id = actorUrl, type = "Service", followers = $"{actorUrl}/followers", preferredUsername = acct, name = twitterUser.Name, inbox = $"{actorUrl}/inbox", summary = description, url = actorUrl, manuallyApprovesFollowers = twitterUser.Protected, publicKey = new PublicKey() { id = $"{actorUrl}#main-key", owner = actorUrl, publicKeyPem = _cryptoService.GetUserPem(acct) }, icon = new Image { mediaType = "image/jpeg", url = twitterUser.ProfileImageUrl }, image = new Image { mediaType = "image/jpeg", url = twitterUser.ProfileBannerURL }, attachment = new [] { new UserAttachment { type = "PropertyValue", name = "Official", value = $"<a href=\"https://twitter.com/{acct}\" rel=\"me nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">twitter.com/{acct}</span></a>" } }, endpoints = new EndPoints { sharedInbox = $"https://{_instanceSettings.Domain}/inbox" } }; return(user); }
public async Task PostNewNoteActivity(Note note, string username, string noteId, string targetHost, string targetInbox) { try { var actor = UrlFactory.GetActorUrl(_instanceSettings.Domain, username); var noteUri = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, noteId); var now = DateTime.UtcNow; var nowString = now.ToString("s") + "Z"; var noteActivity = new ActivityCreateNote() { context = "https://www.w3.org/ns/activitystreams", id = $"{noteUri}/activity", type = "Create", actor = actor, published = nowString, to = note.to, cc = note.cc, apObject = note }; await PostDataAsync(noteActivity, targetHost, actor, targetInbox); } catch (Exception e) { _logger.LogError(e, "Error sending {Username} post ({NoteId}) to {Host}{Inbox}", username, noteId, targetHost, targetInbox); throw; } }
public Note GetStatus(string username, ExtractedTweet tweet) { var actorUrl = UrlFactory.GetActorUrl(_instanceSettings.Domain, username); var noteUrl = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, tweet.Id.ToString()); var to = $"{actorUrl}/followers"; var apPublic = "https://www.w3.org/ns/activitystreams#Public"; var extractedTags = _statusExtractor.Extract(tweet.MessageContent); _statisticsHandler.ExtractedStatus(extractedTags.tags.Count(x => x.type == "Mention")); // Replace RT by a link var content = extractedTags.content; if (content.Contains("{RT}") && tweet.IsRetweet) { if (!string.IsNullOrWhiteSpace(tweet.RetweetUrl)) { content = content.Replace("{RT}", $@"<a href=""{tweet.RetweetUrl}"" rel=""nofollow noopener noreferrer"" target=""_blank"">RT</a>"); } else { content = content.Replace("{RT}", "RT"); } } string inReplyTo = null; if (tweet.InReplyToStatusId != default) { inReplyTo = $"https://{_instanceSettings.Domain}/users/{tweet.InReplyToAccount.ToLowerInvariant()}/statuses/{tweet.InReplyToStatusId}"; } var note = new Note { id = noteUrl, published = tweet.CreatedAt.ToString("s") + "Z", url = noteUrl, attributedTo = actorUrl, inReplyTo = inReplyTo, //to = new [] {to}, //cc = new [] { apPublic }, to = new[] { to }, //cc = new[] { apPublic }, cc = new string[0], sensitive = false, content = $"<p>{content}</p>", attachment = Convert(tweet.Media), tag = extractedTags.tags }; return(note); }
public async Task ProcessAsync(Follower follower, SyncTwitterUser twitterUser) { try { var activityFollowing = new ActivityFollow { type = "Follow", actor = follower.ActorId, apObject = UrlFactory.GetActorUrl(_instanceSettings.Domain, twitterUser.Acct) }; await _userService.SendRejectFollowAsync(activityFollowing, follower.Host); } catch (Exception) { } }
public async Task PostNewNoteActivity(Note note, string username, string noteId, string targetHost, string targetInbox) { var actor = UrlFactory.GetActorUrl(_instanceSettings.Domain, username); var noteUri = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, noteId); var now = DateTime.UtcNow; var nowString = now.ToString("s") + "Z"; var noteActivity = new ActivityCreateNote() { context = "https://www.w3.org/ns/activitystreams", id = $"{noteUri}/activity", type = "Create", actor = actor, published = nowString, to = note.to, cc = note.cc, apObject = note }; await PostDataAsync(noteActivity, targetHost, actor, targetInbox); }
public IActionResult Webfinger(string resource = null) { var acct = resource.Split("acct:")[1].Trim(); string name = null; string domain = null; var splitAcct = acct.Split('@', StringSplitOptions.RemoveEmptyEntries); var atCount = acct.Count(x => x == '@'); if (atCount == 1 && acct.StartsWith('@')) { name = splitAcct[1]; } else if (atCount == 1 || atCount == 2) { name = splitAcct[0]; domain = splitAcct[1]; } else { return(BadRequest()); } // Ensure lowercase name = name.ToLowerInvariant(); if (!string.IsNullOrWhiteSpace(domain) && domain != _settings.Domain) { return(NotFound()); } var user = _twitterUserService.GetUser(name); if (user == null) { return(NotFound()); } var actorUrl = UrlFactory.GetActorUrl(_settings.Domain, name); var result = new WebFingerResult() { subject = $"acct:{name}@{_settings.Domain}", aliases = new[] { actorUrl }, links = new List <WebFingerLink> { new WebFingerLink() { rel = "http://webfinger.net/rel/profile-page", type = "text/html", href = actorUrl }, new WebFingerLink() { rel = "self", type = "application/activity+json", href = actorUrl } } }; return(new JsonResult(result)); }