Newer
Older
import { $gettext } from './gettext';
const Blubber = {
App: null, //This app is not always available. The app is blubber with a widget and the threads next to it.
threads: [],
components: {
BlubberGlobalstream: () => import('../../../vue/components/BlubberGlobalstream.vue'),
BlubberPublicComposer: () => import('../../../vue/components/BlubberPublicComposer.vue'),
BlubberThread: () => import('../../../vue/components/BlubberThread.vue'),
BlubberThreadWidget: () => import('../../../vue/components/BlubberThreadWidget.vue'),
},
let components = STUDIP.Blubber.components;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
if ($('#blubber-index, #messenger-course, .blubber_panel.vueinstance').length) {
STUDIP.JSUpdater.register('blubber', Blubber.updateState, Blubber.getParamsForPolling);
let panel_data = $('.blubber_panel').data();
STUDIP.Vue.load().then(({createApp}) => {
STUDIP.Blubber.App = createApp({
el: '#layout_container',
data: {
threads: $('.blubber_threads_widget').data('threads_data'),
thread_data: panel_data.thread_data,
active_thread: panel_data.active_thread,
threads_more_down: panel_data.threads_more_down,
waiting: false,
display_context_posting: 0
},
methods: {
changeActiveThread: function (thread_id) {
this.waiting = true;
let search = jQuery("form.sidebar-search input[name=search]").val();
let parameters = search ? {data: {"search": search}} : {};
STUDIP.api.GET(`blubber/threads/${thread_id}`, parameters).done((data) => {
this.active_thread = thread_id;
this.thread_data = data;
}).always(() => {
this.waiting = false;
}).fail(() => {
window.alert($gettext("Konnte die Konversation nicht laden. Probieren Sie es nachher erneut."));
});
for (let i in this.threads) {
if (this.threads[i].thread_id === thread_id) {
this.threads[i].unseen_comments = 0;
}
}
}
},
components,
});
});

Jan-Hendrik Willms
committed
$(document).on('submit', 'form.sidebar-search', function (event) {
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
this.waiting = true;
let search = jQuery("form.sidebar-search input[name=search]").val();
if ($('#messenger-course').length === 0) {
STUDIP.api.GET(`blubber/threads`, {data: {"search": search}}).done((data) => {
STUDIP.Blubber.App.threads = data.threads;
STUDIP.Blubber.App.threads_more_down = data.more_down;
$('.blubber_thread_widget')[0].__vue__.display_more_down = data.more_down;
}).always(() => {
this.waiting = false;
}).fail(() => {
window.alert($gettext("Konnte die Suche nicht ausführen. Probieren Sie es nachher erneut."));
});
}
let parameters = search ? {"search": search} : {"modifier": "olderthan"};
STUDIP.api.GET(`blubber/threads/` + STUDIP.Blubber.App.active_thread + `/comments`, {data: parameters}).done((data) => {
STUDIP.Blubber.App.thread_data.comments = data.comments;
STUDIP.Blubber.App.thread_data.more_up = data.more_up;
STUDIP.Blubber.App.thread_data.more_down = data.more_down;
$('.blubber_thread')[0].__vue__.scrollDown();
}).always(() => {
this.waiting = false;
}).fail(() => {
window.alert($gettext("Konnte die Suche nicht ausführen. Probieren Sie es nachher erneut."));
});
event.preventDefault();
return false;
});
jQuery('#blubber-index, #messenger-course').on("click", 'a.blubber_hashtag', function (event) {
let tag = jQuery(this).closest("a").data("tag");
jQuery("form.sidebar-search input[name=search]").val("#" + tag);
jQuery("form.sidebar-search").trigger("submit");
event.preventDefault();
return false;
});
}
$(document).on('dialog-open', function() {
$('.studip-dialog .blubber_panel').each(function () {
STUDIP.JSUpdater.register('blubber', Blubber.updateState, Blubber.getParamsForPolling);
let panel_data = $(this).data();
STUDIP.Vue.load().then(({createApp}) => {
createApp({
el: this,
data: {
threads: panel_data.threads_data,
thread_data: panel_data.thread_data,
active_thread: panel_data.active_thread,
threads_more_down: panel_data.threads_more_down,
waiting: false,
display_context_posting: 0
},
components,
});
});
});
});
},
updateState(datagram) {
for (const [method, data] of Object.entries(datagram)) {
if (method in Blubber) {
Blubber[method](data);
}
}
},
getParamsForPolling () {
const data = {
threads: [],
};
$('.blubber_thread').each(function () {
data.threads.push(this.__vue__._props.thread_data.thread_posting.thread_id);
});
return data;
},
addNewComments (blubberdata) {
$('.blubber_thread').each(function () {
for (let thread_id in blubberdata) {
if (this.__vue__._props.thread_data.thread_posting.thread_id === thread_id) {
this.__vue__.addComments(blubberdata[thread_id], true);
this.__vue__.scrollDown();
}
}
});
},
removeDeletedComments: function (comment_ids) {
$('.blubber_thread').each(function () {
this.__vue__.removeDeletedComments(comment_ids);
});
},
updateThreadWidget (threaddata) {
for (let i in threaddata) {
let exists = false;
for (let k in STUDIP.Blubber.App.threads) {
if (STUDIP.Blubber.App.threads[k].thread_id == threaddata[i].thread_id) {
exists = true;
STUDIP.Blubber.App.threads[k].name = threaddata[i].name;
STUDIP.Blubber.App.threads[k].timestamp = threaddata[i].timestamp;
STUDIP.Blubber.App.threads[k].avatar = threaddata[i].avatar;
}
}
if (!exists) {
STUDIP.Blubber.App.threads.push(threaddata[i]);
}
}
},
refreshThread (data) {
STUDIP.Blubber.App.changeActiveThread(data.thread_id);
},
followunfollow (thread_id, follow) {
const elements = $(`.blubber_panel .followunfollow[data-thread_id="${thread_id}"]`);
if (follow === undefined) {
follow = elements.hasClass('unfollowed');
}
elements.addClass('loading');
const promise = follow
? STUDIP.api.POST(`blubber/threads/${thread_id}/follow`)
: STUDIP.api.DELETE(`blubber/threads/${thread_id}/follow`);
return promise.then(() => {
elements.toggleClass('unfollowed', !follow);
return follow;
}).always(() => {
elements.removeClass('loading');
}).promise();
},
Composer: {
vue: null,
init () {
STUDIP.Vue.load().then(({createApp}) => {
let components = STUDIP.Blubber.components;
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
return createApp({
el: '#blubber_contact_ids',
data: {
users: []
},
methods: {
addUser: function (user_id, name) {
this.users.push({
user_id: user_id,
name: name
});
},
removeUser: function (event) {
let user_id = $(event.target).closest('li').find('input').val();
for (let i in this.users) {
if (this.users[i].user_id === user_id) {
this.$delete(this.users, i);
}
}
},
clearUsers: function () {
this.users = [];
}
},
components,
});
}).then((app) => {
STUDIP.Blubber.Composer.vue = app;
});
}
}
};
export default Blubber;