@social-mail/social-mail-web-server 1.7.71 → 1.7.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/model/entities/Mailbox.d.ts +2 -0
- package/dist/server/model/entities/Mailbox.d.ts.map +1 -1
- package/dist/server/model/entities/Mailbox.js +5 -0
- package/dist/server/model/entities/Mailbox.js.map +1 -1
- package/dist/server/model/entities/MailboxContact.d.ts +2 -0
- package/dist/server/model/entities/MailboxContact.d.ts.map +1 -1
- package/dist/server/model/entities/MailboxContact.js +10 -0
- package/dist/server/model/entities/MailboxContact.js.map +1 -1
- package/dist/server/model/entities/SubscriptionType.d.ts +3 -0
- package/dist/server/model/entities/SubscriptionType.d.ts.map +1 -0
- package/dist/server/model/entities/SubscriptionType.js +2 -0
- package/dist/server/model/entities/SubscriptionType.js.map +1 -0
- package/dist/server/seed/ui/seed-ui.js +1 -1
- package/dist/server/workflows/channel/BroadcastEmail.d.ts.map +1 -1
- package/dist/server/workflows/channel/BroadcastEmail.js +4 -1
- package/dist/server/workflows/channel/BroadcastEmail.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/server/model/entities/Mailbox.ts +4 -0
- package/src/server/model/entities/MailboxContact.ts +9 -0
- package/src/server/model/entities/SubscriptionType.ts +2 -0
- package/src/server/seed/ui/seed-ui.ts +1 -1
- package/src/server/workflows/channel/BroadcastEmail.ts +5 -1
- package/dist/server/workflows/post-receive/PostReceiveWorkflow.d.ts +0 -2
- package/dist/server/workflows/post-receive/PostReceiveWorkflow.d.ts.map +0 -1
- package/dist/server/workflows/post-receive/PostReceiveWorkflow.js +0 -189
- package/dist/server/workflows/post-receive/PostReceiveWorkflow.js.map +0 -1
- package/src/server/workflows/post-receive/PostReceiveWorkflow.ts +0 -216
package/package.json
CHANGED
|
@@ -28,6 +28,7 @@ import ScopeVars from "../../../common/ScopeVars.js";
|
|
|
28
28
|
import type MailboxContactEvent from "./MailboxContactEvent.js";
|
|
29
29
|
import type WebHook from "./WebHook.js";
|
|
30
30
|
import CheckConstraint from "@entity-access/entity-access/dist/decorators/CheckConstraint.js";
|
|
31
|
+
import { subscriptionType, subscriptionTypes } from "./SubscriptionType.js";
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* MailBox ID is number because foreign key on Email will
|
|
@@ -187,6 +188,9 @@ export default class Mailbox {
|
|
|
187
188
|
@Column({ dataType: "Int", default: () => 0 })
|
|
188
189
|
public subscriberCount: number;
|
|
189
190
|
|
|
191
|
+
@Column({ dataType: "AsciiChar", length: 20, nullable: true, enum: subscriptionTypes})
|
|
192
|
+
public subscriptionType: subscriptionType;
|
|
193
|
+
|
|
190
194
|
/**
|
|
191
195
|
* Date of recent email published on channel either on private or public
|
|
192
196
|
*/
|
|
@@ -13,6 +13,7 @@ import type MailboxContactTag from "./MailboxContactTag.js";
|
|
|
13
13
|
import type MailboxContactEmail from "./MailboxContactEmail.js";
|
|
14
14
|
import type MailboxContactEvent from "./MailboxContactEvent.js";
|
|
15
15
|
import type WebHook from "./WebHook.js";
|
|
16
|
+
import { subscriptionType, subscriptionTypes } from "./SubscriptionType.js";
|
|
16
17
|
|
|
17
18
|
export const subscriberStatus = ["invited", "added", "active", "unsubscribed", "blocked"] as const;
|
|
18
19
|
export type subscriberStatusType = typeof subscriberStatus[number];
|
|
@@ -151,6 +152,14 @@ export default class MailboxContact {
|
|
|
151
152
|
})
|
|
152
153
|
public status: subscriberStatusType;
|
|
153
154
|
|
|
155
|
+
@Column({
|
|
156
|
+
dataType: "AsciiChar",
|
|
157
|
+
length: 10,
|
|
158
|
+
nullable: true,
|
|
159
|
+
enum: subscriptionTypes
|
|
160
|
+
})
|
|
161
|
+
public subscriptionType: subscriptionType;
|
|
162
|
+
|
|
154
163
|
public mailbox: Mailbox;
|
|
155
164
|
|
|
156
165
|
public emailAddress: EmailAddress;
|
|
@@ -201,7 +201,11 @@ export default class BroadcastEmail extends Workflow<IBroadcastEmail> {
|
|
|
201
201
|
return db.mailboxContacts.where(this.input, (p) => (x) => x.mailboxID === p.mailboxID
|
|
202
202
|
&& x.emailAddressID !== p.mailboxID
|
|
203
203
|
&& !x.emailAddress.subscriberActivities.some((sa) => sa.emailID === p.emailID)
|
|
204
|
-
&& x.status === "active"
|
|
204
|
+
&& x.status === "active"
|
|
205
|
+
&& (x.subscriptionType === null
|
|
206
|
+
|| x.subscriptionType === "all"
|
|
207
|
+
|| x.mailbox.emails.some((ce) => ce.email.thread.threadParticipants.some((tp) => tp.emailAddressID === x.emailAddressID)) )
|
|
208
|
+
)
|
|
205
209
|
.include((x) => x.emailAddress);
|
|
206
210
|
}
|
|
207
211
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PostReceiveWorkflow.d.ts","sourceRoot":"","sources":["../../../../src/server/workflows/post-receive/PostReceiveWorkflow.ts"],"names":[],"mappings":""}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
// import Workflow, { UniqueActivity } from "@entity-access/entity-access/dist/workflows/Workflow.js";
|
|
2
|
-
// import Inject, { ServiceProvider } from "@entity-access/entity-access/dist/di/di.js";
|
|
3
|
-
// import SocialMailContext from "../../model/SocialMailContext.js";
|
|
4
|
-
// import EmailAddressService from "../../services/EmailAddressService.js";
|
|
5
|
-
// import BroadcastEmail from "../channel/BroadcastEmail.js";
|
|
6
|
-
// import ChannelService from "../../smtp/services/ChannelService.js";
|
|
7
|
-
// import Sql from "@entity-access/entity-access/dist/sql/Sql.js";
|
|
8
|
-
// import SendWebPushNotification from "../web-push/SendWebPushNotification.js";
|
|
9
|
-
// import EntityContext from "@entity-access/entity-access/dist/model/EntityContext.js";
|
|
10
|
-
// import DateTime from "@entity-access/entity-access/dist/types/DateTime.js";
|
|
11
|
-
// import WorkflowContext from "@entity-access/entity-access/dist/workflows/WorkflowContext.js";
|
|
12
|
-
// import { Base36 } from "../../../common/Base36.js";
|
|
13
|
-
// import MailboxNamespace from "../../services/socket/rooms/MailboxNamespace.js";
|
|
14
|
-
// import TempFileService from "../../storage/TempFileService.js";
|
|
15
|
-
export {};
|
|
16
|
-
// import Calendar from "@social-mail/shared/dist/ical-parser/Calender.js";
|
|
17
|
-
// import { AppStringHelper } from "../../../common/AppStringHelper.js";
|
|
18
|
-
// import { EmojiDateParser } from "./EmojiDateParser.js";
|
|
19
|
-
// import CachedEmailService from "../../smtp/services/CachedEmailService.js";
|
|
20
|
-
// import QueueInvokeWebHookWorkflow from "../web-hooks/QueueInvokeWebHookWorkflow.js";
|
|
21
|
-
// export interface IPostReceiveWorkflowArgs { senderID: number, recipientID: number, emailID: number, sent: boolean}
|
|
22
|
-
// export default class PostReceiveWorkflow extends Workflow<IPostReceiveWorkflowArgs> {
|
|
23
|
-
// static taskGroup = "notify";
|
|
24
|
-
// public static queue(context: WorkflowContext, args: IPostReceiveWorkflowArgs, eta: DateTime = DateTime.now) {
|
|
25
|
-
// const { senderID, emailID, recipientID } = args;
|
|
26
|
-
// return context.queue(PostReceiveWorkflow, args, {
|
|
27
|
-
// id: `received-${Base36.encode(senderID)}-${Base36.encode(recipientID)}-${Base36.encode(emailID)}`,
|
|
28
|
-
// eta
|
|
29
|
-
// });
|
|
30
|
-
// }
|
|
31
|
-
// async run() {
|
|
32
|
-
// await this.dispatchChannel();
|
|
33
|
-
// await this.queueWebHooks();
|
|
34
|
-
// }
|
|
35
|
-
// @UniqueActivity
|
|
36
|
-
// async queueWebHooks(
|
|
37
|
-
// @Inject db?: SocialMailContext
|
|
38
|
-
// ) {
|
|
39
|
-
// const { senderID: mailboxID, recipientID: emailAddressID, emailID } = this.input;
|
|
40
|
-
// let hasWebHook = await db.webHooks.where({ mailboxID }, (p) => (x) => x.mailboxID === p.mailboxID && x.emailAddressID === null)
|
|
41
|
-
// .some();
|
|
42
|
-
// if(hasWebHook) {
|
|
43
|
-
// await QueueInvokeWebHookWorkflow.queue(this.context, {
|
|
44
|
-
// type: "email-received",
|
|
45
|
-
// mailboxID, input: {
|
|
46
|
-
// mailboxID,
|
|
47
|
-
// emailAddressID,
|
|
48
|
-
// emailID
|
|
49
|
-
// } });
|
|
50
|
-
// }
|
|
51
|
-
// hasWebHook = await db.webHooks.where({ mailboxID, emailAddressID }, (p) => (x) =>
|
|
52
|
-
// x.mailboxID === p.mailboxID
|
|
53
|
-
// && x.emailAddressID === p.emailAddressID)
|
|
54
|
-
// .some();
|
|
55
|
-
// if(hasWebHook) {
|
|
56
|
-
// await QueueInvokeWebHookWorkflow.queue(this.context, {
|
|
57
|
-
// type: "email-received",
|
|
58
|
-
// emailAddressID,
|
|
59
|
-
// mailboxID, input: {
|
|
60
|
-
// mailboxID,
|
|
61
|
-
// emailAddressID,
|
|
62
|
-
// emailID
|
|
63
|
-
// } });
|
|
64
|
-
// }
|
|
65
|
-
// }
|
|
66
|
-
// @UniqueActivity
|
|
67
|
-
// async dispatchChannel(
|
|
68
|
-
// @Inject db?: SocialMailContext,
|
|
69
|
-
// @Inject eas?: EmailAddressService,
|
|
70
|
-
// @Inject tfs?: TempFileService,
|
|
71
|
-
// @Inject channelService?: ChannelService,
|
|
72
|
-
// @Inject ces?: CachedEmailService
|
|
73
|
-
// ) {
|
|
74
|
-
// const { senderID, emailID, recipientID } = this.input;
|
|
75
|
-
// // check if it is not an engagement and can send an email
|
|
76
|
-
// const ne = await db.mailboxContactEmails.where(this.input, (p) =>
|
|
77
|
-
// (x) => x.emailID === p.emailID
|
|
78
|
-
// && x.mailboxID === p.recipientID
|
|
79
|
-
// && x.emailAddressID === p.senderID
|
|
80
|
-
// && x.email.status !== "published")
|
|
81
|
-
// .first();
|
|
82
|
-
// if (!ne) {
|
|
83
|
-
// return;
|
|
84
|
-
// }
|
|
85
|
-
// const isHostedChannelID = await eas.isHostedChannelID(recipientID);
|
|
86
|
-
// if (ne.engagement) {
|
|
87
|
-
// await db.mailboxes.where(this.input, (p) => (x) => x.mailboxID === p.recipientID)
|
|
88
|
-
// .update(void 0, (p) => (x) => ({
|
|
89
|
-
// dateEngaged: Sql.date.now()
|
|
90
|
-
// }));
|
|
91
|
-
// switch(ne.engagement) {
|
|
92
|
-
// case "✅":
|
|
93
|
-
// if (isHostedChannelID) {
|
|
94
|
-
// return await channelService.approveSubscriber(emailID);
|
|
95
|
-
// }
|
|
96
|
-
// return;
|
|
97
|
-
// case "🔔":
|
|
98
|
-
// case "🔕":
|
|
99
|
-
// case "❌":
|
|
100
|
-
// case "📈":
|
|
101
|
-
// return;
|
|
102
|
-
// case "➕":
|
|
103
|
-
// if (isHostedChannelID) {
|
|
104
|
-
// await BroadcastEmail.broadcast(this.context, {
|
|
105
|
-
// mailboxID: recipientID,
|
|
106
|
-
// emailID,
|
|
107
|
-
// senderID,
|
|
108
|
-
// subscribe: true
|
|
109
|
-
// });
|
|
110
|
-
// }
|
|
111
|
-
// return;
|
|
112
|
-
// case "💬":
|
|
113
|
-
// // following will make comment appear publicly
|
|
114
|
-
// // todo: moderation...
|
|
115
|
-
// await db.emails.where(this.input, (p) => (x) => x.emailID === p.emailID
|
|
116
|
-
// && x.parent.status === "published"
|
|
117
|
-
// )
|
|
118
|
-
// .update(void 0, (p) => (x) => ({ status: "published" }));
|
|
119
|
-
// return;
|
|
120
|
-
// default:
|
|
121
|
-
// return;
|
|
122
|
-
// }
|
|
123
|
-
// }
|
|
124
|
-
// const mc = await db.mailboxContacts.where(this.input, (p) =>
|
|
125
|
-
// (x) => x.mailboxID === p.recipientID
|
|
126
|
-
// && x.emailAddressID === p.senderID)
|
|
127
|
-
// .first();
|
|
128
|
-
// if(!isHostedChannelID) {
|
|
129
|
-
// // send push notification here...
|
|
130
|
-
// if (mc?.blocked) {
|
|
131
|
-
// return;
|
|
132
|
-
// }
|
|
133
|
-
// const mn = ServiceProvider.resolve(this, MailboxNamespace);
|
|
134
|
-
// mn.newMail(this.input.recipientID, this.input.senderID, this.input.emailID);
|
|
135
|
-
// // verify if anyone is listening...
|
|
136
|
-
// const hasSubscriptions = await db.userPushSubscriptions.where(this.input, (p) => (x) => x.mailboxID === p.recipientID).some();
|
|
137
|
-
// if (hasSubscriptions) {
|
|
138
|
-
// const id = `send-push-${this.input.emailID}-${this.input.recipientID}`;
|
|
139
|
-
// await this.context.queue(SendWebPushNotification, ne, { id, throwIfExists: false });
|
|
140
|
-
// }
|
|
141
|
-
// return;
|
|
142
|
-
// }
|
|
143
|
-
// // can send...
|
|
144
|
-
// if (!mc || !(mc.canContribute || mc.isOwner)) {
|
|
145
|
-
// return;
|
|
146
|
-
// }
|
|
147
|
-
// // Has event attachment?
|
|
148
|
-
// const calendarAttachments = await db.appFiles.where(this.input, (p) => (x) => x.emailID === p.emailID && x.contentType === "text/calendar")
|
|
149
|
-
// .include((x) => x.fileContent)
|
|
150
|
-
// .toArray();
|
|
151
|
-
// for (const file of calendarAttachments) {
|
|
152
|
-
// const localFile = await tfs.downloadAppFile(file);
|
|
153
|
-
// const events = await Calendar.parse(await localFile.readAsText());
|
|
154
|
-
// for (const e of events.events) {
|
|
155
|
-
// await db.mailboxContactEvents.statements.insert({
|
|
156
|
-
// mailboxID: recipientID,
|
|
157
|
-
// emailAddressID: senderID,
|
|
158
|
-
// emailID,
|
|
159
|
-
// startDate: e.startDate,
|
|
160
|
-
// endDate: e.endDate,
|
|
161
|
-
// title: AppStringHelper.left(e.summary, 200),
|
|
162
|
-
// location: AppStringHelper.left(e.location, 400)
|
|
163
|
-
// });
|
|
164
|
-
// }
|
|
165
|
-
// }
|
|
166
|
-
// const { textBody, subject } = await ces.get(emailID);
|
|
167
|
-
// const calendarDate = EmojiDateParser.parse(textBody);
|
|
168
|
-
// if (calendarDate) {
|
|
169
|
-
// const { date, location } = calendarDate;
|
|
170
|
-
// if (date) {
|
|
171
|
-
// await db.mailboxContactEvents.statements.insert({
|
|
172
|
-
// mailboxID: recipientID,
|
|
173
|
-
// emailAddressID: senderID,
|
|
174
|
-
// emailID,
|
|
175
|
-
// startDate: date,
|
|
176
|
-
// endDate: date,
|
|
177
|
-
// title: AppStringHelper.left(subject, 200),
|
|
178
|
-
// location: location ? AppStringHelper.left(location, 400) : void 0
|
|
179
|
-
// });
|
|
180
|
-
// }
|
|
181
|
-
// }
|
|
182
|
-
// await BroadcastEmail.broadcast(this.context, {
|
|
183
|
-
// mailboxID: recipientID,
|
|
184
|
-
// emailID,
|
|
185
|
-
// senderID
|
|
186
|
-
// });
|
|
187
|
-
// }
|
|
188
|
-
// }
|
|
189
|
-
//# sourceMappingURL=PostReceiveWorkflow.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PostReceiveWorkflow.js","sourceRoot":"","sources":["../../../../src/server/workflows/post-receive/PostReceiveWorkflow.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
// import Workflow, { UniqueActivity } from "@entity-access/entity-access/dist/workflows/Workflow.js";
|
|
2
|
-
// import Inject, { ServiceProvider } from "@entity-access/entity-access/dist/di/di.js";
|
|
3
|
-
// import SocialMailContext from "../../model/SocialMailContext.js";
|
|
4
|
-
// import EmailAddressService from "../../services/EmailAddressService.js";
|
|
5
|
-
// import BroadcastEmail from "../channel/BroadcastEmail.js";
|
|
6
|
-
// import ChannelService from "../../smtp/services/ChannelService.js";
|
|
7
|
-
// import Sql from "@entity-access/entity-access/dist/sql/Sql.js";
|
|
8
|
-
// import SendWebPushNotification from "../web-push/SendWebPushNotification.js";
|
|
9
|
-
// import EntityContext from "@entity-access/entity-access/dist/model/EntityContext.js";
|
|
10
|
-
// import DateTime from "@entity-access/entity-access/dist/types/DateTime.js";
|
|
11
|
-
// import WorkflowContext from "@entity-access/entity-access/dist/workflows/WorkflowContext.js";
|
|
12
|
-
// import { Base36 } from "../../../common/Base36.js";
|
|
13
|
-
// import MailboxNamespace from "../../services/socket/rooms/MailboxNamespace.js";
|
|
14
|
-
// import TempFileService from "../../storage/TempFileService.js";
|
|
15
|
-
|
|
16
|
-
// import Calendar from "@social-mail/shared/dist/ical-parser/Calender.js";
|
|
17
|
-
// import { AppStringHelper } from "../../../common/AppStringHelper.js";
|
|
18
|
-
// import { EmojiDateParser } from "./EmojiDateParser.js";
|
|
19
|
-
// import CachedEmailService from "../../smtp/services/CachedEmailService.js";
|
|
20
|
-
// import QueueInvokeWebHookWorkflow from "../web-hooks/QueueInvokeWebHookWorkflow.js";
|
|
21
|
-
|
|
22
|
-
// export interface IPostReceiveWorkflowArgs { senderID: number, recipientID: number, emailID: number, sent: boolean}
|
|
23
|
-
// export default class PostReceiveWorkflow extends Workflow<IPostReceiveWorkflowArgs> {
|
|
24
|
-
|
|
25
|
-
// static taskGroup = "notify";
|
|
26
|
-
|
|
27
|
-
// public static queue(context: WorkflowContext, args: IPostReceiveWorkflowArgs, eta: DateTime = DateTime.now) {
|
|
28
|
-
// const { senderID, emailID, recipientID } = args;
|
|
29
|
-
// return context.queue(PostReceiveWorkflow, args, {
|
|
30
|
-
// id: `received-${Base36.encode(senderID)}-${Base36.encode(recipientID)}-${Base36.encode(emailID)}`,
|
|
31
|
-
// eta
|
|
32
|
-
// });
|
|
33
|
-
// }
|
|
34
|
-
|
|
35
|
-
// async run() {
|
|
36
|
-
// await this.dispatchChannel();
|
|
37
|
-
// await this.queueWebHooks();
|
|
38
|
-
// }
|
|
39
|
-
|
|
40
|
-
// @UniqueActivity
|
|
41
|
-
// async queueWebHooks(
|
|
42
|
-
// @Inject db?: SocialMailContext
|
|
43
|
-
// ) {
|
|
44
|
-
// const { senderID: mailboxID, recipientID: emailAddressID, emailID } = this.input;
|
|
45
|
-
|
|
46
|
-
// let hasWebHook = await db.webHooks.where({ mailboxID }, (p) => (x) => x.mailboxID === p.mailboxID && x.emailAddressID === null)
|
|
47
|
-
// .some();
|
|
48
|
-
// if(hasWebHook) {
|
|
49
|
-
// await QueueInvokeWebHookWorkflow.queue(this.context, {
|
|
50
|
-
// type: "email-received",
|
|
51
|
-
// mailboxID, input: {
|
|
52
|
-
// mailboxID,
|
|
53
|
-
// emailAddressID,
|
|
54
|
-
// emailID
|
|
55
|
-
// } });
|
|
56
|
-
// }
|
|
57
|
-
|
|
58
|
-
// hasWebHook = await db.webHooks.where({ mailboxID, emailAddressID }, (p) => (x) =>
|
|
59
|
-
// x.mailboxID === p.mailboxID
|
|
60
|
-
// && x.emailAddressID === p.emailAddressID)
|
|
61
|
-
// .some();
|
|
62
|
-
|
|
63
|
-
// if(hasWebHook) {
|
|
64
|
-
// await QueueInvokeWebHookWorkflow.queue(this.context, {
|
|
65
|
-
// type: "email-received",
|
|
66
|
-
// emailAddressID,
|
|
67
|
-
// mailboxID, input: {
|
|
68
|
-
// mailboxID,
|
|
69
|
-
// emailAddressID,
|
|
70
|
-
// emailID
|
|
71
|
-
// } });
|
|
72
|
-
// }
|
|
73
|
-
// }
|
|
74
|
-
|
|
75
|
-
// @UniqueActivity
|
|
76
|
-
// async dispatchChannel(
|
|
77
|
-
// @Inject db?: SocialMailContext,
|
|
78
|
-
// @Inject eas?: EmailAddressService,
|
|
79
|
-
// @Inject tfs?: TempFileService,
|
|
80
|
-
// @Inject channelService?: ChannelService,
|
|
81
|
-
// @Inject ces?: CachedEmailService
|
|
82
|
-
// ) {
|
|
83
|
-
// const { senderID, emailID, recipientID } = this.input;
|
|
84
|
-
|
|
85
|
-
// // check if it is not an engagement and can send an email
|
|
86
|
-
// const ne = await db.mailboxContactEmails.where(this.input, (p) =>
|
|
87
|
-
// (x) => x.emailID === p.emailID
|
|
88
|
-
// && x.mailboxID === p.recipientID
|
|
89
|
-
// && x.emailAddressID === p.senderID
|
|
90
|
-
// && x.email.status !== "published")
|
|
91
|
-
// .first();
|
|
92
|
-
|
|
93
|
-
// if (!ne) {
|
|
94
|
-
// return;
|
|
95
|
-
// }
|
|
96
|
-
|
|
97
|
-
// const isHostedChannelID = await eas.isHostedChannelID(recipientID);
|
|
98
|
-
|
|
99
|
-
// if (ne.engagement) {
|
|
100
|
-
|
|
101
|
-
// await db.mailboxes.where(this.input, (p) => (x) => x.mailboxID === p.recipientID)
|
|
102
|
-
// .update(void 0, (p) => (x) => ({
|
|
103
|
-
// dateEngaged: Sql.date.now()
|
|
104
|
-
// }));
|
|
105
|
-
|
|
106
|
-
// switch(ne.engagement) {
|
|
107
|
-
// case "✅":
|
|
108
|
-
// if (isHostedChannelID) {
|
|
109
|
-
// return await channelService.approveSubscriber(emailID);
|
|
110
|
-
// }
|
|
111
|
-
// return;
|
|
112
|
-
// case "🔔":
|
|
113
|
-
// case "🔕":
|
|
114
|
-
// case "❌":
|
|
115
|
-
// case "📈":
|
|
116
|
-
// return;
|
|
117
|
-
// case "➕":
|
|
118
|
-
// if (isHostedChannelID) {
|
|
119
|
-
// await BroadcastEmail.broadcast(this.context, {
|
|
120
|
-
// mailboxID: recipientID,
|
|
121
|
-
// emailID,
|
|
122
|
-
// senderID,
|
|
123
|
-
// subscribe: true
|
|
124
|
-
// });
|
|
125
|
-
// }
|
|
126
|
-
// return;
|
|
127
|
-
// case "💬":
|
|
128
|
-
// // following will make comment appear publicly
|
|
129
|
-
// // todo: moderation...
|
|
130
|
-
// await db.emails.where(this.input, (p) => (x) => x.emailID === p.emailID
|
|
131
|
-
// && x.parent.status === "published"
|
|
132
|
-
// )
|
|
133
|
-
// .update(void 0, (p) => (x) => ({ status: "published" }));
|
|
134
|
-
// return;
|
|
135
|
-
// default:
|
|
136
|
-
// return;
|
|
137
|
-
// }
|
|
138
|
-
// }
|
|
139
|
-
|
|
140
|
-
// const mc = await db.mailboxContacts.where(this.input, (p) =>
|
|
141
|
-
// (x) => x.mailboxID === p.recipientID
|
|
142
|
-
// && x.emailAddressID === p.senderID)
|
|
143
|
-
// .first();
|
|
144
|
-
|
|
145
|
-
// if(!isHostedChannelID) {
|
|
146
|
-
|
|
147
|
-
// // send push notification here...
|
|
148
|
-
// if (mc?.blocked) {
|
|
149
|
-
// return;
|
|
150
|
-
// }
|
|
151
|
-
|
|
152
|
-
// const mn = ServiceProvider.resolve(this, MailboxNamespace);
|
|
153
|
-
// mn.newMail(this.input.recipientID, this.input.senderID, this.input.emailID);
|
|
154
|
-
|
|
155
|
-
// // verify if anyone is listening...
|
|
156
|
-
// const hasSubscriptions = await db.userPushSubscriptions.where(this.input, (p) => (x) => x.mailboxID === p.recipientID).some();
|
|
157
|
-
// if (hasSubscriptions) {
|
|
158
|
-
// const id = `send-push-${this.input.emailID}-${this.input.recipientID}`;
|
|
159
|
-
// await this.context.queue(SendWebPushNotification, ne, { id, throwIfExists: false });
|
|
160
|
-
// }
|
|
161
|
-
// return;
|
|
162
|
-
// }
|
|
163
|
-
|
|
164
|
-
// // can send...
|
|
165
|
-
// if (!mc || !(mc.canContribute || mc.isOwner)) {
|
|
166
|
-
// return;
|
|
167
|
-
// }
|
|
168
|
-
|
|
169
|
-
// // Has event attachment?
|
|
170
|
-
// const calendarAttachments = await db.appFiles.where(this.input, (p) => (x) => x.emailID === p.emailID && x.contentType === "text/calendar")
|
|
171
|
-
// .include((x) => x.fileContent)
|
|
172
|
-
// .toArray();
|
|
173
|
-
|
|
174
|
-
// for (const file of calendarAttachments) {
|
|
175
|
-
// const localFile = await tfs.downloadAppFile(file);
|
|
176
|
-
|
|
177
|
-
// const events = await Calendar.parse(await localFile.readAsText());
|
|
178
|
-
// for (const e of events.events) {
|
|
179
|
-
// await db.mailboxContactEvents.statements.insert({
|
|
180
|
-
// mailboxID: recipientID,
|
|
181
|
-
// emailAddressID: senderID,
|
|
182
|
-
// emailID,
|
|
183
|
-
// startDate: e.startDate,
|
|
184
|
-
// endDate: e.endDate,
|
|
185
|
-
// title: AppStringHelper.left(e.summary, 200),
|
|
186
|
-
// location: AppStringHelper.left(e.location, 400)
|
|
187
|
-
// });
|
|
188
|
-
// }
|
|
189
|
-
// }
|
|
190
|
-
|
|
191
|
-
// const { textBody, subject } = await ces.get(emailID);
|
|
192
|
-
|
|
193
|
-
// const calendarDate = EmojiDateParser.parse(textBody);
|
|
194
|
-
// if (calendarDate) {
|
|
195
|
-
// const { date, location } = calendarDate;
|
|
196
|
-
// if (date) {
|
|
197
|
-
// await db.mailboxContactEvents.statements.insert({
|
|
198
|
-
// mailboxID: recipientID,
|
|
199
|
-
// emailAddressID: senderID,
|
|
200
|
-
// emailID,
|
|
201
|
-
// startDate: date,
|
|
202
|
-
// endDate: date,
|
|
203
|
-
// title: AppStringHelper.left(subject, 200),
|
|
204
|
-
// location: location ? AppStringHelper.left(location, 400) : void 0
|
|
205
|
-
// });
|
|
206
|
-
// }
|
|
207
|
-
// }
|
|
208
|
-
|
|
209
|
-
// await BroadcastEmail.broadcast(this.context, {
|
|
210
|
-
// mailboxID: recipientID,
|
|
211
|
-
// emailID,
|
|
212
|
-
// senderID
|
|
213
|
-
// });
|
|
214
|
-
// }
|
|
215
|
-
|
|
216
|
-
// }
|