Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
feat: social links, doc comments and reactions, event series
Browse files Browse the repository at this point in the history
  • Loading branch information
SrGaabriel committed Mar 5, 2023
1 parent b9e34cd commit 1d55bdc
Show file tree
Hide file tree
Showing 72 changed files with 1,302 additions and 308 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Library.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
object Library {
const val Group = "io.github.srgaabriel.deck"
const val Version = "0.8.11"
const val Version = "0.9"
const val Url = "https://srgaabriel.github.io/deck/"

const val Release = true
Expand Down
115 changes: 100 additions & 15 deletions deck-common/src/main/kotlin/entity/Channels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import java.util.*
@Serializable
public data class RawServerChannel(
public val id: UUID,
public val type: RawServerChannelType,
public val type: ServerChannelType,
public val name: String,
public val topic: OptionalProperty<String> = OptionalProperty.NotPresent,
public val createdAt: Instant,
Expand All @@ -34,27 +34,36 @@ public data class RawServerChannel(
public class RawChannelId(public val id: UUID)

@Serializable
public enum class RawServerChannelType {
public enum class ServerChannelType(public val contentName: String) {
@SerialName("announcements")
ANNOUNCEMENTS,
Announcements("announcements"),

@SerialName("chat")
CHAT,
Chat("content"),

@SerialName("calendar")
CALENDAR,
Calendar("events"),

@SerialName("forums")
FORUMS,
Forums("topics"),

@SerialName("media")
MEDIA,
Media("media"),

@SerialName("docs")
DOCS,
Documentation("docs"),

@SerialName("voice")
VOICE,
Voice("voice"),

@SerialName("list")
LIST,
List("items"),

@SerialName("scheduling")
SCHEDULING,
Scheduling("scheduling"),

@SerialName("stream")
STREAM
Streaming("stream");
}

@Serializable
Expand All @@ -70,6 +79,18 @@ public data class RawDocumentation(
public val updatedBy: OptionalProperty<GenericId> = OptionalProperty.NotPresent
)

@Serializable
public data class RawDocumentationComment(
public val id: IntGenericId,
public val content: String,
public val createdAt: Instant,
public val createdBy: GenericId,
public val updatedAt: OptionalProperty<Instant> = OptionalProperty.NotPresent,
public val channelId: UUID,
public val docId: IntGenericId,
public val mentions: OptionalProperty<RawMessageMentions> = OptionalProperty.NotPresent
)

@Serializable
public data class RawListItem(
public val id: UUID,
Expand Down Expand Up @@ -125,7 +146,6 @@ public data class RawForumTopicSummary(
val title: String,
val createdAt: Instant,
val createdBy: GenericId,
val createdByWebhookId: OptionalProperty<GenericId> = OptionalProperty.NotPresent,
val updatedAt: OptionalProperty<Instant> = OptionalProperty.NotPresent,
val bumpedAt: OptionalProperty<Instant> = OptionalProperty.NotPresent
)
Expand All @@ -152,6 +172,10 @@ public data class RawCalendarEvent(
val location: OptionalProperty<String> = OptionalProperty.NotPresent,
val url: OptionalProperty<String> = OptionalProperty.NotPresent,
val color: OptionalProperty<Int> = OptionalProperty.NotPresent,
val repeats: Boolean = false,
val seriesId: OptionalProperty<UUID> = OptionalProperty.NotPresent,
val roleIds: OptionalProperty<List<Int>> = OptionalProperty.NotPresent,
val isAllDay: Boolean = false,
val rsvpLimit: OptionalProperty<Int> = OptionalProperty.NotPresent,
val startsAt: Instant,
val duration: OptionalProperty<Int> = OptionalProperty.NotPresent,
Expand All @@ -165,7 +189,7 @@ public data class RawCalendarEvent(
@Serializable
public data class RawCalendarEventCancellation(
val description: OptionalProperty<String> = OptionalProperty.NotPresent,
val createdBy: String,
val createdBy: GenericId,
)

@Serializable
Expand Down Expand Up @@ -195,6 +219,66 @@ public enum class CalendarEventRsvpStatus {
Waitlisted;
}


@Serializable
public data class RawCalendarEventRepeatInfo(
val type: RawCalendarEventRepeatInfoType,
val every: OptionalProperty<RawCalendarEventRepeatInfoCustom> = OptionalProperty.NotPresent,
val endAfterOccurrences: OptionalProperty<Int> = OptionalProperty.NotPresent,
val endDate: OptionalProperty<Instant> = OptionalProperty.NotPresent,
val on: OptionalProperty<List<CalendarEventWeekDay>> = OptionalProperty.NotPresent
)

@Serializable
public data class RawCalendarEventRepeatInfoCustom(
val count: Int,
val interval: CalendarEventCustomIntervalType
)

@Serializable
public enum class RawCalendarEventRepeatInfoType {
@SerialName("once")
Once,
@SerialName("everyDay")
EveryDay,
@SerialName("everyWeek")
EveryWeek,
@SerialName("everyMonth")
EveryMonth,
@SerialName("custom")
Custom;
}

@Serializable
public enum class CalendarEventCustomIntervalType {
@SerialName("once")
Day,
@SerialName("everyDay")
Month,
@SerialName("everyWeek")
Year,
@SerialName("everyMonth")
Week,
}

@Serializable
public enum class CalendarEventWeekDay {
@SerialName("sunday")
Sunday,
@SerialName("monday")
Monday,
@SerialName("tuesday")
Tuesday,
@SerialName("wednesday")
Wednesday,
@SerialName("thursday")
Thursday,
@SerialName("friday")
Friday,
@SerialName("saturday")
Saturday
}

@Serializable
public data class RawCalendarEventComment(
val id: IntGenericId,
Expand All @@ -203,5 +287,6 @@ public data class RawCalendarEventComment(
val updatedAt: OptionalProperty<Instant> = OptionalProperty.NotPresent,
val calendarEventId: IntGenericId,
val channelId: UUID,
val createdBy: GenericId
val createdBy: GenericId,
val mentions: OptionalProperty<RawMessageMentions> = OptionalProperty.NotPresent
)
4 changes: 3 additions & 1 deletion deck-common/src/main/kotlin/entity/Users.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public data class RawUserSummary(
public data class RawUserSocialLink(
val handle: OptionalProperty<String> = OptionalProperty.NotPresent,
val serviceId: OptionalProperty<GenericId> = OptionalProperty.NotPresent,
val type: SocialLinkType
val type: SocialLinkType,
val userId: GenericId,
val createdAt: Instant
)

@Serializable
Expand Down
3 changes: 2 additions & 1 deletion deck-common/src/main/kotlin/entity/Webhooks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public data class RawWebhook(
val createdAt: Instant,
val createdBy: GenericId,
val deletedAt: OptionalProperty<Instant> = OptionalProperty.NotPresent,
val token: OptionalProperty<String> = OptionalProperty.NotPresent
val token: OptionalProperty<String> = OptionalProperty.NotPresent,
val avatar: OptionalProperty<String> = OptionalProperty.NotPresent
)
2 changes: 1 addition & 1 deletion deck-core/src/main/kotlin/DeckClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class DeckClient internal constructor(
*/
public suspend fun login() {
if (!rest.token.startsWith("gapi_"))
rest.logger.warning { "Your token does not start with 'gapi_', meaning it is either invalid or outdated." }
rest.logger.warning { "Your token does not start with 'gapi_', meaning this token is either invalid or outdated." }
val masterGateway = gateway.createGateway()
eventService.listen()
masterGateway.start()
Expand Down
28 changes: 25 additions & 3 deletions deck-core/src/main/kotlin/entity/CalendarEvent.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package io.github.srgaabriel.deck.core.entity

import io.github.srgaabriel.deck.common.util.GenericId
import io.github.srgaabriel.deck.common.util.IntGenericId
import io.github.srgaabriel.deck.core.entity.channel.CalendarChannel
import io.github.srgaabriel.deck.core.stateless.StatelessCalendarEvent
import io.github.srgaabriel.deck.core.stateless.StatelessRole
import io.github.srgaabriel.deck.core.stateless.StatelessUser
import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessCalendarEvent
import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessCalendarEventSeries
import io.github.srgaabriel.deck.core.util.BlankStatelessCalendarEventSeries
import io.github.srgaabriel.deck.core.util.BlankStatelessRole
import io.github.srgaabriel.deck.core.util.BlankStatelessUser
import kotlinx.datetime.Instant
import java.util.*
import kotlin.time.Duration
import kotlin.time.Duration.Companion.minutes

Expand All @@ -24,12 +30,28 @@ public interface CalendarEvent: StatelessCalendarEvent {

/** Max attendance, null if none */
public val rsvpLimit: Int?

/** Calendar event's color, null if not defined */
public val color: Int?
/** Does the event last all day */
public val lastsAllDay: Boolean
/** Does this event repeat */
public val repeats: Boolean

/** The id of the series this event belongs to, null if none */
public val seriesId: UUID?
/** Wrapper of [seriesId] */
public val series: StatelessCalendarEventSeries?
get() = seriesId?.let { BlankStatelessCalendarEventSeries(client, it, channelId, serverId) }

/** Allowed roles for this event */
public val roleIds: List<IntGenericId>
/** Wrapper of [roleIds] */
public val roles: List<StatelessRole> get() = roleIds.map { BlankStatelessRole(client, id, serverId) }



/** Calendar event's duration in minutes, null if not defined */
public val durationInMinutes: Int?

/** Wrapper of [durationInMinutes] */
public val duration: Duration? get() = durationInMinutes?.minutes

Expand Down
5 changes: 4 additions & 1 deletion deck-core/src/main/kotlin/entity/CalendarEventComment.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.srgaabriel.deck.core.entity

import io.github.srgaabriel.deck.common.util.GenericId
import io.github.srgaabriel.deck.core.stateless.StatelessCalendarEventComment
import io.github.srgaabriel.deck.core.stateless.StatelessUser
import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessCalendarEventComment
import io.github.srgaabriel.deck.core.util.BlankStatelessUser
import kotlinx.datetime.Instant

Expand All @@ -21,4 +21,7 @@ public interface CalendarEventComment: StatelessCalendarEventComment {
public val createdAt: Instant
/** The date when this comment was updated, if it was ever updated */
public val updatedAt: Instant?

/** The mentions in this comment, null if none */
public val mentions: Mentions?
}
2 changes: 1 addition & 1 deletion deck-core/src/main/kotlin/entity/CalendarEventRsvp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package io.github.srgaabriel.deck.core.entity

import io.github.srgaabriel.deck.common.entity.CalendarEventRsvpStatus
import io.github.srgaabriel.deck.common.util.GenericId
import io.github.srgaabriel.deck.core.stateless.StatelessCalendarEventRsvp
import io.github.srgaabriel.deck.core.stateless.StatelessUser
import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessCalendarEventRsvp
import io.github.srgaabriel.deck.core.util.BlankStatelessUser
import kotlinx.datetime.Instant

Expand Down
2 changes: 1 addition & 1 deletion deck-core/src/main/kotlin/entity/Documentation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package io.github.srgaabriel.deck.core.entity

import io.github.srgaabriel.deck.common.util.GenericId
import io.github.srgaabriel.deck.core.entity.channel.DocumentationChannel
import io.github.srgaabriel.deck.core.stateless.StatelessDocumentation
import io.github.srgaabriel.deck.core.stateless.StatelessUser
import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessDocumentation
import io.github.srgaabriel.deck.core.util.BlankStatelessUser
import io.github.srgaabriel.deck.rest.builder.CreateDocumentationRequestBuilder
import kotlinx.datetime.Instant
Expand Down
27 changes: 27 additions & 0 deletions deck-core/src/main/kotlin/entity/DocumentationComment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.srgaabriel.deck.core.entity

import io.github.srgaabriel.deck.common.util.GenericId
import io.github.srgaabriel.deck.core.stateless.StatelessUser
import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessDocumentationComment
import io.github.srgaabriel.deck.core.util.BlankStatelessUser
import kotlinx.datetime.Instant

/**
* Represents a comment posted in a [Documentation]
*/
public interface DocumentationComment: StatelessDocumentationComment {
/** The comment's content */
public val content: String

/** The id of this comment's author */
public val authorId: GenericId
public val author: StatelessUser get() = BlankStatelessUser(client, authorId)

/** The date when this comment was created */
public val createdAt: Instant
/** The date when this comment was updated, if it was ever updated */
public val updatedAt: Instant?

/** The mentions in this comment, null if none */
public val mentions: Mentions?
}
2 changes: 1 addition & 1 deletion deck-core/src/main/kotlin/entity/ForumTopic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import io.github.srgaabriel.deck.common.util.IntGenericId
import io.github.srgaabriel.deck.common.util.asNullable
import io.github.srgaabriel.deck.core.DeckClient
import io.github.srgaabriel.deck.core.entity.channel.ForumChannel
import io.github.srgaabriel.deck.core.stateless.StatelessForumTopic
import io.github.srgaabriel.deck.core.stateless.StatelessUser
import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessForumTopic
import io.github.srgaabriel.deck.core.util.BlankStatelessUser
import kotlinx.datetime.Instant
import java.util.*
Expand Down
2 changes: 1 addition & 1 deletion deck-core/src/main/kotlin/entity/ForumTopicComment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.srgaabriel.deck.core.entity

import io.github.srgaabriel.deck.core.stateless.StatelessForumTopicComment
import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessForumTopicComment
import kotlinx.datetime.Instant

/**
Expand Down
2 changes: 1 addition & 1 deletion deck-core/src/main/kotlin/entity/ListItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import io.github.srgaabriel.deck.common.entity.RawListItemNote
import io.github.srgaabriel.deck.common.util.*
import io.github.srgaabriel.deck.core.DeckClient
import io.github.srgaabriel.deck.core.entity.channel.ListChannel
import io.github.srgaabriel.deck.core.stateless.StatelessListItem
import io.github.srgaabriel.deck.core.stateless.StatelessUser
import io.github.srgaabriel.deck.core.stateless.channel.content.StatelessListItem
import io.github.srgaabriel.deck.core.util.BlankStatelessUser
import io.github.srgaabriel.deck.rest.builder.UpdateListItemRequestBuilder
import kotlinx.datetime.Instant
Expand Down
32 changes: 32 additions & 0 deletions deck-core/src/main/kotlin/entity/SocialLink.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.srgaabriel.deck.core.entity

import io.github.srgaabriel.deck.common.entity.RawUserSocialLink
import io.github.srgaabriel.deck.common.entity.SocialLinkType
import io.github.srgaabriel.deck.common.util.GenericId
import io.github.srgaabriel.deck.common.util.asNullable
import io.github.srgaabriel.deck.core.DeckClient
import io.github.srgaabriel.deck.core.stateless.StatelessUser
import io.github.srgaabriel.deck.core.util.BlankStatelessUser
import kotlinx.datetime.Instant

public data class SocialLink(
val client: DeckClient,
val type: SocialLinkType,
val userId: GenericId,
val handle: String?,
val serviceId: String?,
val createdAt: Instant
) {
val user: StatelessUser get() = BlankStatelessUser(client, userId)

public companion object {
public fun from(client: DeckClient, raw: RawUserSocialLink): SocialLink = SocialLink(
client = client,
type = raw.type,
userId = raw.userId,
handle = raw.handle.asNullable(),
serviceId = raw.serviceId.asNullable(),
createdAt = raw.createdAt
)
}
}
Loading

0 comments on commit 1d55bdc

Please sign in to comment.