Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview posts in stream #4099

Merged
merged 1 commit into from
Apr 7, 2013
Merged

Conversation

svbergerem
Copy link
Member

#2108

This will add a preview button to the publisher. When you press the button the current post will be presented in the stream. When you share the post the preview will disappear.

Just like the share button the preview button is disabled if there is nothing to post.

Currently not working:

@DeadSuperHero
Copy link
Member

Wow, awesome! Users would totally love this!

On Thursday, April 4, 2013, svbergerem wrote:

#2108 #2108

This will add a preview button to the publisher. When you press the button
the current post will be presented in the stream. When you share the post
the preview will disappear.

Currently not working:

  • present photos that are uploaded in the publisher
  • oEmbed
  • mentions

You can merge this Pull Request by running

git pull https://github.com/svbergerem/diaspora feature/post-preview

Or view, comment on, or merge it at:

#4099
Commit Summary

  • preview posts in stream

File Changes

Patch Links:

@jhass
Copy link
Member

jhass commented Apr 4, 2013

Great work!

Code wise I think you're on the right path, did you think about creating a new app.models.Post and calling save on that when pressing "Share" though? I think this way we could dry up some parts here.

UI wise I think that's okay for a first iteration, but maybe our UI gurus have some ideas already. I'm attaching a screenie for convenience ;)
Selection_039

@svbergerem
Copy link
Member Author

@MrZyx Yes, I already tried to create a new app.models.Post but I wasn't able to find out how to set the attributes without saving the post. Would you be so kind and tell me how to do that? ;)

I am also looking forward to see some suggestions from the "UI gurus" :)

@jhass
Copy link
Member

jhass commented Apr 4, 2013

Mmmh, new app.models.Post(attrHash) iirc, but @Raven24 surely knows better than me :P

@svbergerem
Copy link
Member Author

Ok, then just tell me what attrHash should be. I already tried

var statusMessage=new app.models.Post({
      "status_message" : {
        "text" : serializedForm["status_message[text]"]
      },
      "aspect_ids" : serializedForm["aspect_ids[]"],
      "photos" : serializedForm["photos[]"],
      "services" : serializedForm["services[]"]
    });

and to add the object to the stream I did app.stream.items.add(statusMessage.toJSON());
But that didn't work.

@jhass
Copy link
Member

jhass commented Apr 5, 2013

Hm, indeed, looks like we're just abusing the bacbkone model to construct the AJAX call, the data structure is completely different between submit and receive, wasn't aware of that. Since this won't change without larger refactors on the Rails side too, your approach looks good as a intermediary solution :)

You could pass the object you're currently building in previewMessage into app.models.Post and save the .toJSON() when adding it to the collection but it doesn't look like we would win anything by that, for the moment.

@svbergerem
Copy link
Member Author

I added a preview for photos and wrote a cucumber feature. I don't think that adding mentions and oEmbed will work without blowing up the code and I also don't think that they are that important for a preview. IMO we should add them after the possible refactors @MrZyx mentioned.

@Flaburgan
Copy link
Member

If we do a preview, I think it's important that the preview looks exactly like the real post.

@svbergerem
Copy link
Member Author

@Flaburgan Ok, I added mentions in the preview. At the moment the link to the userpage is broken because I need the guid for that but just got the name and the diaspora-handle.

After sharing a post oEmbed doesn't work in the stream either. You have to reload the stream to see the content. If that has to be in the preview it also has to be in the stream after sharing the post. (and I don't know how to do that)

Edit: Fixed the link to the userpage.

var regexp = new RegExp("@{\(\.\*\) ; \(\.\*\)}", "g");
while(user=regexp.exec(serializedForm["status_message[text]"])){
// user[1]: name, user[2]: handle
var mentioned_user = Mentions.contacts.filter(function(item) { return item.handle.toLowerCase().indexOf(user[2].toLowerCase()) > -1 })[0];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that in /app/assets/javascripts/mentions.js. Is there another (shorter) way to get the JSON of the user?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the easiest way would probably be to write a helper function and use that in both places. (and to write a jasmine test for that new helper function)
;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly should the helper function do? I copied the line from mentions.js but then I changed a few things because here I want to get the JSON of a single user with his handle, in mentions.js we need an array of users with a name including a given string.

Edit: I just changed the line because we look for a contact with the same handle, so I now use item.handle == user[2]

@Raven24
Copy link
Member

Raven24 commented Apr 5, 2013

About the backbone.js model ... I'd have to take a closer look, but I guess the way it is handled now is just as good as any other, Unfortunately the backbone models are not entirely the same when an object is created client side vs. the server side... that's probably an artifact from the old pre-backbone UI code.

If we ever get to do a proper API, we should start with a separate backbone-UI JSON API...

@jaywink
Copy link
Contributor

jaywink commented Apr 5, 2013

Wow, awesome! This has to be the single most wanted feature :)


.post_preview
:border
:bottom 3px solid #3f8fba !important
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe also let it have a very light blue or gray background color, so that it really looks different from the rest of the posts in the stream.

@jaywink
Copy link
Contributor

jaywink commented Apr 5, 2013

Just pulled on my pod and works great - such an awesome feature, people are going to love it! Also the light blue background is a good addition to distinguish it from the stream.

Nice one!

@svbergerem
Copy link
Member Author

Another screenshot with the light blue background:
preview_posts

@movilla
Copy link
Contributor

movilla commented Apr 5, 2013

Great!

@svbergerem
Copy link
Member Author

Is there anything that needs to be done before this pull request is ready to merge?

