yumush
Clone
https://git.tahinli.com/Tahinli/yumush.git
0 watching·0 forks·Rust·AGPL-3.0·10.6 MiB·02871e1·Tahinli·47 minutes ago·415 commits
| 1 | use crate::gui::builder::{BuilderTab, Transfer}; |
| 2 | use crate::gui::{Yumush, new_input}; |
| 3 | use crate::lang::w; |
| 4 | use common::model::{ |
| 5 | Account, AdminActionKind, AdminLogEntry, AttachmentInfo, BanScope, CommunitySummary, |
| 6 | CommunityUsage, DayStat, Id, InviteCode, MessageHit, Overview, Report, ReportStatus, ServerBan, |
| 7 | SessionInfo, UpdateClient, User, UserUsage, VoiceRoom, |
| 8 | }; |
| 9 | use common::stats::Stats; |
| 10 | use gpui_kit::{ |
| 11 | AppContext, Context, Entity, Task, Window, |
| 12 | component::{ |
| 13 | IndexPath, input::InputState, searchable_list::SearchableVec, select::SelectState, |
| 14 | }, |
| 15 | }; |
| 16 | |
| 17 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 18 | pub enum UserEdit { |
| 19 | Password, |
| 20 | Rename, |
| 21 | Timeout, |
| 22 | Ban, |
| 23 | } |
| 24 | |
| 25 | pub struct Admin { |
| 26 | pub builder_password: Entity<InputState>, |
| 27 | pub builder_rename: Entity<InputState>, |
| 28 | pub builder_timeout: Entity<InputState>, |
| 29 | pub builder_ban_reason: Entity<InputState>, |
| 30 | pub new_username: Entity<InputState>, |
| 31 | pub new_password: Entity<InputState>, |
| 32 | pub server_name: Entity<InputState>, |
| 33 | pub server_limit: Entity<InputState>, |
| 34 | pub server_user_quota: Entity<InputState>, |
| 35 | pub server_community_quota: Entity<InputState>, |
| 36 | pub server_message_retention: Entity<InputState>, |
| 37 | pub server_attachment_retention: Entity<InputState>, |
| 38 | pub server_announcement: Entity<InputState>, |
| 39 | pub server_max_communities: Entity<InputState>, |
| 40 | pub server_max_message_length: Entity<InputState>, |
| 41 | pub server_max_avatar: Entity<InputState>, |
| 42 | pub server_messages_per_minute: Entity<InputState>, |
| 43 | pub server_logins_per_minute: Entity<InputState>, |
| 44 | pub invite_uses: Entity<InputState>, |
| 45 | pub invite_hours: Entity<InputState>, |
| 46 | pub builder_log_actor: Entity<InputState>, |
| 47 | pub builder_log_target: Entity<InputState>, |
| 48 | pub builder_log_action: Entity<SelectState<SearchableVec<&'static str>>>, |
| 49 | pub builder_log_from: Entity<InputState>, |
| 50 | pub builder_log_to: Entity<InputState>, |
| 51 | pub builder_search: Entity<InputState>, |
| 52 | pub builder_friend_search: Entity<InputState>, |
| 53 | pub builder_message_text: Entity<InputState>, |
| 54 | pub builder_message_user: Entity<InputState>, |
| 55 | pub builder_message_community: Entity<InputState>, |
| 56 | pub builder_message_from: Entity<InputState>, |
| 57 | pub builder_message_to: Entity<InputState>, |
| 58 | pub builder_attachment_user: Entity<InputState>, |
| 59 | pub builder_attachment_community: Entity<InputState>, |
| 60 | pub builder_tab: BuilderTab, |
| 61 | pub builder_users: Vec<Account>, |
| 62 | pub builder_overview: Option<Overview>, |
| 63 | pub builder_logs: Vec<AdminLogEntry>, |
| 64 | pub builder_stats: Vec<DayStat>, |
| 65 | pub builder_communities: Vec<CommunitySummary>, |
| 66 | pub builder_reports: Vec<Report>, |
| 67 | pub report_filter: Option<ReportStatus>, |
| 68 | pub open_reports: usize, |
| 69 | pub builder_messages: Vec<MessageHit>, |
| 70 | pub builder_usage_users: Vec<UserUsage>, |
| 71 | pub builder_usage_communities: Vec<CommunityUsage>, |
| 72 | pub builder_attachments: Vec<AttachmentInfo>, |
| 73 | pub transfer: Option<Transfer>, |
| 74 | pub editing: Option<(Id, UserEdit)>, |
| 75 | pub builder_sessions: Option<(Id, Vec<SessionInfo>)>, |
| 76 | pub builder_clients: Vec<UpdateClient>, |
| 77 | pub builder_clients_task: Option<Task<()>>, |
| 78 | pub builder_friends: Vec<User>, |
| 79 | pub builder_bans: Vec<ServerBan>, |
| 80 | pub builder_ban_scope: BanScope, |
| 81 | pub builder_invites: Vec<InviteCode>, |
| 82 | pub builder_voice_rooms: Vec<VoiceRoom>, |
| 83 | pub server_registration_open: bool, |
| 84 | pub server_maintenance: bool, |
| 85 | pub server_stats: Option<Stats>, |
| 86 | pub server_stats_task: Option<Task<()>>, |
| 87 | } |
| 88 | |
| 89 | impl Admin { |
| 90 | pub fn new(window: &mut Window, cx: &mut Context<Yumush>) -> Self { |
| 91 | let builder_password = new_input(w().chat.new_password, window, cx); |
| 92 | builder_password.update(cx, |input, cx| input.set_masked(true, window, cx)); |
| 93 | let new_password = new_input(w().chat.password, window, cx); |
| 94 | new_password.update(cx, |input, cx| input.set_masked(true, window, cx)); |
| 95 | |
| 96 | Self { |
| 97 | builder_password, |
| 98 | builder_rename: new_input(w().chat.new_username, window, cx), |
| 99 | builder_timeout: new_input(w().chat.minutes, window, cx), |
| 100 | builder_ban_reason: new_input(w().chat.reason, window, cx), |
| 101 | new_username: new_input(w().chat.username, window, cx), |
| 102 | new_password, |
| 103 | server_name: new_input(w().chat.server_name, window, cx), |
| 104 | server_limit: new_input("", window, cx), |
| 105 | server_user_quota: new_input("", window, cx), |
| 106 | server_community_quota: new_input("", window, cx), |
| 107 | server_message_retention: new_input("", window, cx), |
| 108 | server_attachment_retention: new_input("", window, cx), |
| 109 | server_announcement: new_input(w().chat.announcement, window, cx), |
| 110 | server_max_communities: new_input("", window, cx), |
| 111 | server_max_message_length: new_input(w().chat.max_message_length, window, cx), |
| 112 | server_max_avatar: new_input("", window, cx), |
| 113 | server_messages_per_minute: new_input("", window, cx), |
| 114 | server_logins_per_minute: new_input("", window, cx), |
| 115 | invite_uses: new_input(w().chat.uses, window, cx), |
| 116 | invite_hours: new_input(w().chat.hours, window, cx), |
| 117 | builder_log_actor: new_input(w().chat.actor, window, cx), |
| 118 | builder_log_target: new_input(w().chat.target, window, cx), |
| 119 | builder_log_action: cx.new(|cx| { |
| 120 | SelectState::new( |
| 121 | SearchableVec::new( |
| 122 | std::iter::once(w().chat.all) |
| 123 | .chain( |
| 124 | AdminActionKind::ALL |
| 125 | .into_iter() |
| 126 | .map(AdminActionKind::as_str), |
| 127 | ) |
| 128 | .collect::<Vec<_>>(), |
| 129 | ), |
| 130 | Some(IndexPath::new(0)), |
| 131 | window, |
| 132 | cx, |
| 133 | ) |
| 134 | }), |
| 135 | builder_log_from: new_input(w().chat.date_from, window, cx), |
| 136 | builder_log_to: new_input(w().chat.date_to, window, cx), |
| 137 | builder_search: new_input(w().chat.search, window, cx), |
| 138 | builder_friend_search: new_input(w().chat.search, window, cx), |
| 139 | builder_message_text: new_input(w().chat.text, window, cx), |
| 140 | builder_message_user: new_input(w().chat.user, window, cx), |
| 141 | builder_message_community: new_input(w().chat.community, window, cx), |
| 142 | builder_message_from: new_input(w().chat.date_from, window, cx), |
| 143 | builder_message_to: new_input(w().chat.date_to, window, cx), |
| 144 | builder_attachment_user: new_input(w().chat.user, window, cx), |
| 145 | builder_attachment_community: new_input(w().chat.community, window, cx), |
| 146 | builder_tab: BuilderTab::Overview, |
| 147 | builder_users: vec![], |
| 148 | builder_overview: None, |
| 149 | builder_logs: vec![], |
| 150 | builder_stats: vec![], |
| 151 | builder_communities: vec![], |
| 152 | builder_reports: vec![], |
| 153 | report_filter: Some(ReportStatus::Open), |
| 154 | open_reports: 0, |
| 155 | builder_messages: vec![], |
| 156 | builder_usage_users: vec![], |
| 157 | builder_usage_communities: vec![], |
| 158 | builder_attachments: vec![], |
| 159 | transfer: None, |
| 160 | editing: None, |
| 161 | builder_sessions: None, |
| 162 | builder_clients: vec![], |
| 163 | builder_clients_task: None, |
| 164 | builder_friends: vec![], |
| 165 | builder_bans: vec![], |
| 166 | builder_ban_scope: BanScope::Account, |
| 167 | builder_invites: vec![], |
| 168 | builder_voice_rooms: vec![], |
| 169 | server_registration_open: true, |
| 170 | server_maintenance: false, |
| 171 | server_stats: None, |
| 172 | server_stats_task: None, |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | pub fn clear(&mut self) { |
| 177 | self.builder_tab = BuilderTab::Overview; |
| 178 | self.builder_users.clear(); |
| 179 | self.builder_overview = None; |
| 180 | self.builder_logs.clear(); |
| 181 | self.builder_stats.clear(); |
| 182 | self.builder_communities.clear(); |
| 183 | self.builder_reports.clear(); |
| 184 | self.report_filter = Some(ReportStatus::Open); |
| 185 | self.open_reports = 0; |
| 186 | self.builder_messages.clear(); |
| 187 | self.builder_usage_users.clear(); |
| 188 | self.builder_usage_communities.clear(); |
| 189 | self.builder_attachments.clear(); |
| 190 | self.transfer = None; |
| 191 | self.editing = None; |
| 192 | self.builder_sessions = None; |
| 193 | self.builder_clients.clear(); |
| 194 | self.builder_clients_task = None; |
| 195 | self.builder_friends.clear(); |
| 196 | self.builder_bans.clear(); |
| 197 | self.builder_ban_scope = BanScope::Account; |
| 198 | self.builder_invites.clear(); |
| 199 | self.builder_voice_rooms.clear(); |
| 200 | self.server_registration_open = true; |
| 201 | self.server_maintenance = false; |
| 202 | self.server_stats = None; |
| 203 | self.server_stats_task = None; |
| 204 | } |
| 205 | } |