Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fractastical/989769 to your computer and use it in GitHub Desktop.
Save fractastical/989769 to your computer and use it in GitHub Desktop.
@fractastical ChatPostWrapper class
class ChatPostWrapper {
Chat_Session__Feed post;
public String postBody { get; set; }
public String userHandle { get; set; }
public String createdDate { get; set; }
public Boolean newPost { get; set; }
public Boolean systemMessage { get; private set; }
public List<FeedComment> comments { get; set; }
public ChatPostWrapper(Chat_Session__Feed post)
{
newPost = true;
this.post = post;
createdDate = post.createdDate.format('d MMM yy HH:mm:ss Z');
if(post.FeedPost.Body.length() > 1)
if(post.FeedPost.Body.substring(0,1) == '@')
{
try {
String[] s = post.FeedPost.Body.split(': ',2);
userHandle = s[0];
postBody = s[1];
if(userHandle == '@System')
systemMessage = true;
}
catch (Exception e)
{
System.debug('ChatPostWrapperConstructor:' + e);
userHandle = 'Anonymous';
postBody = post.FeedPost.Body;
}
}
else
{
postBody = post.FeedPost.Body;
userHandle = 'Anonymous';
}
//System.debug('ChatPostWrapper comment size:' + post.FeedComments.size());
try {
comments = post.FeedComments;
}
catch (Exception e)
{
}
}
public ChatPostWrapper(Chat_Session__Feed post, List<Chat_Session__Feed> oldPosts)
{
System.debug('ChatPostWrapper Constructor checking old posts... START');
this.post = post;
newPost = true;
if(oldPosts != null)
{
System.debug('Old posts is not null');
for(Chat_Session__Feed op : oldPosts)
{
System.debug('ChatPostWrapper Constructor checking old posts...' + op.id);
if(op.id == post.id)
newPost = false;
}
}
System.debug('New post? ' + newPost);
createdDate = post.createdDate.format('d MMM yy HH:mm:ss Z');
if(post.FeedPost.Body.length() > 1)
if(post.FeedPost.Body.substring(0,1) == '@')
{
try {
String[] s = post.FeedPost.Body.split(': ',2);
userHandle = s[0];
postBody = s[1];
if(userHandle == '@System')
systemMessage = true;
}
catch (Exception e)
{
System.debug('ChatPostWrapperConstructor:' + e);
userHandle = 'Anonymous';
postBody = post.FeedPost.Body;
}
}
else
{
postBody = post.FeedPost.Body;
userHandle = 'Anonymous';
}
System.debug('ChatPostWrapper comment size:' + post.FeedComments.size());
comments = post.FeedComments;
}
public Boolean getHasComments()
{
if(comments.size() > 0)
return true;
else
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment