added display of attachment presence to post
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 }}
|
||||
<div class="flex flex-col gap-2">
|
||||
|
||||
@@ -20,6 +20,13 @@
|
||||
<span class="text-gray-600 text-sm ml-2">(<em>
|
||||
<a href="/user/{{ post_userName }}" target="_blank" class="text-blue-700 hover:text-blue-900">{{ post_userName }}</a>,
|
||||
{{ DisplayDateTime(post_cur.Posted, .) }}</em>)
|
||||
{{ if post_attach.Filename != "" }}
|
||||
<a href="/TODO" title="(Attachment {{ post_attach.Filename }} - {{ post_attach.Length }} bytes)"
|
||||
{{ if hasPrefix(post_attach.MIMEType, "text/") || hasPrefix(post_attach.MIMEType, "image/" )}}
|
||||
target="_blank"
|
||||
{{ end }}
|
||||
class="text-lg">📎</a>
|
||||
{{ end }}
|
||||
</span>
|
||||
</div>
|
||||
{{ if post_overrideLine != "" }}
|
||||
|
||||
@@ -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 }}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user