Пример #1
0
        public static object FetchArticleDetail(string articleId)
        {
            return(new ThunkAction <AppState>((dispatcher, getState) => {
                return ArticleApi.FetchArticleDetail(articleId)
                .Then(articleDetailResponse => {
                    if (articleDetailResponse.project.comments.items.Count > 0)
                    {
                        var itemIds = new List <string>();
                        var messageItems = new Dictionary <string, Message>();
                        var userMap = new Dictionary <string, User>();
                        articleDetailResponse.project.comments.items.ForEach(message => {
                            itemIds.Add(message.id);
                            messageItems[message.id] = message;
                            if (userMap.ContainsKey(message.author.id))
                            {
                                userMap[message.author.id] = message.author;
                            }
                            else
                            {
                                userMap.Add(message.author.id, message.author);
                            }
                        });
                        dispatcher.dispatch(new UserMapAction {
                            userMap = userMap
                        });
                        dispatcher.dispatch(new FetchArticleCommentsSuccessAction {
                            channelId = articleDetailResponse.project.channelId,
                            itemIds = itemIds,
                            messageItems = messageItems,
                            isRefreshList = true,
                            hasMore = articleDetailResponse.project.comments.hasMore,
                            currOldestMessageId = articleDetailResponse.project.comments.currOldestMessageId
                        });
                    }

                    dispatcher.dispatch(new UserMapAction {
                        userMap = articleDetailResponse.project.userMap
                    });
                    dispatcher.dispatch(new TeamMapAction {
                        teamMap = articleDetailResponse.project.teamMap
                    });
                    dispatcher.dispatch(new FetchArticleDetailSuccessAction {
                        articleDetail = articleDetailResponse.project
                    });
                    dispatcher.dispatch(new SaveArticleHistoryAction {
                        article = articleDetailResponse.project.projectData
                    });
                })
                .Catch(error => {
//                        dispatcher.dispatch(new FetchArticleDetailFailureAction());
                    Debug.Log(error);
                });
            }));
        }
Пример #2
0
        public static object FetchArticleDetail(string articleId, bool isPush = false)
        {
            return(new ThunkAction <AppState>((dispatcher, getState) => {
                return ArticleApi.FetchArticleDetail(articleId: articleId, isPush: isPush)
                .Then(articleDetailResponse => {
                    var itemIds = new List <string>();
                    var messageItems = new Dictionary <string, Message>();
                    var userMap = new Dictionary <string, User>();
                    articleDetailResponse.project.comments.items.ForEach(message => {
                        itemIds.Add(item: message.id);
                        messageItems[key: message.id] = message;
                        if (userMap.ContainsKey(key: message.author.id))
                        {
                            userMap[key: message.author.id] = message.author;
                        }
                        else
                        {
                            userMap.Add(key: message.author.id, value: message.author);
                        }
                    });
                    articleDetailResponse.project.comments.parents.ForEach(message => {
                        if (messageItems.ContainsKey(key: message.id))
                        {
                            messageItems[key: message.id] = message;
                        }
                        else
                        {
                            messageItems.Add(key: message.id, value: message);
                        }

                        if (userMap.ContainsKey(key: message.author.id))
                        {
                            userMap[key: message.author.id] = message.author;
                        }
                        else
                        {
                            userMap.Add(key: message.author.id, value: message.author);
                        }
                    });
                    articleDetailResponse.project.comments.uppers.ForEach(message => {
                        if (messageItems.ContainsKey(key: message.id))
                        {
                            messageItems[key: message.id] = message;
                        }
                        else
                        {
                            messageItems.Add(key: message.id, value: message);
                        }

                        if (userMap.ContainsKey(key: message.author.id))
                        {
                            userMap[key: message.author.id] = message.author;
                        }
                        else
                        {
                            userMap.Add(key: message.author.id, value: message.author);
                        }
                    });
                    dispatcher.dispatch(new UserMapAction {
                        userMap = userMap
                    });
                    dispatcher.dispatch(new UserLicenseMapAction
                    {
                        userLicenseMap = articleDetailResponse.project.userLicenseMap
                    });
                    dispatcher.dispatch(new FetchArticleCommentsSuccessAction {
                        channelId = articleDetailResponse.project.channelId,
                        itemIds = itemIds,
                        messageItems = messageItems,
                        isRefreshList = true,
                        hasMore = articleDetailResponse.project.comments.hasMore,
                        currOldestMessageId = articleDetailResponse.project.comments.currOldestMessageId
                    });

                    dispatcher.dispatch(new UserMapAction {
                        userMap = articleDetailResponse.project.userMap
                    });
                    dispatcher.dispatch(new UserMapAction {
                        userMap = articleDetailResponse.project.mentionUsers
                    });
                    dispatcher.dispatch(new TeamMapAction {
                        teamMap = articleDetailResponse.project.teamMap
                    });
                    dispatcher.dispatch(new FollowMapAction {
                        followMap = articleDetailResponse.project.followMap
                    });
                    dispatcher.dispatch(new FetchArticleDetailSuccessAction {
                        articleDetail = articleDetailResponse.project,
                        articleId = articleId
                    });
                    dispatcher.dispatch(new SaveArticleHistoryAction {
                        article = articleDetailResponse.project.projectData
                    });
                })
                .Catch(error => {
                    dispatcher.dispatch(new FetchArticleDetailFailureAction());
                    Debuger.LogError(message: error);
                });
            }));
        }