OSDN Git Service

HttpTwitter.GetListMembersメソッドをTwitterApiクラスに置き換え
[opentween/open-tween.git] / OpenTween / ListElement.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 //           (c) 2008-2011 Moz (@syo68k)
4 //           (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 //           (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 //           (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 //           (c) 2011      Egtra (@egtra) <http://dev.activebasic.com/egtra/>
8 // All rights reserved.
9 //
10 // This file is part of OpenTween.
11 //
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
15 // any later version.
16 //
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
26
27 using System.Collections.Generic;
28 using System.Threading.Tasks;
29 using System.Xml.Serialization;
30 using OpenTween.Api.DataModel;
31
32 namespace OpenTween
33 {
34     public class ListElement
35     {
36         public long Id = 0;
37         public string Name = "";
38         public string Description = "";
39         public string Slug = "";
40         public bool IsPublic = true;
41         public int SubscriberCount = 0;   //購読者数
42         public int MemberCount = 0;   //リストメンバ数
43         public long UserId = 0;
44         public string Username = "";
45         public string Nickname = "";
46
47         protected Twitter _tw;
48
49         private List<UserInfo> _members = null;
50         private long _cursor = -1;
51
52         public ListElement()
53         {
54         }
55
56         public ListElement(TwitterList listElementData, Twitter tw)
57         {
58             this.Description = listElementData.Description;
59             this.Id = listElementData.Id;
60             this.IsPublic = (listElementData.Mode == "public");
61             this.MemberCount = listElementData.MemberCount;
62             this.Name = listElementData.Name;
63             this.SubscriberCount = listElementData.SubscriberCount;
64             this.Slug = listElementData.Slug;
65             this.Nickname = listElementData.User.Name.Trim();
66             this.Username = listElementData.User.ScreenName;
67             this.UserId = listElementData.User.Id;
68
69             this._tw = tw;
70         }
71
72         public virtual async Task Refresh()
73         {
74             var newList = await _tw.EditList(this.Id, Name, !this.IsPublic, this.Description)
75                 .ConfigureAwait(false);
76
77             this.Description = newList.Description;
78             this.Id = newList.Id;
79             this.IsPublic = newList.IsPublic;
80             this.MemberCount = newList.MemberCount;
81             this.Name = newList.Name;
82             this.SubscriberCount = newList.SubscriberCount;
83             this.Slug = newList.Slug;
84             this.Nickname = newList.Nickname;
85             this.Username = newList.Username;
86             this.UserId = newList.UserId;
87         }
88
89         [XmlIgnore]
90         public List<UserInfo> Members
91         {
92             get
93             {
94                 if (this._members == null) this._members = new List<UserInfo>();
95                 return this._members;
96             }
97         }
98
99         [XmlIgnore]
100         public long Cursor
101         {
102             get
103             {
104                 return _cursor;
105             }
106         }
107
108         public async Task RefreshMembers()
109         {
110             var users = new List<UserInfo>();
111             this._cursor = await this._tw.GetListMembers(this.Id, users, cursor: -1)
112                 .ConfigureAwait(false);
113             this._members = users;
114         }
115
116         public async Task GetMoreMembers()
117         {
118             this._cursor = await this._tw.GetListMembers(this.Id, this._members, this._cursor)
119                 .ConfigureAwait(false);
120         }
121
122         public override string ToString()
123         {
124             return "@" + Username + "/" + Name + " [" + (this.IsPublic ? "public" : "Protected") + "]";
125         }
126     }
127 }