From 1beafdafe4deed2c26c6b5c9c321704bcb0d3f4e Mon Sep 17 00:00:00 2001 From: kiri_feather Date: Tue, 9 Mar 2010 09:45:22 +0000 Subject: [PATCH] =?utf8?q?lists=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?utf8?q?=E8=BF=BD=E5=8A=A0=20=E6=9C=80=E5=8F=A4ID=E4=BF=9D=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.sourceforge.jp/svnroot/tween/trunk@125 e39ad16e-3079-482e-bb30-4b4d378143b6 --- Tween/Connection/HttpConnectionBasic.vb | 2 +- Tween/Connection/HttpConnectionOAuth.vb | 2 +- Tween/Connection/HttpTwitter.vb | 137 ++++++++++++++++++-------------- Tween/StatusDictionary.vb | 31 ++++---- Tween/Tween.vb | 2 +- Tween/Tween.vbproj.user | 2 +- Tween/Twitter.vb | 26 +++++- 7 files changed, 120 insertions(+), 82 deletions(-) diff --git a/Tween/Connection/HttpConnectionBasic.vb b/Tween/Connection/HttpConnectionBasic.vb index e68bf11b..66355dad 100644 --- a/Tween/Connection/HttpConnectionBasic.vb +++ b/Tween/Connection/HttpConnectionBasic.vb @@ -40,7 +40,7 @@ Public Class HttpConnectionBasic ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode Implements IHttpConnection.GetContent '認証済かチェック - If String.IsNullOrEmpty(Me.credential) Then Throw New Exception("Sequence error. (account is blank.)") + If String.IsNullOrEmpty(Me.credential) Then Return HttpStatusCode.Unauthorized Dim webReq As HttpWebRequest = CreateRequest(method, _ requestUri, _ diff --git a/Tween/Connection/HttpConnectionOAuth.vb b/Tween/Connection/HttpConnectionOAuth.vb index 20124dd4..34879aaa 100644 --- a/Tween/Connection/HttpConnectionOAuth.vb +++ b/Tween/Connection/HttpConnectionOAuth.vb @@ -70,7 +70,7 @@ Public Class HttpConnectionOAuth ByRef content As String, _ ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode Implements IHttpConnection.GetContent '認証済かチェック - If String.IsNullOrEmpty(token) Then Throw New Exception("Sequence error. (Token is blank.)") + If String.IsNullOrEmpty(token) Then Return HttpStatusCode.Unauthorized Dim webReq As HttpWebRequest = CreateRequest(method, _ requestUri, _ diff --git a/Tween/Connection/HttpTwitter.vb b/Tween/Connection/HttpTwitter.vb index cd258dda..cfe6d45f 100644 --- a/Tween/Connection/HttpTwitter.vb +++ b/Tween/Connection/HttpTwitter.vb @@ -142,9 +142,6 @@ Public Class HttpTwitter End Property Public Function UpdateStatus(ByVal status As String, ByVal replyToId As Long, ByRef content As String) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If Dim param As New Dictionary(Of String, String) param.Add("status", status) If replyToId > 0 Then param.Add("in_reply_to_status_id", replyToId.ToString) @@ -157,10 +154,6 @@ Public Class HttpTwitter End Function Public Function DestroyStatus(ByVal id As Long) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If - Return httpCon.GetContent(PostMethod, _ CreateTwitterUri("/1/statuses/destroy/" + id.ToString + ".xml"), _ Nothing, _ @@ -169,10 +162,6 @@ Public Class HttpTwitter End Function Public Function DestroyDirectMessage(ByVal id As Long) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If - Return httpCon.GetContent(PostMethod, _ CreateTwitterUri("/1/direct_messages/destroy/" + id.ToString + ".xml"), _ Nothing, _ @@ -181,9 +170,6 @@ Public Class HttpTwitter End Function Public Function RetweetStatus(ByVal id As Long, ByRef content As String) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If Return httpCon.GetContent(PostMethod, _ CreateTwitterUri("/1/statuses/retweet/" + id.ToString() + ".xml"), _ Nothing, _ @@ -192,9 +178,6 @@ Public Class HttpTwitter End Function Public Function CreateFriendships(ByVal screenName As String) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If Dim param As New Dictionary(Of String, String) param.Add("screen_name", screenName) @@ -206,9 +189,6 @@ Public Class HttpTwitter End Function Public Function DestroyFriendships(ByVal screenName As String) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If Dim param As New Dictionary(Of String, String) param.Add("screen_name", screenName) @@ -220,9 +200,6 @@ Public Class HttpTwitter End Function Public Function ShowFriendships(ByVal souceScreenName As String, ByVal targetScreenName As String, ByRef content As String) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If Dim param As New Dictionary(Of String, String) param.Add("source_screen_name", souceScreenName) param.Add("target_screen_name", targetScreenName) @@ -235,10 +212,6 @@ Public Class HttpTwitter End Function Public Function ShowStatuses(ByVal id As Long, ByRef content As String) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If - Return httpCon.GetContent(GetMethod, _ CreateTwitterUri("/1/statuses/show/" + id.ToString() + ".xml"), _ Nothing, _ @@ -247,10 +220,6 @@ Public Class HttpTwitter End Function Public Function CreateFavorites(ByVal id As Long) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If - Return httpCon.GetContent(PostMethod, _ CreateTwitterUri("/1/favorites/create/" + id.ToString() + ".xml"), _ Nothing, _ @@ -259,10 +228,6 @@ Public Class HttpTwitter End Function Public Function DestroyFavorites(ByVal id As Long) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If - Return httpCon.GetContent(PostMethod, _ CreateTwitterUri("/1/favorites/destroy/" + id.ToString() + ".xml"), _ Nothing, _ @@ -270,14 +235,17 @@ Public Class HttpTwitter Nothing) End Function - Public Function HomeTimeline(ByVal count As Integer, ByRef content As String) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If + Public Function HomeTimeline(ByVal count As Integer, ByVal max_id As Long, ByVal since_id As Long, ByRef content As String) As HttpStatusCode Dim param As New Dictionary(Of String, String) If count > 0 Then param.Add("count", count.ToString()) End If + If max_id > 0 Then + param.Add("max_id", max_id.ToString()) + End If + If since_id > 0 Then + param.Add("since_id", since_id.ToString()) + End If Return httpCon.GetContent(GetMethod, _ CreateTwitterUri("/1/statuses/home_timeline.xml"), _ @@ -286,14 +254,17 @@ Public Class HttpTwitter _remainCountApi) End Function - Public Function Mentions(ByVal count As Integer, ByRef content As String) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If + Public Function Mentions(ByVal count As Integer, ByVal max_id As Long, ByVal since_id As Long, ByRef content As String) As HttpStatusCode Dim param As New Dictionary(Of String, String) If count > 0 Then param.Add("count", count.ToString()) End If + If max_id > 0 Then + param.Add("max_id", max_id.ToString()) + End If + If since_id > 0 Then + param.Add("since_id", since_id.ToString()) + End If Return httpCon.GetContent(GetMethod, _ CreateTwitterUri("/1/statuses/mentions.xml"), _ @@ -302,9 +273,16 @@ Public Class HttpTwitter _remainCountApi) End Function - Public Function DirectMessages(ByRef content As String) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized + Public Function DirectMessages(ByVal count As Integer, ByVal max_id As Long, ByVal since_id As Long, ByRef content As String) As HttpStatusCode + Dim param As New Dictionary(Of String, String) + If count > 0 Then + param.Add("count", count.ToString()) + End If + If max_id > 0 Then + param.Add("max_id", max_id.ToString()) + End If + If since_id > 0 Then + param.Add("since_id", since_id.ToString()) End If Return httpCon.GetContent(GetMethod, _ @@ -314,9 +292,16 @@ Public Class HttpTwitter _remainCountApi) End Function - Public Function DirectMessagesSent(ByRef content As String) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized + Public Function DirectMessagesSent(ByVal count As Integer, ByVal max_id As Long, ByVal since_id As Long, ByRef content As String) As HttpStatusCode + Dim param As New Dictionary(Of String, String) + If count > 0 Then + param.Add("count", count.ToString()) + End If + If max_id > 0 Then + param.Add("max_id", max_id.ToString()) + End If + If since_id > 0 Then + param.Add("since_id", since_id.ToString()) End If Return httpCon.GetContent(GetMethod, _ @@ -327,9 +312,6 @@ Public Class HttpTwitter End Function Public Function Favorites(ByVal count As Integer, ByRef content As String) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If Dim param As New Dictionary(Of String, String) If count <> 20 Then param.Add("count", count.ToString()) @@ -358,9 +340,6 @@ Public Class HttpTwitter End Function Public Function FollowerIds(ByVal cursor As Long, ByRef content As String) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If Dim param As New Dictionary(Of String, String) param.Add("cursor", cursor.ToString()) @@ -372,10 +351,6 @@ Public Class HttpTwitter End Function Public Function RateLimitStatus(ByRef content As String) As HttpStatusCode - If Me.AuthenticatedUsername = "" Then - Return HttpStatusCode.Unauthorized - End If - Return httpCon.GetContent(GetMethod, _ CreateTwitterUri("/1/account/rate_limit_status.xml"), _ Nothing, _ @@ -383,6 +358,48 @@ Public Class HttpTwitter Nothing) End Function + Public Function GetLists(ByVal user As String, ByVal cursor As Long, ByRef content As String) As HttpStatusCode + Dim param As New Dictionary(Of String, String) + param.Add("cursor", cursor.ToString) + Return httpCon.GetContent(GetMethod, _ + CreateTwitterUri("/1/" + user + "/lists.xml"), _ + param, _ + content, _ + _remainCountApi) + End Function + + Public Function GetListsSubscriptions(ByVal user As String, ByVal cursor As Long, ByRef content As String) As HttpStatusCode + Dim param As New Dictionary(Of String, String) + param.Add("cursor", cursor.ToString) + Return httpCon.GetContent(GetMethod, _ + CreateTwitterUri("/1/" + user + "/lists/subscriptions.xml"), _ + param, _ + content, _ + _remainCountApi) + End Function + + Public Function GetListsStatuses(ByVal user As String, ByVal list_id As String, ByVal per_page As Integer, ByVal max_id As Long, ByVal since_id As Long, ByRef content As String) As HttpStatusCode + '”FØ‚È‚­‚Ä‚àŽæ“¾‚Å‚«‚邪Aprotectedƒ†[ƒU[•ª‚ª”²‚¯‚é + Dim param As New Dictionary(Of String, String) + If per_page > 0 Then + param.Add("per_page", per_page.ToString()) + End If + If max_id > 0 Then + param.Add("max_id", max_id.ToString()) + End If + If since_id > 0 Then + param.Add("since_id", since_id.ToString()) + End If + + Return httpCon.GetContent(GetMethod, _ + CreateTwitterUri("/1/" + user + "/lists/" + list_id + "/statuses.xml"), _ + param, _ + content, _ + _remainCountApi) + End Function + + +#Region "Proxy API" Private Shared _twitterUrl As String = "api.twitter.com" 'Private TwitterUrl As String = "sorayukigtap.appspot.com/api" Private Shared _TwitterSearchUrl As String = "search.twitter.com" @@ -407,4 +424,6 @@ Public Class HttpTwitter _TwitterSearchUrl = value End Set End Property +#End Region + End Class diff --git a/Tween/StatusDictionary.vb b/Tween/StatusDictionary.vb index 8d1ebad3..2705e30c 100644 --- a/Tween/StatusDictionary.vb +++ b/Tween/StatusDictionary.vb @@ -505,10 +505,11 @@ Public NotInheritable Class TabInformations End Get End Property - Public Sub RemovePost(ByVal Name As String, ByVal Id As Long) + Public Sub RemoveFavPost(ByVal Id As Long) SyncLock LockObj Dim post As PostClass = Nothing - Dim tab As TabClass = _tabs(Name) + Dim tab As TabClass = Me.GetTabByType(TabUsageType.Favorites) + Dim tn As String = tab.TabName If _statuses.ContainsKey(Id) Then post = _statuses(Id) '指定タブから該当ID削除 @@ -525,7 +526,7 @@ Public NotInheritable Class TabInformations 'FavタブからRetweet発言を削除する場合は、他の同一参照Retweetも削除 If tType = TabUsageType.Favorites AndAlso post.RetweetedId > 0 Then For i As Integer = 0 To tab.AllCount - 1 - Dim rPost As PostClass = Me.Item(Name, i) + Dim rPost As PostClass = Me.Item(tn, i) If rPost.RetweetedId > 0 AndAlso rPost.RetweetedId = post.RetweetedId Then If tab.UnreadManage AndAlso Not rPost.IsRead Then '未読管理 SyncLock LockUnread @@ -538,18 +539,18 @@ Public NotInheritable Class TabInformations Next End If End If - 'TabType=PublicSearchの場合(Postの保存先がTabClass内) - If tab.Contains(Id) AndAlso _ - (tab.TabType = TabUsageType.PublicSearch OrElse tab.TabType = TabUsageType.DirectMessage) Then - post = tab.Posts(Id) - If tab.UnreadManage AndAlso Not post.IsRead Then '未読管理 - SyncLock LockUnread - tab.UnreadCount -= 1 - Me.SetNextUnreadId(Id, tab) - End SyncLock - End If - tab.Remove(Id) - End If + ''TabType=PublicSearchの場合(Postの保存先がTabClass内) + 'If tab.Contains(Id) AndAlso _ + ' (tab.TabType = TabUsageType.PublicSearch OrElse tab.TabType = TabUsageType.DirectMessage) Then + ' post = tab.Posts(Id) + ' If tab.UnreadManage AndAlso Not post.IsRead Then '未読管理 + ' SyncLock LockUnread + ' tab.UnreadCount -= 1 + ' Me.SetNextUnreadId(Id, tab) + ' End SyncLock + ' End If + ' tab.Remove(Id) + 'End If End SyncLock End Sub diff --git a/Tween/Tween.vb b/Tween/Tween.vb index 424a9968..9ac39fa1 100644 --- a/Tween/Tween.vb +++ b/Tween/Tween.vb @@ -2196,7 +2196,7 @@ Public Class TweenMain DispSelectedPost() ' 詳細画面書き直し Dim favTabName As String = _statuses.GetTabByType(TabUsageType.Favorites).TabName For Each i As Long In rslt.sIds - _statuses.RemovePost(favTabName, i) + _statuses.RemoveFavPost(i) Next If _curTab.Text.Equals(favTabName) Then _itemCache = Nothing 'キャッシュ破棄 diff --git a/Tween/Tween.vbproj.user b/Tween/Tween.vbproj.user index 65f5e9c9..5f6826b4 100644 --- a/Tween/Tween.vbproj.user +++ b/Tween/Tween.vbproj.user @@ -11,7 +11,7 @@ ja-JP false - ShowAllFiles + ProjectFiles 0 diff --git a/Tween/Twitter.vb b/Tween/Twitter.vb index 29a0d203..14905555 100644 --- a/Tween/Twitter.vb +++ b/Tween/Twitter.vb @@ -194,6 +194,13 @@ Public Module Twitter ''''Wedata対応 'Private Const wedataUrl As String = "http://wedata.net/databases/Tween/items.json" + 'max_idで古い発言を取得するために保持(lists分は個別タブで管理) + Private minHomeTimeline As Long = Long.MaxValue + Private minMentions As Long = Long.MaxValue + Private minDirectmessage As Long = Long.MaxValue + Private minDirectmessageSent As Long = Long.MaxValue + Private minFavorites As Long = Long.MaxValue + Private twCon As New HttpTwitter Public Function Authenticate(ByVal username As String, ByVal password As String) As Boolean @@ -3274,10 +3281,10 @@ Public Module Twitter Dim content As String = "" Try If gType = WORKERTYPE.Timeline Then - res = twCon.HomeTimeline(_countApi, content) + res = twCon.HomeTimeline(_countApi, 0, 0, content) countQuery = _countApi Else - res = twCon.Mentions(_countApiReply, content) + res = twCon.Mentions(_countApiReply, 0, 0, content) countQuery = _countApiReply End If Catch ex As Exception @@ -3311,6 +3318,11 @@ Public Module Twitter Dim post As New PostClass Try post.Id = Long.Parse(xentry.Item("id").InnerText) + If gType = WORKERTYPE.Timeline Then + If minHomeTimeline > post.Id Then minHomeTimeline = post.Id + Else + If minMentions > post.Id Then minMentions = post.Id + End If '二重取得回避 SyncLock LockObj If TabInformations.GetInstance.ContainsKey(post.Id) Then Continue For @@ -3548,9 +3560,9 @@ Public Module Twitter Try If gType = WORKERTYPE.DirectMessegeRcv Then - res = twCon.DirectMessages(content) + res = twCon.DirectMessages(0, 0, 0, content) Else - res = twCon.DirectMessagesSent(content) + res = twCon.DirectMessagesSent(0, 0, 0, content) End If Catch ex As Exception Return "Err:" + ex.Message @@ -3584,6 +3596,11 @@ Public Module Twitter Dim post As New PostClass Try post.Id = Long.Parse(xentry.Item("id").InnerText) + If gType = WORKERTYPE.DirectMessegeRcv Then + If minDirectmessage > post.Id Then minDirectmessage = post.Id + Else + If minDirectmessageSent > post.Id Then minDirectmessageSent = post.Id + End If '二重取得回避 SyncLock LockObj If TabInformations.GetInstance.GetTabByType(TabUsageType.DirectMessage).Contains(post.Id) Then Continue For @@ -3695,6 +3712,7 @@ Public Module Twitter Dim post As New PostClass Try post.Id = Long.Parse(xentry.Item("id").InnerText) + If minFavorites > post.Id Then minFavorites = post.Id '二重取得回避 SyncLock LockObj If TabInformations.GetInstance.ContainsKey(post.Id) Then Continue For -- 2.11.0