Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Feat/mentions feed (#1689)
Browse files Browse the repository at this point in the history
* mentions proto definition

* wip(daemon): initial mentions filtering

* wip(daemon): include full mentions

* fix(daemon): remove duplicated mentions.
  • Loading branch information
juligasa authored Apr 9, 2024
1 parent cd3f34f commit 2bacc25
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 15 deletions.
35 changes: 28 additions & 7 deletions backend/daemon/api/activity/v1alpha/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,32 @@ func (srv *Server) ListEvents(ctx context.Context, req *activity.ListEventsReque
}
filtersStr += ") AND "
}
var linksStr string
if len(req.AddLinkedResource) > 0 {
if len(req.FilterResource) > 0 || len(req.FilterEventType) > 0 {
linksStr += " OR "
}
linksStr += "(" + storage.StructuralBlobsType.String() + " in ('Change', 'Comment') AND " + storage.ResourceLinksTarget.String() + " IN (" +
"select " + storage.ResourcesID.String() + " FROM " + storage.T_Resources + " where " + storage.ResourcesIRI.String() + " in ("
for i, resource := range req.AddLinkedResource {
if !resourcePattern.MatchString(resource) {
return nil, fmt.Errorf("Invalid link resource format [%s]", resource)
}
if i > 0 {
linksStr += ", "
}
linksStr += "'" + resource + "'"
}
linksStr += "))) AND "
}
var (
selectStr = "SELECT " + storage.BlobsID + ", " + storage.StructuralBlobsType + ", " + storage.PublicKeysPrincipal + ", " + storage.ResourcesIRI + ", " + storage.StructuralBlobsTs + ", " + storage.BlobsInsertTime + ", " + storage.BlobsMultihash + ", " + storage.BlobsCodec
tableStr = "FROM " + storage.T_StructuralBlobs
joinIDStr = "JOIN " + storage.Blobs.String() + " ON " + storage.BlobsID.String() + "=" + storage.StructuralBlobsID.String()
joinpkStr = "JOIN " + storage.PublicKeys.String() + " ON " + storage.StructuralBlobsAuthor.String() + "=" + storage.PublicKeysID.String()
leftjoinStr = "LEFT JOIN " + storage.Resources.String() + " ON " + storage.StructuralBlobsResource.String() + "=" + storage.ResourcesID.String()
selectStr = "SELECT distinct " + storage.BlobsID + ", " + storage.StructuralBlobsType + ", " + storage.PublicKeysPrincipal + ", " + storage.ResourcesIRI + ", " + storage.StructuralBlobsTs + ", " + storage.BlobsInsertTime + ", " + storage.BlobsMultihash + ", " + storage.BlobsCodec
tableStr = "FROM " + storage.T_StructuralBlobs
joinIDStr = "JOIN " + storage.Blobs.String() + " ON " + storage.BlobsID.String() + "=" + storage.StructuralBlobsID.String()
joinpkStr = "JOIN " + storage.PublicKeys.String() + " ON " + storage.StructuralBlobsAuthor.String() + "=" + storage.PublicKeysID.String()
joinLinksStr = "JOIN " + storage.ResourceLinks.String() + " ON " + storage.StructuralBlobsID.String() + "=" + storage.ResourceLinksSource.String()
leftjoinResourcesStr = "LEFT JOIN " + storage.Resources.String() + " ON " + storage.StructuralBlobsResource.String() + "=" + storage.ResourcesID.String()

pageTokenStr = storage.BlobsID.String() + " <= :idx AND (" + storage.ResourcesIRI.String() + " NOT IN (SELECT " + storage.DraftsViewResource.String() + " from " + storage.DraftsView.String() + ") OR " + storage.ResourcesIRI.String() + " IS NULL) ORDER BY " + storage.BlobsID.String() + " desc limit :page_size"
)

Expand All @@ -143,8 +163,9 @@ func (srv *Server) ListEvents(ctx context.Context, req *activity.ListEventsReque
%s
%s
%s
WHERE %s %s;
`, selectStr, tableStr, joinIDStr, joinpkStr, leftjoinStr, trustedStr, filtersStr, pageTokenStr)
%s
WHERE %s %s %s;
`, selectStr, tableStr, joinIDStr, joinpkStr, joinLinksStr, leftjoinResourcesStr, trustedStr, filtersStr, linksStr, pageTokenStr)
var lastBlobID int64
err = sqlitex.Exec(conn, dqb.Str(getEventsStr)(), func(stmt *sqlite.Stmt) error {
lastBlobID = stmt.ColumnInt64(0)
Expand Down
23 changes: 21 additions & 2 deletions backend/genproto/activity/v1alpha/activity.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,24 @@ export class ListEventsRequest extends Message<ListEventsRequest> {
/**
* Optional. If we want events only from specific resource IDs
*
*
* @generated from field: repeated string filter_resource = 6;
*/
filterResource: string[] = [];

/**
* Optional. If we want to include link events. These blobs (usually documents
* or comments), link (mention) to another resource (currently only account
* mentions supported). We can add these blobs to the feed result by providing a
* list of resources iris we want links to aggregated as a logical OR.
* These link events are also treated as ogical OR when grouped with other filters.
* Unlike filters (users, event_types) that are grouped under a logic AND.
* filter_users(u1 OR u2 ...) AND filter_event_type(et1 OR et2 ...) OR
* add_linked_resource(lr1 OR lr2 ...)
*
* @generated from field: repeated string add_linked_resource = 7;
*/
addLinkedResource: string[] = [];

constructor(data?: PartialMessage<ListEventsRequest>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -76,6 +89,7 @@ export class ListEventsRequest extends Message<ListEventsRequest> {
{ no: 4, name: "filter_users", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true },
{ no: 5, name: "filter_event_type", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true },
{ no: 6, name: "filter_resource", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true },
{ no: 7, name: "add_linked_resource", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ListEventsRequest {
Expand Down
11 changes: 10 additions & 1 deletion proto/activity/v1alpha/activity.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,18 @@ message ListEventsRequest {
repeated string filter_event_type = 5;

// Optional. If we want events only from specific resource IDs
//
repeated string filter_resource = 6;

// Optional. If we want to include link events. These blobs (usually documents
// or comments), link (mention) to another resource (currently only account
// mentions supported). We can add these blobs to the feed result by providing a
// list of resources iris we want links to aggregated as a logical OR.
// These link events are also treated as ogical OR when grouped with other filters.
// Unlike filters (users, event_types) that are grouped under a logic AND.
// filter_users(u1 OR u2 ...) AND filter_event_type(et1 OR et2 ...) OR
// add_linked_resource(lr1 OR lr2 ...)
repeated string add_linked_resource = 7;

}

// The response with the list of events.
Expand Down
4 changes: 2 additions & 2 deletions proto/activity/v1alpha/go.gensum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
srcs: a89cea1221fc65cb12dbf7fc5e55b92a
outs: b5ff909757a801be9931f17d4669248f
srcs: fc15899e11013c57b0c36297c617270d
outs: 591d305d0ec2a1e29ca02bd073d2ed61
4 changes: 2 additions & 2 deletions proto/activity/v1alpha/js.gensum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
srcs: a89cea1221fc65cb12dbf7fc5e55b92a
outs: e30b2acb41c8f20995c6af6df944094c
srcs: fc15899e11013c57b0c36297c617270d
outs: cc2ba6e98262896aef8c423d8efcaed2

0 comments on commit 2bacc25

Please sign in to comment.