Ejemplo n.º 1
0
        public Result GotoPostIndex(int iChoice, LocalUser user, CommandParser parser)
        {
            Result rs = null;
            bool bShowBBCode = false;

            if (parser != null)
            {
                // TODO: need to refactor/rewrite the command parser
                foreach (string strOption in parser.Parameters)
                {
                    if (strOption.ToLower() == "b")
                    {
                        bShowBBCode = true;
                        break;
                    }
                }
            }

            UserLocation curPostLoc = UserLocation.LoadLocation(UserLocationType.POST, user);

            if (curPostLoc != null)
            {
                VBotService.UserCredentials uc = BotService.Credentialize(ResponseChannel);
                VBotService.GetPostResult r = BotService.Instance.GetPostByIndex(uc, (int)curPostLoc.LocationRemoteID, iChoice, bShowBBCode);

                if (r.Result.Code == 0)
                {
                    if (r.Post != null && r.Post.PostID > 0)
                    {
                        string strText = ResponseChannel.FetchTemplate(@"postbit",
                            new object[] {r.Post.PageText,iChoice,r.Post.DateLineText,r.Post.Username});

                        user.SaveLastPostIndex(iChoice);
                        rs = new Result(ResultCode.Success, strText);
                    }
                    else
                    {
                        rs = new Result(ResultCode.Error, @"Invalid post index.");
                    }
                }
                else
                {
                    rs = new Result(ResultCode.Error, @"Invalid request.");
                }
            }
            else
            {// no location for a thread exists in the local db

                rs = new Result(ResultCode.Error, @"Invalid thread id. Use `lt` and browse to a thread");
            }
            return rs;
        }
Ejemplo n.º 2
0
        public Result ListPosts(LocalUser user, string[] options, VBotService.PostListResult result)
        {
            lock (this)
            {
                ResultCode rc = ResultCode.Unknown;
                UserLocation loc = UserLocation.LoadLocation(UserLocationType.POST, user);

                if (loc == null)
                {
                    Result ret = new Result(ResultCode.Error, @"No active thread. Use `lt` to browse to a thread.");
                    return ret;
                }

                int iPageNumber = 0;
                int iPerPage = 0;

                if (options.Length < 1 || !int.TryParse(options[0], out iPageNumber))
                {
                    iPageNumber = 1;
                }

                if (options.Length < 2 || !int.TryParse(options[1], out iPerPage))
                {
                    iPerPage = 5;
                }

                if (iPerPage > 30)
                {
                    iPerPage = 30;
                }

                if (result == null)
                {
                    VBotService.UserCredentials uc = BotService.Credentialize(ResponseChannel);
                    result = BotService.Instance.ListPosts(uc, (int)loc.LocationRemoteID, iPageNumber, iPerPage);

                    if (result.Result.Code != 0)
                    {
                        log.ErrorFormat("Could not list posts: {0}", result.Result.Text);
                        return new Result(ResultCode.Error, ResponseChannel.FetchTemplate(result.Result.Text));
                    }
                }

                string strResponse = string.Empty;

                double dTotalPosts = (double)(result.Thread.ReplyCount + 1);
                int iTotalPages = (int)Math.Ceiling(dTotalPosts / (double)iPerPage);

                string strIsNew = string.Empty;
                if (result.PostList.Count() > 0)
                {
                    int iCount = ((iPageNumber - 1) * iPerPage) + 1;
                    foreach (VBotService.Post postInfo in result.PostList)
                    {
                        strIsNew = string.Empty;
                        if (postInfo.IsNew)
                        {
                            strIsNew = "*";
                        }

                        strResponse += ResponseChannel.FetchTemplate("post_list_inline", new object[] {
                                            iCount,
                                            strIsNew,
                                            postInfo.GetShortPostText(),
                                            postInfo.DateLineText,
                                            postInfo.Username
                        });

                        iCount++;
                    }

                    strResponse = ResponseChannel.FetchTemplate("post_list", new object[] {
                        loc.Title,
                        iPageNumber,
                        iTotalPages,
                        iPerPage,
                        strResponse });

                    rc = ResultCode.Success;
                }
                else
                {
                    strResponse += "Invalid page number";
                    rc = ResultCode.Error;
                }

                user.SaveLastList(@"post");
                user.SaveLastPostIndex(1);
                return new Result(rc, strResponse);
            }
        }