Skip to content

Commit 8e357a8

Browse files
Merge branch 'master' into vishal/thread_participants_type
2 parents 158218d + 8e4c25e commit 8e357a8

File tree

3 files changed

+382
-0
lines changed

3 files changed

+382
-0
lines changed

src/client.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,59 @@ export class StreamChat<
19761976
});
19771977
}
19781978

1979+
/**
1980+
* pinMessage - pins provided message
1981+
* @param {UpdatedMessage<AttachmentType,ChannelType,CommandType,MessageType,ReactionType,UserType>} message object
1982+
* @param {undefined|number|string|Date} timeoutOrExpirationDate expiration date or timeout. Use number type to set timeout in seconds, string or Date to set exact expiration date
1983+
*/
1984+
pinMessage(
1985+
message: UpdatedMessage<
1986+
AttachmentType,
1987+
ChannelType,
1988+
CommandType,
1989+
MessageType,
1990+
ReactionType,
1991+
UserType
1992+
>,
1993+
timeoutOrExpirationDate?: number | string | Date,
1994+
) {
1995+
let pinExpires;
1996+
if (typeof timeoutOrExpirationDate === 'number') {
1997+
const now = new Date();
1998+
now.setSeconds(now.getSeconds() + timeoutOrExpirationDate);
1999+
pinExpires = now.toISOString();
2000+
} else if (isString(timeoutOrExpirationDate)) {
2001+
pinExpires = timeoutOrExpirationDate;
2002+
} else if (timeoutOrExpirationDate instanceof Date) {
2003+
pinExpires = timeoutOrExpirationDate.toISOString();
2004+
}
2005+
return this.updateMessage({
2006+
...message,
2007+
pinned: true,
2008+
pin_expires: pinExpires,
2009+
});
2010+
}
2011+
2012+
/**
2013+
* unpinMessage - unpins provided message
2014+
* @param {UpdatedMessage<AttachmentType,ChannelType,CommandType,MessageType,ReactionType,UserType>} message object
2015+
*/
2016+
unpinMessage(
2017+
message: UpdatedMessage<
2018+
AttachmentType,
2019+
ChannelType,
2020+
CommandType,
2021+
MessageType,
2022+
ReactionType,
2023+
UserType
2024+
>,
2025+
) {
2026+
return this.updateMessage({
2027+
...message,
2028+
pinned: false,
2029+
});
2030+
}
2031+
19792032
/**
19802033
* updateMessage - Update the given message
19812034
*

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,10 +1484,14 @@ export type MessageBase<
14841484
UserType = UnknownType
14851485
> = MessageType & {
14861486
id: string;
1487+
pinned: boolean;
14871488
attachments?: Attachment<AttachmentType>[];
14881489
html?: string;
14891490
mml?: string;
14901491
parent_id?: string;
1492+
pin_expires?: string;
1493+
pinned_at?: string;
1494+
pinned_by?: UserResponse<UserType> | null;
14911495
quoted_message_id?: string;
14921496
show_in_channel?: boolean;
14931497
text?: string;

0 commit comments

Comments
 (0)