@jhass
Copy link
Member

jhass commented Apr 6, 2013

Less of a bug, more a behaviour decision: Currently the preview button does nothing when just uploading some photos without entering any text.

I'd also remove the comments inside the JSON constructions and I'm not sure why you changed the URL for the exisiting changelog entry, especially since the new one just redirects to the old :)

@jhass
Copy link
Member

jhass commented Apr 6, 2013

Oh and maybe we should find a way to disable/remove the comment/like buttons in the preview. If there's no easy one I'd be fine pulling this in as it is as a first iteration though.

@svbergerem
Copy link
Member Author

Allright the classes of the comment/like buttons are now changed in the preview so they don't do anything. I removed the comments in the JSON and changed back the URL in the changelog.

The behaviour you described is weird. On textchange checkSubmitAvailability gets called and toggles both buttons (preview and submit). I don't see any line that does that for the photodropzone, so also the submit button shouldn't be enabled. Does anyone know where this is done? Then I could just add a line that does the same thing for the preview button.

Edit: I just found out that uploading a photo and then deleting it gives you the opportunity to share an empty post. So the share button just gets enabled on changes in the photodropzone but not disabled again.

@Flaburgan
Copy link
Member

Did you try to add embed support? Just look at oEmbed i don't think this is hard to do.

@jhass
Copy link
Member

jhass commented Apr 6, 2013

@Flaburgan it is and out of scope of this PR.

@svbergerem I fear it's legacy hackery :/ https://github.com/diaspora/diaspora/blob/develop/app/views/photos/_new_photo.haml#L32

@svbergerem
Copy link
Member Author

@Flaburgan No, I did not add oEmbed support. There is an issue because of missing oEmbed support when sharing a post and I thing this should be done in a seperate PR for both.

@Flaburgan
Copy link
Member

Okay, we can merge that and deal with oembed after, but I think we should improve that.

@svbergerem
Copy link
Member Author

@MrZyx Ok, I added the same legacy hackery for the preview button, so both buttons should be treated the same way now.

// (e.g. bookmarklet, mentions popup)
if( this.options.standalone ) {
this.$('#hide_publisher').hide();
this.$('.post_preview_button').hide();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can now use this.el_preview.hide() here...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, changed the line.

@Raven24
Copy link
Member

Raven24 commented Apr 7, 2013

Ok, one last little comment from me, and then this is good to go IMHO.

In a subsequent iteration, the way we extract the form data from the publisher for posting and preview should really be unified to get more DRY.
oEmbed previews are a different topic...

Also, anybody who wants to Backbone-ify the image uploading code is very welcome to do so (I will gladly assist anyone who is brave enough to attempt this) ;)

@svbergerem
Copy link
Member Author

@Raven24 What exactly do you have in mind? I have the var serializedForm just like in createStatusMessage() and then create an object, which is AFAIK done server-side when posting. I have to do this client-side, thats why I create the object manually. The only thing that I extract in a different way are photos because for posting the server just needs the ids and creates a photo array out of those but I need the paths of the photos. I don't know if we could handle that in a different way without changing the photo uploader.

@rivendale2010
Copy link
Contributor

most of the format problems are in the user defined markdown, the object embed is either valid or not

this be very handy! :)

@Raven24
Copy link
Member

Raven24 commented Apr 7, 2013

@svbergerem I meant that should happen at a later refactoring. I haven't really thought about anything specific ;)

@svbergerem
Copy link
Member Author

@Raven24 Ok, now I understand what you are talking about :)

By the way the Travis build fails but IMO that has nothing to do with this PR.

Raven24 added a commit that referenced this pull request Apr 7, 2013
@Raven24 Raven24 merged commit 06d67bf into diaspora:develop Apr 7, 2013
@Raven24
Copy link
Member

Raven24 commented Apr 7, 2013

merged.
thank you very much! keep up the good work ;)

@svbergerem
Copy link
Member Author

Thanks to all who were involved in this. You help new developers a lot!

@Flaburgan
Copy link
Member

Thank you very much for your work, this was a really waited feature!

@rivendale2010
Copy link
Contributor

testing this on my pod, it is beyond wonderful! many thanks. :)

one small problem i note is: if you are in a tag stream (from searching on a tag), it does not pick up on the content and just previews "The think about tag is...."

but if find no other problem i any other places :)

@svbergerem
Copy link
Member Author

I think that has nothing to do with the preview. The publisher on the tag stream is a known problem #4017, so if you share your post instead of previewing it the text should be the same (The thing about #tag is...). If it does not just tell me. :)

@rivendale2010
Copy link
Contributor

that is very possible. i did not post it. :) i'll report back here if that does not happen :)

thanks again for the great feature. :)

@svbergerem svbergerem deleted the feature/post-preview branch May 8, 2013 19:27
@goobertron
Copy link

Just wanted to say huge thanks to @svbergerem and everyone else who helped for this great feature - it answers the request from thousands of people to have previews.

I've just noticed a possible bug with it: I went to a tag page (#cricket) to test out the fix to the bug in posting from tag pages ('The thing about #tagname is...') and when I pressed the Preview button, instead of the post preview having a blue background, the name of the first tag follower in the list on the left went blue.

It's only a very minor thing, and didn't stop the preview from working at all, but you might want to look into it.

Thanks.

@jhass
Copy link
Member

jhass commented May 20, 2013

@goobertron sure, would you mind opening a separate report about this?

@goobertron
Copy link

Yes, of course. Sorry, I didn't know the form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants