}
[DataContract]
- public class TargetObject : TwitterStatus
- {
- [DataMember(Name = "mode")] public string Mode;
- [DataMember(Name = "description")] public string Description;
- [DataMember(Name = "slug")] public string Slug;
- [DataMember(Name = "uri")] public string Uri;
- [DataMember(Name = "member_count")] public int MemberCount;
- [DataMember(Name = "full_name")] public string FullName;
- [DataMember(Name = "subscriber_count")] public int SubscriberCount;
- [DataMember(Name = "name")] public string Name;
- [DataMember(Name = "following")] public bool Following;
- }
-
- [DataContract]
public class Friendsevent
{
[DataMember(Name = "friends")] public Int64[] Friends;
}
[DataContract]
- public class EventData
- {
- [DataMember(Name = "target")] public TwitterUser Target;
- [DataMember(Name = "target_object", IsRequired = false)] public TargetObject TargetObject;
- [DataMember(Name = "created_at")] public string CreatedAt;
- [DataMember(Name = "event")] public string Event;
- [DataMember(Name = "source")] public TwitterUser Source;
- }
-
- [DataContract]
public class RelatedTweet
{
[DataMember(Name = "annotations")] public Annotations Annotations;
--- /dev/null
+// OpenTween - Client of Twitter
+// Copyright (c) 2014 kim_upsilon (@kim_upsilon) <https://upsilo.net/~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 <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpenTween.Api
+{
+ [DataContract]
+ public class TwitterStreamEvent
+ {
+ [DataMember(Name = "target")]
+ public TwitterUser Target { get; set; }
+
+ [DataMember(Name = "source")]
+ public TwitterUser Source { get; set; }
+
+ [DataMember(Name = "event")]
+ public string Event { get; set; }
+
+ [DataMember(Name = "created_at")]
+ public string CreatedAt { get; set; }
+
+ /// <exception cref="SerializationException"/>
+ public static TwitterStreamEvent ParseJson(string json)
+ {
+ return MyCommon.CreateDataFromJson<TwitterStreamEvent>(json);
+ }
+ }
+
+ [DataContract]
+ public class TwitterStreamEvent<T> : TwitterStreamEvent
+ {
+ [DataMember(Name = "target_object")]
+ public T TargetObject { get; set; }
+
+ /// <exception cref="SerializationException"/>
+ public static new TwitterStreamEvent<T> ParseJson(string json)
+ {
+ return MyCommon.CreateDataFromJson<TwitterStreamEvent<T>>(json);
+ }
+ }
+
+ [DataContract]
+ public class TwitterStreamEventDirectMessage
+ {
+ [DataMember(Name = "direct_message")]
+ public TwitterDirectMessage DirectMessage;
+
+ /// <exception cref="SerializationException"/>
+ public static TwitterStreamEventDirectMessage ParseJson(string json)
+ {
+ return MyCommon.CreateDataFromJson<TwitterStreamEventDirectMessage>(json);
+ }
+ }
+}
<Compile Include="Api\TwitterPlace.cs" />
<Compile Include="Api\TwitterSearchResult.cs" />
<Compile Include="Api\TwitterStatus.cs" />
+ <Compile Include="Api\TwitterStreamEvent.cs" />
<Compile Include="Api\TwitterUser.cs" />
<Compile Include="Api\TwitterApiAccessLevel.cs" />
<Compile Include="Api\TwitterApiStatus.cs" />
{
if (gType == MyCommon.WORKERTYPE.UserStream)
{
- var itm = MyCommon.CreateDataFromJson<List<TwitterDataModel.DirectmessageEvent>>(content);
- item = itm.Select(x => x.Directmessage).ToArray();
+ item = new[] { TwitterStreamEventDirectMessage.ParseJson(content).DirectMessage };
}
else
{
}
}
- var res = new StringBuilder();
- res.Length = 0;
- res.Append("[");
- res.Append(line);
- res.Append("]");
-
if (isDm)
{
- CreateDirectMessagesFromJson(res.ToString(), MyCommon.WORKERTYPE.UserStream, false);
+ CreateDirectMessagesFromJson(line, MyCommon.WORKERTYPE.UserStream, false);
}
else
{
long dummy = 0;
- CreatePostsFromJson(res.ToString(), MyCommon.WORKERTYPE.Timeline, null, false, 0, ref dummy);
+ CreatePostsFromJson("[" + line + "]", MyCommon.WORKERTYPE.Timeline, null, false, 0, ref dummy);
}
}
catch(NullReferenceException)
private void CreateEventFromJson(string content)
{
- TwitterDataModel.EventData eventData = null;
+ TwitterStreamEvent eventData = null;
try
{
- eventData = MyCommon.CreateDataFromJson<TwitterDataModel.EventData>(content);
+ eventData = TwitterStreamEvent.ParseJson(content);
}
catch(SerializationException ex)
{
break;
case "favorite":
case "unfavorite":
- evt.Target = "@" + eventData.TargetObject.User.ScreenName + ":" + WebUtility.HtmlDecode(eventData.TargetObject.Text);
- evt.Id = eventData.TargetObject.Id;
+ var tweetEvent = TwitterStreamEvent<TwitterStatus>.ParseJson(content);
+ evt.Target = "@" + tweetEvent.TargetObject.User.ScreenName + ":" + WebUtility.HtmlDecode(tweetEvent.TargetObject.Text);
+ evt.Id = tweetEvent.TargetObject.Id;
if (AppendSettingDialog.Instance.IsRemoveSameEvent)
{
if (StoredEvent.Any(ev =>
return ev.Username == evt.Username && ev.Eventtype == evt.Eventtype && ev.Target == evt.Target;
})) return;
}
- if (TabInformations.GetInstance().ContainsKey(eventData.TargetObject.Id))
+ if (TabInformations.GetInstance().ContainsKey(tweetEvent.TargetObject.Id))
{
- var post = TabInformations.GetInstance()[eventData.TargetObject.Id];
+ var post = TabInformations.GetInstance()[tweetEvent.TargetObject.Id];
if (eventData.Event == "favorite")
{
if (evt.Username.ToLower().Equals(_uname))
case "list_updated":
case "list_user_subscribed":
case "list_user_unsubscribed":
- evt.Target = eventData.TargetObject.FullName;
+ var listEvent = TwitterStreamEvent<TwitterList>.ParseJson(content);
+ evt.Target = listEvent.TargetObject.FullName;
break;
case "block":
if (!TabInformations.GetInstance().BlockIds.Contains(eventData.Target.Id)) TabInformations.GetInstance().BlockIds.Add(eventData.Target.Id);