@@ -45,6 +45,7 @@ type User struct {
45
45
LastActive * time.Time `json:"last_active,omitempty"`
46
46
47
47
Mutes []* Mute `json:"mutes,omitempty"`
48
+ BlockedUserIDs []string `json:"blocked_user_ids"`
48
49
ChannelMutes []* ChannelMute `json:"channel_mutes,omitempty"`
49
50
ExtraData map [string ]interface {} `json:"-"`
50
51
RevokeTokensIssuedBefore * time.Time `json:"revoke_tokens_issued_before,omitempty"`
@@ -112,6 +113,94 @@ func (c *Client) MuteUser(ctx context.Context, targetID, mutedBy string, options
112
113
return & resp , err
113
114
}
114
115
116
+ type BlockUsersResponse struct {
117
+ Response
118
+ BlockedByUserID string `json:"blocked_by_user_id"`
119
+ BlockedUserID string `json:"blocked_user_id"`
120
+ CreatedAt time.Time `json:"created_at"`
121
+ }
122
+
123
+ type userBlockOptions struct {
124
+ BlockedUserID string `json:"blocked_user_id"`
125
+ UserID string `json:"user_id"`
126
+ }
127
+
128
+ // BlockUser blocks targetID.
129
+ func (c * Client ) BlockUser (ctx context.Context , targetID , userID string ) (* BlockUsersResponse , error ) {
130
+ switch {
131
+ case targetID == "" :
132
+ return nil , errors .New ("targetID should not be empty" )
133
+ case userID == "" :
134
+ return nil , errors .New ("userID should not be empty" )
135
+ }
136
+
137
+ opts := & userBlockOptions {
138
+ BlockedUserID : targetID ,
139
+ UserID : userID ,
140
+ }
141
+
142
+ var resp BlockUsersResponse
143
+ err := c .makeRequest (ctx , http .MethodPost , "users/block" , nil , opts , & resp )
144
+ return & resp , err
145
+ }
146
+
147
+ type UnblockUsersResponse struct {
148
+ Response
149
+ }
150
+
151
+ type userUnblockOptions struct {
152
+ BlockedUserID string `json:"blocked_user_id"`
153
+ UserID string `json:"user_id"`
154
+ }
155
+
156
+ // UnblockUser Unblocks targetID.
157
+ func (c * Client ) UnblockUser (ctx context.Context , targetID , userID string ) (* UnblockUsersResponse , error ) {
158
+ switch {
159
+ case targetID == "" :
160
+ return nil , errors .New ("targetID should not be empty" )
161
+ case userID == "" :
162
+ return nil , errors .New ("userID should not be empty" )
163
+ }
164
+
165
+ opts := & userUnblockOptions {
166
+ BlockedUserID : targetID ,
167
+ UserID : userID ,
168
+ }
169
+
170
+ var resp UnblockUsersResponse
171
+ err := c .makeRequest (ctx , http .MethodPost , "users/unblock" , nil , opts , & resp )
172
+ return & resp , err
173
+ }
174
+
175
+ type GetBlockedUsersResponse struct {
176
+ Response
177
+ BlockedUsers []* BlockedUserResponse `json:"blocks"`
178
+ }
179
+
180
+ type BlockedUserResponse struct {
181
+ BlockedByUser UsersResponse `json:"user"`
182
+ BlockedByUserID string `json:"user_id"`
183
+
184
+ BlockedUser UsersResponse `json:"blocked_user"`
185
+ BlockedUserID string `json:"blocked_user_id"`
186
+ CreatedAt time.Time `json:"created_at"`
187
+ }
188
+
189
+ // GetBlockedUser returns blocked user
190
+ func (c * Client ) GetBlockedUser (ctx context.Context , blockedBy string ) (* GetBlockedUsersResponse , error ) {
191
+ switch {
192
+ case blockedBy == "" :
193
+ return nil , errors .New ("user_id should not be empty" )
194
+ }
195
+
196
+ var resp GetBlockedUsersResponse
197
+
198
+ params := make (url.Values )
199
+ params .Set ("user_id" , blockedBy )
200
+ err := c .makeRequest (ctx , http .MethodGet , "users/block" , params , nil , & resp )
201
+ return & resp , err
202
+ }
203
+
115
204
// MuteUsers mutes all users in targetIDs.
116
205
func (c * Client ) MuteUsers (ctx context.Context , targetIDs []string , mutedBy string , options ... MuteOption ) (* Response , error ) {
117
206
switch {
0 commit comments