Skip to content

Commit

Permalink
Merge pull request #712 from BlueBubblesApp/development
Browse files Browse the repository at this point in the history
v1.9.8
  • Loading branch information
zlshames authored Nov 20, 2024
2 parents 87679b7 + c1356d1 commit 9ee9120
Show file tree
Hide file tree
Showing 47 changed files with 1,052 additions and 281 deletions.
28 changes: 28 additions & 0 deletions macos/database/samples/sequoia/attachment.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE TABLE attachment (
ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
guid TEXT UNIQUE NOT NULL,
created_date INTEGER DEFAULT 0,
start_date INTEGER DEFAULT 0,
filename TEXT,
uti TEXT,
mime_type TEXT,
transfer_state INTEGER DEFAULT 0,
is_outgoing INTEGER DEFAULT 0,
user_info BLOB,
transfer_name TEXT,
total_bytes INTEGER DEFAULT 0,
is_sticker INTEGER DEFAULT 0,
sticker_user_info BLOB,
attribution_info BLOB,
hide_attachment INTEGER DEFAULT 0,
ck_sync_state INTEGER DEFAULT 0,
ck_server_change_token_blob BLOB,
ck_record_id TEXT,
original_guid TEXT UNIQUE NOT NULL,
sr_ck_sync_state INTEGER DEFAULT 0,
sr_ck_server_change_token_blob BLOB,
sr_ck_record_id TEXT,
is_commsafety_sensitive INTEGER DEFAULT 0,
emoji_image_content_identifier TEXT DEFAULT NULL,
emoji_image_short_description TEXT DEFAULT NULL
)
33 changes: 33 additions & 0 deletions macos/database/samples/sequoia/chat.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
CREATE TABLE chat (
ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
guid TEXT UNIQUE NOT NULL,
style INTEGER,
state INTEGER,
account_id TEXT,
properties BLOB,
chat_identifier TEXT,
service_name TEXT,
room_name TEXT,
account_login TEXT,
is_archived INTEGER DEFAULT 0,
last_addressed_handle TEXT,
display_name TEXT,
group_id TEXT,
is_filtered INTEGER,
successful_query INTEGER,
engram_id TEXT,
server_change_token TEXT,
ck_sync_state INTEGER DEFAULT 0,
original_group_id TEXT,
last_read_message_timestamp INTEGER DEFAULT 0,
sr_server_change_token TEXT,
sr_ck_sync_state INTEGER DEFAULT 0,
cloudkit_record_id TEXT,
sr_cloudkit_record_id TEXT,
last_addressed_sim_id TEXT,
is_blackholed INTEGER DEFAULT 0,
syndication_date INTEGER DEFAULT 0,
syndication_type INTEGER DEFAULT 0,
is_recovered INTEGER DEFAULT 0,
is_deleting_incoming_messages INTEGER DEFAULT 0
)
4 changes: 4 additions & 0 deletions macos/database/samples/sequoia/deleted_messages.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE deleted_messages (
ROWID INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
guid TEXT NOT NULL
)
9 changes: 9 additions & 0 deletions macos/database/samples/sequoia/handle.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE handle (
ROWID INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
id TEXT NOT NULL,
country TEXT,
service TEXT NOT NULL,
uncanonicalized_id TEXT,
person_centric_id TEXT,
UNIQUE (id, service)
)
96 changes: 96 additions & 0 deletions macos/database/samples/sequoia/message.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
CREATE TABLE message (
ROWID INTEGER PRIMARY KEY AUTOINCREMENT,
guid TEXT UNIQUE NOT NULL,
text TEXT,
replace INTEGER DEFAULT 0,
service_center TEXT,
handle_id INTEGER DEFAULT 0,
subject TEXT,
country TEXT,
attributedBody BLOB,
version INTEGER DEFAULT 0,
type INTEGER DEFAULT 0,
service TEXT,
account TEXT,
account_guid TEXT,
error INTEGER DEFAULT 0,
date INTEGER,
date_read INTEGER,
date_delivered INTEGER,
is_delivered INTEGER DEFAULT 0,
is_finished INTEGER DEFAULT 0,
is_emote INTEGER DEFAULT 0,
is_from_me INTEGER DEFAULT 0,
is_empty INTEGER DEFAULT 0,
is_delayed INTEGER DEFAULT 0,
is_auto_reply INTEGER DEFAULT 0,
is_prepared INTEGER DEFAULT 0,
is_read INTEGER DEFAULT 0,
is_system_message INTEGER DEFAULT 0,
is_sent INTEGER DEFAULT 0,
has_dd_results INTEGER DEFAULT 0,
is_service_message INTEGER DEFAULT 0,
is_forward INTEGER DEFAULT 0,
was_downgraded INTEGER DEFAULT 0,
is_archive INTEGER DEFAULT 0,
cache_has_attachments INTEGER DEFAULT 0,
cache_roomnames TEXT,
was_data_detected INTEGER DEFAULT 0,
was_deduplicated INTEGER DEFAULT 0,
is_audio_message INTEGER DEFAULT 0,
is_played INTEGER DEFAULT 0,
date_played INTEGER,
item_type INTEGER DEFAULT 0,
other_handle INTEGER DEFAULT 0,
group_title TEXT,
group_action_type INTEGER DEFAULT 0,
share_status INTEGER DEFAULT 0,
share_direction INTEGER DEFAULT 0,
is_expirable INTEGER DEFAULT 0,
expire_state INTEGER DEFAULT 0,
message_action_type INTEGER DEFAULT 0,
message_source INTEGER DEFAULT 0,
associated_message_guid TEXT,
associated_message_type INTEGER DEFAULT 0,
balloon_bundle_id TEXT,
payload_data BLOB,
expressive_send_style_id TEXT,
associated_message_range_location INTEGER DEFAULT 0,
associated_message_range_length INTEGER DEFAULT 0,
time_expressive_send_played INTEGER,
message_summary_info BLOB,
ck_sync_state INTEGER DEFAULT 0,
ck_record_id TEXT,
ck_record_change_tag TEXT,
destination_caller_id TEXT,
sr_ck_sync_state INTEGER DEFAULT 0,
sr_ck_record_id TEXT,
sr_ck_record_change_tag TEXT,
is_corrupt INTEGER DEFAULT 0,
reply_to_guid TEXT,
sort_id INTEGER,
is_spam INTEGER DEFAULT 0,
has_unseen_mention INTEGER DEFAULT 0,
thread_originator_guid TEXT,
thread_originator_part TEXT,
syndication_ranges TEXT DEFAULT NULL,
was_delivered_quietly INTEGER DEFAULT 0,
did_notify_recipient INTEGER DEFAULT 0,
synced_syndication_ranges TEXT DEFAULT NULL,
date_retracted INTEGER DEFAULT 0,
date_edited INTEGER DEFAULT 0,
was_detonated INTEGER DEFAULT 0,
part_count INTEGER,
is_stewie INTEGER DEFAULT 0,
is_sos INTEGER DEFAULT 0,
is_critical INTEGER DEFAULT 0,
bia_reference_id TEXT DEFAULT NULL,
is_kt_verified INTEGER DEFAULT 0,
fallback_hash TEXT DEFAULT NULL,
associated_message_emoji TEXT DEFAULT NULL,
is_pending_satellite_send INTEGER DEFAULT 0,
needs_relay INTEGER DEFAULT 0,
schedule_type INTEGER DEFAULT 0,
schedule_state INTEGER DEFAULT 0,
sent_or_received_off_grid INTEGER DEFAULT 0
)
10 changes: 10 additions & 0 deletions macos/database/samples/sequoia/message_processing_task.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE recoverable_message_part (
chat_id INTEGER REFERENCES chat (ROWID) ON DELETE CASCADE,
message_id INTEGER REFERENCES message (ROWID) ON DELETE CASCADE,
part_index INTEGER,
delete_date INTEGER,
part_text BLOB NOT NULL,
ck_sync_state INTEGER DEFAULT 0,
PRIMARY KEY (chat_id, message_id, part_index),
CHECK (delete_date != 0)
)
10 changes: 10 additions & 0 deletions macos/database/samples/sequoia/recoverable_message_part.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE recoverable_message_part (
chat_id INTEGER REFERENCES chat (ROWID) ON DELETE CASCADE,
message_id INTEGER REFERENCES message (ROWID) ON DELETE CASCADE,
part_index INTEGER,
delete_date INTEGER,
part_text BLOB NOT NULL,
ck_sync_state INTEGER DEFAULT 0,
PRIMARY KEY (chat_id, message_id, part_index),
CHECK (delete_date != 0)
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ The `.md5` files within this directory contain a single string that is correlate

## Clourflared

This is the official cloudflare daemon (x86; amd64), downloaded from: https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-darwin-amd64.tgz
This is the official cloudflare daemon:

The arm64 (Apple Silicon) build is from Homebrew: https://formulae.brew.sh/formula/cloudflared
- (x86; amd64) downloaded from: https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-darwin-amd64.tgz
- (arm64 - Apple Silicon) downloaded from: https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-darwin-arm64.tgz

The dummy `cloudflared-config.yml` file is for the daemon to use as to not interfere with the default system configuration
The dummy `cloudflared-config.yml` file is for the daemon to use as to not interfere with the default system configuration
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bb5b2df38ee82a42ec156ceb0b3744fa
7673f85211adbead7799915ae223f064
Binary file not shown.
26 changes: 26 additions & 0 deletions packages/server/src/server/api/http/api/v1/httpRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import { ThemeValidator } from "./validators/themeValidator";
import type { Context, Next } from "koa";
import { FindMyRouter } from "./routers/findmyRouter";
import { getLogger } from "@server/lib/logging/Loggable";
import { WebhookRouter } from "./routers/webhookRouter";
import { WebhookValidator } from "./validators/webhookValidator";

export class HttpRoutes {
static version = 1;
Expand Down Expand Up @@ -660,6 +662,30 @@ export class HttpRoutes {
controller: SettingsRouter.delete
}
]
},
{
name: "Webhooks",
middleware: HttpRoutes.protected,
prefix: "webhook",
routes: [
{
method: HttpMethod.GET,
path: "",
validators: [WebhookValidator.validateGetWebhooks],
controller: WebhookRouter.get
},
{
method: HttpMethod.POST,
path: "",
validators: [WebhookValidator.validateCreateWebhook],
controller: WebhookRouter.create
},
{
method: HttpMethod.DELETE,
path: ":id",
controller: WebhookRouter.delete
}
]
}
]
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import { FindMyInterface } from "@server/api/interfaces/findMyInterface";
export class FindMyRouter {
static async refreshDevices(ctx: RouterContext, _: Next) {
try {
await FindMyInterface.refreshDevices();
return new Success(ctx, { message: "Successfully refreshed Find My device locations!" }).send();
const locations = await FindMyInterface.refreshDevices();
return new Success(ctx, {
message: "Successfully refreshed Find My device locations!",
data: locations
}).send();
} catch (ex: any) {
throw new ServerError({
message: "Failed to refresh Find My device locations!",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { RouterContext } from "koa-router";
import { Next } from "koa";

import { Server } from "@server";
import { isEmpty } from "@server/helpers/utils";

import { Success } from "../responses/success";
import { NotFound } from "../responses/errors";

export class WebhookRouter {
static async get(ctx: RouterContext, _: Next) {
const url = ctx?.request?.query?.url as string;
const id = (ctx?.request?.query?.id) ? Number.parseInt(ctx?.request?.query?.id as string) : null;
const webhooks = await Server().repo.getWebhooks({ url, id });

// Convert the events to a list (from json array)
for (const webhook of webhooks) {
webhook.events = JSON.parse(webhook.events);
}

return new Success(ctx, { message: "Successfully fetched webhooks!", data: webhooks }).send();
}

static async create(ctx: RouterContext, _: Next) {
const { url, events } = ctx.request.body;
const webhook = await Server().repo.addWebhook(url, events);

// Convert the events to a list (from json array)
webhook.events = JSON.parse(webhook.events);

return new Success(ctx, { data: webhook, message: "Successfully created webhook!" }).send();
}

static async delete(ctx: RouterContext, _: Next): Promise<void> {
const { id } = ctx.params;

// Find it
const webhooks = await Server().repo.getWebhooks({ id: Number.parseInt(id as string) });
if (isEmpty(webhooks)) throw new NotFound({ error: "Webhook does not exist!" });

// Delete it
await Server().repo.deleteWebhook({ id: Number.parseInt(id as string) });

// Send success
return new Success(ctx, { message: "Successfully deleted webhook!" }).send();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { RouterContext } from "koa-router";
import { Next } from "koa";

import { ValidateInput } from "./index";
import { BadRequest } from "../responses/errors";
import { webhookEventOptions } from "@server/api/http/constants";

export class WebhookValidator {

static webhookValues = webhookEventOptions.map(e => e.value);

static getWebhookRules = {
name: "string",
id: "number",
};

static async validateGetWebhooks(ctx: RouterContext, next: Next) {
ValidateInput(ctx?.request?.query, WebhookValidator.getWebhookRules);
await next();
}

static createRules = {
url: "required|string",
events: "required|array"
};

static async validateCreateWebhook(ctx: RouterContext, next: Next) {
ValidateInput(ctx?.request?.body, WebhookValidator.createRules);

const { url, events } = ctx.request.body;
if (url.length === 0) {
throw new BadRequest({ error: "Webhook URL is required!" });
} else if (!url.startsWith('http')) {
throw new BadRequest({ error: "Webhook URL must include an HTTP scheme!" });
}

// Ensure that the events are valid
const validatedEvents = [];
for (const event of events) {
if (typeof event !== "string") {
throw new BadRequest({ error: "Webhook events must be strings!" });
}

// Find the webhook value in the webhook events
const webhookEvent = webhookEventOptions.find(e => e.value === event);
if (!webhookEvent) {
throw new BadRequest({ error: `Invalid webhook event: ${event}! Webhook must be one of: ${WebhookValidator.webhookValues}` });
}

// Update the event to the label
validatedEvents.push(webhookEvent);
}

// Update the events
ctx.request.body.events = validatedEvents;

await next();
}
}
Loading

0 comments on commit 9ee9120

Please sign in to comment.