kopia lustrzana https://codeberg.org/nmkj/audon
add room restriction
rodzic
b928a4a65e
commit
67492012d5
|
@ -46,11 +46,11 @@ export default {
|
||||||
relationship: "everyone",
|
relationship: "everyone",
|
||||||
relOptions: [
|
relOptions: [
|
||||||
{ title: "制限なし", value: "everyone" },
|
{ title: "制限なし", value: "everyone" },
|
||||||
{ title: "フォロー限定", value: "following" },
|
{ title: "あなたのフォロー限定", value: "following" },
|
||||||
{ title: "フォロワー限定", value: "follower" },
|
{ title: "あなたのフォロワー限定", value: "follower" },
|
||||||
{ title: "フォローまたはフォロワー限定", value: "knows" },
|
{ title: "あなたのフォローまたはフォロワー限定", value: "knowing" },
|
||||||
{ title: "相互フォロー限定", value: "mutual" },
|
{ title: "あなたの相互フォロー限定", value: "mutual" },
|
||||||
{ title: "非公開", value: "private" },
|
{ title: "共同ホスト限定", value: "private" },
|
||||||
],
|
],
|
||||||
scheduledAt: null,
|
scheduledAt: null,
|
||||||
searchResult: null,
|
searchResult: null,
|
||||||
|
@ -167,6 +167,7 @@ export default {
|
||||||
remote_id: u.id,
|
remote_id: u.id,
|
||||||
remote_url: u.url,
|
remote_url: u.url,
|
||||||
})),
|
})),
|
||||||
|
restriction: this.relationship
|
||||||
};
|
};
|
||||||
this.isSubmissionLoading = false;
|
this.isSubmissionLoading = false;
|
||||||
try {
|
try {
|
||||||
|
@ -266,8 +267,7 @@ export default {
|
||||||
:items="relOptions"
|
:items="relOptions"
|
||||||
label="入室制限"
|
label="入室制限"
|
||||||
v-model="relationship"
|
v-model="relationship"
|
||||||
disabled
|
:messages="['共同ホストは制限に関わらず入室できます']"
|
||||||
:messages="['今後のアップデートで追加予定']"
|
|
||||||
></v-select>
|
></v-select>
|
||||||
<v-text-field
|
<v-text-field
|
||||||
type="datetime-local"
|
type="datetime-local"
|
||||||
|
|
11
oauth.go
11
oauth.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -19,11 +20,13 @@ func verifyTokenInSession(c echo.Context) (bool, *mastodon.Account, error) {
|
||||||
return false, nil, err
|
return false, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.MastodonConfig.AccessToken == "" {
|
mastoClient, err := getMastodonClient(c)
|
||||||
|
if err != nil {
|
||||||
|
return false, nil, err
|
||||||
|
}
|
||||||
|
if mastoClient == nil {
|
||||||
return false, nil, nil
|
return false, nil, nil
|
||||||
}
|
}
|
||||||
mastoClient := mastodon.NewClient(data.MastodonConfig)
|
|
||||||
mastoClient.UserAgent = USER_AGENT
|
|
||||||
|
|
||||||
acc, err := mastoClient.GetAccountCurrentUser(c.Request().Context())
|
acc, err := mastoClient.GetAccountCurrentUser(c.Request().Context())
|
||||||
user, dbErr := findUserByID(c.Request().Context(), data.AudonID)
|
user, dbErr := findUserByID(c.Request().Context(), data.AudonID)
|
||||||
|
@ -146,10 +149,12 @@ 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)
|
||||||
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", acc.Username, acctUrl.Host),
|
||||||
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 {
|
||||||
|
|
35
room.go
35
room.go
|
@ -130,6 +130,41 @@ func joinRoomHandler(c echo.Context) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
canTalk := room.IsHost(user) || room.IsCoHost(user) // host and cohost can talk from the beginning
|
canTalk := room.IsHost(user) || room.IsCoHost(user) // host and cohost can talk from the beginning
|
||||||
|
|
||||||
|
// check room restriction
|
||||||
|
if room.IsPrivate() && !canTalk {
|
||||||
|
return ErrOperationNotPermitted
|
||||||
|
}
|
||||||
|
if !canTalk && (room.IsFollowingOnly() || room.IsFollowerOnly() || room.IsFollowingOrFollowerOnly() || room.IsMutualOnly()) {
|
||||||
|
mastoClient, _ := getMastodonClient(c)
|
||||||
|
if mastoClient == nil {
|
||||||
|
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
search, err := mastoClient.AccountsSearch(c.Request().Context(), room.Host.Webfinger, 1)
|
||||||
|
if err != nil {
|
||||||
|
c.Logger().Error(err)
|
||||||
|
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
if len(search) != 1 {
|
||||||
|
return ErrOperationNotPermitted
|
||||||
|
}
|
||||||
|
rels, err := mastoClient.GetAccountRelationships(c.Request().Context(), []string{string(search[0].ID)})
|
||||||
|
if err != nil {
|
||||||
|
c.Logger().Error(err)
|
||||||
|
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
if len(rels) != 1 {
|
||||||
|
return ErrOperationNotPermitted
|
||||||
|
}
|
||||||
|
rel := rels[0]
|
||||||
|
if (room.IsFollowingOnly() && !rel.FollowedBy) ||
|
||||||
|
(room.IsFollowerOnly() && !rel.Following) ||
|
||||||
|
(room.IsFollowingOrFollowerOnly() && !(rel.FollowedBy || rel.Following)) ||
|
||||||
|
(room.IsMutualOnly() && !(rel.FollowedBy && rel.Following)) {
|
||||||
|
return ErrOperationNotPermitted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
roomMetadata := &RoomMetadata{Room: room}
|
roomMetadata := &RoomMetadata{Room: room}
|
||||||
|
|
||||||
// Allows the user to talk if the user is a speaker
|
// Allows the user to talk if the user is a speaker
|
||||||
|
|
51
schema.go
51
schema.go
|
@ -23,6 +23,7 @@ type (
|
||||||
AudonID string `bson:"audon_id" json:"audon_id" validate:"alphanum"`
|
AudonID string `bson:"audon_id" json:"audon_id" validate:"alphanum"`
|
||||||
RemoteID string `bson:"remote_id" json:"remote_id" validate:"printascii"`
|
RemoteID string `bson:"remote_id" json:"remote_id" validate:"printascii"`
|
||||||
RemoteURL string `bson:"remote_url" json:"remote_url" validate:"url"`
|
RemoteURL string `bson:"remote_url" json:"remote_url" validate:"url"`
|
||||||
|
Webfinger string `bson:"webfinger" jsong:"webfinger" validate:"email"`
|
||||||
CreatedAt time.Time `bson:"created_at" json:"created_at"`
|
CreatedAt time.Time `bson:"created_at" json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,18 +33,16 @@ type (
|
||||||
}
|
}
|
||||||
|
|
||||||
Room struct {
|
Room struct {
|
||||||
RoomID string `bson:"room_id" json:"room_id" validate:"required,printascii"`
|
RoomID string `bson:"room_id" json:"room_id" validate:"required,printascii"`
|
||||||
Title string `bson:"title" json:"title" validate:"required,max=100,printascii|multibyte"`
|
Title string `bson:"title" json:"title" validate:"required,max=100,printascii|multibyte"`
|
||||||
Description string `bson:"description" json:"description" validate:"max=500,ascii|multibyte"`
|
Description string `bson:"description" json:"description" validate:"max=500,ascii|multibyte"`
|
||||||
Host *AudonUser `bson:"host" json:"host"`
|
Host *AudonUser `bson:"host" json:"host"`
|
||||||
CoHosts []*AudonUser `bson:"cohost" json:"cohosts"`
|
CoHosts []*AudonUser `bson:"cohost" json:"cohosts"`
|
||||||
FollowingOnly bool `bson:"following_only" json:"following_only"`
|
Restriction JoinRestriction `bsong:"restriction" json:"restriction"`
|
||||||
FollowerOnly bool `bson:"follower_only" json:"follower_only"`
|
Kicked []*AudonUser `bson:"kicked" json:"kicked"`
|
||||||
MutualOnly bool `bson:"mutual_only" json:"mutual_only"`
|
ScheduledAt time.Time `bson:"scheduled_at" json:"scheduled_at"`
|
||||||
Kicked []*AudonUser `bson:"kicked" json:"kicked"`
|
EndedAt time.Time `bson:"ended_at" json:"ended_at"`
|
||||||
ScheduledAt time.Time `bson:"scheduled_at" json:"scheduled_at"`
|
CreatedAt time.Time `bson:"created_at" json:"created_at"`
|
||||||
EndedAt time.Time `bson:"ended_at" json:"ended_at"`
|
|
||||||
CreatedAt time.Time `bson:"created_at" json:"created_at"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenResponse struct {
|
TokenResponse struct {
|
||||||
|
@ -53,9 +52,17 @@ type (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type JoinRestriction string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
COLLECTION_USER = "user"
|
COLLECTION_USER = "user"
|
||||||
COLLECTION_ROOM = "room"
|
COLLECTION_ROOM = "room"
|
||||||
|
|
||||||
|
FOLLOWING JoinRestriction = "following"
|
||||||
|
FOLLOWER JoinRestriction = "follower"
|
||||||
|
FOLLOWING_OR_FOLLOWER JoinRestriction = "knowing"
|
||||||
|
MUTUAL JoinRestriction = "mutual"
|
||||||
|
PRIVATE JoinRestriction = "private"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *AudonUser) Equal(u *AudonUser) bool {
|
func (a *AudonUser) Equal(u *AudonUser) bool {
|
||||||
|
@ -66,6 +73,26 @@ func (a *AudonUser) Equal(u *AudonUser) bool {
|
||||||
return a.AudonID == u.AudonID || (a.RemoteID == u.RemoteID && a.RemoteURL == u.RemoteURL)
|
return a.AudonID == u.AudonID || (a.RemoteID == u.RemoteID && a.RemoteURL == u.RemoteURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Room) IsFollowingOnly() bool {
|
||||||
|
return r.Restriction == FOLLOWING
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Room) IsFollowerOnly() bool {
|
||||||
|
return r.Restriction == FOLLOWER
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Room) IsFollowingOrFollowerOnly() bool {
|
||||||
|
return r.Restriction == FOLLOWING_OR_FOLLOWER
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Room) IsMutualOnly() bool {
|
||||||
|
return r.Restriction == MUTUAL
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Room) IsPrivate() bool {
|
||||||
|
return r.Restriction == PRIVATE
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Room) IsCoHost(u *AudonUser) bool {
|
func (r *Room) IsCoHost(u *AudonUser) bool {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return false
|
return false
|
||||||
|
|
12
utils.go
12
utils.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
mastodon "github.com/mattn/go-mastodon"
|
mastodon "github.com/mattn/go-mastodon"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -71,3 +72,14 @@ func registerApp(ctx context.Context, appConfig *mastodon.AppConfig) (*mastodon.
|
||||||
|
|
||||||
return &app, nil
|
return &app, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getMastodonClient(c echo.Context) (*mastodon.Client, error) {
|
||||||
|
data, err := getSessionData(c)
|
||||||
|
if err != nil || data.MastodonConfig.AccessToken == "" {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mastoClient := mastodon.NewClient(data.MastodonConfig)
|
||||||
|
mastoClient.UserAgent = USER_AGENT
|
||||||
|
|
||||||
|
return mastoClient, nil
|
||||||
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue