-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CXAN-464 Add mentions related models and APIs (#627)
* CXAN-464 Add rich text models and related json adapters * CXAN-464 Add create/edit note APIs with Note parameter * CXAN-464 Add guestName property to Note * Add new fields for mention feature (#629) * CXAN-472 Add the field personalTeamFolderOwner to the FolderConnection * CXAN-472 Add capability team_mention --------- Co-authored-by: Alexander Baltser <[email protected]> --------- Co-authored-by: Alexander Baltser <[email protected]> Co-authored-by: Alexander Baltser <[email protected]>
- Loading branch information
1 parent
3c96373
commit e4f31d4
Showing
21 changed files
with
346 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
api-core/src/main/java/com/vimeo/networking2/internal/adapters/RichTextStringJsonAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.vimeo.networking2.internal.adapters | ||
|
||
import com.squareup.moshi.FromJson | ||
import com.squareup.moshi.JsonAdapter | ||
import com.squareup.moshi.JsonReader | ||
import com.squareup.moshi.JsonWriter | ||
import com.squareup.moshi.ToJson | ||
import com.vimeo.networking2.annotations.RichTextString | ||
import com.vimeo.networking2.richtext.RichText | ||
|
||
/** | ||
* Json adapter for [RichText] properties annotated with [RichTextString]. | ||
*/ | ||
class RichTextStringJsonAdapter { | ||
|
||
/** | ||
* Converts JSON string rich text representation to [RichText]. | ||
*/ | ||
@FromJson | ||
@RichTextString | ||
fun fromJson( | ||
jsonReader: JsonReader, | ||
adapter: JsonAdapter<RichText>, | ||
): RichText? = if (jsonReader.peek() == JsonReader.Token.NULL) { | ||
jsonReader.nextNull() | ||
} else { | ||
adapter.fromJson(jsonReader.nextString()) | ||
} | ||
|
||
/** | ||
* Converts [RichText] instance to JSON string. | ||
*/ | ||
@ToJson | ||
fun toJson( | ||
jsonWriter: JsonWriter, | ||
@RichTextString value: RichText?, | ||
adapter: JsonAdapter<RichText>, | ||
) { | ||
jsonWriter.value(value?.let(adapter::toJson)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
models-annotations/src/main/java/com/vimeo/networking2/annotations/RichTextString.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.vimeo.networking2.annotations | ||
|
||
import com.squareup.moshi.JsonQualifier | ||
|
||
@Retention(AnnotationRetention.RUNTIME) | ||
@JsonQualifier | ||
annotation class RichTextString |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
models/src/main/java/com/vimeo/networking2/richtext/Mention.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.vimeo.networking2.richtext | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
/** | ||
* [RichText] node model for mentions. | ||
* | ||
* @param attrs The attributes of the mention. | ||
* @param text The text this node represents. | ||
*/ | ||
@JsonClass(generateAdapter = true) | ||
data class Mention( | ||
@Json(name = "attrs") | ||
val attrs: MentionAttrs? = null, | ||
|
||
@Json(name = "text") | ||
val text: String? = null | ||
) : RichText { | ||
|
||
@Json(name = "type") | ||
override val type: RichTextType = RichTextType.MENTION | ||
} |
31 changes: 31 additions & 0 deletions
31
models/src/main/java/com/vimeo/networking2/richtext/MentionAttrs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.vimeo.networking2.richtext | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
/** | ||
* Attributes of [Mention] rich text node. | ||
* | ||
* @param label The label of the mention. | ||
* @param userId The user id of the user this mention represents. | ||
* @param name The name of the user this mention represents. | ||
* @param avatar The avatar URL of the user this mention represents. | ||
* @param email The email of the user this mention represents. | ||
*/ | ||
@JsonClass(generateAdapter = true) | ||
data class MentionAttrs( | ||
@Json(name = "label") | ||
val label: String? = null, | ||
|
||
@Json(name = "userId") | ||
val userId: Long? = null, | ||
|
||
@Json(name = "name") | ||
val name: String? = null, | ||
|
||
@Json(name = "avatar") | ||
val avatar: String? = null, | ||
|
||
@Json(name = "email") | ||
val email: String? = null, | ||
) |
18 changes: 18 additions & 0 deletions
18
models/src/main/java/com/vimeo/networking2/richtext/RichText.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.vimeo.networking2.richtext | ||
|
||
/** | ||
* Interface for all models representing rich text nodes. | ||
*/ | ||
sealed interface RichText { | ||
/** | ||
* The [RichTextType] of this node. | ||
*/ | ||
val type: RichTextType? | ||
|
||
companion object { | ||
/** | ||
* The name of the JSON field representing type of the rich text node. | ||
*/ | ||
const val TYPE_FIELD = "type" | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
models/src/main/java/com/vimeo/networking2/richtext/RichTextContainer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.vimeo.networking2.richtext | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
/** | ||
* [RichText] node model that that contains other nodes. | ||
* | ||
* @param type The [RichTextType] of this node. | ||
* @param content The [RichText] nodes this node contains. | ||
*/ | ||
@JsonClass(generateAdapter = true) | ||
data class RichTextContainer( | ||
@Json(name = "type") | ||
override val type: RichTextType? = null, | ||
|
||
@Json(name = "content") | ||
val content: List<RichText>? = null, | ||
) : RichText |
34 changes: 34 additions & 0 deletions
34
models/src/main/java/com/vimeo/networking2/richtext/RichTextType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.vimeo.networking2.richtext | ||
|
||
import com.vimeo.networking2.enums.StringValue | ||
|
||
/** | ||
* Enum with types of [RichText] nodes. | ||
*/ | ||
enum class RichTextType(override val value: String?) : StringValue { | ||
|
||
/** | ||
* Type of node that represents document. | ||
*/ | ||
DOC("doc"), | ||
|
||
/** | ||
* Type of node that represents paragraph. | ||
*/ | ||
PARAGRAPH("paragraph"), | ||
|
||
/** | ||
* Type of node that represents mention. | ||
*/ | ||
MENTION("mention"), | ||
|
||
/** | ||
* Type of node that represents simple text. | ||
*/ | ||
TEXT("text"), | ||
|
||
/** | ||
* Unknown node type. | ||
*/ | ||
UNKNOWN(null), | ||
} |
19 changes: 19 additions & 0 deletions
19
models/src/main/java/com/vimeo/networking2/richtext/Text.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.vimeo.networking2.richtext | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
/** | ||
* [RichText] node model for simple text. | ||
* | ||
* @param text The text this node represents. | ||
*/ | ||
@JsonClass(generateAdapter = true) | ||
data class Text( | ||
@Json(name = "text") | ||
val text: String? = null | ||
) : RichText { | ||
|
||
@Json(name = "type") | ||
override val type: RichTextType = RichTextType.TEXT | ||
} |
10 changes: 10 additions & 0 deletions
10
models/src/main/java/com/vimeo/networking2/richtext/UnknownRichTextNode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.vimeo.networking2.richtext | ||
|
||
/** | ||
* The fallback [RichText] node. | ||
* | ||
* Appears on unknown type. | ||
*/ | ||
class UnknownRichTextNode : RichText { | ||
override val type: RichTextType get() = RichTextType.UNKNOWN | ||
} |
Oops, something went wrong.