Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/DiscordKitCore/APIUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import Foundation

let DISCORD_EPOCH: TimeInterval = 1420070400000

let iso8601 = { () -> ISO8601DateFormatter in
let fmt = ISO8601DateFormatter()
fmt.formatOptions = [.withInternetDateTime]
Expand Down
4 changes: 4 additions & 0 deletions Sources/DiscordKitCore/Objects/REST/MessageReadAck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ import Foundation

public struct MessageReadAck: Codable {
public let token: String?
public let last_viewed: Int?

public let manual: Bool?
public let mention_count: Int?
}
14 changes: 11 additions & 3 deletions Sources/DiscordKitCore/REST/APIChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public extension DiscordREST {
after: Snowflake? = nil
) async throws -> [Message] {
var query = [URLQueryItem(name: "limit", value: String(limit))]
if around != nil { query.append(URLQueryItem(name: "around", value: around?.description)) } else if before != nil {query.append(URLQueryItem(name: "before", value: before?.description))} else if after != nil { query.append(URLQueryItem(name: "after", value: after?.description)) }
if around != nil { query.append(URLQueryItem(name: "around", value: around?.description)) } else if before != nil {query.append(URLQueryItem(name: "before", value: before?.description))} else if after != nil { query.append(URLQueryItem(name: "after", value: after?.description)) }

return try await getReq(path: "channels/\(id)/messages", query: query)
}
Expand Down Expand Up @@ -64,9 +64,17 @@ public extension DiscordREST {
/// > POST: `/channels/{channel.id}/messages/{message.id}/ack`
func ackMessageRead(
id: Snowflake,
msgID: Snowflake
msgID: Snowflake,
manual: Bool? = false,
mention_count: Int? = 0
) async throws -> MessageReadAck {
return try await postReq(path: "channels/\(id)/messages/\(msgID)/ack", body: MessageReadAck(token: nil), attachments: [])
if manual ?? false {
return try await postReq(path: "channels/\(id)/messages/\(msgID)/ack", body: MessageReadAck(token: nil, last_viewed: nil, manual: manual, mention_count: mention_count))
}

let lastViewed = Int(ceil((Date().timeIntervalSince1970*1000 - DISCORD_EPOCH) / 864e5))

return try await postReq(path: "channels/\(id)/messages/\(msgID)/ack", body: MessageReadAck(token: nil, last_viewed: lastViewed, manual: nil, mention_count: nil))
}

/// Typing Start (Undocumented endpoint!)
Expand Down