kopia lustrzana https://codeberg.org/nmkj/audon
add room restriction
rodzic
b928a4a65e
commit
67492012d5
|
@ -46,11 +46,11 @@ export default {
|
|||
relationship: "everyone",
|
||||
relOptions: [
|
||||
{ title: "制限なし", value: "everyone" },
|
||||
{ title: "フォロー限定", value: "following" },
|
||||
{ title: "フォロワー限定", value: "follower" },
|
||||
{ title: "フォローまたはフォロワー限定", value: "knows" },
|
||||
{ title: "相互フォロー限定", value: "mutual" },
|
||||
{ title: "非公開", value: "private" },
|
||||
{ title: "あなたのフォロー限定", value: "following" },
|
||||
{ title: "あなたのフォロワー限定", value: "follower" },
|
||||
{ title: "あなたのフォローまたはフォロワー限定", value: "knowing" },
|
||||
{ title: "あなたの相互フォロー限定", value: "mutual" },
|
||||
{ title: "共同ホスト限定", value: "private" },
|
||||
],
|
||||
scheduledAt: null,
|
||||
searchResult: null,
|
||||
|
@ -167,6 +167,7 @@ export default {
|
|||
remote_id: u.id,
|
||||
remote_url: u.url,
|
||||
})),
|
||||
restriction: this.relationship
|
||||
};
|
||||
this.isSubmissionLoading = false;
|
||||
try {
|
||||
|
@ -266,8 +267,7 @@ export default {
|
|||
:items="relOptions"
|
||||
label="入室制限"
|
||||
v-model="relationship"
|
||||
disabled
|
||||
:messages="['今後のアップデートで追加予定']"
|
||||
:messages="['共同ホストは制限に関わらず入室できます']"
|
||||
></v-select>
|
||||
<v-text-field
|
||||
type="datetime-local"
|
||||
|
|
11
oauth.go
11
oauth.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
@ -19,11 +20,13 @@ func verifyTokenInSession(c echo.Context) (bool, *mastodon.Account, error) {
|
|||
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
|
||||
}
|
||||
mastoClient := mastodon.NewClient(data.MastodonConfig)
|
||||
mastoClient.UserAgent = USER_AGENT
|
||||
|
||||
acc, err := mastoClient.GetAccountCurrentUser(c.Request().Context())
|
||||
user, dbErr := findUserByID(c.Request().Context(), data.AudonID)
|
||||
|
@ -146,10 +149,12 @@ func oauthHandler(c echo.Context) (err error) {
|
|||
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||
}
|
||||
data.AudonID = id.String()
|
||||
acctUrl, _ := url.Parse(acc.URL)
|
||||
newUser := AudonUser{
|
||||
AudonID: data.AudonID,
|
||||
RemoteID: string(acc.ID),
|
||||
RemoteURL: acc.URL,
|
||||
Webfinger: fmt.Sprintf("%s@%s", acc.Username, acctUrl.Host),
|
||||
CreatedAt: time.Now().UTC(),
|
||||
}
|
||||
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
|
||||
|
||||
// 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}
|
||||
|
||||
// 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"`
|
||||
RemoteID string `bson:"remote_id" json:"remote_id" validate:"printascii"`
|
||||
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"`
|
||||
}
|
||||
|
||||
|
@ -32,18 +33,16 @@ type (
|
|||
}
|
||||
|
||||
Room struct {
|
||||
RoomID string `bson:"room_id" json:"room_id" validate:"required,printascii"`
|
||||
Title string `bson:"title" json:"title" validate:"required,max=100,printascii|multibyte"`
|
||||
Description string `bson:"description" json:"description" validate:"max=500,ascii|multibyte"`
|
||||
Host *AudonUser `bson:"host" json:"host"`
|
||||
CoHosts []*AudonUser `bson:"cohost" json:"cohosts"`
|
||||
FollowingOnly bool `bson:"following_only" json:"following_only"`
|
||||
FollowerOnly bool `bson:"follower_only" json:"follower_only"`
|
||||
MutualOnly bool `bson:"mutual_only" json:"mutual_only"`
|
||||
Kicked []*AudonUser `bson:"kicked" json:"kicked"`
|
||||
ScheduledAt time.Time `bson:"scheduled_at" json:"scheduled_at"`
|
||||
EndedAt time.Time `bson:"ended_at" json:"ended_at"`
|
||||
CreatedAt time.Time `bson:"created_at" json:"created_at"`
|
||||
RoomID string `bson:"room_id" json:"room_id" validate:"required,printascii"`
|
||||
Title string `bson:"title" json:"title" validate:"required,max=100,printascii|multibyte"`
|
||||
Description string `bson:"description" json:"description" validate:"max=500,ascii|multibyte"`
|
||||
Host *AudonUser `bson:"host" json:"host"`
|
||||
CoHosts []*AudonUser `bson:"cohost" json:"cohosts"`
|
||||
Restriction JoinRestriction `bsong:"restriction" json:"restriction"`
|
||||
Kicked []*AudonUser `bson:"kicked" json:"kicked"`
|
||||
ScheduledAt time.Time `bson:"scheduled_at" json:"scheduled_at"`
|
||||
EndedAt time.Time `bson:"ended_at" json:"ended_at"`
|
||||
CreatedAt time.Time `bson:"created_at" json:"created_at"`
|
||||
}
|
||||
|
||||
TokenResponse struct {
|
||||
|
@ -53,9 +52,17 @@ type (
|
|||
}
|
||||
)
|
||||
|
||||
type JoinRestriction string
|
||||
|
||||
const (
|
||||
COLLECTION_USER = "user"
|
||||
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 {
|
||||
|
@ -66,6 +73,26 @@ func (a *AudonUser) Equal(u *AudonUser) bool {
|
|||
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 {
|
||||
if r == nil {
|
||||
return false
|
||||
|
|
12
utils.go
12
utils.go
|
@ -9,6 +9,7 @@ import (
|
|||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
mastodon "github.com/mattn/go-mastodon"
|
||||
)
|
||||
|
||||
|
@ -71,3 +72,14 @@ func registerApp(ctx context.Context, appConfig *mastodon.AppConfig) (*mastodon.
|
|||
|
||||
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