Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to dedicated event names per event #285

Merged
merged 1 commit into from
Feb 26, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,22 @@ class XMTPModule : Module() {
override fun definition() = ModuleDefinition {
Name("XMTP")
Events(
// Auth
"sign",
"authed",
"preCreateIdentityCallback",
"preEnableIdentityCallback",
// Conversations
"conversation",
"conversationContainer",
"group",
"conversationContainer",
"message",
"preEnableIdentityCallback",
"preCreateIdentityCallback"
"allGroupMessage",
// Conversation
"conversationMessage",
// Group
"groupMessage"

)

Function("address") { clientAddress: String ->
Expand Down Expand Up @@ -1019,7 +1027,7 @@ class XMTPModule : Module() {
try {
client.conversations.streamAllGroupDecryptedMessages().collect { message ->
sendEvent(
"message",
"allGroupMessage",
mapOf(
"clientAddress" to clientAddress,
"message" to DecodedMessageWrapper.encodeMap(message),
Expand All @@ -1045,7 +1053,7 @@ class XMTPModule : Module() {
try {
conversation.streamDecryptedMessages().collect { message ->
sendEvent(
"message",
"conversationMessage",
mapOf(
"clientAddress" to clientAddress,
"message" to DecodedMessageWrapper.encodeMap(message),
Expand All @@ -1071,7 +1079,7 @@ class XMTPModule : Module() {
try {
group.streamDecryptedMessages().collect { message ->
sendEvent(
"message",
"groupMessage",
mapOf(
"clientAddress" to clientAddress,
"message" to DecodedMessageWrapper.encodeMap(message),
Expand Down
24 changes: 20 additions & 4 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,23 @@ public class XMTPModule: Module {
public func definition() -> ModuleDefinition {
Name("XMTP")

Events("sign", "authed", "conversation", "message", "group", "conversationContainer", "preEnableIdentityCallback", "preCreateIdentityCallback")
Events(
// Auth
"sign",
"authed",
"preCreateIdentityCallback",
"preEnableIdentityCallback",
// Conversations
"conversation",
"group",
"conversationContainer",
"message",
"allGroupMessage",
// Conversation
"conversationMessage",
// Group
"groupMessage"
)

AsyncFunction("address") { (clientAddress: String) -> String in
if let client = await clientsManager.getClient(key: clientAddress) {
Expand Down Expand Up @@ -960,7 +976,7 @@ public class XMTPModule: Module {
do {
for try await message in await client.conversations.streamAllGroupDecryptedMessages() {
do {
try sendEvent("message", [
try sendEvent("allGroupMessage", [
"clientAddress": clientAddress,
"message": DecodedMessageWrapper.encodeToObj(message, client: client),
])
Expand Down Expand Up @@ -989,7 +1005,7 @@ public class XMTPModule: Module {
do {
for try await message in conversation.streamDecryptedMessages() {
do {
try sendEvent("message", [
try sendEvent("conversationMessage", [
"clientAddress": clientAddress,
"message": DecodedMessageWrapper.encodeToObj(message, client: client),
])
Expand Down Expand Up @@ -1059,7 +1075,7 @@ public class XMTPModule: Module {
do {
for try await message in group.streamDecryptedMessages() {
do {
try sendEvent("message", [
try sendEvent("groupMessage", [
"clientAddress": clientAddress,
"message": DecodedMessageWrapper.encodeToObj(message, client: client),
])
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from './ConversationContainer'
import { ConversationSendPayload } from './types/ConversationCodecs'
import { DefaultContentTypes } from './types/DefaultContentType'
import { EventTypes } from './types/EventTypes'
import { SendOptions } from './types/SendOptions'
import * as XMTP from '../index'
import {
Expand Down Expand Up @@ -274,7 +275,7 @@ export class Conversation<ContentTypes extends DefaultContentTypes>
XMTP.subscribeToMessages(this.client.address, this.topic)
const hasSeen = {}
const messageSubscription = XMTP.emitter.addListener(
'message',
EventTypes.ConversationMessage,
async ({
clientAddress,
message,
Expand Down
11 changes: 6 additions & 5 deletions src/lib/Conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from './ConversationContainer'
import { DecodedMessage } from './DecodedMessage'
import { Group } from './Group'
import { EventTypes } from './types/EventTypes'
import { ConversationContext } from '../XMTP.types'
import * as XMTPModule from '../index'
import { ContentCodec } from '../index'
Expand Down Expand Up @@ -110,7 +111,7 @@ export default class Conversations<
): Promise<() => void> {
XMTPModule.subscribeToGroups(this.client.address)
const groupsSubscription = XMTPModule.emitter.addListener(
'group',
EventTypes.Group,
async ({
clientAddress,
group,
Expand Down Expand Up @@ -168,7 +169,7 @@ export default class Conversations<
) {
XMTPModule.subscribeToConversations(this.client.address)
XMTPModule.emitter.addListener(
'conversation',
EventTypes.Conversation,
async ({
clientAddress,
conversation,
Expand Down Expand Up @@ -205,7 +206,7 @@ export default class Conversations<
) {
XMTPModule.subscribeToAll(this.client.address)
const subscription = XMTPModule.emitter.addListener(
'conversationContainer',
EventTypes.ConversationContainer,
async ({
clientAddress,
conversationContainer,
Expand Down Expand Up @@ -252,7 +253,7 @@ export default class Conversations<
): Promise<void> {
XMTPModule.subscribeToAllMessages(this.client.address, includeGroups)
XMTPModule.emitter.addListener(
'message',
EventTypes.Message,
async ({
clientAddress,
message,
Expand Down Expand Up @@ -285,7 +286,7 @@ export default class Conversations<
): Promise<void> {
XMTPModule.subscribeToAllGroupMessages(this.client.address)
XMTPModule.emitter.addListener(
'message',
EventTypes.AllGroupMessage,
async ({
clientAddress,
message,
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import { DecodedMessage } from './DecodedMessage'
import { ConversationSendPayload } from './types/ConversationCodecs'
import { DefaultContentTypes } from './types/DefaultContentType'
import { EventTypes } from './types/EventTypes'
import { SendOptions } from './types/SendOptions'
import * as XMTP from '../index'

Expand Down Expand Up @@ -128,7 +129,7 @@ export class Group<
XMTP.subscribeToGroupMessages(this.client.address, this.id)
const hasSeen = {}
const messageSubscription = XMTP.emitter.addListener(
'message',
EventTypes.GroupMessage,
async ({
clientAddress,
message,
Expand Down
40 changes: 40 additions & 0 deletions src/lib/types/EventTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export enum EventTypes {
// Auth
Sign = 'sign',
Authed = 'authed',
PreCreateIdentityCallback = 'preCreateIdentityCallback',
PreEnableIdentityCallback = 'preEnableIdentityCallback',
// Conversations Events
/**
* Current user is in a newly created conversation
*/
Conversation = 'conversation',
/**
* Current user is in a newly created group
*/
Group = 'group',
/**
* Current user is in a newly created group or conversation
*/
ConversationContainer = 'conversationContainer',
/**
* Current user receives a new message in any conversation
*/
Message = 'message',
/**
* Current user receives a new message in any group
* Current limitation, only groups created before listener is added will be received
*/
AllGroupMessage = 'allGroupMessage',

// Conversation Events
/**
* A new message is sent to a specific conversation
*/
ConversationMessage = 'conversationMessage',
// Group Events
/**
* A new message is sent to a specific group
*/
GroupMessage = 'groupMessage',
}
Loading