]> cat aescling's git repositories - mastodon.git/commitdiff
[Glitch] When deleting & redrafting a poll, fill in closest expires_in
authorThibG <thib@sitedethib.com>
Mon, 1 Jul 2019 22:36:16 +0000 (00:36 +0200)
committerThibaut Girka <thib@sitedethib.com>
Thu, 4 Jul 2019 14:24:48 +0000 (16:24 +0200)
Port dc88d226e1fdb20499d6e81838b81894b2d0be2d to glitch-soc

app/javascript/flavours/glitch/reducers/compose.js

index 36dfb8f1524773c779dd1f8f0e4963df75ba8dc4..a47b8b7bda19802256e40fe617f9c53abe9586cc 100644 (file)
@@ -275,6 +275,12 @@ const expandMentions = status => {
   return fragment.innerHTML;
 };
 
+const expiresInFromExpiresAt = expires_at => {
+  if (!expires_at) return 24 * 3600;
+  const delta = (new Date(expires_at).getTime() - Date.now()) / 1000;
+  return [300, 1800, 3600, 21600, 86400, 259200, 604800].find(expires_in => expires_in >= delta) || 24 * 3600;
+};
+
 export default function compose(state = initialState, action) {
   switch(action.type) {
   case STORE_HYDRATE:
@@ -456,7 +462,7 @@ export default function compose(state = initialState, action) {
         map.set('poll', ImmutableMap({
           options: action.status.getIn(['poll', 'options']).map(x => x.get('title')),
           multiple: action.status.getIn(['poll', 'multiple']),
-          expires_in: 24 * 3600,
+          expires_in: expiresInFromExpiresAt(action.status.getIn(['poll', 'expires_at'])),
         }));
       }
     });