2020-04-04 14:24:51 +00:00
|
|
|
CREATE TABLE configuration (
|
|
|
|
rev INT PRIMARY KEY,
|
|
|
|
server VARCHAR NOT NULL,
|
|
|
|
port INT NOT NULL,
|
|
|
|
component_name VARCHAR NOT NULL,
|
|
|
|
shared_secret VARCHAR NOT NULL,
|
2020-09-30 13:01:52 +00:00
|
|
|
upload_component_name VARCHAR NOT NULL,
|
|
|
|
allow_archiving BOOL NOT NULL DEFAULT false,
|
|
|
|
allow_history_fetches BOOL NOT NULL DEFAULT false
|
2020-04-04 14:24:51 +00:00
|
|
|
);
|
|
|
|
|
2020-04-03 16:40:05 +00:00
|
|
|
CREATE TABLE users (
|
2020-04-04 14:24:51 +00:00
|
|
|
id INTEGER PRIMARY KEY,
|
2020-04-03 16:40:05 +00:00
|
|
|
jid VARCHAR UNIQUE NOT NULL,
|
2020-09-30 13:01:52 +00:00
|
|
|
session_data VARCHAR,
|
|
|
|
enable_archiving BOOL NOT NULL DEFAULT false
|
2020-04-03 16:40:05 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE user_contacts (
|
2020-04-04 22:12:39 +00:00
|
|
|
id INTEGER PRIMARY KEY,
|
2020-04-03 16:40:05 +00:00
|
|
|
user_id INT NOT NULL REFERENCES users,
|
2020-09-30 13:01:52 +00:00
|
|
|
wa_jid VARCHAR NOT NULL,
|
2020-04-03 16:40:05 +00:00
|
|
|
subscription_state VARCHAR NOT NULL DEFAULT 'none',
|
|
|
|
avatar_url VARCHAR,
|
|
|
|
name VARCHAR,
|
2020-04-07 12:06:26 +00:00
|
|
|
notify VARCHAR,
|
2020-09-30 13:01:52 +00:00
|
|
|
status VARCHAR,
|
|
|
|
UNIQUE(user_id, wa_jid)
|
2020-04-03 16:40:05 +00:00
|
|
|
);
|
2020-04-05 11:04:19 +00:00
|
|
|
|
|
|
|
CREATE TABLE user_messages (
|
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
user_id INT NOT NULL REFERENCES users,
|
|
|
|
xmpp_id VARCHAR NOT NULL,
|
|
|
|
wa_id VARCHAR NOT NULL,
|
|
|
|
UNIQUE(user_id, wa_id)
|
|
|
|
);
|
2020-04-05 14:05:27 +00:00
|
|
|
|
|
|
|
CREATE TABLE avatar_data (
|
|
|
|
avatar_url VARCHAR NOT NULL PRIMARY KEY,
|
|
|
|
sha1 VARCHAR NOT NULL,
|
|
|
|
image BLOB NOT NULL
|
|
|
|
);
|
2020-04-12 07:27:04 +00:00
|
|
|
|
|
|
|
CREATE TABLE user_chats (
|
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
user_id INT NOT NULL REFERENCES users,
|
|
|
|
wa_jid VARCHAR NOT NULL,
|
|
|
|
user_resource VARCHAR,
|
|
|
|
invitation_state VARCHAR NOT NULL DEFAULT 'none',
|
|
|
|
subject VARCHAR
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE user_chat_members (
|
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
chat_id INT NOT NULL REFERENCES user_chats,
|
|
|
|
wa_jid VARCHAR NOT NULL,
|
|
|
|
resource VARCHAR NOT NULL,
|
|
|
|
affiliation VARCHAR NOT NULL DEFAULT 'member'
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE user_chat_joined (
|
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
chat_id INT NOT NULL REFERENCES user_chats,
|
|
|
|
jid VARCHAR NOT NULL
|
|
|
|
);
|
Save groupchat messages in an archive, allow bulk history requesting
- WARNING: This change is hilariously unsuitable for public instances. Don't run
this code in such an environment yet!
- Groupchat messages are now stored in the sqlite3 database, with the intent
to allow retrieval via MAM at a later date.
FIXME: You can't opt out of this though, which is a huge GDPR hole.
- You can also request ALL of your group chat history from whatsapp be fetched
and stored in the database (!!). This is a VERY resource-intensive operation,
as it involves spawning a metric crapton of threads, uploading a metric
crapton of historical media to the configured upload server, and writing a
metric crapton of messages into the database.
- At some point, the ability to invoke this will be severely limited to only
approved users. That point has not yet come, though.
- Additionally, the chat history request will abort if the connection it's
associated with dies. (You can just retry it, though.)
2020-09-26 18:49:26 +00:00
|
|
|
|
|
|
|
CREATE TABLE user_chat_history (
|
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
user_id INT NOT NULL REFERENCES users,
|
|
|
|
chat_id INT NOT NULL REFERENCES user_chats,
|
|
|
|
user_from VARCHAR NOT NULL,
|
|
|
|
ts_unix INT NOT NULL,
|
|
|
|
xmpp_id VARCHAR NOT NULL,
|
|
|
|
orig_id VARCHAR,
|
|
|
|
body VARCHAR NOT NULL,
|
|
|
|
oob_url VARCHAR
|
|
|
|
);
|
2020-09-27 22:01:40 +00:00
|
|
|
|
|
|
|
CREATE UNIQUE INDEX user_chat_history_unique ON user_chat_history (user_id, chat_id, xmpp_id);
|
2020-09-30 13:01:52 +00:00
|
|
|
|
|
|
|
CREATE TABLE administrators (
|
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
jid VARCHAR UNIQUE NOT NULL
|
|
|
|
);
|