forked from pydio/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dao.go
102 lines (84 loc) · 3.42 KB
/
dao.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright (c) 2018. Abstrium SAS <team (at) pydio.com>
* This file is part of Pydio Cells.
*
* Pydio Cells is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio Cells is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio Cells. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com>.
*/
// Package activity stores and distributes events to users in a social-feed manner.
//
// It is composed of two services, one GRPC for persistence layer and one REST for logic.
// Persistence is currently only implemented using a BoltDB store.
package activity
import (
"context"
"time"
"github.com/pydio/cells/common/boltdb"
"github.com/pydio/cells/common/dao"
"github.com/pydio/cells/common/proto/activity"
)
var testEnv bool
type BoxName string
const (
BoxInbox BoxName = "inbox"
BoxOutbox BoxName = "outbox"
BoxSubscriptions BoxName = "subscriptions"
BoxLastRead BoxName = "lastread"
BoxLastSent BoxName = "lastsent"
)
type DAO interface {
dao.DAO
// Post an activity to target inbox
PostActivity(ownerType activity.OwnerType, ownerId string, boxName BoxName, object *activity.Object, publishCtx context.Context) error
// Update Subscription status
UpdateSubscription(subscription *activity.Subscription) error
// List subscriptions on a given object
// Returns a map of userId => status (true/false, required to disable default subscriptions like workspaces)
ListSubscriptions(objectType activity.OwnerType, objectIds []string) ([]*activity.Subscription, error)
// Count the number of unread activities in user "Inbox" box
CountUnreadForUser(userId string) int
// Load activities for a given owner. Targets "outbox" by default
ActivitiesFor(ownerType activity.OwnerType, ownerId string, boxName BoxName, refBoxOffset BoxName, reverseOffset int64, limit int64, result chan *activity.Object, done chan bool) error
// Store the last read uint ID for a given box
StoreLastUserInbox(userId string, boxName BoxName, last []byte, activityId string) error
// Should be wired to "USER_DELETE" and "NODE_DELETE" events
// to remove (or archive?) deprecated queues
Delete(ownerType activity.OwnerType, ownerId string) error
// Purge removes records based on a maximum number of records and/or based on the activity update date
// It keeps at least minCount record(s) - to see last activity - even if older than expected date
Purge(logger func(string), ownerType activity.OwnerType, ownerId string, boxName BoxName, minCount, maxCount int, updatedBefore time.Time, clearBackup bool) error
}
type batchActivity struct {
*activity.Object
ownerType activity.OwnerType
ownerId string
boxName BoxName
publishCtx context.Context
}
type batchDAO interface {
BatchPost([]*batchActivity) error
}
func NewDAO(o dao.DAO) dao.DAO {
switch v := o.(type) {
case boltdb.DAO:
bi := &boltdbimpl{DAO: v, InboxMaxSize: 1000}
if testEnv {
return bi
} else {
return WithCache(bi)
}
}
return nil
}