Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
pleroma
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
391
Issues
391
List
Boards
Labels
Service Desk
Milestones
Merge Requests
54
Merge Requests
54
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pleroma
pleroma
Commits
d1cf1108
Commit
d1cf1108
authored
Jul 30, 2020
by
Haelwenn
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'render-preview-cards-in-chats' into 'develop'
Render preview cards in chats See merge request
!2816
parents
87fe31fb
a3c37379
Pipeline
#29246
passed with stages
in 66 minutes and 27 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
8 deletions
+66
-8
lib/pleroma/web/api_spec/schemas/chat_message.ex
lib/pleroma/web/api_spec/schemas/chat_message.ex
+34
-1
lib/pleroma/web/pleroma_api/views/chat/message_reference_view.ex
...roma/web/pleroma_api/views/chat/message_reference_view.ex
+7
-2
lib/pleroma/web/rich_media/helpers.ex
lib/pleroma/web/rich_media/helpers.ex
+12
-3
test/web/pleroma_api/views/chat/message_reference_view_test.exs
...eb/pleroma_api/views/chat/message_reference_view_test.exs
+13
-2
No files found.
lib/pleroma/web/api_spec/schemas/chat_message.ex
View file @
d1cf1108
...
...
@@ -19,13 +19,46 @@ defmodule Pleroma.Web.ApiSpec.Schemas.ChatMessage do
content:
%
Schema
{
type:
:string
,
nullable:
true
},
created_at:
%
Schema
{
type:
:string
,
format:
:"date-time"
},
emojis:
%
Schema
{
type:
:array
},
attachment:
%
Schema
{
type:
:object
,
nullable:
true
}
attachment:
%
Schema
{
type:
:object
,
nullable:
true
},
card:
%
Schema
{
type:
:object
,
nullable:
true
,
description:
"Preview card for links included within status content"
,
required:
[
:url
,
:title
,
:description
,
:type
],
properties:
%{
type:
%
Schema
{
type:
:string
,
enum:
[
"link"
,
"photo"
,
"video"
,
"rich"
],
description:
"The type of the preview card"
},
provider_name:
%
Schema
{
type:
:string
,
nullable:
true
,
description:
"The provider of the original resource"
},
provider_url:
%
Schema
{
type:
:string
,
format:
:uri
,
description:
"A link to the provider of the original resource"
},
url:
%
Schema
{
type:
:string
,
format:
:uri
,
description:
"Location of linked resource"
},
image:
%
Schema
{
type:
:string
,
nullable:
true
,
format:
:uri
,
description:
"Preview thumbnail"
},
title:
%
Schema
{
type:
:string
,
description:
"Title of linked resource"
},
description:
%
Schema
{
type:
:string
,
description:
"Description of preview"
}
}
}
},
example:
%{
"account_id"
=>
"someflakeid"
,
"chat_id"
=>
"1"
,
"content"
=>
"hey you again"
,
"created_at"
=>
"2020-04-21T15:06:45.000Z"
,
"card"
=>
nil
,
"emojis"
=>
[
%{
"static_url"
=>
"https://dontbulling.me/emoji/Firefox.gif"
,
...
...
lib/pleroma/web/pleroma_api/views/chat/message_reference_view.ex
View file @
d1cf1108
...
...
@@ -14,7 +14,7 @@ def render(
%{
chat_message_reference:
%{
id:
id
,
object:
%{
data:
chat_message
},
object:
%{
data:
chat_message
}
=
object
,
chat_id:
chat_id
,
unread:
unread
}
...
...
@@ -30,7 +30,12 @@ def render(
attachment:
chat_message
[
"attachment"
]
&&
StatusView
.
render
(
"attachment.json"
,
attachment:
chat_message
[
"attachment"
]),
unread:
unread
unread:
unread
,
card:
StatusView
.
render
(
"card.json"
,
Pleroma
.
Web
.
RichMedia
.
Helpers
.
fetch_data_for_object
(
object
)
)
}
end
...
...
lib/pleroma/web/rich_media/helpers.ex
View file @
d1cf1108
...
...
@@ -49,11 +49,11 @@ defp get_tld(host) do
|>
hd
end
def
fetch_data_for_
activity
(%
Activity
{
data:
%{
"type"
=>
"Create"
}}
=
activity
)
do
def
fetch_data_for_
object
(
object
)
do
with
true
<-
Config
.
get
([
:rich_media
,
:enabled
]),
%
Object
{}
=
object
<-
Object
.
normalize
(
activity
),
false
<-
object
.
data
[
"sensitive"
]
||
false
,
{
:ok
,
page_url
}
<-
HTML
.
extract_first_external_url
(
object
,
object
.
data
[
"content"
]),
{
:ok
,
page_url
}
<-
HTML
.
extract_first_external_url
(
object
,
object
.
data
[
"content"
]),
:ok
<-
validate_page_url
(
page_url
),
{
:ok
,
rich_media
}
<-
Parser
.
parse
(
page_url
)
do
%{
page_url:
page_url
,
rich_media:
rich_media
}
...
...
@@ -62,6 +62,15 @@ def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) d
end
end
def
fetch_data_for_activity
(%
Activity
{
data:
%{
"type"
=>
"Create"
}}
=
activity
)
do
with
true
<-
Config
.
get
([
:rich_media
,
:enabled
]),
%
Object
{}
=
object
<-
Object
.
normalize
(
activity
)
do
fetch_data_for_object
(
object
)
else
_
->
%{}
end
end
def
fetch_data_for_activity
(
_
),
do
:
%{}
def
perform
(
:fetch
,
%
Activity
{}
=
activity
)
do
...
...
test/web/pleroma_api/views/chat/message_reference_view_test.exs
View file @
d1cf1108
...
...
@@ -43,7 +43,17 @@ test "it displays a chat message" do
assert
chat_message
[
:unread
]
==
false
assert
match?
([%{
shortcode:
"firefox"
}],
chat_message
[
:emojis
])
{
:ok
,
activity
}
=
CommonAPI
.
post_chat_message
(
recipient
,
user
,
"gkgkgk"
,
media_id:
upload
.
id
)
clear_config
([
:rich_media
,
:enabled
],
true
)
Tesla
.
Mock
.
mock
(
fn
%{
url:
"https://example.com/ogp"
}
->
%
Tesla
.
Env
{
status:
200
,
body:
File
.
read!
(
"test/fixtures/rich_media/ogp.html"
)}
end
)
{
:ok
,
activity
}
=
CommonAPI
.
post_chat_message
(
recipient
,
user
,
"gkgkgk https://example.com/ogp"
,
media_id:
upload
.
id
)
object
=
Object
.
normalize
(
activity
)
...
...
@@ -52,10 +62,11 @@ test "it displays a chat message" do
chat_message_two
=
MessageReferenceView
.
render
(
"show.json"
,
chat_message_reference:
cm_ref
)
assert
chat_message_two
[
:id
]
==
cm_ref
.
id
assert
chat_message_two
[
:content
]
==
"gkgkgk"
assert
chat_message_two
[
:content
]
==
object
.
data
[
"content"
]
assert
chat_message_two
[
:account_id
]
==
recipient
.
id
assert
chat_message_two
[
:chat_id
]
==
chat_message
[
:chat_id
]
assert
chat_message_two
[
:attachment
]
assert
chat_message_two
[
:unread
]
==
true
assert
chat_message_two
[
:card
]
end
end
Write
Preview
Markdown
is supported
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