mirror of
https://github.com/twisterarmy/twister-react.git
synced 2025-01-12 07:58:14 +00:00
72 lines
2.2 KiB
JavaScript
72 lines
2.2 KiB
JavaScript
module.exports = StreamMixin = {
|
|
|
|
addPost: function(post) {
|
|
|
|
var postid = post.getUsername() + ":post" + post.getId();
|
|
|
|
if (!this.state.postIdentifiers[postid]) {
|
|
|
|
this.setStateSafe(function(previousState, currentProps) {
|
|
|
|
previousState.postIdentifiers[postid] = true;
|
|
|
|
if (post.isRetwist()){
|
|
|
|
|
|
var postdata = {
|
|
username: post.getRetwistedUser(),
|
|
retwistingUser: post.getUsername(),
|
|
content: post.getRetwistedContent(),
|
|
id: post.getRetwistedId(),
|
|
timestamp: post.getTimestamp(),
|
|
postid: postid,
|
|
isRetwist: true
|
|
}
|
|
|
|
} else {
|
|
|
|
var postdata = {
|
|
username: post.getUsername(),
|
|
content: post.getContent(),
|
|
id: post.getId(),
|
|
timestamp: post.getTimestamp(),
|
|
postid: postid,
|
|
isRetwist: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (post.isReply()) {
|
|
|
|
postdata.isReply = true;
|
|
postdata.replyUser = post.getReplyUser();
|
|
postdata.replyId = post.getReplyId();
|
|
|
|
} else {
|
|
|
|
postdata.isReply = false;
|
|
|
|
}
|
|
|
|
previousState.data.push(postdata)
|
|
|
|
var compare = function (a,b) {
|
|
if (a.timestamp < b.timestamp)
|
|
return 1;
|
|
if (a.timestamp > b.timestamp)
|
|
return -1;
|
|
return 0;
|
|
}
|
|
|
|
previousState.data.sort(compare);
|
|
|
|
return {data: previousState.data, postIdentifiers: previousState.postIdentifiers };
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
}
|
|
}
|
|
} |