Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into release-0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Oct 27, 2020
2 parents e99f132 + 3dbb8f8 commit cf3fd4f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
1 change: 1 addition & 0 deletions changelog.d/189.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure stanzas are emitted in the right order when an XMPP user joins a MUC
38 changes: 20 additions & 18 deletions src/xmppjs/XJSGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ export class XmppJsGateway implements IGateway {

public reflectXMPPStanza(chatName: string, stanza: StzaBase) {
const xmppDevices = [...this.members.getXmppMembersDevices(chatName)];
xmppDevices.forEach((device) => {
return Promise.all(xmppDevices.map((device) => {
stanza.to = device;
this.xmpp.xmppSend(stanza);
});
return this.xmpp.xmppSend(stanza);
}));
}

public reflectPM(stanza: Element) {
Expand Down Expand Up @@ -387,7 +387,20 @@ export class XmppJsGateway implements IGateway {
await Promise.all(allMembershipPromises);

log.debug("Emitting membership of self");
// 2. self presence
// 2. Send everyone else the users new presence.
const reflectedPresence = new StzaPresenceItem(
stanza.attrs.to,
"",
undefined,
PresenceAffiliation.Member,
PresenceRole.Participant,
false,
stanza.attrs.from,
);
await this.reflectXMPPStanza(chatName, reflectedPresence);
// FROM THIS POINT ON, WE CONSIDER THE USER JOINED.

// 3. Send the user self presence
const selfPresence = new StzaPresenceItem(
stanza.attrs.to,
stanza.attrs.from,
Expand All @@ -402,18 +415,6 @@ export class XmppJsGateway implements IGateway {
selfPresence.statusCodes.add(XMPPStatusCode.RoomLoggingEnabled);
await this.xmpp.xmppSend(selfPresence);

// Send everyone else the users new presence.
const reflectedPresence = new StzaPresenceItem(
stanza.attrs.to,
"",
undefined,
PresenceAffiliation.Member,
PresenceRole.Participant,
false,
stanza.attrs.from,
);
this.reflectXMPPStanza(chatName, reflectedPresence);
// FROM THIS POINT ON, WE CONSIDER THE USER JOINED.

this.members.addXmppMember(
`${to.local}@${to.domain}`,
Expand All @@ -422,16 +423,17 @@ export class XmppJsGateway implements IGateway {
ownMxid,
);

// 3. Room history
// 4. Room history
log.debug("Emitting history");
const history: Element[] = this.roomHistory.get(room.roomId) || [];
history.forEach((e) => {
e.attrs.to = stanza.attrs.from;
// TODO: Add delay info to this.
this.xmpp.xmppWriteToStream(e);
});

log.debug("Emitting subject");
// 4. The room subject
// 5. The room subject
this.xmpp.xmppSend(new StzaMessageSubject(chatName, stanza.attrs.from, undefined,
`${room.name || ""} ${room.topic ? "| " + room.topic : ""}`,
));
Expand Down

0 comments on commit cf3fd4f

Please sign in to comment.