Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
e343c0c9
Commit
e343c0c9
authored
Jul 02, 2017
by
lain
Browse files
Add way to update most recent notification id.
parent
5d8352a4
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/user.ex
View file @
e343c0c9
...
...
@@ -46,6 +46,12 @@ def follow_changeset(struct, params \\ %{}) do
|>
validate_required
([
:following
])
end
def
info_changeset
(
struct
,
params
\\
%{})
do
struct
|>
cast
(
params
,
[
:info
])
|>
validate_required
([
:info
])
end
def
user_info
(%
User
{}
=
user
)
do
note_count_query
=
from
a
in
Object
,
where:
fragment
(
"? @> ?"
,
a
.
data
,
^
%{
actor:
user
.
ap_id
,
type:
"Note"
}),
...
...
lib/pleroma/web/router.ex
View file @
e343c0c9
...
...
@@ -49,6 +49,8 @@ def user_fetcher(username) do
get
"/account/verify_credentials"
,
TwitterAPI
.
Controller
,
:verify_credentials
post
"/account/verify_credentials"
,
TwitterAPI
.
Controller
,
:verify_credentials
post
"/account/most_recent_notification"
,
TwitterAPI
.
Controller
,
:update_most_recent_notification
get
"/statuses/home_timeline"
,
TwitterAPI
.
Controller
,
:friends_timeline
get
"/statuses/friends_timeline"
,
TwitterAPI
.
Controller
,
:friends_timeline
get
"/statuses/mentions"
,
TwitterAPI
.
Controller
,
:mentions_timeline
...
...
lib/pleroma/web/twitter_api/twitter_api_controller.ex
View file @
e343c0c9
...
...
@@ -2,7 +2,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
use
Pleroma
.
Web
,
:controller
alias
Pleroma
.
Web
.
TwitterAPI
.
{
TwitterAPI
,
UserView
}
alias
Pleroma
.
Web
.
TwitterAPI
.
Representers
.
ActivityRepresenter
alias
Pleroma
.
{
Repo
,
Activity
}
alias
Pleroma
.
{
Repo
,
Activity
,
User
}
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
alias
Ecto
.
Changeset
...
...
@@ -196,6 +196,20 @@ def external_profile(%{assigns: %{user: current_user}} = conn, %{"profileurl" =>
end
end
def
update_most_recent_notification
(%{
assigns:
%{
user:
user
}}
=
conn
,
%{
"id"
=>
id
})
do
with
id
when
is_number
(
id
)
<-
String
.
to_integer
(
id
),
info
<-
user
.
info
,
mrn
<-
max
(
id
,
user
.
info
[
"most_recent_notification"
]
||
0
),
updated_info
<-
Map
.
put
(
info
,
"most_recent_notification"
,
mrn
),
changeset
<-
User
.
info_changeset
(
user
,
%{
info:
updated_info
}),
{
:ok
,
user
}
<-
Repo
.
update
(
changeset
)
do
conn
|>
json_reply
(
200
,
Poison
.
encode!
(
mrn
))
else
_e
->
bad_request_reply
(
conn
,
"Can't update."
)
end
end
defp
bad_request_reply
(
conn
,
error_message
)
do
json
=
error_json
(
conn
,
error_message
)
json_reply
(
conn
,
400
,
json
)
...
...
test/web/twitter_api/twitter_api_controller_test.exs
View file @
e343c0c9
...
...
@@ -24,6 +24,24 @@ test "with credentials", %{conn: conn, user: user} do
end
end
describe
"POST /api/account/most_recent_notification"
do
setup
[
:valid_user
]
test
"without valid credentials"
,
%{
conn:
conn
}
do
conn
=
post
conn
,
"/api/account/most_recent_notification.json"
assert
json_response
(
conn
,
403
)
==
%{
"error"
=>
"Invalid credentials."
}
end
test
"with credentials"
,
%{
conn:
conn
,
user:
user
}
do
conn
=
conn
|>
with_credentials
(
user
.
nickname
,
"test"
)
|>
post
(
"/api/account/most_recent_notification.json"
,
%{
id:
"200"
})
assert
json_response
(
conn
,
200
)
user
=
User
.
get_by_nickname
(
user
.
nickname
)
assert
user
.
info
[
"most_recent_notification"
]
==
200
end
end
describe
"POST /statuses/update.json"
do
setup
[
:valid_user
]
test
"without valid credentials"
,
%{
conn:
conn
}
do
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment