Skip to content

Commit

Permalink
chore: conform code style
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed Oct 10, 2023
1 parent 835d4e3 commit 231290d
Show file tree
Hide file tree
Showing 17 changed files with 258 additions and 189 deletions.
26 changes: 15 additions & 11 deletions src/assemblies/inbox/InboxForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ layout-toolbar(

<script lang="ts">
// NPM
import { JID, Room, RoomType } from "@prose-im/prose-sdk-js";
import { PropType } from "vue";
import { JID, Room, RoomType } from "@prose-im/prose-sdk-js";

// PROJECT: COMPONENTS
import {
Expand All @@ -126,7 +126,8 @@ import InboxFormChatstate from "@/components/inbox/InboxFormChatstate.vue";
// PROJECT: STORES
import Store from "@/store";

// PROJECT: BROKER
// PROJECT: UTILITIES
import logger from "@/utilities/logger";

// CONSTANTS
const CHATSTATE_COMPOSE_INACTIVE_DELAY = 5000; // 5 seconds
Expand Down Expand Up @@ -201,6 +202,7 @@ export default {
// Propagate new chat state?
if (composing !== this.isUserComposing) {
this.isUserComposing = composing;

await this.room.setUserIsComposing(composing);
}
},
Expand Down Expand Up @@ -282,32 +284,34 @@ export default {
// Clear compose chat state timeout (as needed)
this.unscheduleChatStateComposeTimeout();

// Mark user as not composing anymore.
// Mark user as not composing anymore
this.isUserComposing = false;

if (message.startsWith("/invite ")) {
// Invite users to room?
if (message.startsWith("/invite ") === true) {
const jid = new JID(message.substring("/invite ".length).trim());

switch (this.room.type) {
case RoomType.DirectMessage:
case RoomType.Group:
case RoomType.Generic:
console.warn("This room type does not allow inviting users");
logger.warn("This room type does not allow inviting users");

break;

case RoomType.PrivateChannel:
case RoomType.PublicChannel:
console.info(`Inviting user ${jid} to room ${this.room.id}`);
logger.info(`Inviting user ${jid} to room ${this.room.id}`);

await this.room.inviteUsers([jid.toString()]);

break;
}
this.message = "";
return;
} else {
// Send message
await this.room.sendMessage(message);
}

// Send message
await this.room.sendMessage(message);

// Clear message field
this.message = "";
}
Expand Down
13 changes: 7 additions & 6 deletions src/assemblies/inbox/InboxTopbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ layout-toolbar(

<script lang="ts">
// NPM
import { JID, Room, RoomID } from "@prose-im/prose-sdk-js";
import { PropType } from "vue";
import { JID, Room, RoomID } from "@prose-im/prose-sdk-js";

// PROJECT: STORES
import Store from "@/store";
Expand All @@ -148,6 +148,7 @@ export default {
type: Object as PropType<JID>,
required: true
},

room: {
type: Object as PropType<Room>,
required: true
Expand Down Expand Up @@ -226,14 +227,14 @@ export default {

if (
adjacentRoute.name.startsWith("app.inbox") &&
adjacentRoute.params.roomID
adjacentRoute.params.roomId
) {
// Make sure not to push current route JID
if (
!currentRoute.name.startsWith("app.inbox") ||
currentRoute.params.roomID !== adjacentRoute.params.roomID
currentRoute.params.roomId !== adjacentRoute.params.roomId
) {
historyRawJIDs.add(adjacentRoute.params.roomID);
historyRawJIDs.add(adjacentRoute.params.roomId);
}
}
}
Expand Down Expand Up @@ -276,13 +277,13 @@ export default {
this.isActionHistoryPopoverVisible = false;
},

onActionHistoryPopoverEntryClick(roomID: RoomID): void {
onActionHistoryPopoverEntryClick(roomId: RoomID): void {
// Go to conversation
this.$router.push({
name: "app.inbox",

params: {
roomID: roomID
roomId: roomId
}
});

Expand Down
8 changes: 7 additions & 1 deletion src/broker/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,21 @@ class BrokerClient {
}

async awaitConnection(): Promise<void> {
if (this.__isConnected) {
// Already connected?
if (this.__isConnected === true) {
return Promise.resolve();
}

// Not already connected
const delegate = this.__delegate;

return new Promise(resolve => {
const handler = () => {
delegate.events().off("client:connected", handler);

resolve();
};

delegate.events().on("client:connected", handler);
});
}
Expand Down Expand Up @@ -137,12 +141,14 @@ class BrokerClient {

private __onClientConnected(): void {
this.__isConnected = true;

Store.$session.setConnected(true);
Store.$session.setConnecting(false);
}

private __onClientDisconnected(): void {
this.__isConnected = false;

Store.$session.setConnected(false);
Store.$session.setConnecting(false);

Expand Down
30 changes: 14 additions & 16 deletions src/broker/modules/muc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,31 @@ class BrokerModuleMUC extends BrokerModule {
}

async createGroup(participants: JID[]): Promise<void> {
if (!this._client.client) {
return;
}

const room = (await this._client.client.createGroup(
const room = (await this._client.client?.createGroup(
participants.map(jid => jid.toString())
)) as Room;

Store.$muc.insertRoom(room);
if (room) {
Store.$muc.insertRoom(room);
}
}

async createPublicChannel(name: string): Promise<void> {
if (!this._client.client) {
return;
}
const room = (await this._client.client?.createPublicChannel(name)) as Room;

const room = (await this._client.client.createPublicChannel(name)) as Room;
Store.$muc.insertRoom(room);
if (room) {
Store.$muc.insertRoom(room);
}
}

async createPrivateChannel(name: string): Promise<void> {
if (!this._client.client) {
return;
}
const room = (await this._client.client?.createPrivateChannel(
name
)) as Room;

const room = (await this._client.client.createPrivateChannel(name)) as Room;
Store.$muc.insertRoom(room);
if (room) {
Store.$muc.insertRoom(room);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/broker/modules/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class BrokerModuleProfile extends BrokerModule {
logger.info(`Will load avatar for: '${jid}'`);

const dataURL = await this._client.client?.loadAvatarDataURL(jid);

if (dataURL) {
return { dataURL };
}
Expand Down
39 changes: 25 additions & 14 deletions src/components/inbox/InboxMessaging.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@

<script lang="ts">
// NPM
import { PropType, shallowRef } from "vue";
import { JID, Room } from "@prose-im/prose-sdk-js";
import {
Modifier as MessagingModifier,
Platform as MessagingPlatform,
Messaging as MessagingRuntime,
SeekDirection as MessagingSeekDirection,
Theme as MessagingTheme
} from "@prose-im/prose-core-views/types/messaging";
import { JID, Room } from "@prose-im/prose-sdk-js";
import { PropType, shallowRef } from "vue";

// PROJECT: STYLES
import styleElementsFonts from "@/assets/stylesheets/elements/_elements.fonts.scss?inline";
Expand Down Expand Up @@ -348,8 +348,8 @@ export default {

setupStore(runtime: MessagingRuntime): void {
// Identify both parties
//this.identifyPartyLocal(runtime);
//this.identifyPartyRemote(runtime);
this.identifyPartyLocal(runtime);
this.identifyAllPartiesRemote(runtime);

// Mark as initializing?
if (this.isMessageSyncStale === true) {
Expand Down Expand Up @@ -381,11 +381,18 @@ export default {
});
},

identifyPartyRemote(runtime: MessagingRuntime): void {
identifyPartyRemote(runtime: MessagingRuntime, jid: JID): void {
// Identify remote party
runtime.MessagingStore.identify(this.jid.toString(), {
name: Store.$roster.getEntryName(this.jid),
avatar: Store.$avatar.getAvatarDataUrl(this.jid)
runtime.MessagingStore.identify(jid.toString(), {
name: Store.$roster.getEntryName(jid),
avatar: Store.$avatar.getAvatarDataUrl(jid)
});
},

identifyAllPartiesRemote(runtime: MessagingRuntime): void {
// Identify remote all parties
this.room.members.forEach((memberJID: JID) => {
this.identifyPartyRemote(runtime, memberJID);
});
},

Expand Down Expand Up @@ -544,6 +551,7 @@ export default {

// TODO: this one is not working
const messages = await this.room.loadLatestMessages(undefined, true);

Store.$inbox.insertCoreMessages(this.room.id, messages);

// Mark backwards loading as complete
Expand Down Expand Up @@ -858,14 +866,14 @@ export default {
},

onStoreMessageInserted(event: EventMessageGeneric): void {
if (this.room.id === event.roomID) {
if (this.room.id === event.roomId) {
// Insert into view
this.frame()?.MessagingStore.insert(event.message);
}
},

onStoreMessageUpdated(event: EventMessageGeneric): void {
if (this.room.id === event.roomID) {
if (this.room.id === event.roomId) {
// Update in view
// Notice: use identifier from original message as reference, if any, \
// otherwise fallback on the actual message. This is done as the \
Expand All @@ -879,21 +887,24 @@ export default {
},

onStoreMessageRetracted(event: EventMessageGeneric): void {
if (this.room.id === event.roomID) {
if (this.room.id === event.roomId) {
// Retract from view
this.frame()?.MessagingStore.retract(event.message.id);
}
},

onStoreAvatarChangedOrFlushed({ jid }: EventAvatarGeneric): void {
return;
// Check if should re-identify (if runtime is available)
const frameRuntime = this.frame();

if (frameRuntime !== null) {
// Re-identify remote party?
if (this.jid.equals(jid) === true) {
this.identifyPartyRemote(frameRuntime);
const remotePartyJID = this.room.members.find((memberJID: JID) => {
return memberJID.equals(jid);
});

if (remotePartyJID) {
this.identifyPartyRemote(frameRuntime, remotePartyJID);
}

// Re-identify local party?
Expand Down
Loading

0 comments on commit 231290d

Please sign in to comment.