Add settings
parent: tbd commit: 0448edb
1 | use Error; |
2 | |
3 | use crate |
4 | UserSettingsRequest, UserSettingsResponse, UserWriteSettingsRequest, UserWriteSettingsResponse, |
5 | ; |
6 | use crate AuthenticatedUser; |
7 | use crate User; |
8 | use crate:: |
9 | |
10 | UserBioRequest, UserDisplayImageRequest, UserDisplayNameRequest, UserRepositoriesRequest, |
11 | UserRepositoriesResponse, |
12 | , |
13 | , |
14 | ; |
15 | |
16 | use ConnectionState; |
17 | |
18 | pub async |
19 | message_type: &str, |
20 | message: &NetworkMessage, |
21 | state: &ConnectionState, |
22 | |
23 | match message_type |
24 | "&giterated_daemon::messages::user::UserDisplayNameRequest" => |
25 | display_name.handle_message .await?; |
26 | |
27 | Ok |
28 | |
29 | "&giterated_daemon::messages::user::UserDisplayImageRequest" => |
30 | display_image.handle_message .await?; |
31 | |
32 | Ok |
33 | |
34 | "&giterated_daemon::messages::user::UserBioRequest" => |
35 | bio.handle_message .await?; |
36 | |
37 | Ok |
38 | |
39 | "&giterated_daemon::messages::user::UserRepositoriesRequest" => |
40 | repositories.handle_message .await?; |
41 | |
42 | Ok |
43 | |
44 | "&giterated_daemon::messages::user::UserSettingsRequest" => |
45 | user_settings.handle_message .await?; |
46 | |
47 | Ok |
48 | |
49 | "&giterated_daemon::messages::user::UserWriteSettingsRequest" => |
50 | write_user_settings.handle_message .await?; |
51 | |
52 | Ok |
53 | |
54 | _ => Ok, |
55 | |
56 | |
57 | |
58 | async |
59 | Message | : ,
60 | State | : ,
61 | |
62 | let mut user_backend = connection_state.user_backend.lock .await; |
63 | let response = user_backend.display_name .await?; |
64 | |
65 | drop; |
66 | |
67 | connection_state.send .await?; |
68 | |
69 | Ok |
70 | |
71 | |
72 | async |
73 | Message | : ,
74 | State | : ,
75 | |
76 | let mut user_backend = connection_state.user_backend.lock .await; |
77 | let response = user_backend.display_image .await?; |
78 | |
79 | drop; |
80 | |
81 | connection_state.send .await?; |
82 | |
83 | Ok |
84 | |
85 | |
86 | async |
87 | Message | : ,
88 | State | : ,
89 | |
90 | let mut user_backend = connection_state.user_backend.lock .await; |
91 | let response = user_backend.bio .await?; |
92 | |
93 | drop; |
94 | |
95 | connection_state.send .await?; |
96 | |
97 | Ok |
98 | |
99 | |
100 | async |
101 | Message | : ,
102 | State | : ,
103 | requesting_user: , |
104 | |
105 | let requesting_user = requesting_user.map; |
106 | |
107 | let mut repository_backend = connection_state.repository_backend.lock .await; |
108 | let repositories = repository_backend |
109 | .repositories_for_user |
110 | .await; |
111 | |
112 | let repositories = match repositories |
113 | Ok => repositories, |
114 | Err => |
115 | error!; |
116 | return Ok; |
117 | |
118 | ; |
119 | drop; |
120 | |
121 | let mut user_backend = connection_state.user_backend.lock .await; |
122 | let user_exists = user_backend.exists .await; |
123 | |
124 | if repositories.is_empty && !matches! |
125 | return Err; |
126 | |
127 | |
128 | let response: UserRepositoriesResponse = UserRepositoriesResponse ; |
129 | |
130 | connection_state.send .await?; |
131 | |
132 | Ok |
133 | |
134 | |
135 | async |
136 | Message | : ,
137 | State | : ,
138 | AuthenticatedUser | : AuthenticatedUser,
139 | |
140 | if request.user != requesting_user |
141 | return Err; |
142 | |
143 | |
144 | let mut user_backend = connection_state.user_backend.lock .await; |
145 | let mut settings = user_backend.settings .await?; |
146 | |
147 | drop; |
148 | |
149 | let response = UserSettingsResponse |
150 | settings: settings.drain .collect, |
151 | ; |
152 | |
153 | connection_state.send .await?; |
154 | |
155 | Ok |
156 | |
157 | |
158 | async |
159 | Message | : ,
160 | State | : ,
161 | AuthenticatedUser | : AuthenticatedUser,
162 | |
163 | if request.user != requesting_user |
164 | return Err; |
165 | |
166 | |
167 | let mut user_backend = connection_state.user_backend.lock .await; |
168 | user_backend |
169 | .write_settings |
170 | .await?; |
171 | |
172 | drop; |
173 | |
174 | let response = UserWriteSettingsResponse ; |
175 | |
176 | connection_state.send .await?; |
177 | |
178 | Ok |
179 | |
180 | |
181 | |
182 | |
183 | |
184 | InvalidUser, |
185 | |
186 | Other, |
187 | |
188 |