@@ -104,6 +104,25 @@ type QueryEventsByIDResponse struct {
104104 Events []gomatrixserverlib.Event `json:"events"`
105105}
106106
107+ // QueryMembershipForUserRequest is a request to QueryMembership
108+ type QueryMembershipForUserRequest struct {
109+ // ID of the room to fetch membership from
110+ RoomID string `json:"room_id"`
111+ // ID of the user sending the request
112+ Sender string `json:"sender"`
113+ }
114+
115+ // QueryMembershipForUserResponse is a response to QueryMembership
116+ type QueryMembershipForUserResponse struct {
117+ // The EventID of the latest "m.room.member" event for the sender,
118+ // if HasBeenInRoom is true.
119+ EventID string `json:"event_id"`
120+ // True if the user has been in room before and has either stayed in it or left it.
121+ HasBeenInRoom bool `json:"has_been_in_room"`
122+ // True if the user is in room.
123+ IsInRoom bool `json:"is_in_room"`
124+ }
125+
107126// QueryMembershipsForRoomRequest is a request to QueryMembershipsForRoom
108127type QueryMembershipsForRoomRequest struct {
109128 // If true, only returns the membership events of "join" membership
@@ -222,6 +241,13 @@ type RoomserverQueryAPI interface {
222241 response * QueryEventsByIDResponse ,
223242 ) error
224243
244+ // Query the membership event for an user for a room.
245+ QueryMembershipForUser (
246+ ctx context.Context ,
247+ request * QueryMembershipForUserRequest ,
248+ response * QueryMembershipForUserResponse ,
249+ ) error
250+
225251 // Query a list of membership events for a room
226252 QueryMembershipsForRoom (
227253 ctx context.Context ,
@@ -269,6 +295,9 @@ const RoomserverQueryStateAfterEventsPath = "/api/roomserver/queryStateAfterEven
269295// RoomserverQueryEventsByIDPath is the HTTP path for the QueryEventsByID API.
270296const RoomserverQueryEventsByIDPath = "/api/roomserver/queryEventsByID"
271297
298+ // RoomserverQueryMembershipForUserPath is the HTTP path for the QueryMembershipForUser API.
299+ const RoomserverQueryMembershipForUserPath = "/api/roomserver/queryMembershipForUser"
300+
272301// RoomserverQueryMembershipsForRoomPath is the HTTP path for the QueryMembershipsForRoom API
273302const RoomserverQueryMembershipsForRoomPath = "/api/roomserver/queryMembershipsForRoom"
274303
@@ -337,6 +366,19 @@ func (h *httpRoomserverQueryAPI) QueryEventsByID(
337366 return postJSON (ctx , span , h .httpClient , apiURL , request , response )
338367}
339368
369+ // QueryMembershipForUser implements RoomserverQueryAPI
370+ func (h * httpRoomserverQueryAPI ) QueryMembershipForUser (
371+ ctx context.Context ,
372+ request * QueryMembershipForUserRequest ,
373+ response * QueryMembershipForUserResponse ,
374+ ) error {
375+ span , ctx := opentracing .StartSpanFromContext (ctx , "QueryMembershipForUser" )
376+ defer span .Finish ()
377+
378+ apiURL := h .roomserverURL + RoomserverQueryMembershipForUserPath
379+ return postJSON (ctx , span , h .httpClient , apiURL , request , response )
380+ }
381+
340382// QueryMembershipsForRoom implements RoomserverQueryAPI
341383func (h * httpRoomserverQueryAPI ) QueryMembershipsForRoom (
342384 ctx context.Context ,
0 commit comments