Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
ulakbus-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ulakbus
ulakbus-ui
Commits
607813a6
Commit
607813a6
authored
Jul 28, 2016
by
Vladimir Baranov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rref #5392. Process new channel and user status change messages
parent
98bc7944
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
6 deletions
+45
-6
messaging_service.js
app/components/messaging/messaging_service.js
+30
-3
socket.js
app/zetalib/socket.js
+11
-1
utils_service.js
app/zetalib/utils_service.js
+4
-2
No files found.
app/components/messaging/messaging_service.js
View file @
607813a6
...
...
@@ -19,6 +19,7 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
var
msg
=
{};
var
notificationsChannelKey
;
var
channelsMap
=
{};
var
groupedChannels
=
{};
// channels loader promise
var
channelsLoader
;
...
...
@@ -128,6 +129,7 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
currentChannelKey
=
null
;
notificationsChannelKey
=
null
;
channelsMap
=
{};
groupedChannels
=
{};
unread
.
messages
.
count
=
0
;
unread
.
notifications
.
count
=
0
;
channelsLoader
=
false
;
...
...
@@ -179,16 +181,22 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
};
channelsLoader
=
wsRequest
(
outgoing
).
then
(
function
(
data
)
{
var
grouped
=
Utils
.
groupBy
(
data
.
channels
||
[],
"type"
);
var
initialGroups
=
{};
initialGroups
[
msg
.
CHANNEL_TYPE
.
PUBLIC
]
=
[];
initialGroups
[
msg
.
CHANNEL_TYPE
.
DIRECT
]
=
[];
initialGroups
[
msg
.
CHANNEL_TYPE
.
NOTIFICATION
]
=
[];
groupedChannels
=
Utils
.
groupBy
(
data
.
channels
||
[],
"type"
,
initialGroups
);
// add all channels to channels map
for
(
var
i
=
0
;
i
<
data
.
channels
.
length
;
i
++
){
var
channel
=
data
.
channels
[
i
];
channelsMap
[
channel
.
key
]
=
channel
;
}
// save notifications channel key
notificationsChannelKey
=
grouped
[
msg
.
CHANNEL_TYPE
.
NOTIFICATION
][
0
].
key
;
notificationsChannelKey
=
grouped
Channels
[
msg
.
CHANNEL_TYPE
.
NOTIFICATION
][
0
].
key
;
return
{
grouped
:
grouped
,
channelsMap
:
channelsMap
};
return
{
grouped
:
grouped
Channels
,
channelsMap
:
channelsMap
};
});
return
channelsLoader
;
...
...
@@ -486,6 +494,25 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
increaseUnread
(
message
,
'notifications'
);
});
$rootScope
.
$on
(
"channel_change"
,
function
(
e
,
action
,
channel
){
checkIfInitialized
().
then
(
function
(){
if
(
action
==
'add'
){
var
group
=
groupedChannels
[
channel
.
type
];
if
(
!
channelsMap
[
channel
.
key
]){
channelsMap
[
channel
.
key
]
=
channel
;
}
return
group
.
push
(
channel
);
}
if
(
action
==
'status'
){
var
localChannel
=
channelsMap
[
channel
.
channel_key
];
if
(
localChannel
){
localChannel
.
is_online
=
channel
.
is_online
;
}
}
})
});
// reset state on logout
$rootScope
.
$watch
(
"loggedInUser"
,
function
(
value
){
if
(
!
value
){
...
...
app/zetalib/socket.js
View file @
607813a6
...
...
@@ -160,6 +160,16 @@ angular.module('ulakbus')
task_list
:
function
()
{
// broadcast task list to task_list directive in dashboard_widget_directives.js
$rootScope
.
$broadcast
(
'task_list'
,
msg_data
[
"task_list"
]);
},
channel_subscription
:
function
(){
$timeout
(
function
(){
$rootScope
.
$broadcast
(
'channel_change'
,
'add'
,
msg_data
);
})
},
user_status
:
function
(){
$timeout
(
function
(){
$rootScope
.
$broadcast
(
'channel_change'
,
'status'
,
msg_data
);
})
}
};
// do_action is the dispatcher function for incoming events
...
...
@@ -182,7 +192,7 @@ angular.module('ulakbus')
}
do_action
(
msg_data
,
msg_data
.
cmd
);
$log
.
info
(
"MESSAGE:"
,
event
,
"Data:"
,
JSON
.
parse
(
event
.
data
));
$log
.
info
(
"MESSAGE:"
,
msg_data
.
cmd
,
event
,
"Data:"
,
JSON
.
parse
(
event
.
data
));
};
wsOps
.
onError
=
function
(
evt
)
{
$log
.
error
(
"ERROR :: "
+
evt
);
...
...
app/zetalib/utils_service.js
View file @
607813a6
...
...
@@ -26,14 +26,16 @@ angular.module("ulakbus")
/**
* @param list {Array} Array of objects to group
* @param propName {String} property name to group array by
* @param initialObject {Object} initial object for groups setup
* @returns {Object}
*/
this
.
groupBy
=
function
(
list
,
propName
)
{
this
.
groupBy
=
function
(
list
,
propName
,
initialObject
)
{
if
(
!
initialObject
)
initialObject
=
{};
return
list
.
reduce
(
function
(
acc
,
item
)
{
(
acc
[
item
[
propName
]]
=
acc
[
item
[
propName
]]
||
[]).
push
(
item
);
return
acc
;
},
{}
);
},
initialObject
);
};
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment