fix an issue that remote accounts cannot be added as cohosts

peertube
Namekuji 2023-01-27 01:11:37 -05:00
rodzic 7028f5834c
commit abfb2f62f4
7 zmienionych plików z 14 dodań i 19 usunięć

Wyświetl plik

@ -10,7 +10,7 @@ export const validators = {
export function webfinger(user) {
if (!user) return "";
const url = new URL(user.url);
const finger = user.acct.split("@");
const finger = user.username.split("@");
return `${finger[0]}@${url.host}`;
}

Wyświetl plik

@ -176,8 +176,7 @@ export default {
title: this.title,
description: this.description,
cohosts: map(this.cohosts, (u) => ({
remote_id: u.id,
remote_url: u.url,
webfinger: webfinger(u),
})),
restriction: this.relationship,
advertise:
@ -333,7 +332,7 @@ export default {
<v-list lines="two">
<v-list-item
:key="0"
:value="searchResult.acct"
:value="webfinger(searchResult)"
:title="searchResult.displayName"
@click="onResultClick"
>

Wyświetl plik

@ -562,7 +562,7 @@ export default {
const resp = await axios.get(`/app/user/${identity}`);
const account = this.roomInfo.accounts[identity];
const info = {
acct: account.acct,
username: account.username,
displayName: account.displayName,
avatar: account.avatar,
url: account.url,

Wyświetl plik

@ -138,7 +138,10 @@ func oauthHandler(c echo.Context) (err error) {
}
coll := mainDB.Collection(COLLECTION_USER)
if result, dbErr := findUserByRemote(c.Request().Context(), string(acc.ID), acc.URL); dbErr == mongo.ErrNoDocuments {
acctUrl, _ := url.Parse(acc.URL)
finger := strings.Split(acc.Username, "@")
webfinger := fmt.Sprintf("%s@%s", finger[0], acctUrl.Host)
if result, dbErr := findUserByWebfinger(c.Request().Context(), webfinger); dbErr == mongo.ErrNoDocuments {
entropy := ulid.Monotonic(rand.Reader, 0)
id, err := ulid.New(ulid.Timestamp(time.Now().UTC()), entropy)
if err != nil {
@ -146,13 +149,11 @@ func oauthHandler(c echo.Context) (err error) {
return echo.NewHTTPError(http.StatusInternalServerError)
}
data.AudonID = id.String()
acctUrl, _ := url.Parse(acc.URL)
finger := strings.Split(acc.Username, "@")
newUser := AudonUser{
AudonID: data.AudonID,
RemoteID: string(acc.ID),
RemoteURL: acc.URL,
Webfinger: fmt.Sprintf("%s@%s", finger[0], acctUrl.Host),
Webfinger: webfinger,
CreatedAt: time.Now().UTC(),
}
if _, insertErr := coll.InsertOne(c.Request().Context(), newUser); insertErr != nil {

Wyświetl plik

@ -103,7 +103,7 @@ func createRoomHandler(c echo.Context) error {
// if cohosts are already registered, retrieve their data from DB
for i, cohost := range room.CoHosts {
cohostUser, err := findUserByRemote(c.Request().Context(), cohost.RemoteID, cohost.RemoteURL)
cohostUser, err := findUserByWebfinger(c.Request().Context(), cohost.Webfinger)
if err == nil {
room.CoHosts[i] = cohostUser
}

Wyświetl plik

@ -187,20 +187,15 @@ func createIndexes(ctx context.Context) error {
return err
}
if len(userIndexes) < 3 {
if len(userIndexes) < 4 {
_, err := userColl.Indexes().CreateMany(ctx, []mongo.IndexModel{
{
Keys: bson.D{{Key: "audon_id", Value: 1}},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{
{Key: "remote_url", Value: 1},
{Key: "remote_id", Value: 1},
},
},
{
Keys: bson.D{{Key: "webfinger", Value: 1}},
Keys: bson.D{{Key: "webfinger", Value: 1}},
Options: options.Index().SetUnique(true),
},
})
if err != nil {

Wyświetl plik

@ -105,7 +105,7 @@ func (a *AudonUser) Equal(u *AudonUser) bool {
return false
}
return a.AudonID == u.AudonID || (a.RemoteID == u.RemoteID && a.RemoteURL == u.RemoteURL)
return a.AudonID == u.AudonID || a.Webfinger == u.Webfinger
}
func (a *AudonUser) InLivekit(ctx context.Context) (bool, error) {