Skip to content

Commit

Permalink
final hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
melicheradam committed May 8, 2022
1 parent 4580aba commit e8905cd
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions adonisApi/app/Controllers/Ws/ChannelController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export default class ChannelController {
return new_channel
}

public async destroyChannel({ params, socket, auth }: WsContextContract) {
public async destroyChannel({ params, socket, auth }: WsContextContract, channel: number) {
//const message = await this.messageRepository.create(params.id, auth.user!.id)
// broadcast message to other users in channel
socket.broadcast.emit('channelDestroyed', params.id)
socket.broadcast.emit('channelDestroyed', channel)
// return message to sender
return true
}
Expand All @@ -34,9 +34,9 @@ export default class ChannelController {
return auth.user
}

public async addInivte({ params, socket, auth}: WsContextContract, {channelId, nickName}: {channelId: number, nickName: string}) {
public async addInvite({ params, socket, auth}: WsContextContract, {channelId, nickName}: {channelId: number, nickName: string}) {
const channel = await Channel.findOrFail(channelId)
socket.broadcast.emit('addedInvite', {channel: channel, nickName: params.nickName})
socket.broadcast.emit('addedInvite', {channel: channel, nickName: nickName})

return auth.user
}
Expand Down
2 changes: 1 addition & 1 deletion adonisApi/app/Repositories/MessageRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class MessageRepository implements MessageRepositoryContract {
const messages = await channel.related('messages').query()
.preload('user')
.orderBy('createdAt', 'desc')
.limit(10)
.limit(20)
return messages.map((message) => {
return message.serialize() as SerializedMessage
})
Expand Down
2 changes: 1 addition & 1 deletion adonisApi/database/migrations/1649084818248_invites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class Invites extends BaseSchema {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()

table.integer('from_user_id').unsigned().notNullable()
table.integer('from_user_id').unsigned()
.references('id').inTable('users').onDelete('CASCADE')
table.integer('to_user_id').unsigned().notNullable()
.references('id').inTable('users').onDelete('CASCADE')
Expand Down
1 change: 1 addition & 0 deletions adonisApi/start/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Ws.namespace('channel')
.on('setOnline', 'ChannelController.setOnline')
.on('setOffline', 'ChannelController.setOffline')
.on('destroyChannel', 'ChannelController.destroyChannel')
.on('addChannel', 'ChannelController.addChannel')
.on('addInvite', 'ChannelController.addInvite')


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default defineComponent({
methods: {
onLoad (index: number, done: (stop?: boolean) => void): void {
// fetch more messages from api
if(this.activeChannel !== null && this.channelMessages !== undefined && this.channelMessages.length > 0){
if(this.activeChannel !== null && this.channelMessages !== undefined && this.channelMessages.length > 3){
const first_message = this.channelMessages[0]
void this.$store.dispatch('channels/fetchMessages', {channel: this.channelID, lastDate: first_message.createdAt}).then(
() => done(false)
Expand Down
4 changes: 3 additions & 1 deletion quasarApp/src/services/ChannelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class ChannelOpsSocketManager extends SocketManager {
})

this.socket.on('addedInvite', ({channel, nickName}: {channel: ChannelModel, nickName: string}) => {
console.log(store.state.auth.user?.nickName)
console.log(nickName)
if(store.state.auth.user?.nickName === nickName){
//store.commit('channels/REMOVE_CHANNEL', {channel_id: channel.id})
store.commit('channels/NEW_CHANNEL', {channel: channel, type: 'invite'})
Expand All @@ -86,7 +88,7 @@ class ChannelOpsSocketManager extends SocketManager {

// notify all listeners that a new channel was created
public addInvite (data: {channelId: number, nickName: string}): Promise<ChannelModel> {
return this.emitAsync('addChannel', data)
return this.emitAsync('addInvite', data)
}


Expand Down
4 changes: 2 additions & 2 deletions quasarApp/src/store/channels/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ const mutation: MutationTree<ChannelsStateInterface> = {
state.invitesChannels = state.invitesChannels.filter(item => item.id !== channel_id)
},
JOIN_CHANNEL(state, {channel_id}: {channel_id: number}){
const channel = state.publicChannels.filter(item => item.id === channel_id)
let channel = state.publicChannels.filter(item => item.id === channel_id)
if(channel.length === 0) {
const channel = state.invitesChannels.filter(item => item.id === channel_id)
channel = state.invitesChannels.filter(item => item.id === channel_id)
}
state.joinedChannels.push(channel[0])
state.publicChannels = state.publicChannels.filter(item => item.id !== channel_id)
Expand Down

0 comments on commit e8905cd

Please sign in to comment.