@fractastical ChatPostWrapper class


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. class ChatPostWrapper {
  2.  
  3. Chat_Session__Feed post;
  4. public String postBody { get; set; }
  5. public String userHandle { get; set; }
  6. public String createdDate { get; set; }
  7. public Boolean newPost { get; set; }
  8. public Boolean systemMessage { get; private set; }
  9.  
  10. public List<FeedComment> comments { get; set; }
  11.  
  12. public ChatPostWrapper(Chat_Session__Feed post)
  13. {
  14. newPost = true;
  15. this.post = post;
  16. createdDate = post.createdDate.format('d MMM yy HH:mm:ss Z');
  17. if(post.FeedPost.Body.length() > 1)
  18. if(post.FeedPost.Body.substring(0,1) == '@')
  19. {
  20. try {
  21. String[] s = post.FeedPost.Body.split(': ',2);
  22. userHandle = s[0];
  23. postBody = s[1];
  24. if(userHandle == '@System')
  25. systemMessage = true;
  26.  
  27. }
  28. catch (Exception e)
  29. {
  30. System.debug('ChatPostWrapperConstructor:' + e);
  31. userHandle = 'Anonymous';
  32. postBody = post.FeedPost.Body;
  33. }
  34. }
  35. else
  36. {
  37. postBody = post.FeedPost.Body;
  38. userHandle = 'Anonymous';
  39. }
  40. //System.debug('ChatPostWrapper comment size:' + post.FeedComments.size());
  41. try {
  42. comments = post.FeedComments;
  43. }
  44. catch (Exception e)
  45. {
  46.  
  47.  
  48. }
  49. }
  50.  
  51. public ChatPostWrapper(Chat_Session__Feed post, List<Chat_Session__Feed> oldPosts)
  52. {
  53. System.debug('ChatPostWrapper Constructor checking old posts... START');
  54. this.post = post;
  55. newPost = true;
  56. if(oldPosts != null)
  57. {
  58. System.debug('Old posts is not null');
  59.  
  60. for(Chat_Session__Feed op : oldPosts)
  61. {
  62. System.debug('ChatPostWrapper Constructor checking old posts...' + op.id);
  63. if(op.id == post.id)
  64. newPost = false;
  65. }
  66.  
  67. }
  68. System.debug('New post? ' + newPost);
  69.  
  70. createdDate = post.createdDate.format('d MMM yy HH:mm:ss Z');
  71. if(post.FeedPost.Body.length() > 1)
  72. if(post.FeedPost.Body.substring(0,1) == '@')
  73. {
  74. try {
  75. String[] s = post.FeedPost.Body.split(': ',2);
  76. userHandle = s[0];
  77. postBody = s[1];
  78. if(userHandle == '@System')
  79. systemMessage = true;
  80. }
  81. catch (Exception e)
  82. {
  83. System.debug('ChatPostWrapperConstructor:' + e);
  84. userHandle = 'Anonymous';
  85. postBody = post.FeedPost.Body;
  86. }
  87. }
  88. else
  89. {
  90. postBody = post.FeedPost.Body;
  91. userHandle = 'Anonymous';
  92. }
  93. System.debug('ChatPostWrapper comment size:' + post.FeedComments.size());
  94. comments = post.FeedComments;
  95. }
  96.  
  97. public Boolean getHasComments()
  98. {
  99. if(comments.size() > 0)
  100. return true;
  101. else
  102. return false;
  103.  
  104. }
  105.  
  106. }
  107.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.