Skip to content

Commit

Permalink
Merge pull request #101 from BlueBubblesApp/zach/dev
Browse files Browse the repository at this point in the history
Zach/dev
  • Loading branch information
zlshames authored Nov 23, 2020
2 parents 37a9a15 + 57b34b9 commit 4038baa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bluebubbles-server",
"version": "0.1.9",
"version": "0.1.10",
"description": "",
"main": "./dist/main.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/main/server/helpers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export class ActionHandler {
)
);
} catch (ex) {
Server().log(ex);

// If it's not a timeout failure, throw the error
if (!((ex?.message ?? "") as string).includes("AppleEvent timed out")) {
throw ex;
Expand Down
19 changes: 18 additions & 1 deletion src/main/server/services/queue/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FileSystem } from "@server/fileSystem";
import { ActionHandler } from "@server/helpers/actions";
import { Server } from "@server/index";

Expand All @@ -7,7 +8,7 @@ export type QueueItem = {
};

export class QueueService {
items: QueueItem[];
items: QueueItem[] = [];

isProcessing = false;

Expand All @@ -30,10 +31,26 @@ export class QueueService {

// Handle the event
try {
Server().log(`Handling queue item, '${item.type}'`);
switch (item.type) {
case "open-chat":
await ActionHandler.openChat(item.data);
break;
case "send-attachment":
await ActionHandler.sendMessage(
item.data.tempGuid,
item.data.chatGuid,
item.data.message,
item.data.attachmentGuid,
item.data.attachmentName,
item.data.chunks
);

// After 60 seconds, delete the attachment chunks
setTimeout(() => {
FileSystem.deleteChunks(item.data.attachmentGuid);
}, 60000);
break;
default:
Server().log(`Unhandled queue item type: ${item.type}`, "warn");
}
Expand Down
22 changes: 10 additions & 12 deletions src/main/server/services/socket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { getAttachmentResponse } from "@server/databases/imessage/entity/Attachm
import { DBMessageParams } from "@server/databases/imessage/types";
import { Queue } from "@server/databases/server/entity/Queue";
import { ActionHandler } from "@server/helpers/actions";
import { QueueItem } from "@server/services/queue";
import { QueueItem } from "@server/services/queue/index";

const osVersion = macosVersion();

Expand Down Expand Up @@ -524,21 +524,19 @@ export class SocketService {

// If there are no more chunks, compile, save, and send
if (!hasMore) {
try {
await ActionHandler.sendMessage(
Server().queue.add({
type: "send-attachment",
data: {
tempGuid,
chatGuid,
message,
attachmentGuid,
params?.attachmentName,
attachmentGuid ? FileSystem.buildAttachmentChunks(attachmentGuid) : null
);

FileSystem.deleteChunks(attachmentGuid);
return response(cb, "message-sent", createSuccessResponse(null));
} catch (ex) {
return response(cb, "send-message-chunk-error", createServerErrorResponse(ex.message));
}
attachmentName: params?.attachmentName,
chunks: attachmentGuid ? FileSystem.buildAttachmentChunks(attachmentGuid) : null
}
});

return response(cb, "message-sent", createSuccessResponse(null));
}

return response(cb, "message-chunk-saved", createSuccessResponse(null));
Expand Down

0 comments on commit 4038baa

Please sign in to comment.