(app *App, handle string)
| 1045 | } |
| 1046 | |
| 1047 | func GetProfileURLFromHandle(app *App, handle string) (string, error) { |
| 1048 | handle = strings.TrimLeft(handle, "@") |
| 1049 | actorIRI := "" |
| 1050 | parts := strings.Split(handle, "@") |
| 1051 | if len(parts) != 2 { |
| 1052 | return "", fmt.Errorf("invalid handle format") |
| 1053 | } |
| 1054 | domain := parts[1] |
| 1055 | |
| 1056 | // Check non-AP instances |
| 1057 | if siloProfileURL := silobridge.Profile(parts[0], domain); siloProfileURL != "" { |
| 1058 | return siloProfileURL, nil |
| 1059 | } |
| 1060 | |
| 1061 | remoteUser, err := getRemoteUserFromHandle(app, handle) |
| 1062 | if err != nil { |
| 1063 | // can't find using handle in the table but the table may already have this user without |
| 1064 | // handle from a previous version |
| 1065 | // TODO: Make this determination. We should know whether a user exists without a handle, or doesn't exist at all |
| 1066 | actorIRI = RemoteLookup(handle) |
| 1067 | _, errRemoteUser := getRemoteUser(app, actorIRI) |
| 1068 | // if it exists then we need to update the handle |
| 1069 | if errRemoteUser == nil { |
| 1070 | _, err := app.db.Exec("UPDATE remoteusers SET handle = ? WHERE actor_id = ?", handle, actorIRI) |
| 1071 | if err != nil { |
| 1072 | log.Error("Couldn't update handle '%s' for user %s", handle, actorIRI) |
| 1073 | } |
| 1074 | } else { |
| 1075 | // this probably means we don't have the user in the table so let's try to insert it |
| 1076 | // here we need to ask the server for the inboxes |
| 1077 | remoteActor, err := activityserve.NewRemoteActor(actorIRI) |
| 1078 | if err != nil { |
| 1079 | log.Error("Couldn't fetch remote actor: %v", err) |
| 1080 | } |
| 1081 | if debugging { |
| 1082 | log.Info("Got remote actor: %s %s %s %s %s", actorIRI, remoteActor.GetInbox(), remoteActor.GetSharedInbox(), remoteActor.URL(), handle) |
| 1083 | } |
| 1084 | _, err = app.db.Exec("INSERT INTO remoteusers (actor_id, inbox, shared_inbox, url, handle) VALUES(?, ?, ?, ?, ?)", actorIRI, remoteActor.GetInbox(), remoteActor.GetSharedInbox(), remoteActor.URL(), handle) |
| 1085 | if err != nil { |
| 1086 | log.Error("Couldn't insert remote user: %v", err) |
| 1087 | return "", err |
| 1088 | } |
| 1089 | actorIRI = remoteActor.URL() |
| 1090 | } |
| 1091 | } else if remoteUser.URL == "" { |
| 1092 | log.Info("Remote user %s URL empty, fetching", remoteUser.ActorID) |
| 1093 | newRemoteActor, err := activityserve.NewRemoteActor(remoteUser.ActorID) |
| 1094 | if err != nil { |
| 1095 | log.Error("Couldn't fetch remote actor: %v", err) |
| 1096 | } else { |
| 1097 | _, err := app.db.Exec("UPDATE remoteusers SET url = ? WHERE actor_id = ?", newRemoteActor.URL(), remoteUser.ActorID) |
| 1098 | if err != nil { |
| 1099 | log.Error("Couldn't update handle '%s' for user %s", handle, actorIRI) |
| 1100 | } else { |
| 1101 | actorIRI = newRemoteActor.URL() |
| 1102 | } |
| 1103 | } |
| 1104 | } else { |
no test coverage detected