Skip to content

Commit

Permalink
return last message
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Oct 21, 2024
1 parent 334af67 commit d0830c8
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ class XMTPModule : Module() {
val sortedGroupList = if (order == ConversationOrder.LAST_MESSAGE) {
client.conversations.listGroups()
.sortedByDescending { group ->
group.decryptedMessages(limit = 1).firstOrNull()?.sentAt
group.decryptedMessages().firstOrNull()?.sentAt
}
.let { groups ->
if (limit != null && limit > 0) groups.take(limit) else groups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GroupWrapper {
put("consentState", consentStateToString(group.consentState()))
}
if (groupParams.lastMessage) {
val lastMessage = group.decryptedMessages(limit = 1).firstOrNull()
val lastMessage = group.decryptedMessages().firstOrNull()
if (lastMessage != null) {
put("lastMessage", DecodedMessageWrapper.encode(lastMessage))
}
Expand Down
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ PODS:
- LibXMTP (0.5.9-beta0)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.9):
- MMKVCore (~> 1.3.9)
- MMKVCore (1.3.9)
- MMKV (2.0.0):
- MMKVCore (~> 2.0.0)
- MMKVCore (2.0.0)
- OpenSSL-Universal (1.1.2200)
- RCT-Folly (2021.07.22.00):
- boost
Expand Down Expand Up @@ -714,8 +714,8 @@ SPEC CHECKSUMS:
LibXMTP: 5a38722a68a9469be2e711857a5e7d9dd3aa8a61
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: 817ba1eea17421547e01e087285606eb270a8dcb
MMKVCore: af055b00e27d88cd92fad301c5fecd1ff9b26dd9
MMKV: f7d1d5945c8765f97f39c3d121f353d46735d801
MMKVCore: c04b296010fcb1d1638f2c69405096aac12f6390
OpenSSL-Universal: 6e1ae0555546e604dbc632a2b9a24a9c46c41ef6
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
RCTRequired: e9df143e880d0e879e7a498dc06923d728809c79
Expand Down
4 changes: 4 additions & 0 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,10 @@ test('can list groups with params', async () => {
messages[0].content() === 'first message',
`last message should be first message ${messages[0].content()}`
)
assert(
boGroupsOrderLastMessage[0].lastMessage?.content() === 'first message',
`last message should be last message ${boGroupsOrderLastMessage[0].lastMessage?.content()}`
)
assert(
boGroupsLimit.length === 1,
`List length should be 1 but was ${boGroupsLimit.length}`
Expand Down
2 changes: 1 addition & 1 deletion ios/Wrappers/GroupWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct GroupWrapper {
result["consentState"] = ConsentWrapper.consentStateToString(state: try group.consentState())
}
if groupParams.lastMessage {
if let lastMessage = try await group.decryptedMessages(limit: 1).first {
if let lastMessage = try await group.decryptedMessages().first {
result["lastMessage"] = try DecodedMessageWrapper.encode(lastMessage, client: client)
}
}
Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public class XMTPModule: Module {
var groupsWithMessages: [(Group, Date)] = []
for group in groups {
do {
let firstMessage = try await group.decryptedMessages(limit: 1).first
let firstMessage = try await group.decryptedMessages().first
let sentAt = firstMessage?.sentAt ?? Date.distantPast
groupsWithMessages.append((group, sentAt))
} catch {
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,10 @@ export async function listGroups<
const members = group['members']?.map((mem: string) => {
return Member.from(mem)
})
return new Group(client, group, members)
const lastMessage = group['lastMessage']
? DecodedMessage.from(group['lastMessage'], client)
: undefined
return new Group(client, group, members, lastMessage)
})
}

Expand Down
6 changes: 5 additions & 1 deletion src/lib/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface GroupParams {
imageUrlSquare: string
description: string
consentState: ConsentState
lastMessage?: DecodedMessage
}

export class Group<
Expand All @@ -47,12 +48,14 @@ export class Group<
imageUrlSquare: string
description: string
state: ConsentState
lastMessage?: DecodedMessage<ContentTypes>
// pinnedFrameUrl: string

constructor(
client: XMTP.Client<ContentTypes>,
params: GroupParams,
members: Member[]
members: Member[],
lastMessage?: DecodedMessage<ContentTypes>
) {
this.client = client
this.id = params.id
Expand All @@ -66,6 +69,7 @@ export class Group<
this.imageUrlSquare = params.imageUrlSquare
this.description = params.description
this.state = params.consentState
this.lastMessage = lastMessage
// this.pinnedFrameUrl = params.pinnedFrameUrl
}

Expand Down

0 comments on commit d0830c8

Please sign in to comment.