From 0252dfa512a91395de2e3a2b62ec2d02667f96d9 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 2 Mar 2019 11:10:05 -0500 Subject: [PATCH] add option to fetch referenced uri --- .../backends/srndv2/src/srnd/frontend_http.go | 37 ++++++++++--------- contrib/backends/srndv2/src/srnd/model_mem.go | 7 +++- contrib/templates/placebo/post.mustache | 22 +++++++++++ contrib/templates/placebo/thread.mustache | 8 ++-- 4 files changed, 51 insertions(+), 23 deletions(-) diff --git a/contrib/backends/srndv2/src/srnd/frontend_http.go b/contrib/backends/srndv2/src/srnd/frontend_http.go index b9a4a7e..5ef20f7 100644 --- a/contrib/backends/srndv2/src/srnd/frontend_http.go +++ b/contrib/backends/srndv2/src/srnd/frontend_http.go @@ -1062,27 +1062,30 @@ func (self httpFrontend) handle_authed_api(wr http.ResponseWriter, r *http.Reque func (self *httpFrontend) handle_api_find(wr http.ResponseWriter, r *http.Request) { q := r.URL.Query() h := q.Get("hash") + msgid := q.Get("id") if len(h) > 0 { - msgid := q.Get("id") - if len(h) > 0 { - e, err := self.daemon.database.GetMessageIDByHash(h) - if err == nil { - msgid = e.MessageID() - } + e, err := self.daemon.database.GetMessageIDByHash(h) + if err == nil { + msgid = e.MessageID() } - if len(msgid) > 0 { - // found it (probaly) - model := self.daemon.database.GetPostModel(self.prefix, msgid) - if model == nil { - // no model + } + + if !ValidMessageID(msgid) { + msgid = "" + } + + if len(msgid) > 0 { + self.daemon.store.GetMessage(msgid, func(nntp NNTPMessage) { + if nntp == nil { wr.WriteHeader(404) - } else { - // we found it - wr.Header().Add("Content-Type", "text/json; encoding=UTF-8") - json.NewEncoder(wr).Encode([]PostModel{model}) + return } - return - } + model := PostModelFromMessage(self.prefix, nntp) + // we found it + wr.Header().Add("Content-Type", "text/json; encoding=UTF-8") + json.NewEncoder(wr).Encode([]PostModel{model}) + }) + return } s := q.Get("text") g := q.Get("group") diff --git a/contrib/backends/srndv2/src/srnd/model_mem.go b/contrib/backends/srndv2/src/srnd/model_mem.go index b31b4d5..d4323d9 100644 --- a/contrib/backends/srndv2/src/srnd/model_mem.go +++ b/contrib/backends/srndv2/src/srnd/model_mem.go @@ -295,6 +295,7 @@ type post struct { Type string nntp_id int FrontendPublicKey string + ReferencedURI string } func (p *post) IsCtl() bool { @@ -411,7 +412,7 @@ func (self *attachment) Filename() string { return self.Name } -func PostModelFromMessage(parent, prefix string, nntp NNTPMessage) PostModel { +func PostModelFromMessage(prefix string, nntp NNTPMessage) PostModel { p := new(post) p.PostName = nntp.Name() p.PostSubject = nntp.Subject() @@ -422,10 +423,11 @@ func PostModelFromMessage(parent, prefix string, nntp NNTPMessage) PostModel { p.Posted = nntp.Posted() p.op = nntp.OP() p.prefix = prefix - p.Parent = parent + p.Parent = nntp.Reference() p.addr = nntp.Addr() p.sage = nntp.Sage() p.Key = nntp.Pubkey() + p.ReferencedURI = nntp.Headers().Get("X-Referenced-Uri", "") p.FrontendPublicKey = nntp.FrontendPubkey() for _, att := range nntp.Attachments() { p.Files = append(p.Files, att.ToModel(prefix)) @@ -627,6 +629,7 @@ func (self *post) Truncate() PostModel { // TODO: copy? Files: self.Files, FrontendPublicKey: self.FrontendPublicKey, + ReferencedURI: self.ReferencedURI, } } diff --git a/contrib/templates/placebo/post.mustache b/contrib/templates/placebo/post.mustache index fa6066b..1145e59 100644 --- a/contrib/templates/placebo/post.mustache +++ b/contrib/templates/placebo/post.mustache @@ -42,5 +42,27 @@

{{{post.RenderBody}}} + {{#post.OP}} + + {{/post.OP}}
+ diff --git a/contrib/templates/placebo/thread.mustache b/contrib/templates/placebo/thread.mustache index 5b5329e..5f4d118 100644 --- a/contrib/templates/placebo/thread.mustache +++ b/contrib/templates/placebo/thread.mustache @@ -57,10 +57,10 @@ {{^thread.BumpLock}}
{{/thread.BumpLock}} - {{{thread.OP.RenderPost}}} - {{#thread.Replies}} - {{{RenderPost}}} - {{/thread.Replies}} + {{{thread.OP.RenderPost}}} + {{#thread.Replies}} + {{{RenderPost}}} + {{/thread.Replies}}