]> cat aescling's git repositories - mastodon.git/commitdiff
Merge branch 'main' into glitch-soc/merge-upstream
authorClaire <claire.github-309c@sitedethib.com>
Sun, 26 Sep 2021 16:28:59 +0000 (18:28 +0200)
committerClaire <claire.github-309c@sitedethib.com>
Sun, 26 Sep 2021 16:28:59 +0000 (18:28 +0200)
Conflicts:
- `streaming/index.js`:
  Filtering code for streaming notifications has been refactored upstream, but
  glitch-soc had similar code for local-only toots in the same places.
  Ported upstream changes, but did not refactor local-only filtering.

1  2 
app/controllers/home_controller.rb
app/javascript/mastodon/actions/compose.js
streaming/index.js

index c9b84088171788f2e8529ad29c07844ae8dcd9b7,7e443eb9e74e214277d1592ecf533feb0908db23..450f92bd4049deea2b18fbf54e5cfbaa6e379e80
@@@ -16,36 -14,9 +16,13 @@@ class HomeController < ApplicationContr
    def redirect_unauthenticated_to_permalinks!
      return if user_signed_in?
  
-     matches = request.path.match(/\A\/web\/(statuses|accounts)\/([\d]+)\z/)
-     if matches
-       case matches[1]
-       when 'statuses'
-         status = Status.find_by(id: matches[2])
-         if status&.distributable?
-           redirect_to(ActivityPub::TagManager.instance.url_for(status))
-           return
-         end
-       when 'accounts'
-         account = Account.find_by(id: matches[2])
-         if account
-           redirect_to(ActivityPub::TagManager.instance.url_for(account))
-           return
-         end
-       end
-     end
-     matches = request.path.match(%r{\A/web/timelines/tag/(?<tag>.+)\z})
-     redirect_to(matches ? tag_path(CGI.unescape(matches[:tag])) : default_redirect_path)
+     redirect_to(PermalinkRedirector.new(request.path).redirect_path || default_redirect_path)
    end
  
 +  def set_pack
 +    use_pack 'home'
 +  end
 +
    def default_redirect_path
      if request.path.start_with?('/web') || whitelist_mode?
        new_user_session_path
index ac8e80fb9d0ba0aa2ba62d2109839d4ed0e88325,67cd48b43e89d408d2139dc6c857b318622f2e5c..9f8ab107e89b455cc61f35ff37279e3733359ef5
@@@ -581,15 -587,12 +588,13 @@@ const startWorker = (workerId) => 
     * @param {function(string, string): void} output
     * @param {function(string[], function(string): void): void} attachCloseHandler
     * @param {boolean=} needsFiltering
-    * @param {boolean=} notificationOnly
 +   * @param {boolean=} allowLocalOnly
     * @return {function(string): void}
     */
