// Add follower locally, since it wasn't found before
res,err:=t.Exec("INSERT INTO remoteusers (actor_id, inbox, shared_inbox) VALUES (?, ?, ?)",fullActor.ID,fullActor.Inbox,fullActor.Endpoints.SharedInbox)
iferr!=nil{
// if duplicate key, res will be nil and panic on
// res.LastInsertId below
t.Rollback()
log.Error("Couldn't add new remoteuser in DB: %v\n",err)
return
}
followerID,err=res.LastInsertId()
iferr!=nil{
t.Rollback()
log.Error("no lastinsertid for followers, rolling back: %v",err)
return
}
// Add in key
_,err=t.Exec("INSERT INTO remoteuserkeys (id, remote_user_id, public_key) VALUES (?, ?, ?)",fullActor.PublicKey.ID,followerID,fullActor.PublicKey.PublicKeyPEM)
iferr!=nil{
if!app.db.isDuplicateKeyErr(err){
t.Rollback()
log.Error("Couldn't add follower keys in DB: %v\n",err)
return
}
}
}
// Add follow
_,err=t.Exec("INSERT INTO remotefollows (collection_id, remote_user_id, created) VALUES (?, ?, "+app.db.now()+")",c.ID,followerID)
iferr!=nil{
if!app.db.isDuplicateKeyErr(err){
t.Rollback()
log.Error("Couldn't add follower in DB: %v\n",err)
return
}
}
err=t.Commit()
iferr!=nil{
t.Rollback()
log.Error("Rolling back after Commit(): %v\n",err)
return
}
}elseifisUnfollow{
// Remove follower locally
_,err=app.db.Exec("DELETE FROM remotefollows WHERE collection_id = ? AND remote_user_id = (SELECT id FROM remoteusers WHERE actor_id = ?)",c.ID,to.String())
iferr!=nil{
log.Error("Couldn't remove follower from DB: %v\n",err)