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
947410e1
Commit
947410e1
authored
Jul 28, 2016
by
Vladimir Baranov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rref #5392. Improve new messages indication and message-window <-> header communication
parent
06918d29
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
60 deletions
+85
-60
messaging.js
app/components/messaging/messaging.js
+16
-39
messaging_service.js
app/components/messaging/messaging_service.js
+65
-19
directives.js
app/shared/directives.js
+4
-2
No files found.
app/components/messaging/messaging.js
View file @
947410e1
angular
.
module
(
"ulakbus.messaging"
)
angular
.
module
(
"ulakbus.messaging"
)
.
directive
(
'messaging'
,
function
(
Generator
,
MessagingService
,
$log
,
$rootScope
,
MessagingPopup
,
Utils
)
{
.
directive
(
'messaging'
,
function
(
Generator
,
MessagingService
,
$log
,
$rootScope
,
MessagingPopup
,
Utils
,
$q
)
{
// get channel key
// get channel key
function
getKey
(
channel
)
{
function
getKey
(
channel
)
{
...
@@ -30,8 +30,6 @@ angular.module("ulakbus.messaging")
...
@@ -30,8 +30,6 @@ angular.module("ulakbus.messaging")
restrict
:
'E'
,
restrict
:
'E'
,
scope
:
{},
scope
:
{},
link
:
function
(
iScope
,
iElem
,
iAttrs
){
link
:
function
(
iScope
,
iElem
,
iAttrs
){
var
channelsMap
=
{};
iScope
.
chatAppIsHidden
=
true
;
iScope
.
chatAppIsHidden
=
true
;
// reset state when user log in/log out
// reset state when user log in/log out
...
@@ -47,7 +45,6 @@ angular.module("ulakbus.messaging")
...
@@ -47,7 +45,6 @@ angular.module("ulakbus.messaging")
function
reset
(){
function
reset
(){
iScope
.
selectedChannel
=
null
;
iScope
.
selectedChannel
=
null
;
MessagingService
.
reset_current_channel
();
iScope
.
publicChannels
=
[];
iScope
.
publicChannels
=
[];
iScope
.
notificationsChannel
=
[];
iScope
.
notificationsChannel
=
[];
iScope
.
directChannels
=
[];
iScope
.
directChannels
=
[];
...
@@ -82,14 +79,7 @@ angular.module("ulakbus.messaging")
...
@@ -82,14 +79,7 @@ angular.module("ulakbus.messaging")
if
(
channel
.
messages
){
if
(
channel
.
messages
){
channel
.
messages
.
push
(
message
);
channel
.
messages
.
push
(
message
);
}
}
}
else
{
};
// update unread counter
var
ch
=
channelsMap
[
message
.
channel_key
];
if
(
ch
){
ch
.
unread
+=
1
;
}
}
updateLastMessage
(
message
);
updateLastMessage
(
message
);
}
}
...
@@ -112,13 +102,7 @@ angular.module("ulakbus.messaging")
...
@@ -112,13 +102,7 @@ angular.module("ulakbus.messaging")
// FIXME: change to proper moment processing
// FIXME: change to proper moment processing
// var ts = iScope.lastMessage.moment.toISOString();
// var ts = iScope.lastMessage.moment.toISOString();
var
ts
=
iScope
.
lastMessage
.
moment
.
format
(
"YYYY-MM-DDTHH:mm:ss"
);
var
ts
=
iScope
.
lastMessage
.
moment
.
format
(
"YYYY-MM-DDTHH:mm:ss"
);
MessagingService
.
report_last_seen_message
(
getKey
(
iScope
.
selectedChannel
),
iScope
.
lastMessage
.
key
,
ts
).
then
(
function
(){
MessagingService
.
report_last_seen_message
(
getKey
(
iScope
.
selectedChannel
),
iScope
.
lastMessage
.
key
,
ts
);
// set unread to 0 in channels list
var
ch
=
channelsMap
[
getKey
(
iScope
.
selectedChannel
)];
if
(
ch
){
ch
.
unread
=
0
;
}
})
};
};
iScope
.
deleteConfirmation
=
function
(
title
){
iScope
.
deleteConfirmation
=
function
(
title
){
...
@@ -132,20 +116,12 @@ angular.module("ulakbus.messaging")
...
@@ -132,20 +116,12 @@ angular.module("ulakbus.messaging")
};
};
iScope
.
updateChannelsList
=
function
(){
iScope
.
updateChannelsList
=
function
(){
return
MessagingService
.
list_channels
().
then
(
function
(
groupedChannels
)
{
return
MessagingService
.
list_channels
().
then
(
function
(
channels
)
{
var
groupedChannels
=
channels
.
grouped
;
iScope
.
publicChannels
=
groupedChannels
[
MessagingService
.
CHANNEL_TYPE
.
PUBLIC
];
iScope
.
publicChannels
=
groupedChannels
[
MessagingService
.
CHANNEL_TYPE
.
PUBLIC
];
iScope
.
notificationsChannel
=
groupedChannels
[
MessagingService
.
CHANNEL_TYPE
.
NOTIFICATION
][
0
];
iScope
.
notificationsChannel
=
groupedChannels
[
MessagingService
.
CHANNEL_TYPE
.
NOTIFICATION
][
0
];
iScope
.
directChannels
=
groupedChannels
[
MessagingService
.
CHANNEL_TYPE
.
DIRECT
];
iScope
.
directChannels
=
groupedChannels
[
MessagingService
.
CHANNEL_TYPE
.
DIRECT
];
// add all channels to channels map
for
(
var
key
in
groupedChannels
){
if
(
groupedChannels
.
hasOwnProperty
(
key
)){
var
channels
=
groupedChannels
[
key
];
channels
.
forEach
(
function
(
channel
){
channelsMap
[
channel
.
key
]
=
channel
;
})
}
}
console
.
error
(
"CHALLL : "
,
channelsMap
);
});
});
}
}
...
@@ -262,11 +238,10 @@ angular.module("ulakbus.messaging")
...
@@ -262,11 +238,10 @@ angular.module("ulakbus.messaging")
function
selectChannel
(
channelKey
,
silent
){
function
selectChannel
(
channelKey
,
silent
){
if
(
!
silent
)
iScope
.
loadingChannel
=
true
;
if
(
!
silent
)
iScope
.
loadingChannel
=
true
;
return
MessagingService
.
show_channel
(
channelKey
).
then
(
function
(
result
){
return
MessagingService
.
show_channel
(
channelKey
)
return
result
;
.
finally
(
function
(){
}).
finally
(
function
(){
iScope
.
loadingChannel
=
false
;
iScope
.
loadingChannel
=
false
;
})
})
}
}
iScope
.
selectChannel
=
function
(
channel
,
silent
){
iScope
.
selectChannel
=
function
(
channel
,
silent
){
...
@@ -354,11 +329,13 @@ angular.module("ulakbus.messaging")
...
@@ -354,11 +329,13 @@ angular.module("ulakbus.messaging")
});
});
$rootScope
.
$on
(
MessagingService
.
SHOW_MESSAGING_WINDOW_EVENT
,
function
(
e
,
channelKey
){
$rootScope
.
$on
(
MessagingService
.
SHOW_MESSAGING_WINDOW_EVENT
,
function
(
e
,
channelKey
){
var
showApp
=
$q
.
when
();
if
(
iScope
.
chatAppIsHidden
){
if
(
iScope
.
chatAppIsHidden
){
iScope
.
showApp
().
then
(
function
(){
showApp
=
iScope
.
showApp
();
if
(
channelKey
){
}
iScope
.
selectChannel
(
channelKey
);
if
(
channelKey
&&
channelKey
!=
getKey
(
iScope
.
selectedChannel
)){
}
showApp
.
then
(
function
(){
iScope
.
selectChannel
(
channelKey
);
})
})
}
}
})
})
...
...
app/components/messaging/messaging_service.js
View file @
947410e1
...
@@ -18,6 +18,9 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
...
@@ -18,6 +18,9 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
.
factory
(
'MessagingService'
,
function
(
$q
,
$timeout
,
$compile
,
$log
,
$rootScope
,
Moment
,
WSOps
,
Utils
)
{
.
factory
(
'MessagingService'
,
function
(
$q
,
$timeout
,
$compile
,
$log
,
$rootScope
,
Moment
,
WSOps
,
Utils
)
{
var
msg
=
{};
var
msg
=
{};
var
notificationsChannelKey
;
var
notificationsChannelKey
;
var
channelsMap
=
{};
// channels loader promise
var
channelsLoader
;
msg
.
CHANNEL_TYPE
=
{
msg
.
CHANNEL_TYPE
=
{
"PUBLIC"
:
15
,
"PUBLIC"
:
15
,
...
@@ -67,7 +70,37 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
...
@@ -67,7 +70,37 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
if
(
!
messagingAppIsHidden
&&
message
.
channel_key
==
currentChannelKey
){
if
(
!
messagingAppIsHidden
&&
message
.
channel_key
==
currentChannelKey
){
return
;
return
;
}
}
unread
[
messageType
].
count
+=
1
;
checkIfInitialized
().
then
(
function
(){
var
channel
=
channelsMap
[
message
.
channel_key
];
if
(
channel
){
channel
.
unread
+=
1
;
}
unread
[
messageType
].
count
+=
1
;
})
}
function
decreaseUnread
(
channel
){
// get channel from channelsMap. Channels in channelMap has unread property
// which is updated when messages arrive
channel
=
channelsMap
[
channel
.
key
];
if
(
channel
&&
channel
.
unread
){
var
counter
;
if
(
channel
.
type
==
msg
.
CHANNEL_TYPE
.
NOTIFICATION
){
counter
=
unread
.
notifications
}
else
{
counter
=
unread
.
messages
;
}
counter
.
count
-=
channel
.
unread
;
if
(
counter
.
count
<
0
)
counter
.
count
=
0
;
channel
.
unread
=
0
;
}
}
function
checkIfInitialized
(){
if
(
!
channelsLoader
){
return
msg
.
list_channels
()
}
return
channelsLoader
;
}
}
// prepare message to show in UI
// prepare message to show in UI
...
@@ -82,21 +115,28 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
...
@@ -82,21 +115,28 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
};
};
msg
.
get_notifications_channel_key
=
function
(){
msg
.
get_notifications_channel_key
=
function
(){
return
notificationsChannelKey
;
return
checkIfInitialized
().
then
(
function
(){
return
notificationsChannelKey
;
});
};
};
msg
.
get_unread_counters
=
function
(){
msg
.
get_unread_counters
=
function
(){
return
unread
;
return
unread
;
};
};
msg
.
reset_
current_channel
=
function
(){
msg
.
reset_
state
=
function
(){
currentChannelKey
=
null
;
currentChannelKey
=
null
;
notificationsChannelKey
=
null
;
channelsMap
=
{};
unread
.
messages
.
count
=
0
;
unread
.
notifications
.
count
=
0
;
channelsLoader
=
false
;
}
}
msg
.
toggle_messaging_window_visibility
=
function
(
visibility
,
reset
CurrentChannel
){
msg
.
toggle_messaging_window_visibility
=
function
(
visibility
,
reset
State
){
messagingAppIsHidden
=
!
visibility
;
messagingAppIsHidden
=
!
visibility
;
if
(
reset
CurrentChannel
){
if
(
reset
State
){
msg
.
reset_
current_channel
();
msg
.
reset_
state
();
}
}
};
};
...
@@ -137,13 +177,21 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
...
@@ -137,13 +177,21 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
var
outgoing
=
{
var
outgoing
=
{
view
:
'_zops_list_channels'
view
:
'_zops_list_channels'
};
};
return
wsRequest
(
outgoing
).
then
(
function
(
data
)
{
console
.
error
(
"channels: "
,
data
.
channels
);
channelsLoader
=
wsRequest
(
outgoing
).
then
(
function
(
data
)
{
var
grouped
=
Utils
.
groupBy
(
data
.
channels
||
[],
"type"
);
var
grouped
=
Utils
.
groupBy
(
data
.
channels
||
[],
"type"
);
// 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
// save notifications channel key
notificationsChannelKey
=
grouped
[
msg
.
CHANNEL_TYPE
.
NOTIFICATION
][
0
].
key
;
notificationsChannelKey
=
grouped
[
msg
.
CHANNEL_TYPE
.
NOTIFICATION
][
0
].
key
;
return
grouped
;
return
{
grouped
:
grouped
,
channelsMap
:
channelsMap
};
});
});
return
channelsLoader
;
};
};
msg
.
search_user
=
function
(
query
)
{
msg
.
search_user
=
function
(
query
)
{
...
@@ -264,16 +312,7 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
...
@@ -264,16 +312,7 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
return
wsRequest
(
outgoing
).
then
(
function
(
result
){
return
wsRequest
(
outgoing
).
then
(
function
(
result
){
$log
.
info
(
"Show channel "
,
channelKey
,
": "
,
result
);
$log
.
info
(
"Show channel "
,
channelKey
,
": "
,
result
);
// decrease unread messages for current channel
// decrease unread messages for current channel
if
(
result
.
unread
){
decreaseUnread
(
result
);
var
counter
;
if
(
result
.
type
==
msg
.
CHANNEL_TYPE
.
NOTIFICATION
){
counter
=
unread
.
notifications
}
else
{
counter
=
unread
.
messages
;
}
counter
.
count
-=
result
.
unread
;
if
(
counter
.
count
<
0
)
counter
.
count
=
0
;
}
// save current channel key
// save current channel key
currentChannelKey
=
result
.
key
;
currentChannelKey
=
result
.
key
;
prepareMessages
(
result
.
last_messages
);
prepareMessages
(
result
.
last_messages
);
...
@@ -444,6 +483,13 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
...
@@ -444,6 +483,13 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
increaseUnread
(
message
,
'notifications'
);
increaseUnread
(
message
,
'notifications'
);
});
});
// reset state on logout
$rootScope
.
$watch
(
"loggedInUser"
,
function
(
value
){
if
(
!
value
){
msg
.
reset_state
();
};
});
return
msg
;
return
msg
;
})
})
...
...
app/shared/directives.js
View file @
947410e1
...
@@ -48,8 +48,10 @@ angular.module('ulakbus')
...
@@ -48,8 +48,10 @@ angular.module('ulakbus')
$scope
.
showMessagesWindow
=
function
(
type
){
$scope
.
showMessagesWindow
=
function
(
type
){
if
(
type
==
'notifications'
){
if
(
type
==
'notifications'
){
var
channelKey
=
MessagingService
.
get_notifications_channel_key
();
return
MessagingService
.
get_notifications_channel_key
()
return
MessagingService
.
show_messaging_window
(
channelKey
);
.
then
(
function
(
channelKey
){
return
MessagingService
.
show_messaging_window
(
channelKey
);
})
}
}
MessagingService
.
show_messaging_window
();
MessagingService
.
show_messaging_window
();
}
}
...
...
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