github.com/decred/politeia@v1.4.0/politeiawww/cmd/pictl/comment.go (about)

     1  // Copyright (c) 2020-2021 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"strings"
     9  
    10  	cmv1 "github.com/decred/politeia/politeiawww/api/comments/v1"
    11  )
    12  
    13  func printComment(c cmv1.Comment) {
    14  	downvotes := int64(c.Downvotes) * -1
    15  
    16  	printf("Comment %v\n", c.CommentID)
    17  	printf("  Score        : %v %v\n", downvotes, c.Upvotes)
    18  	printf("  Username     : %v\n", c.Username)
    19  	printf("  Parent ID    : %v\n", c.ParentID)
    20  	printf("  Timestamp    : %v\n", dateAndTimeFromUnix(c.Timestamp))
    21  
    22  	// If the comment is an author update print extra data info
    23  	if c.ExtraDataHint != "" {
    24  		printf("  ExtraDataHint: %v\n", c.ExtraDataHint)
    25  		printf("  ExtraData    : %v\n", c.ExtraData)
    26  	}
    27  
    28  	// If the comment has been deleted the comment text will not be
    29  	// present. Print the reason for deletion instead and exit.
    30  	if c.Deleted {
    31  		printf("  Deleted      : %v\n", c.Deleted)
    32  		printf("  Reason       : %v\n", c.Reason)
    33  		return
    34  	}
    35  
    36  	// Print the fist line as is if its less than the 80 character
    37  	// limit (including the leading comment label).
    38  	if len(c.Comment) < 66 {
    39  		printf("  Comment      : %v\n", c.Comment)
    40  		return
    41  	}
    42  
    43  	// Format lines as 80 characters that start with two spaces.
    44  	var b strings.Builder
    45  	b.WriteString("  ")
    46  	for i, v := range c.Comment {
    47  		if i != 0 && i%78 == 0 {
    48  			b.WriteString("\n")
    49  			b.WriteString("  ")
    50  		}
    51  		b.WriteString(string(v))
    52  	}
    53  	printf("  Comment  :\n")
    54  	printf("%v\n", b.String())
    55  }
    56  
    57  func printCommentVotes(votes []cmv1.CommentVote) {
    58  	if len(votes) == 0 {
    59  		return
    60  	}
    61  	printf("Token   : %v\n", votes[0].Token)
    62  	printf("Votes\n")
    63  
    64  	for _, v := range votes {
    65  		printf("  %-22v userid %v username %v comment %v vote %v \n",
    66  			dateAndTimeFromUnix(v.Timestamp), v.UserID, v.Username, v.CommentID,
    67  			v.Vote)
    68  	}
    69  }