2017-09-27 02:42:18 +08:00
|
|
|
import { Rx, Message, DatabaseStore } from 'mailspring-exports';
|
2017-11-09 04:15:24 +08:00
|
|
|
import { OPEN_TRACKING_ID, LINK_TRACKING_ID } from './plugin-helpers';
|
2017-09-07 07:19:48 +08:00
|
|
|
|
|
|
|
export default class ActivityDataSource {
|
2017-11-09 04:15:24 +08:00
|
|
|
buildObservable({ messageLimit }) {
|
2017-09-27 02:33:08 +08:00
|
|
|
const query = DatabaseStore.findAll(Message)
|
2017-09-07 07:19:48 +08:00
|
|
|
.order(Message.attributes.date.descending())
|
2017-11-09 04:15:24 +08:00
|
|
|
.where(Message.attributes.pluginMetadata.contains(OPEN_TRACKING_ID, LINK_TRACKING_ID))
|
2017-09-07 07:19:48 +08:00
|
|
|
.limit(messageLimit);
|
|
|
|
this.observable = Rx.Observable.fromQuery(query);
|
|
|
|
return this.observable;
|
|
|
|
}
|
|
|
|
|
|
|
|
subscribe(callback) {
|
|
|
|
return this.observable.subscribe(callback);
|
|
|
|
}
|
|
|
|
}
|