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.
10 // This file is part of OpenTween.
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)
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
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.
29 using System.Collections.Generic;
30 using System.Threading.Tasks;
31 using System.Xml.Serialization;
32 using OpenTween.Api.DataModel;
36 public class ListElement
39 public string Name = "";
40 public string Description = "";
41 public string Slug = "";
42 public bool IsPublic = true;
43 public int SubscriberCount = 0; // 購読者数
44 public int MemberCount = 0; // リストメンバ数
45 public long UserId = 0;
46 public string Username = "";
47 public string Nickname = "";
49 protected Twitter tw = null!;
51 private List<UserInfo> members = new();
54 public long Cursor { get; private set; } = -1;
60 public ListElement(TwitterList listElementData, Twitter tw)
62 this.Description = listElementData.Description;
63 this.Id = listElementData.Id;
64 this.IsPublic = listElementData.Mode == "public";
65 this.MemberCount = listElementData.MemberCount;
66 this.Name = listElementData.Name;
67 this.SubscriberCount = listElementData.SubscriberCount;
68 this.Slug = listElementData.Slug;
69 this.Nickname = listElementData.User.Name.Trim();
70 this.Username = listElementData.User.ScreenName;
71 this.UserId = listElementData.User.Id;
76 public virtual async Task Refresh()
78 var newList = await this.tw.EditList(this.Id, this.Name, !this.IsPublic, this.Description)
79 .ConfigureAwait(false);
81 this.Description = newList.Description;
83 this.IsPublic = newList.IsPublic;
84 this.MemberCount = newList.MemberCount;
85 this.Name = newList.Name;
86 this.SubscriberCount = newList.SubscriberCount;
87 this.Slug = newList.Slug;
88 this.Nickname = newList.Nickname;
89 this.Username = newList.Username;
90 this.UserId = newList.UserId;
94 public List<UserInfo> Members
97 public async Task RefreshMembers()
99 var users = new List<UserInfo>();
100 this.Cursor = await this.tw.GetListMembers(this.Id, users, cursor: -1)
101 .ConfigureAwait(false);
102 this.members = users;
105 public async Task GetMoreMembers()
106 => this.Cursor = await this.tw.GetListMembers(this.Id, this.members, this.Cursor)
107 .ConfigureAwait(false);
109 public override string ToString()
110 => $"@{this.Username}/{this.Name} [{(this.IsPublic ? "public" : "Protected")}]";