├── .github ├── CODEOWNERS ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── ci.yml │ ├── initiate_release.yml │ ├── javadoc.yml │ ├── release.yml │ └── scheduled_test.yml ├── .gitignore ├── .versionrc.js ├── CHANGELOG.md ├── CONTRIBUTING.md ├── DOCS.md ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── SECURITY.md ├── assets └── logo.svg ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties.example ├── publish.gradle ├── scripts └── get_changelog_diff.js ├── settings.gradle └── src ├── main └── java │ └── io │ └── getstream │ └── chat │ └── java │ ├── exceptions │ └── StreamException.java │ ├── models │ ├── App.java │ ├── BlockUser.java │ ├── Blocklist.java │ ├── Channel.java │ ├── ChannelType.java │ ├── Command.java │ ├── DeleteStrategy.java │ ├── Device.java │ ├── Draft.java │ ├── Event.java │ ├── ExportUsers.java │ ├── FilterCondition.java │ ├── Flag.java │ ├── Import.java │ ├── Language.java │ ├── LanguageDeserializer.java │ ├── Message.java │ ├── MessageHistory.java │ ├── MessagePaginationParameters.java │ ├── Moderation.java │ ├── PaginationParameters.java │ ├── Permission.java │ ├── RateLimit.java │ ├── Reaction.java │ ├── ResourceAction.java │ ├── Role.java │ ├── Sort.java │ ├── TaskStatus.java │ ├── Thread.java │ ├── UnreadCounts.java │ ├── User.java │ └── framework │ │ ├── DefaultFileHandler.java │ │ ├── FileHandler.java │ │ ├── RequestObjectBuilder.java │ │ ├── StreamRequest.java │ │ ├── StreamResponse.java │ │ ├── StreamResponseObject.java │ │ ├── StreamResponseWithRateLimit.java │ │ └── UnixTimestampDeserializer.java │ └── services │ ├── AppService.java │ ├── BlockUserService.java │ ├── BlocklistService.java │ ├── ChannelService.java │ ├── ChannelTypeService.java │ ├── CommandService.java │ ├── DeviceService.java │ ├── DraftService.java │ ├── EventService.java │ ├── ExportUsersService.java │ ├── FlagService.java │ ├── ImportService.java │ ├── MessageHistoryService.java │ ├── MessageService.java │ ├── ModerationService.java │ ├── PermissionService.java │ ├── ReactionService.java │ ├── RoleService.java │ ├── TaskStatusService.java │ ├── ThreadService.java │ ├── UnreadCountsService.java │ ├── UserService.java │ └── framework │ ├── Client.java │ ├── DefaultClient.java │ ├── HttpLoggingInterceptor.java │ ├── QueryConverterFactory.java │ ├── StreamServiceGenerator.java │ ├── StreamServiceHandler.java │ └── ToJson.java └── test ├── java └── io │ └── getstream │ └── chat │ └── java │ ├── AppTest.java │ ├── BasicTest.java │ ├── BlockUserTest.java │ ├── BlocklistTest.java │ ├── ChannelDraftTest.java │ ├── ChannelTest.java │ ├── ChannelTypeTest.java │ ├── CommandTest.java │ ├── DeviceTest.java │ ├── EventTest.java │ ├── ExportUsersTest.java │ ├── FlagTest.java │ ├── ImportTests.java │ ├── MessageHistoryTest.java │ ├── MessageTest.java │ ├── ModerationTest.java │ ├── PermissionTest.java │ ├── ReactionTest.java │ ├── RoleTest.java │ ├── TaskStatusTest.java │ ├── ThreadTest.java │ ├── UnreadCountsTest.java │ └── UserTest.java └── resources ├── upload_file.pdf ├── upload_file.txt ├── upload_image.png └── upload_image.svg /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @ferhatelmas 2 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Submit a pull request 2 | 3 | ## CLA 4 | 5 | - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required). 6 | - [ ] The code changes follow best practices 7 | - [ ] Code changes are tested (add some information if not applicable) 8 | 9 | ## Description of the pull request 10 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [pull_request] 4 | 5 | concurrency: 6 | group: ${{ github.workflow }}-${{ github.head_ref }} 7 | cancel-in-progress: true 8 | 9 | jobs: 10 | ci: 11 | name: 🧪 Test & lint 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Check out code 15 | uses: actions/checkout@v3 16 | with: 17 | fetch-depth: 0 18 | 19 | - name: Test 20 | env: 21 | STREAM_KEY: ${{ secrets.STREAM_KEY }} 22 | STREAM_SECRET: ${{ secrets.STREAM_SECRET }} 23 | run: | 24 | ./gradlew spotlessCheck --no-daemon 25 | ./gradlew javadoc --no-daemon 26 | ./gradlew jacocoTestReport --no-daemon 27 | -------------------------------------------------------------------------------- /.github/workflows/initiate_release.yml: -------------------------------------------------------------------------------- 1 | name: Create release PR 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | version: 7 | description: "The new version number. Example: 1.40.1" 8 | required: true 9 | 10 | jobs: 11 | init_release: 12 | name: 🚀 Create release PR 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v3 16 | with: 17 | fetch-depth: 0 # gives the changelog generator access to all previous commits 18 | 19 | - name: Update CHANGELOG.md, build.gradle and push release branch 20 | env: 21 | VERSION: ${{ github.event.inputs.version }} 22 | run: | 23 | npx --yes standard-version@9.3.2 --release-as "$VERSION" --skip.tag --skip.commit --tag-prefix= 24 | git config --global user.name 'github-actions' 25 | git config --global user.email 'release@getstream.io' 26 | git checkout -q -b "release-$VERSION" 27 | git commit -am "chore(release): $VERSION" 28 | git push -q -u origin "release-$VERSION" 29 | 30 | - name: Get changelog diff 31 | uses: actions/github-script@v6 32 | with: 33 | script: | 34 | const get_change_log_diff = require('./scripts/get_changelog_diff.js') 35 | core.exportVariable('CHANGELOG', get_change_log_diff()) 36 | 37 | - name: Open pull request 38 | env: 39 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 40 | run: | 41 | gh pr create \ 42 | -t "Release ${{ github.event.inputs.version }}" \ 43 | -b "# :rocket: ${{ github.event.inputs.version }} 44 | Make sure to use squash & merge when merging! 45 | Once this is merged, another job will kick off automatically and publish the package. 46 | # :memo: Changelog 47 | ${{ env.CHANGELOG }}" 48 | -------------------------------------------------------------------------------- /.github/workflows/javadoc.yml: -------------------------------------------------------------------------------- 1 | name: javadoc 2 | on: 3 | push: 4 | branches: 5 | - main 6 | jobs: 7 | javadoc: 8 | runs-on: ubuntu-latest 9 | concurrency: docs-${{ github.ref }} 10 | name: 📚 Docs 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v3 14 | with: 15 | persist-credentials: false 16 | 17 | - name: Set up Node.js 14 18 | uses: actions/setup-node@v3 19 | with: 20 | node-version: 14 21 | 22 | - name: Generate doc 23 | run: ./gradlew --no-daemon javadoc 24 | 25 | - name: Deploy 26 | uses: JamesIves/github-pages-deploy-action@v4 27 | with: 28 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 29 | BRANCH: gh-pages 30 | FOLDER: build/docs/javadoc/ 31 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | pull_request: 5 | types: [closed] 6 | branches: 7 | - main 8 | 9 | jobs: 10 | Release: 11 | name: 🚀 Release 12 | if: github.event.pull_request.merged && startsWith(github.head_ref, 'release-') 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v3 16 | with: 17 | fetch-depth: 0 18 | 19 | - uses: actions/github-script@v6 20 | with: 21 | script: | 22 | const get_change_log_diff = require('./scripts/get_changelog_diff.js') 23 | core.exportVariable('CHANGELOG', get_change_log_diff()) 24 | 25 | // Getting the release version from the PR source branch 26 | // Source branch looks like this: release-1.0.0 27 | const version = context.payload.pull_request.head.ref.split('-')[1] 28 | core.exportVariable('VERSION', version) 29 | 30 | - name: Publish to MavenCentral 31 | run: | 32 | sudo bash -c "echo '$GPG_KEY_CONTENTS' | base64 -d > '$SIGNING_SECRET_KEY_RING_FILE'" 33 | ./gradlew publishToSonatype --no-daemon --max-workers 1 closeAndReleaseSonatypeStagingRepository 34 | env: 35 | STREAM_KEY: ${{ secrets.STREAM_KEY }} 36 | STREAM_SECRET: ${{ secrets.STREAM_SECRET }} 37 | GPG_KEY_CONTENTS: ${{ secrets.GPG_KEY_CONTENTS }} 38 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} 39 | OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} 40 | SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} 41 | SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} 42 | SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }} 43 | SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} 44 | 45 | - name: Create release on GitHub 46 | uses: ncipollo/release-action@v1 47 | with: 48 | body: ${{ env.CHANGELOG }} 49 | tag: ${{ env.VERSION }} 50 | token: ${{ secrets.GITHUB_TOKEN }} 51 | -------------------------------------------------------------------------------- /.github/workflows/scheduled_test.yml: -------------------------------------------------------------------------------- 1 | name: Scheduled tests 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | # Monday at 9:00 UTC 7 | - cron: "0 9 * * 1" 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | 15 | - name: Run tests 16 | env: 17 | STREAM_KEY: ${{ secrets.STREAM_KEY }} 18 | STREAM_SECRET: ${{ secrets.STREAM_SECRET }} 19 | run: | 20 | # Retry 3 times because tests can be flaky 21 | for _ in 1 2 3; 22 | do 23 | ./gradlew test --no-daemon && break 24 | done 25 | 26 | - name: Notify Slack if failed 27 | uses: voxmedia/github-action-slack-notify-build@v1 28 | if: failure() 29 | with: 30 | channel_id: C02RPDF7T63 31 | color: danger 32 | status: FAILED 33 | env: 34 | SLACK_BOT_TOKEN: ${{ secrets.SLACK_NOTIFICATIONS_BOT_TOKEN }} 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | !gradle/wrapper/gradle-wrapper.jar 16 | *.war 17 | *.nar 18 | *.ear 19 | *.zip 20 | *.tar.gz 21 | *.rar 22 | 23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 24 | hs_err_pid* 25 | /target/ 26 | /build/ 27 | .gradle/ 28 | /local.properties 29 | /bin/ 30 | 31 | .env 32 | .envrc 33 | secring.gpg 34 | 35 | .vscode/ 36 | .idea/ 37 | .classpath 38 | .project 39 | .settings/ 40 | gradle.properties 41 | -------------------------------------------------------------------------------- /.versionrc.js: -------------------------------------------------------------------------------- 1 | const gradleUpdater = { 2 | VERSION_REGEX: /version = '(.+)'/, 3 | 4 | readVersion: function (contents) { 5 | const version = this.VERSION_REGEX.exec(contents)[1]; 6 | return version; 7 | }, 8 | 9 | writeVersion: function (contents, version) { 10 | return contents.replace(this.VERSION_REGEX.exec(contents)[0], `version = '${version}'`); 11 | } 12 | } 13 | 14 | module.exports = { 15 | bumpFiles: [{ filename: './build.gradle', updater: gradleUpdater }], 16 | } 17 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM amazoncorretto:11 2 | 3 | WORKDIR /code 4 | 5 | # Copy the Gradle wrapper files 6 | COPY gradlew . 7 | COPY gradle gradle/ 8 | COPY build.gradle . 9 | COPY settings.gradle . 10 | 11 | # Make gradlew executable 12 | RUN chmod +x gradlew 13 | 14 | CMD ["sh", "-c", "./gradlew :spotlessApply"] -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | ./gradlew build 3 | 4 | format: 5 | ./gradlew :spotlessApply 6 | 7 | test: 8 | ./gradlew test 9 | 10 | test_with_docker: 11 | docker run -t -i -w /code -v $(PWD):/code --env-file .env amazoncorretto:17 sh -c "sh ./gradlew test" 12 | 13 | format_with_docker: 14 | docker build -t stream-chat-java-formatter . && \ 15 | docker run -v $(PWD):/code stream-chat-java-formatter 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Official Java SDK for [Stream Chat](https://getstream.io/chat/docs/) 2 | 3 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.getstream/stream-chat-java/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/io.getstream/stream-chat-java) [![build](https://github.com/GetStream/stream-chat-java/workflows/Build/badge.svg)](https://github.com/GetStream/stream-chat-java/actions) 4 | 5 |

6 | 7 |

8 |

9 | Official Java API client for Stream Chat, a service for building chat applications. 10 |
11 | Explore the docs » 12 |
13 |
14 | JavaDoc 15 | · 16 | Code Samples 17 | · 18 | Report Bug 19 | · 20 | Request Feature 21 |

