Browse Source

TODO: room joining

master
Claire 4 years ago
parent
commit
1364c49850
  1. BIN
      MatrixDotNetLib/.vs/MatrixDotNetLib/DesignTimeBuild/.dtbcache.v2
  2. BIN
      MatrixDotNetLib/.vs/MatrixDotNetLib/v16/.suo
  3. 4
      MatrixDotNetLib/MatrixDotNetCmd/MatrixDotNetCmd.csproj
  4. 76
      MatrixDotNetLib/MatrixDotNetCmd/Program.cs
  5. BIN
      MatrixDotNetLib/MatrixDotNetCmd/obj/Debug/netcoreapp3.1/MatrixDotNetCmd.assets.cache
  6. BIN
      MatrixDotNetLib/MatrixDotNetCmd/obj/Debug/netcoreapp3.1/MatrixDotNetCmd.csprojAssemblyReference.cache
  7. 6
      MatrixDotNetLib/MatrixDotNetCmd/obj/MatrixDotNetCmd.csproj.nuget.dgspec.json
  8. 1311
      MatrixDotNetLib/MatrixDotNetCmd/obj/project.assets.json
  9. 22
      MatrixDotNetLib/MatrixDotNetCmd/obj/project.nuget.cache
  10. 36
      MatrixDotNetLib/MatrixDotNetLib/MatrixApis.cs
  11. 16
      MatrixDotNetLib/MatrixDotNetLib/MatrixRoom.cs
  12. 22
      MatrixDotNetLib/MatrixDotNetLib/MatrixRoomDirectory.cs
  13. 37
      MatrixDotNetLib/MatrixDotNetLib/MatrixRoomEntry.cs
  14. 43
      MatrixDotNetLib/MatrixDotNetLib/MatrixSessionManager.cs
  15. BIN
      MatrixDotNetLib/MatrixDotNetLib/bin/Debug/netcoreapp3.1/MatrixDotNetLib.dll
  16. BIN
      MatrixDotNetLib/MatrixDotNetLib/bin/Debug/netcoreapp3.1/MatrixDotNetLib.pdb
  17. 2
      MatrixDotNetLib/MatrixDotNetLib/obj/Debug/netcoreapp3.1/MatrixDotNetLib.csproj.CoreCompileInputs.cache
  18. BIN
      MatrixDotNetLib/MatrixDotNetLib/obj/Debug/netcoreapp3.1/MatrixDotNetLib.csprojAssemblyReference.cache
  19. BIN
      MatrixDotNetLib/MatrixDotNetLib/obj/Debug/netcoreapp3.1/MatrixDotNetLib.dll
  20. BIN
      MatrixDotNetLib/MatrixDotNetLib/obj/Debug/netcoreapp3.1/MatrixDotNetLib.pdb

BIN
MatrixDotNetLib/.vs/MatrixDotNetLib/DesignTimeBuild/.dtbcache.v2

diff.bin_not_shown

BIN
MatrixDotNetLib/.vs/MatrixDotNetLib/v16/.suo

diff.bin_not_shown

4
MatrixDotNetLib/MatrixDotNetCmd/MatrixDotNetCmd.csproj

@ -5,6 +5,10 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Collections.Specialized" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MatrixDotNetLib\MatrixDotNetLib.csproj" />
</ItemGroup>

76
MatrixDotNetLib/MatrixDotNetCmd/Program.cs

