diff options
| author | Adam Soltys <[email protected]> | 2025-02-26 17:17:49 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-02-26 17:17:49 -0800 |
| commit | 88175fc2e5cfc313372366018b2f5256382d6e52 (patch) | |
| tree | 7f73c6476b1e5d35411d6da8840ea56aac9b8594 | |
| parent | e556afe44157134cd00972dd9043312694ffad5a (diff) | |
| download | coinos-server-88175fc2e5cfc313372366018b2f5256382d6e52.tar.gz coinos-server-88175fc2e5cfc313372366018b2f5256382d6e52.zip | |
pinned contacts
| -rw-r--r-- | index.ts | 3 | ||||
| -rw-r--r-- | routes/users.ts | 32 |
2 files changed, 33 insertions, 2 deletions
@@ -134,6 +134,9 @@ app.get("/apps", auth, users.apps); app.post("/app", auth, users.updateApp); app.post("/apps/delete", auth, users.deleteApp); +app.post("/pins", auth, users.addPin); +app.post("/pins/delete", auth, users.deletePin); + app.get("/subscriptions", auth, users.subscriptions); app.post("/subscription", auth, users.subscription); app.post("/subscription/delete", auth, users.deleteSubscription); diff --git a/routes/users.ts b/routes/users.ts index 3ef746ec..930c3881 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -461,7 +461,8 @@ export default { (await db.lRange(`${id}:payments`, 0, len - lastlen)) || []; await db.set(`${id}:lastlen`, len); - const contacts = (await g(`${id}:contacts`)) || []; + let contacts = (await g(`${id}:contacts`)) || []; + const pins = await db.sMembers(`${id}:pins`); for (const { ref } of ( await Promise.all( @@ -478,9 +479,21 @@ export default { await s(`${id}:contacts`, contacts); + const pinned = contacts + .filter((c) => pins.includes(c.id)) + .sort((a, b) => a.username.localeCompare(b.username)); + + pinned.map((c) => { + c.pinned = true; + }); + let { limit } = params; limit ||= contacts.length; - res.send(contacts.slice(0, limit)); + contacts = contacts.filter((c) => !pins.includes(c.id)); + contacts = contacts.slice(0, limit); + + const combined = [...pinned, ...contacts]; + res.send(combined); }, async del(req, res) { @@ -915,4 +928,19 @@ export default { bail(res, e.message); } }, + + async addPin(req, res) { + const { id: uid } = req.user; + const { id } = req.body; + await db.sAdd(`${uid}:pins`, id); + console.log("added", id); + res.send({}); + }, + + async deletePin(req, res) { + const { id: uid } = req.user; + const { id } = req.body; + await db.sRem(`${uid}:pins`, id); + res.send({}); + }, }; |
