Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            var homeserverUrl = new Uri("http://localhost:8008");

            MatrixClient client;

            if (File.Exists("/tmp/mx_access"))
            {
                var tokens = File.ReadAllText("/tmp/mx_access").Split("$");
                client = new MatrixClient(homeserverUrl);
                client.UseExistingToken(tokens[1], tokens[0]);
            }
            else
            {
                var username = "******";
                var password = "******";
                client = new MatrixClient(homeserverUrl);
                var login = client.LoginWithPassword(username, password);
                File.WriteAllText("/tmp/mx_access", $"{login.AccessToken}${login.UserId}");
            }

            Console.WriteLine("Starting sync");
            client.StartSync();
            Console.WriteLine("Finished initial sync");
            foreach (var room in client.GetAllRooms())
            {
                Console.WriteLine($"Found room: {room.Id}");
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string       homeserverUrl = "https://matrix.org";
            MatrixClient client;

            if (File.Exists("/tmp/mx_access"))
            {
                string[] tokens = File.ReadAllText("/tmp/mx_access.txt").Split("$");
                client = new MatrixClient(homeserverUrl);
                client.UseExistingToken(tokens[1], tokens[0]);
            }
            else
            {
                string username = "******";
                string password = "******";
                client = new MatrixClient(homeserverUrl);
                MatrixLoginResponse login = client.LoginWithPassword(username, password);
                File.WriteAllText("/tmp/mx_access.txt", $"{login.access_token}${login.user_id}");
            }
            Console.WriteLine("Starting sync");
            client.StartSync();
            Console.WriteLine("Finished initial sync");
            foreach (var room in client.GetAllRooms())
            {
                Console.WriteLine($"Found room: {room.ID}");
            }
        }
Exemplo n.º 3
0
    public void MatrixRoutine()
    {
        var storage = new Storage();

        client = new MatrixClient(storage.Server);
        cache  = new Cache(client);

        try{
            client.UseExistingToken(storage.UserId, storage.Token);
            this.user = client.GetUser();
            Gtk.Application.Invoke(delegate {
                var statusContext = statusbar.GetContextId("matrix");
                statusbar.Push(statusContext, "Logged in to " + storage.Server + " as " + storage.UserId);
                displayName.Text = user.DisplayName;
            });
        }catch (Exception loginException) {
            Gtk.Application.Invoke(delegate {
                var statusContext = statusbar.GetContextId("matrix");
                statusbar.Push(statusContext, "Login failed: " + loginException.Message);
            });

            storage.Token = null;
            storage.Save();
        }

        var rooms = client.GetAllRooms();

        channelList.AppendColumn("Icon", new Gtk.CellRendererPixbuf(), "pixbuf", 0);
        channelList.AppendColumn("Artist", new Gtk.CellRendererText(), "text", 1);


        var liststore = new ListStore(typeof(Gdk.Pixbuf), typeof(string));

        int roomIndex = 0;

        foreach (var channel in rooms)
        {
            var label = getRoomLabel(channel);
            var icon  = AvatarGenerator.createRoomAvatar(label, channel.Encryption != null);
            liststore.AppendValues(icon, label);
            this.rooms.Add(roomIndex, channel);
            roomIndex++;

            foreach (var member in channel.Members)
            {
                if (!this.users.ContainsKey(member.Key))
                {
                    this.users.Add(member.Key, member.Value);
                }
            }
        }

        channelList.Model = liststore;
        var avatar       = cache.GetAvatarObject(user.AvatarURL);
        var avatarScaled = Utils.resizeImage(System.Drawing.Image.FromStream(avatar), 48, 48);

        profileImage.Pixbuf = Utils.bitmapToPixbuf(avatarScaled);

        foreach (var member in this.users)
        {
            if (member.Value.avatar_url != null)
            {
                var memberAvatar = cache.GetAvatarObject(member.Value.avatar_url);
                var scaled       = Utils.resizeImage(System.Drawing.Image.FromStream(memberAvatar), 32, 32);
                this.avatars.Add(member.Key, scaled);
            }
        }
        refreshRoomList();
        Console.WriteLine("Matrix thread done");
    }