Skip to content

Commit

Permalink
Filter partial messages from inbox
Browse files Browse the repository at this point in the history
Skip Announce, Like, etc. messages in inbox streams
  • Loading branch information
benpate committed Jan 23, 2024
1 parent e06d51d commit 5f0d84c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions _embed/templates/user-inbox/following-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
{{ icon .Icon }}
{{.Method}}
{{ .LastPolled | tinyDate }}
{{- else if eq "LOADING" .Status -}}
<span class="green">{{.Status}}</span>
{{- else -}}
{{- else if eq "ERROR" .Status -}}
<span class="red">{{.Status}}</span>
{{- else -}}
<span class="green">{{.Status}}</span>
{{- end -}}
</div>
</div>
Expand Down
32 changes: 32 additions & 0 deletions service/following_threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ func (service *Following) SaveMessage(following *model.Following, document strea
document, originType = getPrimaryPost(document, originType)
}

// If document does not include enough data to create a message, then skip it.
if notAdequate(document) {
derp.Report(derp.NewInternalError("service.Following.SaveMessage", "Skipping inadequate document", document.Value()))
return nil
}

// Convert the document into a message (and traverse responses if necessary)
message := getMessage(following, document, originType)

Expand Down Expand Up @@ -84,6 +90,9 @@ func (service *Following) saveUniqueMessage(message model.Message) error {
// TODO: LOW: In the future, the "context" value may be useful in traversing this list.
func getPrimaryPost(document streams.Document, originType string) (streams.Document, string) {

// Unwrap "activity" documents
document = document.UnwrapActivity()

if inReplyTo := document.InReplyTo(); inReplyTo.NotNil() {

// Change origin type from PRIMARY to REPLY without affecting
Expand All @@ -101,6 +110,29 @@ func getPrimaryPost(document streams.Document, originType string) (streams.Docum
return document, originType
}

// isAdequate returns TRUE if the document contains enough data to create an adequiae message.
func isAdequate(document streams.Document) bool {

if document.Name() != "" {
return true
}

if document.Summary() != "" {
return true
}

if document.Content() != "" {
return true
}

return false
}

// notAdequate returns TRUE if the document DOES NOT contain enough data to create an adequiae message.
func notAdequate(document streams.Document) bool {
return !isAdequate(document)
}

// getMessage returns a Message object based on the provided arguments.
func getMessage(following *model.Following, document streams.Document, originType string) model.Message {

Expand Down

0 comments on commit 5f0d84c

Please sign in to comment.