-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f56731
commit 908bf77
Showing
30 changed files
with
786 additions
and
10 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
14 changes: 14 additions & 0 deletions
14
src/main/java/ca/levimiller/smsbridge/data/db/MediaRepository.java
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,14 @@ | ||
package ca.levimiller.smsbridge.data.db; | ||
|
||
import ca.levimiller.smsbridge.data.model.Media; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.querydsl.QuerydslPredicateExecutor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface MediaRepository extends JpaRepository<Media, Long>, | ||
QuerydslPredicateExecutor<Media> { | ||
Optional<Media> findDistinctByUid(UUID uuid); | ||
} |
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
45 changes: 45 additions & 0 deletions
45
src/main/java/ca/levimiller/smsbridge/data/transformer/matrix/MatrixMediaTransformer.java
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,45 @@ | ||
package ca.levimiller.smsbridge.data.transformer.matrix; | ||
|
||
import ca.levimiller.smsbridge.data.model.Media; | ||
import io.github.ma1uta.matrix.event.content.RoomMessageContent; | ||
import io.github.ma1uta.matrix.event.message.Audio; | ||
import io.github.ma1uta.matrix.event.message.File; | ||
import io.github.ma1uta.matrix.event.message.Image; | ||
import io.github.ma1uta.matrix.event.message.Video; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class MatrixMediaTransformer { | ||
|
||
List<Media> transform(RoomMessageContent content) { | ||
String url = null; | ||
String contentType = null; | ||
|
||
// Mapstruct doesn't support polymorphism :( | ||
if (content instanceof Audio) { | ||
Audio audio = (Audio) content; | ||
url = audio.getUrl(); | ||
contentType = audio.getInfo().getMimetype(); | ||
} else if (content instanceof File) { | ||
File file = (File) content; | ||
url = file.getUrl(); | ||
contentType = file.getInfo().getMimetype(); | ||
} else if (content instanceof Image) { | ||
Image image = (Image) content; | ||
url = image.getUrl(); | ||
contentType = image.getInfo().getMimetype(); | ||
} else if (content instanceof Video) { | ||
Video video = (Video) content; | ||
url = video.getUrl(); | ||
contentType = video.getInfo().getMimetype(); | ||
} | ||
|
||
return url == null ? Collections.emptyList() | ||
: Collections.singletonList(Media.builder() | ||
.url(url) | ||
.contentType(contentType) | ||
.build()); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/ca/levimiller/smsbridge/service/FileService.java
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,17 @@ | ||
package ca.levimiller.smsbridge.service; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URISyntaxException; | ||
|
||
public interface FileService { | ||
|
||
/** | ||
* Gets the file at the given url. | ||
* @param url - file to fetch | ||
* @return - file stream | ||
* @throws URISyntaxException - if url is invalid | ||
* @throws IOException - if an io exception occurs | ||
*/ | ||
InputStream getFileStream(String url) throws URISyntaxException, IOException; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/ca/levimiller/smsbridge/service/MatrixAttachmentService.java
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 @@ | ||
package ca.levimiller.smsbridge.service; | ||
|
||
import ca.levimiller.smsbridge.data.model.ChatUser; | ||
import ca.levimiller.smsbridge.data.model.Media; | ||
|
||
public interface MatrixAttachmentService { | ||
|
||
/** | ||
* Sends the given attachment to matrix. | ||
* @param fromUser - user sending the attachment | ||
* @param attachment - attachment to send | ||
*/ | ||
void sendAttachment(ChatUser fromUser, String roomId, Media attachment); | ||
|
||
/** | ||
* Returns true if the given content type is supported by the attachment service. | ||
* @param contentType - content type to check | ||
* @return - true if supported | ||
*/ | ||
boolean supportsType(String contentType); | ||
} |
1 change: 0 additions & 1 deletion
1
src/main/java/ca/levimiller/smsbridge/service/MatrixEventService.java
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
12 changes: 12 additions & 0 deletions
12
src/main/java/ca/levimiller/smsbridge/service/OutgoingAttachmentService.java
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,12 @@ | ||
package ca.levimiller.smsbridge.service; | ||
|
||
import ca.levimiller.smsbridge.data.model.Media; | ||
|
||
public interface OutgoingAttachmentService { | ||
|
||
/** | ||
* Sends the given attachment to matrix. | ||
* @param attachment - attachment to send | ||
*/ | ||
void sendAttachment(Media attachment); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/ca/levimiller/smsbridge/service/impl/FileServiceImpl.java
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,32 @@ | ||
package ca.levimiller.smsbridge.service.impl; | ||
|
||
import ca.levimiller.smsbridge.service.FileService; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.impl.client.LaxRedirectStrategy; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Primary | ||
@Qualifier("simpleFileService") | ||
public class FileServiceImpl implements FileService { | ||
|
||
@Override | ||
public InputStream getFileStream(String url) throws URISyntaxException, IOException { | ||
// Download file | ||
CloseableHttpClient httpclient = HttpClients.custom() | ||
.setRedirectStrategy(new LaxRedirectStrategy()) | ||
.build(); | ||
HttpGet get = new HttpGet(new URL(url).toURI()); | ||
HttpResponse response = httpclient.execute(get); | ||
return response.getEntity().getContent(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/ca/levimiller/smsbridge/service/impl/HostedUrlService.java
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,16 @@ | ||
package ca.levimiller.smsbridge.service.impl; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | ||
|
||
@Service | ||
public class HostedUrlService { | ||
|
||
/** | ||
* Gets the hosted url from the current context path. | ||
* @return - base url of app. | ||
*/ | ||
public String getBaseUrl() { | ||
return ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString(); | ||
} | ||
} |
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
Oops, something went wrong.