Esempio n. 1
0
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{}{}
}
Esempio n. 2
0
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}
}