mixin chatMessages(inbox)
  ul.list-unstyled.tavern-chat
    - var ngRepeat = inbox ? 'message in user.inbox.messages | toArray:true | orderBy:"sort":true' : 'message in group.chat track by message.id'
    li.chat-message(ng-repeat=ngRepeat, ng-class=':: {highlight: isUserMentioned(user,message) || message.uuid=="system", "own-message": user._id == message.uuid}', ng-if="!message.flagCount || message.flagCount < 2 || user.contributor.admin")
      span.pull-right.text-danger(ng-if="user.contributor.admin && message.flagCount > 0")
        | {{message.flagCount > 1 ? "Message Hidden" : "1 flag"}}
      .scrollable-message(ng-class='{"transparent": message.sent || message.flags[user._id] || (user.contributor.admin && message.flagCount > 1)}')
        span(ng-if='::message.user')
          a.label.label-default.chat-message.hidden-label
            span.glyphicon.glyphicon-arrow-right(ng-if='::message.sent')
            | &nbsp; &nbsp;
            span {{::message.user}}&nbsp;
            span(ng-class='userAdminGlyphiconStyleFromLevel(message.contributor.level)')
            // this invisible username label is here to push the message text far enough right that the visible label can be floated to this point without covering up any of the text
        markdown(text='::message.text', remove-watch='true')
        | -
        span.muted.time(from-now='::message.timestamp' tooltip="{{::message.timestamp | date:user.preferences.dateFormat.concat(' HH:mm:ss')}}")
        unless inbox
          span
            a.label.label-default(ng-show='countExists(message.likes)', ng-class='{"label-success":message.likes[user._id]}', ng-click='likeChatMessage(group,message)') +{{countExists(message.likes)}}
            a.chat-plus-one.muted(ng-show='!countExists(message.likes)', ng-click='likeChatMessage(group, message)') +1
          | &nbsp; &nbsp;
          a(ng-click="quickReply(message.uuid)" ng-if=":: message.uuid != 'system'")
            span.glyphicon.glyphicon-envelope(tooltip=env.t('sendPM'))
        if inbox
          a(ng-click="quickReply(message.uuid)")
            span.glyphicon.glyphicon-share-alt(tooltip=env.t('pm-reply'))
        | &nbsp; &nbsp;
        a(ng-click='#{inbox? "user.ops.deletePM({params:{id:message.$key}})" : "deleteChatMessage(group, message)"}', ng-if='#{inbox ? "true" : ":: user.contributor.admin || message.uuid == user.id"}')
          span.glyphicon.glyphicon-trash(tooltip=env.t('delete'))
        | &nbsp; &nbsp;
        a(ng-click="flagChatMessage(group._id, message)", ng-if=':: user.contributor.admin || (!message.sent && user.flags.communityGuidelinesAccepted && message.uuid != user.id && message.uuid != "system")')
          span.glyphicon.glyphicon-flag(tooltip="{{message.flags[user._id] ? env.t('abuseAlreadyReported') : env.t('abuseFlag')}}" ng-class='message.flags[user._id] ? "text-danger" : ""')
      span.float-label(ng-class='::contribText(message.contributor, message.backer).length > 30 ? "long-title" : ""')
        a.label.label-default.chat-message(ng-if=':: message.user', ng-class='::userLevelStyleFromLevel(message.contributor.level, message.backer.npc, style)', ng-click='clickMember(message.uuid, true)')
          span.glyphicon.glyphicon-arrow-right(ng-if='::message.sent')
          | &nbsp;
          span(tooltip='{{::contribText(message.contributor, message.backer)}}') {{::message.user}}&nbsp;
          span(ng-class='::userAdminGlyphiconStyleFromLevel(message.contributor.level)')
