From 4cdc71ffb99963e2a0790697fdafb0cc1cc73b21 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tadeusz=20So=C5=9Bnierz?= <tadeusz@sosnierz.com>
Date: Fri, 15 Oct 2021 12:11:27 +0200
Subject: [PATCH] Workaround different JSON field handling between SQLite and
 Pg

---
 src/store.ts | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/store.ts b/src/store.ts
index 1ddc597..9cbed77 100644
--- a/src/store.ts
+++ b/src/store.ts
@@ -303,7 +303,11 @@ export class DiscordStore implements IAppserviceStorageProvider {
         const rows = await this.db.All('SELECT * FROM user_activity');
         const users: {[mxid: string]: any} = {};
         for (const row of rows) {
-            users[row.user_id as string] = JSON.parse(row.data as any);
+            let data = row.data as any;
+            if (typeof data === 'string') { // sqlite has no first-class JSON
+                data = JSON.parse(data);
+            }
+            users[row.user_id as string] = data;
         }
         return { users };
     }
-- 
GitLab