// OpenTween - Client of Twitter
// Copyright (c) 2023 kim_upsilon (@kim_upsilon)
// All rights reserved.
//
// This file is part of OpenTween.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program. If not, see , or write to
// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.
#nullable enable
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using OpenTween.Connection;
using OpenTween.Models;
namespace OpenTween.Api.GraphQL
{
public class TweetDetailRequest
{
public static readonly string EndpointName = "TweetDetail";
private static readonly Uri EndpointUri = new("https://twitter.com/i/api/graphql/-Ls3CrSQNo2fRKH6i6Na1A/TweetDetail");
public required TwitterStatusId FocalTweetId { get; set; }
public Dictionary CreateParameters()
{
return new()
{
["variables"] = $$"""
{"focalTweetId":"{{this.FocalTweetId.Id}}","with_rux_injections":false,"includePromotedContent":true,"withCommunity":true,"withQuickPromoteEligibilityTweetFields":true,"withBirdwatchNotes":true,"withVoice":true,"withV2Timeline":true}
""",
["features"] = """
{"rweb_lists_timeline_redesign_enabled":true,"responsive_web_graphql_exclude_directive_enabled":true,"verified_phone_label_enabled":false,"creator_subscriptions_tweet_preview_api_enabled":true,"responsive_web_graphql_timeline_navigation_enabled":true,"responsive_web_graphql_skip_user_profile_image_extensions_enabled":false,"tweetypie_unmention_optimization_enabled":true,"responsive_web_edit_tweet_api_enabled":true,"graphql_is_translatable_rweb_tweet_is_translatable_enabled":true,"view_counts_everywhere_api_enabled":true,"longform_notetweets_consumption_enabled":true,"responsive_web_twitter_article_tweet_consumption_enabled":false,"tweet_awards_web_tipping_enabled":false,"freedom_of_speech_not_reach_fetch_enabled":true,"standardized_nudges_misinfo":true,"tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled":true,"longform_notetweets_rich_text_read_enabled":true,"longform_notetweets_inline_media_enabled":true,"responsive_web_media_download_video_enabled":false,"responsive_web_enhance_cards_enabled":false}
""",
["fieldToggles"] = """
{"withAuxiliaryUserLabels":false,"withArticleRichContentState":false}
""",
};
}
public async Task Send(IApiConnection apiConnection)
{
var request = new GetRequest
{
RequestUri = EndpointUri,
Query = this.CreateParameters(),
EndpointName = EndpointName,
};
using var response = await apiConnection.SendAsync(request)
.ConfigureAwait(false);
var rootElm = await response.ReadAsJsonXml()
.ConfigureAwait(false);
ErrorResponse.ThrowIfError(rootElm);
return TimelineTweet.ExtractTimelineTweets(rootElm);
}
}
}