reformat post_list.jsx to match style guide more closely
Этот коммит содержится в:
@@ -39,7 +39,7 @@ function getStateFromStores() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
displayName: "PostList",
|
displayName: 'PostList',
|
||||||
scrollPosition: 0,
|
scrollPosition: 0,
|
||||||
preventScrollTrigger: false,
|
preventScrollTrigger: false,
|
||||||
gotMorePosts: false,
|
gotMorePosts: false,
|
||||||
@@ -54,69 +54,70 @@ module.exports = React.createClass({
|
|||||||
utils.changeCss('.modal .modal-header', 'background: ' + user.props.theme + ';');
|
utils.changeCss('.modal .modal-header', 'background: ' + user.props.theme + ';');
|
||||||
utils.changeCss('.mention', 'background: ' + user.props.theme + ';');
|
utils.changeCss('.mention', 'background: ' + user.props.theme + ';');
|
||||||
utils.changeCss('.mention-link', 'color: ' + user.props.theme + ';');
|
utils.changeCss('.mention-link', 'color: ' + user.props.theme + ';');
|
||||||
utils.changeCss('.mention-link', 'color: ' + user.props.theme+';');
|
|
||||||
utils.changeCss('.mention-link', 'color: ' + user.props.theme+';');
|
|
||||||
utils.changeCss('.search-item-container:hover', 'background: ' + utils.changeOpacity(user.props.theme, 0.05) +';');
|
|
||||||
utils.changeCss('@media(max-width: 768px){.search-bar__container', 'background: ' + user.props.theme + ';}');
|
utils.changeCss('@media(max-width: 768px){.search-bar__container', 'background: ' + user.props.theme + ';}');
|
||||||
|
utils.changeCss('.search-item-container:hover', 'background: ' + utils.changeOpacity(user.props.theme, 0.05) + ';');
|
||||||
}
|
}
|
||||||
if (user.props.theme != '#000000' && user.props.theme != '#585858') {
|
|
||||||
|
if (user.props.theme !== '#000000' && user.props.theme !== '#585858') {
|
||||||
utils.changeCss('.btn.btn-primary:hover, .btn.btn-primary:active, .btn.btn-primary:focus', 'background: ' + utils.changeColor(user.props.theme, -10) + ';');
|
utils.changeCss('.btn.btn-primary:hover, .btn.btn-primary:active, .btn.btn-primary:focus', 'background: ' + utils.changeColor(user.props.theme, -10) + ';');
|
||||||
utils.changeCss('a.theme', 'color:' + user.props.theme + '; fill:' + user.props.theme + '!important;');
|
utils.changeCss('a.theme', 'color:' + user.props.theme + '; fill:' + user.props.theme + '!important;');
|
||||||
} else if (user.props.theme == '#000000') {
|
} else if (user.props.theme === '#000000') {
|
||||||
utils.changeCss('.btn.btn-primary:hover, .btn.btn-primary:active, .btn.btn-primary:focus', 'background: ' + utils.changeColor(user.props.theme, +50) + ';');
|
utils.changeCss('.btn.btn-primary:hover, .btn.btn-primary:active, .btn.btn-primary:focus', 'background: ' + utils.changeColor(user.props.theme, +50) + ';');
|
||||||
$('.team__header').addClass('theme--black');
|
$('.team__header').addClass('theme--black');
|
||||||
} else if (user.props.theme == '#585858') {
|
} else if (user.props.theme === '#585858') {
|
||||||
utils.changeCss('.btn.btn-primary:hover, .btn.btn-primary:active, .btn.btn-primary:focus', 'background: ' + utils.changeColor(user.props.theme, +10) + ';');
|
utils.changeCss('.btn.btn-primary:hover, .btn.btn-primary:active, .btn.btn-primary:focus', 'background: ' + utils.changeColor(user.props.theme, +10) + ';');
|
||||||
$('.team__header').addClass('theme--gray');
|
$('.team__header').addClass('theme--gray');
|
||||||
}
|
}
|
||||||
|
|
||||||
PostStore.addChangeListener(this._onChange);
|
PostStore.addChangeListener(this.onChange);
|
||||||
ChannelStore.addChangeListener(this._onChange);
|
ChannelStore.addChangeListener(this.onChange);
|
||||||
UserStore.addStatusesChangeListener(this._onTimeChange);
|
UserStore.addStatusesChangeListener(this.onTimeChange);
|
||||||
SocketStore.addChangeListener(this._onSocketChange);
|
SocketStore.addChangeListener(this.onSocketChange);
|
||||||
|
|
||||||
$(".post-list-holder-by-time").perfectScrollbar();
|
$('.post-list-holder-by-time').perfectScrollbar();
|
||||||
|
|
||||||
this.resize();
|
this.resize();
|
||||||
|
|
||||||
var post_holder = $(".post-list-holder-by-time")[0];
|
var postHolder = $('.post-list-holder-by-time')[0];
|
||||||
this.scrollPosition = $(post_holder).scrollTop() + $(post_holder).innerHeight();
|
this.scrollPosition = $(postHolder).scrollTop() + $(postHolder).innerHeight();
|
||||||
this.oldScrollHeight = post_holder.scrollHeight;
|
this.oldScrollHeight = postHolder.scrollHeight;
|
||||||
this.oldZoom = (window.outerWidth - 8) / window.innerWidth;
|
this.oldZoom = (window.outerWidth - 8) / window.innerWidth;
|
||||||
|
|
||||||
$('.modal').on('show.bs.modal', function () {
|
$('.modal').on('show.bs.modal', function onShow() {
|
||||||
$('.modal-body').css('overflow-y', 'auto');
|
$('.modal-body').css('overflow-y', 'auto');
|
||||||
$('.modal-body').css('max-height', $(window).height() * 0.7);
|
$('.modal-body').css('max-height', $(window).height() * 0.7);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Timeout exists for the DOM to fully render before making changes
|
// Timeout exists for the DOM to fully render before making changes
|
||||||
var self = this;
|
var self = this;
|
||||||
$(window).resize(function(){
|
$(window).resize(function resize() {
|
||||||
$(post_holder).perfectScrollbar('update');
|
$(postHolder).perfectScrollbar('update');
|
||||||
|
|
||||||
// this only kind of works, detecting zoom in browsers is a nightmare
|
// this only kind of works, detecting zoom in browsers is a nightmare
|
||||||
var newZoom = (window.outerWidth - 8) / window.innerWidth;
|
var newZoom = (window.outerWidth - 8) / window.innerWidth;
|
||||||
|
|
||||||
if (self.scrollPosition >= post_holder.scrollHeight || (self.oldScrollHeight != post_holder.scrollHeight && self.scrollPosition >= self.oldScrollHeight) || self.oldZoom != newZoom) self.resize();
|
if (self.scrollPosition >= postHolder.scrollHeight || (self.oldScrollHeight !== postHolder.scrollHeight && self.scrollPosition >= self.oldScrollHeight) || self.oldZoom !== newZoom) {
|
||||||
|
self.resize();
|
||||||
|
}
|
||||||
|
|
||||||
self.oldZoom = newZoom;
|
self.oldZoom = newZoom;
|
||||||
|
|
||||||
if ($('#create_post').length > 0) {
|
if ($('#create_post').length > 0) {
|
||||||
var height = $(window).height() - $('#create_post').height() - $('#error_bar').outerHeight() - 50;
|
var height = $(window).height() - $('#create_post').height() - $('#error_bar').outerHeight() - 50;
|
||||||
$(".post-list-holder-by-time").css("height", height + "px");
|
$('.post-list-holder-by-time').css('height', height + 'px');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(post_holder).scroll(function(e){
|
$(postHolder).scroll(function scroll() {
|
||||||
if (!self.preventScrollTrigger) {
|
if (!self.preventScrollTrigger) {
|
||||||
self.scrollPosition = $(post_holder).scrollTop() + $(post_holder).innerHeight();
|
self.scrollPosition = $(postHolder).scrollTop() + $(postHolder).innerHeight();
|
||||||
}
|
}
|
||||||
self.preventScrollTrigger = false;
|
self.preventScrollTrigger = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$('body').on('click.userpopover', function(e){
|
$('body').on('click.userpopover', function popOver(e) {
|
||||||
if ($(e.target).attr('data-toggle') !== 'popover'
|
if ($(e.target).attr('data-toggle') !== 'popover' &&
|
||||||
&& $(e.target).parents('.popover.in').length === 0) {
|
$(e.target).parents('.popover.in').length === 0) {
|
||||||
$('.user-popover').popover('hide');
|
$('.user-popover').popover('hide');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -124,67 +125,62 @@ module.exports = React.createClass({
|
|||||||
$('.post-list__content div .post').removeClass('post--last');
|
$('.post-list__content div .post').removeClass('post--last');
|
||||||
$('.post-list__content div:last-child .post').addClass('post--last');
|
$('.post-list__content div:last-child .post').addClass('post--last');
|
||||||
|
|
||||||
$('body').on('mouseenter mouseleave', '.post', function(ev){
|
$('body').on('mouseenter mouseleave', '.post', function mouseOver(ev) {
|
||||||
if (ev.type === 'mouseenter') {
|
if (ev.type === 'mouseenter') {
|
||||||
$(this).parent('div').prev('.date-separator, .new-separator').addClass('hovered--after');
|
$(this).parent('div').prev('.date-separator, .new-separator').addClass('hovered--after');
|
||||||
$(this).parent('div').next('.date-separator, .new-separator').addClass('hovered--before');
|
$(this).parent('div').next('.date-separator, .new-separator').addClass('hovered--before');
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$(this).parent('div').prev('.date-separator, .new-separator').removeClass('hovered--after');
|
$(this).parent('div').prev('.date-separator, .new-separator').removeClass('hovered--after');
|
||||||
$(this).parent('div').next('.date-separator, .new-separator').removeClass('hovered--before');
|
$(this).parent('div').next('.date-separator, .new-separator').removeClass('hovered--before');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('body').on('mouseenter mouseleave', '.post.post--comment.same--root', function(ev){
|
$('body').on('mouseenter mouseleave', '.post.post--comment.same--root', function mouseOver(ev) {
|
||||||
if (ev.type === 'mouseenter') {
|
if (ev.type === 'mouseenter') {
|
||||||
$(this).parent('div').prev('.date-separator, .new-separator').addClass('hovered--comment');
|
$(this).parent('div').prev('.date-separator, .new-separator').addClass('hovered--comment');
|
||||||
$(this).parent('div').next('.date-separator, .new-separator').addClass('hovered--comment');
|
$(this).parent('div').next('.date-separator, .new-separator').addClass('hovered--comment');
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$(this).parent('div').prev('.date-separator, .new-separator').removeClass('hovered--comment');
|
$(this).parent('div').prev('.date-separator, .new-separator').removeClass('hovered--comment');
|
||||||
$(this).parent('div').next('.date-separator, .new-separator').removeClass('hovered--comment');
|
$(this).parent('div').next('.date-separator, .new-separator').removeClass('hovered--comment');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
componentDidUpdate: function() {
|
componentDidUpdate: function() {
|
||||||
this.resize();
|
this.resize();
|
||||||
var post_holder = $(".post-list-holder-by-time")[0];
|
var postHolder = $('.post-list-holder-by-time')[0];
|
||||||
this.scrollPosition = $(post_holder).scrollTop() + $(post_holder).innerHeight();
|
this.scrollPosition = $(postHolder).scrollTop() + $(postHolder).innerHeight();
|
||||||
this.oldScrollHeight = post_holder.scrollHeight;
|
this.oldScrollHeight = postHolder.scrollHeight;
|
||||||
$('.post-list__content div .post').removeClass('post--last');
|
$('.post-list__content div .post').removeClass('post--last');
|
||||||
$('.post-list__content div:last-child .post').addClass('post--last');
|
$('.post-list__content div:last-child .post').addClass('post--last');
|
||||||
},
|
},
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
PostStore.removeChangeListener(this._onChange);
|
PostStore.removeChangeListener(this.onChange);
|
||||||
ChannelStore.removeChangeListener(this._onChange);
|
ChannelStore.removeChangeListener(this.onChange);
|
||||||
UserStore.removeStatusesChangeListener(this._onTimeChange);
|
UserStore.removeStatusesChangeListener(this.onTimeChange);
|
||||||
SocketStore.removeChangeListener(this._onSocketChange);
|
SocketStore.removeChangeListener(this.onSocketChange);
|
||||||
$('body').off('click.userpopover');
|
$('body').off('click.userpopover');
|
||||||
$('.modal').off('show.bs.modal')
|
$('.modal').off('show.bs.modal');
|
||||||
},
|
},
|
||||||
resize: function() {
|
resize: function() {
|
||||||
var post_holder = $(".post-list-holder-by-time")[0];
|
var postHolder = $('.post-list-holder-by-time')[0];
|
||||||
this.preventScrollTrigger = true;
|
this.preventScrollTrigger = true;
|
||||||
if (this.gotMorePosts) {
|
if (this.gotMorePosts) {
|
||||||
this.gotMorePosts = false;
|
this.gotMorePosts = false;
|
||||||
$(post_holder).scrollTop($(post_holder).scrollTop() + (post_holder.scrollHeight-this.oldScrollHeight) );
|
$(postHolder).scrollTop($(postHolder).scrollTop() + (postHolder.scrollHeight - this.oldScrollHeight));
|
||||||
} else {
|
} else if ($('#new_message')[0] && !this.scrolledToNew) {
|
||||||
if ($("#new_message")[0] && !this.scrolledToNew) {
|
$(postHolder).scrollTop($(postHolder).scrollTop() + $('#new_message').offset().top - 63);
|
||||||
$(post_holder).scrollTop($(post_holder).scrollTop() + $("#new_message").offset().top - 63);
|
|
||||||
this.scrolledToNew = true;
|
this.scrolledToNew = true;
|
||||||
} else {
|
} else {
|
||||||
$(post_holder).scrollTop(post_holder.scrollHeight);
|
$(postHolder).scrollTop(postHolder.scrollHeight);
|
||||||
}
|
}
|
||||||
}
|
$(postHolder).perfectScrollbar('update');
|
||||||
$(post_holder).perfectScrollbar('update');
|
|
||||||
},
|
},
|
||||||
_onChange: function() {
|
onChange: function() {
|
||||||
var newState = getStateFromStores();
|
var newState = getStateFromStores();
|
||||||
|
|
||||||
if (!utils.areStatesEqual(newState, this.state)) {
|
if (!utils.areStatesEqual(newState, this.state)) {
|
||||||
if (this.state.post_list && this.state.post_list.order) {
|
if (this.state.postList && this.state.postList.order) {
|
||||||
if (this.state.channel.id === newState.channel.id && this.state.post_list.order.length != newState.post_list.order.length && newState.post_list.order.length > Constants.POST_CHUNK_SIZE) {
|
if (this.state.channel.id === newState.channel.id && this.state.postList.order.length !== newState.postList.order.length && newState.postList.order.length > Constants.POST_CHUNK_SIZE) {
|
||||||
this.gotMorePosts = true;
|
this.gotMorePosts = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,99 +198,119 @@ module.exports = React.createClass({
|
|||||||
PostStore.storePost(post);
|
PostStore.storePost(post);
|
||||||
} else if (msg.action === 'post_edited') {
|
} else if (msg.action === 'post_edited') {
|
||||||
if (this.state.channel.id === msg.channel_id) {
|
if (this.state.channel.id === msg.channel_id) {
|
||||||
this.setState({ post_list: post_list });
|
this.setState({postList: postList});
|
||||||
};
|
}
|
||||||
|
|
||||||
PostStore.storePosts(post.channel_id, post_list);
|
PostStore.storePosts(post.channel_id, postList);
|
||||||
} else if (msg.action == "post_edited") {
|
} else if (msg.action === 'post_edited') {
|
||||||
if (this.state.channel.id == msg.channel_id) {
|
if (this.state.channel.id === msg.channel_id) {
|
||||||
var post_list = this.state.post_list;
|
postList = this.state.postList;
|
||||||
if (!(msg.props.post_id in post_list.posts)) return;
|
if (!(msg.props.post_id in postList.posts)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var post = post_list.posts[msg.props.post_id];
|
post = postList.posts[msg.props.post_id];
|
||||||
post.message = msg.props.message;
|
post.message = msg.props.message;
|
||||||
|
|
||||||
post_list.posts[post.id] = post;
|
postList.posts[post.id] = post;
|
||||||
this.setState({ post_list: post_list });
|
this.setState({postList: postList});
|
||||||
|
|
||||||
PostStore.storePosts(msg.channel_id, post_list);
|
PostStore.storePosts(msg.channel_id, postList);
|
||||||
} else {
|
} else {
|
||||||
AsyncClient.getPosts(true, msg.channel_id);
|
AsyncClient.getPosts(true, msg.channel_id);
|
||||||
}
|
}
|
||||||
} else if (msg.action == "post_deleted") {
|
} else if (msg.action === 'post_deleted') {
|
||||||
var activeRoot = $(document.activeElement).closest('.comment-create-body')[0];
|
var activeRoot = $(document.activeElement).closest('.comment-create-body')[0];
|
||||||
var activeRootPostId = activeRoot && activeRoot.id.length > 0 ? activeRoot.id : "";
|
var activeRootPostId = '';
|
||||||
|
if (activeRoot && activeRoot.id.length > 0) {
|
||||||
|
activeRootPostId = activeRoot.id;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.state.channel.id == msg.channel_id) {
|
if (this.state.channel.id === msg.channel_id) {
|
||||||
var post_list = this.state.post_list;
|
postList = this.state.postList;
|
||||||
if (!(msg.props.post_id in this.state.post_list.posts)) return;
|
if (!(msg.props.post_id in this.state.postList.posts)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
delete post_list.posts[msg.props.post_id];
|
delete postList.posts[msg.props.post_id];
|
||||||
var index = post_list.order.indexOf(msg.props.post_id);
|
var index = postList.order.indexOf(msg.props.post_id);
|
||||||
if (index > -1) post_list.order.splice(index, 1);
|
if (index > -1) {
|
||||||
|
postList.order.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({ post_list: post_list });
|
this.setState({postList: postList});
|
||||||
|
|
||||||
PostStore.storePosts(msg.channel_id, post_list);
|
PostStore.storePosts(msg.channel_id, postList);
|
||||||
} else {
|
} else {
|
||||||
AsyncClient.getPosts(true, msg.channel_id);
|
AsyncClient.getPosts(true, msg.channel_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeRootPostId === msg.props.post_id && UserStore.getCurrentId() != msg.user_id) {
|
if (activeRootPostId === msg.props.post_id && UserStore.getCurrentId() !== msg.user_id) {
|
||||||
$('#post_deleted').modal('show');
|
$('#post_deleted').modal('show');
|
||||||
}
|
}
|
||||||
} else if (msg.action == "new_user") {
|
} else if (msg.action === 'new_user') {
|
||||||
AsyncClient.getProfiles();
|
AsyncClient.getProfiles();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_onTimeChange: function() {
|
onTimeChange: function() {
|
||||||
if (!this.state.post_list) return;
|
if (!this.state.postList) {
|
||||||
for (var id in this.state.post_list.posts) {
|
return;
|
||||||
if (!this.refs[id]) continue;
|
}
|
||||||
|
|
||||||
|
for (var id in this.state.postList.posts) {
|
||||||
|
if (!this.refs[id]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
this.refs[id].forceUpdateInfo();
|
this.refs[id].forceUpdateInfo();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getMorePosts: function(e) {
|
getMorePosts: function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (!this.state.post_list) return;
|
if (!this.state.postList) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var posts = this.state.post_list.posts;
|
var posts = this.state.postList.posts;
|
||||||
var order = this.state.post_list.order;
|
var order = this.state.postList.order;
|
||||||
var channel_id = this.state.channel.id;
|
var channelId = this.state.channel.id;
|
||||||
|
|
||||||
$(this.refs.loadmore.getDOMNode()).text("Retrieving more messages...");
|
$(this.refs.loadmore.getDOMNode()).text('Retrieving more messages...');
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var currentPos = $(".post-list").scrollTop;
|
var currentPos = $('.post-list').scrollTop;
|
||||||
|
|
||||||
Client.getPosts(
|
Client.getPosts(
|
||||||
channel_id,
|
channelId,
|
||||||
order.length,
|
order.length,
|
||||||
Constants.POST_CHUNK_SIZE,
|
Constants.POST_CHUNK_SIZE,
|
||||||
function(data) {
|
function success(data) {
|
||||||
$(self.refs.loadmore.getDOMNode()).text("Load more messages");
|
$(self.refs.loadmore.getDOMNode()).text('Load more messages');
|
||||||
|
|
||||||
if (!data) return;
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (data.order.length === 0) return;
|
if (data.order.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var post_list = {}
|
var postList = {};
|
||||||
post_list.posts = $.extend(posts, data.posts);
|
postList.posts = $.extend(posts, data.posts);
|
||||||
post_list.order = order.concat(data.order);
|
postList.order = order.concat(data.order);
|
||||||
|
|
||||||
AppDispatcher.handleServerAction({
|
AppDispatcher.handleServerAction({
|
||||||
type: ActionTypes.RECIEVED_POSTS,
|
type: ActionTypes.RECIEVED_POSTS,
|
||||||
id: channel_id,
|
id: channelId,
|
||||||
post_list: post_list
|
postList: postList
|
||||||
});
|
});
|
||||||
|
|
||||||
Client.getProfiles();
|
Client.getProfiles();
|
||||||
$(".post-list").scrollTop(currentPos);
|
$('.post-list').scrollTop(currentPos);
|
||||||
},
|
},
|
||||||
function(err) {
|
function fail(err) {
|
||||||
$(self.refs.loadmore.getDOMNode()).text("Load more messages");
|
$(self.refs.loadmore.getDOMNode()).text('Load more messages');
|
||||||
AsyncClient.dispatchError(err, "getPosts");
|
AsyncClient.dispatchError(err, 'getPosts');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -305,81 +321,86 @@ module.exports = React.createClass({
|
|||||||
var order = [];
|
var order = [];
|
||||||
var posts;
|
var posts;
|
||||||
|
|
||||||
var last_viewed = Number.MAX_VALUE;
|
var lastViewed = Number.MAX_VALUE;
|
||||||
|
|
||||||
if (ChannelStore.getCurrentMember() != null)
|
if (ChannelStore.getCurrentMember() != null) {
|
||||||
last_viewed = ChannelStore.getCurrentMember().last_viewed_at;
|
lastViewed = ChannelStore.getCurrentMember().lastViewed_at;
|
||||||
|
|
||||||
if (this.state.post_list != null) {
|
|
||||||
posts = this.state.post_list.posts;
|
|
||||||
order = this.state.post_list.order;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var rendered_last_viewed = false;
|
if (this.state.postList != null) {
|
||||||
|
posts = this.state.postList.posts;
|
||||||
|
order = this.state.postList.order;
|
||||||
|
}
|
||||||
|
|
||||||
var user_id = "";
|
var renderedLastViewed = false;
|
||||||
|
|
||||||
|
var userId = '';
|
||||||
if (UserStore.getCurrentId()) {
|
if (UserStore.getCurrentId()) {
|
||||||
user_id = UserStore.getCurrentId();
|
userId = UserStore.getCurrentId();
|
||||||
} else {
|
} else {
|
||||||
return <div/>;
|
return <div/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
var channel = this.state.channel;
|
var channel = this.state.channel;
|
||||||
|
|
||||||
var more_messages = <p className="beginning-messages-text">Beginning of Channel</p>;
|
var moreMessages = <p className='beginning-messages-text'>Beginning of Channel</p>;
|
||||||
|
|
||||||
var userStyle = { color: UserStore.getCurrentUser().props.theme }
|
var userStyle = {color: UserStore.getCurrentUser().props.theme};
|
||||||
|
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
if (order.length > 0 && order.length % Constants.POST_CHUNK_SIZE === 0) {
|
if (order.length > 0 && order.length % Constants.POST_CHUNK_SIZE === 0) {
|
||||||
more_messages = <a ref="loadmore" className="more-messages-text theme" href="#" onClick={this.getMorePosts}>Load more messages</a>;
|
moreMessages = <a ref='loadmore' className='more-messages-text theme' href='#' onClick={this.getMorePosts}>Load more messages</a>;
|
||||||
} else if (channel.type === 'D') {
|
} else if (channel.type === 'D') {
|
||||||
var teammate = utils.getDirectTeammate(channel.id)
|
var teammate = utils.getDirectTeammate(channel.id);
|
||||||
|
|
||||||
if (teammate) {
|
if (teammate) {
|
||||||
var teammate_name = teammate.nickname.length > 0 ? teammate.nickname : teammate.username;
|
var teammateName = teammate.username;
|
||||||
more_messages = (
|
if (teammate.nickname.length > 0) {
|
||||||
<div className="channel-intro">
|
teammateName = teammate.nickname;
|
||||||
<div className="post-profile-img__container channel-intro-img">
|
}
|
||||||
<img className="post-profile-img" src={"/api/v1/users/" + teammate.id + "/image?time=" + teammate.update_at} height="50" width="50" />
|
|
||||||
|
moreMessages = (
|
||||||
|
<div className='channel-intro'>
|
||||||
|
<div className='post-profile-img__container channel-intro-img'>
|
||||||
|
<img className='post-profile-img' src={'/api/v1/users/' + teammate.id + '/image?time=' + teammate.update_at} height='50' width='50' />
|
||||||
</div>
|
</div>
|
||||||
<div className="channel-intro-profile">
|
<div className='channel-intro-profile'>
|
||||||
<strong><UserProfile userId={teammate.id} /></strong>
|
<strong><UserProfile userId={teammate.id} /></strong>
|
||||||
</div>
|
</div>
|
||||||
<p className="channel-intro-text">
|
<p className='channel-intro-text'>
|
||||||
{"This is the start of your private message history with " + teammate_name + "." }<br/>
|
{'This is the start of your private message history with ' + teammateName + '.'}<br/>
|
||||||
{"Private messages and files shared here are not shown to people outside this area."}
|
{'Private messages and files shared here are not shown to people outside this area.'}
|
||||||
</p>
|
</p>
|
||||||
<a className="intro-links" href="#" style={userStyle} data-toggle="modal" data-target="#edit_channel" data-desc={channel.description} data-title={channel.display_name} data-channelid={channel.id}><i className="fa fa-pencil"></i>Set a description</a>
|
<a className='intro-links' href='#' style={userStyle} data-toggle='modal' data-target='#edit_channel' data-desc={channel.description} data-title={channel.display_name} data-channelid={channel.id}><i className='fa fa-pencil'></i>Set a description</a>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
more_messages = (
|
moreMessages = (
|
||||||
<div className="channel-intro">
|
<div className='channel-intro'>
|
||||||
<p className="channel-intro-text">{"This is the start of your private message history with this " + strings.Team + "mate. Private messages and files shared here are not shown to people outside this area."}</p>
|
<p className='channel-intro-text'>{'This is the start of your private message history with this ' + strings.Team + 'mate. Private messages and files shared here are not shown to people outside this area.'}</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (channel.type === 'P' || channel.type === 'O') {
|
} else if (channel.type === 'P' || channel.type === 'O') {
|
||||||
var ui_name = channel.display_name
|
var uiName = channel.display_name;
|
||||||
var members = ChannelStore.getCurrentExtraInfo().members;
|
var members = ChannelStore.getCurrentExtraInfo().members;
|
||||||
var creator_name = "";
|
var creatorName = '';
|
||||||
|
|
||||||
for (var i = 0; i < members.length; i++) {
|
for (var i = 0; i < members.length; i++) {
|
||||||
if (members[i].roles.indexOf('admin') > -1) {
|
if (members[i].roles.indexOf('admin') > -1) {
|
||||||
creator_name = members[i].username;
|
creatorName = members[i].username;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ChannelStore.isDefault(channel)) {
|
if (ChannelStore.isDefault(channel)) {
|
||||||
more_messages = (
|
moreMessages = (
|
||||||
<div className="channel-intro">
|
<div className='channel-intro'>
|
||||||
<h4 className="channel-intro__title">Beginning of {ui_name}</h4>
|
<h4 className='channel-intro__title'>Beginning of {uiName}</h4>
|
||||||
<p className="channel-intro__content">
|
<p className='channel-intro__content'>
|
||||||
Welcome to {ui_name}!
|
Welcome to {uiName}!
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
{"This is the first channel " + strings.Team + "mates see when they"}
|
{'This is the first channel ' + strings.Team + 'mates see when they'}
|
||||||
<br/>
|
<br/>
|
||||||
sign up - use it for posting updates everyone needs to know.
|
sign up - use it for posting updates everyone needs to know.
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
@@ -391,29 +412,44 @@ module.exports = React.createClass({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else if (channel.name === Constants.OFFTOPIC_CHANNEL) {
|
} else if (channel.name === Constants.OFFTOPIC_CHANNEL) {
|
||||||
more_messages = (
|
moreMessages = (
|
||||||
<div className="channel-intro">
|
<div className='channel-intro'>
|
||||||
<h4 className="channel-intro__title">Beginning of {ui_name}</h4>
|
<h4 className='channel-intro__title'>Beginning of {uiName}</h4>
|
||||||
<p className="channel-intro__content">
|
<p className='channel-intro__content'>
|
||||||
{"This is the start of " + ui_name + ", a channel for non-work-related conversations."}
|
{'This is the start of ' + uiName + ', a channel for non-work-related conversations.'}
|
||||||
<br/>
|
<br/>
|
||||||
</p>
|
</p>
|
||||||
<a className="intro-links" href="#" style={userStyle} data-toggle="modal" data-target="#edit_channel" data-desc={channel.description} data-title={ui_name} data-channelid={channel.id}><i className="fa fa-pencil"></i>Set a description</a>
|
<a className='intro-links' href='#' style={userStyle} data-toggle='modal' data-target='#edit_channel' data-desc={channel.description} data-title={uiName} data-channelid={channel.id}><i className='fa fa-pencil'></i>Set a description</a>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
var ui_type = channel.type === 'P' ? "private group" : "channel";
|
var uiType;
|
||||||
more_messages = (
|
var memberMessage;
|
||||||
<div className="channel-intro">
|
if (channel.type === 'P') {
|
||||||
<h4 className="channel-intro__title">Beginning of {ui_name}</h4>
|
uiType = 'private group';
|
||||||
<p className="channel-intro__content">
|
memberMessage = ' Only invited members can see this private group.';
|
||||||
{ creator_name != "" ? "This is the start of the " + ui_name + " " + ui_type + ", created by " + creator_name + " on " + utils.displayDate(channel.create_at) + "."
|
} else {
|
||||||
: "This is the start of the " + ui_name + " " + ui_type + ", created on "+ utils.displayDate(channel.create_at) + "." }
|
uiType = 'channel';
|
||||||
{ channel.type === 'P' ? " Only invited members can see this private group." : " Any member can join and read this channel." }
|
memberMessage = ' Any member can join and read this channel.';
|
||||||
|
}
|
||||||
|
|
||||||
|
var createMessage;
|
||||||
|
if (creatorName !== '') {
|
||||||
|
createMessage = 'This is the start of the ' + uiName + ' ' + uiType + ', created by ' + creatorName + ' on ' + utils.displayDate(channel.create_at) + '.';
|
||||||
|
} else {
|
||||||
|
createMessage = 'This is the start of the ' + uiName + ' ' + uiType + ', created on ' + utils.displayDate(channel.create_at) + '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
moreMessages = (
|
||||||
|
<div className='channel-intro'>
|
||||||
|
<h4 className='channel-intro__title'>Beginning of {uiName}</h4>
|
||||||
|
<p className='channel-intro__content'>
|
||||||
|
{createMessage}
|
||||||
|
{memberMessage}
|
||||||
<br/>
|
<br/>
|
||||||
</p>
|
</p>
|
||||||
<a className="intro-links" href="#" style={userStyle} data-toggle="modal" data-target="#edit_channel" data-desc={channel.description} data-title={channel.display_name} data-channelid={channel.id}><i className="fa fa-pencil"></i>Set a description</a>
|
<a className='intro-links' href='#' style={userStyle} data-toggle='modal' data-target='#edit_channel' data-desc={channel.description} data-title={channel.display_name} data-channelid={channel.id}><i className='fa fa-pencil'></i>Set a description</a>
|
||||||
<a className="intro-links" href="#" style={userStyle} data-toggle="modal" data-target="#channel_invite"><i className="fa fa-user-plus"></i>Invite others to this {ui_type}</a>
|
<a className='intro-links' href='#' style={userStyle} data-toggle='modal' data-target='#channel_invite'><i className='fa fa-user-plus'></i>Invite others to this {uiType}</a>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -428,15 +464,23 @@ module.exports = React.createClass({
|
|||||||
|
|
||||||
for (var i = order.length - 1; i >= 0; i--) {
|
for (var i = order.length - 1; i >= 0; i--) {
|
||||||
var post = posts[order[i]];
|
var post = posts[order[i]];
|
||||||
var parentPost = post.parent_id ? posts[post.parent_id] : null;
|
var parentPost = null;
|
||||||
|
if (post.parent_id) {
|
||||||
|
parentPost = posts[post.parent_id];
|
||||||
|
}
|
||||||
|
|
||||||
var sameUser = '';
|
var sameUser = '';
|
||||||
var sameRoot = false;
|
var sameRoot = false;
|
||||||
var hideProfilePic = false;
|
var hideProfilePic = false;
|
||||||
var prevPost = (i < order.length - 1) ? posts[order[i + 1]] : null;
|
var prevPost;
|
||||||
|
if (i < order.length - 1) {
|
||||||
|
prevPost = posts[order[i + 1]];
|
||||||
|
}
|
||||||
|
|
||||||
if (prevPost) {
|
if (prevPost) {
|
||||||
sameUser = (prevPost.user_id === post.user_id) && (post.create_at - prevPost.create_at <= 1000*60*5) ? "same--user" : "";
|
if ((prevPost.user_id === post.user_id) && (post.create_at - prevPost.create_at <= 1000 * 60 * 5)) {
|
||||||
|
sameUser = 'same--user';
|
||||||
|
}
|
||||||
sameRoot = utils.isComment(post) && (prevPost.id === post.root_id || prevPost.root_id === post.root_id);
|
sameRoot = utils.isComment(post) && (prevPost.id === post.root_id || prevPost.root_id === post.root_id);
|
||||||
|
|
||||||
// we only hide the profile pic if the previous post is not a comment, the current post is not a comment, and the previous post was made by the same user as the current post
|
// we only hide the profile pic if the previous post is not a comment, the current post is not a comment, and the previous post was made by the same user as the current post
|
||||||
@@ -445,7 +489,7 @@ module.exports = React.createClass({
|
|||||||
|
|
||||||
// check if it's the last comment in a consecutive string of comments on the same post
|
// check if it's the last comment in a consecutive string of comments on the same post
|
||||||
// it is the last comment if it is last post in the channel or the next post has a different root post
|
// it is the last comment if it is last post in the channel or the next post has a different root post
|
||||||
var isLastComment = utils.isComment(post) && (i === 0 || posts[order[i-1]].root_id != post.root_id);
|
var isLastComment = utils.isComment(post) && (i === 0 || posts[order[i - 1]].root_id !== post.root_id);
|
||||||
|
|
||||||
var postCtl = (
|
var postCtl = (
|
||||||
<Post ref={post.id} sameUser={sameUser} sameRoot={sameRoot} post={post} parentPost={parentPost} key={post.id}
|
<Post ref={post.id} sameUser={sameUser} sameRoot={sameRoot} post={post} parentPost={parentPost} key={post.id}
|
||||||
@@ -454,23 +498,21 @@ module.exports = React.createClass({
|
|||||||
);
|
);
|
||||||
|
|
||||||
currentPostDay = utils.getDateForUnixTicks(post.create_at);
|
currentPostDay = utils.getDateForUnixTicks(post.create_at);
|
||||||
if (currentPostDay.toDateString() != previousPostDay.toDateString()) {
|
if (currentPostDay.toDateString() !== previousPostDay.toDateString()) {
|
||||||
postCtls.push(
|
postCtls.push(
|
||||||
<div key={currentPostDay.toDateString()} className="date-separator">
|
<div key={currentPostDay.toDateString()} className='date-separator'>
|
||||||
<hr className="separator__hr" />
|
<hr className='separator__hr' />
|
||||||
<div className="separator__text">{currentPostDay.toDateString()}</div>
|
<div className='separator__text'>{currentPostDay.toDateString()}</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var userId = UserStore.getCurrentId();
|
if (post.user_id !== userId && post.create_at > lastViewed && !renderedLastViewed) {
|
||||||
|
renderedLastViewed = true;
|
||||||
if (post.user_id !== userId && post.create_at > last_viewed && !rendered_last_viewed) {
|
|
||||||
rendered_last_viewed = true;
|
|
||||||
postCtls.push(
|
postCtls.push(
|
||||||
<div key="unviewed" className="new-separator">
|
<div key='unviewed' className='new-separator'>
|
||||||
<hr id="new_message" className="separator__hr" />
|
<hr id='new_message' className='separator__hr' />
|
||||||
<div className="separator__text">New Messages</div>
|
<div className='separator__text'>New Messages</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -478,14 +520,14 @@ module.exports = React.createClass({
|
|||||||
previousPostDay = currentPostDay;
|
previousPostDay = currentPostDay;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
postCtls.push(<LoadingScreen position="absolute" />);
|
postCtls.push(<LoadingScreen position='absolute' />);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref="postlist" className="post-list-holder-by-time">
|
<div ref='postlist' className='post-list-holder-by-time'>
|
||||||
<div className="post-list__table">
|
<div className='post-list__table'>
|
||||||
<div className="post-list__content">
|
<div className='post-list__content'>
|
||||||
{ more_messages }
|
{moreMessages}
|
||||||
{postCtls}
|
{postCtls}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user