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

Method roomName

userapi/consumers/syncapi_streamevent.go:223–265  ·  view source on GitHub ↗

roomName returns the name in the event (if type==m.room.name), or looks it up in roomserver. If there is no name, m.room.canonical_alias is consulted. Returns an empty string if the room has no name.

(ctx context.Context, event *gomatrixserverlib.HeaderedEvent)

Source from the content-addressed store, hash-verified

221// m.room.canonical_alias is consulted. Returns an empty string if the
222// room has no name.
223func (s *OutputStreamEventConsumer) roomName(ctx context.Context, event *gomatrixserverlib.HeaderedEvent) (string, error) {
224 if event.Type() == gomatrixserverlib.MRoomName {
225 name, err := unmarshalRoomName(event)
226 if err != nil {
227 return "", err
228 }
229
230 if name != "" {
231 return name, nil
232 }
233 }
234
235 req := &rsapi.QueryCurrentStateRequest{
236 RoomID: event.RoomID(),
237 StateTuples: []gomatrixserverlib.StateKeyTuple{roomNameTuple, canonicalAliasTuple},
238 }
239 var res rsapi.QueryCurrentStateResponse
240
241 if err := s.rsAPI.QueryCurrentState(ctx, req, &res); err != nil {
242 return "", nil
243 }
244
245 if eventS := res.StateEvents[roomNameTuple]; eventS != nil {
246 return unmarshalRoomName(eventS)
247 }
248
249 if event.Type() == gomatrixserverlib.MRoomCanonicalAlias {
250 alias, err := unmarshalCanonicalAlias(event)
251 if err != nil {
252 return "", err
253 }
254
255 if alias != "" {
256 return alias, nil
257 }
258 }
259
260 if event = res.StateEvents[canonicalAliasTuple]; event != nil {
261 return unmarshalCanonicalAlias(event)
262 }
263
264 return "", nil
265}
266
267var (
268 canonicalAliasTuple = gomatrixserverlib.StateKeyTuple{EventType: gomatrixserverlib.MRoomCanonicalAlias}

Callers 1

processMessageMethod · 0.95

Calls 3

unmarshalRoomNameFunction · 0.85
unmarshalCanonicalAliasFunction · 0.85
QueryCurrentStateMethod · 0.65

Tested by

no test coverage detected