コード例 #1
0
        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;
            }
        }
コード例 #2
0
        public async Task <IActionResult> PostNote()
        {
            var username   = "******";
            var actor      = $"https://{_instanceSettings.Domain}/users/{username}";
            var targetHost = "mastodon.technology";
            var target     = $"{targetHost}/users/testtest";
            var inbox      = $"/users/testtest/inbox";

            var noteGuid = Guid.NewGuid();
            var noteId   = $"https://{_instanceSettings.Domain}/users/{username}/statuses/{noteGuid}";
            var noteUrl  = $"https://{_instanceSettings.Domain}/@{username}/{noteGuid}";

            var to = $"{actor}/followers";

            var now       = DateTime.UtcNow;
            var nowString = now.ToString("s") + "Z";

            var noteActivity = new ActivityCreateNote()
            {
                context   = "https://www.w3.org/ns/activitystreams",
                id        = $"{noteId}/activity",
                type      = "Create",
                actor     = actor,
                published = nowString,
                to        = new [] { to },
                //cc = new [] { "https://www.w3.org/ns/activitystreams#Public" },
                apObject = new Note()
                {
                    id           = noteId,
                    summary      = null,
                    inReplyTo    = null,
                    published    = nowString,
                    url          = noteUrl,
                    attributedTo = actor,

                    // Unlisted
                    to = new[] { to },
                    cc = new [] { "https://www.w3.org/ns/activitystreams#Public" },

                    //// Public
                    //to = new[] { "https://www.w3.org/ns/activitystreams#Public" },
                    //cc = new[] { to },

                    sensitive  = false,
                    content    = "<p>TEST PUBLIC</p>",
                    attachment = new Attachment[0],
                    tag        = new Tag[0]
                }
            };

            await _activityPubService.PostDataAsync(noteActivity, targetHost, actor, inbox);

            return(View("Index"));
        }
コード例 #3
0
        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);
        }