Skip to content

Commit ab78e75

Browse files
committed
Merge branch 'main' into 245-refactor-close-command
2 parents 8b6bf69 + 0464229 commit ab78e75

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- Allow NULL in avatar_hash column for users without Discord avatars
2+
-- SQLite doesn't support ALTER COLUMN, so we need to recreate the table
3+
CREATE TABLE IF NOT EXISTS sessions_panel_new (
4+
session_id TEXT PRIMARY KEY,
5+
user_id TEXT NOT NULL,
6+
access_token TEXT NOT NULL,
7+
refresh_token TEXT,
8+
expires_at INTEGER NOT NULL,
9+
avatar_hash TEXT
10+
);
11+
12+
-- Copy existing data
13+
INSERT INTO sessions_panel_new (session_id, user_id, access_token, refresh_token, expires_at, avatar_hash)
14+
SELECT session_id, user_id, access_token, refresh_token, expires_at, avatar_hash
15+
FROM sessions_panel;
16+
17+
-- Drop old table and rename new one
18+
DROP TABLE sessions_panel;
19+
ALTER TABLE sessions_panel_new RENAME TO sessions_panel;

rustmail/src/api/handler/user/avatar.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,25 @@ pub async fn handle_get_user_avatar(
4747
.await
4848
{
4949
Ok(record) => {
50-
let avatar_hash: String = record.get::<String, _>("avatar_hash");
50+
let avatar_hash: Option<String> = record.get::<Option<String>, _>("avatar_hash");
5151

52-
if !avatar_hash.is_empty() {
53-
let avatar_url = format!(
54-
"https://cdn.discordapp.com/avatars/{}/{}.png",
55-
user_id_str, avatar_hash
56-
);
57-
UserAvatar {
58-
avatar_url: Some(avatar_url),
52+
if let Some(hash) = avatar_hash {
53+
if !hash.is_empty() {
54+
let avatar_url = format!(
55+
"https://cdn.discordapp.com/avatars/{}/{}.png",
56+
user_id_str, hash
57+
);
58+
UserAvatar {
59+
avatar_url: Some(avatar_url),
60+
}
61+
} else {
62+
let avatar_url = format!(
63+
"https://cdn.discordapp.com/embed/avatars/{}.png",
64+
(user_id >> 22) % 6
65+
);
66+
UserAvatar {
67+
avatar_url: Some(avatar_url),
68+
}
5969
}
6070
} else {
6171
let avatar_url = format!(

0 commit comments

Comments
 (0)