-   const streamFrom = (ids, req, output, attachCloseHandler, needsFiltering = false, notificationOnly = false, allowLocalOnly = false) => {
 -  const streamFrom = (ids, req, output, attachCloseHandler, needsFiltering = false) => {
++  const streamFrom = (ids, req, output, attachCloseHandler, needsFiltering = false, allowLocalOnly = false) => {
      const accountId  = req.accountId || req.remoteAddress;
-     const streamType = notificationOnly ? ' (notification)' : '';
  
-     log.verbose(req.requestId, `Starting stream from ${ids.join(', ')} for ${accountId}${streamType}`);
+     log.verbose(req.requestId, `Starting stream from ${ids.join(', ')} for ${accountId}`);
  
      const listener = message => {
        const json = parseJSON(message);
          output(event, encodedPayload);
        };
  
-       if (notificationOnly && event !== 'notification') {
-         return;
-       }
-       if (event === 'notification' && !req.allowNotifications) {
-         return;
-       }
 +      // Only send local-only statuses to logged-in users
 +      if (event === 'update' && payload.local_only && !(req.accountId && allowLocalOnly)) {
 +        log.silly(req.requestId, `Message ${payload.id} filtered because it was local-only`);
 +        return;
 +      }
 +
        // Only messages that may require filtering are statuses, since notifications
        // are already personalized and deletes do not matter
        if (!needsFiltering || event !== 'update') {
        const onSend = streamToHttp(req, res);
        const onEnd  = streamHttpEnd(req, subscriptionHeartbeat(channelIds));
  
-       streamFrom(channelIds, req, onSend, onEnd, options.needsFiltering, options.notificationOnly, options.allowLocalOnly);
 -      streamFrom(channelIds, req, onSend, onEnd, options.needsFiltering);
++      streamFrom(channelIds, req, onSend, onEnd, options.needsFiltering, options.allowLocalOnly);
      }).catch(err => {
        log.verbose(req.requestId, 'Subscription error:', err.toString());
        httpNotFound(res);
      switch(name) {
      case 'user':
        resolve({
-         channelIds: req.deviceId ? [`timeline:${req.accountId}`, `timeline:${req.accountId}:${req.deviceId}`] : [`timeline:${req.accountId}`],
-         options: { needsFiltering: false, notificationOnly: false, allowLocalOnly: true },
+         channelIds: channelsForUserStream(req),
 -        options: { needsFiltering: false },
++        options: { needsFiltering: false, allowLocalOnly: true },
        });
  
        break;
      case 'user:notification':
        resolve({
-         channelIds: [`timeline:${req.accountId}`],
-         options: { needsFiltering: false, notificationOnly: true, allowLocalOnly: true },
+         channelIds: [`timeline:${req.accountId}:notifications`],
 -        options: { needsFiltering: false },
++        options: { needsFiltering: false, allowLocalOnly: true },
        });
  
        break;
      case 'public':
        resolve({
          channelIds: ['timeline:public'],
-         options: { needsFiltering: true, notificationOnly: false, allowLocalOnly: isTruthy(params.allow_local_only) },
 -        options: { needsFiltering: true },
++        options: { needsFiltering: true, allowLocalOnly: isTruthy(params.allow_local_only) },
 +      });
 +
 +      break;
 +    case 'public:allow_local_only':
 +      resolve({
 +        channelIds: ['timeline:public'],
-         options: { needsFiltering: true, notificationOnly: false, allowLocalOnly: true },
++        options: { needsFiltering: true, allowLocalOnly: true },
        });
  
        break;
      case 'public:local':
        resolve({
          channelIds: ['timeline:public:local'],
-         options: { needsFiltering: true, notificationOnly: false, allowLocalOnly: true },
 -        options: { needsFiltering: true },
++        options: { needsFiltering: true, allowLocalOnly: true },
        });
  
        break;
      case 'public:remote':
        resolve({
          channelIds: ['timeline:public:remote'],
-         options: { needsFiltering: true, notificationOnly: false, allowLocalOnly: false },
 -        options: { needsFiltering: true },
++        options: { needsFiltering: true, allowLocalOnly: false },
        });
  
        break;
      case 'public:media':
        resolve({
          channelIds: ['timeline:public:media'],
-         options: { needsFiltering: true, notificationOnly: false, allowLocalOnly: isTruthy(query.allow_local_only) },
 -        options: { needsFiltering: true },
++        options: { needsFiltering: true, allowLocalOnly: isTruthy(query.allow_local_only) },
 +      });
 +
 +      break;
 +    case 'public:allow_local_only:media':
 +      resolve({
 +        channelIds: ['timeline:public:media'],
-         options: { needsFiltering: true, notificationsOnly: false, allowLocalOnly: true },
++        options: { needsFiltering: true, allowLocalOnly: true },
        });
  
        break;
      case 'public:local:media':
        resolve({
          channelIds: ['timeline:public:local:media'],
-         options: { needsFiltering: true, notificationOnly: false, allowLocalOnly: true },
 -        options: { needsFiltering: true },
++        options: { needsFiltering: true, allowLocalOnly: true },
        });
  
        break;
      case 'public:remote:media':
        resolve({
          channelIds: ['timeline:public:remote:media'],
-         options: { needsFiltering: true, notificationOnly: false, allowLocalOnly: false },
 -        options: { needsFiltering: true },
++        options: { needsFiltering: true, allowLocalOnly: false },
        });
  
        break;
      case 'direct':
        resolve({
          channelIds: [`timeline:direct:${req.accountId}`],
-         options: { needsFiltering: false, notificationOnly: false, allowLocalOnly: true },
 -        options: { needsFiltering: false },
++        options: { needsFiltering: false, allowLocalOnly: true },
        });
  
        break;
        } else {
          resolve({
            channelIds: [`timeline:hashtag:${params.tag.toLowerCase()}`],
-           options: { needsFiltering: true, notificationOnly: false, allowLocalOnly: true },
 -          options: { needsFiltering: true },
++          options: { needsFiltering: true, allowLocalOnly: true },
          });
        }
  
        } else {
          resolve({
            channelIds: [`timeline:hashtag:${params.tag.toLowerCase()}:local`],
-           options: { needsFiltering: true, notificationOnly: false, allowLocalOnly: true },
 -          options: { needsFiltering: true },
++          options: { needsFiltering: true, allowLocalOnly: true },
          });
        }
  
        authorizeListAccess(params.list, req).then(() => {
          resolve({
            channelIds: [`timeline:list:${params.list}`],
-           options: { needsFiltering: false, notificationOnly: false, allowLocalOnly: true },
 -          options: { needsFiltering: false },
++          options: { needsFiltering: false, allowLocalOnly: true },
          });
        }).catch(() => {
          reject('Not authorized to stream this list');
  
        const onSend        = streamToWs(request, socket, streamNameFromChannelName(channelName, params));
        const stopHeartbeat = subscriptionHeartbeat(channelIds);
-       const listener      = streamFrom(channelIds, request, onSend, undefined, options.needsFiltering, options.notificationOnly, options.allowLocalOnly);
 -      const listener      = streamFrom(channelIds, request, onSend, undefined, options.needsFiltering);
++
++      const listener      = streamFrom(channelIds, request, onSend, undefined, options.needsFiltering, options.allowLocalOnly);
  
        subscriptions[channelIds.join(';')] = {
          listener,