Skip to content

Commit ba2c678

Browse files
authored
Merge pull request #119 from BlueBubblesApp/zach/dev
v0.1.12
2 parents a7c5060 + b382259 commit ba2c678

File tree

9 files changed

+181
-79
lines changed

9 files changed

+181
-79
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bluebubbles-server",
3-
"version": "0.1.11",
3+
"version": "0.1.12",
44
"description": "BlueBubbles Server is the app that powers the BlueBubbles Android and Desktop Apps",
55
"main": "./dist/main.js",
66
"scripts": {

src/main/server/databases/imessage/listeners/incomingMessageListener.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { MessageRepository } from "@server/databases/imessage";
22
import { Message } from "@server/databases/imessage/entity/Message";
33
import { EventCache } from "@server/eventCache";
4+
import { Server } from "@server/index";
45
import { ChangeListener } from "./changeListener";
56
import { getCacheName } from "../helpers/utils";
67

@@ -19,20 +20,27 @@ export class IncomingMessageListener extends ChangeListener {
1920
async getEntries(after: Date, before: Date): Promise<void> {
2021
// Offset 15 seconds to account for the "Apple" delay
2122
const offsetDate = new Date(after.getTime() - 15000);
23+
const query = [
24+
{
25+
statement: "message.is_from_me = :fromMe",
26+
args: { fromMe: 0 }
27+
}
28+
];
29+
30+
// If SMS support isn't enabled, add the iMessage server specifier
31+
const smsSupport = Server().repo.getConfig("sms_support") as boolean;
32+
if (!smsSupport) {
33+
query.push({
34+
statement: "message.service = 'iMessage'",
35+
args: null
36+
});
37+
}
38+
2239
const entries = await this.repo.getMessages({
2340
after: offsetDate,
2441
before,
2542
withChats: true,
26-
where: [
27-
{
28-
statement: "message.service = 'iMessage'",
29-
args: null
30-
},
31-
{
32-
statement: "message.is_from_me = :fromMe",
33-
args: { fromMe: 0 }
34-
}
35-
]
43+
where: query
3644
});
3745

3846
// Emit the new message

src/main/server/databases/imessage/listeners/outgoingMessageListener.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ export class OutgoingMessageListener extends ChangeListener {
145145
}
146146
];
147147

148+
// If SMS support is disabled, only search for iMessage
149+
const smsSupport = Server().repo.getConfig("sms_support") as boolean;
150+
if (!smsSupport) {
151+
baseQuery.push({
152+
statement: "message.service = 'iMessage'",
153+
args: null
154+
});
155+
}
156+
148157
// First, check for unsent messages
149158
const newUnsent = await this.repo.getMessages({
150159
after,
@@ -236,12 +245,24 @@ export class OutgoingMessageListener extends ChangeListener {
236245
}
237246

238247
async emitUpdatedMessages(after: Date, before: Date) {
248+
const baseQuery: DBWhereItem[] = [];
249+
250+
// If SMS support is disabled, only search for iMessage
251+
const smsSupport = Server().repo.getConfig("sms_support") as boolean;
252+
if (!smsSupport) {
253+
baseQuery.push({
254+
statement: "message.service = 'iMessage'",
255+
args: null
256+
});
257+
}
258+
239259
// Get updated entries from myself only
240260
const entries = await this.repo.getUpdatedMessages({
241261
after,
242262
before,
243263
withChats: true,
244264
where: [
265+
...baseQuery,
245266
{
246267
statement: "message.is_from_me = :isFromMe",
247268
args: { isFromMe: 1 }

src/main/server/databases/server/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export const DEFAULT_DB_ITEMS: { [key: string]: Function } = {
1111
encrypt_coms: () => 0,
1212
hide_dock_icon: () => 0,
1313
last_fcm_restart: () => 0,
14-
start_via_terminal: () => 0
14+
start_via_terminal: () => 0,
15+
sms_support: () => 0
1516
};

src/main/server/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ class BlueBubblesServer {
302302
} catch (ex) {
303303
Server().log(`Failed to restart via terminal!\n${ex}`);
304304
}
305+
306+
this.log("Finished post-start checks...");
305307
}
306308

307309
private setDockIcon() {

src/main/server/services/socket/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ export class SocketService {
8888
* Handle all other data requests
8989
*/
9090
this.server.on("connection", async socket => {
91-
const pass = socket.handshake.query?.password ?? socket.handshake.query?.guid;
91+
let pass = socket.handshake.query?.password ?? socket.handshake.query?.guid;
9292
const cfgPass = (await Server().repo.getConfig("password")) as string;
9393

94+
// Decode the param incase it contains URL encoded characters
95+
pass = decodeURI(pass);
96+
9497
// Basic authentication
9598
if (pass === cfgPass) {
9699
Server().log(`Client Authenticated Successfully`);

src/renderer/components/ViewContainer/PreDashboardView/PreDashboardView.tsx

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as React from "react";
1111
import Dropzone from "react-dropzone";
1212
import { shell, ipcRenderer } from "electron";
1313
import { Redirect } from "react-router";
14-
import { isValidServerConfig, isValidClientConfig } from "@renderer/helpers/utils";
14+
import { isValidServerConfig, isValidClientConfig, checkFirebaseUrl, invokeMain } from "@renderer/helpers/utils";
1515
import "./PreDashboardView.css";
1616
import { Config } from "@server/databases/server/entity";
1717

@@ -27,6 +27,7 @@ interface State {
2727
enableNgrok: boolean;
2828
showModal: boolean;
2929
serverUrl: string;
30+
smsSupport: boolean;
3031
}
3132

3233
class PreDashboardView extends React.Component<unknown, State> {
@@ -45,7 +46,8 @@ class PreDashboardView extends React.Component<unknown, State> {
4546
inputPassword: "",
4647
enableNgrok: true,
4748
showModal: false,
48-
serverUrl: ""
49+
serverUrl: "",
50+
smsSupport: false
4951
};
5052
}
5153

@@ -147,25 +149,29 @@ class PreDashboardView extends React.Component<unknown, State> {
147149
const binaryStr = reader.result;
148150
const valid = isValidServerConfig(binaryStr as string);
149151
const validClient = isValidClientConfig(binaryStr as string);
152+
const jsonData = JSON.parse(binaryStr as string);
150153

151154
if (valid) {
152-
ipcRenderer.invoke("set-fcm-server", JSON.parse(binaryStr as string));
155+
ipcRenderer.invoke("set-fcm-server", jsonData);
153156
this.setState({ fcmServer: binaryStr });
154157
} else if (validClient) {
155-
ipcRenderer.invoke("set-fcm-client", JSON.parse(binaryStr as string));
156-
this.setState({ fcmClient: binaryStr });
157-
158-
this.invokeMain("show-dialog", {
159-
type: "warning",
160-
buttons: ["OK"],
161-
title: "BlueBubbles Warning",
162-
message: "We've corrected a mistake you made",
163-
detail:
164-
`The file you chose was for the FCM Client configuration and ` +
165-
`we've saved it as such. Now, please choose the correct server configuration.`
166-
});
158+
const test = checkFirebaseUrl(jsonData);
159+
if (test) {
160+
ipcRenderer.invoke("set-fcm-client", jsonData);
161+
this.setState({ fcmClient: binaryStr });
162+
163+
invokeMain("show-dialog", {
164+
type: "warning",
165+
buttons: ["OK"],
166+
title: "BlueBubbles Warning",
167+
message: "We've corrected a mistake you made",
168+
detail:
169+
`The file you chose was for the FCM Client configuration and ` +
170+
`we've saved it as such. Now, please choose the correct server configuration.`
171+
});
172+
}
167173
} else {
168-
this.invokeMain("show-dialog", {
174+
invokeMain("show-dialog", {
169175
type: "error",
170176
buttons: ["OK"],
171177
title: "BlueBubbles Error",
@@ -178,10 +184,6 @@ class PreDashboardView extends React.Component<unknown, State> {
178184
reader.readAsText(acceptedFiles[0]);
179185
};
180186

181-
async invokeMain(event: string, args: any): Promise<any> {
182-
return ipcRenderer.invoke(event, args);
183-
}
184-
185187
handleClientFile = (acceptedFiles: any) => {
186188
const reader = new FileReader();
187189

@@ -192,25 +194,19 @@ class PreDashboardView extends React.Component<unknown, State> {
192194
const binaryStr = reader.result;
193195
const valid = isValidClientConfig(binaryStr as string);
194196
const validServer = isValidServerConfig(binaryStr as string);
197+
const jsonData = JSON.parse(binaryStr as string);
195198

196199
if (valid) {
197-
ipcRenderer.invoke("set-fcm-client", JSON.parse(binaryStr as string));
198-
this.setState({ fcmClient: binaryStr });
200+
const test = checkFirebaseUrl(jsonData);
201+
if (test) {
202+
ipcRenderer.invoke("set-fcm-client", jsonData);
203+
this.setState({ fcmClient: binaryStr });
204+
}
199205
} else if (validServer) {
200206
ipcRenderer.invoke("set-fcm-server", JSON.parse(binaryStr as string));
201207
this.setState({ fcmServer: binaryStr });
202-
203-
this.invokeMain("show-dialog", {
204-
type: "warning",
205-
buttons: ["OK"],
206-
title: "BlueBubbles Warning",
207-
message: "We've corrected a mistake you made",
208-
detail:
209-
`The file you chose was for the FCM Server configuration and ` +
210-
`we've saved it as such. Now, please choose the correct client configuration.`
211-
});
212208
} else {
213-
this.invokeMain("show-dialog", {
209+
invokeMain("show-dialog", {
214210
type: "error",
215211
buttons: ["OK"],
216212
title: "BlueBubbles Error",
@@ -228,7 +224,6 @@ class PreDashboardView extends React.Component<unknown, State> {
228224
}
229225

230226
completeTutorial() {
231-
console.log(this.state);
232227
ipcRenderer.invoke("toggle-tutorial", true);
233228
this.setState({ redirect: "/dashboard" });
234229
}
@@ -237,11 +232,19 @@ class PreDashboardView extends React.Component<unknown, State> {
237232
this.setState({ [e.target.name]: e.target.value } as any);
238233
};
239234

240-
handleNgrokCheckboxChange(e: React.ChangeEvent<HTMLInputElement>) {
241-
this.setState({ enableNgrok: e.target.checked });
242-
ipcRenderer.invoke("toggle-ngrok", e.target.checked);
243-
if (!e.target.checked) {
244-
this.setState({ showModal: true });
235+
handleCheckboxChange(e: React.ChangeEvent<HTMLInputElement>, stateVar: string) {
236+
this.setState({ [stateVar]: e.target.checked } as any);
237+
238+
if (e.target.id === "toggleNgrok") {
239+
ipcRenderer.invoke("toggle-ngrok", e.target.checked);
240+
241+
if (!e.target.checked) {
242+
this.setState({ showModal: true });
243+
}
244+
} else {
245+
ipcRenderer.invoke("set-config", {
246+
[e.target.id]: e.target.checked
247+
});
245248
}
246249
}
247250

@@ -358,7 +361,19 @@ class PreDashboardView extends React.Component<unknown, State> {
358361
<input
359362
id="toggleNgrok"
360363
checked={this.state.enableNgrok}
361-
onChange={e => this.handleNgrokCheckboxChange(e)}
364+
onChange={e => this.handleCheckboxChange(e, "enableNgrok")}
365+
type="checkbox"
366+
/>
367+
<i />
368+
</div>
369+
</div>
370+
<div id="setNgrokContainer">
371+
<h3>SMS Support (Android Client): </h3>
372+
<div style={{ marginTop: "3px" }}>
373+
<input
374+
id="sms_support"
375+
checked={this.state.smsSupport}
376+
onChange={e => this.handleCheckboxChange(e, "smsSupport")}
362377
type="checkbox"
363378
/>
364379
<i />

0 commit comments

Comments
 (0)