From 652cdf84774258813f820715725e3970125b873e Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Mon, 19 Jan 2026 22:54:28 -0700 Subject: [PATCH] added display of attachment presence to post --- conference.go | 13 +++++++++++++ database/post.go | 27 +++++++++++++++++++++++++++ ui/views/posts.jet | 2 ++ ui/views/singlepost.jet | 7 +++++++ ui/views/slippage.jet | 2 ++ 5 files changed, 51 insertions(+) diff --git a/conference.go b/conference.go index 5c1518d..cb089c1 100644 --- a/conference.go +++ b/conference.go @@ -438,6 +438,17 @@ func templateOverrideLink(args jet.Arguments) reflect.Value { return reflect.ValueOf(rc) } +// templateAttachmentInfo gets the attachment info for a post. +func templateAttachmentInfo(args jet.Arguments) reflect.Value { + post := args.Get(0).Convert(reflect.TypeFor[*database.PostHeader]()).Interface().(*database.PostHeader) + ctxt := args.Get(1).Convert(reflect.TypeFor[ui.AmContext]()).Interface().(ui.AmContext) + rc, _ := post.AttachmentInfo(ctxt.Ctx()) + if rc == nil { + rc = &database.PostAttachInfo{} + } + return reflect.ValueOf(rc) +} + /* ReadPosts displays posts in a topic. * Parameters: * ctxt - The AmContext for the request. @@ -619,6 +630,7 @@ func ReadPosts(ctxt ui.AmContext) (string, any, error) { ctxt.VarMap().SetFunc("post_getOverrideLink", templateOverrideLink) ctxt.VarMap().SetFunc("post_getText", templatePostText) ctxt.VarMap().SetFunc("post_getUserName", templateExtractUserName) + ctxt.VarMap().SetFunc("post_getAttachmentInfo", templateAttachmentInfo) ctxt.VarMap().Set("post_stem", fmt.Sprintf("%s/r/%d", urlStem, topic.Number)) ctxt.VarMap().Set("post_max", topic.TopMessage) ctxt.VarMap().Set("posts", posts) @@ -741,6 +753,7 @@ func PostInTopic(ctxt ui.AmContext) (string, any, error) { ctxt.VarMap().SetFunc("post_getOverrideLink", templateOverrideLink) ctxt.VarMap().SetFunc("post_getText", templatePostText) ctxt.VarMap().SetFunc("post_getUserName", templateExtractUserName) + ctxt.VarMap().SetFunc("post_getAttachmentInfo", templateAttachmentInfo) ctxt.VarMap().Set("post_stem", fmt.Sprintf("/comm/%s/conf/%s/r/%d", comm.Alias, ctxt.GetScratch("currentAlias"), topic.Number)) ctxt.VarMap().Set("post_max", topic.TopMessage) ctxt.VarMap().Set("posts", posts) diff --git a/database/post.go b/database/post.go index 74ff1c3..d07b270 100644 --- a/database/post.go +++ b/database/post.go @@ -36,6 +36,13 @@ type PostData struct { Data *string `db:"data"` // actual post data } +// PostAttachInfo contains information about a file attachment to a post. +type PostAttachInfo struct { + Filename string // name of attached file + MIMEType string // MIME type of attached file + Length int32 // length in bytes of attached file +} + // ErrNoPostData is returned if post data is missing. var ErrNoPostData = errors.New("no post data") @@ -58,6 +65,26 @@ func (p *PostHeader) IsPublished(ctx context.Context) (bool, error) { return ct > 0, err } +/* AttachmentInfo returns attachment information for a post. + * Parameters: + * ctx - Standard Go context value. + * Returns: + * Pointer to structure with post attachment info. + * Standard Go error status. + */ +func (p *PostHeader) AttachmentInfo(ctx context.Context) (*PostAttachInfo, error) { + rs, err := amdb.QueryContext(ctx, "SELECT filename, mimetype, datalen FROM postattach WHERE postid = ?", p.PostId) + if err != nil { + return nil, err + } + if !rs.Next() { + return nil, nil + } + var rc PostAttachInfo + err = rs.Scan(&(rc.Filename), &(rc.MIMEType), &(rc.Length)) + return &rc, err +} + /* SetAttachment sets the attachment data for a post. * Parameters: * ctx - Standard Go context value. diff --git a/ui/views/posts.jet b/ui/views/posts.jet index 90a04f0..f6c526f 100644 --- a/ui/views/posts.jet +++ b/ui/views/posts.jet @@ -106,12 +106,14 @@ {{ post_text := "" }} {{ post_overrideLine := "" }} {{ post_overrideLink := "" }} + {{ post_attach := nil }} {{ range i, p := posts }} {{ post_cur = p }} {{ post_userName = post_getUserName(p, .) }} {{ post_text = post_getText(p, .) }} {{ post_overrideLine = post_getOverrideLine(p, .) }} {{ post_overrideLink = post_getOverrideLink(p, post_topicPermalink) }} + {{ post_attach = post_getAttachmentInfo(p, .) }} {{ include "singlepost.jet" }} {{ if advancedControls }}
diff --git a/ui/views/singlepost.jet b/ui/views/singlepost.jet index cde5123..9541d54 100644 --- a/ui/views/singlepost.jet +++ b/ui/views/singlepost.jet @@ -20,6 +20,13 @@ ( {{ post_userName }}, {{ DisplayDateTime(post_cur.Posted, .) }}) + {{ if post_attach.Filename != "" }} + 📎 + {{ end }}
{{ if post_overrideLine != "" }} diff --git a/ui/views/slippage.jet b/ui/views/slippage.jet index c59a348..c244405 100644 --- a/ui/views/slippage.jet +++ b/ui/views/slippage.jet @@ -24,6 +24,7 @@ {{ post_text := "" }} {{ post_overrideLine := "" }} {{ post_overrideLink := "" }} + {{ post_attach := nil }} {{ range i, p := posts }} {{ m = map("post_cur", p, "post_userName", post_getUserName(p, .), "post_text", post_getText(p, .), "post_overrideLine", post_getOverrideLine(p, .), "post_overrideLink", post_getOverrideLink(p, post_topicPermalink)) }} @@ -32,6 +33,7 @@ {{ post_text = post_getText(p, .) }} {{ post_overrideLine = post_getOverrideLine(p, .) }} {{ post_overrideLink = post_getOverrideLink(p, post_topicPermalink) }} + {{ post_attach = post_getAttachmentInfo(p, .) }} {{ include "singlepost.jet" }} {{ end }}