Add-ish support for tags and mentions in new messages
Some checks failed
/ docker (push) Has been cancelled
Some checks failed
/ docker (push) Has been cancelled
This commit is contained in:
parent
94106bb82f
commit
b0f041e7b0
14 changed files with 242 additions and 53 deletions
|
@ -23,8 +23,10 @@ import (
|
|||
|
||||
func postAs(w http.ResponseWriter, r *http.Request) {
|
||||
type Inbound struct {
|
||||
Username string `json:"username"`
|
||||
Content string `json:"content"`
|
||||
Username string `json:"username"`
|
||||
Content string `json:"content"`
|
||||
ContentWarning *string `json:"content_warning"`
|
||||
ReplyTo *string `json:"reply_to"`
|
||||
}
|
||||
log := hlog.FromRequest(r)
|
||||
dec := json.NewDecoder(r.Body)
|
||||
|
@ -69,6 +71,34 @@ func postAs(w http.ResponseWriter, r *http.Request) {
|
|||
AccessLevel: models.NOTE_TARGET_PUBLIC,
|
||||
OriginId: 1,
|
||||
}
|
||||
if data.ContentWarning != nil {
|
||||
note.ContentWarning = sql.NullString{Valid: true, String: *data.ContentWarning}
|
||||
}
|
||||
if data.ReplyTo != nil {
|
||||
note.RepliesTo = sql.NullString{Valid: true, String: *data.ReplyTo}
|
||||
_, err = activitypub.ImportRemoteNote(*data.ReplyTo, user)
|
||||
if err != nil {
|
||||
log.Error().
|
||||
Err(err).
|
||||
Str("remote-note-id", *data.ReplyTo).
|
||||
Msg("Failed to import remote note that's being replied to")
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
mentions := webshared.MentionsFromContent(data.Content)
|
||||
dbPings := []*models.NoteToPing{}
|
||||
for _, mention := range mentions {
|
||||
accId, err := activitypub.ImportRemoteAccountByHandle(mention)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Str("handle", mention).Msg("Failed to import pinged target")
|
||||
continue
|
||||
}
|
||||
dbPings = append(dbPings, &models.NoteToPing{
|
||||
NoteId: note.ID,
|
||||
PingTargetId: accId,
|
||||
})
|
||||
}
|
||||
tx := dbgen.Q.Begin()
|
||||
err = tx.Note.Select(
|
||||
n.ID,
|
||||
|
@ -91,6 +121,7 @@ func postAs(w http.ResponseWriter, r *http.Request) {
|
|||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = tx.NoteToPing.Create(dbPings...)
|
||||
activity := models.Activity{
|
||||
Id: shared.NewId(),
|
||||
Type: string(models.ActivityCreate),
|
||||
|
@ -108,6 +139,7 @@ func postAs(w http.ResponseWriter, r *http.Request) {
|
|||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// TODO: Move everything past this into separate functions
|
||||
u2u := dbgen.UserToUserRelation
|
||||
links, err := u2u.GetFollowerInboxesForId(user.ID)
|
||||
if err != nil {
|
||||
|
@ -132,9 +164,10 @@ func postAs(w http.ResponseWriter, r *http.Request) {
|
|||
for _, link := range links {
|
||||
log.Debug().Str("target-inbox", link).Msg("Sending message to")
|
||||
go func() {
|
||||
res, err := webshared.RequestSignedCavage("POST", link, outData, user)
|
||||
res, _, err := webshared.RequestSigned("POST", link, outData, user)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Str("link", link).Msg("Failed to send create to target inbox")
|
||||
return
|
||||
}
|
||||
if res.StatusCode >= 400 {
|
||||
body, _ := io.ReadAll(res.Body)
|
||||
|
@ -142,6 +175,36 @@ func postAs(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}()
|
||||
}
|
||||
go func() {
|
||||
for _, ping := range dbPings {
|
||||
go func() {
|
||||
links, err := dbgen.UserRemoteLinks.Where(dbgen.UserRemoteLinks.UserId.Eq(ping.PingTargetId)).
|
||||
First()
|
||||
if err != nil {
|
||||
log.Warn().
|
||||
Err(err).
|
||||
Str("tagged-id", ping.PingTargetId).
|
||||
Msg("Failed to get link for tagged account")
|
||||
return
|
||||
}
|
||||
res, _, err := webshared.RequestSigned("POST", links.InboxLink, outData, user)
|
||||
if err != nil {
|
||||
log.Warn().
|
||||
Err(err).
|
||||
Str("link", links.InboxLink).
|
||||
Msg("Failed to send create to ping target inbox")
|
||||
return
|
||||
}
|
||||
if res.StatusCode >= 400 {
|
||||
body, _ := io.ReadAll(res.Body)
|
||||
log.Warn().
|
||||
Int("status-code", res.StatusCode).
|
||||
Bytes("body", body).
|
||||
Msg("Bad reply")
|
||||
}
|
||||
}()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func notesFrom(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue