public void ClientSync(bool ConnectionFailureTimeout = false) { ThrowIfNotSupported(); string url = "/_matrix/client/r0/sync?timeout=" + SyncTimeout; if (!String.IsNullOrEmpty(syncToken)) { url += "&since=" + syncToken; } MatrixRequestError error = mbackend.Get(url, true, out var response); if (error.IsOk) { try { MatrixSync sync = JsonConvert.DeserializeObject <MatrixSync> (response.ToString(), event_converter); ProcessSync(sync); IsConnected = true; } catch (Exception e) { Console.WriteLine(e.InnerException); throw new MatrixException("Could not decode sync", e); } } else if (ConnectionFailureTimeout) { IsConnected = false; Console.Error.WriteLine("Couldn't reach the matrix home server during a sync."); Console.Error.WriteLine(error.ToString()); Thread.Sleep(BadSyncTimeout); } if (RunningInitialSync) { RunningInitialSync = false; } }
public PublicRooms PublicRooms(int limit, string since, string server) { ThrowIfNotSupported(); var qs = HttpUtility.ParseQueryString(string.Empty); if (limit != 0) { qs.Set("limit", limit.ToString()); } if (since != "") { qs.Set("since", since); } if (server != "") { qs.Set("server", server); } MatrixRequestError error = mbackend.Get($"/_matrix/client/r0/publicRooms?{qs}", true, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); } return(result.ToObject <PublicRooms>()); }
public void DeleteFromRoomDirectory(string alias) { MatrixRequestError error = mbackend.Delete($"/_matrix/client/r0/directory/room/{alias}", true, out var _); if (!error.IsOk) { throw new MatrixException(error.ToString()); } }
public void RoomLeave(string roomid) { MatrixRequestError error = mbackend.Post(String.Format("/_matrix/client/r0/rooms/{0}/leave", System.Uri.EscapeDataString(roomid)), true, null, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); } }
public ChunkedMessages GetRoomMessages(string roomId) { MatrixRequestError error = mbackend.Get($"/_matrix/client/r0/rooms/{roomId}/messages?limit=100&dir=b", true, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); } return(JsonConvert.DeserializeObject <ChunkedMessages> (result.ToString(), event_converter)); }
public List <string> GetJoinedRooms() { MatrixRequestError error = mbackend.Get("/_matrix/client/r0/joined_rooms", true, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); } return((result as JObject)?.GetValue("joined_rooms").ToObject <List <string> >()); }
public MatrixLoginResponse ClientLogin(MatrixLogin login) { MatrixRequestError error = mbackend.Post("/_matrix/client/r0/login", false, JObject.FromObject(login), out var result); if (error.IsOk) { return(result.ToObject <MatrixLoginResponse> ()); } throw new MatrixException(error.ToString()); //TODO: Need a better exception }
public Dictionary <string, MatrixProfile> GetJoinedMembers(string roomId) { MatrixRequestError error = mbackend.Get($"/_matrix/client/r0/rooms/{roomId}/joined_members", true, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); } return((result as JObject)?.GetValue("joined").ToObject <Dictionary <string, MatrixProfile> >()); }
public void InviteToRoom(string roomid, string userid) { JObject msgData = JObject.FromObject(new { user_id = userid }); MatrixRequestError error = mbackend.Post(String.Format("/_matrix/client/r0/rooms/{0}/invite", System.Uri.EscapeDataString(roomid)), true, msgData, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); //TODO: Need a better exception } }
public virtual void RoomStateSend(string roomid, string type, MatrixRoomStateEvent message, string key = "") { JObject msgData = ObjectToJson(message); MatrixRequestError error = mbackend.Put(String.Format("/_matrix/client/r0/rooms/{0}/state/{1}/{2}", System.Uri.EscapeDataString(roomid), type, key), true, msgData, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); //TODO: Need a better exception } }
public RoomTags RoomGetTags(string roomid) { MatrixRequestError error = mbackend.Get($"/_matrix/client/r0/user/{user_id}/rooms/{roomid}/tags", true, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); } return(result.ToObject <RoomTags>()); }
public MatrixEvent[] GetRoomState(string roomId) { ThrowIfNotSupported(); MatrixRequestError error = mbackend.Get($"/_matrix/client/r0/rooms/{roomId}/state", true, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); } return(JsonConvert.DeserializeObject <MatrixEvent[]> (result.ToString(), event_converter)); }
public void RoomPutTag(string roomid, string tag, double order) { JObject req = new JObject(); req["order"] = order; MatrixRequestError error = mbackend.Put($"/_matrix/client/r0/user/{user_id}/rooms/{roomid}/tags/{tag}", true, req, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); } }
public void ClientSetAvatar(string userid, string avatar_url) { JObject request = new JObject(); request.Add("avatar_url", JToken.FromObject(avatar_url)); MatrixRequestError error = mbackend.Put(string.Format("/_matrix/client/r0/profile/{0}/avatar_url", Uri.EscapeUriString(userid)), true, request, out var response); if (!error.IsOk) { throw new MatrixException(error.ToString()); //TODO: Need a better exception } }
public virtual string RoomStateSend(string roomid, string type, MatrixRoomStateEvent message, string key = "") { ThrowIfNotSupported(); JObject msgData = ObjectToJson(message); MatrixRequestError error = mbackend.Put(String.Format("/_matrix/client/r0/rooms/{0}/state/{1}/{2}", Uri.EscapeDataString(roomid), type, key), true, msgData, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); //TODO: Need a better exception } return(result["event_id"].ToObject <string>()); }
public MemoryStream MediaDownload(string serverName, string contentId) { MemoryStream result = new MemoryStream(); var url = String.Format("/_matrix/media/r0/download/{0}/{1}", serverName, contentId); MatrixRequestError error = mbackend.GetBlob(url, false, out result); if (!error.IsOk) { throw new MatrixException(error.ToString()); //TODO: Need a better exception } return(result); }
public MatrixEventContent GetRoomStateType(string roomId, string type) { ThrowIfNotSupported(); MatrixRequestError error = mbackend.Get($"/_matrix/client/r0/rooms/{roomId}/state/{type}/", true, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); } return(event_converter.GetContent(result as JObject, new JsonSerializer(), type)); }
public string MediaUpload(string contentType, byte[] data) { MatrixRequestError error = mbackend.Post("/_matrix/media/r0/upload", true, data, new Dictionary <string, string>() { { "Content-Type", contentType } }, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); } return((result as JObject)?.GetValue("content_uri").ToObject <string>()); }
public MatrixVersions ClientVersions() { MatrixRequestError error = mbackend.Get("/_matrix/client/versions", false, out var result); if (error.IsOk) { var res = result.ToObject <MatrixVersions>(); versions = res; return(res); } throw new MatrixException(error.ToString()); //TODO: Need a better exception }
public void ClientSetDisplayName(string userid, string displayname) { JObject response; JObject request = new JObject(); request.Add("displayname", JToken.FromObject(displayname)); MatrixRequestError error = mbackend.Put(string.Format("/_matrix/client/r0/profile/{0}/displayname", Uri.EscapeUriString(userid)), true, request, out response); if (!error.IsOk) { throw new MatrixException(error.ToString()); //TODO: Need a better exception } }
public string MediaUpload(string contentType, byte[] data) { JObject result = new JObject(); MatrixRequestError error = mbackend.Post("/_matrix/media/r0/upload", true, data, new Dictionary <string, string>() { { "Content-Type", contentType } }, out result); if (!error.IsOk) { throw new MatrixException(error.ToString()); //TODO: Need a better exception } return(result.GetValue("content_uri").ToObject <string>()); }
public void ClientLogin(MatrixLogin login) { JObject result; MatrixRequestError error = mbackend.Post("/_matrix/client/r0/login", false, JObject.FromObject(login), out result); if (error.IsOk) { current_login = result.ToObject <MatrixLoginResponse> (); SetLogin(current_login); } else { throw new MatrixException(error.ToString()); //TODO: Need a better exception } }
public void RegisterUserAsAS(string user) { if (!IsAS) { throw new MatrixException("This client is not registered as a application service client. You can't create new appservice users"); } JObject request = JObject.FromObject(new { type = "m.login.application_service", user = user }); MatrixRequestError error = mbackend.Post("/_matrix/client/r0/register", true, request, out var result); if (!error.IsOk) { throw new MatrixException(error.ToString()); //TODO: Need a better exception } }
public void RoomTypingSend(string roomid, bool typing, int timeout = 0) { JObject msgData; if (timeout == 0) { msgData = JObject.FromObject(new { typing = typing }); } else { msgData = JObject.FromObject(new { typing = typing, timeout = timeout }); } MatrixRequestError error = mbackend.Put( $"/_matrix/client/r0/rooms/{System.Uri.EscapeDataString(roomid)}/typing/{System.Uri.EscapeDataString(user_id)}", true, msgData, out _); if (!error.IsOk) { throw new MatrixException(error.ToString()); } }
public void RoomTypingSend(string roomid, bool typing, int timeout = 0) { JObject msgData; JObject result; if (timeout == 0) { msgData = JObject.FromObject(new { typing = typing }); } else { msgData = JObject.FromObject(new { typing = typing, timeout = timeout }); } MatrixRequestError error = mbackend.Put(String.Format("/_matrix/client/r0/rooms/{0}/typing/{1}", System.Uri.EscapeDataString(roomid), System.Uri.EscapeDataString(user_id)), true, msgData, out result); if (!error.IsOk) { throw new MatrixException(error.ToString()); //TODO: Need a better exception } }