当前位置: 首页>>代码示例>>Golang>>正文


Golang types.MembershipEventContent类代码示例

本文整理汇总了Golang中github.com/matrix-org/bullettime/matrix/types.MembershipEventContent的典型用法代码示例。如果您正苦于以下问题:Golang MembershipEventContent类的具体用法?Golang MembershipEventContent怎么用?Golang MembershipEventContent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MembershipEventContent类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: doWildcardJoin

func (e roomsEndpoint) doWildcardJoin(req *http.Request, params httprouter.Params) interface{} {
	user, err := readAccessToken(e.userService, e.tokenService, req)
	if err != nil {
		return err
	}
	roomIdOrAlias := params[0].Value
	room, parseErr := ct.ParseRoomId(roomIdOrAlias)
	if parseErr != nil {
		alias, parseErr := ct.ParseAlias(roomIdOrAlias)
		if parseErr != nil {
			return types.BadParamError("invalid room id or alias: " + roomIdOrAlias)
		}
		room, err = e.roomService.LookupAlias(alias)
		if err != nil {
			return err
		}
	}
	content := types.MembershipEventContent{}
	content.Membership = types.MembershipMember
	_, err = e.roomService.SetState(room, user, &content, user.String())
	if err != nil {
		return err
	}
	return struct{}{}
}
开发者ID:rezacute,项目名称:bullettime,代码行数:25,代码来源:rooms.go

示例2: doLeave

func (e roomsEndpoint) doLeave(req *http.Request, params httprouter.Params) interface{} {
	room, user, err := e.getRoomAndUser(req, params)
	if err != nil {
		return err
	}
	content := types.MembershipEventContent{}
	content.Membership = types.MembershipLeaving
	state, err := e.roomService.SetState(room, user, &content, user.String())
	if err != nil {
		return err
	}
	return eventIdResponse{state.EventId}
}
开发者ID:rezacute,项目名称:bullettime,代码行数:13,代码来源:rooms.go

示例3: doMembershipChange

func (s roomService) doMembershipChange(
	room ct.RoomId,
	caller ct.UserId,
	user ct.UserId,
	membership *types.MembershipEventContent,
) (*types.State, types.Error) {
	log.Printf("attempting membership change of %s in %s to %s, by %s", user, room, membership.Membership, caller)
	currentMembership, err := s.userMembership(room, user)
	if err != nil {
		return nil, err
	}
	if currentMembership == membership.Membership {
		return nil, types.ForbiddenError("membership change was a no-op")
	}
	membership.UserProfile = nil

	switch membership.Membership {
	case types.MembershipNone:
		if currentMembership != types.MembershipBanned {
			return nil, types.BadJsonError("invalid or missing membership in membership change")
		}
		err = s.testPowerLevel(room, caller, func(pl *types.PowerLevelsEventContent) int {
			return pl.Ban
		})
		if err != nil {
			return nil, err
		}
		if user == caller {
			return nil, types.ForbiddenError("cannot remove a ban from self")
		}

	case types.MembershipInvited:
		if currentMembership != types.MembershipNone {
			return nil, types.ForbiddenError("could not invite user to room, already have membership '" + currentMembership.String() + "'")
		}
		ok, err := s.allowsJoinRule(room, types.JoinRuleInvite)
		if err != nil {
			return nil, err
		}
		if !ok {
			return nil, types.ForbiddenError("room does not allow join method: " + types.JoinRuleInvite.String())
		}
		err = s.testPowerLevel(room, caller, func(pl *types.PowerLevelsEventContent) int {
			return pl.Invite
		})
		if err != nil {
			return nil, err
		}

	case types.MembershipMember:
		switch currentMembership {
		case types.MembershipNone:
			ok, err := s.allowsJoinRule(room, types.JoinRulePublic)
			if err != nil {
				return nil, err
			}
			if !ok {
				return nil, types.ForbiddenError("room does not allow join method: " + types.JoinRuleInvite.String())
			}
		case types.MembershipInvited:
			if user != caller {
				return nil, types.ForbiddenError("cannot force other users to join the room")
			}
		case types.MembershipKnocking:
			if user == caller {
				return nil, types.ForbiddenError("cannot let yourself in after knocking")
			}
			err = s.testPowerLevel(room, caller, func(pl *types.PowerLevelsEventContent) int {
				return pl.Invite
			})
			if err != nil {
				return nil, err
			}
		case types.MembershipBanned:
			if user == caller {
				return nil, types.ForbiddenError("you are banned from that room")
			} else {
				return nil, types.ForbiddenError("that user is banned from this room")
			}
		}
		profile, err := s.profileProvider.Profile(caller)
		if err != nil {
			return nil, err
		}
		membership.UserProfile = &profile

	case types.MembershipKnocking:
		if user != caller {
			return nil, types.ForbiddenError("cannot force other users to knock")
		}
		if currentMembership != types.MembershipNone {
			return nil, types.ForbiddenError("could not knock on room, already have membership '" + currentMembership.String() + "'")
		}
		ok, err := s.allowsJoinRule(room, types.JoinRuleKnock)
		if err != nil {
			return nil, err
		}
		if !ok {
			return nil, types.ForbiddenError("room does not allow join method: " + types.JoinRuleKnock.String())
		}
//.........这里部分代码省略.........
开发者ID:Rugvip,项目名称:bullettime,代码行数:101,代码来源:rooms.go


注:本文中的github.com/matrix-org/bullettime/matrix/types.MembershipEventContent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。