Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
--- UserStreamAddIn.cs.org 2010-05-12 02:55:38.000000000 +0900
+++ UserStreamAddIn.cs 2010-10-02 11:25:30.000000000 +0900
@@ -17,7 +17,7 @@
{
public class UserStreamAddIn : AddInBase
{
- private HashSet<Int64> _friendIds;
+ private HashSet<String> _friendIds;
private Thread _workerThread;
private Boolean _isRunning;
@@ -31,10 +31,10 @@
ServicePointManager.DefaultConnectionLimit = 1000;
ServicePointManager.MaxServicePoints = 0;
- Session.AddInsLoadCompleted += (sender, e) =>
+ CurrentSession.AddInsLoadCompleted += (sender, e) =>
{
- Session.AddInManager.GetAddIn<ConsoleAddIn>().RegisterContext<UserStreamContext>();
- Config = Session.AddInManager.GetConfig<UserStreamConfig>();
+ CurrentSession.AddInManager.GetAddIn<ConsoleAddIn>().RegisterContext<UserStreamContext>();
+ Config = CurrentSession.AddInManager.GetConfig<UserStreamConfig>();
Setup(Config.Enabled);
};
}
@@ -62,7 +62,7 @@
if (isStart)
{
- _friendIds = new HashSet<Int64>();
+ _friendIds = new HashSet<String>();
_workerThread = new Thread(WorkerProcedure);
_workerThread.Start();
_isRunning = true;
@@ -77,12 +77,8 @@
DataContractJsonSerializer serializer2 = new DataContractJsonSerializer(typeof(_FriendsObject));
DataContractJsonSerializer serializer3 = new DataContractJsonSerializer(typeof(_EventObject));
- //_webRequest = WebRequest.Create("http://betastream.twitter.com/2b/user.json") as HttpWebRequest;
- //_webRequest.Credentials = new NetworkCredential(CurrentSession.Connections[0].UserInfo.UserName,
- // CurrentSession.Connections[0].UserInfo.Password);
- //_webRequest.PreAuthenticate = true;
_webRequest = CurrentSession.TwitterService.OAuthClient.CreateRequest(
- new Uri("http://betastream.twitter.com/2b/user.json"),
+ new Uri("https://userstream.twitter.com/2/user.json"),
TwitterOAuth.HttpMethod.GET);
_webRequest.ServicePoint.ConnectionLimit = 1000;
_webRequest.Timeout = 30 * 1000;
@@ -107,9 +103,9 @@
_FriendsObject streamObject =
serializer2.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(line))) as
_FriendsObject;
- if (streamObject != null && streamObject.friends != null)
+ if (streamObject != null && streamObject.Friends != null)
{
- _friendIds.UnionWith(streamObject.friends);
+ _friendIds.UnionWith(streamObject.Friends);
}
}
else if (line.IndexOf("\"event\":") > -1)
@@ -117,8 +113,8 @@
_EventObject eventObj =
serializer3.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(line))) as _EventObject;
- if (eventObj.Event == "follow" && eventObj.source.id == CurrentSession.TwitterUser.Id)
- _friendIds.Add(eventObj.target.id);
+ if (eventObj.Event == "follow" && Int64.Parse(eventObj.Source.Id) == CurrentSession.TwitterUser.Id)
+ _friendIds.Add(eventObj.Target.Id);
}
else
{
@@ -133,24 +129,20 @@
continue;
}
- if (statusJson == null || statusJson.id == 0)
+ if (statusJson == null || statusJson.Id == 0)
continue;
- if (Config.IsThroughMyPostFromUserStream && (statusJson.user.id == CurrentSession.TwitterUser.Id))
+ if (Config.IsThroughMyPostFromUserStream && (Int64.Parse(statusJson.User.Id) == CurrentSession.TwitterUser.Id))
continue;
Status status = statusJson.ToStatus();
Boolean friendCheckRequired = false;
if (Config.AllAtMode ||
- (statusJson.in_reply_to_user_id.HasValue == false) ||
- (statusJson.in_reply_to_user_id.HasValue && _friendIds.Contains(statusJson.in_reply_to_user_id.Value)))
+ (String.IsNullOrEmpty(statusJson.InReplyToUserId)) ||
+ (String.IsNullOrEmpty(statusJson.InReplyToUserId) && _friendIds.Contains(statusJson.InReplyToUserId)))
{
CurrentSession.TwitterService.ProcessStatus(status,
- (s) =>
- CurrentSession.ProcessTimelineStatus(s,
- ref friendCheckRequired,
- false,
- false));
+ (s) => CurrentSession.ProcessTimelineStatus(s, ref friendCheckRequired, false, false));
}
}
}
@@ -222,46 +214,51 @@
[DataContract]
class _Status
{
- [DataMember]
- public Int64 id { get; set; }
- [DataMember]
- public String text { get; set; }
- [DataMember]
- public String created_at { get; set; }
- [DataMember]
- public String source { get; set; }
- [DataMember]
- public _User user { get; set; }
-
- public DateTime CreatedAt { get { return DateTime.ParseExact(created_at, "ddd MMM dd HH:mm:ss zz00 yyyy", CultureInfo.InvariantCulture.DateTimeFormat); } }
+ [DataMember(Name = "id")]
+ public Int64 Id { get; set; }
- [DataMember]
- public Int64? in_reply_to { get; set; }
+ [DataMember(Name = "text")]
+ public String Text { get; set; }
- [DataMember]
- public Int64? in_reply_to_user_id { get; set; }
+ [DataMember(Name = "created_at")]
+ public String _created_at { get; set; }
+ public DateTime CreatedAt { get { return DateTime.ParseExact(_created_at, "ddd MMM dd HH:mm:ss zz00 yyyy", CultureInfo.InvariantCulture.DateTimeFormat); } }
- [DataMember]
- public _Status retweeted_status { get; set; }
+ [DataMember(Name = "source")]
+ public String Source { get; set; }
+
+ [DataMember(Name = "truncated")]
+ public Boolean Truncated { get; set; }
+
+ [DataMember(Name = "favorited")]
+ public String Favorited { get; set; }
+
+ [DataMember(Name = "in_reply_to_status_id")]
+ public String InReplyToStatusId { get; set; }
+
+ [DataMember(Name = "in_reply_to_user_id")]
+ public String InReplyToUserId { get; set; }
+
+ [DataMember(Name = "retweeted_status")]
+ public _Status RetweetedStatus { get; set; }
+
+ [DataMember(Name = "user")]
+ public _User User { get; set; }
public Status ToStatus()
{
return new Status()
{
+ Id = this.Id,
+ _textOriginal = this.Text,
CreatedAt = this.CreatedAt,
- _textOriginal = this.text,
- Source = this.source,
- Id = this.id,
- InReplyToUserId =
- this.in_reply_to_user_id.HasValue
- ? this.in_reply_to_user_id.Value.ToString()
- : null,
- InReplyToStatusId =
- this.in_reply_to.HasValue
- ? this.in_reply_to.Value.ToString()
- : null,
- RetweetedStatus = (this.retweeted_status == null) ? null : this.retweeted_status.ToStatus(),
- User = this.user.ToUser()
+ Source = this.Source,
+ Truncated = this.Truncated,
+ Favorited = this.Favorited,
+ InReplyToStatusId = this.InReplyToStatusId,
+ InReplyToUserId = this.InReplyToUserId,
+ RetweetedStatus = (this.RetweetedStatus == null) ? null : this.RetweetedStatus.ToStatus(),
+ User = this.User.ToUser()
};
}
}
@@ -269,19 +266,34 @@
[DataContract]
class _EventTarget
{
- [DataMember]
- public Int64 id { get; set; }
+ [DataMember(Name = "id")]
+ public String Id { get; set; }
}
[DataContract]
class _User
{
- [DataMember]
- public Int64 id { get; set; }
- [DataMember]
- public String screen_name { get; set; }
- [DataMember]
- public String profile_image_url { get; set; }
+ [DataMember(Name = "id")]
+ public String Id { get; set; }
+
+ [DataMember(Name = "screen_name")]
+ public String ScreenName { get; set; }
+
+ [DataMember(Name = "name")]
+ public String Name { get; set; }
+
+ [DataMember(Name = "description")]
+ public String Description { get; set; }
+
+ [DataMember(Name = "location")]
+ public String Location { get; set; }
+
+ [DataMember(Name = "profile_image_url")]
+ public String ProfileImageUrl { get; set; }
+
+ [DataMember(Name = "url")]
+ public String Url { get; set; }
+
[DataMember(Name = "protected")]
public Boolean Protected { get; set; }
@@ -289,10 +301,14 @@
{
return new User()
{
- Id = (Int32)this.id,
+ Id = Int32.Parse(this.Id),
+ ScreenName = this.ScreenName,
+ Name = this.Name,
+ Description = this.Description,
+ Location = this.Location,
+ ProfileImageUrl = this.ProfileImageUrl,
+ Url = this.Url,
Protected = this.Protected,
- ProfileImageUrl = this.profile_image_url,
- ScreenName = this.screen_name
};
}
}
@@ -300,8 +316,8 @@
[DataContract]
class _FriendsObject
{
- [DataMember]
- public List<Int64> friends { get; set; }
+ [DataMember(Name = "friends")]
+ public List<String> Friends { get; set; }
}
[DataContract]
@@ -309,9 +325,11 @@
{
[DataMember(Name = "event")]
public String Event { get; set; }
- [DataMember]
- public _EventTarget target { get; set; }
- [DataMember]
- public _EventTarget source { get; set; }
+
+ [DataMember(Name = "target")]
+ public _EventTarget Target { get; set; }
+
+ [DataMember(Name = "source")]
+ public _EventTarget Source { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.