@ -1,4 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
@ -66,7 +69,7 @@ namespace MatrixDotNetCmd
Console.WriteLine("Logged in!");
// show the room menu
RoomMenu();
RoomMenu(false);
}
catch(Exception ex)
{
@ -77,18 +80,57 @@ namespace MatrixDotNetCmd
Console.WriteLine(ex.Message);
}
void RoomMenu()
void RoomMenu(bool getPublic)
{
MatrixUserRooms rooms = session.GetRooms();
// prompt user to choose a room
// i guess we should find an alias for each room, if it exists
string roomList = "Select a room:";
List<string> rooms = new List<string>();
OrderedDictionary roomz = new OrderedDictionary();
for (int i = 0; i < rooms.Joined.Count(); i++)
if(getPublic)
{
// get public room directory
MatrixRoomDirectory pubRooms = session.GetPublicRooms();
// display first page of rooms
// I might complete this but rn I do not care enough
foreach(MatrixRoomEntry rm in pubRooms.Rooms)
{
if (rm.Alias != null)
{
rooms.Add(rm.Alias);
roomz.Add(rm.RoomId, rm.Alias);
}
else if (rm.Aliases != null)
{
rooms.Add(rm.Aliases.First());
roomz.Add(rm.RoomId, rm.Aliases.First());
}
else
{
rooms.Add(rm.RoomId);
roomz.Add(rm.RoomId, rm.RoomId);
}
}
}
else
{
string roomId = rooms.Joined[i];
MatrixUserRooms urooms = session.GetRooms();
foreach(string room in urooms.Joined)
{
roomz.Add(room, room);
}
rooms = urooms.Joined.ToList<string>();
}
for (int i = 0; i < rooms.Count(); i++)
{
string roomId = rooms[i];
// get the aliases for the room
MatrixRoomAliases roomAliases = session.GetRoomAliases(roomId);
@ -99,19 +141,20 @@ namespace MatrixDotNetCmd
else
{
roomList += "\n[" + i + "] " + roomAliases.Aliases[0];
roomz[roomId] = roomAliases.Aliases[0];
}
}
roomList += "\n";
//roomList += "\n\n";
Console.Write(roomList);
Console.WriteLine(roomList);
string roomListItem = Console.ReadLine();
if (roomListItem.Trim() == "")
{
// user didn't select a room, now what?
Console.WriteLine("You didn't select a room. Type /join #roomId to join a room, or /join to view a list of public rooms.");
Console.WriteLine("You didn't select a room. Type /join #roomId to join a room, /join to view a list of public rooms, or /mine to view a list of your joined rooms");
string stdIn = Console.ReadLine();
SlashInput(stdIn);
}
@ -119,7 +162,12 @@ namespace MatrixDotNetCmd
{
int roomListInt = Convert.ToInt32(roomListItem);
string theRoomId = rooms.Joined[roomListInt];
string theRoomId = roomz.Cast<DictionaryEntry>().ElementAt(1).Key.ToString();
string theRoomAlias = roomz[roomListInt].ToString();
// now we can join the room or something
}
}
@ -129,9 +177,13 @@ namespace MatrixDotNetCmd
switch (stdIn)
{
case "/join":
RoomMenu();
RoomMenu(true);
break;
case "/mine":
RoomMenu(false);
break;
case "":
case "/quit":
System.Environment.Exit(0);
break;
}
}

BIN
MatrixDotNetLib/MatrixDotNetCmd/obj/Debug/netcoreapp3.1/MatrixDotNetCmd.assets.cache

diff.bin_not_shown

BIN
MatrixDotNetLib/MatrixDotNetCmd/obj/Debug/netcoreapp3.1/MatrixDotNetCmd.csprojAssemblyReference.cache

diff.bin_not_shown

6
MatrixDotNetLib/MatrixDotNetCmd/obj/MatrixDotNetCmd.csproj.nuget.dgspec.json

