This commit is contained in:
Troplo 2022-08-31 18:46:40 +10:00
parent 642b4ccf34
commit 686f602b56
5 changed files with 27 additions and 11 deletions

View file

@ -28,7 +28,7 @@ module.exports = async function (req, res, next) {
}) })
if (user) { if (user) {
if (user.banned) { if (user.banned) {
res.status(401).json(Errors.banned) res.status(401).json({ errors: [Errors.banned] })
return return
} }
await user.update({ await user.update({
@ -38,7 +38,7 @@ module.exports = async function (req, res, next) {
next() next()
} }
} else { } else {
res.status(401).json(Errors.unauthorized) res.status(401).json({ errors: [Errors.unauthorized] })
} }
} else { } else {
res.status(401).json({ res.status(401).json({

View file

@ -531,6 +531,7 @@ router.get("/:id/pins", auth, async (req, res, next) => {
{ {
model: Message, model: Message,
as: "message", as: "message",
required: true,
include: [ include: [
{ {
model: User, model: User,
@ -950,7 +951,7 @@ router.get("/:id/search", auth, async (req, res, next) => {
} }
] ]
}) })
const page = parseInt(req.params.page) || 1 const page = parseInt(req.query.page) || 1
const pager = paginate(messages.length, page, 15) const pager = paginate(messages.length, page, 15)
const result = messages.slice(pager.startIndex, pager.endIndex + 1) const result = messages.slice(pager.startIndex, pager.endIndex + 1)
res.json({ res.json({

View file

@ -1,6 +1,6 @@
{ {
"name": "colubrina", "name": "colubrina",
"version": "1.0.24", "version": "1.0.25",
"description": "Simple instant communication.", "description": "Simple instant communication.",
"private": true, "private": true,
"author": "Troplo <troplo@troplo.com>", "author": "Troplo <troplo@troplo.com>",

View file

@ -804,6 +804,7 @@ export default {
} }
}) })
.catch(() => { .catch(() => {
this.$store.dispatch("logout")
this.$router.push("/login") this.$router.push("/login")
}) })
this.getThemes() this.getThemes()

View file

@ -8,8 +8,9 @@
absolute absolute
transition="scroll-y-transition" transition="scroll-y-transition"
:close-on-content-click="false" :close-on-content-click="false"
style="z-index: 15"
> >
<v-card min-width="350" color="toolbar"> <v-card min-width="400" max-width="400" color="toolbar">
<v-toolbar color="toolbar lighten-1"> <v-toolbar color="toolbar lighten-1">
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-toolbar-title> Pins </v-toolbar-title> <v-toolbar-title> Pins </v-toolbar-title>
@ -28,6 +29,7 @@
:index="index" :index="index"
:key="pin.message.keyId" :key="pin.message.keyId"
></SimpleMessage> ></SimpleMessage>
<v-spacer></v-spacer>
<v-btn icon text @click="removePin(pin.messageId)"> <v-btn icon text @click="removePin(pin.messageId)">
<v-icon> mdi-close </v-icon> <v-icon> mdi-close </v-icon>
</v-btn> </v-btn>
@ -414,6 +416,7 @@
class="" class=""
id="search-col" id="search-col"
v-if="$store.state.searchPanel && !$vuetify.breakpoint.mobile" v-if="$store.state.searchPanel && !$vuetify.breakpoint.mobile"
style="z-index: 15"
> >
<v-card <v-card
class="d-flex flex-column fill-height" class="d-flex flex-column fill-height"
@ -464,6 +467,12 @@
></Message> ></Message>
</div> </div>
</template> </template>
<v-pagination
v-model="search.page"
class="my-4"
:length="search.pager.totalPages"
@input="doSearch"
></v-pagination>
</v-list> </v-list>
</v-card-text> </v-card-text>
</v-card> </v-card>
@ -607,7 +616,7 @@ export default {
display: false display: false
} }
}, },
offset: 0, offset: null,
nickname: { nickname: {
dialog: false, dialog: false,
nickname: "", nickname: "",
@ -637,7 +646,9 @@ export default {
search: { search: {
query: "", query: "",
results: [], results: [],
pager: {}, pager: {
totalPages: 1
},
loading: false, loading: false,
page: 1 page: 1
}, },
@ -706,6 +717,9 @@ export default {
lastRead: 0 lastRead: 0
}), }),
computed: { computed: {
offsetValue() {
return this.offset || this.messages[0]?.id || 0
},
associations() { associations() {
if (this.chat) { if (this.chat) {
return this.chat.chat.associations.slice().sort((a, b) => { return this.chat.chat.associations.slice().sort((a, b) => {
@ -799,7 +813,6 @@ export default {
!this.loadingMessages !this.loadingMessages
) { ) {
this.rateLimit = true this.rateLimit = true
this.offset += 50
this.loadingMessages = true this.loadingMessages = true
const element = document.getElementById("message-0") const element = document.getElementById("message-0")
await this.getMessages() await this.getMessages()
@ -1001,9 +1014,10 @@ export default {
lastMessage.style.backgroundColor = "" lastMessage.style.backgroundColor = ""
}, 1500) }, 1500)
} else { } else {
this.offset = id this.offset = id + 10
await this.getMessages() await this.getMessages()
this.jumpToMessage(id) this.jumpToMessage(id)
this.offset = null
} }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
@ -1072,7 +1086,7 @@ export default {
"/api/v1/communications/" + "/api/v1/communications/" +
this.$route.params.id + this.$route.params.id +
"/messages?limit=50&offset=" + "/messages?limit=50&offset=" +
this.messages[0]?.id || 0 this.offsetValue
) )
.then((res) => { .then((res) => {
if (!res.data.length) { if (!res.data.length) {
@ -1237,7 +1251,7 @@ export default {
this.replying = null this.replying = null
this.reachedTop = false this.reachedTop = false
this.avoidAutoScroll = false this.avoidAutoScroll = false
this.offset = 0 this.offset = null
this.pins = [] this.pins = []
this.messages = [] this.messages = []
this.getMessages() this.getMessages()