kopia lustrzana https://codeberg.org/nmkj/audon
fix an issue that remote accounts cannot be added as cohosts
rodzic
7028f5834c
commit
abfb2f62f4
|
@ -10,7 +10,7 @@ export const validators = {
|
||||||
export function webfinger(user) {
|
export function webfinger(user) {
|
||||||
if (!user) return "";
|
if (!user) return "";
|
||||||
const url = new URL(user.url);
|
const url = new URL(user.url);
|
||||||
const finger = user.acct.split("@");
|
const finger = user.username.split("@");
|
||||||
return `${finger[0]}@${url.host}`;
|
return `${finger[0]}@${url.host}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,8 +176,7 @@ export default {
|
||||||
title: this.title,
|
title: this.title,
|
||||||
description: this.description,
|
description: this.description,
|
||||||
cohosts: map(this.cohosts, (u) => ({
|
cohosts: map(this.cohosts, (u) => ({
|
||||||
remote_id: u.id,
|
webfinger: webfinger(u),
|
||||||
remote_url: u.url,
|
|
||||||
})),
|
})),
|
||||||
restriction: this.relationship,
|
restriction: this.relationship,
|
||||||
advertise:
|
advertise:
|
||||||
|
@ -333,7 +332,7 @@ export default {
|
||||||
<v-list lines="two">
|
<v-list lines="two">
|
||||||
<v-list-item
|
<v-list-item
|
||||||
:key="0"
|
:key="0"
|
||||||
:value="searchResult.acct"
|
:value="webfinger(searchResult)"
|
||||||
:title="searchResult.displayName"
|
:title="searchResult.displayName"
|
||||||
@click="onResultClick"
|
@click="onResultClick"
|
||||||
>
|
>
|
||||||
|
|
|
@ -562,7 +562,7 @@ export default {
|
||||||
const resp = await axios.get(`/app/user/${identity}`);
|
const resp = await axios.get(`/app/user/${identity}`);
|
||||||
const account = this.roomInfo.accounts[identity];
|
const account = this.roomInfo.accounts[identity];
|
||||||
const info = {
|
const info = {
|
||||||
acct: account.acct,
|
username: account.username,
|
||||||
displayName: account.displayName,
|
displayName: account.displayName,
|
||||||
avatar: account.avatar,
|
avatar: account.avatar,
|
||||||
url: account.url,
|
url: account.url,
|
||||||
|
|
9
auth.go
9
auth.go
|
@ -138,7 +138,10 @@ func oauthHandler(c echo.Context) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
coll := mainDB.Collection(COLLECTION_USER)
|
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)
|
entropy := ulid.Monotonic(rand.Reader, 0)
|
||||||
id, err := ulid.New(ulid.Timestamp(time.Now().UTC()), entropy)
|
id, err := ulid.New(ulid.Timestamp(time.Now().UTC()), entropy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -146,13 +149,11 @@ func oauthHandler(c echo.Context) (err error) {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
data.AudonID = id.String()
|
data.AudonID = id.String()
|
||||||
acctUrl, _ := url.Parse(acc.URL)
|
|
||||||
finger := strings.Split(acc.Username, "@")
|
|
||||||
newUser := AudonUser{
|
newUser := AudonUser{
|
||||||
AudonID: data.AudonID,
|
AudonID: data.AudonID,
|
||||||
RemoteID: string(acc.ID),
|
RemoteID: string(acc.ID),
|
||||||
RemoteURL: acc.URL,
|
RemoteURL: acc.URL,
|
||||||
Webfinger: fmt.Sprintf("%s@%s", finger[0], acctUrl.Host),
|
Webfinger: webfinger,
|
||||||
CreatedAt: time.Now().UTC(),
|
CreatedAt: time.Now().UTC(),
|
||||||
}
|
}
|
||||||
if _, insertErr := coll.InsertOne(c.Request().Context(), newUser); insertErr != nil {
|
if _, insertErr := coll.InsertOne(c.Request().Context(), newUser); insertErr != nil {
|
||||||
|
|
2
room.go
2
room.go
|
@ -103,7 +103,7 @@ func createRoomHandler(c echo.Context) error {
|
||||||
|
|
||||||
// if cohosts are already registered, retrieve their data from DB
|
// if cohosts are already registered, retrieve their data from DB
|
||||||
for i, cohost := range room.CoHosts {
|
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 {
|
if err == nil {
|
||||||
room.CoHosts[i] = cohostUser
|
room.CoHosts[i] = cohostUser
|
||||||
}
|
}
|
||||||
|
|
11
schema.go
11
schema.go
|
@ -187,20 +187,15 @@ func createIndexes(ctx context.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(userIndexes) < 3 {
|
if len(userIndexes) < 4 {
|
||||||
_, err := userColl.Indexes().CreateMany(ctx, []mongo.IndexModel{
|
_, err := userColl.Indexes().CreateMany(ctx, []mongo.IndexModel{
|
||||||
{
|
{
|
||||||
Keys: bson.D{{Key: "audon_id", Value: 1}},
|
Keys: bson.D{{Key: "audon_id", Value: 1}},
|
||||||
Options: options.Index().SetUnique(true),
|
Options: options.Index().SetUnique(true),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Keys: bson.D{
|
Keys: bson.D{{Key: "webfinger", Value: 1}},
|
||||||
{Key: "remote_url", Value: 1},
|
Options: options.Index().SetUnique(true),
|
||||||
{Key: "remote_id", Value: 1},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Keys: bson.D{{Key: "webfinger", Value: 1}},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
2
user.go
2
user.go
|
@ -105,7 +105,7 @@ func (a *AudonUser) Equal(u *AudonUser) bool {
|
||||||
return false
|
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) {
|
func (a *AudonUser) InLivekit(ctx context.Context) (bool, error) {
|
||||||
|
|
Ładowanie…
Reference in New Issue