2017-06-02 20:55:02 +00:00
< template lang = "pug" >
2017-09-07 19:26:53 +00:00
. row ( v - if = "group._id" )
2017-08-22 05:04:56 +00:00
group - form - modal ( v - if = 'isParty' )
2017-08-01 18:52:49 +00:00
invite - modal ( : group = 'this.group' )
2017-07-29 22:08:36 +00:00
start - quest - modal ( : group = 'this.group' )
2017-09-30 13:28:39 +00:00
quest - details - modal ( : group = 'this.group' )
2017-10-02 01:42:02 +00:00
group - gems - modal
2017-09-30 13:34:25 +00:00
. col - 12. col - sm - 8. standard - page
2017-06-02 20:55:02 +00:00
. row
2017-12-26 23:31:00 +00:00
. col - 12. col - md - 6. title - details
2017-06-27 20:02:55 +00:00
h1 { { group . name } }
strong . float - left ( v - once ) { { $t ( 'groupLeader' ) } }
2017-09-25 18:02:12 +00:00
span . leader . float - left ( v - if = 'group.leader.profile' , @ click = 'showMemberProfile(group.leader)' ) : { { group . leader . profile . name } }
2017-12-26 23:31:00 +00:00
. col - 12. col - md - 6
2017-06-27 20:02:55 +00:00
. row . icon - row
2017-07-29 22:08:36 +00:00
. col - 4. offset - 4 ( v - bind : class = "{ 'offset-8': isParty }" )
. item - with - icon ( @ click = "showMemberModal()" )
2017-08-09 16:56:48 +00:00
. svg - icon . shield ( v - html = "icons.goldGuildBadgeIcon" , v - if = 'group.memberCount > 1000' )
. svg - icon . shield ( v - html = "icons.silverGuildBadgeIcon" , v - if = 'group.memberCount > 100 && group.memberCount < 999' )
. svg - icon . shield ( v - html = "icons.bronzeGuildBadgeIcon" , v - if = 'group.memberCount < 100' )
2017-09-25 18:02:12 +00:00
span . number { { group . memberCount | abbrNum } }
2018-01-29 21:44:22 +00:00
div . member - list ( v - once ) { { $t ( 'memberList' ) } }
2017-07-29 22:08:36 +00:00
. col - 4 ( v - if = '!isParty' )
2017-10-02 01:42:02 +00:00
. item - with - icon ( @ click = 'showGroupGems()' )
2017-06-27 20:02:55 +00:00
. svg - icon . gem ( v - html = "icons.gem" )
2017-08-09 16:56:48 +00:00
span . number { { group . balance * 4 } }
2017-06-27 20:02:55 +00:00
div ( v - once ) { { $t ( 'guildBank' ) } }
2017-06-02 20:55:02 +00:00
. row . chat - row
. col - 12
h3 ( v - once ) { { $t ( 'chat' ) } }
2017-09-01 21:26:10 +00:00
. row . new - message - row
2018-05-11 20:18:41 +00:00
textarea ( : placeholder = "!isParty ? $t('chatPlaceholder') : $t('partyChatPlaceholder')" , v - model = 'newMessage' , @ keydown = 'updateCarretPosition' , @ keyup . ctrl . enter = 'sendMessageShortcut()' , @ paste = 'disableMessageSendShortcut()' )
2017-09-01 21:26:10 +00:00
autocomplete ( : text = 'newMessage' , v - on : select = "selectedAutocomplete" , : coords = 'coords' , : chat = 'group.chat' )
2018-01-29 21:44:22 +00:00
. row . chat - actions
. col - 6. chat - receive - actions
2017-09-25 18:02:12 +00:00
button . btn . btn - secondary . float - left . fetch ( v - once , @ click = 'fetchRecentMessages()' ) { { $t ( 'fetchRecentMessages' ) } }
button . btn . btn - secondary . float - left ( v - once , @ click = 'reverseChat()' ) { { $t ( 'reverseChat' ) } }
2018-01-29 21:44:22 +00:00
. col - 6. chat - send - actions
2017-10-01 04:54:12 +00:00
button . btn . btn - secondary . send - chat . float - right ( v - once , @ click = 'sendMessage()' ) { { $t ( 'send' ) } }
2018-01-29 21:18:20 +00:00
community - guidelines
2018-02-11 15:34:57 +00:00
. row ( v - if = 'showNoNotificationsMessage' )
. col - 12. no - notifications
| { { $t ( 'groupNoNotifications' ) } }
2017-09-01 21:26:10 +00:00
. row
. col - 12. hr
2018-02-06 16:53:43 +00:00
chat - message ( : chat . sync = 'group.chat' , : group - id = 'group._id' , : group - name = 'group.name' )
2017-09-30 13:34:25 +00:00
. col - 12. col - sm - 4. sidebar
2017-08-03 20:04:03 +00:00
. row ( : class = '{"guild-background": !isParty}' )
2018-01-29 21:44:22 +00:00
. col - 12
2017-06-27 20:02:55 +00:00
. button - container
2017-08-26 02:56:21 +00:00
button . btn . btn - success ( class = 'btn-success' , v - if = 'isLeader && !group.purchased.active' , @ click = 'upgradeGroup()' )
| { { $t ( 'upgrade' ) } }
2017-06-27 20:02:55 +00:00
. button - container
2017-10-04 02:15:00 +00:00
button . btn . btn - primary ( b - btn , @ click = "updateGuild" , v - once , v - if = 'isLeader || isAdmin' ) { { $t ( 'edit' ) } }
2017-06-27 20:02:55 +00:00
. button - container
2017-08-09 16:56:48 +00:00
button . btn . btn - success ( class = 'btn-success' , v - if = '!isMember' , @ click = 'join()' ) { { $t ( 'join' ) } }
2017-06-27 20:02:55 +00:00
. button - container
2017-07-25 14:24:40 +00:00
button . btn . btn - primary ( v - once , @ click = 'showInviteModal()' ) { { $t ( 'invite' ) } }
2017-10-04 02:15:00 +00:00
// @TODO: hide the invitation button if there's an active group plan and the player is not the leader
2017-06-27 20:02:55 +00:00
. button - container
2017-10-04 02:15:00 +00:00
// @TODO: V2 button.btn.btn-primary(v-once, v-if='!isLeader') {{$t('messageGuildLeader')}} // Suggest making the button visible to the leader too - useful for them to test how the feature works or to send a note to themself. -- Alys
2017-06-27 20:02:55 +00:00
. button - container
2017-10-04 02:15:00 +00:00
// @TODO: V2 button.btn.btn-primary(v-once, v-if='isMember && !isParty') {{$t('donateGems')}} // Suggest removing the isMember restriction - it's okay if non-members donate to a public guild. Also probably allow it for parties if parties can buy imagery. -- Alys
2017-07-29 22:08:36 +00:00
. section - header ( v - if = 'isParty' )
2017-12-06 16:13:44 +00:00
quest - sidebar - section ( @ toggle = 'toggleQuestSection' , : show = 'sections.quest' , : group = 'group' )
2017-09-25 18:02:12 +00:00
. section - header ( v - if = '!isParty' )
2017-06-27 20:02:55 +00:00
. row
. col - 10
2017-08-22 20:39:45 +00:00
h3 ( v - once ) { { $t ( 'guildSummary' ) } }
2017-06-27 20:02:55 +00:00
. col - 2
2017-08-22 20:39:45 +00:00
. toggle - up ( @ click = "sections.summary = !sections.summary" , v - if = "sections.summary" )
2017-06-27 20:02:55 +00:00
. svg - icon ( v - html = "icons.upIcon" )
2017-08-22 20:39:45 +00:00
. toggle - down ( @ click = "sections.summary = !sections.summary" , v - if = "!sections.summary" )
2017-06-27 20:02:55 +00:00
. svg - icon ( v - html = "icons.downIcon" )
2017-08-22 20:39:45 +00:00
. section ( v - if = "sections.summary" )
2017-09-13 18:31:23 +00:00
p ( v - markdown = 'group.summary' )
2017-06-27 20:02:55 +00:00
. section - header
. row
. col - 10
2017-08-22 20:39:45 +00:00
h3 { { $t ( 'groupDescription' ) } }
2017-06-27 20:02:55 +00:00
. col - 2
2017-08-22 20:39:45 +00:00
. toggle - up ( @ click = "sections.description = !sections.description" , v - if = "sections.description" )
2017-06-27 20:02:55 +00:00
. svg - icon ( v - html = "icons.upIcon" )
2017-08-22 20:39:45 +00:00
. toggle - down ( @ click = "sections.description = !sections.description" , v - if = "!sections.description" )
2017-06-27 20:02:55 +00:00
. svg - icon ( v - html = "icons.downIcon" )
2017-08-22 20:39:45 +00:00
. section ( v - if = "sections.description" )
2017-08-23 19:36:43 +00:00
p ( v - markdown = 'group.description' )
2017-06-27 20:02:55 +00:00
. section - header . challenge
. row
. col - 10. information - header
h3 ( v - once )
| { { $t ( 'challenges' ) } }
2017-09-01 13:15:54 +00:00
# groupPrivateDescOrChallengeInfo . icon . tooltip - wrapper ( : title = "isParty ? $t('challengeDetails') : $t('privateDescription')" )
2017-06-27 20:02:55 +00:00
. svg - icon ( v - html = 'icons.information' )
2017-09-01 13:15:54 +00:00
b - tooltip (
: title = "isParty ? $t('challengeDetails') : $t('privateDescription')" ,
target = "groupPrivateDescOrChallengeInfo" ,
)
2017-06-27 20:02:55 +00:00
. col - 2
. toggle - up ( @ click = "sections.challenges = !sections.challenges" , v - if = "sections.challenges" )
. svg - icon ( v - html = "icons.upIcon" )
. toggle - down ( @ click = "sections.challenges = !sections.challenges" , v - if = "!sections.challenges" )
. svg - icon ( v - html = "icons.downIcon" )
. section ( v - if = "sections.challenges" )
2017-07-29 22:08:36 +00:00
group - challenges ( : groupId = 'searchId' )
2017-06-27 20:02:55 +00:00
div . text - center
2018-01-29 20:52:28 +00:00
button . btn . btn - danger ( v - if = 'isMember' , @ click = 'clickLeave()' ) { { isParty ? $t ( 'leaveParty' ) : $t ( 'leaveGroup' ) } }
2017-06-02 20:55:02 +00:00
< / template >
< style lang = "scss" scoped >
2017-06-27 20:02:55 +00:00
@ import '~client/assets/scss/colors.scss' ;
2017-06-02 20:55:02 +00:00
2017-12-01 13:47:45 +00:00
@ media ( min - width : 1300 px ) {
. standard - page {
2017-12-04 17:24:04 +00:00
max - width : calc ( 100 % - 430 px ) ;
2017-12-01 13:47:45 +00:00
}
. sidebar {
max - width : 430 px ! important ;
}
}
2017-07-29 22:08:36 +00:00
h1 {
color : $purple - 200 ;
}
2017-09-25 18:02:12 +00:00
. leader : hover {
cursor : pointer ;
}
2017-06-27 20:02:55 +00:00
. button - container {
margin - bottom : 1 em ;
2017-06-02 20:55:02 +00:00
2017-06-27 20:02:55 +00:00
button {
width : 100 % ;
}
}
. item - with - icon {
border - radius : 2 px ;
background - color : # ffffff ;
box - shadow : 0 2 px 2 px 0 rgba ( 26 , 24 , 29 , 0.16 ) , 0 1 px 4 px 0 rgba ( 26 , 24 , 29 , 0.12 ) ;
padding : 1 em ;
2017-07-29 22:08:36 +00:00
text - align : center ;
. svg - icon . shield , . svg - icon . gem {
2017-08-21 15:36:31 +00:00
width : 28 px ;
2018-01-29 21:44:22 +00:00
height : auto ;
2017-07-29 22:08:36 +00:00
margin : 0 auto ;
2017-07-31 19:54:52 +00:00
display : inline - block ;
2017-08-21 15:36:31 +00:00
vertical - align : bottom ;
margin - right : 0.5 em ;
2017-07-29 22:08:36 +00:00
}
. number {
font - size : 22 px ;
font - weight : bold ;
}
2018-01-29 21:44:22 +00:00
. member - list {
margin - top : .5 em ;
}
2017-07-29 22:08:36 +00:00
}
. item - with - icon : hover {
cursor : pointer ;
2017-06-27 20:02:55 +00:00
}
2017-06-02 20:55:02 +00:00
2017-06-27 20:02:55 +00:00
. sidebar {
background - color : $gray - 600 ;
2017-07-29 22:08:36 +00:00
padding - bottom : 2 em ;
2018-01-29 21:44:22 +00:00
padding - top : 2.8 em ;
2017-06-02 20:55:02 +00:00
}
2017-06-27 20:02:55 +00:00
. card {
margin : 2 em 0 ;
padding : 1 em ;
h3 . leader {
color : $purple - 200 ;
}
. text {
font - size : 16 px ;
line - height : 1.43 ;
color : $gray - 50 ;
}
}
. guild - background {
2017-07-31 19:54:52 +00:00
background - image : url ( '~assets/images/groups/grassy-meadow-backdrop.png' ) ;
height : 246 px ;
2017-06-27 20:02:55 +00:00
}
textarea {
height : 150 px ;
width : 100 % ;
background - color : $white ;
border : solid 1 px $gray - 400 ;
2017-06-02 20:55:02 +00:00
font - size : 16 px ;
line - height : 1.43 ;
2017-06-27 20:02:55 +00:00
color : $gray - 300 ;
padding : .5 em ;
2017-06-02 20:55:02 +00:00
}
2017-06-27 20:02:55 +00:00
2017-08-07 20:26:17 +00:00
textarea : : - webkit - input - placeholder { /* Chrome/Opera/Safari */
font - style : italic ;
}
textarea : : - moz - placeholder { /* Firefox 19+ */
font - style : italic ;
}
textarea : - ms - input - placeholder { /* IE 10+ */
font - style : italic ;
}
textarea : - moz - placeholder { /* Firefox 18- */
font - style : italic ;
}
2017-06-27 20:02:55 +00:00
. title - details {
padding - top : 1 em ;
padding - left : 1 em ;
}
. icon - row {
margin - top : 1 em ;
. number {
font - size : 22 px ;
font - weight : bold ;
}
}
. chat - row {
margin - top : 2 em ;
2017-09-01 21:26:10 +00:00
. new - message - row {
position : relative ;
}
2018-01-29 21:44:22 +00:00
. chat - actions {
margin - top : 1 em ;
. chat - receive - actions {
padding - left : 0 ;
button {
margin - bottom : 1 em ;
& : not ( : last - child ) {
margin - right : 1 em ;
}
}
}
. chat - send - actions {
padding - right : 0 ;
}
}
2017-06-27 20:02:55 +00:00
}
span . action {
font - size : 14 px ;
line - height : 1.33 ;
color : $gray - 200 ;
font - weight : 500 ;
2017-06-08 19:04:19 +00:00
margin - right : 1 em ;
2017-06-02 20:55:02 +00:00
}
2017-06-27 20:02:55 +00:00
span . action . icon {
margin - right : .3 em ;
}
. information - header {
h3 , . tooltip - wrapper {
display : inline - block ;
}
. tooltip - wrapper {
2017-08-07 20:26:17 +00:00
width : 15 px ;
margin - left : 1.2 em ;
2017-06-27 20:02:55 +00:00
}
}
. section - header {
border - top : 1 px solid # e1e0e3 ;
margin - top : 1 em ;
padding - top : 1 em ;
}
. section - header . challenge {
border - bottom : 1 px solid # e1e0e3 ;
margin - bottom : 1 em ;
padding - bottom : 1 em ;
}
2017-09-01 21:26:10 +00:00
. hr {
width : 100 % ;
height : 20 px ;
border - bottom : 1 px solid $gray - 500 ;
text - align : center ;
margin : 2 em 0 ;
}
2018-02-11 15:34:57 +00:00
. no - notifications {
border - radius : 4 px ;
border : solid 1 px $orange - 10 ;
padding : 1 em ;
margin - top : 3 em ;
text - align : center ;
font - size : 14 px ;
font - weight : bold ;
color : $orange - 50 ;
}
2017-06-02 20:55:02 +00:00
< / style >
< script >
2017-09-30 13:28:39 +00:00
// @TODO: Break this down into components
2017-09-29 21:03:43 +00:00
import debounce from 'lodash/debounce' ;
2017-08-18 20:29:49 +00:00
import extend from 'lodash/extend' ;
2017-06-02 20:55:02 +00:00
import groupUtilities from 'client/mixins/groupsUtilities' ;
2017-07-29 22:08:36 +00:00
import styleHelper from 'client/mixins/styleHelper' ;
2017-06-02 20:55:02 +00:00
import { mapState } from 'client/libs/store' ;
2017-09-08 19:23:58 +00:00
import * as Analytics from 'client/libs/analytics' ;
2017-06-02 20:55:02 +00:00
import membersModal from './membersModal' ;
2017-07-29 22:08:36 +00:00
import startQuestModal from './startQuestModal' ;
2017-09-30 13:28:39 +00:00
import questDetailsModal from './questDetailsModal' ;
2017-06-27 20:02:55 +00:00
import groupFormModal from './groupFormModal' ;
2017-07-25 14:24:40 +00:00
import inviteModal from './inviteModal' ;
2017-07-21 17:00:36 +00:00
import chatMessage from '../chat/chatMessages' ;
2017-08-07 20:26:17 +00:00
import autocomplete from '../chat/autoComplete' ;
2017-07-26 15:05:13 +00:00
import groupChallenges from '../challenges/groupChallenges' ;
2017-10-02 01:42:02 +00:00
import groupGemsModal from 'client/components/groups/groupGemsModal' ;
2017-12-06 16:13:44 +00:00
import questSidebarSection from 'client/components/groups/questSidebarSection' ;
2017-08-23 19:36:43 +00:00
import markdownDirective from 'client/directives/markdown' ;
2018-01-29 21:18:20 +00:00
import communityGuidelines from './communityGuidelines' ;
2017-06-27 20:02:55 +00:00
2017-06-08 19:04:19 +00:00
import deleteIcon from 'assets/svg/delete.svg' ;
import copyIcon from 'assets/svg/copy.svg' ;
import likeIcon from 'assets/svg/like.svg' ;
import likedIcon from 'assets/svg/liked.svg' ;
import reportIcon from 'assets/svg/report.svg' ;
import gemIcon from 'assets/svg/gem.svg' ;
2017-06-27 20:02:55 +00:00
import questIcon from 'assets/svg/quest.svg' ;
import informationIcon from 'assets/svg/information.svg' ;
import questBackground from 'assets/svg/quest-background-border.svg' ;
import upIcon from 'assets/svg/up.svg' ;
import downIcon from 'assets/svg/down.svg' ;
2017-08-09 16:56:48 +00:00
import goldGuildBadgeIcon from 'assets/svg/gold-guild-badge-small.svg' ;
import silverGuildBadgeIcon from 'assets/svg/silver-guild-badge-small.svg' ;
import bronzeGuildBadgeIcon from 'assets/svg/bronze-guild-badge-small.svg' ;
2017-06-08 19:04:19 +00:00
2017-06-02 20:55:02 +00:00
export default {
2017-07-29 22:08:36 +00:00
mixins : [ groupUtilities , styleHelper ] ,
2017-07-21 17:00:36 +00:00
props : [ 'groupId' ] ,
2017-06-02 20:55:02 +00:00
components : {
membersModal ,
2017-07-29 22:08:36 +00:00
startQuestModal ,
2017-06-27 20:02:55 +00:00
groupFormModal ,
2017-07-21 17:00:36 +00:00
chatMessage ,
2017-07-25 14:24:40 +00:00
inviteModal ,
2017-07-26 15:05:13 +00:00
groupChallenges ,
2017-08-07 20:26:17 +00:00
autocomplete ,
2017-09-30 13:28:39 +00:00
questDetailsModal ,
2017-10-02 01:42:02 +00:00
groupGemsModal ,
2017-12-06 16:13:44 +00:00
questSidebarSection ,
2018-01-29 21:18:20 +00:00
communityGuidelines ,
2017-06-27 20:02:55 +00:00
} ,
directives : {
2017-08-23 19:36:43 +00:00
markdown : markdownDirective ,
2017-06-02 20:55:02 +00:00
} ,
data ( ) {
return {
2017-09-07 19:26:53 +00:00
searchId : '' ,
group : { } ,
2017-06-08 19:04:19 +00:00
icons : Object . freeze ( {
like : likeIcon ,
copy : copyIcon ,
report : reportIcon ,
delete : deleteIcon ,
gem : gemIcon ,
liked : likedIcon ,
2017-06-27 20:02:55 +00:00
questIcon ,
information : informationIcon ,
questBackground ,
upIcon ,
downIcon ,
2017-07-29 22:08:36 +00:00
goldGuildBadgeIcon ,
2017-08-09 16:56:48 +00:00
silverGuildBadgeIcon ,
bronzeGuildBadgeIcon ,
2017-06-08 19:04:19 +00:00
} ) ,
2018-02-05 18:42:54 +00:00
members : [ ] ,
2017-06-27 20:02:55 +00:00
selectedQuest : { } ,
sections : {
quest : true ,
2017-08-22 20:39:45 +00:00
summary : true ,
2017-06-27 20:02:55 +00:00
description : true ,
challenges : true ,
} ,
2018-05-11 20:18:41 +00:00
chat : {
submitDisable : false ,
submitTimeout : null ,
} ,
2017-07-21 17:00:36 +00:00
newMessage : '' ,
2017-08-07 20:26:17 +00:00
coords : {
TOP : 0 ,
LEFT : 0 ,
} ,
2017-06-02 20:55:02 +00:00
} ;
} ,
computed : {
... mapState ( { user : 'user.data' } ) ,
2017-07-31 19:54:52 +00:00
partyStore ( ) {
return this . $store . state . party ;
} ,
2017-06-27 20:02:55 +00:00
isParty ( ) {
return this . $route . path . startsWith ( '/party' ) ;
} ,
isLeader ( ) {
return this . user . _id === this . group . leader . _id ;
} ,
2017-10-04 02:15:00 +00:00
isAdmin ( ) {
return Boolean ( this . user . contributor . admin ) ;
} ,
2017-06-02 20:55:02 +00:00
isMember ( ) {
2017-06-27 20:02:55 +00:00
return this . isMemberOfGroup ( this . user , this . group ) ;
} ,
2017-06-02 20:55:02 +00:00
memberProfileName ( memberId ) {
let foundMember = find ( this . group . members , function findMember ( member ) {
return member . _id === memberId ;
} ) ;
return foundMember . profile . name ;
} ,
isManager ( memberId , group ) {
return Boolean ( group . managers [ memberId ] ) ;
} ,
userCanApprove ( userId , group ) {
if ( ! group ) return false ;
let leader = group . leader . _id === userId ;
let userIsManager = Boolean ( group . managers [ userId ] ) ;
return leader || userIsManager ;
} ,
2017-06-27 20:02:55 +00:00
hasChallenges ( ) {
if ( ! this . group . challenges ) return false ;
return this . group . challenges . length === 0 ;
} ,
2018-02-11 15:34:57 +00:00
showNoNotificationsMessage ( ) {
return this . group . memberCount > this . $store . state . constants . LARGE _GROUP _COUNT _MESSAGE _CUTOFF ;
} ,
2017-06-02 20:55:02 +00:00
} ,
2017-07-31 19:54:52 +00:00
mounted ( ) {
2018-01-31 10:55:39 +00:00
if ( this . isParty ) this . searchId = 'party' ;
2017-09-05 18:34:00 +00:00
if ( ! this . searchId ) this . searchId = this . groupId ;
this . load ( ) ;
} ,
beforeRouteUpdate ( to , from , next ) {
2017-09-07 19:26:53 +00:00
this . $set ( this , 'searchId' , to . params . groupId ) ;
2018-01-03 05:56:31 +00:00
// Reset chat
this . newMessage = '' ;
this . coords = {
TOP : 0 ,
LEFT : 0 ,
} ;
2017-09-05 18:34:00 +00:00
next ( ) ;
2017-06-02 20:55:02 +00:00
} ,
watch : {
// call again the method if the route changes (when this route is already active)
$route : 'fetchGuild' ,
2017-07-31 19:54:52 +00:00
partyStore ( ) {
if ( this . $store . state . party . _id ) {
this . group = this . $store . state . party ;
} else {
this . group = null ;
this . $router . push ( '/' ) ;
}
} ,
2017-06-02 20:55:02 +00:00
} ,
methods : {
2018-02-05 18:42:54 +00:00
acceptCommunityGuidelines ( ) {
this . $store . dispatch ( 'user:set' , { 'flags.communityGuidelinesAccepted' : true } ) ;
} ,
async load ( ) {
if ( this . isParty ) {
this . searchId = 'party' ;
// @TODO: Set up from old client. Decide what we need and what we don't
// Check Desktop notifs
// Load invites
}
await this . fetchGuild ( ) ;
// Fetch group members on load
this . members = await this . loadMembers ( {
groupId : this . group . _id ,
includeAllPublicFields : true ,
} ) ;
2017-09-05 18:34:00 +00:00
this . $root . $on ( 'updatedGroup' , group => {
let updatedGroup = extend ( this . group , group ) ;
this . $set ( this . group , updatedGroup ) ;
} ) ;
} ,
2018-02-05 18:42:54 +00:00
/ * *
* Method for loading members of a group , with optional parameters for
* modifying requests .
*
* @ param { Object } payload Used for modifying requests for members
* /
loadMembers ( payload = null ) {
// Remove unnecessary data
if ( payload && payload . challengeId ) {
delete payload . challengeId ;
}
return this . $store . dispatch ( 'members:getGroupMembers' , payload ) ;
} ,
2017-08-07 20:26:17 +00:00
// @TODO: abstract autocomplete
// https://medium.com/@_jh3y/how-to-where-s-the-caret-getting-the-xy-position-of-the-caret-a24ba372990a
getCoord ( e , text ) {
let carPos = text . selectionEnd ;
let div = document . createElement ( 'div' ) ;
let span = document . createElement ( 'span' ) ;
let copyStyle = getComputedStyle ( text ) ;
[ ] . forEach . call ( copyStyle , ( prop ) => {
div . style [ prop ] = copyStyle [ prop ] ;
} ) ;
div . style . position = 'absolute' ;
document . body . appendChild ( div ) ;
div . textContent = text . value . substr ( 0 , carPos ) ;
span . textContent = text . value . substr ( carPos ) || '.' ;
div . appendChild ( span ) ;
this . coords = {
TOP : span . offsetTop ,
LEFT : span . offsetLeft ,
} ;
document . body . removeChild ( div ) ;
} ,
2017-09-29 21:03:43 +00:00
updateCarretPosition : debounce ( function updateCarretPosition ( eventUpdate ) {
this . _updateCarretPosition ( eventUpdate ) ;
} , 250 ) ,
_updateCarretPosition ( eventUpdate ) {
2017-08-07 20:26:17 +00:00
let text = eventUpdate . target ;
this . getCoord ( eventUpdate , text ) ;
} ,
selectedAutocomplete ( newText ) {
this . newMessage = newText ;
} ,
2017-07-29 22:08:36 +00:00
showMemberModal ( ) {
2017-08-23 03:58:13 +00:00
this . $store . state . memberModalOptions . groupId = this . group . _id ;
this . $store . state . memberModalOptions . group = this . group ;
2018-02-05 18:42:54 +00:00
this . $store . state . memberModalOptions . memberCount = this . group . memberCount ;
this . $store . state . memberModalOptions . viewingMembers = this . members ;
this . $store . state . memberModalOptions . fetchMoreMembers = this . loadMembers ;
2017-11-08 17:40:37 +00:00
this . $root . $emit ( 'bv::show::modal' , 'members-modal' ) ;
2017-07-29 22:08:36 +00:00
} ,
2018-05-11 20:18:41 +00:00
disableMessageSendShortcut ( ) {
// Some users were experiencing accidental sending of messages after pasting
// So, after pasting, disable the shortcut for a second.
this . chat . submitDisable = true ;
if ( this . chat . submitTimeout ) {
// If someone pastes during the disabled period, prevent early re-enable
clearTimeout ( this . chat . submitTimeout ) ;
this . chat . submitTimeout = null ;
}
this . chat . submitTimeout = window . setTimeout ( ( ) => {
this . chat . submitTimeout = null ;
this . chat . submitDisable = false ;
} , 500 ) ;
} ,
async sendMessageShortcut ( ) {
// If the user recently pasted in the text field, don't submit
if ( ! this . chat . submitDisable ) {
this . sendMessage ( ) ;
}
} ,
2017-07-21 17:00:36 +00:00
async sendMessage ( ) {
2017-09-25 18:02:12 +00:00
if ( ! this . newMessage ) return ;
2017-07-21 17:00:36 +00:00
let response = await this . $store . dispatch ( 'chat:postChat' , {
2017-09-10 21:55:35 +00:00
group : this . group ,
2017-07-21 17:00:36 +00:00
message : this . newMessage ,
} ) ;
this . group . chat . unshift ( response . message ) ;
this . newMessage = '' ;
} ,
2017-08-03 20:04:03 +00:00
fetchRecentMessages ( ) {
this . fetchGuild ( ) ;
} ,
2017-10-04 02:15:00 +00:00
reverseChat ( ) {
this . group . chat . reverse ( ) ;
} ,
2017-06-02 20:55:02 +00:00
updateGuild ( ) {
2017-06-27 20:02:55 +00:00
this . $store . state . editingGroup = this . group ;
2017-11-08 17:40:37 +00:00
this . $root . $emit ( 'bv::show::modal' , 'guild-form' ) ;
2017-06-02 20:55:02 +00:00
} ,
2017-07-25 14:24:40 +00:00
showInviteModal ( ) {
2017-11-08 17:40:37 +00:00
this . $root . $emit ( 'bv::show::modal' , 'invite-modal' ) ;
2017-07-25 14:24:40 +00:00
} ,
2017-06-02 20:55:02 +00:00
async fetchGuild ( ) {
2017-07-31 19:54:52 +00:00
if ( this . searchId === 'party' && ! this . user . party . _id ) {
2017-11-08 17:40:37 +00:00
this . $root . $emit ( 'bv::show::modal' , 'create-party-modal' ) ;
2017-07-31 19:54:52 +00:00
return ;
}
2017-06-27 20:02:55 +00:00
if ( this . isParty ) {
2018-01-15 17:21:08 +00:00
await this . $store . dispatch ( 'party:getParty' , true ) ;
2017-09-12 17:56:06 +00:00
this . group = this . $store . state . party . data ;
2017-06-27 20:02:55 +00:00
this . checkForAchievements ( ) ;
2018-01-12 22:18:56 +00:00
} else {
const group = await this . $store . dispatch ( 'guilds:getGroup' , { groupId : this . searchId } ) ;
this . $set ( this , 'group' , group ) ;
2017-06-27 20:02:55 +00:00
}
2018-01-31 10:55:39 +00:00
const groupId = this . searchId === 'party' ? this . user . party . _id : this . searchId ;
if ( this . hasUnreadMessages ( groupId ) ) {
// Delay by 1sec to make sure it returns after other requests that don't have the notification marked as read
setTimeout ( ( ) => {
this . $store . dispatch ( 'chat:markChatSeen' , { groupId } ) ;
this . $delete ( this . user . newMessages , groupId ) ;
} , 1000 ) ;
}
} ,
hasUnreadMessages ( groupId ) {
if ( this . user . newMessages [ groupId ] ) return true ;
return this . user . notifications . some ( n => {
return n . type === 'NEW_CHAT_MESSAGE' && n . data . group . id === groupId ;
} ) ;
2017-06-02 20:55:02 +00:00
} ,
deleteAllMessages ( ) {
if ( confirm ( this . $t ( 'confirmDeleteAllMessages' ) ) ) {
// User.clearPMs();
}
} ,
2017-06-27 20:02:55 +00:00
checkForAchievements ( ) {
// Checks if user's party has reached 2 players for the first time.
if ( ! this . user . achievements . partyUp && this . group . memberCount >= 2 ) {
// @TODO
// User.set({'achievements.partyUp':true});
// Achievement.displayAchievement('partyUp');
}
// Checks if user's party has reached 4 players for the first time.
if ( ! this . user . achievements . partyOn && this . group . memberCount >= 4 ) {
// @TODO
// User.set({'achievements.partyOn':true});
// Achievement.displayAchievement('partyOn');
}
} ,
async join ( ) {
2017-08-23 03:58:13 +00:00
if ( this . group . cancelledPlan && ! confirm ( this . $t ( 'aboutToJoinCancelledGroupPlan' ) ) ) {
2017-06-27 20:02:55 +00:00
return ;
}
2018-01-31 10:55:39 +00:00
await this . $store . dispatch ( 'guilds:join' , { groupId : this . group . _id , type : 'guild' } ) ;
2017-06-27 20:02:55 +00:00
} ,
clickLeave ( ) {
2017-09-08 19:23:58 +00:00
Analytics . track ( {
hitType : 'event' ,
eventCategory : 'button' ,
eventAction : 'click' ,
eventLabel : 'Leave Party' ,
} ) ;
2017-06-27 20:02:55 +00:00
// @TODO: Get challenges and ask to keep or remove
2017-08-09 16:56:48 +00:00
if ( ! confirm ( 'Are you sure you want to leave?' ) ) return ;
2017-06-27 20:02:55 +00:00
let keep = true ;
this . leave ( keep ) ;
} ,
async leave ( keepTasks ) {
let keepChallenges = 'remain-in-challenges' ;
2017-07-31 19:54:52 +00:00
let data = {
2017-06-27 20:02:55 +00:00
groupId : this . group . _id ,
keep : keepTasks ,
keepChallenges ,
2017-07-31 19:54:52 +00:00
} ;
2017-09-08 19:23:58 +00:00
if ( this . isParty ) {
data . type = 'party' ;
Analytics . updateUser ( { partySize : null , partyID : null } ) ;
2018-01-15 17:21:08 +00:00
this . $store . state . partyMembers = [ ] ;
2017-09-08 19:23:58 +00:00
}
2017-07-31 19:54:52 +00:00
await this . $store . dispatch ( 'guilds:leave' , data ) ;
2018-01-15 17:21:08 +00:00
if ( this . isParty ) {
this . $router . push ( { name : 'tasks' } ) ;
}
2017-06-27 20:02:55 +00:00
} ,
2017-08-26 02:56:21 +00:00
upgradeGroup ( ) {
this . $store . state . upgradingGroup = this . group ;
this . $router . push ( '/group-plans' ) ;
} ,
2017-06-27 20:02:55 +00:00
clickStartQuest ( ) {
2017-09-08 19:23:58 +00:00
Analytics . track ( {
hitType : 'event' ,
eventCategory : 'button' ,
eventAction : 'click' ,
eventLabel : 'Start a Quest' ,
} ) ;
2017-06-27 20:02:55 +00:00
let hasQuests = find ( this . user . items . quests , ( quest ) => {
return quest > 0 ;
} ) ;
if ( hasQuests ) {
2017-11-08 17:40:37 +00:00
this . $root . $emit ( 'bv::show::modal' , 'start-quest-modal' ) ;
2017-06-27 20:02:55 +00:00
return ;
}
// $rootScope.$state.go('options.inventory.quests');
} ,
2017-09-25 18:02:12 +00:00
async showMemberProfile ( leader ) {
let heroDetails = await this . $store . dispatch ( 'members:fetchMember' , { memberId : leader . _id } ) ;
2017-11-27 16:29:20 +00:00
this . $root . $emit ( 'habitica:show-profile' , {
user : heroDetails . data . data ,
startingPage : 'profile' ,
} ) ;
2017-09-25 18:02:12 +00:00
} ,
2017-10-02 01:42:02 +00:00
showGroupGems ( ) {
2017-11-08 17:40:37 +00:00
this . $root . $emit ( 'bv::show::modal' , 'group-gems-modal' ) ;
2017-10-02 01:42:02 +00:00
} ,
2017-12-06 16:13:44 +00:00
toggleQuestSection ( ) {
this . sections . quest = ! this . sections . quest ;
} ,
2017-06-02 20:55:02 +00:00
} ,
} ;
< / script >