ad splitArray method

update_chat
adb 4 years ago
parent 5da4aaf066
commit 5a3a49ab43

@ -52,6 +52,7 @@ export class MatrixHandler {
this.client.once('sync', (state) => { this.client.once('sync', (state) => {
console.log(state); console.log(state);
this.rooms = this.client.getRooms(); this.rooms = this.client.getRooms();
console.log(this.rooms)
this.loading = false; this.loading = false;
callback(); callback();
}); });

@ -16,7 +16,7 @@
<userThumbnail v-if="(message.sender !== session.user) && (i===session.currentRoom.messages.length-1 || session.currentRoom.messages[i+1].sender!==message.sender)" <userThumbnail v-if="(message.sender !== session.user) && (i===session.currentRoom.messages.length-1 || session.currentRoom.messages[i+1].sender!==message.sender)"
:userId="message.sender" width="64" height="64" resizeMethod="scale" class="userThumbnail" /> :userId="message.sender" width="64" height="64" resizeMethod="scale" class="userThumbnail" />
</div>--> </div>-->
<div class="eventGroup" v-for="group in splitTimelineToGroups(room.timeline)" :key="group[0].origin_server_ts"> <div class="eventGroup" v-for="group in splitArray(room.timeline, obj => obj.event.sender, obj => obj.event)" :key="group[0].origin_server_ts">
<div class="username" v-if="group[0].sender !== user">{{group[0].sender}}</div> <div class="username" v-if="group[0].sender !== user">{{group[0].sender}}</div>
<div class="thumbnailContainer"> <div class="thumbnailContainer">
<userThumbnail v-if="group[0].sender !== user && room._membersPromise.length > 2" :userId="group[0].sender" width="64" height="64" resizeMethod="scale" class="userThumbnail" /> <userThumbnail v-if="group[0].sender !== user && room._membersPromise.length > 2" :userId="group[0].sender" width="64" height="64" resizeMethod="scale" class="userThumbnail" />
@ -29,16 +29,16 @@
</div> </div>
</div> </div>
</div> </div>
<newMessage /> <!--<newMessage />-->
<icon v-if="showScrollBtn" @click.native="scrollToBottom()" id="scrollDown" ic="./sym/expand_more-black-24dp.svg" /> <icon v-if="showScrollBtn" @click.native="scrollToBottom()" id="scrollDown" ic="./sym/expand_more-black-24dp.svg" />
<topBanner /> <!--<topBanner />-->
</div> </div>
</template> </template>
<script> <script>
import message from '@/components/message.vue'; import message from '@/components/message.vue';
import newMessage from '@/components/newMessage.vue'; //import newMessage from '@/components/newMessage.vue';
import topBanner from '@/components/topBanner.vue'; //import topBanner from '@/components/topBanner.vue';
import Icon from "@/components/icon"; import Icon from "@/components/icon";
import userThumbnail from '@/components/userThumbnail'; import userThumbnail from '@/components/userThumbnail';
@ -47,8 +47,8 @@ export default {
components: { components: {
Icon, Icon,
message, message,
newMessage, //newMessage,
topBanner, //topBanner,
userThumbnail userThumbnail
}, },
props: { props: {
@ -76,18 +76,15 @@ export default {
let msgContainer = document.getElementById("messagesContainer") let msgContainer = document.getElementById("messagesContainer")
this.showScrollBtn = msgContainer.scrollHeight - msgContainer.scrollTop > msgContainer.offsetHeight + 200; this.showScrollBtn = msgContainer.scrollHeight - msgContainer.scrollTop > msgContainer.offsetHeight + 200;
}, },
splitTimelineToGroups(timeline){ splitArray(arr, key, get=obj=>obj){
let payload = [[]]; let payload = [[]];
timeline.forEach((object, i) => { arr.forEach((obj, i) => {
let event = object.event; let nextObj = arr[i+1];
let nextEvent = timeline[i+1]?timeline[i+1].event:undefined; payload[payload.length-1].push(get(obj));
payload[payload.length-1].push(event); if (!nextObj) return payload;
if (!nextEvent) return payload; if (key(obj) !== key(nextObj)) payload.push([]);
if (event.sender !== nextEvent.sender ||
this.getDate(event.origin_server_ts) !== this.getDate(nextEvent.origin_server_ts)){
payload.push([]);
}
}) })
return payload;
} }
}, },
data(){ data(){

@ -20,20 +20,20 @@
<div class="roomListName">{{room.name}}</div> <div class="roomListName">{{room.name}}</div>
</div> </div>
</div> </div>
<chatInformation v-if="currentRoom" :room="currentRoom"/> <!--<chatInformation v-if="currentRoom" :room="currentRoom"/>-->
</div> </div>
</template> </template>
<script> <script>
import chat from '@/views/chat.vue'; import chat from '@/views/chat.vue';
import chatInformation from "@/components/chatInformation"; //import chatInformation from "@/components/chatInformation";
import {matrix} from "@/main"; import {matrix} from "@/main";
export default { export default {
name: "rooms", name: "rooms",
components:{ components:{
chat, chat,
chatInformation //chatInformation
}, },
methods:{ methods:{
openChat(room){ openChat(room){

Loading…
Cancel
Save