mirror of https://gitlab.com/ngerakines/tavern.git
Resolved bug where objects and users weren't visible. Closes #63
This commit is contained in:
parent
d779e36f28
commit
ff0a76b115
|
@ -1,9 +1,11 @@
|
|||
{{define "head"}}{{end}}
|
||||
{{define "footer_script"}}{{end}}
|
||||
{{define "content"}}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
{{template "view_object" .root }}
|
||||
{{ if .feed }}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
{{template "object_feed" .feed }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{end}}
|
|
@ -1,7 +1,35 @@
|
|||
{{ define "object_feed" }}
|
||||
{{ with . }}
|
||||
{{ range . }}
|
||||
{{template "view_object" . }}
|
||||
{{ if .ViewContext.Error }}
|
||||
<div class="media pt-2 border-top border-danger">
|
||||
<div class="media-body">
|
||||
<h3 class="text-danger">Error</h3>
|
||||
<p class="lead text-danger">.ViewContext.Error</p>
|
||||
</div>
|
||||
</div>
|
||||
{{ else }}
|
||||
{{ if .ViewContext.Tombstone }}
|
||||
<div class="media pt-2 border-top border-danger">
|
||||
<div class="media-body">
|
||||
<h3 class="text-danger">Object Removed</h3>
|
||||
<ul class="text-muted">
|
||||
{{ with .ViewContext.ObjectID }}
|
||||
<li>{{ . }}</li>
|
||||
{{ end }}
|
||||
{{ with .ViewContext.TombstoneDeletedAt }}
|
||||
<li>Deleted {{ date . }}</li>
|
||||
{{ end }}
|
||||
{{ with .ViewContext.TombstoneFormerType }}
|
||||
<li>Former Type "{{ . }}"</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{{ else }}
|
||||
{{template "view_object" . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
|
@ -42,7 +42,10 @@
|
|||
{{ end }}
|
||||
</span>
|
||||
</p>
|
||||
{{ .ViewContext.Content | wrapMaybe | toHTML }}
|
||||
{{ with .ViewContext.Content }}
|
||||
{{ . | wrapMaybe | toHTML }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
{{ if .ViewContext.Media }}
|
||||
<ul class="list-inline">
|
||||
|
|
|
@ -255,6 +255,22 @@ func (h handler) displayObjectFeed(c *gin.Context, requireUser bool, vars map[st
|
|||
}
|
||||
viewContext.ObjectID = objectID
|
||||
|
||||
if objectType == "Tombstone" {
|
||||
viewContext.Tombstone = true
|
||||
viewContext.TombstoneFormerType, _ = storage.JSONString(payload, "formerType")
|
||||
|
||||
if deleted, hasDeleted := storage.JSONString(payload, "deleted"); hasDeleted {
|
||||
var deletedAt time.Time
|
||||
deletedAt, err := time.ParseInLocation("2006-01-02T15:04:05Z", deleted, time.UTC)
|
||||
if err == nil {
|
||||
viewContext.TombstoneDeletedAt = deletedAt
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return viewContext
|
||||
}
|
||||
|
||||
attributedTo, hasAttributedTo := storage.JSONString(objectPayload, "attributedTo")
|
||||
content, hasContent := storage.JSONString(objectPayload, "content")
|
||||
if !hasAttributedTo {
|
||||
|
|
|
@ -87,17 +87,22 @@ func (h handler) viewUser(c *gin.Context) {
|
|||
}
|
||||
|
||||
func (h handler) viewObject(c *gin.Context) {
|
||||
data, localUser, _ /* session */, cont := h.loggedIn(c, true)
|
||||
data, localUser, _ /* session */, cont := h.loggedIn(c, false)
|
||||
if !cont {
|
||||
return
|
||||
}
|
||||
ctx := c.Request.Context()
|
||||
|
||||
localUserActor, err := h.storage.GetActor(c.Request.Context(), localUser.ActorID)
|
||||
if err != nil {
|
||||
h.hardFail(c, err)
|
||||
return
|
||||
var err error
|
||||
var localUserActor *storage.Actor
|
||||
if localUser != nil {
|
||||
localUserActor, err = h.storage.GetActor(c.Request.Context(), localUser.ActorID)
|
||||
if err != nil {
|
||||
h.hardFail(c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
data["param"] = c.Param("object")
|
||||
|
||||
objectID := common.ObjectURL(h.domain, c.Param("object"))
|
||||
|
||||
|
@ -106,6 +111,7 @@ func (h handler) viewObject(c *gin.Context) {
|
|||
h.hardFail(c, err)
|
||||
return
|
||||
}
|
||||
data["object_row_id"] = objectRowID
|
||||
|
||||
object, err := h.storage.ObjectPayloadByObjectID(ctx, objectID)
|
||||
if err != nil {
|
||||
|
@ -114,6 +120,19 @@ func (h handler) viewObject(c *gin.Context) {
|
|||
}
|
||||
data["object"] = object
|
||||
|
||||
destinations := storage.ActivityDestinations(object)
|
||||
origPublic := false
|
||||
for _, destination := range destinations {
|
||||
if destination == "https://www.w3.org/ns/activitystreams#Public" {
|
||||
origPublic = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !origPublic {
|
||||
h.notFoundJSON(c, nil)
|
||||
return
|
||||
}
|
||||
|
||||
objectParents, err := h.storage.ObjectParentsByObjectID(ctx, objectRowID)
|
||||
if err != nil {
|
||||
h.hardFail(c, err)
|
||||
|
@ -137,6 +156,7 @@ func (h handler) viewObject(c *gin.Context) {
|
|||
allChildren := make(map[uuid.UUID][]uuid.UUID)
|
||||
|
||||
objectRowIDs := make([]uuid.UUID, 0)
|
||||
objectRowIDs = append(objectRowIDs, objectRowID)
|
||||
for k, v := range objectParents {
|
||||
objectRowIDs = append(objectRowIDs, k)
|
||||
objectRowIDs = append(objectRowIDs, v...)
|
||||
|
@ -218,14 +238,16 @@ func (h handler) viewObject(c *gin.Context) {
|
|||
mappedBoosts[boost.Key] = boost.Count
|
||||
}
|
||||
|
||||
userBoosts, err := h.storage.CountObjectBoostsByActorObjectIDs(ctx, localUserActor.ID, objectRowIDs)
|
||||
if err != nil {
|
||||
h.hardFail(c, err)
|
||||
return
|
||||
}
|
||||
mappedUserBoosts := make(map[string]int)
|
||||
for _, userBoost := range userBoosts {
|
||||
mappedUserBoosts[userBoost.Key] = userBoost.Count
|
||||
if localUserActor != nil {
|
||||
userBoosts, err := h.storage.CountObjectBoostsByActorObjectIDs(ctx, localUserActor.ID, objectRowIDs)
|
||||
if err != nil {
|
||||
h.hardFail(c, err)
|
||||
return
|
||||
}
|
||||
for _, userBoost := range userBoosts {
|
||||
mappedUserBoosts[userBoost.Key] = userBoost.Count
|
||||
}
|
||||
}
|
||||
|
||||
replies, err := h.storage.CountObjectRepliesByObjectIDs(ctx, objectRowIDs)
|
||||
|
@ -244,6 +266,7 @@ func (h handler) viewObject(c *gin.Context) {
|
|||
|
||||
topParentRef, hasTopParentRef := refs[topParent]
|
||||
if !hasTopParentRef {
|
||||
|
||||
c.HTML(http.StatusOK, "object", data)
|
||||
return
|
||||
}
|
||||
|
@ -305,7 +328,7 @@ func (h handler) viewObject(c *gin.Context) {
|
|||
}
|
||||
viewContext.LinkAnnounce = true
|
||||
|
||||
if attributedTo == localUserActor.ActorID {
|
||||
if localUserActor != nil && attributedTo == localUserActor.ActorID {
|
||||
viewContext.LinkDelete = true
|
||||
}
|
||||
|
||||
|
@ -396,7 +419,7 @@ func (h handler) viewObject(c *gin.Context) {
|
|||
return viewContext
|
||||
})
|
||||
|
||||
data["root"] = root
|
||||
data["feed"] = []interface{}{root}
|
||||
|
||||
c.HTML(http.StatusOK, "object", data)
|
||||
}
|
||||
|
|
|
@ -62,6 +62,10 @@ type viewObjectContext struct {
|
|||
TotalReplies int
|
||||
|
||||
Error string
|
||||
|
||||
Tombstone bool
|
||||
TombstoneFormerType string
|
||||
TombstoneDeletedAt time.Time
|
||||
}
|
||||
|
||||
type viewContentAttachment struct {
|
||||
|
|
Loading…
Reference in New Issue