From 9c6d99f2d6aa7d3b8f58d8c849b8399faed9b018 Mon Sep 17 00:00:00 2001 From: zlshames Date: Fri, 23 Oct 2020 12:03:52 -0400 Subject: [PATCH 1/2] Adds hasDdResults column --- src/main/server/databases/imessage/entity/Message.ts | 1 + src/main/server/helpers/actions.ts | 2 +- src/main/server/types.ts | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/server/databases/imessage/entity/Message.ts b/src/main/server/databases/imessage/entity/Message.ts index e6076853..ef6b2fea 100644 --- a/src/main/server/databases/imessage/entity/Message.ts +++ b/src/main/server/databases/imessage/entity/Message.ts @@ -430,6 +430,7 @@ export const getMessageResponse = async (tableData: Message, withBlurhash = true isArchived: tableData.isArchived, cacheRoomnames: tableData.cacheRoomnames, isAudioMessage: tableData.isAudioMessage, + hasDdResults: tableData.hasDdResults, datePlayed: tableData.datePlayed ? tableData.datePlayed.getTime() : null, itemType: tableData.itemType, groupTitle: tableData.groupTitle, diff --git a/src/main/server/helpers/actions.ts b/src/main/server/helpers/actions.ts index 9c2cd55c..813641d9 100644 --- a/src/main/server/helpers/actions.ts +++ b/src/main/server/helpers/actions.ts @@ -58,7 +58,7 @@ export class ActionHandler { await FileSystem.startMessages(); // We need offsets here due to iMessage's save times being a bit off for some reason - const now = new Date(new Date().getTime() - 3000).getTime(); // With 3 second offset + const now = new Date(new Date().getTime() - 10000).getTime(); // With 10 second offset await FileSystem.executeAppleScript( sendMessage( chatGuid, diff --git a/src/main/server/types.ts b/src/main/server/types.ts index 01778f46..5ac80005 100644 --- a/src/main/server/types.ts +++ b/src/main/server/types.ts @@ -59,6 +59,7 @@ export type MessageResponse = { isServiceMessage: boolean; isForward: boolean; isArchived: boolean; + hasDdResults: boolean; cacheRoomnames: string | null; isAudioMessage: boolean; datePlayed: number | null; From 1a4547e93a6a7deb472a5b3131110f89a4af3046 Mon Sep 17 00:00:00 2001 From: zlshames Date: Fri, 23 Oct 2020 14:06:44 -0400 Subject: [PATCH 2/2] Adds ability to toggle chat read status - Increases lookback time for new message matches - Adds force restart to ngrok after max retry attempts (25) --- package.json | 2 +- src/main/server/services/ngrok/index.ts | 9 ++++++++- src/main/server/services/socket/index.ts | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bb06d34b..eb998c6e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bluebubbles-server", - "version": "0.1.5", + "version": "0.1.6", "description": "", "main": "./dist/main.js", "scripts": { diff --git a/src/main/server/services/ngrok/index.ts b/src/main/server/services/ngrok/index.ts index 31ab6d21..3133b144 100644 --- a/src/main/server/services/ngrok/index.ts +++ b/src/main/server/services/ngrok/index.ts @@ -1,3 +1,4 @@ +import { app } from "electron"; import { Server } from "@server/index"; import { connect, disconnect, kill, authtoken } from "ngrok"; @@ -119,7 +120,7 @@ export class NgrokService { tries += 1; // Set the wait time based on which try we are attempting - const wait = tries > 1 ? 5000 * tries : 1000; + const wait = tries > 1 ? 2000 * tries : 1000; Server().log(`Attempting to restart ngrok (attempt ${tries}; ${wait} ms delay)`); connected = await this.restartHandler(wait); } @@ -131,6 +132,12 @@ export class NgrokService { Server().log(`Failed to connect to ngrok after ${maxTries} tries`); } + if (tries >= maxTries) { + Server().log("Reached maximum retry attempts for Ngrok. Force restarting app..."); + app.relaunch({ args: process.argv.slice(1).concat(["--relaunch"]) }); + app.exit(0); + } + return connected; } diff --git a/src/main/server/services/socket/index.ts b/src/main/server/services/socket/index.ts index 28a89764..64711305 100644 --- a/src/main/server/services/socket/index.ts +++ b/src/main/server/services/socket/index.ts @@ -687,6 +687,24 @@ export class SocketService { } ); + /** + * Tells all clients that a chat is read + */ + socket.on("toggle-chat-read-status", (params, cb): void => { + // Make sure we have all the required data + if (!params?.chatGuid) return respond(cb, "error", createBadRequestResponse("No chat GUID provided!")); + if (!params?.status) return respond(cb, "error", createBadRequestResponse("No chat status provided!")); + + // Send the notification out to all clients + Server().emitMessage("chat-read-status-changed", { + chatGuid: params.chatGuid, + status: params.status + }); + + // Return null so Typescript doesn't yell at us + return null; + }); + socket.on("disconnect", reason => { Server().log(`Client ${socket.id} disconnected! Reason: ${reason}`); });