1 // OpenTween - Client of Twitter
2 // Copyright (c) 2018 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
5 // This file is part of OpenTween.
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
22 using System.Runtime.Serialization;
24 namespace OpenTween.Api.DataModel
26 public interface ITwitterStreamMessage
30 public class StreamMessageStatus : ITwitterStreamMessage
32 public TwitterStatusCompat Status { get; }
34 public StreamMessageStatus(TwitterStatusCompat status)
35 => this.Status = status;
37 public static StreamMessageStatus ParseJson(string json)
38 => new StreamMessageStatus(TwitterStatusCompat.ParseJson(json));
41 public class StreamMessageEvent : ITwitterStreamMessage
43 public TwitterStreamEvent Event { get; }
44 public string Json { get; }
46 public StreamMessageEvent(TwitterStreamEvent eventData, string json)
48 this.Event = eventData;
52 public TwitterStreamEvent<T> ParseTargetObjectAs<T>()
53 => TwitterStreamEvent<T>.ParseJson(this.Json);
55 public static StreamMessageEvent ParseJson(string json)
56 => new StreamMessageEvent(TwitterStreamEvent.ParseJson(json), json);
60 public class StreamMessageDirectMessage : ITwitterStreamMessage
62 [DataMember(Name = "direct_message")]
63 public TwitterDirectMessage DirectMessage { get; set; }
65 public static StreamMessageDirectMessage ParseJson(string json)
66 => MyCommon.CreateDataFromJson<StreamMessageDirectMessage>(json);
70 public class StreamMessageDelete : ITwitterStreamMessage
73 public class DeletedId
75 [DataMember(Name = "id")]
76 public long Id { get; set; }
79 [DataMember(Name = "direct_message", IsRequired = false)]
80 public DeletedId DirectMessage { get; set; } // Nullable
82 [DataMember(Name = "status", IsRequired = false)]
83 public DeletedId Status { get; set; } // Nullable
85 public static StreamMessageDelete ParseJson(string json)
86 => MyCommon.CreateDataFromJson<StreamMessageDelete>(json);
90 public class StreamMessageScrubGeo : ITwitterStreamMessage
92 [DataMember(Name = "user_id")]
93 public long UserId { get; set; }
95 [DataMember(Name = "up_to_status_id")]
96 public long UpToStatusId { get; set; }
98 public static StreamMessageScrubGeo ParseJson(string json)
99 => MyCommon.CreateDataFromJson<StreamMessageScrubGeo>(json);
102 public class StreamMessageKeepAlive : ITwitterStreamMessage
106 public class StreamMessageUnknown : ITwitterStreamMessage
108 public string Json { get; }
110 public StreamMessageUnknown(string json)