OSDN Git Service

listsメソッド追加
authorkiri_feather <kiri_feather@users.sourceforge.jp>
Tue, 9 Mar 2010 09:45:22 +0000 (09:45 +0000)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 18 Feb 2012 14:11:13 +0000 (23:11 +0900)
最古ID保持

git-svn-id: http://svn.sourceforge.jp/svnroot/tween/trunk@125 e39ad16e-3079-482e-bb30-4b4d378143b6

Tween/Connection/HttpConnectionBasic.vb
Tween/Connection/HttpConnectionOAuth.vb
Tween/Connection/HttpTwitter.vb
Tween/StatusDictionary.vb
Tween/Tween.vb
Tween/Tween.vbproj.user
Tween/Twitter.vb

index e68bf11..66355da 100644 (file)
@@ -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, _
index 20124dd..34879aa 100644 (file)
@@ -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, _
index cd258dd..cfe6d45 100644 (file)
@@ -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
+        '\94F\8fØ\82È\82­\82Ä\82à\8eæ\93¾\82Å\82«\82é\82ª\81Aprotected\83\86\81[\83U\81[\95ª\82ª\94²\82¯\82é
+        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
index 8d1ebad..2705e30 100644 (file)
@@ -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
 
index 424a996..9ac39fa 100644 (file)
@@ -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    'キャッシュ破棄
index 65f5e9c..5f6826b 100644 (file)
@@ -11,7 +11,7 @@
     </BootstrapperUrlHistory>
     <FallbackCulture>ja-JP</FallbackCulture>
     <VerifyUploadedFiles>false</VerifyUploadedFiles>
-    <ProjectView>ShowAllFiles</ProjectView>
+    <ProjectView>ProjectFiles</ProjectView>
     <ErrorReportUrlHistory>
     </ErrorReportUrlHistory>
     <ApplicationRevision>0</ApplicationRevision>
index 29a0d20..1490555 100644 (file)
@@ -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