-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into MAM-2677-rebase
- Loading branch information
Showing
18 changed files
with
253 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V3::Timelines::StatusesController < Api::BaseController | ||
before_action :require_mammoth! | ||
|
||
rescue_from Mammoth::StatusOrigin::NotFound do |e| | ||
render json: { error: e.to_s }, status: 404 | ||
end | ||
|
||
def show | ||
origin = Mammoth::StatusOrigin.instance | ||
@origins = origin.find(status_id_param) | ||
render json: @origins, each_serializer: StatusOriginSerializer | ||
end | ||
|
||
private | ||
|
||
def status_id_param | ||
params.require(:id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# frozen_string_literal: true | ||
# rubocop:disable all | ||
require 'singleton' | ||
|
||
module Mammoth | ||
|
||
class StatusOrigin | ||
include Singleton | ||
include Redisable | ||
class NotFound < StandardError; end | ||
|
||
|
||
# Add Status and Reason to list | ||
def add_channel(status, channel) | ||
list_key = key(status[:id]) | ||
reason = channel_reason(status, channel) | ||
|
||
add_reason(list_key, reason) | ||
end | ||
|
||
def add_mammoth_pick(status) | ||
list_key = key(status[:id]) | ||
reason = mammoth_pick_reason(status) | ||
|
||
add_reason(list_key, reason) | ||
end | ||
|
||
# Add reason by key id | ||
# Expire Reason in 7 days | ||
def add_reason(key, reason) | ||
redis.sadd(key, reason) | ||
redis.expire(key, 7.day.seconds) | ||
end | ||
|
||
def find(status_id) | ||
list_key = key(status_id) | ||
results = redis.smembers(list_key).map { |o| | ||
payload = Oj.load(o, symbol_keys: true) | ||
originating_account = Account.create(payload[:originating_account]) | ||
# StatusOrigin Active Model for serialization | ||
::StatusOrigin.new(source: payload[:source], channel_id: payload[:channel_id], title: payload[:title], originating_account:originating_account ) | ||
} | ||
# Throw Error if array find is empty | ||
raise NotFound, 'status not found' unless results.length > 0 | ||
return results | ||
end | ||
|
||
private | ||
|
||
# Redis key of a status | ||
# @param [Integer] status id | ||
# @param [Symbol] subtype | ||
# @return [String] | ||
def key(id, subtype = nil) | ||
return "origin:for_you:#{id}" unless subtype | ||
"origin:for_you:#{id}:#{subtype}" | ||
end | ||
|
||
def channel_reason(status, channel) | ||
Oj.dump({source: "SmartList", channel_id: channel[:id], title: channel[:title], originating_account: status.account}) | ||
end | ||
|
||
def mammoth_pick_reason(status) | ||
Oj.dump({source: "MammothPick", originating_account: status.account }) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# ActiveModel Only for Serialization | ||
class StatusOrigin | ||
include ActiveModel::Model | ||
include ActiveModel::Serialization | ||
|
||
attr_accessor :source, :channel_id, :title, :originating_account | ||
|
||
def initialize(attributes = {}) | ||
super | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Required Source & Originating Account | ||
# Channel_id & Title maybe be null | ||
class StatusOriginSerializer < ActiveModel::Serializer | ||
attributes :source, :title, :channel_id | ||
|
||
belongs_to :originating_account, serializer: REST::AccountSerializer | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
- [mailers, 2] | ||
- [pull] | ||
- [scheduler] | ||
- [mammoth] | ||
:scheduler: | ||
:listened_queues_only: true | ||
:schedule: | ||
|
Oops, something went wrong.