Webmentions: Remove type, fix content parsing

This commit is contained in:
Jan-Lukas Else 2020-11-16 15:46:16 +01:00
parent 5754543d7a
commit 6dd99289ad
2 changed files with 6 additions and 19 deletions

View File

@ -32,7 +32,6 @@ type mention struct {
Title string
Content string
Author string
Type string
}
func initWebmention() {
@ -174,7 +173,7 @@ func verifyNextWebmention() error {
// Approve if it's server-intern
newStatus = webmentionStatusApproved
}
_, err = appDbExec("update webmentions set status = ?, title = ?, type = ?, content = ?, author = ? where id = ?", newStatus, m.Title, m.Type, m.Content, m.Author, m.ID)
_, err = appDbExec("update webmentions set status = ?, title = ?, content = ?, author = ? where id = ?", newStatus, m.Title, m.Content, m.Author, m.ID)
if oldStatus == string(webmentionStatusNew) {
sendNotification(fmt.Sprintf("New webmention from %s to %s", m.Source, m.Target))
}
@ -228,13 +227,13 @@ func getWebmentions(config *webmentionsRequestConfig) ([]*mention, error) {
if config.asc {
order = "asc"
}
rows, err = appDbQuery("select id, source, target, created, title, content, author, type from webmentions "+filter+" order by created "+order, args...)
rows, err = appDbQuery("select id, source, target, created, title, content, author from webmentions "+filter+" order by created "+order, args...)
if err != nil {
return nil, err
}
for rows.Next() {
m := &mention{}
err = rows.Scan(&m.ID, &m.Source, &m.Target, &m.Created, &m.Title, &m.Content, &m.Author, &m.Type)
err = rows.Scan(&m.ID, &m.Source, &m.Target, &m.Created, &m.Title, &m.Content, &m.Author)
if err != nil {
return nil, err
}

View File

@ -80,22 +80,10 @@ func mfFillMention(m *mention, mf *microformats.Microformat) bool {
m.Title = title
}
}
if reply, ok := mf.Properties["in-reply-to"]; ok && len(reply) > 0 {
if replyLink, ok := reply[0].(string); ok && replyLink == m.Target {
m.Type = "comment"
}
}
if like, ok := mf.Properties["like-of"]; ok && len(like) > 0 {
if likeLink, ok := like[0].(string); ok && likeLink == m.Target {
m.Type = "like"
}
}
if contents, ok := mf.Properties["content"]; ok && len(contents) > 0 {
if content, ok := contents[0].(map[string]interface{}); ok {
if rawContentValue, ok := content["value"]; ok {
if contentValue, ok := rawContentValue.(string); ok {
m.Content = contentValue
}
if content, ok := contents[0].(map[string]string); ok {
if contentValue, ok := content["value"]; ok {
m.Content = contentValue
}
}
}