@ -41,6 +41,12 @@
},
"frameworks": {
"netcoreapp3.1": {
"dependencies": {
"System.Collections.Specialized": {
"target": "Package",
"version": "[4.3.0, )"
}
},
"imports": [
"net461",
"net462",

1311
MatrixDotNetLib/MatrixDotNetCmd/obj/project.assets.json

File diff suppressed because it is too large diff.load

22
MatrixDotNetLib/MatrixDotNetCmd/obj/project.nuget.cache

@ -1,10 +1,28 @@
{
"version": 2,
"dgSpecHash": "8K9QsUKHtNC7PQ873ayC0GHP0lzCog8MTKCNWMZpyzUOnHRnzzR9zoCKZj29McVjauf8VButj3vnkK+05EZTuA==",
"dgSpecHash": "gh4758M0XWKdnbAuiUsvkVtqh82+N/bkCf1KzJxu9ZhL8LktmgTG0/UO95U541U2RezmrouG7omHkJBEYFVrsQ==",
"success": true,
"projectFilePath": "D:\\Source\\MatrixDotNetLib\\MatrixDotNetLib\\MatrixDotNetCmd\\MatrixDotNetCmd.csproj",
"expectedPackageFiles": [
"C:\\Users\\Claire\\.nuget\\packages\\newtonsoft.json\\12.0.3\\newtonsoft.json.12.0.3.nupkg.sha512"
"C:\\Users\\Claire\\.nuget\\packages\\microsoft.netcore.platforms\\1.1.0\\microsoft.netcore.platforms.1.1.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\microsoft.netcore.targets\\1.1.0\\microsoft.netcore.targets.1.1.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\newtonsoft.json\\12.0.3\\newtonsoft.json.12.0.3.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.collections.nongeneric\\4.3.0\\system.collections.nongeneric.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.collections.specialized\\4.3.0\\system.collections.specialized.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.diagnostics.debug\\4.3.0\\system.diagnostics.debug.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.globalization\\4.3.0\\system.globalization.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.globalization.extensions\\4.3.0\\system.globalization.extensions.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.io\\4.3.0\\system.io.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.reflection\\4.3.0\\system.reflection.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.reflection.primitives\\4.3.0\\system.reflection.primitives.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.resources.resourcemanager\\4.3.0\\system.resources.resourcemanager.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.runtime\\4.3.0\\system.runtime.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.runtime.extensions\\4.3.0\\system.runtime.extensions.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.runtime.handles\\4.3.0\\system.runtime.handles.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.runtime.interopservices\\4.3.0\\system.runtime.interopservices.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.text.encoding\\4.3.0\\system.text.encoding.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.threading\\4.3.0\\system.threading.4.3.0.nupkg.sha512",
"C:\\Users\\Claire\\.nuget\\packages\\system.threading.tasks\\4.3.0\\system.threading.tasks.4.3.0.nupkg.sha512"
],
"logs": []
}

36
MatrixDotNetLib/MatrixDotNetLib/MatrixApis.cs

@ -62,7 +62,7 @@ namespace MatrixDotNetLib
/// <remarks>
/// https://matrix.org/docs/api/client-server/#!/Room32discovery/getPublicRooms
/// </remarks>
public static string RoomList = "/_matrix/client/r0/publicrooms";
public static string RoomList = "/_matrix/client/r0/publicRooms";
/// <summary>
/// Updates the visibility of a given room in the directory. Puts a visibility object.
@ -94,7 +94,7 @@ namespace MatrixDotNetLib
/// <remarks>
/// https://matrix.org/docs/api/client-server/#!/VOIP/getTurnServer
/// </remarks>
public static string Voip = "/_matrix/client/r0/voip/turnserver";
public static string Voip = "/_matrix/client/r0/voip/turnServer";
}
public static class Key
@ -442,6 +442,10 @@ namespace MatrixDotNetLib
public static class Room
{
/// <summary>
/// Private string for room URL
/// </summary>
private static string roomBase = "/_matrix/client/r0/rooms/{RoomId}";
/// <summary>
///
@ -449,7 +453,7 @@ namespace MatrixDotNetLib
/// <remarks>
///
/// </remarks>
public static string Create = "/_matrix/client/r0/createroom";
public static string Create = "/_matrix/client/r0/createRoom";
/// <summary>
///
@ -465,7 +469,7 @@ namespace MatrixDotNetLib
/// <remarks>
///
/// </remarks>
public static string Active = "/_matrix/client/r0/rooms/{RoomId}/joined_members";
public static string Active = roomBase + "/joined_members";
/// <summary>
///
@ -473,7 +477,7 @@ namespace MatrixDotNetLib
/// <remarks>
///
/// </remarks>
public static string Members = "/_matrix/client/r0/rooms/{RoomId}/members";
public static string Members = roomBase + "/members";
/// <summary>
///
@ -481,7 +485,7 @@ namespace MatrixDotNetLib
/// <remarks>
///
/// </remarks>
public static string Messages = "/_matrix/client/r0/rooms/{RoomId}/messages";
public static string Messages = roomBase + "/messages";
/// <summary>
///
@ -497,7 +501,7 @@ namespace MatrixDotNetLib
/// <remarks>
///
/// </remarks>
public static string Ban = "/_matrix/client/r0/rooms/{RoomId}/ban";
public static string Ban = roomBase + "/ban";
/// <summary>
///
@ -505,7 +509,7 @@ namespace MatrixDotNetLib
/// <remarks>
///
/// </remarks>
public static string Forget = "/_matrix/client/r0/rooms/{RoomId}/forget";
public static string Forget = roomBase + "/forget";
/// <summary>
///
@ -513,15 +517,15 @@ namespace MatrixDotNetLib
/// <remarks>
///
/// </remarks>
public static string Invite = "/_matrix/client/r0/rooms/{RoomId}/invite";
public static string Invite = roomBase + "/invite";
/// <summary>
///
/// Starts the user participating in the given room. Posts RoomId (not alias).
/// </summary>
/// <remarks>
///
/// https://matrix.org/docs/api/client-server/#!/Room32membership/joinRoomById
/// </remarks>
public static string IdJoin = "/_matrix/client/r0/rooms/{RoomId}/join";
public static string IdJoin = roomBase + "/join";
/// <summary>
///
@ -529,7 +533,7 @@ namespace MatrixDotNetLib
/// <remarks>
///
/// </remarks>
public static string Kick = "/_matrix/client/r0/rooms/{RoomId}/kick";
public static string Kick = roomBase + "/kick";
/// <summary>
///
@ -537,7 +541,7 @@ namespace MatrixDotNetLib
/// <remarks>
///
/// </remarks>
public static string Leave = "/_matrix/client/r0/rooms/{RoomId}/leave";
public static string Leave = roomBase + "/leave";
/// <summary>
///
@ -545,7 +549,7 @@ namespace MatrixDotNetLib
/// <remarks>
///
/// </remarks>
public static string Unban = "/_matrix/client/r0/rooms/{RoomId}/unban";
public static string Unban = roomBase + "/unban";
/// <summary>
///
@ -553,7 +557,7 @@ namespace MatrixDotNetLib
/// <remarks>
///
/// </remarks>
public static string Marker = "/_matrix/client/r0/rooms/{RoomId}/read_markers";
public static string Marker = roomBase + "/read_markers";
}
public static class RoomEvent

16
MatrixDotNetLib/MatrixDotNetLib/MatrixRoom.cs

@ -0,0 +1,16 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace MatrixDotNetLib
{
public class MatrixRoom
{
/// <summary>
/// Gets or sets the chat room id.
/// </summary>
[JsonProperty("room_id")]
public string RoomId { get; set; }
}
}

22
MatrixDotNetLib/MatrixDotNetLib/MatrixRoomDirectory.cs

@ -0,0 +1,22 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace MatrixDotNetLib
{
public class MatrixRoomDirectory
{
[JsonProperty("chunk")]
public MatrixRoomEntry[] Rooms { get; set; }
[JsonProperty("next_batch")]
public string NextPage { get; set; }
[JsonProperty("prev_batch")]
public string PrevPage { get; set; }
[JsonProperty("total_room_count_estimate")]
public int RoomTotal { get; set; }
}
}

37
MatrixDotNetLib/MatrixDotNetLib/MatrixRoomEntry.cs

@ -0,0 +1,37 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace MatrixDotNetLib
{
public class MatrixRoomEntry
{
[JsonProperty("aliases")]
public string[] Aliases { get; set; }
[JsonProperty("canonical_alias")]
public string Alias { get; set; }
[JsonProperty("avatar_url")]
public string Avatar { get; set; }
[JsonProperty("guest_can_join")]
public bool GuestAccess { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("num_joined_members")]
public int Members { get; set; }
[JsonProperty("room_id")]
public string RoomId { get; set; }
[JsonProperty("topic")]
public string Topic { get; set; }
[JsonProperty("world_readable")]
public bool Readable { get; set; }
}
}

43
MatrixDotNetLib/MatrixDotNetLib/MatrixSessionManager.cs

@ -2,10 +2,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@ -100,6 +102,41 @@ namespace MatrixDotNetLib
return (MatrixRoomAliases)JsonConvert.DeserializeObject<MatrixRoomAliases>(responseJson);
}
public MatrixRoomDirectory GetPublicRooms(int limit = 0, string page = null, string server = null)
{
string[] querystring = { };
if (limit > 0)
{
querystring.Append("limit=" + limit);
}
if (page != null)
{
querystring.Append("since=" + page);
}
if (server != null)
{
querystring.Append("server=" + server);
}
string responseJson = "";
if (querystring.Count() > 0)
{
string qs = string.Join("&", querystring);
responseJson = ApiResult(MatrixApis.Server.RoomList, httpAction.GET, query: qs);
}
else
{
responseJson = ApiResult(MatrixApis.Server.RoomList, httpAction.GET);
}
return (MatrixRoomDirectory)JsonConvert.DeserializeObject<MatrixRoomDirectory>(responseJson);
}
public enum httpAction
{
DELETE,
@ -108,7 +145,7 @@ namespace MatrixDotNetLib
PUT
}
public string ApiResult(string api, httpAction action = httpAction.GET, string json = null, MatrixApiEntities entities = null)
public string ApiResult(string api, httpAction action = httpAction.GET, string json = null, MatrixApiEntities entities = null, string query = null)
{
// simplest implementation
// might not work for UWP
@ -210,6 +247,8 @@ namespace MatrixDotNetLib
// convert error object to a string
string errMsg = error.ErrorCode + ": " + error.ErrorMessage;
errMsg += "\n\nAPI accessed : " + url;
errMsg += "\nToken Used : " + (this.Token.Length > 0 ? "yes" : "no");
// throw exception (can be caught and handled gracefully)
throw new Exception(errMsg);
@ -218,6 +257,8 @@ namespace MatrixDotNetLib
{
// web server responded with an HTTP status code other than 200 OK
string errMsg = "Server returned " + (int)responseMessage.StatusCode + ": " + responseMessage.StatusCode.ToString();
errMsg += "\n\nAPI accessed : " + url;
errMsg += "\nToken Used : " + (this.Token.Length > 0 ? "yes" : "no");
throw new Exception(errMsg);
}
else

BIN
MatrixDotNetLib/MatrixDotNetLib/bin/Debug/netcoreapp3.1/MatrixDotNetLib.dll

diff.bin_not_shown

BIN
MatrixDotNetLib/MatrixDotNetLib/bin/Debug/netcoreapp3.1/MatrixDotNetLib.pdb

diff.bin_not_shown

2
MatrixDotNetLib/MatrixDotNetLib/obj/Debug/netcoreapp3.1/MatrixDotNetLib.csproj.CoreCompileInputs.cache

@ -1 +1 @@
5eb8af853df6cefc73690046f1829a4a47fc69f4
d134ecf746b427f75753ffff9f48fb08b71ead11

BIN
MatrixDotNetLib/MatrixDotNetLib/obj/Debug/netcoreapp3.1/MatrixDotNetLib.csprojAssemblyReference.cache

diff.bin_not_shown

BIN
MatrixDotNetLib/MatrixDotNetLib/obj/Debug/netcoreapp3.1/MatrixDotNetLib.dll

diff.bin_not_shown

BIN
MatrixDotNetLib/MatrixDotNetLib/obj/Debug/netcoreapp3.1/MatrixDotNetLib.pdb

diff.bin_not_shown
Loading…
Cancel
Save