@hasna/conversations 0.1.17 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/hook.js CHANGED
@@ -120,6 +120,17 @@ function getDb() {
120
120
  metadata TEXT
121
121
  )
122
122
  `);
123
+ db.exec(`
124
+ CREATE TABLE IF NOT EXISTS reactions (
125
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
126
+ message_id INTEGER NOT NULL REFERENCES messages(id) ON DELETE CASCADE,
127
+ agent TEXT NOT NULL,
128
+ emoji TEXT NOT NULL,
129
+ created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%f', 'now')),
130
+ UNIQUE(message_id, agent, emoji)
131
+ )
132
+ `);
133
+ db.exec("CREATE INDEX IF NOT EXISTS idx_reactions_message ON reactions(message_id)");
123
134
  const existingTables = db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all();
124
135
  const tableNames = existingTables.map((t) => t.name);
125
136
  if (tableNames.includes("channels") && tableNames.includes("spaces")) {
@@ -177,6 +188,46 @@ function getDb() {
177
188
  db.exec("ALTER TABLE messages ADD COLUMN blocking INTEGER NOT NULL DEFAULT 0");
178
189
  db.exec("CREATE INDEX IF NOT EXISTS idx_messages_blocking ON messages(blocking)");
179
190
  }
191
+ if (!colNames2.includes("attachments")) {
192
+ db.exec("ALTER TABLE messages ADD COLUMN attachments TEXT");
193
+ }
194
+ if (!colNames2.includes("reply_to")) {
195
+ db.exec("ALTER TABLE messages ADD COLUMN reply_to INTEGER REFERENCES messages(id)");
196
+ db.exec("CREATE INDEX IF NOT EXISTS idx_messages_reply_to ON messages(reply_to)");
197
+ }
198
+ const ftsExists = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='messages_fts'").get();
199
+ if (!ftsExists) {
200
+ db.exec(`
201
+ CREATE VIRTUAL TABLE messages_fts USING fts5(
202
+ content, from_agent, to_agent, space,
203
+ content_rowid='id', content='messages'
204
+ )
205
+ `);
206
+ db.exec(`
207
+ INSERT INTO messages_fts(rowid, content, from_agent, to_agent, space)
208
+ SELECT id, content, from_agent, to_agent, space FROM messages
209
+ `);
210
+ db.exec(`
211
+ CREATE TRIGGER IF NOT EXISTS messages_fts_insert AFTER INSERT ON messages BEGIN
212
+ INSERT INTO messages_fts(rowid, content, from_agent, to_agent, space)
213
+ VALUES (new.id, new.content, new.from_agent, new.to_agent, new.space);
214
+ END
215
+ `);
216
+ db.exec(`
217
+ CREATE TRIGGER IF NOT EXISTS messages_fts_delete AFTER DELETE ON messages BEGIN
218
+ INSERT INTO messages_fts(messages_fts, rowid, content, from_agent, to_agent, space)
219
+ VALUES ('delete', old.id, old.content, old.from_agent, old.to_agent, old.space);
220
+ END
221
+ `);
222
+ db.exec(`
223
+ CREATE TRIGGER IF NOT EXISTS messages_fts_update AFTER UPDATE OF content ON messages BEGIN
224
+ INSERT INTO messages_fts(messages_fts, rowid, content, from_agent, to_agent, space)
225
+ VALUES ('delete', old.id, old.content, old.from_agent, old.to_agent, old.space);
226
+ INSERT INTO messages_fts(rowid, content, from_agent, to_agent, space)
227
+ VALUES (new.id, new.content, new.from_agent, new.to_agent, new.space);
228
+ END
229
+ `);
230
+ }
180
231
  return db;
181
232
  }
182
233
  function closeDb() {