/// <summary> /// Return a joined room object by it's roomid. /// </summary> /// <returns>The room.</returns> /// <param name="roomid">Roomid.</param> public MatrixRoom GetRoom(string roomid) //TODO: Maybe add a try method. { MatrixRoom room = null; rooms.TryGetValue(roomid, out room); return(room); }
/// <summary> /// Creates a new room with the specified details, or a blank one otherwise. /// </summary> /// <returns>A MatrixRoom object</returns> /// <param name="roomdetails">Optional set of options to send to the server.</param> public MatrixRoom CreateRoom(MatrixCreateRoom roomdetails = null) { string roomid = api.ClientCreateRoom(roomdetails); if (roomid != null) { MatrixRoom room = JoinRoom(roomid); return(room); } return(null); }
/// <summary> /// Join a matrix room. If the user has already joined this room, do nothing. /// </summary> /// <returns>The room.</returns> /// <param name="roomid">roomid or alias</param> public MatrixRoom JoinRoom(string roomid) //TODO: Maybe add a try method. { if (!rooms.ContainsKey(roomid)) //TODO: Check the status of the room too. { roomid = api.ClientJoin(roomid); if (roomid == null) { return(null); } MatrixRoom room = new MatrixRoom(api, roomid); rooms.TryAdd(room.ID, room); } return(rooms [roomid]); }
private void MatrixClient_OnEvent(string roomid, MatrixEventRoomJoined joined) { MatrixRoom mroom; if (!rooms.ContainsKey(roomid)) { mroom = new MatrixRoom(api, roomid); rooms.TryAdd(roomid, mroom); //Update existing room } else { mroom = rooms [roomid]; } joined.state.events.ToList().ForEach(x => { mroom.FeedEvent(x); }); joined.timeline.events.ToList().ForEach(x => { mroom.FeedEvent(x); }); mroom.SetEphemeral(joined.ephemeral); }
/// <summary> /// Get a room object by any of it's registered aliases. /// </summary> /// <returns>The room by alias.</returns> /// <param name="alias">CanonicalAlias or any Alias</param> public MatrixRoom GetRoomByAlias(string alias) { MatrixRoom room = rooms.Values.FirstOrDefault(x => { if (x.CanonicalAlias == alias) { return(true); } else if (x.Aliases != null) { return(x.Aliases.Contains(alias)); } return(false); }); if (room != default(MatrixRoom)) { return(room); } else { return(null); } }