22 | 23 | ## 📝 About Stream 24 | 25 | You can sign up for a Stream account at our [Get Started](https://getstream.io/chat/get_started/) page. 26 | 27 | You can use this library to access chat API endpoints server-side. 28 | 29 | For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries ([docs](https://getstream.io/chat/)). 30 | 31 | ## ⚙️ Installation 32 | 33 | > The Stream chat Java SDK requires Java 11+. It supports latest LTS. 34 | 35 | > The Stream chat Java SDK is compatible with Groovy, Scala, Kotlin and Clojure. 36 | 37 | ### Installation for Java 38 | 39 | #### Gradle 40 | 41 | ```gradle 42 | dependencies { 43 | implementation "io.getstream:stream-chat-java:$stream_version" 44 | } 45 | ``` 46 | 47 | #### Maven 48 | 49 | ```maven 50 | 51 | io.getstream 52 | stream-chat-java 53 | $stream_version 54 | 55 | ``` 56 | 57 | ### Installation for Groovy 58 | 59 | #### Gradle 60 | 61 | ```gradle 62 | dependencies { 63 | implementation 'io.getstream:stream-chat-java:$stream_version' 64 | } 65 | ``` 66 | 67 | > You can see an example project at [GetStream/stream-chat-groovy-example](https://github.com/GetStream/stream-chat-groovy-example). 68 | 69 | ### Installation for Scala 70 | 71 | #### Gradle 72 | 73 | ```gradle 74 | dependencies { 75 | implementation 'io.getstream:stream-chat-java:$stream_version' 76 | } 77 | ``` 78 | 79 | > You can see an example project at [GetStream/stream-chat-scala-example](https://github.com/GetStream/stream-chat-scala-example). 80 | 81 | ### Installation for Kotlin 82 | 83 | #### Gradle 84 | 85 | ```gradle 86 | dependencies { 87 | implementation("io.getstream:stream-chat-java:$stream_version") 88 | } 89 | ``` 90 | 91 | > You can see an example project at [GetStream/stream-chat-kotlin-example](https://github.com/GetStream/stream-chat-kotlin-example). 92 | 93 | ### Installation for Clojure 94 | 95 | #### Leiningen 96 | 97 | ```leiningen 98 | :dependencies [[io.getstream/stream-chat-java "$stream_version"]] 99 | ``` 100 | 101 | > You can see an example project at [GetStream/stream-chat-clojure-example](https://github.com/GetStream/stream-chat-clojure-example). 102 | 103 | ## 🔀 Dependencies 104 | 105 | This SDK uses lombok (code generation), retrofit (http client), jackson (json) and jjwt (jwt). 106 | 107 | > You can find the exact versions in [build.gradle](./build.gradle). 108 | 109 | ## 🥷🏿 Shadowed version 110 | 111 | If you have conflicts with our dependencies, you can use the shadowed (shaded) version of the library: 112 | 113 |
114 | io.getstream:stream-chat-java-all:1.26.2
115 | 
116 | 117 | ## ✨ Getting started 118 | 119 | ### Configuration 120 | 121 | To configure the SDK you need to provide required properties 122 | 123 | | Property | ENV | Default | Required | 124 | | --------------------------- | ------------------- | ------------------------------ | -------- | 125 | | io.getstream.chat.apiKey | STREAM_KEY | - | Yes | 126 | | io.getstream.chat.apiSecret | STREAM_SECRET | - | Yes | 127 | | io.getstream.chat.timeout | STREAM_CHAT_TIMEOUT | 10000 | No | 128 | | io.getstream.chat.url | STREAM_CHAT_URL | https://chat.stream-io-api.com | No | 129 | 130 | You can also use your own CDN by creating an implementation of FileHandler and setting it this way 131 | 132 | ```java 133 | Message.fileHandlerClass = MyFileHandler.class 134 | ``` 135 | 136 | All setup must be done prior to any request to the API. 137 | 138 | ## Print Chat app configuration 139 | 140 | 141 | 142 | 173 |
Java 143 | 144 | ```java 145 | System.out.println(App.get().request()); 146 | ``` 147 | 148 |
Groovy 149 | 150 | ```groovy 151 | println App.get().request() 152 | ``` 153 | 154 |
Scala 155 | 156 | ```scala 157 | println(App.get.request) 158 | ``` 159 | 160 |
Kotlin 161 | 162 | ```kotlin 163 | println(App.get().request()) 164 | ``` 165 | 166 |
Clojure 167 | 168 | ```clojure 169 | println (.request (App/get)) 170 | ``` 171 | 172 |
174 | 175 | ## 📚 Code examples 176 | 177 | Head over to [DOCS.md](./DOCS.md) for code snippets. 178 | 179 | ## 🙋 FAQ 180 | 181 | 1. If you get this exception: `java.lang.ClassNotFoundException: io.jsonwebtoken.SignatureAlgorithm`: 182 | 183 | See [shadowed version](#-shadowed-version). 184 | 185 | ## ✍️ Contributing 186 | 187 | We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our [Contributor License Agreement (CLA)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our [license file](./LICENSE) for more details. 188 | 189 | Head over to [CONTRIBUTING.md](./CONTRIBUTING.md) for some development tips. 190 | 191 | ## 🧑‍💻 We are hiring! 192 | 193 | We've recently closed a [$38 million Series B funding round](https://techcrunch.com/2021/03/04/stream-raises-38m-as-its-chat-and-activity-feed-apis-power-communications-for-1b-users/) and we keep actively growing. 194 | Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world. 195 | 196 | Check out our current openings and apply via [Stream's website](https://getstream.io/team/#jobs). 197 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting a Vulnerability 2 | At Stream we are committed to the security of our Software. We appreciate your efforts in disclosing vulnerabilities responsibly and we will make every effort to acknowledge your contributions. 3 | 4 | Report security vulnerabilities at the following email address: 5 | ``` 6 | [security@getstream.io](mailto:security@getstream.io) 7 | ``` 8 | Alternatively it is also possible to open a new issue in the affected repository, tagging it with the `security` tag. 9 | 10 | A team member will acknowledge the vulnerability and will follow-up with more detailed information. A representative of the security team will be in touch if more information is needed. 11 | 12 | # Information to include in a report 13 | While we appreciate any information that you are willing to provide, please make sure to include the following: 14 | * Which repository is affected 15 | * Which branch, if relevant 16 | * Be as descriptive as possible, the team will replicate the vulnerability before working on a fix. 17 | -------------------------------------------------------------------------------- /assets/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | STREAM MARK 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' 4 | id 'com.diffplug.spotless' version '6.25.0' 5 | id 'org.barfuin.gradle.jacocolog' version '3.1.0' 6 | id 'com.github.johnrengelman.shadow' version '8.1.1' 7 | } 8 | 9 | group = 'io.getstream' 10 | version = '1.29.0' 11 | description = 'Stream Chat official Java SDK' 12 | 13 | java { 14 | toolchain { 15 | languageVersion = JavaLanguageVersion.of(11) 16 | } 17 | 18 | withJavadocJar() 19 | withSourcesJar() 20 | } 21 | 22 | repositories { 23 | mavenLocal() 24 | mavenCentral() 25 | maven { url "https://plugins.gradle.org/m2/" } 26 | maven { url uri('https://repo.maven.apache.org/maven2/') } 27 | } 28 | 29 | dependencies { 30 | implementation(platform("com.squareup.okhttp3:okhttp-bom:4.12.0")) 31 | 32 | // define any required OkHttp artifacts without version 33 | implementation("com.squareup.okhttp3:okhttp") 34 | 35 | implementation 'com.squareup.retrofit2:retrofit:2.9.0' 36 | implementation 'com.squareup.retrofit2:converter-jackson:2.9.0' 37 | implementation 'io.jsonwebtoken:jjwt-api:0.12.5' 38 | runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.5' 39 | runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.5' 40 | testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2' 41 | testImplementation 'org.apache.commons:commons-lang3:3.12.0' 42 | compileOnly 'org.projectlombok:lombok:1.18.32' 43 | annotationProcessor 'org.projectlombok:lombok:1.18.32' 44 | 45 | testCompileOnly 'org.projectlombok:lombok:1.18.32' 46 | testAnnotationProcessor 'org.projectlombok:lombok:1.18.32' 47 | } 48 | 49 | def localProperties = new Properties() 50 | def localPropertiesFile = project.rootProject.file('local.properties') 51 | if (localPropertiesFile.exists()) { 52 | localProperties.load(localPropertiesFile.newDataInputStream()) 53 | } 54 | 55 | test { 56 | useJUnitPlatform() 57 | 58 | testLogging { 59 | exceptionFormat = 'full' 60 | events 'standard_out', 'standard_error', "passed", "skipped", "failed" 61 | } 62 | 63 | doFirst { 64 | // Inject local properties into tests runtime system properties 65 | localProperties.each{k, v -> 66 | systemProperty k.toString(), v.toString() 67 | } 68 | } 69 | 70 | finalizedBy jacocoTestReport 71 | } 72 | 73 | def generatedVersionDir = "${buildDir}/generated-version" 74 | 75 | sourceSets { 76 | main { 77 | output.dir(generatedVersionDir, builtBy: 'generateVersionProperties') 78 | } 79 | } 80 | spotless { 81 | java { 82 | googleJavaFormat() 83 | } 84 | 85 | groovyGradle { 86 | target '*.gradle' 87 | greclipse() 88 | } 89 | } 90 | 91 | jacocoTestReport { 92 | dependsOn test 93 | } 94 | 95 | task generateVersionProperties { 96 | doLast { 97 | def propertiesFile = file "$generatedVersionDir/version.properties" 98 | propertiesFile.parentFile.mkdirs() 99 | def properties = new Properties() 100 | properties.setProperty("version", rootProject.version.toString()) 101 | propertiesFile.withWriter { properties.store(it, null) } 102 | } 103 | } 104 | processResources.dependsOn generateVersionProperties 105 | 106 | shadowJar { 107 | enableRelocation true 108 | relocationPrefix "shadowed" 109 | mergeServiceFiles() 110 | } 111 | 112 | apply from: "publish.gradle" 113 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/stream-chat-java/5c415dba32ea40e867ced2ac004dad057348b6a1/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 1>&2 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 48 | echo. 1>&2 49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 50 | echo location of your Java installation. 1>&2 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 1>&2 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 62 | echo. 1>&2 63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 64 | echo location of your Java installation. 1>&2 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /local.properties.example: -------------------------------------------------------------------------------- 1 | ossrhUsername= 2 | ossrhPassword= 3 | signing.keyId= 4 | signing.password= 5 | signing.secretKeyRingFile= 6 | sonatypeStagingProfileId= 7 | io.getstream.chat.apiKey= 8 | io.getstream.chat.apiSecret= 9 | io.getstream.chat.url=https://chat.stream-io-api.com 10 | io.getstream.chat.timeout=10000 11 | -------------------------------------------------------------------------------- /publish.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven-publish' 2 | apply plugin: 'signing' 3 | 4 | // Create variables with empty default values 5 | ext["ossrhUsername"] = '' 6 | ext["ossrhPassword"] = '' 7 | ext["signing.keyId"] = '' 8 | ext["signing.password"] = '' 9 | ext["signing.secretKeyRingFile"] = '' 10 | ext["sonatypeStagingProfileId"] = '' 11 | 12 | File secretPropsFile = project.rootProject.file('local.properties') 13 | if (secretPropsFile.exists()) { 14 | // Read local.properties file first if it exists 15 | Properties p = new Properties() 16 | new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) } 17 | p.each { name, value -> ext[name] = value } 18 | } else { 19 | // Use system environment variables 20 | ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME') 21 | ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD') 22 | ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') 23 | ext["signing.password"] = System.getenv('SIGNING_PASSWORD') 24 | ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE') 25 | ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID') 26 | } 27 | 28 | nexusPublishing { 29 | repositories { 30 | sonatype { 31 | stagingProfileId = sonatypeStagingProfileId 32 | username = ossrhUsername 33 | password = ossrhPassword 34 | } 35 | } 36 | } 37 | 38 | // to remove shadowed jar from the regular release publication 39 | components.java.withVariantsFromConfiguration(configurations.shadowRuntimeElements) { 40 | skip() 41 | } 42 | 43 | def configurePom(pom) { 44 | pom.with { 45 | name = "Stream Chat official Java API Client" 46 | description = "Stream Chat Java Client for backend integrations" 47 | url = 'https://github.com/getstream/stream-chat-java' 48 | licenses { 49 | license { 50 | name = 'Stream License' 51 | url = 'https://github.com/GetStream/stream-chat-java/blob/main/LICENSE' 52 | } 53 | } 54 | developers { 55 | developer { 56 | id = 'getstream-support' 57 | name = 'Stream Support' 58 | email = 'support@getstream.io' 59 | } 60 | } 61 | scm { 62 | connection = 'scm:git:github.com/getstream/stream-chat-java.git' 63 | developerConnection = 'scm:git:ssh://github.com/getstream/stream-chat-java.git' 64 | url = 'https://github.com/getstream/stream-chat-java/tree/main' 65 | } 66 | } 67 | } 68 | 69 | afterEvaluate { 70 | publishing { 71 | publications { 72 | release(MavenPublication) { 73 | from components.java 74 | artifactId 'stream-chat-java' 75 | configurePom(pom) 76 | } 77 | 78 | shadow(MavenPublication) { publication -> 79 | project.shadow.component(publication) 80 | artifactId 'stream-chat-java-all' 81 | artifact javadocJar 82 | artifact sourcesJar 83 | configurePom(pom) 84 | } 85 | } 86 | } 87 | } 88 | 89 | signing { 90 | sign publishing.publications 91 | } 92 | 93 | // Ensure that the publish tasks run after the sign tasks, otherwise gradle will complain 94 | tasks.matching { it.name.startsWith('publish') }.all { publishTask -> 95 | tasks.matching { it.name.startsWith('sign') }.all { signTask -> 96 | publishTask.mustRunAfter(signTask) 97 | } 98 | } 99 | 100 | javadoc { 101 | options.addBooleanOption('html5', true) 102 | } 103 | -------------------------------------------------------------------------------- /scripts/get_changelog_diff.js: -------------------------------------------------------------------------------- 1 | /* 2 | Here we're trying to parse the latest changes from CHANGELOG.md file. 3 | The changelog looks like this: 4 | 5 | ## 0.0.3 6 | - Something #3 7 | ## 0.0.2 8 | - Something #2 9 | ## 0.0.1 10 | - Something #1 11 | 12 | In this case we're trying to extract "- Something #3" since that's the latest change. 13 | */ 14 | module.exports = () => { 15 | const fs = require('fs') 16 | 17 | changelog = fs.readFileSync('CHANGELOG.md', 'utf8') 18 | releases = changelog.match(/## [?[0-9](.+)/g) 19 | 20 | current_release = changelog.indexOf(releases[0]) 21 | previous_release = changelog.indexOf(releases[1]) 22 | 23 | latest_changes = changelog.substr(current_release, previous_release - current_release) 24 | 25 | return latest_changes 26 | } 27 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | */ 4 | 5 | rootProject.name = 'stream-chat-java' 6 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/exceptions/StreamException.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.exceptions; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.core.JsonProcessingException; 5 | import com.fasterxml.jackson.databind.DeserializationFeature; 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | import java.io.IOException; 8 | import java.util.Map; 9 | import lombok.Data; 10 | import lombok.Getter; 11 | import okhttp3.ResponseBody; 12 | import retrofit2.Response; 13 | 14 | public class StreamException extends Exception { 15 | private static final long serialVersionUID = 1L; 16 | 17 | @Getter private ResponseData responseData; 18 | 19 | public StreamException(String message, ResponseData responseData) { 20 | super(message); 21 | this.responseData = responseData; 22 | } 23 | 24 | public StreamException(String message, Throwable t) { 25 | super(message, t); 26 | } 27 | 28 | public StreamException(Throwable t) { 29 | super(t); 30 | } 31 | 32 | /** 33 | * Builds a StreamException to signal an issue 34 | * 35 | * @param issue the issue 36 | * @return the StreamException 37 | */ 38 | public static StreamException build(String issue) { 39 | return new StreamException(issue, (Throwable) null); 40 | } 41 | 42 | /** 43 | * Builds a StreamException using the response body when Stream API request fails 44 | * 45 | * @param responseBody Stream API response body 46 | * @return the StreamException 47 | */ 48 | @Deprecated 49 | public static StreamException build(ResponseBody responseBody) { 50 | ObjectMapper objectMapper = new ObjectMapper(); 51 | objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 52 | try { 53 | String responseBodyString = responseBody.string(); 54 | try { 55 | ResponseData responseData = objectMapper.readValue(responseBodyString, ResponseData.class); 56 | return new StreamException(responseData.getMessage(), responseData); 57 | } catch (JsonProcessingException e) { 58 | return new StreamException(responseBodyString, e); 59 | } 60 | } catch (IOException e) { 61 | return new StreamException(e); 62 | } 63 | } 64 | 65 | /** 66 | * Builds a StreamException based on response from the server and http code 67 | * 68 | * @param httpResponse Stream API response 69 | * @return the StreamException 70 | */ 71 | public static StreamException build(Response httpResponse) { 72 | StreamException exception; 73 | 74 | ResponseBody errorBody = httpResponse.errorBody(); 75 | if (errorBody != null) { 76 | exception = StreamException.build(errorBody); 77 | } else { 78 | exception = 79 | StreamException.build( 80 | String.format("Unexpected server response code %d", httpResponse.code())); 81 | } 82 | 83 | if (exception.responseData == null) { 84 | ResponseData responseData = new ResponseData(); 85 | responseData.statusCode = httpResponse.code(); 86 | exception.responseData = responseData; 87 | } 88 | 89 | return exception; 90 | } 91 | 92 | /** 93 | * Builds a StreamException when an exception occurs calling the API 94 | * 95 | * @param t the underlying exception 96 | * @return the StreamException 97 | */ 98 | public static StreamException build(Throwable t) { 99 | return new StreamException(t); 100 | } 101 | 102 | @Data 103 | public static class ResponseData { 104 | @JsonProperty("code") 105 | private Integer code; 106 | 107 | @JsonProperty("message") 108 | private String message; 109 | 110 | @JsonProperty("exception_fields") 111 | private Map exceptionFields; 112 | 113 | @JsonProperty("StatusCode") 114 | private Integer statusCode; 115 | 116 | @JsonProperty("duration") 117 | private String duration; 118 | 119 | @JsonProperty("more_info") 120 | private String moreInfo; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/BlockUser.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import io.getstream.chat.java.models.framework.StreamRequest; 5 | import io.getstream.chat.java.models.framework.StreamResponseObject; 6 | import io.getstream.chat.java.services.BlockUserService; 7 | import io.getstream.chat.java.services.framework.Client; 8 | import java.util.Date; 9 | import java.util.List; 10 | import lombok.*; 11 | import org.jetbrains.annotations.NotNull; 12 | import retrofit2.Call; 13 | 14 | @Data 15 | @NoArgsConstructor 16 | public class BlockUser { 17 | 18 | @Builder( 19 | builderClassName = "BlockUserRequest", 20 | builderMethodName = "", 21 | buildMethodName = "internalBuild") 22 | public static class BlockUserRequestData { 23 | @NotNull 24 | @JsonProperty("blocked_user_id") 25 | private String blockedUserID; 26 | 27 | @NotNull 28 | @JsonProperty("user_id") 29 | private String userID; 30 | 31 | public static class BlockUserRequest extends StreamRequest { 32 | @Override 33 | protected Call generateCall(Client client) { 34 | var data = this.internalBuild(); 35 | return client.create(BlockUserService.class).blockUser(data); 36 | } 37 | } 38 | } 39 | 40 | @Builder( 41 | builderClassName = "UnblockUserRequest", 42 | builderMethodName = "", 43 | buildMethodName = "internalBuild") 44 | public static class UnblockUserRequestData { 45 | @NotNull 46 | @JsonProperty("blocked_user_id") 47 | private String blockedUserID; 48 | 49 | @NotNull 50 | @JsonProperty("user_id") 51 | private String userID; 52 | 53 | public static class UnblockUserRequest extends StreamRequest { 54 | @Override 55 | protected Call generateCall(Client client) { 56 | var data = this.internalBuild(); 57 | return client.create(BlockUserService.class).unblockUser(data); 58 | } 59 | } 60 | } 61 | 62 | @NotNull 63 | public static BlockUserRequestData.BlockUserRequest blockUser() { 64 | return new BlockUserRequestData.BlockUserRequest(); 65 | } 66 | 67 | @NotNull 68 | public static UnblockUserRequestData.UnblockUserRequest unblockUser() { 69 | return new UnblockUserRequestData.UnblockUserRequest(); 70 | } 71 | 72 | @Data 73 | @EqualsAndHashCode(callSuper = true) 74 | @NoArgsConstructor 75 | public static class BlockUserResponse extends StreamResponseObject { 76 | @JsonProperty("blocked_by_user_id") 77 | private String blockedByUserID; 78 | 79 | @JsonProperty("blocked_user_id") 80 | private String blockedUserID; 81 | 82 | @JsonProperty("created_at") 83 | private Date createdAt; 84 | } 85 | 86 | @Data 87 | @EqualsAndHashCode(callSuper = true) 88 | @NoArgsConstructor 89 | public static class UnblockUserResponse extends StreamResponseObject {} 90 | 91 | @Data 92 | @EqualsAndHashCode(callSuper = true) 93 | @NoArgsConstructor 94 | public static class GetBlockedUsersResponse extends StreamResponseObject { 95 | @JsonProperty("blocks") 96 | private List blockedUsers; 97 | } 98 | 99 | @Data 100 | @NoArgsConstructor 101 | public static class BlockedUserResponse { 102 | @JsonProperty("user") 103 | private User blockedByUser; 104 | 105 | @JsonProperty("user_id") 106 | private String blockedByUserID; 107 | 108 | @JsonProperty("blocked_user") 109 | private User blockedUser; 110 | 111 | @JsonProperty("blocked_user_id") 112 | private String blockedUserID; 113 | 114 | @JsonProperty("created_at") 115 | private Date createdAt; 116 | } 117 | 118 | @Builder( 119 | builderClassName = "GetBlockedUsersRequest", 120 | builderMethodName = "", 121 | buildMethodName = "internalBuild") 122 | public static class GetBlockedUsersRequestData { 123 | @NotNull 124 | @JsonProperty("user_id") 125 | private String blockedByUserID; 126 | 127 | public static class GetBlockedUsersRequest extends StreamRequest { 128 | private String blockedByUserID; 129 | 130 | public GetBlockedUsersRequest(String blockedByUserID) { 131 | this.blockedByUserID = blockedByUserID; 132 | } 133 | 134 | @Override 135 | protected Call generateCall(Client client) { 136 | return client.create(BlockUserService.class).getBlockedUsers(blockedByUserID); 137 | } 138 | } 139 | } 140 | 141 | @NotNull 142 | public static GetBlockedUsersRequestData.GetBlockedUsersRequest getBlockedUsers( 143 | String blockedByUserID) { 144 | return new GetBlockedUsersRequestData.GetBlockedUsersRequest(blockedByUserID); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/Blocklist.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import io.getstream.chat.java.models.Blocklist.BlocklistCreateRequestData.BlocklistCreateRequest; 5 | import io.getstream.chat.java.models.Blocklist.BlocklistUpdateRequestData.BlocklistUpdateRequest; 6 | import io.getstream.chat.java.models.framework.StreamRequest; 7 | import io.getstream.chat.java.models.framework.StreamResponseObject; 8 | import io.getstream.chat.java.services.BlocklistService; 9 | import io.getstream.chat.java.services.framework.Client; 10 | import java.util.Date; 11 | import java.util.List; 12 | import lombok.*; 13 | import org.jetbrains.annotations.NotNull; 14 | import org.jetbrains.annotations.Nullable; 15 | import retrofit2.Call; 16 | 17 | @Data 18 | @NoArgsConstructor 19 | public class Blocklist { 20 | @NotNull 21 | @JsonProperty("created_at") 22 | private Date createdAt; 23 | 24 | @NotNull 25 | @JsonProperty("updated_at") 26 | private Date updatedAt; 27 | 28 | @NotNull 29 | @JsonProperty("name") 30 | private String name; 31 | 32 | @NotNull 33 | @JsonProperty("words") 34 | private List words; 35 | 36 | @Builder( 37 | builderClassName = "BlocklistCreateRequest", 38 | builderMethodName = "", 39 | buildMethodName = "internalBuild") 40 | public static class BlocklistCreateRequestData { 41 | @Nullable 42 | @JsonProperty("name") 43 | private String name; 44 | 45 | @Nullable 46 | @JsonProperty("words") 47 | private List words; 48 | 49 | public static class BlocklistCreateRequest extends StreamRequest { 50 | @Override 51 | protected Call generateCall(Client client) { 52 | return client.create(BlocklistService.class).create(this.internalBuild()); 53 | } 54 | } 55 | } 56 | 57 | @RequiredArgsConstructor 58 | public static class BlocklistGetRequest extends StreamRequest { 59 | @NotNull private String name; 60 | 61 | @Override 62 | protected Call generateCall(Client client) { 63 | return client.create(BlocklistService.class).get(name); 64 | } 65 | } 66 | 67 | @Builder( 68 | builderClassName = "BlocklistUpdateRequest", 69 | builderMethodName = "", 70 | buildMethodName = "internalBuild") 71 | public static class BlocklistUpdateRequestData { 72 | @Nullable 73 | @JsonProperty("words") 74 | private List words; 75 | 76 | public static class BlocklistUpdateRequest extends StreamRequest { 77 | @NotNull private String name; 78 | 79 | private BlocklistUpdateRequest(@NotNull String name) { 80 | this.name = name; 81 | } 82 | 83 | @Override 84 | protected Call generateCall(Client client) { 85 | return client.create(BlocklistService.class).update(name, this.internalBuild()); 86 | } 87 | } 88 | } 89 | 90 | @RequiredArgsConstructor 91 | public static class BlocklistDeleteRequest extends StreamRequest { 92 | @NotNull private String name; 93 | 94 | @Override 95 | protected Call generateCall(Client client) { 96 | return client.create(BlocklistService.class).delete(name); 97 | } 98 | } 99 | 100 | public static class BlocklistListRequest extends StreamRequest { 101 | @Override 102 | protected Call generateCall(Client client) { 103 | return client.create(BlocklistService.class).list(); 104 | } 105 | } 106 | 107 | @Data 108 | @NoArgsConstructor 109 | @EqualsAndHashCode(callSuper = true) 110 | public static class BlocklistGetResponse extends StreamResponseObject { 111 | @NotNull 112 | @JsonProperty("blocklist") 113 | private Blocklist blocklist; 114 | } 115 | 116 | @Data 117 | @NoArgsConstructor 118 | @EqualsAndHashCode(callSuper = true) 119 | public static class BlocklistListResponse extends StreamResponseObject { 120 | @NotNull 121 | @JsonProperty("blocklists") 122 | private List blocklists; 123 | } 124 | 125 | /** 126 | * Creates a create request 127 | * 128 | * @return the created request 129 | */ 130 | @NotNull 131 | public static BlocklistCreateRequest create() { 132 | return new BlocklistCreateRequest(); 133 | } 134 | 135 | /** 136 | * Creates a get request 137 | * 138 | * @param name the blocklist name 139 | * @return the created request 140 | */ 141 | @NotNull 142 | public static BlocklistGetRequest get(@NotNull String name) { 143 | return new BlocklistGetRequest(name); 144 | } 145 | 146 | /** 147 | * Creates an update request 148 | * 149 | * @param name the blocklist name 150 | * @return the created request 151 | */ 152 | @NotNull 153 | public static BlocklistUpdateRequest update(@NotNull String name) { 154 | return new BlocklistUpdateRequest(name); 155 | } 156 | 157 | /** 158 | * Creates a delete request 159 | * 160 | * @param name the blocklist name 161 | * @return the created request 162 | */ 163 | @NotNull 164 | public static BlocklistDeleteRequest delete(@NotNull String name) { 165 | return new BlocklistDeleteRequest(name); 166 | } 167 | 168 | /** 169 | * Creates a list request 170 | * 171 | * @return the created request 172 | */ 173 | @NotNull 174 | public static BlocklistListRequest list() { 175 | return new BlocklistListRequest(); 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/Command.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import io.getstream.chat.java.models.Command.CommandCreateRequestData.CommandCreateRequest; 5 | import io.getstream.chat.java.models.Command.CommandUpdateRequestData.CommandUpdateRequest; 6 | import io.getstream.chat.java.models.framework.StreamRequest; 7 | import io.getstream.chat.java.models.framework.StreamResponse; 8 | import io.getstream.chat.java.models.framework.StreamResponseObject; 9 | import io.getstream.chat.java.services.CommandService; 10 | import io.getstream.chat.java.services.framework.Client; 11 | import java.util.Date; 12 | import java.util.List; 13 | import lombok.*; 14 | import org.jetbrains.annotations.NotNull; 15 | import org.jetbrains.annotations.Nullable; 16 | import retrofit2.Call; 17 | 18 | @Data 19 | @NoArgsConstructor 20 | public class Command { 21 | @NotNull 22 | @JsonProperty("created_at") 23 | private Date createdAt; 24 | 25 | @NotNull 26 | @JsonProperty("updated_at") 27 | private Date updatedAt; 28 | 29 | @NotNull 30 | @JsonProperty("name") 31 | private String name; 32 | 33 | @NotNull 34 | @JsonProperty("description") 35 | private String description; 36 | 37 | @Nullable 38 | @JsonProperty("args") 39 | private String args; 40 | 41 | @Nullable 42 | @JsonProperty("set") 43 | private String setValue; 44 | 45 | @Builder( 46 | builderClassName = "CommandCreateRequest", 47 | builderMethodName = "", 48 | buildMethodName = "internalBuild") 49 | public static class CommandCreateRequestData { 50 | @Nullable 51 | @JsonProperty("name") 52 | private String name; 53 | 54 | @Nullable 55 | @JsonProperty("description") 56 | private String description; 57 | 58 | @Nullable 59 | @JsonProperty("args") 60 | private String args; 61 | 62 | @Nullable 63 | @JsonProperty("set") 64 | private String setValue; 65 | 66 | public static class CommandCreateRequest extends StreamRequest { 67 | @Override 68 | protected Call generateCall(Client client) { 69 | return client.create(CommandService.class).create(this.internalBuild()); 70 | } 71 | } 72 | } 73 | 74 | @RequiredArgsConstructor 75 | public static class CommandGetRequest extends StreamRequest { 76 | @NotNull private String name; 77 | 78 | @Override 79 | protected Call generateCall(Client client) { 80 | return client.create(CommandService.class).get(name); 81 | } 82 | } 83 | 84 | @Builder( 85 | builderClassName = "CommandUpdateRequest", 86 | builderMethodName = "", 87 | buildMethodName = "internalBuild") 88 | public static class CommandUpdateRequestData { 89 | @Nullable 90 | @JsonProperty("description") 91 | private String description; 92 | 93 | @Nullable 94 | @JsonProperty("args") 95 | private String args; 96 | 97 | @Nullable 98 | @JsonProperty("set") 99 | private String setValue; 100 | 101 | public static class CommandUpdateRequest extends StreamRequest { 102 | @NotNull private String name; 103 | 104 | private CommandUpdateRequest(@NotNull String name) { 105 | this.name = name; 106 | } 107 | 108 | @Override 109 | protected Call generateCall(Client client) { 110 | return client.create(CommandService.class).update(name, this.internalBuild()); 111 | } 112 | } 113 | } 114 | 115 | @RequiredArgsConstructor 116 | public static class CommandDeleteRequest extends StreamRequest { 117 | @NotNull private String name; 118 | 119 | @Override 120 | protected Call generateCall(Client client) { 121 | return client.create(CommandService.class).delete(name); 122 | } 123 | } 124 | 125 | public static class CommandListRequest extends StreamRequest { 126 | @Override 127 | protected Call generateCall(Client client) { 128 | return client.create(CommandService.class).list(); 129 | } 130 | } 131 | 132 | @Data 133 | @NoArgsConstructor 134 | @EqualsAndHashCode(callSuper = true) 135 | public static class CommandCreateResponse extends StreamResponseObject { 136 | @NotNull 137 | @JsonProperty("command") 138 | private Command command; 139 | } 140 | 141 | @Data 142 | @NoArgsConstructor 143 | @EqualsAndHashCode(callSuper = true) 144 | public static class CommandGetResponse extends Command implements StreamResponse { 145 | private RateLimit rateLimit; 146 | 147 | @NotNull 148 | @JsonProperty("duration") 149 | private String duration; 150 | } 151 | 152 | @Data 153 | @NoArgsConstructor 154 | @EqualsAndHashCode(callSuper = true) 155 | public static class CommandUpdateResponse extends StreamResponseObject { 156 | @NotNull 157 | @JsonProperty("command") 158 | private Command command; 159 | } 160 | 161 | @Data 162 | @NoArgsConstructor 163 | @EqualsAndHashCode(callSuper = true) 164 | public static class CommandDeleteResponse extends StreamResponseObject { 165 | @NotNull 166 | @JsonProperty("name") 167 | private String name; 168 | } 169 | 170 | @Data 171 | @NoArgsConstructor 172 | @EqualsAndHashCode(callSuper = true) 173 | public static class CommandListResponse extends StreamResponseObject { 174 | @NotNull 175 | @JsonProperty("commands") 176 | private List commands; 177 | } 178 | 179 | /** 180 | * Creates a create request 181 | * 182 | * @return the created request 183 | */ 184 | @NotNull 185 | public static CommandCreateRequest create() { 186 | return new CommandCreateRequest(); 187 | } 188 | 189 | /** 190 | * Creates a get request 191 | * 192 | * @param name the command name 193 | * @return the created request 194 | */ 195 | @NotNull 196 | public static CommandGetRequest get(@NotNull String name) { 197 | return new CommandGetRequest(name); 198 | } 199 | 200 | /** 201 | * Creates an update request 202 | * 203 | * @param name the command name 204 | * @return the created request 205 | */ 206 | @NotNull 207 | public static CommandUpdateRequest update(@NotNull String name) { 208 | return new CommandUpdateRequest(name); 209 | } 210 | 211 | /** 212 | * Creates a delete request 213 | * 214 | * @param name the command name 215 | * @return the created request 216 | */ 217 | @NotNull 218 | public static CommandDeleteRequest delete(@NotNull String name) { 219 | return new CommandDeleteRequest(name); 220 | } 221 | 222 | /** 223 | * Creates a list request 224 | * 225 | * @return the created request 226 | */ 227 | @NotNull 228 | public static CommandListRequest list() { 229 | return new CommandListRequest(); 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/DeleteStrategy.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | public enum DeleteStrategy { 6 | @JsonProperty("soft") 7 | SOFT, 8 | @JsonProperty("hard") 9 | HARD 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/Device.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import io.getstream.chat.java.models.App.PushProviderType; 5 | import io.getstream.chat.java.models.Device.DeviceCreateRequestData.DeviceCreateRequest; 6 | import io.getstream.chat.java.models.User.UserRequestObject; 7 | import io.getstream.chat.java.models.framework.RequestObjectBuilder; 8 | import io.getstream.chat.java.models.framework.StreamRequest; 9 | import io.getstream.chat.java.models.framework.StreamResponseObject; 10 | import io.getstream.chat.java.services.DeviceService; 11 | import io.getstream.chat.java.services.framework.Client; 12 | import java.util.Date; 13 | import java.util.List; 14 | import lombok.*; 15 | import org.jetbrains.annotations.NotNull; 16 | import org.jetbrains.annotations.Nullable; 17 | import retrofit2.Call; 18 | 19 | @Data 20 | @NoArgsConstructor 21 | public class Device { 22 | @Nullable 23 | @JsonProperty("push_provider") 24 | private PushProviderType pushProvider; 25 | 26 | @NotNull 27 | @JsonProperty("id") 28 | private String id; 29 | 30 | @Nullable 31 | @JsonProperty("push_provider_name") 32 | private String pushProviderName; 33 | 34 | @NotNull 35 | @JsonProperty("created_at") 36 | private Date createdAt; 37 | 38 | @Nullable 39 | @JsonProperty("disabled") 40 | private Boolean disabled; 41 | 42 | @Nullable 43 | @JsonProperty("disabled_reason") 44 | private String disabledReason; 45 | 46 | @NotNull 47 | @JsonProperty("user_id") 48 | private String userId; 49 | 50 | @Builder 51 | @Setter 52 | public static class DeviceRequestObject { 53 | @Nullable 54 | @JsonProperty("push_provider") 55 | private PushProviderType pushProvider; 56 | 57 | @Nullable 58 | @JsonProperty("id") 59 | private String id; 60 | 61 | @Nullable 62 | @JsonProperty("push_provider_name") 63 | private String pushProviderName; 64 | 65 | @Nullable 66 | @JsonProperty("created_at") 67 | private Date createdAt; 68 | 69 | @Nullable 70 | @JsonProperty("disabled") 71 | private Boolean disabled; 72 | 73 | @Nullable 74 | @JsonProperty("disabled_reason") 75 | private String disabledReason; 76 | 77 | @Nullable 78 | @JsonProperty("user_id") 79 | private String userId; 80 | 81 | @Nullable 82 | public static DeviceRequestObject buildFrom(@Nullable Device device) { 83 | return RequestObjectBuilder.build(DeviceRequestObject.class, device); 84 | } 85 | } 86 | 87 | @Builder( 88 | builderClassName = "DeviceCreateRequest", 89 | builderMethodName = "", 90 | buildMethodName = "internalBuild") 91 | public static class DeviceCreateRequestData { 92 | @Nullable 93 | @JsonProperty("push_provider") 94 | private PushProviderType pushProvider; 95 | 96 | @Nullable 97 | @JsonProperty("id") 98 | private String id; 99 | 100 | @Nullable 101 | @JsonProperty("push_provider_name") 102 | private String pushProviderName; 103 | 104 | @Nullable 105 | @JsonProperty("user_id") 106 | private String userId; 107 | 108 | @Nullable 109 | @JsonProperty("user") 110 | private UserRequestObject user; 111 | 112 | public static class DeviceCreateRequest extends StreamRequest { 113 | @Override 114 | protected Call generateCall(Client client) { 115 | return client.create(DeviceService.class).create(this.internalBuild()); 116 | } 117 | } 118 | } 119 | 120 | @RequiredArgsConstructor 121 | public static class DeviceDeleteRequest extends StreamRequest { 122 | @NotNull private String id; 123 | 124 | @NotNull private String userId; 125 | 126 | @NotNull 127 | public DeviceDeleteRequest id(@NotNull String id) { 128 | this.id = id; 129 | return this; 130 | } 131 | 132 | @NotNull 133 | public DeviceDeleteRequest userId(@NotNull String userId) { 134 | this.userId = userId; 135 | return this; 136 | } 137 | 138 | @Override 139 | protected Call generateCall(Client client) { 140 | return client.create(DeviceService.class).delete(id, userId); 141 | } 142 | } 143 | 144 | @RequiredArgsConstructor 145 | public static class DeviceListRequest extends StreamRequest { 146 | @NotNull private String userId; 147 | 148 | @Override 149 | protected Call generateCall(Client client) { 150 | return client.create(DeviceService.class).list(userId); 151 | } 152 | } 153 | 154 | @Data 155 | @NoArgsConstructor 156 | @EqualsAndHashCode(callSuper = true) 157 | public static class DeviceListResponse extends StreamResponseObject { 158 | @NotNull 159 | @JsonProperty("devices") 160 | private List devices; 161 | } 162 | 163 | /** 164 | * Creates a create request 165 | * 166 | * @return the created request 167 | */ 168 | @NotNull 169 | public static DeviceCreateRequest create() { 170 | return new DeviceCreateRequest(); 171 | } 172 | 173 | /** 174 | * Creates a delete request 175 | * 176 | * @param id the device id 177 | * @param userId the user id 178 | * @return the created request 179 | */ 180 | @NotNull 181 | public static DeviceDeleteRequest delete(@NotNull String id, @NotNull String userId) { 182 | return new DeviceDeleteRequest(id, userId); 183 | } 184 | 185 | /** 186 | * Creates a list request 187 | * 188 | * @param userId the user id 189 | * @return the created request 190 | */ 191 | @NotNull 192 | public static DeviceListRequest list(@NotNull String userId) { 193 | return new DeviceListRequest(userId); 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/ExportUsers.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import io.getstream.chat.java.models.framework.StreamRequest; 5 | import io.getstream.chat.java.models.framework.StreamResponseObject; 6 | import io.getstream.chat.java.services.ExportUsersService; 7 | import io.getstream.chat.java.services.framework.Client; 8 | import java.util.List; 9 | import lombok.Builder; 10 | import lombok.Data; 11 | import lombok.EqualsAndHashCode; 12 | import lombok.NoArgsConstructor; 13 | import org.jetbrains.annotations.NotNull; 14 | import retrofit2.Call; 15 | 16 | @Data 17 | @NoArgsConstructor 18 | public class ExportUsers { 19 | 20 | @Builder( 21 | builderClassName = "ExportUsersRequest", 22 | builderMethodName = "", 23 | buildMethodName = "internalBuild") 24 | public static class ExportUsersRequestData { 25 | @JsonProperty("user_ids") 26 | private List userIds; 27 | 28 | public static class ExportUsersRequest extends StreamRequest { 29 | @Override 30 | protected Call generateCall(Client client) { 31 | return client.create(ExportUsersService.class).exportUsers(this.internalBuild()); 32 | } 33 | } 34 | } 35 | 36 | @Data 37 | @NoArgsConstructor 38 | @EqualsAndHashCode(callSuper = true) 39 | public static class ExportUsersResponse extends StreamResponseObject { 40 | @NotNull 41 | @JsonProperty("task_id") 42 | private String taskId; 43 | } 44 | 45 | /** 46 | * Creates a export users request 47 | * 48 | * @param userIds list of user IDs to be exported 49 | * @return the created request 50 | */ 51 | @NotNull 52 | public static ExportUsers.ExportUsersRequestData.ExportUsersRequest exportUsers( 53 | @NotNull List userIds) { 54 | return new ExportUsers.ExportUsersRequestData.ExportUsersRequest().userIds(userIds); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/FilterCondition.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collection; 5 | import java.util.Collections; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | public class FilterCondition { 11 | @SafeVarargs 12 | public static Map and(@NotNull Map... filters) { 13 | return Collections.singletonMap("$and", Arrays.asList(filters)); 14 | } 15 | 16 | @SafeVarargs 17 | public static Map or(@NotNull Map... filters) { 18 | return Collections.singletonMap("$or", Arrays.asList(filters)); 19 | } 20 | 21 | @SafeVarargs 22 | public static Map nor(@NotNull Map... filters) { 23 | return Collections.singletonMap("$nor", Arrays.asList(filters)); 24 | } 25 | 26 | public static Map autocomplete( 27 | @NotNull String fieldName, @NotNull String inputString) { 28 | return Collections.singletonMap( 29 | fieldName, Collections.singletonMap("$autocomplete", inputString)); 30 | } 31 | 32 | public static Map contains( 33 | @NotNull String fieldName, @NotNull String inputString) { 34 | return Collections.singletonMap(fieldName, Collections.singletonMap("$contains", inputString)); 35 | } 36 | 37 | public static Map eq(@NotNull String fieldName, @NotNull Object fieldValue) { 38 | return Collections.singletonMap(fieldName, Collections.singletonMap("$eq", fieldValue)); 39 | } 40 | 41 | public static Map greaterThan( 42 | @NotNull String fieldName, @NotNull Object fieldValue) { 43 | return Collections.singletonMap(fieldName, Collections.singletonMap("$gt", fieldValue)); 44 | } 45 | 46 | public static Map greaterThanEquals( 47 | @NotNull String fieldName, @NotNull Object fieldValue) { 48 | return Collections.singletonMap(fieldName, Collections.singletonMap("$gte", fieldValue)); 49 | } 50 | 51 | public static Map lessThan( 52 | @NotNull String fieldName, @NotNull Object fieldValue) { 53 | return Collections.singletonMap(fieldName, Collections.singletonMap("$lt", fieldValue)); 54 | } 55 | 56 | public static Map lessThanEquals( 57 | @NotNull String fieldName, @NotNull Object fieldValue) { 58 | return Collections.singletonMap(fieldName, Collections.singletonMap("$lte", fieldValue)); 59 | } 60 | 61 | public static Map ne(@NotNull String fieldName, @NotNull Object fieldValue) { 62 | return Collections.singletonMap(fieldName, Collections.singletonMap("$ne", fieldValue)); 63 | } 64 | 65 | public static Map in( 66 | @NotNull String fieldName, @NotNull Collection fieldValues) { 67 | return Collections.singletonMap(fieldName, Collections.singletonMap("$in", fieldValues)); 68 | } 69 | 70 | public static Map in(@NotNull String fieldName, @NotNull Object... fieldValues) { 71 | return in(fieldName, Arrays.asList(fieldValues)); 72 | } 73 | 74 | public static Map nin( 75 | @NotNull String fieldName, @NotNull Collection fieldValues) { 76 | return Collections.singletonMap(fieldName, Collections.singletonMap("$nin", fieldValues)); 77 | } 78 | 79 | public static Map nin(@NotNull String fieldName, @NotNull Object... fieldValues) { 80 | return nin(fieldName, Arrays.asList(fieldValues)); 81 | } 82 | 83 | public static Map exists() { 84 | return Collections.singletonMap("$exists", true); 85 | } 86 | 87 | public static Map notExists(@NotNull String fieldName) { 88 | return Collections.singletonMap(fieldName, Collections.singletonMap("$exists", false)); 89 | } 90 | 91 | public static Map distinct( 92 | @NotNull String fieldName, @NotNull Collection memberIds) { 93 | Map map = new HashMap<>(); 94 | map.put("$distinct", true); 95 | map.put("$members", memberIds); 96 | return Collections.singletonMap(fieldName, map); 97 | } 98 | 99 | public static Map distinct( 100 | @NotNull String fieldName, @NotNull String... memberIds) { 101 | return distinct(fieldName, memberIds); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/Import.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import io.getstream.chat.java.models.framework.StreamRequest; 6 | import io.getstream.chat.java.models.framework.StreamResponseObject; 7 | import io.getstream.chat.java.services.ImportService; 8 | import io.getstream.chat.java.services.framework.Client; 9 | import java.util.Date; 10 | import java.util.List; 11 | import lombok.Builder; 12 | import lombok.Data; 13 | import lombok.EqualsAndHashCode; 14 | import lombok.NoArgsConstructor; 15 | import org.jetbrains.annotations.NotNull; 16 | import org.jetbrains.annotations.Nullable; 17 | import retrofit2.Call; 18 | 19 | @Data 20 | @NoArgsConstructor 21 | public class Import { 22 | @Nullable 23 | @JsonProperty("id") 24 | private String id; 25 | 26 | @Nullable 27 | @JsonProperty("path") 28 | private String path; 29 | 30 | @Nullable 31 | @JsonProperty("mode") 32 | private ImportMode mode; 33 | 34 | @Nullable 35 | @JsonProperty("state") 36 | private ImportState state; 37 | 38 | @Nullable 39 | @JsonProperty("history") 40 | private List history; 41 | 42 | @Nullable 43 | @JsonProperty("created_at") 44 | private Date createdAt; 45 | 46 | @Nullable 47 | @JsonProperty("updated_at") 48 | private Date updatedAt; 49 | 50 | public enum ImportMode { 51 | @JsonProperty("upsert") 52 | Upsert, 53 | @JsonProperty("insert") 54 | Insert, 55 | @JsonEnumDefaultValue 56 | UNKNOWN 57 | } 58 | 59 | public enum ImportState { 60 | @JsonProperty("uploaded") 61 | Uploaded, 62 | @JsonProperty("analyzing") 63 | Analyzing, 64 | @JsonProperty("analyzing_failed") 65 | AnalyzingFailed, 66 | @JsonProperty("waiting_for_confirmation") 67 | WaitingForConfirmation, 68 | @JsonProperty("importing") 69 | Importing, 70 | @JsonProperty("importing_failed") 71 | ImportingFailed, 72 | @JsonProperty("completed") 73 | Completed, 74 | @JsonProperty("failed") 75 | Failed, 76 | @JsonEnumDefaultValue 77 | UNKNOWN 78 | } 79 | 80 | @Builder( 81 | builderClassName = "CreateImportUrlRequest", 82 | builderMethodName = "", 83 | buildMethodName = "internalBuild") 84 | public static class CreateImportUrlRequestData { 85 | @Nullable 86 | @JsonProperty("filename") 87 | private String fileName; 88 | 89 | public static class CreateImportUrlRequest 90 | extends StreamRequest { 91 | @Override 92 | protected Call generateCall(Client client) { 93 | return client.create(ImportService.class).createImportUrl(this.internalBuild()); 94 | } 95 | } 96 | } 97 | 98 | @Data 99 | @NoArgsConstructor 100 | @EqualsAndHashCode(callSuper = true) 101 | public static class CreateImportUrlResponse extends StreamResponseObject { 102 | @NotNull 103 | @JsonProperty("upload_url") 104 | private String uploadUrl; 105 | 106 | @NotNull 107 | @JsonProperty("path") 108 | private String path; 109 | } 110 | 111 | @Builder( 112 | builderClassName = "CreateImportRequest", 113 | builderMethodName = "", 114 | buildMethodName = "internalBuild") 115 | public static class CreateImportRequestData { 116 | @NotNull 117 | @JsonProperty("path") 118 | private String path; 119 | 120 | @NotNull 121 | @JsonProperty("mode") 122 | private ImportMode mode; 123 | 124 | public static class CreateImportRequest extends StreamRequest { 125 | @Override 126 | protected Call generateCall(Client client) { 127 | return client.create(ImportService.class).createImport(this.internalBuild()); 128 | } 129 | } 130 | } 131 | 132 | @Data 133 | @NoArgsConstructor 134 | @EqualsAndHashCode(callSuper = true) 135 | public static class CreateImportResponse extends StreamResponseObject { 136 | @NotNull 137 | @JsonProperty("import_task") 138 | private Import importTask; 139 | } 140 | 141 | public static class GetImportRequest extends StreamRequest { 142 | private final String id; 143 | 144 | public GetImportRequest(String id) { 145 | this.id = id; 146 | } 147 | 148 | @Override 149 | protected Call generateCall(Client client) { 150 | return client.create(ImportService.class).getImport(this.id); 151 | } 152 | } 153 | 154 | public static class ListImportsRequest extends StreamRequest { 155 | private final Integer limit; 156 | private final Integer offset; 157 | 158 | public ListImportsRequest(Integer limit, Integer offset) { 159 | this.limit = limit; 160 | this.offset = offset; 161 | } 162 | 163 | @Override 164 | protected Call generateCall(Client client) { 165 | return client.create(ImportService.class).listImports(this.limit, this.offset); 166 | } 167 | } 168 | 169 | public static class GetImportResponse extends CreateImportResponse {} 170 | 171 | @Data 172 | @NoArgsConstructor 173 | @EqualsAndHashCode(callSuper = true) 174 | public static class ListImportsResponse extends StreamResponseObject { 175 | @NotNull 176 | @JsonProperty("import_tasks") 177 | private List importTasks; 178 | } 179 | 180 | @Data 181 | @NoArgsConstructor 182 | public static class ImportHistoryItem { 183 | @NotNull 184 | @JsonProperty("created_at") 185 | private Date createdAt; 186 | 187 | @NotNull 188 | @JsonProperty("prev_state") 189 | private String prevState; 190 | 191 | @NotNull 192 | @JsonProperty("next_state") 193 | private String nextState; 194 | } 195 | 196 | /** 197 | * Creates a create import url request 198 | * 199 | * @param fileName the name of the file to be imported 200 | * @return the created request 201 | */ 202 | @NotNull 203 | public static CreateImportUrlRequestData.CreateImportUrlRequest createImportUrl( 204 | @NotNull String fileName) { 205 | return new CreateImportUrlRequestData.CreateImportUrlRequest().fileName(fileName); 206 | } 207 | 208 | /** 209 | * Creates a create import request 210 | * 211 | * @param path the path returned by createImportUrl endpoint 212 | * @param mode the import mode 213 | * @return the created request 214 | */ 215 | @NotNull 216 | public static CreateImportRequestData.CreateImportRequest createImport( 217 | @NotNull String path, @Nullable ImportMode mode) { 218 | return new CreateImportRequestData.CreateImportRequest().path(path).mode(mode); 219 | } 220 | 221 | /** 222 | * Creates a get import request 223 | * 224 | * @param id the id of the import 225 | * @return the created request 226 | */ 227 | @NotNull 228 | public static GetImportRequest getImport(@NotNull String id) { 229 | return new GetImportRequest(id); 230 | } 231 | 232 | /** 233 | * Creates a list import request 234 | * 235 | * @param limit how many records to return 236 | * @param offset how many records to skip during pagination 237 | * @return the created request 238 | */ 239 | @NotNull 240 | public static ListImportsRequest listImports(@Nullable Integer limit, @Nullable Integer offset) { 241 | return new ListImportsRequest(limit, offset); 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/Language.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | 6 | public enum Language { 7 | @JsonProperty("af") 8 | AF, 9 | @JsonProperty("am") 10 | AM, 11 | @JsonProperty("ar") 12 | AR, 13 | @JsonProperty("az") 14 | AZ, 15 | @JsonProperty("bg") 16 | BG, 17 | @JsonProperty("bn") 18 | BN, 19 | @JsonProperty("bs") 20 | BS, 21 | @JsonProperty("cs") 22 | CS, 23 | @JsonProperty("da") 24 | DA, 25 | @JsonProperty("de") 26 | DE, 27 | @JsonProperty("el") 28 | EL, 29 | @JsonProperty("en") 30 | EN, 31 | @JsonProperty("es") 32 | ES, 33 | @JsonProperty("es-MX") 34 | ES_MX, 35 | @JsonProperty("et") 36 | ET, 37 | @JsonProperty("fa") 38 | FA, 39 | @JsonProperty("fa-AF") 40 | FA_AF, 41 | @JsonProperty("fi") 42 | FI, 43 | @JsonProperty("fr") 44 | FR, 45 | @JsonProperty("fr-CA") 46 | FR_CA, 47 | @JsonProperty("ha") 48 | HA, 49 | @JsonProperty("he") 50 | HE, 51 | @JsonProperty("hi") 52 | HI, 53 | @JsonProperty("hr") 54 | HR, 55 | @JsonProperty("hu") 56 | HU, 57 | @JsonProperty("id") 58 | ID, 59 | @JsonProperty("it") 60 | IT, 61 | @JsonProperty("ja") 62 | JA, 63 | @JsonProperty("ka") 64 | KA, 65 | @JsonProperty("ko") 66 | KO, 67 | @JsonProperty("lt") 68 | LT, 69 | @JsonProperty("lv") 70 | LV, 71 | @JsonProperty("ms") 72 | MS, 73 | @JsonProperty("nl") 74 | NL, 75 | @JsonProperty("no") 76 | NO, 77 | @JsonProperty("pl") 78 | PL, 79 | @JsonProperty("ps") 80 | PS, 81 | @JsonProperty("pt") 82 | PT, 83 | @JsonProperty("ro") 84 | RO, 85 | @JsonProperty("ru") 86 | RU, 87 | @JsonProperty("sk") 88 | SK, 89 | @JsonProperty("sl") 90 | SL, 91 | @JsonProperty("so") 92 | SO, 93 | @JsonProperty("sq") 94 | SQ, 95 | @JsonProperty("sr") 96 | SR, 97 | @JsonProperty("sv") 98 | SV, 99 | @JsonProperty("sw") 100 | SW, 101 | @JsonProperty("ta") 102 | TA, 103 | @JsonProperty("th") 104 | TH, 105 | @JsonProperty("tl") 106 | TL, 107 | @JsonProperty("tr") 108 | TR, 109 | @JsonProperty("uk") 110 | UK, 111 | @JsonProperty("ur") 112 | UR, 113 | @JsonProperty("vi") 114 | VI, 115 | @JsonProperty("zh") 116 | ZH, 117 | @JsonProperty("zh-TW") 118 | ZH_TW, 119 | @JsonEnumDefaultValue 120 | UNKNOWN 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/LanguageDeserializer.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.core.JsonParser; 5 | import com.fasterxml.jackson.core.JsonProcessingException; 6 | import com.fasterxml.jackson.databind.DeserializationContext; 7 | import com.fasterxml.jackson.databind.JsonDeserializer; 8 | import java.io.IOException; 9 | 10 | public class LanguageDeserializer extends JsonDeserializer { 11 | @Override 12 | public Language deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) 13 | throws IOException, JsonProcessingException { 14 | String jsonString = jsonParser.readValueAs(String.class); 15 | if (jsonString == null || jsonString.equals("")) { 16 | return null; 17 | } 18 | for (Language enumValue : Language.values()) { 19 | if (enumValue == Language.UNKNOWN) { 20 | continue; 21 | } 22 | try { 23 | if (jsonString.equals( 24 | Language.class.getField(enumValue.name()).getAnnotation(JsonProperty.class).value())) { 25 | return enumValue; 26 | } 27 | } catch (NoSuchFieldException e) { 28 | return null; 29 | } catch (SecurityException e) { 30 | throw deserializationContext.instantiationException(Language.class, "Should not happen"); 31 | } 32 | } 33 | return Language.UNKNOWN; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/MessageHistory.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonAnyGetter; 4 | import com.fasterxml.jackson.annotation.JsonAnySetter; 5 | import com.fasterxml.jackson.annotation.JsonIgnore; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | import io.getstream.chat.java.models.Message.Attachment; 8 | import io.getstream.chat.java.models.MessageHistory.MessageHistoryQueryRequestData.MessageHistoryQueryRequest; 9 | import io.getstream.chat.java.models.framework.StreamRequest; 10 | import io.getstream.chat.java.models.framework.StreamResponseObject; 11 | import io.getstream.chat.java.services.MessageHistoryService; 12 | import io.getstream.chat.java.services.framework.Client; 13 | import java.util.*; 14 | import lombok.*; 15 | import org.jetbrains.annotations.NotNull; 16 | import org.jetbrains.annotations.Nullable; 17 | import retrofit2.Call; 18 | 19 | @Data 20 | @NoArgsConstructor 21 | public class MessageHistory { 22 | @Builder( 23 | builderClassName = "MessageHistoryQueryRequest", 24 | builderMethodName = "", 25 | buildMethodName = "internalBuild") 26 | public static class MessageHistoryQueryRequestData { 27 | @Nullable 28 | @JsonProperty("filter") 29 | private Map filter; 30 | 31 | @Singular 32 | @Nullable 33 | @JsonProperty("sort") 34 | private List sorts; 35 | 36 | @Nullable 37 | @JsonProperty("limit") 38 | private Integer limit; 39 | 40 | @Nullable 41 | @JsonProperty("next") 42 | private String next; 43 | 44 | @Nullable 45 | @JsonProperty("prev") 46 | private String prev; 47 | 48 | public static class MessageHistoryQueryRequest 49 | extends StreamRequest { 50 | @Override 51 | protected Call generateCall(Client client) { 52 | var data = this.internalBuild(); 53 | return client.create(MessageHistoryService.class).query(data); 54 | } 55 | } 56 | } 57 | 58 | /** 59 | * Creates a query request 60 | * 61 | * @return the created request 62 | */ 63 | @NotNull 64 | public static MessageHistoryQueryRequest query() { 65 | return new MessageHistoryQueryRequest(); 66 | } 67 | 68 | @Data 69 | @NoArgsConstructor 70 | public static class MessageHistoryEntry { 71 | @NotNull 72 | @JsonProperty("message_id") 73 | private String messageId; 74 | 75 | @NotNull 76 | @JsonProperty("message_updated_at") 77 | private Date messageUpdatedAt; 78 | 79 | @Nullable 80 | @JsonProperty("attachments") 81 | private List attachments; 82 | 83 | @NotNull 84 | @JsonProperty("message_updated_by_id") 85 | private String messageUpdatedById; 86 | 87 | @Nullable 88 | @JsonProperty("text") 89 | private String text; 90 | 91 | @NotNull @JsonIgnore private Map additionalFields = new HashMap<>(); 92 | 93 | @JsonAnyGetter 94 | public Map getAdditionalFields() { 95 | return this.additionalFields; 96 | } 97 | 98 | @JsonAnySetter 99 | public void setAdditionalField(String name, Object value) { 100 | this.additionalFields.put(name, value); 101 | } 102 | } 103 | 104 | @Data 105 | @NoArgsConstructor 106 | @EqualsAndHashCode(callSuper = true) 107 | public static class MessageHistoryQueryResponse extends StreamResponseObject { 108 | @NotNull 109 | @JsonProperty("message_history") 110 | private List messageHistory; 111 | 112 | @NotNull 113 | @JsonProperty("next") 114 | private String next; 115 | 116 | @NotNull 117 | @JsonProperty("prev") 118 | private String prev; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/MessagePaginationParameters.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import java.util.Date; 5 | import lombok.Builder; 6 | import org.jetbrains.annotations.Nullable; 7 | 8 | @Builder 9 | public class MessagePaginationParameters { 10 | @Nullable 11 | @JsonProperty("limit") 12 | private Integer limit; 13 | 14 | @Nullable 15 | @JsonProperty("offset") 16 | private Integer offset; 17 | 18 | @Nullable 19 | @JsonProperty("id_gte") 20 | private String idGte; 21 | 22 | @Nullable 23 | @JsonProperty("id_gt") 24 | private String idGt; 25 | 26 | @Nullable 27 | @JsonProperty("id_lte") 28 | private String idLte; 29 | 30 | @Nullable 31 | @JsonProperty("id_lt") 32 | private String idLt; 33 | 34 | @Nullable 35 | @JsonProperty("created_at_after_or_equal") 36 | private Date createdAtAfterOrEqual; 37 | 38 | @Nullable 39 | @JsonProperty("created_at_after") 40 | private Date createdAtAfter; 41 | 42 | @Nullable 43 | @JsonProperty("created_at_before_or_equal") 44 | private Date createdAtBeforeOrEqual; 45 | 46 | @Nullable 47 | @JsonProperty("created_at_before") 48 | private Date createdAtBefore; 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/Moderation.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.*; 4 | import io.getstream.chat.java.models.Moderation.UpsertConfigRequestData.UpsertConfigRequest; 5 | import io.getstream.chat.java.models.framework.StreamRequest; 6 | import io.getstream.chat.java.models.framework.StreamResponseObject; 7 | import io.getstream.chat.java.services.ModerationService; 8 | import io.getstream.chat.java.services.framework.Client; 9 | import java.util.Date; 10 | import java.util.List; 11 | import lombok.*; 12 | import org.jetbrains.annotations.NotNull; 13 | import org.jetbrains.annotations.Nullable; 14 | import retrofit2.Call; 15 | 16 | @Data 17 | @NoArgsConstructor 18 | public class Moderation { 19 | 20 | @Builder( 21 | builderClassName = "ConfigGetRequest", 22 | builderMethodName = "", 23 | buildMethodName = "internalBuild") 24 | public static class ConfigGetRequestData { 25 | public static class ConfigGetRequest extends StreamRequest { 26 | @NotNull private String key; 27 | 28 | private ConfigGetRequest(@NotNull String key) { 29 | this.key = key; 30 | } 31 | 32 | @Override 33 | protected Call generateCall(Client client) { 34 | return client.create(ModerationService.class).getConfig(this.key); 35 | } 36 | } 37 | } 38 | 39 | @Data 40 | @NoArgsConstructor 41 | @EqualsAndHashCode(callSuper = true) 42 | public static class ConfigGetResponse extends StreamResponseObject { 43 | @Nullable 44 | @JsonProperty("config") 45 | private Config config; 46 | } 47 | 48 | @Data 49 | @NoArgsConstructor 50 | public static class Config { 51 | @Nullable 52 | @JsonProperty("key") 53 | private String key; 54 | 55 | @Nullable 56 | @JsonProperty("async") 57 | private Boolean async; 58 | 59 | @Nullable 60 | @JsonProperty("block_list_config") 61 | private BlockListConfig blockListConfig; 62 | 63 | @Nullable 64 | @JsonProperty("created_at") 65 | private Date createdAt; 66 | 67 | @Nullable 68 | @JsonProperty("updated_at") 69 | private Date updatedAt; 70 | } 71 | 72 | @Data 73 | @NoArgsConstructor 74 | public static class BlockListConfig { 75 | @Nullable 76 | @JsonProperty("async") 77 | private Boolean async; 78 | 79 | @NotNull 80 | @JsonProperty("enabled") 81 | private Boolean enabled; 82 | 83 | @NotNull 84 | @JsonProperty("rules") 85 | private List rules; 86 | } 87 | 88 | public enum Action { 89 | @JsonProperty("flag") 90 | FLAG, 91 | @JsonProperty("shadow") 92 | SHADOW, 93 | @JsonProperty("remove") 94 | REMOVE, 95 | @JsonProperty("bounce") 96 | BOUNCE, 97 | @JsonProperty("bounce_flag") 98 | BOUNCE_FLAG, 99 | @JsonProperty("bounce_remove") 100 | BOUNCE_REMOVE, 101 | @JsonEnumDefaultValue 102 | UNKNOWN 103 | } 104 | 105 | @Data 106 | @NoArgsConstructor 107 | @Builder 108 | @AllArgsConstructor 109 | public static class BlockListRule { 110 | @NotNull 111 | @JsonProperty("name") 112 | private String name; 113 | 114 | @NotNull 115 | @JsonProperty("action") 116 | private Action action; 117 | } 118 | 119 | @Builder 120 | public static class BlockListConfigRequestObject { 121 | @Nullable 122 | @JsonProperty("async") 123 | private Boolean async; 124 | 125 | @NotNull 126 | @JsonProperty("rules") 127 | private List rules; 128 | } 129 | 130 | @Builder( 131 | builderClassName = "UpsertConfigRequest", 132 | builderMethodName = "", 133 | buildMethodName = "internalBuild") 134 | public static class UpsertConfigRequestData { 135 | @Nullable 136 | @JsonProperty("key") 137 | private String key; 138 | 139 | @Nullable 140 | @JsonProperty("async") 141 | private Boolean async; 142 | 143 | @Nullable 144 | @JsonProperty("block_list_config") 145 | private BlockListConfigRequestObject blockListConfig; 146 | 147 | public static class UpsertConfigRequest extends StreamRequest { 148 | @NotNull private String key; 149 | 150 | private UpsertConfigRequest(@NotNull String key) { 151 | this.key = key; 152 | } 153 | 154 | @Override 155 | protected Call generateCall(Client client) { 156 | return client 157 | .create(ModerationService.class) 158 | .upsertConfig(this.key(this.key).internalBuild()); 159 | } 160 | } 161 | } 162 | 163 | @Data 164 | @NoArgsConstructor 165 | @EqualsAndHashCode(callSuper = true) 166 | public static class UpsertConfigResponse extends StreamResponseObject { 167 | @Nullable 168 | @JsonProperty("config") 169 | private Config config; 170 | } 171 | 172 | @RequiredArgsConstructor 173 | public static class DeleteConfigRequest extends StreamRequest { 174 | @NotNull private String key; 175 | 176 | @Override 177 | protected Call generateCall(Client client) { 178 | return client.create(ModerationService.class).deleteConfig(this.key); 179 | } 180 | } 181 | 182 | @RequiredArgsConstructor 183 | public static class ConfigGetRequest extends StreamRequest { 184 | @NotNull private String key; 185 | 186 | @Override 187 | protected Call generateCall(Client client) { 188 | return client.create(ModerationService.class).getConfig(this.key); 189 | } 190 | } 191 | 192 | /** 193 | * Creates an upsert config request 194 | * 195 | * @param key the moderation config key 196 | * @return the created request 197 | */ 198 | @NotNull 199 | public static UpsertConfigRequest upsertConfig(@NotNull String key) { 200 | return new UpsertConfigRequest(key); 201 | } 202 | 203 | /** 204 | * Creates a delete config request 205 | * 206 | * @param key the moderation config key 207 | * @return the created request 208 | */ 209 | @NotNull 210 | public static DeleteConfigRequest deleteConfig(@NotNull String key) { 211 | return new DeleteConfigRequest(key); 212 | } 213 | 214 | /* 215 | * Creates a get config request 216 | * 217 | * @param key the moderation config key 218 | * @return the created request 219 | */ 220 | @NotNull 221 | public static ConfigGetRequest getConfig(@NotNull String key) { 222 | return new ConfigGetRequest(key); 223 | } 224 | } 225 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/PaginationParameters.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.Builder; 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | @Builder 8 | public class PaginationParameters { 9 | @Nullable 10 | @JsonProperty("limit") 11 | private Integer limit; 12 | 13 | @Nullable 14 | @JsonProperty("offset") 15 | private Integer offset; 16 | 17 | @Nullable 18 | @JsonProperty("id_gte") 19 | private String idGte; 20 | 21 | @Nullable 22 | @JsonProperty("id_gt") 23 | private String idGt; 24 | 25 | @Nullable 26 | @JsonProperty("id_lte") 27 | private String idLte; 28 | 29 | @Nullable 30 | @JsonProperty("id_lt") 31 | private String idLt; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/Permission.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import io.getstream.chat.java.models.Permission.PermissionCreateRequestData.PermissionCreateRequest; 5 | import io.getstream.chat.java.models.Permission.PermissionUpdateRequestData.PermissionUpdateRequest; 6 | import io.getstream.chat.java.models.framework.StreamRequest; 7 | import io.getstream.chat.java.models.framework.StreamResponseObject; 8 | import io.getstream.chat.java.services.PermissionService; 9 | import io.getstream.chat.java.services.framework.Client; 10 | import java.util.List; 11 | import java.util.Map; 12 | import lombok.*; 13 | import org.jetbrains.annotations.NotNull; 14 | import org.jetbrains.annotations.Nullable; 15 | import retrofit2.Call; 16 | 17 | @Data 18 | @NoArgsConstructor 19 | public class Permission { 20 | @NotNull 21 | @JsonProperty("id") 22 | private String id; 23 | 24 | @NotNull 25 | @JsonProperty("name") 26 | private String name; 27 | 28 | @NotNull 29 | @JsonProperty("action") 30 | private String action; 31 | 32 | @Nullable 33 | @JsonProperty("owner") 34 | private Boolean owner; 35 | 36 | @Nullable 37 | @JsonProperty("same_team") 38 | private Boolean sameTeam; 39 | 40 | @NotNull 41 | @JsonProperty("custom") 42 | private Boolean custom; 43 | 44 | @Nullable 45 | @JsonProperty("condition") 46 | private Condition condition; 47 | 48 | @Data 49 | @NoArgsConstructor 50 | public static class Condition { 51 | @NotNull private String expression; 52 | } 53 | 54 | @Builder( 55 | builderClassName = "PermissionCreateRequest", 56 | builderMethodName = "", 57 | buildMethodName = "internalBuild") 58 | public static class PermissionCreateRequestData { 59 | @NotNull 60 | @JsonProperty("id") 61 | private String id; 62 | 63 | @NotNull 64 | @JsonProperty("name") 65 | private String name; 66 | 67 | @NotNull 68 | @JsonProperty("action") 69 | private String action; 70 | 71 | @Nullable 72 | @JsonProperty("owner") 73 | private Boolean owner; 74 | 75 | @Nullable 76 | @JsonProperty("same_team") 77 | private Boolean sameTeam; 78 | 79 | @Nullable 80 | @JsonProperty("condition") 81 | private Map condition; 82 | 83 | public static class PermissionCreateRequest extends StreamRequest { 84 | @Override 85 | protected Call generateCall(Client client) { 86 | return client.create(PermissionService.class).create(this.internalBuild()); 87 | } 88 | } 89 | } 90 | 91 | @RequiredArgsConstructor 92 | public static class PermissionGetRequest extends StreamRequest { 93 | @NotNull private String id; 94 | 95 | @Override 96 | protected Call generateCall(Client client) { 97 | return client.create(PermissionService.class).get(id); 98 | } 99 | } 100 | 101 | @Builder( 102 | builderClassName = "PermissionUpdateRequest", 103 | builderMethodName = "", 104 | buildMethodName = "internalBuild") 105 | public static class PermissionUpdateRequestData { 106 | @Nullable 107 | @JsonProperty("id") 108 | private String id; 109 | 110 | @Nullable 111 | @JsonProperty("name") 112 | private String name; 113 | 114 | @Nullable 115 | @JsonProperty("action") 116 | private String action; 117 | 118 | @Nullable 119 | @JsonProperty("owner") 120 | private Boolean owner; 121 | 122 | @Nullable 123 | @JsonProperty("same_team") 124 | private Boolean sameTeam; 125 | 126 | @Nullable 127 | @JsonProperty("condition") 128 | private Map condition; 129 | 130 | public static class PermissionUpdateRequest extends StreamRequest { 131 | private PermissionUpdateRequest(@NotNull String id, @NotNull String name) { 132 | this.id = id; 133 | this.name = name; 134 | } 135 | 136 | @SuppressWarnings("unused") 137 | private PermissionUpdateRequest name(@NotNull String name) { 138 | throw new IllegalStateException("Should not use as it is only to hide builder method"); 139 | } 140 | 141 | @Override 142 | protected Call generateCall(Client client) { 143 | return client.create(PermissionService.class).update(id, this.internalBuild()); 144 | } 145 | } 146 | } 147 | 148 | @RequiredArgsConstructor 149 | public static class PermissionDeleteRequest extends StreamRequest { 150 | @NotNull private String id; 151 | 152 | @Override 153 | protected Call generateCall(Client client) { 154 | return client.create(PermissionService.class).delete(id); 155 | } 156 | } 157 | 158 | public static class PermissionListRequest extends StreamRequest { 159 | @Override 160 | protected Call generateCall(Client client) { 161 | return client.create(PermissionService.class).list(); 162 | } 163 | } 164 | 165 | @Data 166 | @NoArgsConstructor 167 | @EqualsAndHashCode(callSuper = true) 168 | public static class PermissionGetResponse extends StreamResponseObject { 169 | @NotNull 170 | @JsonProperty("permission") 171 | private Permission permission; 172 | } 173 | 174 | @Data 175 | @NoArgsConstructor 176 | @EqualsAndHashCode(callSuper = true) 177 | public static class PermissionListResponse extends StreamResponseObject { 178 | @NotNull 179 | @JsonProperty("permissions") 180 | private List permissions; 181 | } 182 | 183 | /** 184 | * Creates a create request 185 | * 186 | * @return the created request 187 | */ 188 | @NotNull 189 | public static PermissionCreateRequest create() { 190 | return new PermissionCreateRequest(); 191 | } 192 | 193 | /** 194 | * Creates a get request 195 | * 196 | * @param id the permission id 197 | * @return the created request 198 | */ 199 | @NotNull 200 | public static PermissionGetRequest get(@NotNull String id) { 201 | return new PermissionGetRequest(id); 202 | } 203 | 204 | /** 205 | * Creates an update request 206 | * 207 | * @param id the permission id 208 | * @param name the permission name 209 | * @return the created request 210 | */ 211 | @NotNull 212 | public static PermissionUpdateRequest update(@NotNull String id, @NotNull String name) { 213 | return new PermissionUpdateRequest(id, name); 214 | } 215 | 216 | /** 217 | * Creates a delete request 218 | * 219 | * @param id the permission id 220 | * @return the created request 221 | */ 222 | @NotNull 223 | public static PermissionDeleteRequest delete(@NotNull String id) { 224 | return new PermissionDeleteRequest(id); 225 | } 226 | 227 | /** 228 | * Creates a list request 229 | * 230 | * @return the created request 231 | */ 232 | @NotNull 233 | public static PermissionListRequest list() { 234 | return new PermissionListRequest(); 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/RateLimit.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.core.JsonParser; 5 | import com.fasterxml.jackson.core.JsonProcessingException; 6 | import com.fasterxml.jackson.databind.DeserializationContext; 7 | import com.fasterxml.jackson.databind.JsonDeserializer; 8 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 9 | import java.io.IOException; 10 | import java.util.Date; 11 | import lombok.Data; 12 | import lombok.NoArgsConstructor; 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | @Data 16 | @NoArgsConstructor 17 | public class RateLimit { 18 | @NotNull 19 | @JsonProperty("limit") 20 | private Integer limit; 21 | 22 | @NotNull 23 | @JsonProperty("remaining") 24 | private Integer remaining; 25 | 26 | @NotNull 27 | @JsonProperty("reset") 28 | @JsonDeserialize(using = UnixTimestampDeserializer.class) 29 | private Date reset; 30 | 31 | public static class UnixTimestampDeserializer extends JsonDeserializer { 32 | @Override 33 | public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) 34 | throws IOException, JsonProcessingException { 35 | String jsonString = jsonParser.readValueAs(String.class); 36 | try { 37 | return new Date(Long.parseLong(jsonString) * 1000); 38 | } catch (NumberFormatException e) { 39 | throw deserializationContext.instantiationException( 40 | Date.class, "Unparseable date for unix timestamp: " + jsonString); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/ResourceAction.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | public class ResourceAction { 4 | public static final String ALL = "*"; 5 | public static final String CREATE_CHANNEL = "CreateChannel"; 6 | public static final String CREATE_DISTINCT_CHANNEL_FOR_OTHERS = "CreateDistinctChannelsForOthers"; 7 | public static final String READ_CHANNEL = "ReadChannel"; 8 | public static final String UPDATE_CHANNEL_MEMBERS = "UpdateChannelMembers"; 9 | public static final String REMOVE_OWN_CHANNEL_MEMBERSHIP = "RemoveOwnChannelMembership"; 10 | public static final String UPDATE_CHANNEL = "UpdateChannel"; 11 | public static final String DELETE_CHANNEL = "DeleteChannel"; 12 | public static final String CREATE_MESSAGE = "CreateMessage"; 13 | public static final String UPDATE_MESSAGE = "UpdateMessage"; 14 | public static final String PIN_MESSAGE = "PinMessage"; 15 | public static final String DELETE_MESSAGE = "DeleteMessage"; 16 | public static final String RUN_MESSAGE_ACTION = "RunMessageAction"; 17 | public static final String UPLOAD_ATTACHMENT = "UploadAttachment"; 18 | public static final String DELETE_ATTACHMENT = "DeleteAttachment"; 19 | public static final String ADD_LINKS = "AddLinks"; 20 | public static final String CREATE_REACTION = "CreateReaction"; 21 | public static final String DELETE_REACTION = "DeleteReaction"; 22 | public static final String USE_FROZEN_CHANNEL = "UseFrozenChannel"; 23 | public static final String SEND_CUSTOM_EVENT = "SendCustomEvent"; 24 | public static final String SKIP_MESSAGE_MODERATION = "SkipMessageModeration"; 25 | public static final String READ_MESSAGE_FLAGS = "ReadMessageFlags"; 26 | public static final String UPDATE_CHANNEL_FROZEN = "UpdateChannelFrozen"; 27 | public static final String UPDATE_CHANNEL_COOLDOWN = "UpdateChannelCooldown"; 28 | public static final String SKIP_CHANNEL_COOLDOWN = "SkipChannelCooldown"; 29 | public static final String TRUNCATE_CHANNEL = "TruncateChannel"; 30 | public static final String FLAG_MESSAGE = "FlagMessage"; 31 | public static final String MUTE_CHANNEL = "MuteChannel"; 32 | public static final String BAN_USER = "BanUser"; 33 | public static final String UPDATE_USER = "UpdateUser"; 34 | public static final String UPDATE_USER_ROLE = "UpdateUserRole"; 35 | public static final String UPDATE_USER_TEAMS = "UpdateUserTeams"; 36 | public static final String SEARCH_USER = "SearchUser"; 37 | public static final String FLAG_USER = "FlagUser"; 38 | public static final String MUTE_USER = "MuteUser"; 39 | 40 | private ResourceAction() {} 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/Role.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import io.getstream.chat.java.models.Role.RoleCreateRequestData.RoleCreateRequest; 5 | import io.getstream.chat.java.models.framework.StreamRequest; 6 | import io.getstream.chat.java.models.framework.StreamResponseObject; 7 | import io.getstream.chat.java.services.RoleService; 8 | import io.getstream.chat.java.services.framework.Client; 9 | import java.util.Date; 10 | import java.util.List; 11 | import lombok.*; 12 | import org.jetbrains.annotations.NotNull; 13 | import org.jetbrains.annotations.Nullable; 14 | import retrofit2.Call; 15 | 16 | @Data 17 | @NoArgsConstructor 18 | public class Role { 19 | @NotNull 20 | @JsonProperty("name") 21 | private String name; 22 | 23 | @NotNull 24 | @JsonProperty("custom") 25 | private Boolean custom; 26 | 27 | @NotNull 28 | @JsonProperty("created_at") 29 | private Date createdAt; 30 | 31 | @NotNull 32 | @JsonProperty("updated_at") 33 | private Date updatedAt; 34 | 35 | @Builder( 36 | builderClassName = "RoleCreateRequest", 37 | builderMethodName = "", 38 | buildMethodName = "internalBuild") 39 | public static class RoleCreateRequestData { 40 | @Nullable 41 | @JsonProperty("name") 42 | private String name; 43 | 44 | public static class RoleCreateRequest extends StreamRequest { 45 | @Override 46 | protected Call generateCall(Client client) { 47 | return client.create(RoleService.class).create(this.internalBuild()); 48 | } 49 | } 50 | } 51 | 52 | @RequiredArgsConstructor 53 | public static class RoleDeleteRequest extends StreamRequest { 54 | @NotNull private String name; 55 | 56 | @Override 57 | protected Call generateCall(Client client) { 58 | return client.create(RoleService.class).delete(name); 59 | } 60 | } 61 | 62 | public static class RoleListRequest extends StreamRequest { 63 | @Override 64 | protected Call generateCall(Client client) { 65 | return client.create(RoleService.class).list(); 66 | } 67 | } 68 | 69 | @Data 70 | @NoArgsConstructor 71 | @EqualsAndHashCode(callSuper = true) 72 | public static class RoleListResponse extends StreamResponseObject { 73 | @NotNull 74 | @JsonProperty("roles") 75 | private List roles; 76 | } 77 | 78 | /** 79 | * Creates a create request 80 | * 81 | * @return the created request 82 | */ 83 | @NotNull 84 | public static RoleCreateRequest create() { 85 | return new RoleCreateRequest(); 86 | } 87 | 88 | /** 89 | * Creates a delete request 90 | * 91 | * @param name the role name 92 | * @return the created request 93 | */ 94 | @NotNull 95 | public static RoleDeleteRequest delete(@NotNull String name) { 96 | return new RoleDeleteRequest(name); 97 | } 98 | 99 | /** 100 | * Creates a list request 101 | * 102 | * @return the created request 103 | */ 104 | @NotNull 105 | public static RoleListRequest list() { 106 | return new RoleListRequest(); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/Sort.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import com.fasterxml.jackson.annotation.JsonValue; 6 | import lombok.Builder; 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | @Builder 10 | public class Sort { 11 | @NotNull 12 | @JsonProperty("field") 13 | private String field; 14 | 15 | @NotNull 16 | @JsonProperty("direction") 17 | private Direction direction; 18 | 19 | @JsonFormat(shape = JsonFormat.Shape.NUMBER) 20 | public enum Direction { 21 | ASC, 22 | DESC; 23 | 24 | @JsonValue 25 | public int toValue() { 26 | return this == ASC ? 1 : -1; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/TaskStatus.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import io.getstream.chat.java.exceptions.StreamException; 5 | import io.getstream.chat.java.models.framework.StreamRequest; 6 | import io.getstream.chat.java.models.framework.StreamResponseObject; 7 | import io.getstream.chat.java.services.TaskStatusService; 8 | import io.getstream.chat.java.services.framework.Client; 9 | import java.util.Date; 10 | import java.util.Map; 11 | import lombok.Data; 12 | import lombok.EqualsAndHashCode; 13 | import lombok.NoArgsConstructor; 14 | import lombok.RequiredArgsConstructor; 15 | import org.jetbrains.annotations.NotNull; 16 | import retrofit2.Call; 17 | 18 | @Data 19 | @NoArgsConstructor 20 | public class TaskStatus { 21 | public static TaskStatusGetRequest get(@NotNull String taskId) { 22 | return new TaskStatusGetRequest(taskId); 23 | } 24 | 25 | @RequiredArgsConstructor 26 | public static class TaskStatusGetRequest extends StreamRequest { 27 | @NotNull private String id; 28 | 29 | @Override 30 | protected Call generateCall(Client client) throws StreamException { 31 | return client.create(TaskStatusService.class).get(this.id); 32 | } 33 | } 34 | 35 | @Data 36 | @NoArgsConstructor 37 | @EqualsAndHashCode(callSuper = true) 38 | public static class TaskStatusGetResponse extends StreamResponseObject { 39 | @NotNull 40 | @JsonProperty("task_id") 41 | private String id; 42 | 43 | @NotNull 44 | @JsonProperty("status") 45 | private String status; 46 | 47 | @NotNull 48 | @JsonProperty("created_at") 49 | private Date createdAt; 50 | 51 | @NotNull 52 | @JsonProperty("updated_at") 53 | private Date updatedAt; 54 | 55 | @NotNull @JsonProperty private Map result; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/Thread.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.*; 4 | import io.getstream.chat.java.exceptions.StreamException; 5 | import io.getstream.chat.java.models.framework.StreamRequest; 6 | import io.getstream.chat.java.models.framework.StreamResponseObject; 7 | import io.getstream.chat.java.services.ThreadService; 8 | import io.getstream.chat.java.services.framework.Client; 9 | import java.util.Date; 10 | import java.util.List; 11 | import java.util.Map; 12 | import lombok.*; 13 | import org.jetbrains.annotations.NotNull; 14 | import org.jetbrains.annotations.Nullable; 15 | import retrofit2.Call; 16 | 17 | /** Represents thread functionality in Stream Chat. */ 18 | @Data 19 | public class Thread { 20 | /** A thread participant. */ 21 | @Data 22 | @NoArgsConstructor 23 | public static class ThreadParticipant { 24 | @Nullable 25 | @JsonProperty("app_pk") 26 | private Integer appPk; 27 | 28 | @Nullable 29 | @JsonProperty("channel_cid") 30 | private String channelCid; 31 | 32 | @Nullable 33 | @JsonProperty("last_thread_message_at") 34 | private Date lastThreadMessageAt; 35 | 36 | @Nullable 37 | @JsonProperty("thread_id") 38 | private String threadId; 39 | 40 | @Nullable 41 | @JsonProperty("user_id") 42 | private String userId; 43 | 44 | @Nullable 45 | @JsonProperty("user") 46 | private User user; 47 | 48 | @Nullable 49 | @JsonProperty("created_at") 50 | private Date createdAt; 51 | 52 | @Nullable 53 | @JsonProperty("left_thread_at") 54 | private Date leftThreadAt; 55 | 56 | @Nullable 57 | @JsonProperty("last_read_at") 58 | private Date lastReadAt; 59 | 60 | @Nullable 61 | @JsonProperty("custom") 62 | private Map custom; 63 | } 64 | 65 | /** A thread object containing thread data and metadata. */ 66 | @Data 67 | @NoArgsConstructor 68 | public static class ThreadObject { 69 | @Nullable 70 | @JsonProperty("app_pk") 71 | private Integer appPk; 72 | 73 | @NotNull 74 | @JsonProperty("channel_cid") 75 | private String channelCid; 76 | 77 | @Nullable 78 | @JsonProperty("channel") 79 | private Channel channel; 80 | 81 | @NotNull 82 | @JsonProperty("parent_message_id") 83 | private String parentMessageId; 84 | 85 | @Nullable 86 | @JsonProperty("parent_message") 87 | private Message parentMessage; 88 | 89 | @NotNull 90 | @JsonProperty("created_by_user_id") 91 | private String createdByUserId; 92 | 93 | @Nullable 94 | @JsonProperty("created_by") 95 | private User createdBy; 96 | 97 | @Nullable 98 | @JsonProperty("reply_count") 99 | private Integer replyCount; 100 | 101 | @Nullable 102 | @JsonProperty("participant_count") 103 | private Integer participantCount; 104 | 105 | @Nullable 106 | @JsonProperty("active_participant_count") 107 | private Integer activeParticipantCount; 108 | 109 | @Nullable 110 | @JsonProperty("thread_participants") 111 | private List participants; 112 | 113 | @Nullable 114 | @JsonProperty("last_message_at") 115 | private Date lastMessageAt; 116 | 117 | @NotNull 118 | @JsonProperty("created_at") 119 | private Date createdAt; 120 | 121 | @NotNull 122 | @JsonProperty("updated_at") 123 | private Date updatedAt; 124 | 125 | @Nullable 126 | @JsonProperty("deleted_at") 127 | private Date deletedAt; 128 | 129 | @NotNull 130 | @JsonProperty("title") 131 | private String title; 132 | 133 | @Nullable 134 | @JsonProperty("custom") 135 | private Map custom; 136 | 137 | @Nullable 138 | @JsonProperty("latest_replies") 139 | private List latestReplies; 140 | 141 | @Nullable 142 | @JsonProperty("read") 143 | private List read; 144 | 145 | @Nullable 146 | @JsonProperty("draft") 147 | private Draft.DraftObject draft; 148 | } 149 | 150 | /** Response for querying threads. */ 151 | @Data 152 | @NoArgsConstructor 153 | @EqualsAndHashCode(callSuper = true) 154 | public static class QueryThreadsResponse extends StreamResponseObject { 155 | @NotNull 156 | @JsonProperty("threads") 157 | private List threads; 158 | 159 | @Nullable 160 | @JsonProperty("next") 161 | private String next; 162 | 163 | @Nullable 164 | @JsonProperty("prev") 165 | private String prev; 166 | } 167 | 168 | /** Request data for querying threads. */ 169 | @Builder( 170 | builderClassName = "QueryThreadsRequest", 171 | builderMethodName = "", 172 | buildMethodName = "internalBuild") 173 | public static class QueryThreadsRequestData { 174 | @Nullable 175 | @JsonProperty("filter") 176 | private Map filter; 177 | 178 | @Singular 179 | @Nullable 180 | @JsonProperty("sort") 181 | private List sorts; 182 | 183 | @Nullable 184 | @JsonProperty("watch") 185 | private Boolean watch; 186 | 187 | @Nullable 188 | @JsonProperty("user_id") 189 | private String userId; 190 | 191 | @Nullable 192 | @JsonProperty("user") 193 | private User.UserRequestObject user; 194 | 195 | @Nullable 196 | @JsonProperty("limit") 197 | private Integer limit; 198 | 199 | @Nullable 200 | @JsonProperty("next") 201 | private String next; 202 | 203 | @Nullable 204 | @JsonProperty("prev") 205 | private String prev; 206 | 207 | public static class QueryThreadsRequest extends StreamRequest { 208 | public QueryThreadsRequest() {} 209 | 210 | @Override 211 | protected Call generateCall(Client client) throws StreamException { 212 | return client.create(ThreadService.class).queryThreads(this.internalBuild()); 213 | } 214 | } 215 | } 216 | 217 | /** 218 | * Queries threads based on the provided parameters 219 | * 220 | * @return the created request 221 | */ 222 | @NotNull 223 | public static QueryThreadsRequestData.QueryThreadsRequest queryThreads() { 224 | return new QueryThreadsRequestData.QueryThreadsRequest(); 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/UnreadCounts.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models; 2 | 3 | import com.fasterxml.jackson.annotation.*; 4 | import io.getstream.chat.java.models.UnreadCounts.UnreadCountsBatchRequestData.UnreadCountsBatchRequest; 5 | import io.getstream.chat.java.models.UnreadCounts.UnreadCountsGetRequestData.UnreadCountsGetRequest; 6 | import io.getstream.chat.java.models.framework.StreamRequest; 7 | import io.getstream.chat.java.models.framework.StreamResponseObject; 8 | import io.getstream.chat.java.services.UnreadCountsService; 9 | import io.getstream.chat.java.services.framework.Client; 10 | import java.util.*; 11 | import lombok.*; 12 | import org.jetbrains.annotations.NotNull; 13 | import org.jetbrains.annotations.Nullable; 14 | import retrofit2.Call; 15 | 16 | @Data 17 | @NoArgsConstructor 18 | public class UnreadCounts { 19 | @Data 20 | @NoArgsConstructor 21 | public static class UnreadCountsChannel { 22 | @NotNull 23 | @JsonProperty("channel_id") 24 | private String channelId; 25 | 26 | @NotNull 27 | @JsonProperty("unread_count") 28 | private Integer unreadCount; 29 | 30 | @NotNull 31 | @JsonProperty("last_read") 32 | private Date lastRead; 33 | } 34 | 35 | @Data 36 | @NoArgsConstructor 37 | public static class UnreadCountsChannelType { 38 | @NotNull 39 | @JsonProperty("channel_type") 40 | private String channelType; 41 | 42 | @NotNull 43 | @JsonProperty("channel_count") 44 | private String channelCount; 45 | 46 | @NotNull 47 | @JsonProperty("unread_count") 48 | private Integer unreadCount; 49 | } 50 | 51 | @Data 52 | @NoArgsConstructor 53 | public static class UnreadCountsThread { 54 | @NotNull 55 | @JsonProperty("unread_count") 56 | private Integer unreadCount; 57 | 58 | @NotNull 59 | @JsonProperty("last_read") 60 | private Date lastRead; 61 | 62 | @Nullable 63 | @JsonProperty("last_read_message_id") 64 | private String lastReadMessageId; 65 | 66 | @Nullable 67 | @JsonProperty("parent_message_id") 68 | private String parentMessageId; 69 | } 70 | 71 | @Data 72 | @NoArgsConstructor 73 | @EqualsAndHashCode(callSuper = true) 74 | public static class UnreadCountsResponse extends StreamResponseObject { 75 | @NotNull 76 | @JsonProperty("total_unread_count") 77 | private Integer totalUnreadCount; 78 | 79 | @NotNull 80 | @JsonProperty("total_unread_threads_count") 81 | private Integer totalUnreadThreadsCount; 82 | 83 | @Nullable 84 | @JsonProperty("channels") 85 | private List channels; 86 | 87 | @Nullable 88 | @JsonProperty("channel_type") 89 | private List channelType; 90 | 91 | @Nullable 92 | @JsonProperty("threads") 93 | private List threads; 94 | } 95 | 96 | @Builder( 97 | builderClassName = "UnreadCountsGetRequest", 98 | builderMethodName = "", 99 | buildMethodName = "internalBuild") 100 | public static class UnreadCountsGetRequestData { 101 | @Nullable 102 | @JsonProperty("user_id") 103 | private String userId; 104 | 105 | public static class UnreadCountsGetRequest extends StreamRequest { 106 | private UnreadCountsGetRequest(@NotNull String userId) { 107 | this.userId = userId; 108 | } 109 | 110 | @Override 111 | protected Call generateCall(Client client) { 112 | return client.create(UnreadCountsService.class).get(userId); 113 | } 114 | } 115 | } 116 | 117 | @Data 118 | @NoArgsConstructor 119 | @EqualsAndHashCode(callSuper = true) 120 | public static class UnreadCountsBatchResponse extends StreamResponseObject { 121 | @NotNull 122 | @JsonProperty("counts_by_user") 123 | private Map countsByUser; 124 | } 125 | 126 | @Builder( 127 | builderClassName = "UnreadCountsBatchRequest", 128 | builderMethodName = "", 129 | buildMethodName = "internalBuild") 130 | public static class UnreadCountsBatchRequestData { 131 | @NotNull 132 | @JsonProperty("user_ids") 133 | private List userIds; 134 | 135 | public static class UnreadCountsBatchRequest extends StreamRequest { 136 | private UnreadCountsBatchRequest() {} 137 | 138 | @Override 139 | protected Call generateCall(Client client) { 140 | return client.create(UnreadCountsService.class).batch(this.internalBuild()); 141 | } 142 | } 143 | } 144 | 145 | /** 146 | * Creates a get request. 147 | * 148 | * @param userId the user id 149 | * @return the created request 150 | */ 151 | @NotNull 152 | public static UnreadCountsGetRequest get(@NotNull String userId) { 153 | return new UnreadCountsGetRequest(userId); 154 | } 155 | 156 | /** 157 | * Creates a batch request. 158 | * 159 | * @return the created request 160 | */ 161 | @NotNull 162 | public static UnreadCountsBatchRequest batch() { 163 | return new UnreadCountsBatchRequest(); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/framework/FileHandler.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models.framework; 2 | 3 | import io.getstream.chat.java.exceptions.StreamException; 4 | import io.getstream.chat.java.models.Message.ImageSizeRequestObject; 5 | import io.getstream.chat.java.models.Message.MessageUploadFileResponse; 6 | import io.getstream.chat.java.models.Message.MessageUploadImageResponse; 7 | import java.io.File; 8 | import java.util.List; 9 | import java.util.function.Consumer; 10 | import org.jetbrains.annotations.NotNull; 11 | import org.jetbrains.annotations.Nullable; 12 | 13 | public interface FileHandler { 14 | 15 | MessageUploadFileResponse uploadFile( 16 | @NotNull String channelType, 17 | @NotNull String channelId, 18 | @NotNull String userId, 19 | @Nullable File file, 20 | @Nullable String contentType) 21 | throws StreamException; 22 | 23 | MessageUploadImageResponse uploadImage( 24 | @NotNull String channelType, 25 | @NotNull String channelId, 26 | @NotNull String userId, 27 | @Nullable File file, 28 | @Nullable String contentType, 29 | @Nullable List uploadSizes) 30 | throws StreamException; 31 | 32 | StreamResponseObject deleteFile( 33 | @NotNull String channelType, @NotNull String channelId, @NotNull String url) 34 | throws StreamException; 35 | 36 | StreamResponseObject deleteImage( 37 | @NotNull String channelType, @NotNull String channelId, @NotNull String url) 38 | throws StreamException; 39 | 40 | void uploadFileAsync( 41 | @NotNull String channelType, 42 | @NotNull String channelId, 43 | @NotNull String userId, 44 | @Nullable File file, 45 | @Nullable String contentType, 46 | @Nullable Consumer onSuccess, 47 | @Nullable Consumer onError); 48 | 49 | void uploadImageAsync( 50 | @NotNull String channelType, 51 | @NotNull String channelId, 52 | @NotNull String userId, 53 | @Nullable File file, 54 | @Nullable String contentType, 55 | @Nullable List uploadSizes, 56 | @Nullable Consumer onSuccess, 57 | @Nullable Consumer onError); 58 | 59 | void deleteFileAsync( 60 | @NotNull String channelType, 61 | @NotNull String channelId, 62 | @NotNull String url, 63 | @Nullable Consumer onSuccess, 64 | @Nullable Consumer onError); 65 | 66 | void deleteImageAsync( 67 | @NotNull String channelType, 68 | @NotNull String channelId, 69 | @NotNull String url, 70 | @Nullable Consumer onSuccess, 71 | @Nullable Consumer onError); 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/framework/StreamRequest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models.framework; 2 | 3 | import io.getstream.chat.java.exceptions.StreamException; 4 | import io.getstream.chat.java.services.framework.Client; 5 | import io.getstream.chat.java.services.framework.StreamServiceHandler; 6 | import java.util.function.Consumer; 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | import retrofit2.Call; 10 | 11 | public abstract class StreamRequest { 12 | protected abstract Call generateCall(Client client) throws StreamException; 13 | 14 | private Client client; 15 | 16 | /** 17 | * Executes the request 18 | * 19 | * @return response 20 | * @throws StreamException when IO problem occurs or the stream API return an error 21 | */ 22 | @NotNull 23 | public T request() throws StreamException { 24 | return new StreamServiceHandler().handle(generateCall(getClient())); 25 | } 26 | 27 | /** 28 | * Executes the request asynchronously 29 | * 30 | * @param onSuccess executed when the request is successful 31 | * @param onError executed when IO problem occurs or the stream API return an error 32 | */ 33 | public void requestAsync( 34 | @Nullable Consumer onSuccess, @Nullable Consumer onError) { 35 | try { 36 | var client = getClient(); 37 | new StreamServiceHandler().handleAsync(generateCall(client), onSuccess, onError); 38 | } catch (StreamException e) { 39 | if (onError != null) { 40 | onError.accept(e); 41 | } 42 | } 43 | } 44 | 45 | /** 46 | * Use custom client implementation to execute requests 47 | * 48 | * @param client the client implementation 49 | * @return the request 50 | */ 51 | public StreamRequest withClient(Client client) { 52 | this.client = client; 53 | return this; 54 | } 55 | 56 | @NotNull 57 | protected Client getClient() { 58 | return (client == null) ? Client.getInstance() : client; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/framework/StreamResponse.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models.framework; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | public interface StreamResponse { 6 | 7 | String getDuration(); 8 | 9 | void setDuration(@NotNull String duration); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/framework/StreamResponseObject.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models.framework; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import io.getstream.chat.java.models.RateLimit; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | public class StreamResponseObject implements StreamResponseWithRateLimit { 12 | private RateLimit rateLimit; 13 | 14 | @NotNull 15 | @JsonProperty("duration") 16 | private String duration; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/framework/StreamResponseWithRateLimit.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models.framework; 2 | 3 | import io.getstream.chat.java.models.RateLimit; 4 | 5 | public interface StreamResponseWithRateLimit extends StreamResponse { 6 | RateLimit getRateLimit(); 7 | 8 | void setRateLimit(RateLimit rateLimit); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/models/framework/UnixTimestampDeserializer.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.models.framework; 2 | 3 | import com.fasterxml.jackson.core.JsonParser; 4 | import com.fasterxml.jackson.core.JsonProcessingException; 5 | import com.fasterxml.jackson.databind.DeserializationContext; 6 | import com.fasterxml.jackson.databind.JsonDeserializer; 7 | import java.io.IOException; 8 | import java.util.Date; 9 | 10 | public class UnixTimestampDeserializer extends JsonDeserializer { 11 | @Override 12 | public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) 13 | throws IOException, JsonProcessingException { 14 | String jsonString = jsonParser.readValueAs(String.class); 15 | try { 16 | return new Date(Long.parseLong(jsonString) * 1000); 17 | } catch (NumberFormatException e) { 18 | throw deserializationContext.instantiationException( 19 | Date.class, "Unparseable date for unix timestamp: " + jsonString); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/AppService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.App; 4 | import io.getstream.chat.java.models.App.AppCheckPushRequestData; 5 | import io.getstream.chat.java.models.App.AppCheckPushResponse; 6 | import io.getstream.chat.java.models.App.AppCheckSnsRequestData; 7 | import io.getstream.chat.java.models.App.AppCheckSnsResponse; 8 | import io.getstream.chat.java.models.App.AppCheckSqsRequestData; 9 | import io.getstream.chat.java.models.App.AppCheckSqsResponse; 10 | import io.getstream.chat.java.models.App.AppGetRateLimitsResponse; 11 | import io.getstream.chat.java.models.App.AppUpdateRequestData; 12 | import io.getstream.chat.java.models.App.ListPushProviderResponse; 13 | import io.getstream.chat.java.models.App.PushProviderRequestData; 14 | import io.getstream.chat.java.models.App.UpsertPushProviderResponse; 15 | import io.getstream.chat.java.models.framework.StreamResponseObject; 16 | import org.jetbrains.annotations.NotNull; 17 | import org.jetbrains.annotations.Nullable; 18 | import retrofit2.Call; 19 | import retrofit2.http.Body; 20 | import retrofit2.http.DELETE; 21 | import retrofit2.http.GET; 22 | import retrofit2.http.PATCH; 23 | import retrofit2.http.POST; 24 | import retrofit2.http.Path; 25 | import retrofit2.http.Query; 26 | 27 | public interface AppService { 28 | @GET("app") 29 | @NotNull 30 | Call get(); 31 | 32 | @PATCH("app") 33 | @NotNull 34 | Call update(@NotNull @Body AppUpdateRequestData appSettings); 35 | 36 | @GET("rate_limits") 37 | Call getRateLimits( 38 | @Nullable @Query("serverSide") Boolean serverSide, 39 | @Nullable @Query("android") Boolean android, 40 | @Nullable @Query("ios") Boolean ios, 41 | @Nullable @Query("web") Boolean web, 42 | @Nullable @Query("endpoints") String endpoints); 43 | 44 | @POST("check_sqs") 45 | Call checkSqs(@NotNull @Body AppCheckSqsRequestData appCheckSqsRequestData); 46 | 47 | @POST("check_sns") 48 | Call checkSns(@NotNull @Body AppCheckSnsRequestData appCheckSnsRequestData); 49 | 50 | @POST("check_push") 51 | Call checkPush(@NotNull @Body AppCheckPushRequestData internalBuild); 52 | 53 | @POST("push_providers") 54 | Call upsertPushProvider( 55 | @NotNull @Body PushProviderRequestData pushProviderRequestData); 56 | 57 | @GET("push_providers") 58 | Call listPushProviders(); 59 | 60 | @DELETE("push_providers/{type}/{name}") 61 | Call deletePushProvider( 62 | @NotNull @Path("type") String providerType, @NotNull @Path("name") String name); 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/BlockUserService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.BlockUser; 4 | import io.getstream.chat.java.models.BlockUser.BlockUserResponse; 5 | import io.getstream.chat.java.models.BlockUser.GetBlockedUsersResponse; 6 | import org.jetbrains.annotations.NotNull; 7 | import retrofit2.Call; 8 | import retrofit2.http.Body; 9 | import retrofit2.http.GET; 10 | import retrofit2.http.POST; 11 | import retrofit2.http.Query; 12 | 13 | public interface BlockUserService { 14 | @POST("users/block") 15 | Call blockUser(@NotNull @Body BlockUser.BlockUserRequestData data); 16 | 17 | @POST("users/unblock") 18 | Call unblockUser( 19 | @NotNull @Body BlockUser.UnblockUserRequestData data); 20 | 21 | @GET("users/block") 22 | Call getBlockedUsers(@Query("user_id") String blockedByUserID); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/BlocklistService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Blocklist.BlocklistCreateRequestData; 4 | import io.getstream.chat.java.models.Blocklist.BlocklistGetResponse; 5 | import io.getstream.chat.java.models.Blocklist.BlocklistListResponse; 6 | import io.getstream.chat.java.models.Blocklist.BlocklistUpdateRequestData; 7 | import io.getstream.chat.java.models.framework.StreamResponseObject; 8 | import org.jetbrains.annotations.NotNull; 9 | import retrofit2.Call; 10 | import retrofit2.http.Body; 11 | import retrofit2.http.DELETE; 12 | import retrofit2.http.GET; 13 | import retrofit2.http.POST; 14 | import retrofit2.http.PUT; 15 | import retrofit2.http.Path; 16 | 17 | public interface BlocklistService { 18 | 19 | @POST("blocklists") 20 | @NotNull 21 | Call create( 22 | @NotNull @Body BlocklistCreateRequestData blocklistCreateRequestData); 23 | 24 | @GET("blocklists/{name}") 25 | @NotNull 26 | Call get(@NotNull @Path("name") String name); 27 | 28 | @PUT("blocklists/{name}") 29 | @NotNull 30 | Call update( 31 | @NotNull @Path("name") String name, 32 | @NotNull @Body BlocklistUpdateRequestData blocklistUpdateRequestData); 33 | 34 | @DELETE("blocklists/{name}") 35 | @NotNull 36 | Call delete(@NotNull @Path("name") String name); 37 | 38 | @GET("blocklists") 39 | @NotNull 40 | Call list(); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/ChannelService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Channel; 4 | import io.getstream.chat.java.models.Channel.*; 5 | import io.getstream.chat.java.models.framework.StreamResponseObject; 6 | import io.getstream.chat.java.services.framework.ToJson; 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | import retrofit2.Call; 10 | import retrofit2.http.*; 11 | 12 | public interface ChannelService { 13 | @POST("channels/{type}/{id}") 14 | Call update( 15 | @NotNull @Path("type") String channelType, 16 | @NotNull @Path("id") String channelId, 17 | @NotNull @Body ChannelUpdateRequestData channelUpdateRequestData); 18 | 19 | @POST("channels/{type}/{id}/query") 20 | Call getOrCreateWithId( 21 | @NotNull @Path("type") String channelType, 22 | @NotNull @Path("id") String channelId, 23 | @Nullable @Body ChannelGetRequestData channelGetRequestData); 24 | 25 | @POST("channels/{type}/query") 26 | Call getOrCreateWithoutId( 27 | @NotNull @Path("type") String channelType, 28 | @Nullable @Body ChannelGetRequestData channelGetRequestData); 29 | 30 | @DELETE("channels/{type}/{id}") 31 | Call delete( 32 | @NotNull @Path("type") String channelType, @NotNull @Path("id") String channelId); 33 | 34 | @POST("channels/delete") 35 | Call deleteMany( 36 | @NotNull @Body Channel.ChannelDeleteManyRequest channelDeleteManyRequest); 37 | 38 | @POST("channels") 39 | Call list(@Nullable @Body ChannelListRequestData channelListRequestData); 40 | 41 | @POST("channels/{type}/{id}/truncate") 42 | Call truncate( 43 | @NotNull @Path("type") String channelType, 44 | @NotNull @Path("id") String channelId, 45 | @Nullable @Body ChannelTruncateRequestData channelTruncateRequestData); 46 | 47 | @GET("members") 48 | Call queryMembers( 49 | @NotNull @ToJson @Query("payload") 50 | ChannelQueryMembersRequestData channelQueryMembersRequestData); 51 | 52 | @POST("export_channels") 53 | Call export( 54 | @NotNull @Body ChannelExportRequestData channelExportRequestData); 55 | 56 | @GET("export_channels/{id}") 57 | Call exportStatus(@NotNull @Path("id") String taskId); 58 | 59 | @POST("channels/{type}/{id}/hide") 60 | Call hide( 61 | @NotNull @Path("type") String channelType, 62 | @NotNull @Path("id") String channelId, 63 | @NotNull @Body ChannelHideRequestData channelHideRequestData); 64 | 65 | @POST("channels/read") 66 | Call markAllRead( 67 | @NotNull @Body ChannelMarkAllReadRequestData channelMarkAllReadRequestData); 68 | 69 | @POST("channels/{type}/{id}/read") 70 | Call markRead( 71 | @NotNull @Path("type") String channelType, 72 | @NotNull @Path("id") String channelId, 73 | @NotNull @Body ChannelMarkReadRequestData channelMarkReadRequestData); 74 | 75 | @POST("moderation/mute/channel") 76 | Call mute(@NotNull @Body ChannelMuteRequestData channelMuteRequestData); 77 | 78 | @POST("channels/{type}/{id}/show") 79 | Call show( 80 | @NotNull @Path("type") String channelType, 81 | @NotNull @Path("id") String channelId, 82 | @NotNull @Body ChannelShowRequestData channelShowRequestData); 83 | 84 | @POST("moderation/unmute/channel") 85 | Call unmute( 86 | @NotNull @Body ChannelUnMuteRequestData channelUnMuteRequestData); 87 | 88 | @PATCH("channels/{type}/{id}") 89 | Call partialUpdate( 90 | @NotNull @Path("type") String channelType, 91 | @NotNull @Path("id") String channelId, 92 | @NotNull @Body ChannelPartialUpdateRequestData channelPartialUpdateRequestData); 93 | 94 | @POST("channels/{type}/{id}") 95 | Call assignRoles( 96 | @NotNull @Path("type") String channelType, 97 | @NotNull @Path("id") String channelId, 98 | @NotNull @Body AssignRoleRequestData assignRoleRequestData); 99 | 100 | @PATCH("channels/{type}/{id}/member/{user_id}") 101 | Call updateMemberPartial( 102 | @NotNull @Path("type") String channelType, 103 | @NotNull @Path("id") String channelId, 104 | @NotNull @Path("user_id") String userId, 105 | @NotNull @Body ChannelMemberPartialUpdateRequestData updateMemberPartialRequestData); 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/ChannelTypeService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.ChannelType.ChannelTypeCreateRequestData; 4 | import io.getstream.chat.java.models.ChannelType.ChannelTypeCreateResponse; 5 | import io.getstream.chat.java.models.ChannelType.ChannelTypeGetResponse; 6 | import io.getstream.chat.java.models.ChannelType.ChannelTypeListResponse; 7 | import io.getstream.chat.java.models.ChannelType.ChannelTypeUpdateRequestData; 8 | import io.getstream.chat.java.models.ChannelType.ChannelTypeUpdateResponse; 9 | import io.getstream.chat.java.models.framework.StreamResponseObject; 10 | import org.jetbrains.annotations.NotNull; 11 | import retrofit2.Call; 12 | import retrofit2.http.Body; 13 | import retrofit2.http.DELETE; 14 | import retrofit2.http.GET; 15 | import retrofit2.http.POST; 16 | import retrofit2.http.PUT; 17 | import retrofit2.http.Path; 18 | 19 | public interface ChannelTypeService { 20 | @POST("channeltypes") 21 | @NotNull 22 | Call create( 23 | @NotNull @Body ChannelTypeCreateRequestData channelTypeCreateRequestData); 24 | 25 | @DELETE("channeltypes/{name}") 26 | @NotNull 27 | Call delete(@NotNull @Path("name") String name); 28 | 29 | @GET("channeltypes/{name}") 30 | @NotNull 31 | Call get(@NotNull @Path("name") String name); 32 | 33 | @GET("channeltypes") 34 | @NotNull 35 | Call list(); 36 | 37 | @PUT("channeltypes/{name}") 38 | @NotNull 39 | Call update( 40 | @NotNull @Path("name") String name, 41 | @NotNull @Body ChannelTypeUpdateRequestData channelTypeUpdateRequestData); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/CommandService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Command.CommandCreateRequestData; 4 | import io.getstream.chat.java.models.Command.CommandCreateResponse; 5 | import io.getstream.chat.java.models.Command.CommandDeleteResponse; 6 | import io.getstream.chat.java.models.Command.CommandGetResponse; 7 | import io.getstream.chat.java.models.Command.CommandListResponse; 8 | import io.getstream.chat.java.models.Command.CommandUpdateRequestData; 9 | import io.getstream.chat.java.models.Command.CommandUpdateResponse; 10 | import org.jetbrains.annotations.NotNull; 11 | import retrofit2.Call; 12 | import retrofit2.http.Body; 13 | import retrofit2.http.DELETE; 14 | import retrofit2.http.GET; 15 | import retrofit2.http.POST; 16 | import retrofit2.http.PUT; 17 | import retrofit2.http.Path; 18 | 19 | public interface CommandService { 20 | 21 | @POST("commands") 22 | @NotNull 23 | Call create( 24 | @NotNull @Body CommandCreateRequestData commandCreateRequestData); 25 | 26 | @GET("commands/{name}") 27 | @NotNull 28 | Call get(@NotNull @Path("name") String name); 29 | 30 | @PUT("commands/{name}") 31 | @NotNull 32 | Call update( 33 | @NotNull @Path("name") String name, 34 | @NotNull @Body CommandUpdateRequestData commandUpdateRequestData); 35 | 36 | @DELETE("commands/{name}") 37 | @NotNull 38 | Call delete(@NotNull @Path("name") String name); 39 | 40 | @GET("commands") 41 | @NotNull 42 | Call list(); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/DeviceService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Device.DeviceCreateRequestData; 4 | import io.getstream.chat.java.models.Device.DeviceListResponse; 5 | import io.getstream.chat.java.models.framework.StreamResponseObject; 6 | import org.jetbrains.annotations.NotNull; 7 | import retrofit2.Call; 8 | import retrofit2.http.Body; 9 | import retrofit2.http.DELETE; 10 | import retrofit2.http.GET; 11 | import retrofit2.http.POST; 12 | import retrofit2.http.Query; 13 | 14 | public interface DeviceService { 15 | 16 | @POST("devices") 17 | Call create(@NotNull @Body DeviceCreateRequestData deviceCreateRequestData); 18 | 19 | @DELETE("devices") 20 | Call delete( 21 | @NotNull @Query("id") String id, @NotNull @Query("user_id") String userId); 22 | 23 | @GET("devices") 24 | Call list(@NotNull @Query("user_id") String userId); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/DraftService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Draft.CreateDraftRequestData; 4 | import io.getstream.chat.java.models.Draft.CreateDraftResponse; 5 | import io.getstream.chat.java.models.Draft.GetDraftResponse; 6 | import io.getstream.chat.java.models.Draft.QueryDraftsRequestData; 7 | import io.getstream.chat.java.models.Draft.QueryDraftsResponse; 8 | import io.getstream.chat.java.models.framework.StreamResponseObject; 9 | import org.jetbrains.annotations.Nullable; 10 | import retrofit2.Call; 11 | import retrofit2.http.*; 12 | 13 | /** Service for managing draft messages in channels. */ 14 | public interface DraftService { 15 | /** 16 | * Creates a draft message in a channel. 17 | * 18 | * @param type The channel type 19 | * @param id The channel ID 20 | * @param request The draft creation request data 21 | * @return A response with the created draft 22 | */ 23 | @POST("channels/{type}/{id}/draft") 24 | Call createDraft( 25 | @Path("type") String type, @Path("id") String id, @Body CreateDraftRequestData request); 26 | 27 | /** 28 | * Deletes a draft message from a channel. 29 | * 30 | * @param type The channel type 31 | * @param id The channel ID 32 | * @param userId The user ID 33 | * @param parentId Optional parent message ID 34 | * @return A response indicating success 35 | */ 36 | @DELETE("channels/{type}/{id}/draft") 37 | Call deleteDraft( 38 | @Path("type") String type, 39 | @Path("id") String id, 40 | @Query("user_id") String userId, 41 | @Query("parent_id") @Nullable String parentId); 42 | 43 | /** 44 | * Gets a draft message from a channel. 45 | * 46 | * @param type The channel type 47 | * @param id The channel ID 48 | * @param userId The user ID 49 | * @param parentId Optional parent message ID 50 | * @return A response with the draft 51 | */ 52 | @GET("channels/{type}/{id}/draft") 53 | Call getDraft( 54 | @Path("type") String type, 55 | @Path("id") String id, 56 | @Query("user_id") String userId, 57 | @Query("parent_id") @Nullable String parentId); 58 | 59 | /** 60 | * Queries all drafts for a user. 61 | * 62 | * @param request The query parameters 63 | * @return A response with the matching drafts 64 | */ 65 | @POST("drafts/query") 66 | Call queryDrafts(@Body QueryDraftsRequestData request); 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/EventService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Event.EventSendRequestData; 4 | import io.getstream.chat.java.models.Event.EventSendResponse; 5 | import io.getstream.chat.java.models.Event.EventSendUserCustomRequestData; 6 | import io.getstream.chat.java.models.framework.StreamResponseObject; 7 | import org.jetbrains.annotations.NotNull; 8 | import retrofit2.Call; 9 | import retrofit2.http.Body; 10 | import retrofit2.http.POST; 11 | import retrofit2.http.Path; 12 | 13 | public interface EventService { 14 | 15 | @POST("channels/{type}/{id}/event") 16 | Call send( 17 | @NotNull @Path("type") String channelType, 18 | @NotNull @Path("id") String channelId, 19 | @NotNull @Body EventSendRequestData eventSendRequestData); 20 | 21 | @POST("users/{user_id}/event") 22 | Call sendUserCustom( 23 | @NotNull @Path("user_id") String userId, 24 | @NotNull @Body EventSendUserCustomRequestData eventSendUserCustomRequestData); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/ExportUsersService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.ExportUsers; 4 | import org.jetbrains.annotations.NotNull; 5 | import retrofit2.Call; 6 | import retrofit2.http.*; 7 | 8 | public interface ExportUsersService { 9 | @POST("export/users") 10 | Call exportUsers( 11 | @NotNull @Body ExportUsers.ExportUsersRequestData exportUsersRequest); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/FlagService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Flag.FlagCreateRequestData; 4 | import io.getstream.chat.java.models.Flag.FlagCreateResponse; 5 | import io.getstream.chat.java.models.Flag.FlagDeleteRequestData; 6 | import io.getstream.chat.java.models.Flag.FlagDeleteResponse; 7 | import io.getstream.chat.java.models.Flag.FlagMessageQueryRequestData; 8 | import io.getstream.chat.java.models.Flag.FlagMessageQueryResponse; 9 | import io.getstream.chat.java.models.Flag.QueryFlagReportsRequestData; 10 | import io.getstream.chat.java.models.Flag.QueryFlagReportsResponse; 11 | import io.getstream.chat.java.models.Flag.ReviewFlagReportRequestData; 12 | import io.getstream.chat.java.models.Flag.ReviewFlagReportResponse; 13 | import io.getstream.chat.java.services.framework.ToJson; 14 | import org.jetbrains.annotations.NotNull; 15 | import retrofit2.Call; 16 | import retrofit2.http.*; 17 | 18 | public interface FlagService { 19 | 20 | @POST("moderation/flag") 21 | Call create(@NotNull @Body FlagCreateRequestData flagCreateRequestData); 22 | 23 | @POST("moderation/unflag") 24 | Call delete(@NotNull @Body FlagDeleteRequestData flagDeleteRequestData); 25 | 26 | @GET("moderation/flags/message") 27 | Call messageQuery( 28 | @NotNull @ToJson @Query("payload") FlagMessageQueryRequestData flagMessageQueryRequestData); 29 | 30 | @POST("moderation/reports") 31 | Call queryFlagReports( 32 | @NotNull @Body QueryFlagReportsRequestData queryFlagReportsRequestData); 33 | 34 | @PATCH("moderation/reports/{id}") 35 | Call reviewFlagReport( 36 | @NotNull @Path("id") String id, 37 | @NotNull @Body ReviewFlagReportRequestData reviewFlagReportRequestData); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/ImportService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Import; 4 | import org.jetbrains.annotations.NotNull; 5 | import org.jetbrains.annotations.Nullable; 6 | import retrofit2.Call; 7 | import retrofit2.http.*; 8 | 9 | public interface ImportService { 10 | @POST("import_urls") 11 | Call createImportUrl( 12 | @NotNull @Body Import.CreateImportUrlRequestData createImportUrlRequestData); 13 | 14 | @POST("imports") 15 | Call createImport( 16 | @NotNull @Body Import.CreateImportRequestData createImportRequestData); 17 | 18 | @GET("imports/{id}") 19 | Call getImport(@NotNull @Path("id") String id); 20 | 21 | @GET("imports") 22 | Call listImports( 23 | @Nullable @Query("limit") Integer limit, @Nullable @Query("offset") Integer offset); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/MessageHistoryService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.MessageHistory.MessageHistoryQueryRequestData; 4 | import io.getstream.chat.java.models.MessageHistory.MessageHistoryQueryResponse; 5 | import org.jetbrains.annotations.NotNull; 6 | import retrofit2.Call; 7 | import retrofit2.http.Body; 8 | import retrofit2.http.POST; 9 | 10 | public interface MessageHistoryService { 11 | @POST("messages/history") 12 | Call query( 13 | @NotNull @Body MessageHistoryQueryRequestData messageHistoryQueryRequestData); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/MessageService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Message.MessageCommitResponse; 4 | import io.getstream.chat.java.models.Message.MessageDeleteResponse; 5 | import io.getstream.chat.java.models.Message.MessageGetManyResponse; 6 | import io.getstream.chat.java.models.Message.MessageGetRepliesResponse; 7 | import io.getstream.chat.java.models.Message.MessageGetResponse; 8 | import io.getstream.chat.java.models.Message.MessagePartialUpdateRequestData; 9 | import io.getstream.chat.java.models.Message.MessagePartialUpdateResponse; 10 | import io.getstream.chat.java.models.Message.MessageRunCommandActionRequestData; 11 | import io.getstream.chat.java.models.Message.MessageRunCommandActionResponse; 12 | import io.getstream.chat.java.models.Message.MessageSearchRequestData; 13 | import io.getstream.chat.java.models.Message.MessageSearchResponse; 14 | import io.getstream.chat.java.models.Message.MessageSendRequestData; 15 | import io.getstream.chat.java.models.Message.MessageSendResponse; 16 | import io.getstream.chat.java.models.Message.MessageTranslateRequestData; 17 | import io.getstream.chat.java.models.Message.MessageTranslateResponse; 18 | import io.getstream.chat.java.models.Message.MessageUnblockRequestData; 19 | import io.getstream.chat.java.models.Message.MessageUpdateRequestData; 20 | import io.getstream.chat.java.models.Message.MessageUpdateResponse; 21 | import io.getstream.chat.java.models.Message.MessageUploadFileResponse; 22 | import io.getstream.chat.java.models.Message.MessageUploadImageResponse; 23 | import io.getstream.chat.java.models.framework.StreamResponseObject; 24 | import io.getstream.chat.java.services.framework.ToJson; 25 | import java.util.Date; 26 | import okhttp3.MultipartBody; 27 | import okhttp3.RequestBody; 28 | import org.jetbrains.annotations.NotNull; 29 | import org.jetbrains.annotations.Nullable; 30 | import retrofit2.Call; 31 | import retrofit2.http.Body; 32 | import retrofit2.http.DELETE; 33 | import retrofit2.http.GET; 34 | import retrofit2.http.Headers; 35 | import retrofit2.http.Multipart; 36 | import retrofit2.http.POST; 37 | import retrofit2.http.PUT; 38 | import retrofit2.http.Part; 39 | import retrofit2.http.Path; 40 | import retrofit2.http.Query; 41 | 42 | public interface MessageService { 43 | @POST("channels/{type}/{id}/message") 44 | Call send( 45 | @NotNull @Path("type") String channelType, 46 | @NotNull @Path("id") String channelId, 47 | @NotNull @Body MessageSendRequestData messageSendRequestData); 48 | 49 | @POST("messages/{id}") 50 | Call update( 51 | @NotNull @Path("id") String id, 52 | @NotNull @Body MessageUpdateRequestData messageUpdateRequestData); 53 | 54 | @GET("search") 55 | Call search( 56 | @NotNull @ToJson @Query("payload") MessageSearchRequestData messageSearchRequestData); 57 | 58 | @POST("messages/{id}/commit") 59 | Call commit(@NotNull @Path("id") String messageId); 60 | 61 | @Multipart 62 | @Headers("X-Stream-LogRequestBody: false") 63 | @POST("channels/{type}/{id}/file") 64 | Call uploadFile( 65 | @NotNull @Path("type") String channelType, 66 | @NotNull @Path("id") String channelId, 67 | @NotNull @Part("user") RequestBody userRequestBody, 68 | @NotNull @Part MultipartBody.Part multipartFile); 69 | 70 | @Multipart 71 | @Headers("X-Stream-LogRequestBody: false") 72 | @POST("channels/{type}/{id}/image") 73 | Call uploadImage( 74 | @NotNull @Path("type") String channelType, 75 | @NotNull @Path("id") String channelId, 76 | @NotNull @Part("user") RequestBody userRequestBody, 77 | @NotNull @Part MultipartBody.Part multipartFile, 78 | @NotNull @Part("upload_sizes") RequestBody uploadSizesRequestBody); 79 | 80 | @DELETE("channels/{type}/{id}/file") 81 | Call deleteFile( 82 | @NotNull @Path("type") String channelType, 83 | @NotNull @Path("id") String channelId, 84 | @NotNull @Query("url") String url); 85 | 86 | @DELETE("channels/{type}/{id}/image") 87 | Call deleteImage( 88 | @NotNull @Path("type") String channelType, 89 | @NotNull @Path("id") String channelId, 90 | @NotNull @Query("url") String url); 91 | 92 | @DELETE("messages/{id}") 93 | Call delete( 94 | @NotNull @Path("id") String id, 95 | @Nullable @Query("hard") Boolean hard, 96 | @Nullable @Query("deleted_by") String deletedBy); 97 | 98 | @GET("messages/{id}") 99 | Call get( 100 | @NotNull @Path("id") String id, 101 | @Nullable @Query("show_deleted_message") Boolean showDeletedMessage); 102 | 103 | @GET("channels/{type}/{id}/messages") 104 | Call getMany( 105 | @NotNull @Path("type") String channelType, 106 | @NotNull @Path("id") String channelId, 107 | @NotNull @Query("ids") String messageIds); 108 | 109 | @GET("messages/{parent_id}/replies") 110 | Call getReplies( 111 | @NotNull @Path("parent_id") String parentId, 112 | @Nullable @Query("id_gte") String idGte, 113 | @Nullable @Query("id_gt") String idGt, 114 | @Nullable @Query("id_lte") String idLte, 115 | @Nullable @Query("id_lt") String idLt, 116 | @Nullable @Query("created_at_after_or_equal") Date createdAtAfterOrEqual, 117 | @Nullable @Query("created_at_after") Date createdAtAfter, 118 | @Nullable @Query("created_at_before_or_equal") Date createdAtBeforeOrEqual, 119 | @Nullable @Query("created_at_before") Date createdAtBefore); 120 | 121 | @POST("messages/{id}/action") 122 | Call runCommandAction( 123 | @NotNull @Path("id") String messageId, 124 | @NotNull @Body MessageRunCommandActionRequestData messageRunCommandActionRequestData); 125 | 126 | @POST("messages/{id}/translate") 127 | Call translate( 128 | @NotNull @Path("id") String messageId, 129 | @NotNull @Body MessageTranslateRequestData messageTranslateRequestData); 130 | 131 | @PUT("messages/{id}") 132 | Call partialUpdate( 133 | @NotNull @Path("id") String id, 134 | @NotNull @Body MessagePartialUpdateRequestData messagePartialUpdateRequestData); 135 | 136 | @POST("moderation/unblock_message") 137 | Call unblockMessage( 138 | @NotNull @Body MessageUnblockRequestData messageUnblockRequestData); 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/ModerationService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Moderation.*; 4 | import io.getstream.chat.java.models.framework.StreamResponseObject; 5 | import org.jetbrains.annotations.NotNull; 6 | import org.jetbrains.annotations.Nullable; 7 | import retrofit2.Call; 8 | import retrofit2.http.*; 9 | 10 | public interface ModerationService { 11 | @GET("api/v2/moderation/config/{key}") 12 | Call getConfig(@NotNull @Path("key") String key); 13 | 14 | @DELETE("api/v2/moderation/config/{key}") 15 | Call deleteConfig(@NotNull @Path("key") String key); 16 | 17 | @POST("api/v2/moderation/config") 18 | Call upsertConfig(@Nullable @Body UpsertConfigRequestData upsertConfig); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/PermissionService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Permission.PermissionCreateRequestData; 4 | import io.getstream.chat.java.models.Permission.PermissionGetResponse; 5 | import io.getstream.chat.java.models.Permission.PermissionListResponse; 6 | import io.getstream.chat.java.models.Permission.PermissionUpdateRequestData; 7 | import io.getstream.chat.java.models.framework.StreamResponseObject; 8 | import org.jetbrains.annotations.NotNull; 9 | import retrofit2.Call; 10 | import retrofit2.http.*; 11 | 12 | public interface PermissionService { 13 | 14 | @POST("permissions") 15 | @NotNull 16 | Call create( 17 | @NotNull @Body PermissionCreateRequestData permissionCreateRequestData); 18 | 19 | @GET("permissions/{id}") 20 | @NotNull 21 | Call get(@NotNull @Path("id") String id); 22 | 23 | @PUT("permissions/{id}") 24 | @NotNull 25 | Call update( 26 | @NotNull @Path("id") String id, 27 | @NotNull @Body PermissionUpdateRequestData permissionUpdateRequestData); 28 | 29 | @DELETE("permissions/{id}") 30 | @NotNull 31 | Call delete(@NotNull @Path("id") String name); 32 | 33 | @GET("permissions") 34 | @NotNull 35 | Call list(); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/ReactionService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Reaction.ReactionDeleteResponse; 4 | import io.getstream.chat.java.models.Reaction.ReactionListResponse; 5 | import io.getstream.chat.java.models.Reaction.ReactionSendRequestData; 6 | import io.getstream.chat.java.models.Reaction.ReactionSendResponse; 7 | import org.jetbrains.annotations.NotNull; 8 | import retrofit2.Call; 9 | import retrofit2.http.Body; 10 | import retrofit2.http.DELETE; 11 | import retrofit2.http.GET; 12 | import retrofit2.http.POST; 13 | import retrofit2.http.Path; 14 | import retrofit2.http.Query; 15 | 16 | public interface ReactionService { 17 | 18 | @POST("messages/{id}/reaction") 19 | Call send( 20 | @NotNull @Path("id") String messageId, 21 | @NotNull @Body ReactionSendRequestData reactionSendRequestData); 22 | 23 | @DELETE("messages/{id}/reaction/{type}") 24 | Call delete( 25 | @NotNull @Path("id") String messageId, 26 | @NotNull @Path("type") String type, 27 | @NotNull @Query("user_id") String userId); 28 | 29 | @GET("messages/{id}/reactions") 30 | Call list(@NotNull @Path("id") String messageId); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/RoleService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Role.RoleCreateRequestData; 4 | import io.getstream.chat.java.models.Role.RoleListResponse; 5 | import io.getstream.chat.java.models.framework.StreamResponseObject; 6 | import org.jetbrains.annotations.NotNull; 7 | import retrofit2.Call; 8 | import retrofit2.http.Body; 9 | import retrofit2.http.DELETE; 10 | import retrofit2.http.GET; 11 | import retrofit2.http.POST; 12 | import retrofit2.http.Path; 13 | 14 | public interface RoleService { 15 | 16 | @POST("roles") 17 | @NotNull 18 | Call create(@NotNull @Body RoleCreateRequestData roleCreateRequestData); 19 | 20 | @DELETE("roles/{name}") 21 | @NotNull 22 | Call delete(@NotNull @Path("name") String name); 23 | 24 | @GET("roles") 25 | @NotNull 26 | Call list(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/TaskStatusService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.TaskStatus.TaskStatusGetResponse; 4 | import org.jetbrains.annotations.NotNull; 5 | import retrofit2.Call; 6 | import retrofit2.http.GET; 7 | import retrofit2.http.Path; 8 | 9 | public interface TaskStatusService { 10 | @GET("tasks/{id}") 11 | Call get(@NotNull @Path("id") String id); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/ThreadService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.Thread.QueryThreadsRequestData; 4 | import io.getstream.chat.java.models.Thread.QueryThreadsResponse; 5 | import org.jetbrains.annotations.NotNull; 6 | import retrofit2.Call; 7 | import retrofit2.http.*; 8 | 9 | public interface ThreadService { 10 | @POST("threads") 11 | Call queryThreads( 12 | @NotNull @Body QueryThreadsRequestData queryThreadsRequestData); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/UnreadCountsService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.UnreadCounts.*; 4 | import org.jetbrains.annotations.NotNull; 5 | import retrofit2.Call; 6 | import retrofit2.http.*; 7 | 8 | public interface UnreadCountsService { 9 | @GET("unread") 10 | Call get(@NotNull @Query("user_id") String userId); 11 | 12 | @POST("unread_batch") 13 | Call batch( 14 | @NotNull @Body UnreadCountsBatchRequestData unreadCountsBatchRequestData); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/UserService.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services; 2 | 3 | import io.getstream.chat.java.models.User.*; 4 | import io.getstream.chat.java.models.framework.StreamResponseObject; 5 | import io.getstream.chat.java.services.framework.ToJson; 6 | import org.jetbrains.annotations.NotNull; 7 | import org.jetbrains.annotations.Nullable; 8 | import retrofit2.Call; 9 | import retrofit2.http.*; 10 | 11 | public interface UserService { 12 | @POST("users") 13 | Call upsert(@NotNull @Body UserUpsertRequestData userUpsertRequestData); 14 | 15 | @GET("users") 16 | Call list( 17 | @NotNull @ToJson @Query("payload") UserListRequestData userListRequestData); 18 | 19 | @PATCH("users") 20 | Call partialUpdate( 21 | @NotNull @Body UserPartialUpdateRequestData userPartialUpdateRequestData); 22 | 23 | @GET("query_banned_users") 24 | Call queryBanned( 25 | @NotNull @ToJson @Query("payload") UserQueryBannedRequestData userQueryBannedRequestData); 26 | 27 | @POST("moderation/ban") 28 | Call ban(@NotNull @Body UserBanRequestData userBanRequestData); 29 | 30 | @POST("users/{user_id}/deactivate") 31 | Call deactivate( 32 | @NotNull @Path("user_id") String userId, 33 | @NotNull @Body UserDeactivateRequestData userDeactivateRequestData); 34 | 35 | @DELETE("users/{user_id}") 36 | Call delete( 37 | @NotNull @Path("user_id") String userId, 38 | @Nullable @Query("mark_messages_deleted") Boolean markMessagesDeleted, 39 | @Nullable @Query("hard_delete") Boolean hardDelete, 40 | @Nullable @Query("delete_conversation_channels") Boolean deleteConversationChannels); 41 | 42 | @POST("users/delete") 43 | Call deleteMany(@NotNull @Body UserDeleteManyRequestData data); 44 | 45 | @POST("users/{user_id}/reactivate") 46 | Call reactivate( 47 | @NotNull @Path("user_id") String userId, 48 | @NotNull @Body UserReactivateRequestData userReactivateRequestData); 49 | 50 | @POST("moderation/mute") 51 | Call mute(@NotNull @Body UserMuteRequestData userMuteRequestData); 52 | 53 | @POST("moderation/unmute") 54 | Call unmute(@NotNull @Body UserUnmuteRequestData userUnmuteRequestData); 55 | 56 | @GET("users/{user_id}/export") 57 | Call export(@NotNull @Path("user_id") String userId); 58 | 59 | @POST("guest") 60 | Call createGuest( 61 | @NotNull @Body UserCreateGuestRequestData userCreateGuestRequestData); 62 | 63 | @DELETE("moderation/ban") 64 | Call unban( 65 | @NotNull @Query("target_user_id") String targetUserId, 66 | @Nullable @Query("type") String channelType, 67 | @Nullable @Query("id") String channelId, 68 | @Nullable @Query("shadow") Boolean shadow); 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/framework/Client.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services.framework; 2 | 3 | import java.time.Duration; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public interface Client { 7 | @NotNull 8 | TService create(Class svcClass); 9 | 10 | @NotNull 11 | String getApiKey(); 12 | 13 | @NotNull 14 | String getApiSecret(); 15 | 16 | void setTimeout(@NotNull Duration timeoutDuration); 17 | 18 | static Client getInstance() { 19 | return DefaultClient.getInstance(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/framework/QueryConverterFactory.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services.framework; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import java.io.ByteArrayOutputStream; 5 | import java.lang.annotation.Annotation; 6 | import java.lang.reflect.Type; 7 | import java.time.format.DateTimeFormatter; 8 | import java.util.Date; 9 | import retrofit2.Converter; 10 | import retrofit2.Retrofit; 11 | 12 | public class QueryConverterFactory extends Converter.Factory { 13 | public static QueryConverterFactory create() { 14 | return new QueryConverterFactory(); 15 | } 16 | 17 | @Override 18 | public Converter stringConverter( 19 | Type type, Annotation[] annotations, Retrofit retrofit) { 20 | if (type == Date.class) { 21 | return value -> { 22 | return DateTimeFormatter.ISO_INSTANT.format(((Date) value).toInstant()); 23 | }; 24 | } 25 | if (!hasToJson(annotations)) { 26 | return super.stringConverter(type, annotations, retrofit); 27 | } 28 | return value -> { 29 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 30 | new ObjectMapper().writeValue(baos, value); 31 | return baos.toString("UTF-8"); 32 | }; 33 | } 34 | 35 | private boolean hasToJson(final Annotation[] annotations) { 36 | for (final Annotation annotation : annotations) { 37 | if (annotation instanceof ToJson) { 38 | return true; 39 | } 40 | } 41 | return false; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/framework/StreamServiceGenerator.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services.framework; 2 | 3 | import lombok.extern.java.Log; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | @Log 7 | public class StreamServiceGenerator { 8 | public static @NotNull S createService(@NotNull Class serviceClass) { 9 | return DefaultClient.getInstance().create(serviceClass); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/framework/StreamServiceHandler.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services.framework; 2 | 3 | import io.getstream.chat.java.exceptions.StreamException; 4 | import io.getstream.chat.java.models.RateLimit; 5 | import io.getstream.chat.java.models.framework.StreamResponse; 6 | import io.getstream.chat.java.models.framework.StreamResponseWithRateLimit; 7 | import java.io.IOException; 8 | import java.util.Date; 9 | import java.util.function.Consumer; 10 | import okhttp3.Headers; 11 | import retrofit2.Call; 12 | import retrofit2.Callback; 13 | import retrofit2.Response; 14 | 15 | public class StreamServiceHandler { 16 | public T handle(Call call) throws StreamException { 17 | try { 18 | Response response = call.execute(); 19 | if (response.isSuccessful()) { 20 | return enrichResponse(response); 21 | } 22 | throw StreamException.build(response); 23 | } catch (IOException e) { 24 | throw StreamException.build(e); 25 | } 26 | } 27 | 28 | public void handleAsync( 29 | Call call, Consumer onSuccess, Consumer onError) { 30 | call.enqueue( 31 | new Callback() { 32 | @Override 33 | public void onResponse(Call call, Response response) { 34 | if (response.isSuccessful()) { 35 | if (onSuccess != null) { 36 | onSuccess.accept(enrichResponse(response)); 37 | } 38 | } else if (onError != null) { 39 | onError.accept(StreamException.build(response)); 40 | } 41 | } 42 | 43 | @Override 44 | public void onFailure(Call call, Throwable throwable) { 45 | if (onError != null) { 46 | onError.accept(StreamException.build(throwable)); 47 | } 48 | } 49 | }); 50 | } 51 | 52 | private T enrichResponse(Response response) { 53 | T result = response.body(); 54 | if (result instanceof StreamResponseWithRateLimit) { 55 | Headers headers = response.headers(); 56 | RateLimit rateLimit = new RateLimit(); 57 | if (headers.get("X-Ratelimit-Limit") != null) { 58 | rateLimit.setLimit(Integer.parseInt(headers.get("X-Ratelimit-Limit"))); 59 | } 60 | 61 | if (headers.get("X-Ratelimit-Remaining") != null) { 62 | rateLimit.setRemaining(Integer.parseInt(headers.get("X-Ratelimit-Remaining"))); 63 | } 64 | 65 | if (headers.get("X-Ratelimit-Reset") != null) { 66 | rateLimit.setReset(new Date(Long.parseLong(headers.get("X-Ratelimit-Reset")) * 1000)); 67 | } 68 | ((StreamResponseWithRateLimit) result).setRateLimit(rateLimit); 69 | } 70 | return result; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/io/getstream/chat/java/services/framework/ToJson.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java.services.framework; 2 | 3 | import static java.lang.annotation.ElementType.PARAMETER; 4 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 5 | 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.Target; 8 | 9 | @Target(PARAMETER) 10 | @Retention(RUNTIME) 11 | public @interface ToJson {} 12 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/AppTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.exceptions.StreamException; 4 | import io.getstream.chat.java.models.App; 5 | import io.getstream.chat.java.models.App.AppCheckSnsResponse; 6 | import io.getstream.chat.java.models.App.AppCheckSqsResponse; 7 | import io.getstream.chat.java.models.App.AppConfig; 8 | import io.getstream.chat.java.models.App.PushConfigRequestObject; 9 | import io.getstream.chat.java.models.App.PushVersion; 10 | import io.getstream.chat.java.models.Message; 11 | import io.getstream.chat.java.models.Message.MessageRequestObject; 12 | import io.getstream.chat.java.services.framework.DefaultClient; 13 | import java.util.Calendar; 14 | import java.util.GregorianCalendar; 15 | import java.util.Properties; 16 | import java.util.Random; 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.DisplayName; 19 | import org.junit.jupiter.api.Test; 20 | 21 | public class AppTest extends BasicTest { 22 | private AppCheckSnsResponse.Status SnsStatus; 23 | private AppCheckSqsResponse.Status SqsStatus; 24 | 25 | @DisplayName("App Get does not throw Exception") 26 | @Test 27 | void whenCallingGetApp_thenNoException() { 28 | Assertions.assertDoesNotThrow(() -> App.get().request()); 29 | } 30 | 31 | @Test 32 | @DisplayName("App get async does not throw Exception") 33 | void whenCallingGetAppAsync_thenNoException() { 34 | App.get().requestAsync(Assertions::assertNotNull, Assertions::assertNull); 35 | } 36 | 37 | @DisplayName("App Settings update does not throw Exception") 38 | @Test 39 | void whenUpdatingAppSettings_thenNoException() { 40 | Assertions.assertDoesNotThrow( 41 | () -> 42 | App.update() 43 | .disableAuthChecks(true) 44 | .disablePermissionsChecks(true) 45 | .asyncModerationConfig( 46 | App.AsyncModerationConfigRequestObject.builder() 47 | .callback( 48 | App.AsyncModerationCallback.builder() 49 | .mode("CALLBACK_MODE_REST") 50 | .serverUrl("http://localhost.com") 51 | .build()) 52 | .timeoutMs(3000) 53 | .build()) 54 | .request()); 55 | Assertions.assertDoesNotThrow( 56 | () -> App.update().disableAuthChecks(false).disablePermissionsChecks(false).request()); 57 | } 58 | 59 | @DisplayName("App Get fails with bad key") 60 | @Test 61 | void givenBadKey_whenGettingApp_thenException() { 62 | var properties = new Properties(); 63 | properties.put(DefaultClient.API_KEY_PROP_NAME, "XXX"); 64 | 65 | var client = new DefaultClient(properties); 66 | 67 | StreamException exception = 68 | Assertions.assertThrows( 69 | StreamException.class, () -> App.get().withClient(client).request()); 70 | Assertions.assertEquals(401, exception.getResponseData().getStatusCode()); 71 | } 72 | 73 | @DisplayName("App Get fails with bad secret (after enabling auth)") 74 | @Test 75 | void givenBadSecret_whenEnableAuthAndGettingApp_thenException() { 76 | Assertions.assertDoesNotThrow(() -> App.update().disableAuthChecks(false).request()); 77 | var properties = new Properties(); 78 | properties.put( 79 | DefaultClient.API_SECRET_PROP_NAME, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); 80 | 81 | var client = new DefaultClient(properties); 82 | 83 | StreamException exception = 84 | Assertions.assertThrows( 85 | StreamException.class, () -> App.get().withClient(client).request()); 86 | Assertions.assertEquals(401, exception.getResponseData().getStatusCode()); 87 | } 88 | 89 | @DisplayName("Get rate limits does not throw Exception") 90 | @Test 91 | void whenCallingGetRateLimits_thenNoException() { 92 | Assertions.assertDoesNotThrow(() -> App.getRateLimits().request()); 93 | } 94 | 95 | @DisplayName("Can check sqs") 96 | @Test 97 | void whenCheckingBadSqs_thenError() { 98 | AppCheckSqsResponse response = 99 | Assertions.assertDoesNotThrow( 100 | () -> 101 | App.checkSqs() 102 | .sqsKey("key") 103 | .sqsSecret("secret") 104 | .sqsUrl("https://foo.com/bar") 105 | .request()); 106 | Assertions.assertEquals(SqsStatus.ERROR, response.getStatus()); 107 | } 108 | 109 | @DisplayName("Can check sns") 110 | @Test 111 | void whenCheckingBadSns_thenError() { 112 | AppCheckSnsResponse response = 113 | Assertions.assertDoesNotThrow( 114 | () -> 115 | App.checkSns() 116 | .snsKey("key") 117 | .snsSecret("secret") 118 | .snsTopicArn("arn:aws:sns:us-east-1:123456789012:sns-topic") 119 | .request()); 120 | Assertions.assertEquals(SnsStatus.ERROR, response.getStatus()); 121 | } 122 | 123 | @DisplayName("Can check push templates") 124 | @Test 125 | void whenCheckingPushTemplates_thenNoException() { 126 | String firstUserId = testUserRequestObject.getId(); 127 | String secondUserId = testUsersRequestObjects.get(1).getId(); 128 | String text = "Hello @" + secondUserId; 129 | MessageRequestObject messageRequest = 130 | MessageRequestObject.builder().text(text).userId(firstUserId).build(); 131 | Message message = 132 | Assertions.assertDoesNotThrow( 133 | () -> 134 | Message.send(testChannel.getType(), testChannel.getId()) 135 | .message(messageRequest) 136 | .request()) 137 | .getMessage(); 138 | Assertions.assertDoesNotThrow( 139 | () -> 140 | App.update() 141 | .pushConfig( 142 | PushConfigRequestObject.builder() 143 | .version(PushVersion.V2) 144 | .offlineOnly(false) 145 | .build()) 146 | .request()); 147 | Assertions.assertDoesNotThrow( 148 | () -> 149 | App.checkPush() 150 | .messageId(message.getId()) 151 | .skipDevices(true) 152 | .userId(secondUserId) 153 | .request()); 154 | } 155 | 156 | @DisplayName("Can revoke tokens") 157 | @Test 158 | void whenRevokingTokens_thenNoException() { 159 | Calendar calendar = new GregorianCalendar(); 160 | calendar.add(Calendar.DAY_OF_MONTH, -1); 161 | Assertions.assertDoesNotThrow(() -> App.revokeTokens(calendar.getTime()).request()); 162 | } 163 | 164 | @DisplayName("App Settings update size limit does not throw Exception") 165 | @Test 166 | void whenUpdatingAppSettingsSizeLimit_thenNoException() { 167 | AppConfig appConfig = Assertions.assertDoesNotThrow(() -> App.get().request()).getApp(); 168 | int newSizeLimit = (new Random()).nextInt(100 * 1024 * 1024); 169 | Assertions.assertDoesNotThrow( 170 | () -> 171 | App.update() 172 | .fileUploadConfig( 173 | App.FileUploadConfigRequestObject.builder().sizeLimit(newSizeLimit).build()) 174 | .request()); 175 | 176 | appConfig = Assertions.assertDoesNotThrow(() -> App.get().request()).getApp(); 177 | Assertions.assertEquals(newSizeLimit, appConfig.getFileUploadConfig().getSizeLimit()); 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/BlockUserTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.models.*; 4 | import io.getstream.chat.java.models.BlockUser.*; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.DisplayName; 7 | import org.junit.jupiter.api.Test; 8 | 9 | public class BlockUserTest extends BasicTest { 10 | @Test 11 | @DisplayName("Block User") 12 | void blockUserGetUnBlock() { 13 | Assertions.assertDoesNotThrow( 14 | () -> { 15 | var channel = Assertions.assertDoesNotThrow(BasicTest::createRandomChannel).getChannel(); 16 | Assertions.assertNotNull(channel); 17 | 18 | var blockingUser = testUsersRequestObjects.get(0); 19 | var blockedUser = testUsersRequestObjects.get(1); 20 | BlockUser.BlockUserRequestData.BlockUserRequest blockRequest = 21 | BlockUser.blockUser().blockedUserID(blockedUser.getId()).userID(blockingUser.getId()); 22 | BlockUser.BlockUserResponse blockResponse = blockRequest.request(); 23 | Assertions.assertEquals(blockResponse.getBlockedByUserID(), blockingUser.getId()); 24 | Assertions.assertEquals(blockResponse.getBlockedUserID(), blockedUser.getId()); 25 | Assertions.assertNotNull(blockResponse.getCreatedAt()); 26 | 27 | BlockUser.GetBlockedUsersRequestData.GetBlockedUsersRequest getBlockedUsersRequest = 28 | BlockUser.getBlockedUsers(blockingUser.getId()); 29 | 30 | BlockUser.GetBlockedUsersResponse getBlockedUsersResponse = 31 | getBlockedUsersRequest.request(); 32 | Assertions.assertFalse(getBlockedUsersResponse.getBlockedUsers().isEmpty()); 33 | Assertions.assertEquals( 34 | getBlockedUsersResponse.getBlockedUsers().get(0).getBlockedUserID(), 35 | blockedUser.getId()); 36 | 37 | var users = User.list().filterCondition("id", blockingUser.getId()).request(); 38 | Assertions.assertNotNull(users.getUsers().get(0).getBlockedUserIDs()); 39 | Assertions.assertEquals( 40 | users.getUsers().get(0).getBlockedUserIDs().get(0), blockedUser.getId()); 41 | 42 | // Unblocking the user 43 | BlockUser.UnblockUserRequestData.UnblockUserRequest unblockRequest = 44 | BlockUser.unblockUser() 45 | .blockedUserID(blockedUser.getId()) 46 | .userID(blockingUser.getId()); 47 | 48 | BlockUser.UnblockUserResponse unblockResponse = unblockRequest.request(); 49 | Assertions.assertNotNull(unblockResponse); 50 | 51 | // Verify user is unblocked 52 | getBlockedUsersRequest = BlockUser.getBlockedUsers(blockingUser.getId()); 53 | 54 | getBlockedUsersResponse = getBlockedUsersRequest.request(); 55 | Assertions.assertTrue(getBlockedUsersResponse.getBlockedUsers().isEmpty()); 56 | 57 | users = User.list().filterCondition("id", blockingUser.getId()).request(); 58 | Assertions.assertTrue( 59 | users.getUsers().get(0).getBlockedUserIDs() == null 60 | || users.getUsers().get(0).getBlockedUserIDs().isEmpty()); 61 | }); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/BlocklistTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.models.Blocklist; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import org.apache.commons.lang3.RandomStringUtils; 7 | import org.junit.jupiter.api.Assertions; 8 | import org.junit.jupiter.api.DisplayName; 9 | import org.junit.jupiter.api.Test; 10 | 11 | public class BlocklistTest extends BasicTest { 12 | 13 | @DisplayName("Can create blocklist") 14 | @Test 15 | void whenCreatingBlocklist_thenNoException() { 16 | Assertions.assertDoesNotThrow( 17 | () -> 18 | Blocklist.create() 19 | .name(RandomStringUtils.randomAlphabetic(5)) 20 | .words(Arrays.asList(RandomStringUtils.randomAlphabetic(10))) 21 | .request()); 22 | } 23 | 24 | @DisplayName("Can update blocklist") 25 | @Test 26 | void whenUpdatingBlocklist_thenNoException() { 27 | String name = RandomStringUtils.randomAlphabetic(5); 28 | Assertions.assertDoesNotThrow( 29 | () -> 30 | Blocklist.create() 31 | .name(name) 32 | .words(Arrays.asList(RandomStringUtils.randomAlphabetic(10))) 33 | .request()); 34 | pause(); 35 | Assertions.assertDoesNotThrow( 36 | () -> 37 | Blocklist.update(name) 38 | .words(Arrays.asList(RandomStringUtils.randomAlphabetic(10))) 39 | .request()); 40 | } 41 | 42 | @DisplayName("Can retrieve blocklist") 43 | @Test 44 | void whenRetrievingBlocklist_thenCorrectDescription() { 45 | String name = RandomStringUtils.randomAlphabetic(5); 46 | Assertions.assertDoesNotThrow( 47 | () -> 48 | Blocklist.create() 49 | .name(name) 50 | .words(Arrays.asList(RandomStringUtils.randomAlphabetic(10))) 51 | .request()); 52 | pause(); 53 | Blocklist retrievedBlocklist = 54 | Assertions.assertDoesNotThrow(() -> Blocklist.get(name).request()).getBlocklist(); 55 | Assertions.assertEquals(name, retrievedBlocklist.getName()); 56 | } 57 | 58 | @DisplayName("Can delete blocklist") 59 | @Test 60 | void whenDeletingBlocklist_thenDeleted() { 61 | String name = RandomStringUtils.randomAlphabetic(5); 62 | Assertions.assertDoesNotThrow( 63 | () -> 64 | Blocklist.create() 65 | .name(name) 66 | .words(Arrays.asList(RandomStringUtils.randomAlphabetic(10))) 67 | .request()); 68 | pause(); 69 | Assertions.assertDoesNotThrow(() -> Blocklist.delete(name).request()); 70 | pause(); 71 | List blocklists = 72 | Assertions.assertDoesNotThrow(() -> Blocklist.list().request()).getBlocklists(); 73 | Assertions.assertFalse( 74 | blocklists.stream() 75 | .anyMatch(consideredBlocklist -> consideredBlocklist.getName().equals(name))); 76 | } 77 | 78 | @DisplayName("Can list blocklists") 79 | @Test 80 | void whenListingBlocklist_thenCanRetrieve() { 81 | String name = RandomStringUtils.randomAlphabetic(5); 82 | Assertions.assertDoesNotThrow( 83 | () -> 84 | Blocklist.create() 85 | .name(name) 86 | .words(Arrays.asList(RandomStringUtils.randomAlphabetic(10))) 87 | .request()); 88 | pause(); 89 | List blocklists = 90 | Assertions.assertDoesNotThrow(() -> Blocklist.list().request()).getBlocklists(); 91 | Assertions.assertTrue( 92 | blocklists.stream() 93 | .anyMatch(consideredBlocklist -> consideredBlocklist.getName().equals(name))); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/CommandTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.models.Command; 4 | import java.util.List; 5 | import org.apache.commons.lang3.RandomStringUtils; 6 | import org.junit.jupiter.api.Assertions; 7 | import org.junit.jupiter.api.DisplayName; 8 | import org.junit.jupiter.api.Test; 9 | 10 | public class CommandTest extends BasicTest { 11 | 12 | @DisplayName("Can create command") 13 | @Test 14 | void whenCreatingCommand_thenCorrectDescription() { 15 | String description = "test description"; 16 | Command command = 17 | Assertions.assertDoesNotThrow( 18 | () -> 19 | Command.create() 20 | .name(RandomStringUtils.randomAlphabetic(5)) 21 | .description(description) 22 | .request()) 23 | .getCommand(); 24 | Assertions.assertEquals(description, command.getDescription()); 25 | } 26 | 27 | @DisplayName("Can update command") 28 | @Test 29 | void whenUpdatingCommand_thenCorrectDescription() { 30 | String description = "test description"; 31 | Command command = 32 | Assertions.assertDoesNotThrow( 33 | () -> 34 | Command.create() 35 | .name(RandomStringUtils.randomAlphabetic(5)) 36 | .description(description) 37 | .request()) 38 | .getCommand(); 39 | pause(); 40 | String updatedDescription = "updated description"; 41 | Command updatedCommand = 42 | Assertions.assertDoesNotThrow( 43 | () -> Command.update(command.getName()).description(updatedDescription).request()) 44 | .getCommand(); 45 | Assertions.assertEquals(updatedDescription, updatedCommand.getDescription()); 46 | } 47 | 48 | @DisplayName("Can retrieve command") 49 | @Test 50 | void whenRetrievingCommand_thenCorrectDescription() { 51 | String description = "test description"; 52 | Command command = 53 | Assertions.assertDoesNotThrow( 54 | () -> 55 | Command.create() 56 | .name(RandomStringUtils.randomAlphabetic(5)) 57 | .description(description) 58 | .request()) 59 | .getCommand(); 60 | pause(); 61 | Command retrievedCommand = 62 | Assertions.assertDoesNotThrow(() -> Command.get(command.getName()).request()); 63 | Assertions.assertEquals(command.getName(), retrievedCommand.getName()); 64 | } 65 | 66 | @DisplayName("Can delete command") 67 | @Test 68 | void whenDeletingCommand_thenDeleted() { 69 | String description = "test description"; 70 | Command command = 71 | Assertions.assertDoesNotThrow( 72 | () -> 73 | Command.create() 74 | .name(RandomStringUtils.randomAlphabetic(5)) 75 | .description(description) 76 | .request()) 77 | .getCommand(); 78 | pause(); 79 | Assertions.assertDoesNotThrow(() -> Command.delete(command.getName()).request()); 80 | pause(); 81 | List commands = 82 | Assertions.assertDoesNotThrow(() -> Command.list().request()).getCommands(); 83 | Assertions.assertFalse( 84 | commands.stream() 85 | .anyMatch(consideredCommand -> consideredCommand.getName().equals(command.getName()))); 86 | } 87 | 88 | @DisplayName("Can list commands") 89 | @Test 90 | void whenListingCommand_thenCanRetrieve() { 91 | String description = "test description"; 92 | Command command = 93 | Assertions.assertDoesNotThrow( 94 | () -> 95 | Command.create() 96 | .name(RandomStringUtils.randomAlphabetic(5)) 97 | .description(description) 98 | .request()) 99 | .getCommand(); 100 | pause(); 101 | List commands = 102 | Assertions.assertDoesNotThrow(() -> Command.list().request()).getCommands(); 103 | Assertions.assertTrue( 104 | commands.stream() 105 | .anyMatch(consideredCommand -> consideredCommand.getName().equals(command.getName()))); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/DeviceTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.models.App.PushProviderType; 4 | import io.getstream.chat.java.models.Device; 5 | import java.util.List; 6 | import org.apache.commons.lang3.RandomStringUtils; 7 | import org.junit.jupiter.api.Assertions; 8 | import org.junit.jupiter.api.DisplayName; 9 | import org.junit.jupiter.api.Test; 10 | 11 | public class DeviceTest extends BasicTest { 12 | 13 | @DisplayName("Can create device") 14 | @Test 15 | void whenCreatingDevice_thenNoException() { 16 | Assertions.assertDoesNotThrow( 17 | () -> 18 | Device.create() 19 | .id(RandomStringUtils.randomAlphabetic(10)) 20 | .user(testUserRequestObject) 21 | .pushProvider(PushProviderType.Apn) 22 | .request()); 23 | } 24 | 25 | @DisplayName("Can delete device") 26 | @Test 27 | void whenDeletingDevice_thenDeleted() { 28 | String deviceId = RandomStringUtils.randomAlphabetic(10); 29 | Assertions.assertDoesNotThrow( 30 | () -> 31 | Device.create() 32 | .id(deviceId) 33 | .user(testUserRequestObject) 34 | .pushProvider(PushProviderType.Apn) 35 | .request()); 36 | Assertions.assertDoesNotThrow( 37 | () -> Device.delete(deviceId, testUserRequestObject.getId()).request()); 38 | List devices = 39 | Assertions.assertDoesNotThrow(() -> Device.list(testUserRequestObject.getId()).request()) 40 | .getDevices(); 41 | Assertions.assertFalse( 42 | devices.stream().anyMatch(consideredDevice -> consideredDevice.getId().equals(deviceId))); 43 | } 44 | 45 | @DisplayName("Can list devices") 46 | @Test 47 | void whenListingCommand_thenCanRetrieve() { 48 | String deviceId = RandomStringUtils.randomAlphabetic(10); 49 | Assertions.assertDoesNotThrow( 50 | () -> 51 | Device.create() 52 | .id(deviceId) 53 | .user(testUserRequestObject) 54 | .pushProvider(PushProviderType.Apn) 55 | .request()); 56 | List devices = 57 | Assertions.assertDoesNotThrow(() -> Device.list(testUserRequestObject.getId()).request()) 58 | .getDevices(); 59 | Assertions.assertTrue( 60 | devices.stream().anyMatch(consideredDevice -> consideredDevice.getId().equals(deviceId))); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/EventTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.models.Event; 4 | import io.getstream.chat.java.models.Event.EventRequestObject; 5 | import io.getstream.chat.java.models.Event.EventUserCustomRequestObject; 6 | import org.apache.commons.lang3.RandomStringUtils; 7 | import org.junit.jupiter.api.Assertions; 8 | import org.junit.jupiter.api.DisplayName; 9 | import org.junit.jupiter.api.Test; 10 | 11 | public class EventTest extends BasicTest { 12 | 13 | @DisplayName("Can send event") 14 | @Test 15 | void whenSendingEvent_thenEventIsCreated() { 16 | String eventType = RandomStringUtils.randomAlphabetic(10); 17 | Event event = 18 | Assertions.assertDoesNotThrow( 19 | () -> 20 | Event.send(testChannel.getType(), testChannel.getId()) 21 | .event( 22 | EventRequestObject.builder() 23 | .type(eventType) 24 | .user(testUserRequestObject) 25 | .build()) 26 | .request()) 27 | .getEvent(); 28 | Assertions.assertEquals(eventType, event.getType()); 29 | } 30 | 31 | @DisplayName("Can send user custom event") 32 | @Test 33 | void whenSendingCustomEvent_thenNoException() { 34 | Assertions.assertDoesNotThrow( 35 | () -> 36 | Event.sendUserCustom(testUserRequestObject.getId()) 37 | .event( 38 | EventUserCustomRequestObject.builder() 39 | .type(RandomStringUtils.randomAlphabetic(10)) 40 | .additionalField("customField", "customValue") 41 | .build()) 42 | .request()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/ExportUsersTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.models.*; 4 | import java.util.List; 5 | import org.apache.commons.lang3.RandomStringUtils; 6 | import org.junit.jupiter.api.Assertions; 7 | import org.junit.jupiter.api.DisplayName; 8 | import org.junit.jupiter.api.Test; 9 | 10 | public class ExportUsersTest extends BasicTest { 11 | @DisplayName("Export users") 12 | @Test 13 | void exportUsersTest() { 14 | var userId = RandomStringUtils.randomAlphabetic(10); 15 | Assertions.assertDoesNotThrow( 16 | () -> User.upsert().user(User.UserRequestObject.builder().id(userId).build()).request()); 17 | 18 | var userIds = List.of(userId); 19 | var exportUsersResponse = 20 | Assertions.assertDoesNotThrow(() -> ExportUsers.exportUsers(userIds).request()); 21 | Assertions.assertNotEquals("", exportUsersResponse.getTaskId()); 22 | 23 | var taskId = exportUsersResponse.getTaskId(); 24 | 25 | var taskCompleted = false; 26 | for (int i = 0; i < 10; i++) { 27 | var taskStatus = 28 | Assertions.assertDoesNotThrow(() -> TaskStatus.get(taskId).request()).getStatus(); 29 | if (taskStatus.equals("completed")) { 30 | taskCompleted = true; 31 | break; 32 | } 33 | Assertions.assertDoesNotThrow(() -> java.lang.Thread.sleep(500)); 34 | } 35 | Assertions.assertTrue(taskCompleted); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/FlagTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.models.Flag; 4 | import io.getstream.chat.java.models.Flag.FlagMessageQueryResponse; 5 | import io.getstream.chat.java.models.Message; 6 | import io.getstream.chat.java.models.User; 7 | import io.getstream.chat.java.models.User.UserRequestObject; 8 | import org.apache.commons.lang3.RandomStringUtils; 9 | import org.junit.jupiter.api.Assertions; 10 | import org.junit.jupiter.api.DisplayName; 11 | import org.junit.jupiter.api.Test; 12 | 13 | public class FlagTest extends BasicTest { 14 | 15 | @DisplayName("Can flag a message") 16 | @Test 17 | void whenFlaggingAMessage_thenIsFlagged() { 18 | Message message = Assertions.assertDoesNotThrow(() -> sendTestMessage()); 19 | Flag flag = 20 | Assertions.assertDoesNotThrow( 21 | () -> 22 | Flag.create() 23 | .targetMessageId(message.getId()) 24 | .user(testUserRequestObject) 25 | .request()) 26 | .getFlag(); 27 | Assertions.assertEquals(message.getId(), flag.getTargetMessageId()); 28 | } 29 | 30 | @DisplayName("Can flag a user") 31 | @Test 32 | void whenFlaggingAUser_thenIsFlagged() { 33 | UserRequestObject userRequestObject = 34 | UserRequestObject.builder() 35 | .id(RandomStringUtils.randomAlphabetic(10)) 36 | .name("User to flag") 37 | .build(); 38 | Assertions.assertDoesNotThrow(() -> User.upsert().user(userRequestObject).request()); 39 | Flag flag = 40 | Assertions.assertDoesNotThrow( 41 | () -> 42 | Flag.create() 43 | .targetUserId(userRequestObject.getId()) 44 | .user(testUserRequestObject) 45 | .request()) 46 | .getFlag(); 47 | Assertions.assertEquals(userRequestObject.getId(), flag.getTargetUser().getId()); 48 | } 49 | 50 | @DisplayName("Can unflag a message") 51 | @Test 52 | void whenUnFlaggingAMessage_thenNoException() { 53 | Message message = Assertions.assertDoesNotThrow(() -> sendTestMessage()); 54 | Assertions.assertDoesNotThrow( 55 | () -> Flag.create().targetMessageId(message.getId()).user(testUserRequestObject).request()); 56 | Assertions.assertDoesNotThrow( 57 | () -> 58 | Flag.delete() 59 | .targetMessageId(message.getId()) 60 | .user(testUserRequestObject) 61 | .request()) 62 | .getFlag(); 63 | } 64 | 65 | @DisplayName("Can unflag a user") 66 | @Test 67 | void whenUnFlaggingAUser_thenNoException() { 68 | UserRequestObject userRequestObject = 69 | UserRequestObject.builder() 70 | .id(RandomStringUtils.randomAlphabetic(10)) 71 | .name("User to flag") 72 | .build(); 73 | Assertions.assertDoesNotThrow(() -> User.upsert().user(userRequestObject).request()); 74 | Assertions.assertDoesNotThrow( 75 | () -> 76 | Flag.create() 77 | .targetUserId(userRequestObject.getId()) 78 | .user(testUserRequestObject) 79 | .request()); 80 | Assertions.assertDoesNotThrow( 81 | () -> 82 | Flag.delete() 83 | .targetUserId(userRequestObject.getId()) 84 | .user(testUserRequestObject) 85 | .request()); 86 | } 87 | 88 | @DisplayName("Can search flagged messages") 89 | @Test 90 | void whenQueryingMessageFlags_thenRetrieved() { 91 | Message message = Assertions.assertDoesNotThrow(() -> sendTestMessage()); 92 | Assertions.assertDoesNotThrow( 93 | () -> 94 | Flag.create() 95 | .targetMessageId(message.getId()) 96 | .user(testUserRequestObject) 97 | .request()) 98 | .getFlag(); 99 | FlagMessageQueryResponse response = 100 | Assertions.assertDoesNotThrow( 101 | () -> 102 | Message.queryFlags() 103 | .filterCondition("user_id", testUserRequestObject.getId()) 104 | .user(testUserRequestObject) 105 | .request()); 106 | Assertions.assertTrue( 107 | response.getFlags().stream() 108 | .anyMatch(flag -> flag.getMessage().getId().equals(message.getId()))); 109 | } 110 | 111 | @DisplayName("Can look up flag reports") 112 | @Test 113 | void whenQueryingFlagReports_thenRetrieved() { 114 | Message message = Assertions.assertDoesNotThrow(() -> sendTestMessage()); 115 | Assertions.assertDoesNotThrow( 116 | () -> Flag.create().targetMessageId(message.getId()).user(testUserRequestObject).request()); 117 | var flagReports = 118 | Assertions.assertDoesNotThrow( 119 | () -> 120 | Flag.queryFlagReports() 121 | .filterCondition("message_id", message.getId()) 122 | .request() 123 | .getFlagReports()); 124 | Assertions.assertEquals(message.getId(), flagReports.get(0).getMessage().getId()); 125 | } 126 | 127 | @DisplayName("Can send flag report") 128 | @Test 129 | void whenReviewingFlagReports_thenSucceeds() { 130 | Message message = Assertions.assertDoesNotThrow(() -> sendTestMessage()); 131 | Assertions.assertDoesNotThrow( 132 | () -> Flag.create().targetMessageId(message.getId()).user(testUserRequestObject).request()); 133 | var flagReports = 134 | Assertions.assertDoesNotThrow( 135 | () -> 136 | Flag.queryFlagReports() 137 | .filterCondition("message_id", message.getId()) 138 | .request() 139 | .getFlagReports()); 140 | Assertions.assertEquals(message.getId(), flagReports.get(0).getMessage().getId()); 141 | 142 | var report = 143 | Assertions.assertDoesNotThrow( 144 | () -> 145 | Flag.reviewFlagReport(flagReports.get(0).getId()) 146 | .reviewResult("reviewed") 147 | .userId(testUserRequestObject.getId()) 148 | .request() 149 | .getFlagReport()); 150 | Assertions.assertEquals(message.getId(), report.getMessage().getId()); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/ImportTests.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.models.Import; 4 | import okhttp3.*; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.DisplayName; 7 | import org.junit.jupiter.api.Test; 8 | 9 | public class ImportTests extends BasicTest { 10 | @DisplayName("Can run imports") 11 | @Test 12 | void importTestEnd2End() { 13 | String fileName = "streamchatjava.json"; 14 | var createUrlResponse = 15 | Assertions.assertDoesNotThrow(() -> Import.createImportUrl(fileName).request()); 16 | Assertions.assertTrue(createUrlResponse.getPath().endsWith(fileName)); 17 | 18 | uploadJsonToS3(createUrlResponse); 19 | 20 | var createImportResponse = 21 | Assertions.assertDoesNotThrow( 22 | () -> 23 | Import.createImport(createUrlResponse.getPath(), Import.ImportMode.Upsert) 24 | .request()); 25 | 26 | var getImportResponse = 27 | Assertions.assertDoesNotThrow( 28 | () -> Import.getImport(createImportResponse.getImportTask().getId()).request()); 29 | Assertions.assertEquals( 30 | createImportResponse.getImportTask().getId(), getImportResponse.getImportTask().getId()); 31 | 32 | var listImportResponse = 33 | Assertions.assertDoesNotThrow(() -> Import.listImports(1, 0).request()); 34 | Assertions.assertEquals(1, listImportResponse.getImportTasks().size()); 35 | } 36 | 37 | private void uploadJsonToS3(Import.CreateImportUrlResponse createUrlResponse) { 38 | var client = 39 | new OkHttpClient.Builder() 40 | .addNetworkInterceptor( 41 | chain -> { 42 | var request = 43 | chain 44 | .request() 45 | .newBuilder() 46 | .removeHeader("Accept-Encoding") 47 | .removeHeader("User-Agent") 48 | .removeHeader("Connection") 49 | .removeHeader("Content-Type") 50 | .addHeader("Content-Type", "application/json") 51 | .build(); 52 | 53 | return chain.proceed(request); 54 | }) 55 | .build(); 56 | 57 | var request = 58 | new Request.Builder() 59 | .url(createUrlResponse.getUploadUrl()) 60 | .put(RequestBody.create(MediaType.parse("application/json"), "{}")) 61 | .build(); 62 | 63 | var response = Assertions.assertDoesNotThrow(() -> client.newCall(request).execute()); 64 | Assertions.assertEquals(200, response.code()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/MessageHistoryTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.models.FilterCondition; 4 | import io.getstream.chat.java.models.Message; 5 | import io.getstream.chat.java.models.Message.MessageRequestObject; 6 | import io.getstream.chat.java.models.MessageHistory; 7 | import io.getstream.chat.java.models.Sort; 8 | import io.getstream.chat.java.models.Sort.Direction; 9 | import org.junit.jupiter.api.Assertions; 10 | import org.junit.jupiter.api.DisplayName; 11 | import org.junit.jupiter.api.Test; 12 | 13 | public class MessageHistoryTest extends BasicTest { 14 | @Test 15 | @DisplayName("Can get message history") 16 | void whenMessageUpdated_thenGetHistory() { 17 | Assertions.assertDoesNotThrow( 18 | () -> { 19 | var channel = Assertions.assertDoesNotThrow(BasicTest::createRandomChannel).getChannel(); 20 | Assertions.assertNotNull(channel); 21 | 22 | final var initialText = "initial text"; 23 | final var customField = "custom_field"; 24 | final var initialCustomFieldValue = "custom value"; 25 | MessageRequestObject messageRequest = 26 | MessageRequestObject.builder() 27 | .text(initialText) 28 | .userId(testUserRequestObject.getId()) 29 | .additionalField(customField, initialCustomFieldValue) 30 | .build(); 31 | var message = 32 | Message.send(channel.getType(), channel.getId()) 33 | .message(messageRequest) 34 | .request() 35 | .getMessage(); 36 | 37 | final var updatedText1 = "updated text"; 38 | final var updatedCustomFieldValue = "updated custom value"; 39 | Assertions.assertDoesNotThrow( 40 | () -> 41 | Message.update(message.getId()) 42 | .message( 43 | MessageRequestObject.builder() 44 | .text(updatedText1) 45 | .userId(testUserRequestObject.getId()) 46 | .additionalField(customField, updatedCustomFieldValue) 47 | .build()) 48 | .request()); 49 | 50 | final var updatedText2 = "updated text 2"; 51 | var secondUser = testUsersRequestObjects.get(1); 52 | var r = 53 | Assertions.assertDoesNotThrow( 54 | () -> 55 | Message.update(message.getId()) 56 | .message( 57 | MessageRequestObject.builder() 58 | .text(updatedText2) 59 | .userId(secondUser.getId()) 60 | .build()) 61 | .request()) 62 | .getMessage(); 63 | Assertions.assertEquals(updatedText2, r.getText()); 64 | 65 | var messageHistoryQueryRequest = 66 | MessageHistory.query().filter(FilterCondition.eq("message_id", message.getId())); 67 | 68 | var messageHistoryResponse = 69 | Assertions.assertDoesNotThrow(() -> messageHistoryQueryRequest.request()); 70 | 71 | var history = messageHistoryResponse.getMessageHistory(); 72 | Assertions.assertEquals(2, history.size()); 73 | 74 | var firstUpdate = history.get(1); 75 | Assertions.assertEquals(initialText, firstUpdate.getText()); 76 | Assertions.assertEquals( 77 | testUserRequestObject.getId(), firstUpdate.getMessageUpdatedById()); 78 | Assertions.assertEquals( 79 | initialCustomFieldValue, firstUpdate.getAdditionalFields().get(customField)); 80 | var secondUpdate = history.get(0); 81 | Assertions.assertEquals(updatedText1, secondUpdate.getText()); 82 | Assertions.assertEquals( 83 | testUserRequestObject.getId(), secondUpdate.getMessageUpdatedById()); 84 | Assertions.assertEquals( 85 | updatedCustomFieldValue, secondUpdate.getAdditionalFields().get(customField)); 86 | 87 | // Test sorting 88 | var sortedHistory = 89 | Assertions.assertDoesNotThrow( 90 | () -> 91 | MessageHistory.query() 92 | .filter(FilterCondition.eq("message_id", message.getId())) 93 | .sort( 94 | Sort.builder() 95 | .field("message_updated_at") 96 | .direction(Direction.ASC) 97 | .build()) 98 | .request()) 99 | .getMessageHistory(); 100 | 101 | Assertions.assertEquals(2, sortedHistory.size()); 102 | 103 | firstUpdate = sortedHistory.get(0); 104 | Assertions.assertEquals(initialText, firstUpdate.getText()); 105 | Assertions.assertEquals( 106 | testUserRequestObject.getId(), firstUpdate.getMessageUpdatedById()); 107 | 108 | secondUpdate = sortedHistory.get(1); 109 | Assertions.assertEquals(updatedText1, secondUpdate.getText()); 110 | Assertions.assertEquals( 111 | testUserRequestObject.getId(), secondUpdate.getMessageUpdatedById()); 112 | }); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/ModerationTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.exceptions.StreamException; 4 | import io.getstream.chat.java.models.Moderation; 5 | import io.getstream.chat.java.models.Moderation.*; 6 | import java.util.List; 7 | import org.junit.jupiter.api.Assertions; 8 | import org.junit.jupiter.api.DisplayName; 9 | import org.junit.jupiter.api.Test; 10 | 11 | public class ModerationTest extends BasicTest { 12 | 13 | @DisplayName("Can upsert, get and delete moderation config") 14 | @Test 15 | void whenUpsertingGetttingDeletingModerationConfig_thenNoException() { 16 | final String blocklistName = "profanity_en_2020_v1"; 17 | BlockListRule rule = 18 | BlockListRule.builder().name(blocklistName).action(Moderation.Action.REMOVE).build(); 19 | 20 | String key = "chat:messaging:1234"; 21 | Assertions.assertDoesNotThrow( 22 | () -> 23 | Moderation.upsertConfig(key) 24 | .blockListConfig( 25 | BlockListConfigRequestObject.builder().rules(List.of(rule)).build()) 26 | .request()); 27 | 28 | ConfigGetResponse response = 29 | Assertions.assertDoesNotThrow(() -> Moderation.getConfig(key).request()); 30 | 31 | Assertions.assertEquals( 32 | blocklistName, response.getConfig().getBlockListConfig().getRules().get(0).getName()); 33 | 34 | Assertions.assertDoesNotThrow(() -> Moderation.deleteConfig(key).request()); 35 | 36 | Assertions.assertThrows(StreamException.class, () -> Moderation.getConfig(key).request()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/PermissionTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.models.Permission; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | import org.apache.commons.lang3.RandomStringUtils; 8 | import org.junit.jupiter.api.Assertions; 9 | import org.junit.jupiter.api.DisplayName; 10 | import org.junit.jupiter.api.Test; 11 | 12 | public class PermissionTest extends BasicTest { 13 | 14 | @DisplayName("Can create permission") 15 | @Test 16 | void whenCreatingPermission_thenNoException() { 17 | String name = RandomStringUtils.randomAlphabetic(10); 18 | Map condition = new HashMap<>(); 19 | condition.put("$subject.magic_custom_field", "magic_value"); 20 | Assertions.assertDoesNotThrow( 21 | () -> 22 | Permission.create() 23 | .id(RandomStringUtils.randomAlphabetic(10)) 24 | .name(name) 25 | .action("DeleteChannel") 26 | .condition(condition) 27 | .request()); 28 | } 29 | 30 | @DisplayName("Can update permission") 31 | @Test 32 | void whenUpdatingPermission_thenNoException() { 33 | String name = RandomStringUtils.randomAlphabetic(10); 34 | String id = RandomStringUtils.randomAlphabetic(10); 35 | Map condition = new HashMap<>(); 36 | condition.put("$subject.magic_custom_field", "magic_value"); 37 | Assertions.assertDoesNotThrow( 38 | () -> 39 | Permission.create() 40 | .id(id) 41 | .name(name) 42 | .action("DeleteChannel") 43 | .condition(condition) 44 | .request()); 45 | pause(); 46 | Assertions.assertDoesNotThrow( 47 | () -> 48 | Permission.update(id, name) 49 | .action("DeleteChannel") 50 | .condition(condition) 51 | .owner(true) 52 | .request()); 53 | } 54 | 55 | @DisplayName("Can retrieve permission") 56 | @Test 57 | void whenRetrievingPermission_thenCorrectName() { 58 | String name = RandomStringUtils.randomAlphabetic(10); 59 | String id = RandomStringUtils.randomAlphabetic(10); 60 | Map condition = new HashMap<>(); 61 | condition.put("$subject.magic_custom_field", "magic_value"); 62 | Assertions.assertDoesNotThrow( 63 | () -> 64 | Permission.create() 65 | .id(id) 66 | .name(name) 67 | .action("DeleteChannel") 68 | .condition(condition) 69 | .request()); 70 | pause(); 71 | Permission retrievedPermission = 72 | Assertions.assertDoesNotThrow(() -> Permission.get(id).request()).getPermission(); 73 | Assertions.assertEquals(id, retrievedPermission.getId()); 74 | } 75 | 76 | @DisplayName("Can delete permission") 77 | @Test 78 | void whenDeletingPermission_thenDeleted() { 79 | String name = RandomStringUtils.randomAlphabetic(10); 80 | String id = RandomStringUtils.randomAlphabetic(10); 81 | Map condition = new HashMap<>(); 82 | condition.put("$subject.magic_custom_field", "magic_value"); 83 | Assertions.assertDoesNotThrow( 84 | () -> 85 | Permission.create() 86 | .id(id) 87 | .name(name) 88 | .action("DeleteChannel") 89 | .condition(condition) 90 | .request()); 91 | pause(); 92 | Assertions.assertDoesNotThrow(() -> Permission.delete(id).request()); 93 | pause(); 94 | List permissions = 95 | Assertions.assertDoesNotThrow(() -> Permission.list().request()).getPermissions(); 96 | Assertions.assertFalse( 97 | permissions.stream() 98 | .anyMatch(consideredPermission -> consideredPermission.getId().equals(id))); 99 | } 100 | 101 | @DisplayName("Can list permissions") 102 | @Test 103 | void whenListingPermission_thenCanRetrieve() { 104 | String name = RandomStringUtils.randomAlphabetic(10); 105 | String id = RandomStringUtils.randomAlphabetic(10); 106 | Map condition = new HashMap<>(); 107 | condition.put("$subject.magic_custom_field", "magic_value"); 108 | Assertions.assertDoesNotThrow( 109 | () -> 110 | Permission.create() 111 | .id(id) 112 | .name(name) 113 | .action("DeleteChannel") 114 | .condition(condition) 115 | .request()); 116 | pause(); 117 | List permissions = 118 | Assertions.assertDoesNotThrow(() -> Permission.list().request()).getPermissions(); 119 | Assertions.assertTrue( 120 | permissions.stream() 121 | .anyMatch(consideredPermission -> consideredPermission.getId().equals(id))); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/ReactionTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.models.Reaction; 4 | import io.getstream.chat.java.models.Reaction.ReactionRequestObject; 5 | import java.util.List; 6 | import org.apache.commons.lang3.RandomStringUtils; 7 | import org.junit.jupiter.api.Assertions; 8 | import org.junit.jupiter.api.DisplayName; 9 | import org.junit.jupiter.api.Test; 10 | 11 | public class ReactionTest extends BasicTest { 12 | 13 | @DisplayName("Can send reaction") 14 | @Test 15 | void whenSendingReaction_thenNoException() { 16 | String reactionType = RandomStringUtils.randomAlphabetic(10); 17 | Reaction reaction = 18 | Assertions.assertDoesNotThrow( 19 | () -> 20 | Reaction.send(testMessage.getId()) 21 | .reaction( 22 | ReactionRequestObject.builder() 23 | .type(reactionType) 24 | .user(testUserRequestObject) 25 | .build()) 26 | .request()) 27 | .getReaction(); 28 | Assertions.assertEquals(reactionType, reaction.getType()); 29 | } 30 | 31 | @DisplayName("Cannot send multiple reactions if enforce unique") 32 | @Test 33 | void whenSendingMultipleReactionAndEnforceUnique_thenDoesNotCreateSecond() { 34 | String reactionType = RandomStringUtils.randomAlphabetic(10); 35 | Assertions.assertDoesNotThrow( 36 | () -> 37 | Reaction.send(testMessage.getId()) 38 | .reaction( 39 | ReactionRequestObject.builder() 40 | .type(reactionType) 41 | .user(testUserRequestObject) 42 | .build()) 43 | .request()) 44 | .getReaction(); 45 | Assertions.assertDoesNotThrow( 46 | () -> 47 | Reaction.send(testMessage.getId()) 48 | .reaction( 49 | ReactionRequestObject.builder() 50 | .type(reactionType) 51 | .user(testUserRequestObject) 52 | .build()) 53 | .enforceUnique(true) 54 | .request()); 55 | List reactions = 56 | Assertions.assertDoesNotThrow(() -> Reaction.list(testMessage.getId()).request()) 57 | .getReactions(); 58 | Assertions.assertEquals( 59 | 1, 60 | reactions.stream() 61 | .filter(consideredReaction -> consideredReaction.getType().equals(reactionType)) 62 | .count()); 63 | } 64 | 65 | @DisplayName("Can delete reaction") 66 | @Test 67 | void whenDeletingReaction_thenIsDeleted() { 68 | String reactionType = RandomStringUtils.randomAlphabetic(10); 69 | Assertions.assertDoesNotThrow( 70 | () -> 71 | Reaction.send(testMessage.getId()) 72 | .reaction( 73 | ReactionRequestObject.builder() 74 | .type(reactionType) 75 | .user(testUserRequestObject) 76 | .build()) 77 | .request()); 78 | Assertions.assertDoesNotThrow( 79 | () -> 80 | Reaction.delete(testMessage.getId(), reactionType) 81 | .userId(testUserRequestObject.getId()) 82 | .request()); 83 | List reactions = 84 | Assertions.assertDoesNotThrow(() -> Reaction.list(testMessage.getId()).request()) 85 | .getReactions(); 86 | Assertions.assertEquals( 87 | 0, 88 | reactions.stream() 89 | .filter(consideredReaction -> consideredReaction.getType().equals(reactionType)) 90 | .count()); 91 | } 92 | 93 | @DisplayName("Can list reactions") 94 | @Test 95 | void whenListingReactions_thenCanRetrieve() { 96 | String reactionType = RandomStringUtils.randomAlphabetic(10); 97 | Assertions.assertDoesNotThrow( 98 | () -> 99 | Reaction.send(testMessage.getId()) 100 | .reaction( 101 | ReactionRequestObject.builder() 102 | .type(reactionType) 103 | .user(testUserRequestObject) 104 | .build()) 105 | .request()) 106 | .getReaction(); 107 | List reactions = 108 | Assertions.assertDoesNotThrow(() -> Reaction.list(testMessage.getId()).request()) 109 | .getReactions(); 110 | Assertions.assertTrue( 111 | reactions.stream() 112 | .anyMatch(consideredReaction -> consideredReaction.getType().equals(reactionType))); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/RoleTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.models.Role; 4 | import java.util.List; 5 | import org.apache.commons.lang3.RandomStringUtils; 6 | import org.junit.jupiter.api.Assertions; 7 | import org.junit.jupiter.api.DisplayName; 8 | import org.junit.jupiter.api.Test; 9 | 10 | public class RoleTest extends BasicTest { 11 | @DisplayName("Can delete a role") 12 | @Test 13 | void whenDeletingRole_thenDeleted() { 14 | String name = RandomStringUtils.randomAlphabetic(5); 15 | Assertions.assertDoesNotThrow(() -> Role.create().name(name).request()); 16 | pause(); 17 | Assertions.assertDoesNotThrow(() -> Role.delete(name).request()); 18 | pause(); 19 | List roles = Assertions.assertDoesNotThrow(() -> Role.list().request()).getRoles(); 20 | Assertions.assertFalse(roles.stream().anyMatch(role -> role.getName().equals(name))); 21 | } 22 | 23 | @DisplayName("Can list roles") 24 | @Test 25 | void whenListingRole_thenCanRetrieve() { 26 | String name = RandomStringUtils.randomAlphabetic(5); 27 | Assertions.assertDoesNotThrow(() -> Role.create().name(name).request()); 28 | pause(); 29 | List roles = Assertions.assertDoesNotThrow(() -> Role.list().request()).getRoles(); 30 | Assertions.assertTrue(roles.stream().anyMatch(role -> role.getName().equals(name))); 31 | for (int i = 0; i < roles.size(); i++) { 32 | Role role = roles.get(i); 33 | if (role.getCustom()) { 34 | Assertions.assertDoesNotThrow(() -> Role.delete(role.getName()).request()); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/io/getstream/chat/java/TaskStatusTest.java: -------------------------------------------------------------------------------- 1 | package io.getstream.chat.java; 2 | 3 | import io.getstream.chat.java.models.Channel; 4 | import io.getstream.chat.java.models.TaskStatus; 5 | import java.util.List; 6 | import org.junit.jupiter.api.Assertions; 7 | import org.junit.jupiter.api.DisplayName; 8 | import org.junit.jupiter.api.Test; 9 | 10 | public class TaskStatusTest extends BasicTest { 11 | @Test 12 | @DisplayName("Can get task status by id") 13 | void whenTaskHasBeenExecuted_thenGetItById() { 14 | Assertions.assertDoesNotThrow( 15 | () -> { 16 | var ch1 = Assertions.assertDoesNotThrow(BasicTest::createRandomChannel).getChannel(); 17 | Assertions.assertNotNull(ch1); 18 | var ch2 = Assertions.assertDoesNotThrow(BasicTest::createRandomChannel).getChannel(); 19 | Assertions.assertNotNull(ch2); 20 | 21 | var cids = List.of(ch1.getCId(), ch2.getCId()); 22 | var taskId = Channel.deleteMany(cids).request().getTaskId(); 23 | waitFor( 24 | () -> { 25 | var taskStatusResponse = 26 | Assertions.assertDoesNotThrow(() -> TaskStatus.get(taskId).request()); 27 | return "completed".equals(taskStatusResponse.getStatus()); 28 | }); 29 | }); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/resources/upload_file.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/stream-chat-java/5c415dba32ea40e867ced2ac004dad057348b6a1/src/test/resources/upload_file.pdf -------------------------------------------------------------------------------- /src/test/resources/upload_file.txt: -------------------------------------------------------------------------------- 1 | This is a sample content -------------------------------------------------------------------------------- /src/test/resources/upload_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/stream-chat-java/5c415dba32ea40e867ced2ac004dad057348b6a1/src/test/resources/upload_image.png --------------------------------------------------------------------------------