Skip to content

Commit 065f312

Browse files
committed
Updating sources to timestamp-based
1 parent 75af305 commit 065f312

File tree

4 files changed

+33
-88
lines changed

4 files changed

+33
-88
lines changed

components/frontapp/sources/common/base.mjs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
_setLastTs(lastTs) {
2020
this.db.set("lastTs", lastTs);
2121
},
22-
async startEvent(maxResults = 0) {
22+
async startEvent(maxResults = 0, filterFn = null) {
2323
const lastTs = this._getLastTs();
2424
const items = this.frontapp.paginate({
2525
fn: this._getFunction(),
@@ -30,10 +30,18 @@ export default {
3030
let responseArray = [];
3131

3232
for await (const item of items) {
33-
responseArray.push(item);
33+
// If filterFn is provided, use it to filter items, otherwise add all items
34+
if (!filterFn || filterFn(item, lastTs)) {
35+
responseArray.push(item);
36+
}
3437
}
3538

36-
if (responseArray.length) this._setLastTs(responseArray[0].emitted_at);
39+
if (responseArray.length) {
40+
if (filterFn) {
41+
responseArray.sort((a, b) => b.created_at - a.created_at);
42+
}
43+
this._setLastTs(responseArray[0].emitted_at);
44+
}
3745

3846
for (const item of responseArray.reverse()) {
3947
this.$emit(

components/frontapp/sources/common/polling-ids.mjs

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import common from "../common/polling-ids.mjs";
1+
import common from "../common/base.mjs";
22
import sampleEmit from "./test-event.mjs";
33

44
export default {
@@ -11,26 +11,22 @@ export default {
1111
dedupe: "unique",
1212
methods: {
1313
...common.methods,
14-
generateMeta(conversation) {
14+
_getFunction() {
15+
return this.frontapp.listConversations;
16+
},
17+
_getParams() {
18+
return {
19+
sort_by: "date",
20+
sort_order: "desc",
21+
};
22+
},
23+
_getEmit(conversation) {
1524
return {
1625
id: conversation.id,
1726
summary: `New conversation created: ${conversation.subject}`,
1827
ts: conversation.created_at * 1000,
1928
};
2029
},
21-
getItemId(conversation) {
22-
return conversation.id;
23-
},
24-
async getItems() {
25-
const response = await this.frontapp.listConversations({
26-
params: {
27-
sort_by: "date",
28-
sort_order: "desc",
29-
},
30-
});
31-
32-
return response._results || [];
33-
},
3430
},
3531
sampleEmit,
3632
};
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import common from "../common/polling-ids.mjs";
1+
import common from "../common/base.mjs";
22
import sampleEmit from "./test-event.mjs";
33

44
export default {
@@ -11,26 +11,22 @@ export default {
1111
dedupe: "unique",
1212
methods: {
1313
...common.methods,
14-
generateMeta(template) {
14+
_getFunction() {
15+
return this.frontapp.listMessageTemplates;
16+
},
17+
_getParams() {
18+
return {
19+
sort_by: "created_at",
20+
sort_order: "desc",
21+
};
22+
},
23+
_getEmit(template) {
1524
return {
1625
id: template.id,
1726
summary: `New message template created: ${template.name}`,
1827
ts: template.created_at * 1000,
1928
};
2029
},
21-
getItemId(template) {
22-
return template.id;
23-
},
24-
async getItems() {
25-
const response = await this.frontapp.listMessageTemplates({
26-
params: {
27-
sort_by: "created_at",
28-
sort_order: "desc",
29-
},
30-
});
31-
32-
return response._results || [];
33-
},
3430
},
3531
sampleEmit,
3632
};

0 commit comments

Comments
 (0)