示例#1
0
 async void SendMessage()
 {
     APIResponse response = await MattermostAPI.PostMessage(channel, Message);
 }
示例#2
0
        async void Login(PasswordBox password)
        {
            if (!Regex.IsMatch(Server, @"[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)"))
            {
                await ShowMessageDialog("Server URL is invalid", false);

                return;
            }

            DialogHost.Show(new ProgressDialog(), "RootDialog");

            APIResponse result = await MattermostAPI.Login(Server, Team, Username, password.SecurePassword);

            if (!result.Success)
            {
                await ShowMessageDialog(result.Error);

                return;
            }

            if (config == null)
            {
                config = new LocalConfig();
            }

            config.Server   = Server;
            config.Team     = Team;
            config.Username = Username;
            config.UserID   = MattermostAPI.MyID;
            config.Token    = MattermostAPI.Token;
            config.TeamID   = MattermostAPI.Team.ID;


            try
            {
                LocalStorage.Store("configs", config);
            }
            catch (Exception e)
            {
                LocalStorage.Update("configs", config);
            }


            //if (config == null)

            //else
            //    LocalStorage.Update("configs", config);

            APIResponse <List <User> > users = await MattermostAPI.GetUsers(MattermostAPI.Team.ID);

            if (!users.Success)
            {
                await ShowMessageDialog(users.Error);

                return;
            }

            Task <APIResponse <Preferences> > preferencesTask = MattermostAPI.GetPreferences();
            APIResponse <List <Channel> >     channels        = await MattermostAPI.GetChannels(MattermostAPI.Team.ID);

            if (!channels.Success)
            {
                await ShowMessageDialog(channels.Error);

                return;
            }

            await preferencesTask;

            mainVM.CurrentView = new MessageViewModel(mainVM, users.Value, channels.Value);

            DialogHost.CloseDialogCommand.Execute(true, null);
        }
示例#3
0
        async void GetPosts()
        {
            APIResponse <ChannelPosts> response = await MattermostAPI.GetPosts(ID, 0, 30);

            if (response.Success)
            {
                List <PostViewModel> posts = new List <PostViewModel>();
                Post     lastPost          = null;
                DateTime lastDate          = DateTime.MinValue;
                bool     newDay            = false;

                postCache = response.Value.Posts;

                foreach (string postID in response.Value.Order)
                {
                    Post post = postCache.First(p => p.ID == postID);

                    newDay = false;

                    if (post.Created.Date != lastDate)
                    {
                        posts.Add(new PostViewModel(post.Created));
                        lastDate = post.Created.Date;
                        newDay   = true;
                    }

                    PostViewModel newPost = null;

                    if (lastPost == null)
                    {
                        newPost = new PostViewModel(post);
                    }
                    else
                    {
                        newPost = new PostViewModel(post, lastPost.User, lastPost.Created, newDay);
                    }

                    posts.Add(newPost);

                    string rootID;

                    if (post.RootPost == null)
                    {
                        rootID = post.ID;
                    }
                    else
                    {
                        rootID = post.RootPost.ID;
                    }

                    int count = postCache.Count(p => p.RootPost != null && p.RootPost.ID == rootID);

                    if (count > 0)
                    {
                        newPost.ReplyCount = count;
                    }

                    lastPost = post;
                }

                Posts = new ObservableCollection <PostViewModel>(posts);
            }
        }