import React from "react" import * as actions from "./controls/actions" import LikesModal from "misago/components/post-likes" import modal from "misago/services/modal" import posting from "misago/services/posting" export default function(props) { if (!isVisible(props.post)) return null return (
{getLikesMessage(this.props.likes, this.props.lastLikes)}
) } } export class LikesCompact extends Likes { render() { const hasLikes = (this.props.post.last_likes || []).length > 0 if (!this.props.post.acl.can_see_likes || !hasLikes) return null if (this.props.post.acl.can_see_likes === 2) { return ( ) } return (favorite {this.props.likes}
) } } export function getLikesMessage(likes, users) { const usernames = users.slice(0, 3).map(u => u.username) if (usernames.length == 1) { return interpolate( gettext("%(user)s likes this."), { user: usernames[0] }, true ) } const hiddenLikes = likes - usernames.length const otherUsers = usernames.slice(0, -1).join(", ") const lastUser = usernames.slice(-1)[0] const usernamesList = interpolate( gettext("%(users)s and %(last_user)s"), { users: otherUsers, last_user: lastUser }, true ) if (hiddenLikes === 0) { return interpolate( gettext("%(users)s like this."), { users: usernamesList }, true ) } const message = ngettext( "%(users)s and %(likes)s other user like this.", "%(users)s and %(likes)s other users like this.", hiddenLikes ) return interpolate( message, { users: usernames.join(", "), likes: hiddenLikes }, true ) } export class Reply extends React.Component { onClick = () => { posting.open({ mode: "REPLY", config: this.props.thread.api.editor, submit: this.props.thread.api.posts.index, context: { reply: this.props.post.id } }) } render() { if (this.props.post.acl.can_reply) { return ( ) } else { return null } } } export class Edit extends React.Component { onClick = () => { posting.open({ mode: "EDIT", config: this.props.post.api.editor, submit: this.props.post.api.index }) } render() { if (this.props.post.acl.can_edit) { return ( ) } else { return null } } }