MCPcopy Create free account
hub / github.com/daodst/chat / SendKick

Function SendKick

clientapi/routing/membership.go:127–165  ·  view source on GitHub ↗
(
	req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device,
	roomID string, cfg *config.ClientAPI,
	rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceInternalAPI,
)

Source from the content-addressed store, hash-verified

125}
126
127func SendKick(
128 req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device,
129 roomID string, cfg *config.ClientAPI,
130 rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceInternalAPI,
131) util.JSONResponse {
132 body, evTime, roomVer, reqErr := extractRequestData(req, roomID, rsAPI)
133 if reqErr != nil {
134 return *reqErr
135 }
136 if body.UserID == "" {
137 return util.JSONResponse{
138 Code: 400,
139 JSON: jsonerror.BadJSON("missing user_id"),
140 }
141 }
142
143 errRes := checkMemberInRoom(req.Context(), rsAPI, device.UserID, roomID)
144 if errRes != nil {
145 return *errRes
146 }
147
148 var queryRes roomserverAPI.QueryMembershipForUserResponse
149 err := rsAPI.QueryMembershipForUser(req.Context(), &roomserverAPI.QueryMembershipForUserRequest{
150 RoomID: roomID,
151 UserID: body.UserID,
152 }, &queryRes)
153 if err != nil {
154 return util.ErrorResponse(err)
155 }
156 // kick is only valid if the user is not currently banned or left (that is, they are joined or invited)
157 if queryRes.Membership != "join" && queryRes.Membership != "invite" {
158 return util.JSONResponse{
159 Code: 403,
160 JSON: jsonerror.Unknown("cannot /kick banned or left users"),
161 }
162 }
163 // TODO: should we be using SendLeave instead?
164 return sendMembership(req.Context(), profileAPI, device, roomID, "leave", body.Reason, cfg, body.UserID, evTime, roomVer, rsAPI, asAPI)
165}
166
167func SendUnban(
168 req *http.Request, profileAPI userapi.ClientUserAPI, device *userapi.Device,

Callers 1

SetupFunction · 0.85

Calls 5

extractRequestDataFunction · 0.85
checkMemberInRoomFunction · 0.85
sendMembershipFunction · 0.85
ContextMethod · 0.80

Tested by

no test coverage detected