Add pinned posts (#4217)
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
482a0fb5fc
Коммит
fe38d6d5bb
@@ -16,6 +16,7 @@ const FOCUSED_POST_CHANGE = 'focused_post_change';
|
||||
const EDIT_POST_EVENT = 'edit_post';
|
||||
const POSTS_VIEW_JUMP_EVENT = 'post_list_jump';
|
||||
const SELECTED_POST_CHANGE_EVENT = 'selected_post_change';
|
||||
const POST_PINNED_CHANGE_EVENT = 'post_pinned_change';
|
||||
|
||||
class PostStoreClass extends EventEmitter {
|
||||
constructor() {
|
||||
@@ -259,22 +260,42 @@ class PostStoreClass extends EventEmitter {
|
||||
this.postsInfo[id].postList = combinedPosts;
|
||||
}
|
||||
|
||||
focusedPostListHasPost(id) {
|
||||
const focusedPostId = this.getFocusedPostId();
|
||||
if (focusedPostId == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const focusedPostList = makePostListNonNull(this.getAllPosts(focusedPostId));
|
||||
return focusedPostList.posts.hasOwnProperty(id);
|
||||
}
|
||||
|
||||
storePost(post, isNewPost = false) {
|
||||
const postList = makePostListNonNull(this.getAllPosts(post.channel_id));
|
||||
const ids = [
|
||||
post.channel_id
|
||||
];
|
||||
|
||||
if (post.pending_post_id !== '') {
|
||||
this.removePendingPost(post.channel_id, post.pending_post_id);
|
||||
// update the post in the permalink view if it's there
|
||||
if (!isNewPost && this.focusedPostListHasPost(post.id)) {
|
||||
ids.push(this.getFocusedPostId());
|
||||
}
|
||||
|
||||
post.pending_post_id = '';
|
||||
ids.forEach((id) => {
|
||||
const postList = makePostListNonNull(this.getAllPosts(id));
|
||||
if (post.pending_post_id !== '') {
|
||||
this.removePendingPost(post.channel_id, post.pending_post_id);
|
||||
}
|
||||
|
||||
postList.posts[post.id] = post;
|
||||
if (isNewPost && postList.order.indexOf(post.id) === -1) {
|
||||
postList.order.unshift(post.id);
|
||||
}
|
||||
post.pending_post_id = '';
|
||||
|
||||
this.makePostsInfo(post.channel_id);
|
||||
this.postsInfo[post.channel_id].postList = postList;
|
||||
postList.posts[post.id] = post;
|
||||
if (isNewPost && postList.order.indexOf(post.id) === -1) {
|
||||
postList.order.unshift(post.id);
|
||||
}
|
||||
|
||||
this.makePostsInfo(post.channel_id);
|
||||
this.postsInfo[id].postList = postList;
|
||||
});
|
||||
}
|
||||
|
||||
storeFocusedPost(postId, channelId, postList) {
|
||||
@@ -500,6 +521,18 @@ class PostStoreClass extends EventEmitter {
|
||||
this.removeListener(SELECTED_POST_CHANGE_EVENT, callback);
|
||||
}
|
||||
|
||||
emitPostPinnedChange() {
|
||||
this.emit(POST_PINNED_CHANGE_EVENT);
|
||||
}
|
||||
|
||||
addPostPinnedChangeListener(callback) {
|
||||
this.on(POST_PINNED_CHANGE_EVENT, callback);
|
||||
}
|
||||
|
||||
removePostPinnedChangeListener(callback) {
|
||||
this.removeListener(POST_PINNED_CHANGE_EVENT, callback);
|
||||
}
|
||||
|
||||
getCurrentUsersLatestPost(channelId, rootId) {
|
||||
const userId = UserStore.getCurrentId();
|
||||
|
||||
@@ -686,6 +719,10 @@ PostStore.dispatchToken = AppDispatcher.register((payload) => {
|
||||
PostStore.storeSelectedPostId(action.postId);
|
||||
PostStore.emitSelectedPostChange(action.from_search, action.from_flagged_posts);
|
||||
break;
|
||||
case ActionTypes.RECEIVED_POST_PINNED:
|
||||
case ActionTypes.RECEIVED_POST_UNPINNED:
|
||||
PostStore.emitPostPinnedChange();
|
||||
break;
|
||||
default:
|
||||
}
|
||||
});
|
||||
|
||||
@@ -19,6 +19,7 @@ class SearchStoreClass extends EventEmitter {
|
||||
this.searchResults = null;
|
||||
this.isMentionSearch = false;
|
||||
this.isFlaggedPosts = false;
|
||||
this.isPinnedPosts = false;
|
||||
this.isVisible = false;
|
||||
this.searchTerm = '';
|
||||
}
|
||||
@@ -83,6 +84,10 @@ class SearchStoreClass extends EventEmitter {
|
||||
return this.isFlaggedPosts;
|
||||
}
|
||||
|
||||
getIsPinnedPosts() {
|
||||
return this.isPinnedPosts;
|
||||
}
|
||||
|
||||
storeSearchTerm(term) {
|
||||
this.searchTerm = term;
|
||||
}
|
||||
@@ -91,10 +96,11 @@ class SearchStoreClass extends EventEmitter {
|
||||
return this.searchTerm;
|
||||
}
|
||||
|
||||
storeSearchResults(results, isMentionSearch, isFlaggedPosts) {
|
||||
storeSearchResults(results, isMentionSearch, isFlaggedPosts, isPinnedPosts) {
|
||||
this.searchResults = results;
|
||||
this.isMentionSearch = isMentionSearch;
|
||||
this.isFlaggedPosts = isFlaggedPosts;
|
||||
this.isPinnedPosts = isPinnedPosts;
|
||||
}
|
||||
|
||||
deletePost(post) {
|
||||
@@ -120,7 +126,7 @@ SearchStore.dispatchToken = AppDispatcher.register((payload) => {
|
||||
|
||||
switch (action.type) {
|
||||
case ActionTypes.RECEIVED_SEARCH:
|
||||
SearchStore.storeSearchResults(action.results, action.is_mention_search, action.is_flagged_posts);
|
||||
SearchStore.storeSearchResults(action.results, action.is_mention_search, action.is_flagged_posts, action.is_pinned_posts);
|
||||
SearchStore.emitSearchChange();
|
||||
break;
|
||||
case ActionTypes.RECEIVED_SEARCH_TERM:
|
||||
|
||||
Ссылка в новой задаче
Block a user